* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include "vl.h"
+#include "hw/hw.h"
+#include "hw/usb.h"
+#include "hw/pcmcia.h"
+#include "hw/pc.h"
+#include "hw/pci.h"
+#include "gdbstub.h"
+#include "net.h"
+#include "qemu-char.h"
+#include "sysemu.h"
+#include "console.h"
+#include "block.h"
+#include "audio/audio.h"
#include "disas.h"
#include <dirent.h>
+#include "qemu-timer.h"
//#define DEBUG
//#define DEBUG_COMPLETION
static term_cmd_t term_cmds[];
static term_cmd_t info_cmds[];
-static char term_outbuf[1024];
+static uint8_t term_outbuf[1024];
static int term_outbuf_index;
static void monitor_start_input(void);
/* flush at every end of line or if the buffer is full */
void term_puts(const char *str)
{
- int c;
+ char c;
for(;;) {
c = *str++;
if (c == '\0')
int i, all_devices;
all_devices = !strcmp(device, "all");
- for (i = 0; i < MAX_DISKS; i++) {
- if (bs_table[i]) {
+ for (i = 0; i < nb_drives; i++) {
if (all_devices ||
- !strcmp(bdrv_get_device_name(bs_table[i]), device))
- bdrv_commit(bs_table[i]);
- }
+ !strcmp(bdrv_get_device_name(drives_table[i].bdrv), device))
+ bdrv_commit(drives_table[i].bdrv);
}
- if (mtd_bdrv)
- if (all_devices || !strcmp(bdrv_get_device_name(mtd_bdrv), device))
- bdrv_commit(mtd_bdrv);
}
static void do_info(const char *item)
bdrv_info();
}
+static void do_info_blockstats(void)
+{
+ bdrv_info_stats();
+}
+
/* get the current CPU defined by the user */
-int mon_set_cpu(int cpu_index)
+static int mon_set_cpu(int cpu_index)
{
CPUState *env;
return -1;
}
-CPUState *mon_get_cpu(void)
+static CPUState *mon_get_cpu(void)
{
if (!mon_cpu) {
mon_set_cpu(0);
env->cpu_index);
#if defined(TARGET_I386)
term_printf(" pc=0x" TARGET_FMT_lx, env->eip + env->segs[R_CS].base);
- if (env->hflags & HF_HALTED_MASK)
- term_printf(" (halted)");
#elif defined(TARGET_PPC)
term_printf(" nip=0x" TARGET_FMT_lx, env->nip);
- if (env->halted)
- term_printf(" (halted)");
#elif defined(TARGET_SPARC)
term_printf(" pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx, env->pc, env->npc);
- if (env->halted)
- term_printf(" (halted)");
#elif defined(TARGET_MIPS)
term_printf(" PC=0x" TARGET_FMT_lx, env->PC[env->current_tc]);
+#endif
if (env->halted)
term_printf(" (halted)");
-#endif
term_printf("\n");
}
}
eject_device(bs, force);
}
-static void do_change_block(const char *device, const char *filename)
+static void do_change_block(const char *device, const char *filename, const char *fmt)
{
BlockDriverState *bs;
+ BlockDriver *drv = NULL;
bs = bdrv_find(device);
if (!bs) {
term_printf("device not found\n");
return;
}
+ if (fmt) {
+ drv = bdrv_find_format(fmt);
+ if (!drv) {
+ term_printf("invalid format %s\n", fmt);
+ return;
+ }
+ }
if (eject_device(bs, 0) < 0)
return;
- bdrv_open(bs, filename, 0);
+ bdrv_open2(bs, filename, 0, drv);
qemu_key_check(bs, filename);
}
}
}
-static void do_change(const char *device, const char *target)
+static void do_change(const char *device, const char *target, const char *fmt)
{
if (strcmp(device, "vnc") == 0) {
do_change_vnc(target);
} else {
- do_change_block(device, target);
+ do_change_block(device, target, fmt);
}
}
}
static void memory_dump(int count, int format, int wsize,
- target_ulong addr, int is_physical)
+ target_phys_addr_t addr, int is_physical)
{
CPUState *env;
int nb_per_line, l, line_size, i, max_digits, len;
}
while (len > 0) {
- term_printf(TARGET_FMT_lx ":", addr);
+ if (is_physical)
+ term_printf(TARGET_FMT_plx ":", addr);
+ else
+ term_printf(TARGET_FMT_lx ":", (target_ulong)addr);
l = len;
if (l > line_size)
l = line_size;
memory_dump(count, format, size, addr, 0);
}
+#if TARGET_PHYS_ADDR_BITS > 32
+#define GET_TPHYSADDR(h, l) (((uint64_t)(h) << 32) | (l))
+#else
+#define GET_TPHYSADDR(h, l) (l)
+#endif
+
static void do_physical_memory_dump(int count, int format, int size,
uint32_t addrh, uint32_t addrl)
{
- target_long addr = GET_TLONG(addrh, addrl);
+ target_phys_addr_t addr = GET_TPHYSADDR(addrh, addrl);
memory_dump(count, format, size, addr, 1);
}
static void do_print(int count, int format, int size, unsigned int valh, unsigned int vall)
{
- target_long val = GET_TLONG(valh, vall);
-#if TARGET_LONG_BITS == 32
+ target_phys_addr_t val = GET_TPHYSADDR(valh, vall);
+#if TARGET_PHYS_ADDR_BITS == 32
switch(format) {
case 'o':
term_printf("%#o", val);
fclose(f);
}
+static void do_physical_memory_save(unsigned int valh, unsigned int vall,
+ uint32_t size, const char *filename)
+{
+ FILE *f;
+ uint32_t l;
+ uint8_t buf[1024];
+ target_phys_addr_t addr = GET_TPHYSADDR(valh, vall);
+
+ f = fopen(filename, "wb");
+ if (!f) {
+ term_printf("could not open '%s'\n", filename);
+ return;
+ }
+ while (size != 0) {
+ l = sizeof(buf);
+ if (l > size)
+ l = size;
+ cpu_physical_memory_rw(addr, buf, l, 0);
+ fwrite(buf, 1, l, f);
+ fflush(f);
+ addr += l;
+ size -= l;
+ }
+ fclose(f);
+}
+
static void do_sum(uint32_t start, uint32_t size)
{
uint32_t addr;
{ 0x31, "n" },
{ 0x32, "m" },
+ { 0x37, "asterisk" },
+
{ 0x39, "spc" },
{ 0x3a, "caps_lock" },
{ 0x3b, "f1" },
{ 0x4e, "kp_add" },
{ 0x9c, "kp_enter" },
{ 0x53, "kp_decimal" },
+ { 0x54, "sysrq" },
{ 0x52, "kp_0" },
{ 0x4f, "kp_1" },
{ 0xd2, "insert" },
{ 0xd3, "delete" },
+#if defined(TARGET_SPARC) && !defined(TARGET_SPARC64)
+ { 0xf0, "stop" },
+ { 0xf1, "again" },
+ { 0xf2, "props" },
+ { 0xf3, "undo" },
+ { 0xf4, "front" },
+ { 0xf5, "copy" },
+ { 0xf6, "open" },
+ { 0xf7, "paste" },
+ { 0xf8, "find" },
+ { 0xf9, "cut" },
+ { 0xfa, "lf" },
+ { 0xfb, "help" },
+ { 0xfc, "meta_l" },
+ { 0xfd, "meta_r" },
+ { 0xfe, "compose" },
+#endif
{ 0, NULL },
};
return -1;
}
-static void do_send_key(const char *string)
+#define MAX_KEYCODES 16
+static uint8_t keycodes[MAX_KEYCODES];
+static int nb_pending_keycodes;
+static QEMUTimer *key_timer;
+
+static void release_keys(void *opaque)
{
- char keybuf[16], *q;
- uint8_t keycodes[16];
- const char *p;
- int nb_keycodes, keycode, i;
-
- nb_keycodes = 0;
- p = string;
- while (*p != '\0') {
- q = keybuf;
- while (*p != '\0' && *p != '-') {
- if ((q - keybuf) < sizeof(keybuf) - 1) {
- *q++ = *p;
+ int keycode;
+
+ while (nb_pending_keycodes > 0) {
+ nb_pending_keycodes--;
+ keycode = keycodes[nb_pending_keycodes];
+ if (keycode & 0x80)
+ kbd_put_keycode(0xe0);
+ kbd_put_keycode(keycode | 0x80);
+ }
+}
+
+static void do_sendkey(const char *string, int has_hold_time, int hold_time)
+{
+ char keyname_buf[16];
+ char *separator;
+ int keyname_len, keycode, i;
+
+ if (nb_pending_keycodes > 0) {
+ qemu_del_timer(key_timer);
+ release_keys(NULL);
+ }
+ if (!has_hold_time)
+ hold_time = 100;
+ i = 0;
+ while (1) {
+ separator = strchr(string, '-');
+ keyname_len = separator ? separator - string : strlen(string);
+ if (keyname_len > 0) {
+ pstrcpy(keyname_buf, sizeof(keyname_buf), string);
+ if (keyname_len > sizeof(keyname_buf) - 1) {
+ term_printf("invalid key: '%s...'\n", keyname_buf);
+ return;
}
- p++;
- }
- *q = '\0';
- keycode = get_keycode(keybuf);
- if (keycode < 0) {
- term_printf("unknown key: '%s'\n", keybuf);
- return;
+ if (i == MAX_KEYCODES) {
+ term_printf("too many keys\n");
+ return;
+ }
+ keyname_buf[keyname_len] = 0;
+ keycode = get_keycode(keyname_buf);
+ if (keycode < 0) {
+ term_printf("unknown key: '%s'\n", keyname_buf);
+ return;
+ }
+ keycodes[i++] = keycode;
}
- keycodes[nb_keycodes++] = keycode;
- if (*p == '\0')
+ if (!separator)
break;
- p++;
+ string = separator + 1;
}
+ nb_pending_keycodes = i;
/* key down events */
- for(i = 0; i < nb_keycodes; i++) {
+ for (i = 0; i < nb_pending_keycodes; i++) {
keycode = keycodes[i];
if (keycode & 0x80)
kbd_put_keycode(0xe0);
kbd_put_keycode(keycode & 0x7f);
}
- /* key up events */
- for(i = nb_keycodes - 1; i >= 0; i--) {
- keycode = keycodes[i];
- if (keycode & 0x80)
- kbd_put_keycode(0xe0);
- kbd_put_keycode(keycode | 0x80);
- }
+ /* delayed key up events */
+ qemu_mod_timer(key_timer, qemu_get_clock(vm_clock) +
+ muldiv64(ticks_per_sec, hold_time, 1000));
}
static int mouse_button_state;
suffix, addr, size * 2, val);
}
+/* boot_set handler */
+static QEMUBootSetHandler *qemu_boot_set_handler = NULL;
+static void *boot_opaque;
+
+void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
+{
+ qemu_boot_set_handler = func;
+ boot_opaque = opaque;
+}
+
+static void do_boot_set(const char *bootdevice)
+{
+ int res;
+
+ if (qemu_boot_set_handler) {
+ res = qemu_boot_set_handler(boot_opaque, bootdevice);
+ if (res == 0)
+ term_printf("boot device list now set to %s\n", bootdevice);
+ else
+ term_printf("setting boot device list failed with error %i\n", res);
+ } else {
+ term_printf("no function defined to set boot device list for this architecture\n");
+ }
+}
+
static void do_system_reset(void)
{
qemu_system_reset_request();
}
#endif
+#if defined(TARGET_I386)
+static void do_inject_nmi(int cpu_index)
+{
+ CPUState *env;
+
+ for (env = first_cpu; env != NULL; env = env->next_cpu)
+ if (env->cpu_index == cpu_index) {
+ cpu_interrupt(env, CPU_INTERRUPT_NMI);
+ break;
+ }
+}
+#endif
+
static term_cmd_t term_cmds[] = {
{ "help|?", "s?", do_help,
"[cmd]", "show the help" },
"", "quit the emulator" },
{ "eject", "-fB", do_eject,
"[-f] device", "eject a removable medium (use -f to force it)" },
- { "change", "BF", do_change,
- "device filename", "change a removable medium" },
+ { "change", "BFs?", do_change,
+ "device filename [format]", "change a removable medium, optional format" },
{ "screendump", "F", do_screen_dump,
"filename", "save screen into PPM image 'filename'" },
- { "logfile", "s", do_logfile,
+ { "logfile", "F", do_logfile,
"filename", "output logs to 'filename'" },
{ "log", "s", do_log,
"item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
{ "i", "/ii.", do_ioport_read,
"/fmt addr", "I/O port read" },
- { "sendkey", "s", do_send_key,
- "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },
+ { "sendkey", "si?", do_sendkey,
+ "keys [hold_ms]", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)" },
{ "system_reset", "", do_system_reset,
"", "reset the system" },
{ "system_powerdown", "", do_system_powerdown,
"capture index", "stop capture" },
{ "memsave", "lis", do_memory_save,
"addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },
+ { "pmemsave", "lis", do_physical_memory_save,
+ "addr size file", "save to disk physical memory dump starting at 'addr' of size 'size'", },
+ { "boot_set", "s", do_boot_set,
+ "bootdevice", "define new values for the boot device list" },
+#if defined(TARGET_I386)
+ { "nmi", "i", do_inject_nmi,
+ "cpu", "inject an NMI on the given CPU", },
+#endif
{ NULL, NULL, },
};
"", "show the network state" },
{ "block", "", do_info_block,
"", "show the block devices" },
+ { "blockstats", "", do_info_blockstats,
+ "", "show block device statistics" },
{ "registers", "", do_info_registers,
"", "show the cpu registers" },
{ "cpus", "", do_info_cpus,
#if defined(TARGET_PPC)
{ "cpustats", "", do_info_cpu_stats,
"", "show CPU statistics", },
+#endif
+#if defined(CONFIG_SLIRP)
+ { "slirp", "", do_info_slirp,
+ "", "show SLIRP statistics", },
#endif
{ NULL, NULL, },
};
CPUState *env = mon_get_cpu();
if (!env)
return 0;
- return do_load_msr(env);
+ return env->msr;
}
static target_long monitor_get_xer (struct MonitorDef *md, int val)
}
}
-static target_long expr_sum(void);
+static int64_t expr_sum(void);
-static target_long expr_unary(void)
+static int64_t expr_unary(void)
{
- target_long n;
+ int64_t n;
char *p;
int ret;
case '$':
{
char buf[128], *q;
+ target_long reg=0;
pch++;
q = buf;
while (isspace(*pch))
pch++;
*q = 0;
- ret = get_monitor_def(&n, buf);
+ ret = get_monitor_def(®, buf);
if (ret == -1)
expr_error("unknown register");
else if (ret == -2)
expr_error("no cpu defined");
+ n = reg;
}
break;
case '\0':
n = 0;
break;
default:
-#if TARGET_LONG_BITS == 64
+#if TARGET_PHYS_ADDR_BITS > 32
n = strtoull(pch, &p, 0);
#else
n = strtoul(pch, &p, 0);
}
-static target_long expr_prod(void)
+static int64_t expr_prod(void)
{
- target_long val, val2;
+ int64_t val, val2;
int op;
val = expr_unary();
return val;
}
-static target_long expr_logic(void)
+static int64_t expr_logic(void)
{
- target_long val, val2;
+ int64_t val, val2;
int op;
val = expr_prod();
return val;
}
-static target_long expr_sum(void)
+static int64_t expr_sum(void)
{
- target_long val, val2;
+ int64_t val, val2;
int op;
val = expr_logic();
return val;
}
-static int get_expr(target_long *pval, const char **pp)
+static int get_expr(int64_t *pval, const char **pp)
{
pch = *pp;
if (setjmp(expr_env)) {
case 'i':
case 'l':
{
- target_long val;
+ int64_t val;
+
while (isspace(*p))
p++;
if (*typestr == '?' || *typestr == '.') {
} else {
if ((nb_args + 1) >= MAX_ARGS)
goto error_args;
-#if TARGET_LONG_BITS == 64
+#if TARGET_PHYS_ADDR_BITS > 32
args[nb_args++] = (void *)(long)((val >> 32) & 0xffffffff);
#else
args[nb_args++] = (void *)0;
int i;
if (is_first_init) {
+ key_timer = qemu_new_timer(vm_clock, release_keys, NULL);
+ if (!key_timer)
+ return;
for (i = 0; i < MAX_MON; i++) {
monitor_hd[i] = NULL;
}
hide_banner = !show_banner;
qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL);
+
+ readline_start("", 0, monitor_handle_command1, NULL);
}
/* XXX: use threads ? */