4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #include "monitor/qdev.h"
28 #include "hw/pcmcia.h"
29 #include "hw/i386/pc.h"
30 #include "hw/pci/pci.h"
31 #include "sysemu/watchdog.h"
32 #include "hw/loader.h"
33 #include "exec/gdbstub.h"
35 #include "net/slirp.h"
36 #include "sysemu/char.h"
37 #include "ui/qemu-spice.h"
38 #include "sysemu/sysemu.h"
39 #include "monitor/monitor.h"
40 #include "qemu/readline.h"
41 #include "ui/console.h"
43 #include "sysemu/blockdev.h"
44 #include "audio/audio.h"
45 #include "disas/disas.h"
46 #include "sysemu/balloon.h"
47 #include "qemu/timer.h"
48 #include "migration/migration.h"
49 #include "sysemu/kvm.h"
51 #include "sysemu/tpm.h"
52 #include "qapi/qmp/qint.h"
53 #include "qapi/qmp/qfloat.h"
54 #include "qapi/qmp/qlist.h"
55 #include "qapi/qmp/qbool.h"
56 #include "qapi/qmp/qstring.h"
57 #include "qapi/qmp/qjson.h"
58 #include "qapi/qmp/json-streamer.h"
59 #include "qapi/qmp/json-parser.h"
60 #include <qom/object_interfaces.h>
61 #include "qemu/osdep.h"
64 #include "trace/control.h"
65 #ifdef CONFIG_TRACE_SIMPLE
66 #include "trace/simple.h"
68 #include "exec/memory.h"
69 #include "qmp-commands.h"
71 #include "qemu/thread.h"
73 /* for pic/irq_info */
74 #if defined(TARGET_SPARC)
75 #include "hw/sparc/sun4m.h"
77 #include "hw/lm32/lm32_pic.h"
80 //#define DEBUG_COMPLETION
86 * 'B' block device name
87 * 's' string (accept optional quote)
88 * 'S' it just appends the rest of the string (accept optional quote)
89 * 'O' option string of the form NAME=VALUE,...
90 * parsed according to QemuOptsList given by its name
91 * Example: 'device:O' uses qemu_device_opts.
92 * Restriction: only lists with empty desc are supported
93 * TODO lift the restriction
95 * 'l' target long (32 or 64 bit)
96 * 'M' Non-negative target long (32 or 64 bit), in user mode the
97 * value is multiplied by 2^20 (think Mebibyte)
98 * 'o' octets (aka bytes)
99 * user mode accepts an optional E, e, P, p, T, t, G, g, M, m,
100 * K, k suffix, which multiplies the value by 2^60 for suffixes E
101 * and e, 2^50 for suffixes P and p, 2^40 for suffixes T and t,
102 * 2^30 for suffixes G and g, 2^20 for M and m, 2^10 for K and k
104 * user mode accepts an optional ms, us, ns suffix,
105 * which divides the value by 1e3, 1e6, 1e9, respectively
106 * '/' optional gdb-like print format (like "/10x")
108 * '?' optional type (for all types, except '/')
109 * '.' other form of optional type (for 'i' and 'l')
111 * user mode accepts "on" or "off"
112 * '-' optional parameter (eg. '-f')
116 typedef struct MonitorCompletionData MonitorCompletionData
;
117 struct MonitorCompletionData
{
119 void (*user_print
)(Monitor
*mon
, const QObject
*data
);
122 typedef struct mon_cmd_t
{
124 const char *args_type
;
127 void (*user_print
)(Monitor
*mon
, const QObject
*data
);
129 void (*cmd
)(Monitor
*mon
, const QDict
*qdict
);
130 int (*cmd_new
)(Monitor
*mon
, const QDict
*params
, QObject
**ret_data
);
131 int (*cmd_async
)(Monitor
*mon
, const QDict
*params
,
132 MonitorCompletion
*cb
, void *opaque
);
135 /* @sub_table is a list of 2nd level of commands. If it do not exist,
136 * mhandler should be used. If it exist, sub_table[?].mhandler should be
137 * used, and mhandler of 1st level plays the role of help function.
139 struct mon_cmd_t
*sub_table
;
142 /* file descriptors passed via SCM_RIGHTS */
143 typedef struct mon_fd_t mon_fd_t
;
147 QLIST_ENTRY(mon_fd_t
) next
;
150 /* file descriptor associated with a file descriptor set */
151 typedef struct MonFdsetFd MonFdsetFd
;
156 QLIST_ENTRY(MonFdsetFd
) next
;
159 /* file descriptor set containing fds passed via SCM_RIGHTS */
160 typedef struct MonFdset MonFdset
;
163 QLIST_HEAD(, MonFdsetFd
) fds
;
164 QLIST_HEAD(, MonFdsetFd
) dup_fds
;
165 QLIST_ENTRY(MonFdset
) next
;
168 typedef struct MonitorControl
{
170 JSONMessageParser parser
;
175 * To prevent flooding clients, events can be throttled. The
176 * throttling is calculated globally, rather than per-Monitor
179 typedef struct MonitorEventState
{
180 MonitorEvent event
; /* Event being tracked */
181 int64_t rate
; /* Period over which to throttle. 0 to disable */
182 int64_t last
; /* Time at which event was last emitted */
183 QEMUTimer
*timer
; /* Timer for handling delayed events */
184 QObject
*data
; /* Event pending delayed dispatch */
188 CharDriverState
*chr
;
199 BlockDriverCompletionFunc
*password_completion_cb
;
200 void *password_opaque
;
201 mon_cmd_t
*cmd_table
;
203 QLIST_HEAD(,mon_fd_t
) fds
;
204 QLIST_ENTRY(Monitor
) entry
;
207 /* QMP checker flags */
208 #define QMP_ACCEPT_UNKNOWNS 1
210 static QLIST_HEAD(mon_list
, Monitor
) mon_list
;
211 static QLIST_HEAD(mon_fdsets
, MonFdset
) mon_fdsets
;
212 static int mon_refcount
;
214 static mon_cmd_t mon_cmds
[];
215 static mon_cmd_t info_cmds
[];
217 static const mon_cmd_t qmp_cmds
[];
220 Monitor
*default_mon
;
222 static void monitor_command_cb(void *opaque
, const char *cmdline
,
223 void *readline_opaque
);
225 static inline int qmp_cmd_mode(const Monitor
*mon
)
227 return (mon
->mc ? mon
->mc
->command_mode
: 0);
230 /* Return true if in control mode, false otherwise */
231 static inline int monitor_ctrl_mode(const Monitor
*mon
)
233 return (mon
->flags
& MONITOR_USE_CONTROL
);
236 /* Return non-zero iff we have a current monitor, and it is in QMP mode. */
237 int monitor_cur_is_qmp(void)
239 return cur_mon
&& monitor_ctrl_mode(cur_mon
);
242 void monitor_read_command(Monitor
*mon
, int show_prompt
)
247 readline_start(mon
->rs
, "(qemu) ", 0, monitor_command_cb
, NULL
);
249 readline_show_prompt(mon
->rs
);
252 int monitor_read_password(Monitor
*mon
, ReadLineFunc
*readline_func
,
255 if (monitor_ctrl_mode(mon
)) {
256 qerror_report(QERR_MISSING_PARAMETER
, "password");
258 } else if (mon
->rs
) {
259 readline_start(mon
->rs
, "Password: ", 1, readline_func
, opaque
);
260 /* prompt is printed on return from the command handler */
263 monitor_printf(mon
, "terminal does not support password prompting\n");
268 static gboolean
monitor_unblocked(GIOChannel
*chan
, GIOCondition cond
,
271 Monitor
*mon
= opaque
;
278 void monitor_flush(Monitor
*mon
)
284 if (mon
->skip_flush
) {
288 buf
= qstring_get_str(mon
->outbuf
);
289 len
= qstring_get_length(mon
->outbuf
);
291 if (len
&& !mon
->mux_out
) {
292 rc
= qemu_chr_fe_write(mon
->chr
, (const uint8_t *) buf
, len
);
293 if ((rc
< 0 && errno
!= EAGAIN
) || (rc
== len
)) {
294 /* all flushed or error */
295 QDECREF(mon
->outbuf
);
296 mon
->outbuf
= qstring_new();
301 QString
*tmp
= qstring_from_str(buf
+ rc
);
302 QDECREF(mon
->outbuf
);
305 if (mon
->watch
== 0) {
306 mon
->watch
= qemu_chr_fe_add_watch(mon
->chr
, G_IO_OUT
,
307 monitor_unblocked
, mon
);
312 /* flush at every end of line */
313 static void monitor_puts(Monitor
*mon
, const char *str
)
322 qstring_append_chr(mon
->outbuf
, '\r');
324 qstring_append_chr(mon
->outbuf
, c
);
331 void monitor_vprintf(Monitor
*mon
, const char *fmt
, va_list ap
)
338 if (monitor_ctrl_mode(mon
)) {
342 buf
= g_strdup_vprintf(fmt
, ap
);
343 monitor_puts(mon
, buf
);
347 void monitor_printf(Monitor
*mon
, const char *fmt
, ...)
351 monitor_vprintf(mon
, fmt
, ap
);
355 void monitor_print_filename(Monitor
*mon
, const char *filename
)
359 for (i
= 0; filename
[i
]; i
++) {
360 switch (filename
[i
]) {
364 monitor_printf(mon
, "\\%c", filename
[i
]);
367 monitor_printf(mon
, "\\t");
370 monitor_printf(mon
, "\\r");
373 monitor_printf(mon
, "\\n");
376 monitor_printf(mon
, "%c", filename
[i
]);
382 static int GCC_FMT_ATTR(2, 3) monitor_fprintf(FILE *stream
,
383 const char *fmt
, ...)
387 monitor_vprintf((Monitor
*)stream
, fmt
, ap
);
392 static void monitor_user_noop(Monitor
*mon
, const QObject
*data
) { }
394 static inline int handler_is_qobject(const mon_cmd_t
*cmd
)
396 return cmd
->user_print
!= NULL
;
399 static inline bool handler_is_async(const mon_cmd_t
*cmd
)
401 return cmd
->flags
& MONITOR_CMD_ASYNC
;
404 static inline int monitor_has_error(const Monitor
*mon
)
406 return mon
->error
!= NULL
;
409 static void monitor_json_emitter(Monitor
*mon
, const QObject
*data
)
413 json
= mon
->flags
& MONITOR_USE_PRETTY ?
qobject_to_json_pretty(data
) :
414 qobject_to_json(data
);
415 assert(json
!= NULL
);
417 qstring_append_chr(json
, '\n');
418 monitor_puts(mon
, qstring_get_str(json
));
423 static QDict
*build_qmp_error_dict(const QError
*err
)
427 obj
= qobject_from_jsonf("{ 'error': { 'class': %s, 'desc': %p } }",
428 ErrorClass_lookup
[err
->err_class
],
431 return qobject_to_qdict(obj
);
434 static void monitor_protocol_emitter(Monitor
*mon
, QObject
*data
)
438 trace_monitor_protocol_emitter(mon
);
440 if (!monitor_has_error(mon
)) {
441 /* success response */
444 qobject_incref(data
);
445 qdict_put_obj(qmp
, "return", data
);
447 /* return an empty QDict by default */
448 qdict_put(qmp
, "return", qdict_new());
452 qmp
= build_qmp_error_dict(mon
->error
);
458 qdict_put_obj(qmp
, "id", mon
->mc
->id
);
462 monitor_json_emitter(mon
, QOBJECT(qmp
));
466 static void timestamp_put(QDict
*qdict
)
472 err
= qemu_gettimeofday(&tv
);
476 obj
= qobject_from_jsonf("{ 'seconds': %" PRId64
", "
477 "'microseconds': %" PRId64
" }",
478 (int64_t) tv
.tv_sec
, (int64_t) tv
.tv_usec
);
479 qdict_put_obj(qdict
, "timestamp", obj
);
483 static const char *monitor_event_names
[] = {
484 [QEVENT_SHUTDOWN
] = "SHUTDOWN",
485 [QEVENT_RESET
] = "RESET",
486 [QEVENT_POWERDOWN
] = "POWERDOWN",
487 [QEVENT_STOP
] = "STOP",
488 [QEVENT_RESUME
] = "RESUME",
489 [QEVENT_VNC_CONNECTED
] = "VNC_CONNECTED",
490 [QEVENT_VNC_INITIALIZED
] = "VNC_INITIALIZED",
491 [QEVENT_VNC_DISCONNECTED
] = "VNC_DISCONNECTED",
492 [QEVENT_BLOCK_IO_ERROR
] = "BLOCK_IO_ERROR",
493 [QEVENT_RTC_CHANGE
] = "RTC_CHANGE",
494 [QEVENT_WATCHDOG
] = "WATCHDOG",
495 [QEVENT_SPICE_CONNECTED
] = "SPICE_CONNECTED",
496 [QEVENT_SPICE_INITIALIZED
] = "SPICE_INITIALIZED",
497 [QEVENT_SPICE_DISCONNECTED
] = "SPICE_DISCONNECTED",
498 [QEVENT_BLOCK_JOB_COMPLETED
] = "BLOCK_JOB_COMPLETED",
499 [QEVENT_BLOCK_JOB_CANCELLED
] = "BLOCK_JOB_CANCELLED",
500 [QEVENT_BLOCK_JOB_ERROR
] = "BLOCK_JOB_ERROR",
501 [QEVENT_BLOCK_JOB_READY
] = "BLOCK_JOB_READY",
502 [QEVENT_DEVICE_DELETED
] = "DEVICE_DELETED",
503 [QEVENT_DEVICE_TRAY_MOVED
] = "DEVICE_TRAY_MOVED",
504 [QEVENT_NIC_RX_FILTER_CHANGED
] = "NIC_RX_FILTER_CHANGED",
505 [QEVENT_SUSPEND
] = "SUSPEND",
506 [QEVENT_SUSPEND_DISK
] = "SUSPEND_DISK",
507 [QEVENT_WAKEUP
] = "WAKEUP",
508 [QEVENT_BALLOON_CHANGE
] = "BALLOON_CHANGE",
509 [QEVENT_SPICE_MIGRATE_COMPLETED
] = "SPICE_MIGRATE_COMPLETED",
510 [QEVENT_GUEST_PANICKED
] = "GUEST_PANICKED",
511 [QEVENT_BLOCK_IMAGE_CORRUPTED
] = "BLOCK_IMAGE_CORRUPTED",
512 [QEVENT_QUORUM_FAILURE
] = "QUORUM_FAILURE",
513 [QEVENT_QUORUM_REPORT_BAD
] = "QUORUM_REPORT_BAD",
515 QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names
) != QEVENT_MAX
)
517 MonitorEventState monitor_event_state
[QEVENT_MAX
];
520 * Emits the event to every monitor instance
523 monitor_protocol_event_emit(MonitorEvent event
,
528 trace_monitor_protocol_event_emit(event
, data
);
529 QLIST_FOREACH(mon
, &mon_list
, entry
) {
530 if (monitor_ctrl_mode(mon
) && qmp_cmd_mode(mon
)) {
531 monitor_json_emitter(mon
, data
);
538 * Queue a new event for emission to Monitor instances,
539 * applying any rate limiting if required.
542 monitor_protocol_event_queue(MonitorEvent event
,
545 MonitorEventState
*evstate
;
546 int64_t now
= qemu_clock_get_ns(QEMU_CLOCK_REALTIME
);
547 assert(event
< QEVENT_MAX
);
549 evstate
= &(monitor_event_state
[event
]);
550 trace_monitor_protocol_event_queue(event
,
556 /* Rate limit of 0 indicates no throttling */
557 if (!evstate
->rate
) {
558 monitor_protocol_event_emit(event
, data
);
561 int64_t delta
= now
- evstate
->last
;
563 delta
< evstate
->rate
) {
564 /* If there's an existing event pending, replace
565 * it with the new event, otherwise schedule a
566 * timer for delayed emission
569 qobject_decref(evstate
->data
);
571 int64_t then
= evstate
->last
+ evstate
->rate
;
572 timer_mod_ns(evstate
->timer
, then
);
574 evstate
->data
= data
;
575 qobject_incref(evstate
->data
);
577 monitor_protocol_event_emit(event
, data
);
585 * The callback invoked by QemuTimer when a delayed
586 * event is ready to be emitted
588 static void monitor_protocol_event_handler(void *opaque
)
590 MonitorEventState
*evstate
= opaque
;
591 int64_t now
= qemu_clock_get_ns(QEMU_CLOCK_REALTIME
);
594 trace_monitor_protocol_event_handler(evstate
->event
,
599 monitor_protocol_event_emit(evstate
->event
, evstate
->data
);
600 qobject_decref(evstate
->data
);
601 evstate
->data
= NULL
;
608 * @event: the event ID to be limited
609 * @rate: the rate limit in milliseconds
611 * Sets a rate limit on a particular event, so no
612 * more than 1 event will be emitted within @rate
616 monitor_protocol_event_throttle(MonitorEvent event
,
619 MonitorEventState
*evstate
;
620 assert(event
< QEVENT_MAX
);
622 evstate
= &(monitor_event_state
[event
]);
624 trace_monitor_protocol_event_throttle(event
, rate
);
625 evstate
->event
= event
;
626 evstate
->rate
= rate
* SCALE_MS
;
627 evstate
->timer
= timer_new(QEMU_CLOCK_REALTIME
,
629 monitor_protocol_event_handler
,
632 evstate
->data
= NULL
;
636 /* Global, one-time initializer to configure the rate limiting
637 * and initialize state */
638 static void monitor_protocol_event_init(void)
640 /* Limit RTC & BALLOON events to 1 per second */
641 monitor_protocol_event_throttle(QEVENT_RTC_CHANGE
, 1000);
642 monitor_protocol_event_throttle(QEVENT_BALLOON_CHANGE
, 1000);
643 monitor_protocol_event_throttle(QEVENT_WATCHDOG
, 1000);
644 /* limit the rate of quorum events to avoid hammering the management */
645 monitor_protocol_event_throttle(QEVENT_QUORUM_REPORT_BAD
, 1000);
646 monitor_protocol_event_throttle(QEVENT_QUORUM_FAILURE
, 1000);
650 * monitor_protocol_event(): Generate a Monitor event
652 * Event-specific data can be emitted through the (optional) 'data' parameter.
654 void monitor_protocol_event(MonitorEvent event
, QObject
*data
)
657 const char *event_name
;
659 assert(event
< QEVENT_MAX
);
661 event_name
= monitor_event_names
[event
];
662 assert(event_name
!= NULL
);
666 qdict_put(qmp
, "event", qstring_from_str(event_name
));
668 qobject_incref(data
);
669 qdict_put_obj(qmp
, "data", data
);
672 trace_monitor_protocol_event(event
, event_name
, qmp
);
673 monitor_protocol_event_queue(event
, QOBJECT(qmp
));
677 static int do_qmp_capabilities(Monitor
*mon
, const QDict
*params
,
680 /* Will setup QMP capabilities in the future */
681 if (monitor_ctrl_mode(mon
)) {
682 mon
->mc
->command_mode
= 1;
688 static void handle_user_command(Monitor
*mon
, const char *cmdline
);
690 static void monitor_data_init(Monitor
*mon
)
692 memset(mon
, 0, sizeof(Monitor
));
693 mon
->outbuf
= qstring_new();
694 /* Use *mon_cmds by default. */
695 mon
->cmd_table
= mon_cmds
;
698 static void monitor_data_destroy(Monitor
*mon
)
700 QDECREF(mon
->outbuf
);
703 char *qmp_human_monitor_command(const char *command_line
, bool has_cpu_index
,
704 int64_t cpu_index
, Error
**errp
)
707 Monitor
*old_mon
, hmp
;
709 monitor_data_init(&hmp
);
710 hmp
.skip_flush
= true;
716 int ret
= monitor_set_cpu(cpu_index
);
719 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, "cpu-index",
725 handle_user_command(&hmp
, command_line
);
728 if (qstring_get_length(hmp
.outbuf
) > 0) {
729 output
= g_strdup(qstring_get_str(hmp
.outbuf
));
731 output
= g_strdup("");
735 monitor_data_destroy(&hmp
);
739 static int compare_cmd(const char *name
, const char *list
)
741 const char *p
, *pstart
;
749 p
= pstart
+ strlen(pstart
);
750 if ((p
- pstart
) == len
&& !memcmp(pstart
, name
, len
))
759 static int get_str(char *buf
, int buf_size
, const char **pp
)
767 while (qemu_isspace(*p
)) {
778 while (*p
!= '\0' && *p
!= '\"') {
794 qemu_printf("unsupported escape code: '\\%c'\n", c
);
797 if ((q
- buf
) < buf_size
- 1) {
801 if ((q
- buf
) < buf_size
- 1) {
808 qemu_printf("unterminated string\n");
813 while (*p
!= '\0' && !qemu_isspace(*p
)) {
814 if ((q
- buf
) < buf_size
- 1) {
827 static void free_cmdline_args(char **args
, int nb_args
)
831 assert(nb_args
<= MAX_ARGS
);
833 for (i
= 0; i
< nb_args
; i
++) {
840 * Parse the command line to get valid args.
841 * @cmdline: command line to be parsed.
842 * @pnb_args: location to store the number of args, must NOT be NULL.
843 * @args: location to store the args, which should be freed by caller, must
846 * Returns 0 on success, negative on failure.
848 * NOTE: this parser is an approximate form of the real command parser. Number
849 * of args have a limit of MAX_ARGS. If cmdline contains more, it will
850 * return with failure.
852 static int parse_cmdline(const char *cmdline
,
853 int *pnb_args
, char **args
)
862 while (qemu_isspace(*p
)) {
868 if (nb_args
>= MAX_ARGS
) {
871 ret
= get_str(buf
, sizeof(buf
), &p
);
875 args
[nb_args
] = g_strdup(buf
);
882 free_cmdline_args(args
, nb_args
);
886 static void help_cmd_dump_one(Monitor
*mon
,
887 const mon_cmd_t
*cmd
,
893 for (i
= 0; i
< prefix_args_nb
; i
++) {
894 monitor_printf(mon
, "%s ", prefix_args
[i
]);
896 monitor_printf(mon
, "%s %s -- %s\n", cmd
->name
, cmd
->params
, cmd
->help
);
899 /* @args[@arg_index] is the valid command need to find in @cmds */
900 static void help_cmd_dump(Monitor
*mon
, const mon_cmd_t
*cmds
,
901 char **args
, int nb_args
, int arg_index
)
903 const mon_cmd_t
*cmd
;
905 /* No valid arg need to compare with, dump all in *cmds */
906 if (arg_index
>= nb_args
) {
907 for (cmd
= cmds
; cmd
->name
!= NULL
; cmd
++) {
908 help_cmd_dump_one(mon
, cmd
, args
, arg_index
);
913 /* Find one entry to dump */
914 for (cmd
= cmds
; cmd
->name
!= NULL
; cmd
++) {
915 if (compare_cmd(args
[arg_index
], cmd
->name
)) {
916 if (cmd
->sub_table
) {
917 /* continue with next arg */
918 help_cmd_dump(mon
, cmd
->sub_table
,
919 args
, nb_args
, arg_index
+ 1);
921 help_cmd_dump_one(mon
, cmd
, args
, arg_index
);
928 static void help_cmd(Monitor
*mon
, const char *name
)
930 char *args
[MAX_ARGS
];
933 /* 1. parse user input */
935 /* special case for log, directly dump and return */
936 if (!strcmp(name
, "log")) {
937 const QEMULogItem
*item
;
938 monitor_printf(mon
, "Log items (comma separated):\n");
939 monitor_printf(mon
, "%-10s %s\n", "none", "remove all logs");
940 for (item
= qemu_log_items
; item
->mask
!= 0; item
++) {
941 monitor_printf(mon
, "%-10s %s\n", item
->name
, item
->help
);
946 if (parse_cmdline(name
, &nb_args
, args
) < 0) {
951 /* 2. dump the contents according to parsed args */
952 help_cmd_dump(mon
, mon
->cmd_table
, args
, nb_args
, 0);
954 free_cmdline_args(args
, nb_args
);
957 static void do_help_cmd(Monitor
*mon
, const QDict
*qdict
)
959 help_cmd(mon
, qdict_get_try_str(qdict
, "name"));
962 static void do_trace_event_set_state(Monitor
*mon
, const QDict
*qdict
)
964 const char *tp_name
= qdict_get_str(qdict
, "name");
965 bool new_state
= qdict_get_bool(qdict
, "option");
968 TraceEvent
*ev
= NULL
;
969 while ((ev
= trace_event_pattern(tp_name
, ev
)) != NULL
) {
971 if (!trace_event_get_state_static(ev
)) {
972 monitor_printf(mon
, "event \"%s\" is not traceable\n", tp_name
);
974 trace_event_set_state_dynamic(ev
, new_state
);
977 if (!trace_event_is_pattern(tp_name
) && !found
) {
978 monitor_printf(mon
, "unknown event name \"%s\"\n", tp_name
);
982 #ifdef CONFIG_TRACE_SIMPLE
983 static void do_trace_file(Monitor
*mon
, const QDict
*qdict
)
985 const char *op
= qdict_get_try_str(qdict
, "op");
986 const char *arg
= qdict_get_try_str(qdict
, "arg");
989 st_print_trace_file_status((FILE *)mon
, &monitor_fprintf
);
990 } else if (!strcmp(op
, "on")) {
991 st_set_trace_file_enabled(true);
992 } else if (!strcmp(op
, "off")) {
993 st_set_trace_file_enabled(false);
994 } else if (!strcmp(op
, "flush")) {
995 st_flush_trace_buffer();
996 } else if (!strcmp(op
, "set")) {
998 st_set_trace_file(arg
);
1001 monitor_printf(mon
, "unexpected argument \"%s\"\n", op
);
1002 help_cmd(mon
, "trace-file");
1007 static void user_monitor_complete(void *opaque
, QObject
*ret_data
)
1009 MonitorCompletionData
*data
= (MonitorCompletionData
*)opaque
;
1012 data
->user_print(data
->mon
, ret_data
);
1014 monitor_resume(data
->mon
);
1018 static void qmp_monitor_complete(void *opaque
, QObject
*ret_data
)
1020 monitor_protocol_emitter(opaque
, ret_data
);
1023 static int qmp_async_cmd_handler(Monitor
*mon
, const mon_cmd_t
*cmd
,
1024 const QDict
*params
)
1026 return cmd
->mhandler
.cmd_async(mon
, params
, qmp_monitor_complete
, mon
);
1029 static void user_async_cmd_handler(Monitor
*mon
, const mon_cmd_t
*cmd
,
1030 const QDict
*params
)
1034 MonitorCompletionData
*cb_data
= g_malloc(sizeof(*cb_data
));
1036 cb_data
->user_print
= cmd
->user_print
;
1037 monitor_suspend(mon
);
1038 ret
= cmd
->mhandler
.cmd_async(mon
, params
,
1039 user_monitor_complete
, cb_data
);
1041 monitor_resume(mon
);
1046 static void do_info_help(Monitor
*mon
, const QDict
*qdict
)
1048 help_cmd(mon
, "info");
1051 CommandInfoList
*qmp_query_commands(Error
**errp
)
1053 CommandInfoList
*info
, *cmd_list
= NULL
;
1054 const mon_cmd_t
*cmd
;
1056 for (cmd
= qmp_cmds
; cmd
->name
!= NULL
; cmd
++) {
1057 info
= g_malloc0(sizeof(*info
));
1058 info
->value
= g_malloc0(sizeof(*info
->value
));
1059 info
->value
->name
= g_strdup(cmd
->name
);
1061 info
->next
= cmd_list
;
1068 EventInfoList
*qmp_query_events(Error
**errp
)
1070 EventInfoList
*info
, *ev_list
= NULL
;
1073 for (e
= 0 ; e
< QEVENT_MAX
; e
++) {
1074 const char *event_name
= monitor_event_names
[e
];
1075 assert(event_name
!= NULL
);
1076 info
= g_malloc0(sizeof(*info
));
1077 info
->value
= g_malloc0(sizeof(*info
->value
));
1078 info
->value
->name
= g_strdup(event_name
);
1080 info
->next
= ev_list
;
1087 /* set the current CPU defined by the user */
1088 int monitor_set_cpu(int cpu_index
)
1092 cpu
= qemu_get_cpu(cpu_index
);
1096 cur_mon
->mon_cpu
= cpu
;
1100 static CPUArchState
*mon_get_cpu(void)
1102 if (!cur_mon
->mon_cpu
) {
1105 cpu_synchronize_state(cur_mon
->mon_cpu
);
1106 return cur_mon
->mon_cpu
->env_ptr
;
1109 int monitor_get_cpu_index(void)
1111 CPUState
*cpu
= ENV_GET_CPU(mon_get_cpu());
1112 return cpu
->cpu_index
;
1115 static void do_info_registers(Monitor
*mon
, const QDict
*qdict
)
1119 env
= mon_get_cpu();
1120 cpu
= ENV_GET_CPU(env
);
1121 cpu_dump_state(cpu
, (FILE *)mon
, monitor_fprintf
, CPU_DUMP_FPU
);
1124 static void do_info_jit(Monitor
*mon
, const QDict
*qdict
)
1126 dump_exec_info((FILE *)mon
, monitor_fprintf
);
1129 static void do_info_history(Monitor
*mon
, const QDict
*qdict
)
1138 str
= readline_get_history(mon
->rs
, i
);
1141 monitor_printf(mon
, "%d: '%s'\n", i
, str
);
1146 static void do_info_cpu_stats(Monitor
*mon
, const QDict
*qdict
)
1151 env
= mon_get_cpu();
1152 cpu
= ENV_GET_CPU(env
);
1153 cpu_dump_statistics(cpu
, (FILE *)mon
, &monitor_fprintf
, 0);
1156 static void do_trace_print_events(Monitor
*mon
, const QDict
*qdict
)
1158 trace_print_events((FILE *)mon
, &monitor_fprintf
);
1161 static int client_migrate_info(Monitor
*mon
, const QDict
*qdict
,
1162 MonitorCompletion cb
, void *opaque
)
1164 const char *protocol
= qdict_get_str(qdict
, "protocol");
1165 const char *hostname
= qdict_get_str(qdict
, "hostname");
1166 const char *subject
= qdict_get_try_str(qdict
, "cert-subject");
1167 int port
= qdict_get_try_int(qdict
, "port", -1);
1168 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1171 if (strcmp(protocol
, "spice") == 0) {
1173 qerror_report(QERR_DEVICE_NOT_ACTIVE
, "spice");
1177 if (port
== -1 && tls_port
== -1) {
1178 qerror_report(QERR_MISSING_PARAMETER
, "port/tls-port");
1182 ret
= qemu_spice_migrate_info(hostname
, port
, tls_port
, subject
,
1185 qerror_report(QERR_UNDEFINED_ERROR
);
1191 qerror_report(QERR_INVALID_PARAMETER
, "protocol");
1195 static void do_logfile(Monitor
*mon
, const QDict
*qdict
)
1197 qemu_set_log_filename(qdict_get_str(qdict
, "filename"));
1200 static void do_log(Monitor
*mon
, const QDict
*qdict
)
1203 const char *items
= qdict_get_str(qdict
, "items");
1205 if (!strcmp(items
, "none")) {
1208 mask
= qemu_str_to_log_mask(items
);
1210 help_cmd(mon
, "log");
1217 static void do_singlestep(Monitor
*mon
, const QDict
*qdict
)
1219 const char *option
= qdict_get_try_str(qdict
, "option");
1220 if (!option
|| !strcmp(option
, "on")) {
1222 } else if (!strcmp(option
, "off")) {
1225 monitor_printf(mon
, "unexpected option %s\n", option
);
1229 static void do_gdbserver(Monitor
*mon
, const QDict
*qdict
)
1231 const char *device
= qdict_get_try_str(qdict
, "device");
1233 device
= "tcp::" DEFAULT_GDBSTUB_PORT
;
1234 if (gdbserver_start(device
) < 0) {
1235 monitor_printf(mon
, "Could not open gdbserver on device '%s'\n",
1237 } else if (strcmp(device
, "none") == 0) {
1238 monitor_printf(mon
, "Disabled gdbserver\n");
1240 monitor_printf(mon
, "Waiting for gdb connection on device '%s'\n",
1245 static void do_watchdog_action(Monitor
*mon
, const QDict
*qdict
)
1247 const char *action
= qdict_get_str(qdict
, "action");
1248 if (select_watchdog_action(action
) == -1) {
1249 monitor_printf(mon
, "Unknown watchdog action '%s'\n", action
);
1253 static void monitor_printc(Monitor
*mon
, int c
)
1255 monitor_printf(mon
, "'");
1258 monitor_printf(mon
, "\\'");
1261 monitor_printf(mon
, "\\\\");
1264 monitor_printf(mon
, "\\n");
1267 monitor_printf(mon
, "\\r");
1270 if (c
>= 32 && c
<= 126) {
1271 monitor_printf(mon
, "%c", c
);
1273 monitor_printf(mon
, "\\x%02x", c
);
1277 monitor_printf(mon
, "'");
1280 static void memory_dump(Monitor
*mon
, int count
, int format
, int wsize
,
1281 hwaddr addr
, int is_physical
)
1284 int l
, line_size
, i
, max_digits
, len
;
1288 if (format
== 'i') {
1291 env
= mon_get_cpu();
1295 } else if (wsize
== 4) {
1298 /* as default we use the current CS size */
1301 #ifdef TARGET_X86_64
1302 if ((env
->efer
& MSR_EFER_LMA
) &&
1303 (env
->segs
[R_CS
].flags
& DESC_L_MASK
))
1307 if (!(env
->segs
[R_CS
].flags
& DESC_B_MASK
))
1312 monitor_disas(mon
, env
, addr
, count
, is_physical
, flags
);
1316 len
= wsize
* count
;
1325 max_digits
= (wsize
* 8 + 2) / 3;
1329 max_digits
= (wsize
* 8) / 4;
1333 max_digits
= (wsize
* 8 * 10 + 32) / 33;
1342 monitor_printf(mon
, TARGET_FMT_plx
":", addr
);
1344 monitor_printf(mon
, TARGET_FMT_lx
":", (target_ulong
)addr
);
1349 cpu_physical_memory_read(addr
, buf
, l
);
1351 env
= mon_get_cpu();
1352 if (cpu_memory_rw_debug(ENV_GET_CPU(env
), addr
, buf
, l
, 0) < 0) {
1353 monitor_printf(mon
, " Cannot access memory\n");
1362 v
= ldub_raw(buf
+ i
);
1365 v
= lduw_raw(buf
+ i
);
1368 v
= (uint32_t)ldl_raw(buf
+ i
);
1371 v
= ldq_raw(buf
+ i
);
1374 monitor_printf(mon
, " ");
1377 monitor_printf(mon
, "%#*" PRIo64
, max_digits
, v
);
1380 monitor_printf(mon
, "0x%0*" PRIx64
, max_digits
, v
);
1383 monitor_printf(mon
, "%*" PRIu64
, max_digits
, v
);
1386 monitor_printf(mon
, "%*" PRId64
, max_digits
, v
);
1389 monitor_printc(mon
, v
);
1394 monitor_printf(mon
, "\n");
1400 static void do_memory_dump(Monitor
*mon
, const QDict
*qdict
)
1402 int count
= qdict_get_int(qdict
, "count");
1403 int format
= qdict_get_int(qdict
, "format");
1404 int size
= qdict_get_int(qdict
, "size");
1405 target_long addr
= qdict_get_int(qdict
, "addr");
1407 memory_dump(mon
, count
, format
, size
, addr
, 0);
1410 static void do_physical_memory_dump(Monitor
*mon
, const QDict
*qdict
)
1412 int count
= qdict_get_int(qdict
, "count");
1413 int format
= qdict_get_int(qdict
, "format");
1414 int size
= qdict_get_int(qdict
, "size");
1415 hwaddr addr
= qdict_get_int(qdict
, "addr");
1417 memory_dump(mon
, count
, format
, size
, addr
, 1);
1420 static void do_print(Monitor
*mon
, const QDict
*qdict
)
1422 int format
= qdict_get_int(qdict
, "format");
1423 hwaddr val
= qdict_get_int(qdict
, "val");
1427 monitor_printf(mon
, "%#" HWADDR_PRIo
, val
);
1430 monitor_printf(mon
, "%#" HWADDR_PRIx
, val
);
1433 monitor_printf(mon
, "%" HWADDR_PRIu
, val
);
1437 monitor_printf(mon
, "%" HWADDR_PRId
, val
);
1440 monitor_printc(mon
, val
);
1443 monitor_printf(mon
, "\n");
1446 static void do_sum(Monitor
*mon
, const QDict
*qdict
)
1450 uint32_t start
= qdict_get_int(qdict
, "start");
1451 uint32_t size
= qdict_get_int(qdict
, "size");
1454 for(addr
= start
; addr
< (start
+ size
); addr
++) {
1455 uint8_t val
= ldub_phys(&address_space_memory
, addr
);
1456 /* BSD sum algorithm ('sum' Unix command) */
1457 sum
= (sum
>> 1) | (sum
<< 15);
1460 monitor_printf(mon
, "%05d\n", sum
);
1463 static int mouse_button_state
;
1465 static void do_mouse_move(Monitor
*mon
, const QDict
*qdict
)
1467 int dx
, dy
, dz
, button
;
1468 const char *dx_str
= qdict_get_str(qdict
, "dx_str");
1469 const char *dy_str
= qdict_get_str(qdict
, "dy_str");
1470 const char *dz_str
= qdict_get_try_str(qdict
, "dz_str");
1472 dx
= strtol(dx_str
, NULL
, 0);
1473 dy
= strtol(dy_str
, NULL
, 0);
1474 qemu_input_queue_rel(NULL
, INPUT_AXIS_X
, dx
);
1475 qemu_input_queue_rel(NULL
, INPUT_AXIS_Y
, dy
);
1478 dz
= strtol(dz_str
, NULL
, 0);
1480 button
= (dz
> 0) ? INPUT_BUTTON_WHEEL_UP
: INPUT_BUTTON_WHEEL_DOWN
;
1481 qemu_input_queue_btn(NULL
, button
, true);
1482 qemu_input_event_sync();
1483 qemu_input_queue_btn(NULL
, button
, false);
1486 qemu_input_event_sync();
1489 static void do_mouse_button(Monitor
*mon
, const QDict
*qdict
)
1491 static uint32_t bmap
[INPUT_BUTTON_MAX
] = {
1492 [INPUT_BUTTON_LEFT
] = MOUSE_EVENT_LBUTTON
,
1493 [INPUT_BUTTON_MIDDLE
] = MOUSE_EVENT_MBUTTON
,
1494 [INPUT_BUTTON_RIGHT
] = MOUSE_EVENT_RBUTTON
,
1496 int button_state
= qdict_get_int(qdict
, "button_state");
1498 if (mouse_button_state
== button_state
) {
1501 qemu_input_update_buttons(NULL
, bmap
, mouse_button_state
, button_state
);
1502 qemu_input_event_sync();
1503 mouse_button_state
= button_state
;
1506 static void do_ioport_read(Monitor
*mon
, const QDict
*qdict
)
1508 int size
= qdict_get_int(qdict
, "size");
1509 int addr
= qdict_get_int(qdict
, "addr");
1510 int has_index
= qdict_haskey(qdict
, "index");
1515 int index
= qdict_get_int(qdict
, "index");
1516 cpu_outb(addr
& IOPORTS_MASK
, index
& 0xff);
1524 val
= cpu_inb(addr
);
1528 val
= cpu_inw(addr
);
1532 val
= cpu_inl(addr
);
1536 monitor_printf(mon
, "port%c[0x%04x] = %#0*x\n",
1537 suffix
, addr
, size
* 2, val
);
1540 static void do_ioport_write(Monitor
*mon
, const QDict
*qdict
)
1542 int size
= qdict_get_int(qdict
, "size");
1543 int addr
= qdict_get_int(qdict
, "addr");
1544 int val
= qdict_get_int(qdict
, "val");
1546 addr
&= IOPORTS_MASK
;
1551 cpu_outb(addr
, val
);
1554 cpu_outw(addr
, val
);
1557 cpu_outl(addr
, val
);
1562 static void do_boot_set(Monitor
*mon
, const QDict
*qdict
)
1565 const char *bootdevice
= qdict_get_str(qdict
, "bootdevice");
1567 res
= qemu_boot_set(bootdevice
);
1569 monitor_printf(mon
, "boot device list now set to %s\n", bootdevice
);
1570 } else if (res
> 0) {
1571 monitor_printf(mon
, "setting boot device list failed\n");
1573 monitor_printf(mon
, "no function defined to set boot device list for "
1574 "this architecture\n");
1578 #if defined(TARGET_I386)
1579 static void print_pte(Monitor
*mon
, hwaddr addr
,
1583 #ifdef TARGET_X86_64
1584 if (addr
& (1ULL << 47)) {
1588 monitor_printf(mon
, TARGET_FMT_plx
": " TARGET_FMT_plx
1589 " %c%c%c%c%c%c%c%c%c\n",
1592 pte
& PG_NX_MASK ?
'X' : '-',
1593 pte
& PG_GLOBAL_MASK ?
'G' : '-',
1594 pte
& PG_PSE_MASK ?
'P' : '-',
1595 pte
& PG_DIRTY_MASK ?
'D' : '-',
1596 pte
& PG_ACCESSED_MASK ?
'A' : '-',
1597 pte
& PG_PCD_MASK ?
'C' : '-',
1598 pte
& PG_PWT_MASK ?
'T' : '-',
1599 pte
& PG_USER_MASK ?
'U' : '-',
1600 pte
& PG_RW_MASK ?
'W' : '-');
1603 static void tlb_info_32(Monitor
*mon
, CPUArchState
*env
)
1605 unsigned int l1
, l2
;
1606 uint32_t pgd
, pde
, pte
;
1608 pgd
= env
->cr
[3] & ~0xfff;
1609 for(l1
= 0; l1
< 1024; l1
++) {
1610 cpu_physical_memory_read(pgd
+ l1
* 4, &pde
, 4);
1611 pde
= le32_to_cpu(pde
);
1612 if (pde
& PG_PRESENT_MASK
) {
1613 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1615 print_pte(mon
, (l1
<< 22), pde
, ~((1 << 21) - 1));
1617 for(l2
= 0; l2
< 1024; l2
++) {
1618 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4, &pte
, 4);
1619 pte
= le32_to_cpu(pte
);
1620 if (pte
& PG_PRESENT_MASK
) {
1621 print_pte(mon
, (l1
<< 22) + (l2
<< 12),
1631 static void tlb_info_pae32(Monitor
*mon
, CPUArchState
*env
)
1633 unsigned int l1
, l2
, l3
;
1634 uint64_t pdpe
, pde
, pte
;
1635 uint64_t pdp_addr
, pd_addr
, pt_addr
;
1637 pdp_addr
= env
->cr
[3] & ~0x1f;
1638 for (l1
= 0; l1
< 4; l1
++) {
1639 cpu_physical_memory_read(pdp_addr
+ l1
* 8, &pdpe
, 8);
1640 pdpe
= le64_to_cpu(pdpe
);
1641 if (pdpe
& PG_PRESENT_MASK
) {
1642 pd_addr
= pdpe
& 0x3fffffffff000ULL
;
1643 for (l2
= 0; l2
< 512; l2
++) {
1644 cpu_physical_memory_read(pd_addr
+ l2
* 8, &pde
, 8);
1645 pde
= le64_to_cpu(pde
);
1646 if (pde
& PG_PRESENT_MASK
) {
1647 if (pde
& PG_PSE_MASK
) {
1648 /* 2M pages with PAE, CR4.PSE is ignored */
1649 print_pte(mon
, (l1
<< 30 ) + (l2
<< 21), pde
,
1650 ~((hwaddr
)(1 << 20) - 1));
1652 pt_addr
= pde
& 0x3fffffffff000ULL
;
1653 for (l3
= 0; l3
< 512; l3
++) {
1654 cpu_physical_memory_read(pt_addr
+ l3
* 8, &pte
, 8);
1655 pte
= le64_to_cpu(pte
);
1656 if (pte
& PG_PRESENT_MASK
) {
1657 print_pte(mon
, (l1
<< 30 ) + (l2
<< 21)
1670 #ifdef TARGET_X86_64
1671 static void tlb_info_64(Monitor
*mon
, CPUArchState
*env
)
1673 uint64_t l1
, l2
, l3
, l4
;
1674 uint64_t pml4e
, pdpe
, pde
, pte
;
1675 uint64_t pml4_addr
, pdp_addr
, pd_addr
, pt_addr
;
1677 pml4_addr
= env
->cr
[3] & 0x3fffffffff000ULL
;
1678 for (l1
= 0; l1
< 512; l1
++) {
1679 cpu_physical_memory_read(pml4_addr
+ l1
* 8, &pml4e
, 8);
1680 pml4e
= le64_to_cpu(pml4e
);
1681 if (pml4e
& PG_PRESENT_MASK
) {
1682 pdp_addr
= pml4e
& 0x3fffffffff000ULL
;
1683 for (l2
= 0; l2
< 512; l2
++) {
1684 cpu_physical_memory_read(pdp_addr
+ l2
* 8, &pdpe
, 8);
1685 pdpe
= le64_to_cpu(pdpe
);
1686 if (pdpe
& PG_PRESENT_MASK
) {
1687 if (pdpe
& PG_PSE_MASK
) {
1688 /* 1G pages, CR4.PSE is ignored */
1689 print_pte(mon
, (l1
<< 39) + (l2
<< 30), pdpe
,
1690 0x3ffffc0000000ULL
);
1692 pd_addr
= pdpe
& 0x3fffffffff000ULL
;
1693 for (l3
= 0; l3
< 512; l3
++) {
1694 cpu_physical_memory_read(pd_addr
+ l3
* 8, &pde
, 8);
1695 pde
= le64_to_cpu(pde
);
1696 if (pde
& PG_PRESENT_MASK
) {
1697 if (pde
& PG_PSE_MASK
) {
1698 /* 2M pages, CR4.PSE is ignored */
1699 print_pte(mon
, (l1
<< 39) + (l2
<< 30) +
1701 0x3ffffffe00000ULL
);
1703 pt_addr
= pde
& 0x3fffffffff000ULL
;
1704 for (l4
= 0; l4
< 512; l4
++) {
1705 cpu_physical_memory_read(pt_addr
1708 pte
= le64_to_cpu(pte
);
1709 if (pte
& PG_PRESENT_MASK
) {
1710 print_pte(mon
, (l1
<< 39) +
1712 (l3
<< 21) + (l4
<< 12),
1714 0x3fffffffff000ULL
);
1728 static void tlb_info(Monitor
*mon
, const QDict
*qdict
)
1732 env
= mon_get_cpu();
1734 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1735 monitor_printf(mon
, "PG disabled\n");
1738 if (env
->cr
[4] & CR4_PAE_MASK
) {
1739 #ifdef TARGET_X86_64
1740 if (env
->hflags
& HF_LMA_MASK
) {
1741 tlb_info_64(mon
, env
);
1745 tlb_info_pae32(mon
, env
);
1748 tlb_info_32(mon
, env
);
1752 static void mem_print(Monitor
*mon
, hwaddr
*pstart
,
1754 hwaddr end
, int prot
)
1757 prot1
= *plast_prot
;
1758 if (prot
!= prot1
) {
1759 if (*pstart
!= -1) {
1760 monitor_printf(mon
, TARGET_FMT_plx
"-" TARGET_FMT_plx
" "
1761 TARGET_FMT_plx
" %c%c%c\n",
1762 *pstart
, end
, end
- *pstart
,
1763 prot1
& PG_USER_MASK ?
'u' : '-',
1765 prot1
& PG_RW_MASK ?
'w' : '-');
1775 static void mem_info_32(Monitor
*mon
, CPUArchState
*env
)
1777 unsigned int l1
, l2
;
1778 int prot
, last_prot
;
1779 uint32_t pgd
, pde
, pte
;
1782 pgd
= env
->cr
[3] & ~0xfff;
1785 for(l1
= 0; l1
< 1024; l1
++) {
1786 cpu_physical_memory_read(pgd
+ l1
* 4, &pde
, 4);
1787 pde
= le32_to_cpu(pde
);
1789 if (pde
& PG_PRESENT_MASK
) {
1790 if ((pde
& PG_PSE_MASK
) && (env
->cr
[4] & CR4_PSE_MASK
)) {
1791 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1792 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1794 for(l2
= 0; l2
< 1024; l2
++) {
1795 cpu_physical_memory_read((pde
& ~0xfff) + l2
* 4, &pte
, 4);
1796 pte
= le32_to_cpu(pte
);
1797 end
= (l1
<< 22) + (l2
<< 12);
1798 if (pte
& PG_PRESENT_MASK
) {
1800 (PG_USER_MASK
| PG_RW_MASK
| PG_PRESENT_MASK
);
1804 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1809 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1812 /* Flush last range */
1813 mem_print(mon
, &start
, &last_prot
, (hwaddr
)1 << 32, 0);
1816 static void mem_info_pae32(Monitor
*mon
, CPUArchState
*env
)
1818 unsigned int l1
, l2
, l3
;
1819 int prot
, last_prot
;
1820 uint64_t pdpe
, pde
, pte
;
1821 uint64_t pdp_addr
, pd_addr
, pt_addr
;
1824 pdp_addr
= env
->cr
[3] & ~0x1f;
1827 for (l1
= 0; l1
< 4; l1
++) {
1828 cpu_physical_memory_read(pdp_addr
+ l1
* 8, &pdpe
, 8);
1829 pdpe
= le64_to_cpu(pdpe
);
1831 if (pdpe
& PG_PRESENT_MASK
) {
1832 pd_addr
= pdpe
& 0x3fffffffff000ULL
;
1833 for (l2
= 0; l2
< 512; l2
++) {
1834 cpu_physical_memory_read(pd_addr
+ l2
* 8, &pde
, 8);
1835 pde
= le64_to_cpu(pde
);
1836 end
= (l1
<< 30) + (l2
<< 21);
1837 if (pde
& PG_PRESENT_MASK
) {
1838 if (pde
& PG_PSE_MASK
) {
1839 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
|
1841 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1843 pt_addr
= pde
& 0x3fffffffff000ULL
;
1844 for (l3
= 0; l3
< 512; l3
++) {
1845 cpu_physical_memory_read(pt_addr
+ l3
* 8, &pte
, 8);
1846 pte
= le64_to_cpu(pte
);
1847 end
= (l1
<< 30) + (l2
<< 21) + (l3
<< 12);
1848 if (pte
& PG_PRESENT_MASK
) {
1849 prot
= pte
& pde
& (PG_USER_MASK
| PG_RW_MASK
|
1854 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1859 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1864 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1867 /* Flush last range */
1868 mem_print(mon
, &start
, &last_prot
, (hwaddr
)1 << 32, 0);
1872 #ifdef TARGET_X86_64
1873 static void mem_info_64(Monitor
*mon
, CPUArchState
*env
)
1875 int prot
, last_prot
;
1876 uint64_t l1
, l2
, l3
, l4
;
1877 uint64_t pml4e
, pdpe
, pde
, pte
;
1878 uint64_t pml4_addr
, pdp_addr
, pd_addr
, pt_addr
, start
, end
;
1880 pml4_addr
= env
->cr
[3] & 0x3fffffffff000ULL
;
1883 for (l1
= 0; l1
< 512; l1
++) {
1884 cpu_physical_memory_read(pml4_addr
+ l1
* 8, &pml4e
, 8);
1885 pml4e
= le64_to_cpu(pml4e
);
1887 if (pml4e
& PG_PRESENT_MASK
) {
1888 pdp_addr
= pml4e
& 0x3fffffffff000ULL
;
1889 for (l2
= 0; l2
< 512; l2
++) {
1890 cpu_physical_memory_read(pdp_addr
+ l2
* 8, &pdpe
, 8);
1891 pdpe
= le64_to_cpu(pdpe
);
1892 end
= (l1
<< 39) + (l2
<< 30);
1893 if (pdpe
& PG_PRESENT_MASK
) {
1894 if (pdpe
& PG_PSE_MASK
) {
1895 prot
= pdpe
& (PG_USER_MASK
| PG_RW_MASK
|
1898 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1900 pd_addr
= pdpe
& 0x3fffffffff000ULL
;
1901 for (l3
= 0; l3
< 512; l3
++) {
1902 cpu_physical_memory_read(pd_addr
+ l3
* 8, &pde
, 8);
1903 pde
= le64_to_cpu(pde
);
1904 end
= (l1
<< 39) + (l2
<< 30) + (l3
<< 21);
1905 if (pde
& PG_PRESENT_MASK
) {
1906 if (pde
& PG_PSE_MASK
) {
1907 prot
= pde
& (PG_USER_MASK
| PG_RW_MASK
|
1909 prot
&= pml4e
& pdpe
;
1910 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1912 pt_addr
= pde
& 0x3fffffffff000ULL
;
1913 for (l4
= 0; l4
< 512; l4
++) {
1914 cpu_physical_memory_read(pt_addr
1917 pte
= le64_to_cpu(pte
);
1918 end
= (l1
<< 39) + (l2
<< 30) +
1919 (l3
<< 21) + (l4
<< 12);
1920 if (pte
& PG_PRESENT_MASK
) {
1921 prot
= pte
& (PG_USER_MASK
| PG_RW_MASK
|
1923 prot
&= pml4e
& pdpe
& pde
;
1927 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1932 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1938 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1943 mem_print(mon
, &start
, &last_prot
, end
, prot
);
1946 /* Flush last range */
1947 mem_print(mon
, &start
, &last_prot
, (hwaddr
)1 << 48, 0);
1951 static void mem_info(Monitor
*mon
, const QDict
*qdict
)
1955 env
= mon_get_cpu();
1957 if (!(env
->cr
[0] & CR0_PG_MASK
)) {
1958 monitor_printf(mon
, "PG disabled\n");
1961 if (env
->cr
[4] & CR4_PAE_MASK
) {
1962 #ifdef TARGET_X86_64
1963 if (env
->hflags
& HF_LMA_MASK
) {
1964 mem_info_64(mon
, env
);
1968 mem_info_pae32(mon
, env
);
1971 mem_info_32(mon
, env
);
1976 #if defined(TARGET_SH4)
1978 static void print_tlb(Monitor
*mon
, int idx
, tlb_t
*tlb
)
1980 monitor_printf(mon
, " tlb%i:\t"
1981 "asid=%hhu vpn=%x\tppn=%x\tsz=%hhu size=%u\t"
1982 "v=%hhu shared=%hhu cached=%hhu prot=%hhu "
1983 "dirty=%hhu writethrough=%hhu\n",
1985 tlb
->asid
, tlb
->vpn
, tlb
->ppn
, tlb
->sz
, tlb
->size
,
1986 tlb
->v
, tlb
->sh
, tlb
->c
, tlb
->pr
,
1990 static void tlb_info(Monitor
*mon
, const QDict
*qdict
)
1992 CPUArchState
*env
= mon_get_cpu();
1995 monitor_printf (mon
, "ITLB:\n");
1996 for (i
= 0 ; i
< ITLB_SIZE
; i
++)
1997 print_tlb (mon
, i
, &env
->itlb
[i
]);
1998 monitor_printf (mon
, "UTLB:\n");
1999 for (i
= 0 ; i
< UTLB_SIZE
; i
++)
2000 print_tlb (mon
, i
, &env
->utlb
[i
]);
2005 #if defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_XTENSA)
2006 static void tlb_info(Monitor
*mon
, const QDict
*qdict
)
2008 CPUArchState
*env1
= mon_get_cpu();
2010 dump_mmu((FILE*)mon
, (fprintf_function
)monitor_printf
, env1
);
2014 static void do_info_mtree(Monitor
*mon
, const QDict
*qdict
)
2016 mtree_info((fprintf_function
)monitor_printf
, mon
);
2019 static void do_info_numa(Monitor
*mon
, const QDict
*qdict
)
2024 monitor_printf(mon
, "%d nodes\n", nb_numa_nodes
);
2025 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2026 monitor_printf(mon
, "node %d cpus:", i
);
2028 if (cpu
->numa_node
== i
) {
2029 monitor_printf(mon
, " %d", cpu
->cpu_index
);
2032 monitor_printf(mon
, "\n");
2033 monitor_printf(mon
, "node %d size: %" PRId64
" MB\n", i
,
2038 #ifdef CONFIG_PROFILER
2043 static void do_info_profile(Monitor
*mon
, const QDict
*qdict
)
2045 monitor_printf(mon
, "async time %" PRId64
" (%0.3f)\n",
2046 dev_time
, dev_time
/ (double)get_ticks_per_sec());
2047 monitor_printf(mon
, "qemu time %" PRId64
" (%0.3f)\n",
2048 qemu_time
, qemu_time
/ (double)get_ticks_per_sec());
2053 static void do_info_profile(Monitor
*mon
, const QDict
*qdict
)
2055 monitor_printf(mon
, "Internal profiler not compiled\n");
2059 /* Capture support */
2060 static QLIST_HEAD (capture_list_head
, CaptureState
) capture_head
;
2062 static void do_info_capture(Monitor
*mon
, const QDict
*qdict
)
2067 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
2068 monitor_printf(mon
, "[%d]: ", i
);
2069 s
->ops
.info (s
->opaque
);
2073 static void do_stop_capture(Monitor
*mon
, const QDict
*qdict
)
2076 int n
= qdict_get_int(qdict
, "n");
2079 for (s
= capture_head
.lh_first
, i
= 0; s
; s
= s
->entries
.le_next
, ++i
) {
2081 s
->ops
.destroy (s
->opaque
);
2082 QLIST_REMOVE (s
, entries
);
2089 static void do_wav_capture(Monitor
*mon
, const QDict
*qdict
)
2091 const char *path
= qdict_get_str(qdict
, "path");
2092 int has_freq
= qdict_haskey(qdict
, "freq");
2093 int freq
= qdict_get_try_int(qdict
, "freq", -1);
2094 int has_bits
= qdict_haskey(qdict
, "bits");
2095 int bits
= qdict_get_try_int(qdict
, "bits", -1);
2096 int has_channels
= qdict_haskey(qdict
, "nchannels");
2097 int nchannels
= qdict_get_try_int(qdict
, "nchannels", -1);
2100 s
= g_malloc0 (sizeof (*s
));
2102 freq
= has_freq ? freq
: 44100;
2103 bits
= has_bits ? bits
: 16;
2104 nchannels
= has_channels ? nchannels
: 2;
2106 if (wav_start_capture (s
, path
, freq
, bits
, nchannels
)) {
2107 monitor_printf(mon
, "Failed to add wave capture\n");
2111 QLIST_INSERT_HEAD (&capture_head
, s
, entries
);
2114 static qemu_acl
*find_acl(Monitor
*mon
, const char *name
)
2116 qemu_acl
*acl
= qemu_acl_find(name
);
2119 monitor_printf(mon
, "acl: unknown list '%s'\n", name
);
2124 static void do_acl_show(Monitor
*mon
, const QDict
*qdict
)
2126 const char *aclname
= qdict_get_str(qdict
, "aclname");
2127 qemu_acl
*acl
= find_acl(mon
, aclname
);
2128 qemu_acl_entry
*entry
;
2132 monitor_printf(mon
, "policy: %s\n",
2133 acl
->defaultDeny ?
"deny" : "allow");
2134 QTAILQ_FOREACH(entry
, &acl
->entries
, next
) {
2136 monitor_printf(mon
, "%d: %s %s\n", i
,
2137 entry
->deny ?
"deny" : "allow", entry
->match
);
2142 static void do_acl_reset(Monitor
*mon
, const QDict
*qdict
)
2144 const char *aclname
= qdict_get_str(qdict
, "aclname");
2145 qemu_acl
*acl
= find_acl(mon
, aclname
);
2148 qemu_acl_reset(acl
);
2149 monitor_printf(mon
, "acl: removed all rules\n");
2153 static void do_acl_policy(Monitor
*mon
, const QDict
*qdict
)
2155 const char *aclname
= qdict_get_str(qdict
, "aclname");
2156 const char *policy
= qdict_get_str(qdict
, "policy");
2157 qemu_acl
*acl
= find_acl(mon
, aclname
);
2160 if (strcmp(policy
, "allow") == 0) {
2161 acl
->defaultDeny
= 0;
2162 monitor_printf(mon
, "acl: policy set to 'allow'\n");
2163 } else if (strcmp(policy
, "deny") == 0) {
2164 acl
->defaultDeny
= 1;
2165 monitor_printf(mon
, "acl: policy set to 'deny'\n");
2167 monitor_printf(mon
, "acl: unknown policy '%s', "
2168 "expected 'deny' or 'allow'\n", policy
);
2173 static void do_acl_add(Monitor
*mon
, const QDict
*qdict
)
2175 const char *aclname
= qdict_get_str(qdict
, "aclname");
2176 const char *match
= qdict_get_str(qdict
, "match");
2177 const char *policy
= qdict_get_str(qdict
, "policy");
2178 int has_index
= qdict_haskey(qdict
, "index");
2179 int index
= qdict_get_try_int(qdict
, "index", -1);
2180 qemu_acl
*acl
= find_acl(mon
, aclname
);
2184 if (strcmp(policy
, "allow") == 0) {
2186 } else if (strcmp(policy
, "deny") == 0) {
2189 monitor_printf(mon
, "acl: unknown policy '%s', "
2190 "expected 'deny' or 'allow'\n", policy
);
2194 ret
= qemu_acl_insert(acl
, deny
, match
, index
);
2196 ret
= qemu_acl_append(acl
, deny
, match
);
2198 monitor_printf(mon
, "acl: unable to add acl entry\n");
2200 monitor_printf(mon
, "acl: added rule at position %d\n", ret
);
2204 static void do_acl_remove(Monitor
*mon
, const QDict
*qdict
)
2206 const char *aclname
= qdict_get_str(qdict
, "aclname");
2207 const char *match
= qdict_get_str(qdict
, "match");
2208 qemu_acl
*acl
= find_acl(mon
, aclname
);
2212 ret
= qemu_acl_remove(acl
, match
);
2214 monitor_printf(mon
, "acl: no matching acl entry\n");
2216 monitor_printf(mon
, "acl: removed rule at position %d\n", ret
);
2220 #if defined(TARGET_I386)
2221 static void do_inject_mce(Monitor
*mon
, const QDict
*qdict
)
2225 int cpu_index
= qdict_get_int(qdict
, "cpu_index");
2226 int bank
= qdict_get_int(qdict
, "bank");
2227 uint64_t status
= qdict_get_int(qdict
, "status");
2228 uint64_t mcg_status
= qdict_get_int(qdict
, "mcg_status");
2229 uint64_t addr
= qdict_get_int(qdict
, "addr");
2230 uint64_t misc
= qdict_get_int(qdict
, "misc");
2231 int flags
= MCE_INJECT_UNCOND_AO
;
2233 if (qdict_get_try_bool(qdict
, "broadcast", 0)) {
2234 flags
|= MCE_INJECT_BROADCAST
;
2236 cs
= qemu_get_cpu(cpu_index
);
2239 cpu_x86_inject_mce(mon
, cpu
, bank
, status
, mcg_status
, addr
, misc
,
2245 void qmp_getfd(const char *fdname
, Error
**errp
)
2250 fd
= qemu_chr_fe_get_msgfd(cur_mon
->chr
);
2252 error_set(errp
, QERR_FD_NOT_SUPPLIED
);
2256 if (qemu_isdigit(fdname
[0])) {
2257 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdname",
2258 "a name not starting with a digit");
2262 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
2263 if (strcmp(monfd
->name
, fdname
) != 0) {
2272 monfd
= g_malloc0(sizeof(mon_fd_t
));
2273 monfd
->name
= g_strdup(fdname
);
2276 QLIST_INSERT_HEAD(&cur_mon
->fds
, monfd
, next
);
2279 void qmp_closefd(const char *fdname
, Error
**errp
)
2283 QLIST_FOREACH(monfd
, &cur_mon
->fds
, next
) {
2284 if (strcmp(monfd
->name
, fdname
) != 0) {
2288 QLIST_REMOVE(monfd
, next
);
2290 g_free(monfd
->name
);
2295 error_set(errp
, QERR_FD_NOT_FOUND
, fdname
);
2298 static void do_loadvm(Monitor
*mon
, const QDict
*qdict
)
2300 int saved_vm_running
= runstate_is_running();
2301 const char *name
= qdict_get_str(qdict
, "name");
2303 vm_stop(RUN_STATE_RESTORE_VM
);
2305 if (load_vmstate(name
) == 0 && saved_vm_running
) {
2310 int monitor_get_fd(Monitor
*mon
, const char *fdname
, Error
**errp
)
2314 QLIST_FOREACH(monfd
, &mon
->fds
, next
) {
2317 if (strcmp(monfd
->name
, fdname
) != 0) {
2323 /* caller takes ownership of fd */
2324 QLIST_REMOVE(monfd
, next
);
2325 g_free(monfd
->name
);
2331 error_setg(errp
, "File descriptor named '%s' has not been found", fdname
);
2335 static void monitor_fdset_cleanup(MonFdset
*mon_fdset
)
2337 MonFdsetFd
*mon_fdset_fd
;
2338 MonFdsetFd
*mon_fdset_fd_next
;
2340 QLIST_FOREACH_SAFE(mon_fdset_fd
, &mon_fdset
->fds
, next
, mon_fdset_fd_next
) {
2341 if ((mon_fdset_fd
->removed
||
2342 (QLIST_EMPTY(&mon_fdset
->dup_fds
) && mon_refcount
== 0)) &&
2343 runstate_is_running()) {
2344 close(mon_fdset_fd
->fd
);
2345 g_free(mon_fdset_fd
->opaque
);
2346 QLIST_REMOVE(mon_fdset_fd
, next
);
2347 g_free(mon_fdset_fd
);
2351 if (QLIST_EMPTY(&mon_fdset
->fds
) && QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
2352 QLIST_REMOVE(mon_fdset
, next
);
2357 static void monitor_fdsets_cleanup(void)
2359 MonFdset
*mon_fdset
;
2360 MonFdset
*mon_fdset_next
;
2362 QLIST_FOREACH_SAFE(mon_fdset
, &mon_fdsets
, next
, mon_fdset_next
) {
2363 monitor_fdset_cleanup(mon_fdset
);
2367 AddfdInfo
*qmp_add_fd(bool has_fdset_id
, int64_t fdset_id
, bool has_opaque
,
2368 const char *opaque
, Error
**errp
)
2371 Monitor
*mon
= cur_mon
;
2374 fd
= qemu_chr_fe_get_msgfd(mon
->chr
);
2376 error_set(errp
, QERR_FD_NOT_SUPPLIED
);
2380 fdinfo
= monitor_fdset_add_fd(fd
, has_fdset_id
, fdset_id
,
2381 has_opaque
, opaque
, errp
);
2393 void qmp_remove_fd(int64_t fdset_id
, bool has_fd
, int64_t fd
, Error
**errp
)
2395 MonFdset
*mon_fdset
;
2396 MonFdsetFd
*mon_fdset_fd
;
2399 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
2400 if (mon_fdset
->id
!= fdset_id
) {
2403 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
2405 if (mon_fdset_fd
->fd
!= fd
) {
2408 mon_fdset_fd
->removed
= true;
2411 mon_fdset_fd
->removed
= true;
2414 if (has_fd
&& !mon_fdset_fd
) {
2417 monitor_fdset_cleanup(mon_fdset
);
2423 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
", fd:%" PRId64
,
2426 snprintf(fd_str
, sizeof(fd_str
), "fdset-id:%" PRId64
, fdset_id
);
2428 error_set(errp
, QERR_FD_NOT_FOUND
, fd_str
);
2431 FdsetInfoList
*qmp_query_fdsets(Error
**errp
)
2433 MonFdset
*mon_fdset
;
2434 MonFdsetFd
*mon_fdset_fd
;
2435 FdsetInfoList
*fdset_list
= NULL
;
2437 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
2438 FdsetInfoList
*fdset_info
= g_malloc0(sizeof(*fdset_info
));
2439 FdsetFdInfoList
*fdsetfd_list
= NULL
;
2441 fdset_info
->value
= g_malloc0(sizeof(*fdset_info
->value
));
2442 fdset_info
->value
->fdset_id
= mon_fdset
->id
;
2444 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
2445 FdsetFdInfoList
*fdsetfd_info
;
2447 fdsetfd_info
= g_malloc0(sizeof(*fdsetfd_info
));
2448 fdsetfd_info
->value
= g_malloc0(sizeof(*fdsetfd_info
->value
));
2449 fdsetfd_info
->value
->fd
= mon_fdset_fd
->fd
;
2450 if (mon_fdset_fd
->opaque
) {
2451 fdsetfd_info
->value
->has_opaque
= true;
2452 fdsetfd_info
->value
->opaque
= g_strdup(mon_fdset_fd
->opaque
);
2454 fdsetfd_info
->value
->has_opaque
= false;
2457 fdsetfd_info
->next
= fdsetfd_list
;
2458 fdsetfd_list
= fdsetfd_info
;
2461 fdset_info
->value
->fds
= fdsetfd_list
;
2463 fdset_info
->next
= fdset_list
;
2464 fdset_list
= fdset_info
;
2470 AddfdInfo
*monitor_fdset_add_fd(int fd
, bool has_fdset_id
, int64_t fdset_id
,
2471 bool has_opaque
, const char *opaque
,
2474 MonFdset
*mon_fdset
= NULL
;
2475 MonFdsetFd
*mon_fdset_fd
;
2479 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
2480 /* Break if match found or match impossible due to ordering by ID */
2481 if (fdset_id
<= mon_fdset
->id
) {
2482 if (fdset_id
< mon_fdset
->id
) {
2490 if (mon_fdset
== NULL
) {
2491 int64_t fdset_id_prev
= -1;
2492 MonFdset
*mon_fdset_cur
= QLIST_FIRST(&mon_fdsets
);
2496 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, "fdset-id",
2497 "a non-negative value");
2500 /* Use specified fdset ID */
2501 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
2502 mon_fdset_cur
= mon_fdset
;
2503 if (fdset_id
< mon_fdset_cur
->id
) {
2508 /* Use first available fdset ID */
2509 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
2510 mon_fdset_cur
= mon_fdset
;
2511 if (fdset_id_prev
== mon_fdset_cur
->id
- 1) {
2512 fdset_id_prev
= mon_fdset_cur
->id
;
2519 mon_fdset
= g_malloc0(sizeof(*mon_fdset
));
2521 mon_fdset
->id
= fdset_id
;
2523 mon_fdset
->id
= fdset_id_prev
+ 1;
2526 /* The fdset list is ordered by fdset ID */
2527 if (!mon_fdset_cur
) {
2528 QLIST_INSERT_HEAD(&mon_fdsets
, mon_fdset
, next
);
2529 } else if (mon_fdset
->id
< mon_fdset_cur
->id
) {
2530 QLIST_INSERT_BEFORE(mon_fdset_cur
, mon_fdset
, next
);
2532 QLIST_INSERT_AFTER(mon_fdset_cur
, mon_fdset
, next
);
2536 mon_fdset_fd
= g_malloc0(sizeof(*mon_fdset_fd
));
2537 mon_fdset_fd
->fd
= fd
;
2538 mon_fdset_fd
->removed
= false;
2540 mon_fdset_fd
->opaque
= g_strdup(opaque
);
2542 QLIST_INSERT_HEAD(&mon_fdset
->fds
, mon_fdset_fd
, next
);
2544 fdinfo
= g_malloc0(sizeof(*fdinfo
));
2545 fdinfo
->fdset_id
= mon_fdset
->id
;
2546 fdinfo
->fd
= mon_fdset_fd
->fd
;
2551 int monitor_fdset_get_fd(int64_t fdset_id
, int flags
)
2554 MonFdset
*mon_fdset
;
2555 MonFdsetFd
*mon_fdset_fd
;
2558 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
2559 if (mon_fdset
->id
!= fdset_id
) {
2562 QLIST_FOREACH(mon_fdset_fd
, &mon_fdset
->fds
, next
) {
2563 mon_fd_flags
= fcntl(mon_fdset_fd
->fd
, F_GETFL
);
2564 if (mon_fd_flags
== -1) {
2568 if ((flags
& O_ACCMODE
) == (mon_fd_flags
& O_ACCMODE
)) {
2569 return mon_fdset_fd
->fd
;
2581 int monitor_fdset_dup_fd_add(int64_t fdset_id
, int dup_fd
)
2583 MonFdset
*mon_fdset
;
2584 MonFdsetFd
*mon_fdset_fd_dup
;
2586 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
2587 if (mon_fdset
->id
!= fdset_id
) {
2590 QLIST_FOREACH(mon_fdset_fd_dup
, &mon_fdset
->dup_fds
, next
) {
2591 if (mon_fdset_fd_dup
->fd
== dup_fd
) {
2595 mon_fdset_fd_dup
= g_malloc0(sizeof(*mon_fdset_fd_dup
));
2596 mon_fdset_fd_dup
->fd
= dup_fd
;
2597 QLIST_INSERT_HEAD(&mon_fdset
->dup_fds
, mon_fdset_fd_dup
, next
);
2603 static int monitor_fdset_dup_fd_find_remove(int dup_fd
, bool remove
)
2605 MonFdset
*mon_fdset
;
2606 MonFdsetFd
*mon_fdset_fd_dup
;
2608 QLIST_FOREACH(mon_fdset
, &mon_fdsets
, next
) {
2609 QLIST_FOREACH(mon_fdset_fd_dup
, &mon_fdset
->dup_fds
, next
) {
2610 if (mon_fdset_fd_dup
->fd
== dup_fd
) {
2612 QLIST_REMOVE(mon_fdset_fd_dup
, next
);
2613 if (QLIST_EMPTY(&mon_fdset
->dup_fds
)) {
2614 monitor_fdset_cleanup(mon_fdset
);
2617 return mon_fdset
->id
;
2624 int monitor_fdset_dup_fd_find(int dup_fd
)
2626 return monitor_fdset_dup_fd_find_remove(dup_fd
, false);
2629 int monitor_fdset_dup_fd_remove(int dup_fd
)
2631 return monitor_fdset_dup_fd_find_remove(dup_fd
, true);
2634 int monitor_handle_fd_param(Monitor
*mon
, const char *fdname
)
2637 Error
*local_err
= NULL
;
2639 if (!qemu_isdigit(fdname
[0]) && mon
) {
2641 fd
= monitor_get_fd(mon
, fdname
, &local_err
);
2643 qerror_report_err(local_err
);
2644 error_free(local_err
);
2648 fd
= qemu_parse_fd(fdname
);
2654 /* Please update hmp-commands.hx when adding or changing commands */
2655 static mon_cmd_t info_cmds
[] = {
2660 .help
= "show the version of QEMU",
2661 .mhandler
.cmd
= hmp_info_version
,
2667 .help
= "show the network state",
2668 .mhandler
.cmd
= do_info_network
,
2674 .help
= "show the character devices",
2675 .mhandler
.cmd
= hmp_info_chardev
,
2679 .args_type
= "verbose:-v,device:B?",
2680 .params
= "[-v] [device]",
2681 .help
= "show info of one block device or all block devices "
2682 "(and details of images with -v option)",
2683 .mhandler
.cmd
= hmp_info_block
,
2686 .name
= "blockstats",
2689 .help
= "show block device statistics",
2690 .mhandler
.cmd
= hmp_info_blockstats
,
2693 .name
= "block-jobs",
2696 .help
= "show progress of ongoing block device operations",
2697 .mhandler
.cmd
= hmp_info_block_jobs
,
2700 .name
= "registers",
2703 .help
= "show the cpu registers",
2704 .mhandler
.cmd
= do_info_registers
,
2710 .help
= "show infos for each CPU",
2711 .mhandler
.cmd
= hmp_info_cpus
,
2717 .help
= "show the command line history",
2718 .mhandler
.cmd
= do_info_history
,
2720 #if defined(TARGET_I386) || defined(TARGET_PPC) || defined(TARGET_MIPS) || \
2721 defined(TARGET_LM32) || (defined(TARGET_SPARC) && !defined(TARGET_SPARC64))
2726 .help
= "show the interrupts statistics (if available)",
2728 .mhandler
.cmd
= sun4m_irq_info
,
2729 #elif defined(TARGET_LM32)
2730 .mhandler
.cmd
= lm32_irq_info
,
2732 .mhandler
.cmd
= irq_info
,
2739 .help
= "show i8259 (PIC) state",
2741 .mhandler
.cmd
= sun4m_pic_info
,
2742 #elif defined(TARGET_LM32)
2743 .mhandler
.cmd
= lm32_do_pic_info
,
2745 .mhandler
.cmd
= pic_info
,
2753 .help
= "show PCI info",
2754 .mhandler
.cmd
= hmp_info_pci
,
2756 #if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \
2757 defined(TARGET_PPC) || defined(TARGET_XTENSA)
2762 .help
= "show virtual to physical memory mappings",
2763 .mhandler
.cmd
= tlb_info
,
2766 #if defined(TARGET_I386)
2771 .help
= "show the active virtual memory mappings",
2772 .mhandler
.cmd
= mem_info
,
2779 .help
= "show memory tree",
2780 .mhandler
.cmd
= do_info_mtree
,
2786 .help
= "show dynamic compiler info",
2787 .mhandler
.cmd
= do_info_jit
,
2793 .help
= "show KVM information",
2794 .mhandler
.cmd
= hmp_info_kvm
,
2800 .help
= "show NUMA information",
2801 .mhandler
.cmd
= do_info_numa
,
2807 .help
= "show guest USB devices",
2808 .mhandler
.cmd
= usb_info
,
2814 .help
= "show host USB devices",
2815 .mhandler
.cmd
= usb_host_info
,
2821 .help
= "show profiling information",
2822 .mhandler
.cmd
= do_info_profile
,
2828 .help
= "show capture information",
2829 .mhandler
.cmd
= do_info_capture
,
2832 .name
= "snapshots",
2835 .help
= "show the currently saved VM snapshots",
2836 .mhandler
.cmd
= do_info_snapshots
,
2842 .help
= "show the current VM status (running|paused)",
2843 .mhandler
.cmd
= hmp_info_status
,
2849 .help
= "show guest PCMCIA status",
2850 .mhandler
.cmd
= pcmcia_info
,
2856 .help
= "show which guest mouse is receiving events",
2857 .mhandler
.cmd
= hmp_info_mice
,
2863 .help
= "show the vnc server status",
2864 .mhandler
.cmd
= hmp_info_vnc
,
2866 #if defined(CONFIG_SPICE)
2871 .help
= "show the spice server status",
2872 .mhandler
.cmd
= hmp_info_spice
,
2879 .help
= "show the current VM name",
2880 .mhandler
.cmd
= hmp_info_name
,
2886 .help
= "show the current VM UUID",
2887 .mhandler
.cmd
= hmp_info_uuid
,
2893 .help
= "show CPU statistics",
2894 .mhandler
.cmd
= do_info_cpu_stats
,
2896 #if defined(CONFIG_SLIRP)
2901 .help
= "show user network stack connection states",
2902 .mhandler
.cmd
= do_info_usernet
,
2909 .help
= "show migration status",
2910 .mhandler
.cmd
= hmp_info_migrate
,
2913 .name
= "migrate_capabilities",
2916 .help
= "show current migration capabilities",
2917 .mhandler
.cmd
= hmp_info_migrate_capabilities
,
2920 .name
= "migrate_cache_size",
2923 .help
= "show current migration xbzrle cache size",
2924 .mhandler
.cmd
= hmp_info_migrate_cache_size
,
2930 .help
= "show balloon information",
2931 .mhandler
.cmd
= hmp_info_balloon
,
2937 .help
= "show device tree",
2938 .mhandler
.cmd
= do_info_qtree
,
2944 .help
= "show qdev device model list",
2945 .mhandler
.cmd
= do_info_qdm
,
2951 .help
= "show roms",
2952 .mhandler
.cmd
= do_info_roms
,
2955 .name
= "trace-events",
2958 .help
= "show available trace-events & their state",
2959 .mhandler
.cmd
= do_trace_print_events
,
2965 .help
= "show the TPM device",
2966 .mhandler
.cmd
= hmp_info_tpm
,
2973 /* mon_cmds and info_cmds would be sorted at runtime */
2974 static mon_cmd_t mon_cmds
[] = {
2975 #include "hmp-commands.h"
2979 static const mon_cmd_t qmp_cmds
[] = {
2980 #include "qmp-commands-old.h"
2984 /*******************************************************************/
2986 static const char *pch
;
2987 static sigjmp_buf expr_env
;
2992 typedef struct MonitorDef
{
2995 target_long (*get_value
)(const struct MonitorDef
*md
, int val
);
2999 #if defined(TARGET_I386)
3000 static target_long
monitor_get_pc (const struct MonitorDef
*md
, int val
)
3002 CPUArchState
*env
= mon_get_cpu();
3003 return env
->eip
+ env
->segs
[R_CS
].base
;
3007 #if defined(TARGET_PPC)
3008 static target_long
monitor_get_ccr (const struct MonitorDef
*md
, int val
)
3010 CPUArchState
*env
= mon_get_cpu();
3015 for (i
= 0; i
< 8; i
++)
3016 u
|= env
->crf
[i
] << (32 - (4 * i
));
3021 static target_long
monitor_get_msr (const struct MonitorDef
*md
, int val
)
3023 CPUArchState
*env
= mon_get_cpu();
3027 static target_long
monitor_get_xer (const struct MonitorDef
*md
, int val
)
3029 CPUArchState
*env
= mon_get_cpu();
3033 static target_long
monitor_get_decr (const struct MonitorDef
*md
, int val
)
3035 CPUArchState
*env
= mon_get_cpu();
3036 return cpu_ppc_load_decr(env
);
3039 static target_long
monitor_get_tbu (const struct MonitorDef
*md
, int val
)
3041 CPUArchState
*env
= mon_get_cpu();
3042 return cpu_ppc_load_tbu(env
);
3045 static target_long
monitor_get_tbl (const struct MonitorDef
*md
, int val
)
3047 CPUArchState
*env
= mon_get_cpu();
3048 return cpu_ppc_load_tbl(env
);
3052 #if defined(TARGET_SPARC)
3053 #ifndef TARGET_SPARC64
3054 static target_long
monitor_get_psr (const struct MonitorDef
*md
, int val
)
3056 CPUArchState
*env
= mon_get_cpu();
3058 return cpu_get_psr(env
);
3062 static target_long
monitor_get_reg(const struct MonitorDef
*md
, int val
)
3064 CPUArchState
*env
= mon_get_cpu();
3065 return env
->regwptr
[val
];
3069 static const MonitorDef monitor_defs
[] = {
3072 #define SEG(name, seg) \
3073 { name, offsetof(CPUX86State, segs[seg].selector), NULL, MD_I32 },\
3074 { name ".base", offsetof(CPUX86State, segs[seg].base) },\
3075 { name ".limit", offsetof(CPUX86State, segs[seg].limit), NULL, MD_I32 },
3077 { "eax", offsetof(CPUX86State
, regs
[0]) },
3078 { "ecx", offsetof(CPUX86State
, regs
[1]) },
3079 { "edx", offsetof(CPUX86State
, regs
[2]) },
3080 { "ebx", offsetof(CPUX86State
, regs
[3]) },
3081 { "esp|sp", offsetof(CPUX86State
, regs
[4]) },
3082 { "ebp|fp", offsetof(CPUX86State
, regs
[5]) },
3083 { "esi", offsetof(CPUX86State
, regs
[6]) },
3084 { "edi", offsetof(CPUX86State
, regs
[7]) },
3085 #ifdef TARGET_X86_64
3086 { "r8", offsetof(CPUX86State
, regs
[8]) },
3087 { "r9", offsetof(CPUX86State
, regs
[9]) },
3088 { "r10", offsetof(CPUX86State
, regs
[10]) },
3089 { "r11", offsetof(CPUX86State
, regs
[11]) },
3090 { "r12", offsetof(CPUX86State
, regs
[12]) },
3091 { "r13", offsetof(CPUX86State
, regs
[13]) },
3092 { "r14", offsetof(CPUX86State
, regs
[14]) },
3093 { "r15", offsetof(CPUX86State
, regs
[15]) },
3095 { "eflags", offsetof(CPUX86State
, eflags
) },
3096 { "eip", offsetof(CPUX86State
, eip
) },
3103 { "pc", 0, monitor_get_pc
, },
3104 #elif defined(TARGET_PPC)
3105 /* General purpose registers */
3106 { "r0", offsetof(CPUPPCState
, gpr
[0]) },
3107 { "r1", offsetof(CPUPPCState
, gpr
[1]) },
3108 { "r2", offsetof(CPUPPCState
, gpr
[2]) },
3109 { "r3", offsetof(CPUPPCState
, gpr
[3]) },
3110 { "r4", offsetof(CPUPPCState
, gpr
[4]) },
3111 { "r5", offsetof(CPUPPCState
, gpr
[5]) },
3112 { "r6", offsetof(CPUPPCState
, gpr
[6]) },
3113 { "r7", offsetof(CPUPPCState
, gpr
[7]) },
3114 { "r8", offsetof(CPUPPCState
, gpr
[8]) },
3115 { "r9", offsetof(CPUPPCState
, gpr
[9]) },
3116 { "r10", offsetof(CPUPPCState
, gpr
[10]) },
3117 { "r11", offsetof(CPUPPCState
, gpr
[11]) },
3118 { "r12", offsetof(CPUPPCState
, gpr
[12]) },
3119 { "r13", offsetof(CPUPPCState
, gpr
[13]) },
3120 { "r14", offsetof(CPUPPCState
, gpr
[14]) },
3121 { "r15", offsetof(CPUPPCState
, gpr
[15]) },
3122 { "r16", offsetof(CPUPPCState
, gpr
[16]) },
3123 { "r17", offsetof(CPUPPCState
, gpr
[17]) },
3124 { "r18", offsetof(CPUPPCState
, gpr
[18]) },
3125 { "r19", offsetof(CPUPPCState
, gpr
[19]) },
3126 { "r20", offsetof(CPUPPCState
, gpr
[20]) },
3127 { "r21", offsetof(CPUPPCState
, gpr
[21]) },
3128 { "r22", offsetof(CPUPPCState
, gpr
[22]) },
3129 { "r23", offsetof(CPUPPCState
, gpr
[23]) },
3130 { "r24", offsetof(CPUPPCState
, gpr
[24]) },
3131 { "r25", offsetof(CPUPPCState
, gpr
[25]) },
3132 { "r26", offsetof(CPUPPCState
, gpr
[26]) },
3133 { "r27", offsetof(CPUPPCState
, gpr
[27]) },
3134 { "r28", offsetof(CPUPPCState
, gpr
[28]) },
3135 { "r29", offsetof(CPUPPCState
, gpr
[29]) },
3136 { "r30", offsetof(CPUPPCState
, gpr
[30]) },
3137 { "r31", offsetof(CPUPPCState
, gpr
[31]) },
3138 /* Floating point registers */
3139 { "f0", offsetof(CPUPPCState
, fpr
[0]) },
3140 { "f1", offsetof(CPUPPCState
, fpr
[1]) },
3141 { "f2", offsetof(CPUPPCState
, fpr
[2]) },
3142 { "f3", offsetof(CPUPPCState
, fpr
[3]) },
3143 { "f4", offsetof(CPUPPCState
, fpr
[4]) },
3144 { "f5", offsetof(CPUPPCState
, fpr
[5]) },
3145 { "f6", offsetof(CPUPPCState
, fpr
[6]) },
3146 { "f7", offsetof(CPUPPCState
, fpr
[7]) },
3147 { "f8", offsetof(CPUPPCState
, fpr
[8]) },
3148 { "f9", offsetof(CPUPPCState
, fpr
[9]) },
3149 { "f10", offsetof(CPUPPCState
, fpr
[10]) },
3150 { "f11", offsetof(CPUPPCState
, fpr
[11]) },
3151 { "f12", offsetof(CPUPPCState
, fpr
[12]) },
3152 { "f13", offsetof(CPUPPCState
, fpr
[13]) },
3153 { "f14", offsetof(CPUPPCState
, fpr
[14]) },
3154 { "f15", offsetof(CPUPPCState
, fpr
[15]) },
3155 { "f16", offsetof(CPUPPCState
, fpr
[16]) },
3156 { "f17", offsetof(CPUPPCState
, fpr
[17]) },
3157 { "f18", offsetof(CPUPPCState
, fpr
[18]) },
3158 { "f19", offsetof(CPUPPCState
, fpr
[19]) },
3159 { "f20", offsetof(CPUPPCState
, fpr
[20]) },
3160 { "f21", offsetof(CPUPPCState
, fpr
[21]) },
3161 { "f22", offsetof(CPUPPCState
, fpr
[22]) },
3162 { "f23", offsetof(CPUPPCState
, fpr
[23]) },
3163 { "f24", offsetof(CPUPPCState
, fpr
[24]) },
3164 { "f25", offsetof(CPUPPCState
, fpr
[25]) },
3165 { "f26", offsetof(CPUPPCState
, fpr
[26]) },
3166 { "f27", offsetof(CPUPPCState
, fpr
[27]) },
3167 { "f28", offsetof(CPUPPCState
, fpr
[28]) },
3168 { "f29", offsetof(CPUPPCState
, fpr
[29]) },
3169 { "f30", offsetof(CPUPPCState
, fpr
[30]) },
3170 { "f31", offsetof(CPUPPCState
, fpr
[31]) },
3171 { "fpscr", offsetof(CPUPPCState
, fpscr
) },
3172 /* Next instruction pointer */
3173 { "nip|pc", offsetof(CPUPPCState
, nip
) },
3174 { "lr", offsetof(CPUPPCState
, lr
) },
3175 { "ctr", offsetof(CPUPPCState
, ctr
) },
3176 { "decr", 0, &monitor_get_decr
, },
3177 { "ccr", 0, &monitor_get_ccr
, },
3178 /* Machine state register */
3179 { "msr", 0, &monitor_get_msr
, },
3180 { "xer", 0, &monitor_get_xer
, },
3181 { "tbu", 0, &monitor_get_tbu
, },
3182 { "tbl", 0, &monitor_get_tbl
, },
3183 /* Segment registers */
3184 { "sdr1", offsetof(CPUPPCState
, spr
[SPR_SDR1
]) },
3185 { "sr0", offsetof(CPUPPCState
, sr
[0]) },
3186 { "sr1", offsetof(CPUPPCState
, sr
[1]) },
3187 { "sr2", offsetof(CPUPPCState
, sr
[2]) },
3188 { "sr3", offsetof(CPUPPCState
, sr
[3]) },
3189 { "sr4", offsetof(CPUPPCState
, sr
[4]) },
3190 { "sr5", offsetof(CPUPPCState
, sr
[5]) },
3191 { "sr6", offsetof(CPUPPCState
, sr
[6]) },
3192 { "sr7", offsetof(CPUPPCState
, sr
[7]) },
3193 { "sr8", offsetof(CPUPPCState
, sr
[8]) },
3194 { "sr9", offsetof(CPUPPCState
, sr
[9]) },
3195 { "sr10", offsetof(CPUPPCState
, sr
[10]) },
3196 { "sr11", offsetof(CPUPPCState
, sr
[11]) },
3197 { "sr12", offsetof(CPUPPCState
, sr
[12]) },
3198 { "sr13", offsetof(CPUPPCState
, sr
[13]) },
3199 { "sr14", offsetof(CPUPPCState
, sr
[14]) },
3200 { "sr15", offsetof(CPUPPCState
, sr
[15]) },
3201 /* Too lazy to put BATs... */
3202 { "pvr", offsetof(CPUPPCState
, spr
[SPR_PVR
]) },
3204 { "srr0", offsetof(CPUPPCState
, spr
[SPR_SRR0
]) },
3205 { "srr1", offsetof(CPUPPCState
, spr
[SPR_SRR1
]) },
3206 { "dar", offsetof(CPUPPCState
, spr
[SPR_DAR
]) },
3207 { "dsisr", offsetof(CPUPPCState
, spr
[SPR_DSISR
]) },
3208 { "cfar", offsetof(CPUPPCState
, spr
[SPR_CFAR
]) },
3209 { "sprg0", offsetof(CPUPPCState
, spr
[SPR_SPRG0
]) },
3210 { "sprg1", offsetof(CPUPPCState
, spr
[SPR_SPRG1
]) },
3211 { "sprg2", offsetof(CPUPPCState
, spr
[SPR_SPRG2
]) },
3212 { "sprg3", offsetof(CPUPPCState
, spr
[SPR_SPRG3
]) },
3213 { "sprg4", offsetof(CPUPPCState
, spr
[SPR_SPRG4
]) },
3214 { "sprg5", offsetof(CPUPPCState
, spr
[SPR_SPRG5
]) },
3215 { "sprg6", offsetof(CPUPPCState
, spr
[SPR_SPRG6
]) },
3216 { "sprg7", offsetof(CPUPPCState
, spr
[SPR_SPRG7
]) },
3217 { "pid", offsetof(CPUPPCState
, spr
[SPR_BOOKE_PID
]) },
3218 { "csrr0", offsetof(CPUPPCState
, spr
[SPR_BOOKE_CSRR0
]) },
3219 { "csrr1", offsetof(CPUPPCState
, spr
[SPR_BOOKE_CSRR1
]) },
3220 { "esr", offsetof(CPUPPCState
, spr
[SPR_BOOKE_ESR
]) },
3221 { "dear", offsetof(CPUPPCState
, spr
[SPR_BOOKE_DEAR
]) },
3222 { "mcsr", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MCSR
]) },
3223 { "tsr", offsetof(CPUPPCState
, spr
[SPR_BOOKE_TSR
]) },
3224 { "tcr", offsetof(CPUPPCState
, spr
[SPR_BOOKE_TCR
]) },
3225 { "vrsave", offsetof(CPUPPCState
, spr
[SPR_VRSAVE
]) },
3226 { "pir", offsetof(CPUPPCState
, spr
[SPR_BOOKE_PIR
]) },
3227 { "mcsrr0", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MCSRR0
]) },
3228 { "mcsrr1", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MCSRR1
]) },
3229 { "decar", offsetof(CPUPPCState
, spr
[SPR_BOOKE_DECAR
]) },
3230 { "ivpr", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVPR
]) },
3231 { "epcr", offsetof(CPUPPCState
, spr
[SPR_BOOKE_EPCR
]) },
3232 { "sprg8", offsetof(CPUPPCState
, spr
[SPR_BOOKE_SPRG8
]) },
3233 { "ivor0", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR0
]) },
3234 { "ivor1", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR1
]) },
3235 { "ivor2", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR2
]) },
3236 { "ivor3", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR3
]) },
3237 { "ivor4", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR4
]) },
3238 { "ivor5", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR5
]) },
3239 { "ivor6", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR6
]) },
3240 { "ivor7", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR7
]) },
3241 { "ivor8", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR8
]) },
3242 { "ivor9", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR9
]) },
3243 { "ivor10", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR10
]) },
3244 { "ivor11", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR11
]) },
3245 { "ivor12", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR12
]) },
3246 { "ivor13", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR13
]) },
3247 { "ivor14", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR14
]) },
3248 { "ivor15", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR15
]) },
3249 { "ivor32", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR32
]) },
3250 { "ivor33", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR33
]) },
3251 { "ivor34", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR34
]) },
3252 { "ivor35", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR35
]) },
3253 { "ivor36", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR36
]) },
3254 { "ivor37", offsetof(CPUPPCState
, spr
[SPR_BOOKE_IVOR37
]) },
3255 { "mas0", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MAS0
]) },
3256 { "mas1", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MAS1
]) },
3257 { "mas2", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MAS2
]) },
3258 { "mas3", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MAS3
]) },
3259 { "mas4", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MAS4
]) },
3260 { "mas6", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MAS6
]) },
3261 { "mas7", offsetof(CPUPPCState
, spr
[SPR_BOOKE_MAS7
]) },
3262 { "mmucfg", offsetof(CPUPPCState
, spr
[SPR_MMUCFG
]) },
3263 { "tlb0cfg", offsetof(CPUPPCState
, spr
[SPR_BOOKE_TLB0CFG
]) },
3264 { "tlb1cfg", offsetof(CPUPPCState
, spr
[SPR_BOOKE_TLB1CFG
]) },
3265 { "epr", offsetof(CPUPPCState
, spr
[SPR_BOOKE_EPR
]) },
3266 { "eplc", offsetof(CPUPPCState
, spr
[SPR_BOOKE_EPLC
]) },
3267 { "epsc", offsetof(CPUPPCState
, spr