[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] Term prompt for qemu
From: |
J. Mayer |
Subject: |
Re: [Qemu-devel] [PATCH] Term prompt for qemu |
Date: |
18 Nov 2003 09:13:42 +0100 |
vl.c.diff
Add term prompt for user commands during emulation.
Also add <CTRL><a>+<d> to turn on/off log. This is useful
to know if qemu is still translating code, long time after the
boot.
diff -urNbB -x CVS qemu-current/vl.c qemu/vl.c
--- qemu-current/vl.c Tue Nov 18 06:51:10 2003
+++ qemu/vl.c Tue Nov 18 02:19:33 2003
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
+#include <ctype.h>
#include <getopt.h>
#include <inttypes.h>
#include <unistd.h>
@@ -1422,23 +1483,124 @@
}
#define TERM_ESCAPE 0x01 /* ctrl-a is used for escape */
-static int term_got_escape;
+static int term_got_escape, term_command;
+static unsigned char term_cmd_buf[128];
+
+typedef struct term_cmd_t {
+ const unsigned char *name;
+ void (*handler)(unsigned char *params);
+} term_cmd_t;
+
+static void do_change_cdrom (unsigned char *params);
+static void do_change_fd0 (unsigned char *params);
+static void do_change_fd1 (unsigned char *params);
+
+static term_cmd_t term_cmds[] = {
+ { "changecd", &do_change_cdrom, },
+ { "changefd0", &do_change_fd0, },
+ { "changefd1", &do_change_fd1, },
+ { NULL, NULL, },
+};
void term_print_help(void)
{
printf("\n"
"C-a h print this help\n"
"C-a x exit emulatior\n"
+ "C-a d switch on/off debug log\n"
"C-a s save disk data back to file (if -snapshot)\n"
"C-a b send break (magic sysrq)\n"
+ "C-a c send qemu internal command\n"
"C-a C-a send C-a\n"
);
}
+static void do_change_cdrom (unsigned char *params)
+{
+ /* Dunno how to do it... */
+}
+
+static void do_change_fd (int fd, unsigned char *params)
+{
+ unsigned char *name_start, *name_end, *ros;
+ int ro;
+
+ for (name_start = params;
+ isspace(*name_start); name_start++)
+ continue;
+ if (*name_start == '\0')
+ return;
+ for (name_end = name_start;
+ !isspace(*name_end) && *name_end != '\0'; name_end++)
+ continue;
+ for (ros = name_end + 1; isspace(*ros); ros++)
+ continue;
+ if (ros[0] == 'r' && ros[1] == 'o')
+ ro = 1;
+ else
+ ro = 0;
+ *name_end = '\0';
+ printf("Change fd %d to %s (%s)\n", fd, name_start, params);
+ fdctrl_disk_change(fd, name_start, ro);
+}
+
+static void do_change_fd0 (unsigned char *params)
+{
+ do_change_fd(0, params);
+}
+
+static void do_change_fd1 (unsigned char *params)
+{
+ do_change_fd(1, params);
+}
+
+static void serial_treat_command ()
+{
+ unsigned char *cmd_start, *cmd_end;
+ int i;
+
+ for (cmd_start = term_cmd_buf; isspace(*cmd_start); cmd_start++)
+ continue;
+ for (cmd_end = cmd_start;
+ !isspace(*cmd_end) && *cmd_end != '\0'; cmd_end++)
+ continue;
+ for (i = 0; term_cmds[i].name != NULL; i++) {
+ if (strlen(term_cmds[i].name) == (cmd_end - cmd_start) &&
+ memcmp(term_cmds[i].name, cmd_start, cmd_end - cmd_start) == 0) {
+ (*term_cmds[i].handler)(cmd_end + 1);
+ return;
+ }
+ }
+ *cmd_end = '\0';
+ printf("Unknown term command: %s\n", cmd_start);
+}
+
+extern FILE *logfile;
+
/* called when a char is received */
void serial_received_byte(SerialState *s, int ch)
{
- if (term_got_escape) {
+ if (term_command) {
+ if (ch == '\n' || ch == '\r' || term_command == 127) {
+ printf("\n");
+ serial_treat_command();
+ term_command = 0;
+ } else {
+ if (ch == 0x7F || ch == 0x08) {
+ if (term_command > 0) {
+ term_cmd_buf[--term_command] = '\0';
+ printf("\r "
+ " ");
+ printf("\r> %s", term_cmd_buf);
+ }
+ } else if (ch > 0x1f) {
+ term_cmd_buf[term_command++ - 1] = ch;
+ term_cmd_buf[term_command - 1] = '\0';
+ printf("\r> %s", term_cmd_buf);
+ }
+ fflush(stdout);
+ }
+ } else if (term_got_escape) {
term_got_escape = 0;
switch(ch) {
case 'h':
@@ -1447,6 +1609,14 @@
case 'x':
exit(0);
break;
+ case 'd':
+ if (logfile == NULL) {
+ printf("Turn logging ON\n");
+ cpu_set_log(CPU_LOG_ALL);
+ } else {
+ printf("Turn logging OFF\n");
+ cpu_reset_log();
+ }
case 's':
{
int i;
@@ -1462,6 +1632,11 @@
s->lsr |= UART_LSR_BI | UART_LSR_DR;
serial_update_irq();
break;
+ case 'c':
+ printf("> ");
+ fflush(stdout);
+ term_command = 1;
+ break;
case TERM_ESCAPE:
goto send_char;
}
@@ -2178,12 +2373,14 @@
val |= 0x20;
kbd_queue(s, val, 0);
break;
+#ifdef TARGET_I386
case KBD_CCMD_ENABLE_A20:
cpu_x86_set_a20(env, 1);
break;
case KBD_CCMD_DISABLE_A20:
cpu_x86_set_a20(env, 0);
break;
+#endif
case KBD_CCMD_RESET:
reset_requested = 1;
cpu_x86_interrupt(global_env, CPU_INTERRUPT_EXIT);
@@ -2516,7 +2713,9 @@
kbd_queue(s, val, 1);
break;
case KBD_CCMD_WRITE_OUTPORT:
+#ifdef TARGET_I386
cpu_x86_set_a20(env, (val >> 1) & 1);
+#endif
if (!(val & 1)) {
reset_requested = 1;
cpu_x86_interrupt(global_env, CPU_INTERRUPT_EXIT);
@@ -2559,7 +2758,7 @@
/***********************************************************/
/* Bochs BIOS debug ports */
-
+#ifdef TARGET_I386
void bochs_bios_write(CPUX86State *env, uint32_t addr, uint32_t val)
{
switch(addr) {
@@ -2601,6 +2800,7 @@
register_ioport_write(0x500, 1, bochs_bios_write, 1);
register_ioport_write(0x503, 1, bochs_bios_write, 1);
}
+#endif
/***********************************************************/
/* dumb display */
Re: [Qemu-devel] [ADD] PPC processor emulation, J. Mayer, 2003/11/18
Re: [Qemu-devel] [ADD] PPC processor emulation, J. Mayer, 2003/11/18
[Qemu-devel] [PATCH] Term prompt for qemu, J. Mayer, 2003/11/18