root / monitor.c @ 4118a970
History | View | Annotate | Download (67.4 kB)
1 | 9dc39cba | bellard | /*
|
---|---|---|---|
2 | 9dc39cba | bellard | * QEMU monitor
|
3 | 5fafdf24 | ths | *
|
4 | 9dc39cba | bellard | * Copyright (c) 2003-2004 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 9dc39cba | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 9dc39cba | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 9dc39cba | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 9dc39cba | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 9dc39cba | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 9dc39cba | bellard | * furnished to do so, subject to the following conditions:
|
12 | 9dc39cba | bellard | *
|
13 | 9dc39cba | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 9dc39cba | bellard | * all copies or substantial portions of the Software.
|
15 | 9dc39cba | bellard | *
|
16 | 9dc39cba | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 9dc39cba | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 9dc39cba | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 9dc39cba | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 9dc39cba | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 9dc39cba | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 9dc39cba | bellard | * THE SOFTWARE.
|
23 | 9dc39cba | bellard | */
|
24 | 9dc39cba | bellard | #include "vl.h" |
25 | 9307c4c1 | bellard | #include "disas.h" |
26 | 81d0912d | bellard | #include <dirent.h> |
27 | 9dc39cba | bellard | |
28 | 9dc39cba | bellard | //#define DEBUG
|
29 | 81d0912d | bellard | //#define DEBUG_COMPLETION
|
30 | 9dc39cba | bellard | |
31 | 9307c4c1 | bellard | #ifndef offsetof
|
32 | 9307c4c1 | bellard | #define offsetof(type, field) ((size_t) &((type *)0)->field) |
33 | 9307c4c1 | bellard | #endif
|
34 | 9307c4c1 | bellard | |
35 | 9307c4c1 | bellard | /*
|
36 | 9307c4c1 | bellard | * Supported types:
|
37 | 5fafdf24 | ths | *
|
38 | 9307c4c1 | bellard | * 'F' filename
|
39 | 81d0912d | bellard | * 'B' block device name
|
40 | 9307c4c1 | bellard | * 's' string (accept optional quote)
|
41 | 92a31b1f | bellard | * 'i' 32 bit integer
|
42 | 92a31b1f | bellard | * 'l' target long (32 or 64 bit)
|
43 | 9307c4c1 | bellard | * '/' optional gdb-like print format (like "/10x")
|
44 | 9307c4c1 | bellard | *
|
45 | 9307c4c1 | bellard | * '?' optional type (for 'F', 's' and 'i')
|
46 | 9307c4c1 | bellard | *
|
47 | 9307c4c1 | bellard | */
|
48 | 9307c4c1 | bellard | |
49 | 9dc39cba | bellard | typedef struct term_cmd_t { |
50 | 9dc39cba | bellard | const char *name; |
51 | 9307c4c1 | bellard | const char *args_type; |
52 | 9307c4c1 | bellard | void (*handler)();
|
53 | 9dc39cba | bellard | const char *params; |
54 | 9dc39cba | bellard | const char *help; |
55 | 9dc39cba | bellard | } term_cmd_t; |
56 | 9dc39cba | bellard | |
57 | 20d8a3ed | ths | #define MAX_MON 4 |
58 | 20d8a3ed | ths | static CharDriverState *monitor_hd[MAX_MON];
|
59 | 86e94dea | ths | static int hide_banner; |
60 | 7e2515e8 | bellard | |
61 | 9dc39cba | bellard | static term_cmd_t term_cmds[];
|
62 | 9dc39cba | bellard | static term_cmd_t info_cmds[];
|
63 | 9dc39cba | bellard | |
64 | 7e2515e8 | bellard | static char term_outbuf[1024]; |
65 | 7e2515e8 | bellard | static int term_outbuf_index; |
66 | 81d0912d | bellard | |
67 | 7e2515e8 | bellard | static void monitor_start_input(void); |
68 | 7e2515e8 | bellard | |
69 | 6a00d601 | bellard | CPUState *mon_cpu = NULL;
|
70 | 6a00d601 | bellard | |
71 | 7e2515e8 | bellard | void term_flush(void) |
72 | 7e2515e8 | bellard | { |
73 | 20d8a3ed | ths | int i;
|
74 | 7e2515e8 | bellard | if (term_outbuf_index > 0) { |
75 | 20d8a3ed | ths | for (i = 0; i < MAX_MON; i++) |
76 | 20d8a3ed | ths | if (monitor_hd[i] && monitor_hd[i]->focus == 0) |
77 | 20d8a3ed | ths | qemu_chr_write(monitor_hd[i], term_outbuf, term_outbuf_index); |
78 | 7e2515e8 | bellard | term_outbuf_index = 0;
|
79 | 7e2515e8 | bellard | } |
80 | 7e2515e8 | bellard | } |
81 | 7e2515e8 | bellard | |
82 | 7e2515e8 | bellard | /* flush at every end of line or if the buffer is full */
|
83 | 7e2515e8 | bellard | void term_puts(const char *str) |
84 | 7e2515e8 | bellard | { |
85 | 7e2515e8 | bellard | int c;
|
86 | 7e2515e8 | bellard | for(;;) {
|
87 | 7e2515e8 | bellard | c = *str++; |
88 | 7e2515e8 | bellard | if (c == '\0') |
89 | 7e2515e8 | bellard | break;
|
90 | 7ba1260a | bellard | if (c == '\n') |
91 | 7ba1260a | bellard | term_outbuf[term_outbuf_index++] = '\r';
|
92 | 7e2515e8 | bellard | term_outbuf[term_outbuf_index++] = c; |
93 | 7ba1260a | bellard | if (term_outbuf_index >= (sizeof(term_outbuf) - 1) || |
94 | 7e2515e8 | bellard | c == '\n')
|
95 | 7e2515e8 | bellard | term_flush(); |
96 | 7e2515e8 | bellard | } |
97 | 7e2515e8 | bellard | } |
98 | 7e2515e8 | bellard | |
99 | 7e2515e8 | bellard | void term_vprintf(const char *fmt, va_list ap) |
100 | 9dc39cba | bellard | { |
101 | 81d0912d | bellard | char buf[4096]; |
102 | 81d0912d | bellard | vsnprintf(buf, sizeof(buf), fmt, ap);
|
103 | 7e2515e8 | bellard | term_puts(buf); |
104 | 9dc39cba | bellard | } |
105 | 9dc39cba | bellard | |
106 | 7e2515e8 | bellard | void term_printf(const char *fmt, ...) |
107 | 9dc39cba | bellard | { |
108 | 7e2515e8 | bellard | va_list ap; |
109 | 7e2515e8 | bellard | va_start(ap, fmt); |
110 | 7e2515e8 | bellard | term_vprintf(fmt, ap); |
111 | 7e2515e8 | bellard | va_end(ap); |
112 | 9dc39cba | bellard | } |
113 | 9dc39cba | bellard | |
114 | fef30743 | ths | void term_print_filename(const char *filename) |
115 | fef30743 | ths | { |
116 | fef30743 | ths | int i;
|
117 | fef30743 | ths | |
118 | fef30743 | ths | for (i = 0; filename[i]; i++) { |
119 | fef30743 | ths | switch (filename[i]) {
|
120 | fef30743 | ths | case ' ': |
121 | fef30743 | ths | case '"': |
122 | fef30743 | ths | case '\\': |
123 | fef30743 | ths | term_printf("\\%c", filename[i]);
|
124 | fef30743 | ths | break;
|
125 | fef30743 | ths | case '\t': |
126 | fef30743 | ths | term_printf("\\t");
|
127 | fef30743 | ths | break;
|
128 | fef30743 | ths | case '\r': |
129 | fef30743 | ths | term_printf("\\r");
|
130 | fef30743 | ths | break;
|
131 | fef30743 | ths | case '\n': |
132 | fef30743 | ths | term_printf("\\n");
|
133 | fef30743 | ths | break;
|
134 | fef30743 | ths | default:
|
135 | fef30743 | ths | term_printf("%c", filename[i]);
|
136 | fef30743 | ths | break;
|
137 | fef30743 | ths | } |
138 | fef30743 | ths | } |
139 | fef30743 | ths | } |
140 | fef30743 | ths | |
141 | 7fe48483 | bellard | static int monitor_fprintf(FILE *stream, const char *fmt, ...) |
142 | 7fe48483 | bellard | { |
143 | 7fe48483 | bellard | va_list ap; |
144 | 7fe48483 | bellard | va_start(ap, fmt); |
145 | 7fe48483 | bellard | term_vprintf(fmt, ap); |
146 | 7fe48483 | bellard | va_end(ap); |
147 | 7fe48483 | bellard | return 0; |
148 | 7fe48483 | bellard | } |
149 | 7fe48483 | bellard | |
150 | 9dc39cba | bellard | static int compare_cmd(const char *name, const char *list) |
151 | 9dc39cba | bellard | { |
152 | 9dc39cba | bellard | const char *p, *pstart; |
153 | 9dc39cba | bellard | int len;
|
154 | 9dc39cba | bellard | len = strlen(name); |
155 | 9dc39cba | bellard | p = list; |
156 | 9dc39cba | bellard | for(;;) {
|
157 | 9dc39cba | bellard | pstart = p; |
158 | 9dc39cba | bellard | p = strchr(p, '|');
|
159 | 9dc39cba | bellard | if (!p)
|
160 | 9dc39cba | bellard | p = pstart + strlen(pstart); |
161 | 9dc39cba | bellard | if ((p - pstart) == len && !memcmp(pstart, name, len))
|
162 | 9dc39cba | bellard | return 1; |
163 | 9dc39cba | bellard | if (*p == '\0') |
164 | 9dc39cba | bellard | break;
|
165 | 9dc39cba | bellard | p++; |
166 | 9dc39cba | bellard | } |
167 | 9dc39cba | bellard | return 0; |
168 | 9dc39cba | bellard | } |
169 | 9dc39cba | bellard | |
170 | 9dc39cba | bellard | static void help_cmd1(term_cmd_t *cmds, const char *prefix, const char *name) |
171 | 9dc39cba | bellard | { |
172 | 9dc39cba | bellard | term_cmd_t *cmd; |
173 | 9dc39cba | bellard | |
174 | 9dc39cba | bellard | for(cmd = cmds; cmd->name != NULL; cmd++) { |
175 | 9dc39cba | bellard | if (!name || !strcmp(name, cmd->name))
|
176 | 9dc39cba | bellard | term_printf("%s%s %s -- %s\n", prefix, cmd->name, cmd->params, cmd->help);
|
177 | 9dc39cba | bellard | } |
178 | 9dc39cba | bellard | } |
179 | 9dc39cba | bellard | |
180 | 9dc39cba | bellard | static void help_cmd(const char *name) |
181 | 9dc39cba | bellard | { |
182 | 9dc39cba | bellard | if (name && !strcmp(name, "info")) { |
183 | 9dc39cba | bellard | help_cmd1(info_cmds, "info ", NULL); |
184 | 9dc39cba | bellard | } else {
|
185 | 9dc39cba | bellard | help_cmd1(term_cmds, "", name);
|
186 | f193c797 | bellard | if (name && !strcmp(name, "log")) { |
187 | f193c797 | bellard | CPULogItem *item; |
188 | f193c797 | bellard | term_printf("Log items (comma separated):\n");
|
189 | f193c797 | bellard | term_printf("%-10s %s\n", "none", "remove all logs"); |
190 | f193c797 | bellard | for(item = cpu_log_items; item->mask != 0; item++) { |
191 | f193c797 | bellard | term_printf("%-10s %s\n", item->name, item->help);
|
192 | f193c797 | bellard | } |
193 | f193c797 | bellard | } |
194 | 9dc39cba | bellard | } |
195 | 9dc39cba | bellard | } |
196 | 9dc39cba | bellard | |
197 | 9307c4c1 | bellard | static void do_help(const char *name) |
198 | 9dc39cba | bellard | { |
199 | 9307c4c1 | bellard | help_cmd(name); |
200 | 9dc39cba | bellard | } |
201 | 9dc39cba | bellard | |
202 | 7954c734 | bellard | static void do_commit(const char *device) |
203 | 9dc39cba | bellard | { |
204 | 7954c734 | bellard | int i, all_devices;
|
205 | 2dc7b602 | balrog | |
206 | 7954c734 | bellard | all_devices = !strcmp(device, "all");
|
207 | 9dc39cba | bellard | for (i = 0; i < MAX_DISKS; i++) { |
208 | 7e2515e8 | bellard | if (bs_table[i]) {
|
209 | 5fafdf24 | ths | if (all_devices ||
|
210 | 7954c734 | bellard | !strcmp(bdrv_get_device_name(bs_table[i]), device)) |
211 | 7954c734 | bellard | bdrv_commit(bs_table[i]); |
212 | 7e2515e8 | bellard | } |
213 | 9dc39cba | bellard | } |
214 | 2dc7b602 | balrog | if (mtd_bdrv)
|
215 | 2dc7b602 | balrog | if (all_devices || !strcmp(bdrv_get_device_name(mtd_bdrv), device))
|
216 | 2dc7b602 | balrog | bdrv_commit(mtd_bdrv); |
217 | 9dc39cba | bellard | } |
218 | 9dc39cba | bellard | |
219 | 9307c4c1 | bellard | static void do_info(const char *item) |
220 | 9dc39cba | bellard | { |
221 | 9dc39cba | bellard | term_cmd_t *cmd; |
222 | 9dc39cba | bellard | |
223 | 9307c4c1 | bellard | if (!item)
|
224 | 9dc39cba | bellard | goto help;
|
225 | 9dc39cba | bellard | for(cmd = info_cmds; cmd->name != NULL; cmd++) { |
226 | 5fafdf24 | ths | if (compare_cmd(item, cmd->name))
|
227 | 9dc39cba | bellard | goto found;
|
228 | 9dc39cba | bellard | } |
229 | 9dc39cba | bellard | help:
|
230 | 9307c4c1 | bellard | help_cmd("info");
|
231 | 9dc39cba | bellard | return;
|
232 | 9dc39cba | bellard | found:
|
233 | 9307c4c1 | bellard | cmd->handler(); |
234 | 9dc39cba | bellard | } |
235 | 9dc39cba | bellard | |
236 | 9bc9d1c7 | bellard | static void do_info_version(void) |
237 | 9bc9d1c7 | bellard | { |
238 | 9bc9d1c7 | bellard | term_printf("%s\n", QEMU_VERSION);
|
239 | 9bc9d1c7 | bellard | } |
240 | 9bc9d1c7 | bellard | |
241 | c35734b2 | ths | static void do_info_name(void) |
242 | c35734b2 | ths | { |
243 | c35734b2 | ths | if (qemu_name)
|
244 | c35734b2 | ths | term_printf("%s\n", qemu_name);
|
245 | c35734b2 | ths | } |
246 | c35734b2 | ths | |
247 | 9307c4c1 | bellard | static void do_info_block(void) |
248 | 9dc39cba | bellard | { |
249 | 9dc39cba | bellard | bdrv_info(); |
250 | 9dc39cba | bellard | } |
251 | 9dc39cba | bellard | |
252 | 6a00d601 | bellard | /* get the current CPU defined by the user */
|
253 | 6a00d601 | bellard | int mon_set_cpu(int cpu_index) |
254 | 6a00d601 | bellard | { |
255 | 6a00d601 | bellard | CPUState *env; |
256 | 6a00d601 | bellard | |
257 | 6a00d601 | bellard | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
258 | 6a00d601 | bellard | if (env->cpu_index == cpu_index) {
|
259 | 6a00d601 | bellard | mon_cpu = env; |
260 | 6a00d601 | bellard | return 0; |
261 | 6a00d601 | bellard | } |
262 | 6a00d601 | bellard | } |
263 | 6a00d601 | bellard | return -1; |
264 | 6a00d601 | bellard | } |
265 | 6a00d601 | bellard | |
266 | 6a00d601 | bellard | CPUState *mon_get_cpu(void)
|
267 | 6a00d601 | bellard | { |
268 | 6a00d601 | bellard | if (!mon_cpu) {
|
269 | 6a00d601 | bellard | mon_set_cpu(0);
|
270 | 6a00d601 | bellard | } |
271 | 6a00d601 | bellard | return mon_cpu;
|
272 | 6a00d601 | bellard | } |
273 | 6a00d601 | bellard | |
274 | 9307c4c1 | bellard | static void do_info_registers(void) |
275 | 9307c4c1 | bellard | { |
276 | 6a00d601 | bellard | CPUState *env; |
277 | 6a00d601 | bellard | env = mon_get_cpu(); |
278 | 6a00d601 | bellard | if (!env)
|
279 | 6a00d601 | bellard | return;
|
280 | 9307c4c1 | bellard | #ifdef TARGET_I386
|
281 | 6a00d601 | bellard | cpu_dump_state(env, NULL, monitor_fprintf,
|
282 | d24b15a8 | bellard | X86_DUMP_FPU); |
283 | 9307c4c1 | bellard | #else
|
284 | 5fafdf24 | ths | cpu_dump_state(env, NULL, monitor_fprintf,
|
285 | 7fe48483 | bellard | 0);
|
286 | 9307c4c1 | bellard | #endif
|
287 | 9307c4c1 | bellard | } |
288 | 9307c4c1 | bellard | |
289 | 6a00d601 | bellard | static void do_info_cpus(void) |
290 | 6a00d601 | bellard | { |
291 | 6a00d601 | bellard | CPUState *env; |
292 | 6a00d601 | bellard | |
293 | 6a00d601 | bellard | /* just to set the default cpu if not already done */
|
294 | 6a00d601 | bellard | mon_get_cpu(); |
295 | 6a00d601 | bellard | |
296 | 6a00d601 | bellard | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
297 | 5fafdf24 | ths | term_printf("%c CPU #%d:",
|
298 | 6a00d601 | bellard | (env == mon_cpu) ? '*' : ' ', |
299 | 6a00d601 | bellard | env->cpu_index); |
300 | 6a00d601 | bellard | #if defined(TARGET_I386)
|
301 | 6a00d601 | bellard | term_printf(" pc=0x" TARGET_FMT_lx, env->eip + env->segs[R_CS].base);
|
302 | ad49ff9d | bellard | if (env->hflags & HF_HALTED_MASK)
|
303 | 6a00d601 | bellard | term_printf(" (halted)");
|
304 | e80e1cc4 | bellard | #elif defined(TARGET_PPC)
|
305 | e80e1cc4 | bellard | term_printf(" nip=0x" TARGET_FMT_lx, env->nip);
|
306 | 50443c98 | bellard | if (env->halted)
|
307 | e80e1cc4 | bellard | term_printf(" (halted)");
|
308 | ba3c64fb | bellard | #elif defined(TARGET_SPARC)
|
309 | ba3c64fb | bellard | term_printf(" pc=0x" TARGET_FMT_lx " npc=0x" TARGET_FMT_lx, env->pc, env->npc); |
310 | ba3c64fb | bellard | if (env->halted)
|
311 | ba3c64fb | bellard | term_printf(" (halted)");
|
312 | ead9360e | ths | #elif defined(TARGET_MIPS)
|
313 | ead9360e | ths | term_printf(" PC=0x" TARGET_FMT_lx, env->PC[env->current_tc]);
|
314 | ead9360e | ths | if (env->halted)
|
315 | ead9360e | ths | term_printf(" (halted)");
|
316 | 6a00d601 | bellard | #endif
|
317 | 6a00d601 | bellard | term_printf("\n");
|
318 | 6a00d601 | bellard | } |
319 | 6a00d601 | bellard | } |
320 | 6a00d601 | bellard | |
321 | 6a00d601 | bellard | static void do_cpu_set(int index) |
322 | 6a00d601 | bellard | { |
323 | 6a00d601 | bellard | if (mon_set_cpu(index) < 0) |
324 | 6a00d601 | bellard | term_printf("Invalid CPU index\n");
|
325 | 6a00d601 | bellard | } |
326 | 6a00d601 | bellard | |
327 | e3db7226 | bellard | static void do_info_jit(void) |
328 | e3db7226 | bellard | { |
329 | e3db7226 | bellard | dump_exec_info(NULL, monitor_fprintf);
|
330 | e3db7226 | bellard | } |
331 | e3db7226 | bellard | |
332 | aa455485 | bellard | static void do_info_history (void) |
333 | aa455485 | bellard | { |
334 | aa455485 | bellard | int i;
|
335 | 7e2515e8 | bellard | const char *str; |
336 | 3b46e624 | ths | |
337 | 7e2515e8 | bellard | i = 0;
|
338 | 7e2515e8 | bellard | for(;;) {
|
339 | 7e2515e8 | bellard | str = readline_get_history(i); |
340 | 7e2515e8 | bellard | if (!str)
|
341 | 7e2515e8 | bellard | break;
|
342 | 7e2515e8 | bellard | term_printf("%d: '%s'\n", i, str);
|
343 | 8e3a9fd2 | bellard | i++; |
344 | aa455485 | bellard | } |
345 | aa455485 | bellard | } |
346 | aa455485 | bellard | |
347 | 76a66253 | j_mayer | #if defined(TARGET_PPC)
|
348 | 76a66253 | j_mayer | /* XXX: not implemented in other targets */
|
349 | 76a66253 | j_mayer | static void do_info_cpu_stats (void) |
350 | 76a66253 | j_mayer | { |
351 | 76a66253 | j_mayer | CPUState *env; |
352 | 76a66253 | j_mayer | |
353 | 76a66253 | j_mayer | env = mon_get_cpu(); |
354 | 76a66253 | j_mayer | cpu_dump_statistics(env, NULL, &monitor_fprintf, 0); |
355 | 76a66253 | j_mayer | } |
356 | 76a66253 | j_mayer | #endif
|
357 | 76a66253 | j_mayer | |
358 | 9307c4c1 | bellard | static void do_quit(void) |
359 | 9dc39cba | bellard | { |
360 | 9dc39cba | bellard | exit(0);
|
361 | 9dc39cba | bellard | } |
362 | 9dc39cba | bellard | |
363 | 9dc39cba | bellard | static int eject_device(BlockDriverState *bs, int force) |
364 | 9dc39cba | bellard | { |
365 | 9dc39cba | bellard | if (bdrv_is_inserted(bs)) {
|
366 | 9dc39cba | bellard | if (!force) {
|
367 | 9dc39cba | bellard | if (!bdrv_is_removable(bs)) {
|
368 | 9dc39cba | bellard | term_printf("device is not removable\n");
|
369 | 9dc39cba | bellard | return -1; |
370 | 9dc39cba | bellard | } |
371 | 9dc39cba | bellard | if (bdrv_is_locked(bs)) {
|
372 | 9dc39cba | bellard | term_printf("device is locked\n");
|
373 | 9dc39cba | bellard | return -1; |
374 | 9dc39cba | bellard | } |
375 | 9dc39cba | bellard | } |
376 | 9dc39cba | bellard | bdrv_close(bs); |
377 | 9dc39cba | bellard | } |
378 | 9dc39cba | bellard | return 0; |
379 | 9dc39cba | bellard | } |
380 | 9dc39cba | bellard | |
381 | 9307c4c1 | bellard | static void do_eject(int force, const char *filename) |
382 | 9dc39cba | bellard | { |
383 | 9dc39cba | bellard | BlockDriverState *bs; |
384 | 9dc39cba | bellard | |
385 | 9307c4c1 | bellard | bs = bdrv_find(filename); |
386 | 9dc39cba | bellard | if (!bs) {
|
387 | 9dc39cba | bellard | term_printf("device not found\n");
|
388 | 9dc39cba | bellard | return;
|
389 | 9dc39cba | bellard | } |
390 | 9dc39cba | bellard | eject_device(bs, force); |
391 | 9dc39cba | bellard | } |
392 | 9dc39cba | bellard | |
393 | e25a5822 | ths | static void do_change_block(const char *device, const char *filename) |
394 | 9dc39cba | bellard | { |
395 | 9dc39cba | bellard | BlockDriverState *bs; |
396 | 9dc39cba | bellard | |
397 | 9307c4c1 | bellard | bs = bdrv_find(device); |
398 | 9dc39cba | bellard | if (!bs) {
|
399 | 9dc39cba | bellard | term_printf("device not found\n");
|
400 | 9dc39cba | bellard | return;
|
401 | 9dc39cba | bellard | } |
402 | 9dc39cba | bellard | if (eject_device(bs, 0) < 0) |
403 | 9dc39cba | bellard | return;
|
404 | 9307c4c1 | bellard | bdrv_open(bs, filename, 0);
|
405 | 2bac6019 | balrog | qemu_key_check(bs, filename); |
406 | 9dc39cba | bellard | } |
407 | 9dc39cba | bellard | |
408 | e25a5822 | ths | static void do_change_vnc(const char *target) |
409 | e25a5822 | ths | { |
410 | 70848515 | ths | if (strcmp(target, "passwd") == 0 || |
411 | 70848515 | ths | strcmp(target, "password") == 0) { |
412 | 70848515 | ths | char password[9]; |
413 | 70848515 | ths | monitor_readline("Password: ", 1, password, sizeof(password)-1); |
414 | 70848515 | ths | password[sizeof(password)-1] = '\0'; |
415 | 70848515 | ths | if (vnc_display_password(NULL, password) < 0) |
416 | 70848515 | ths | term_printf("could not set VNC server password\n");
|
417 | 70848515 | ths | } else {
|
418 | 70848515 | ths | if (vnc_display_open(NULL, target) < 0) |
419 | 70848515 | ths | term_printf("could not start VNC server on %s\n", target);
|
420 | 70848515 | ths | } |
421 | e25a5822 | ths | } |
422 | e25a5822 | ths | |
423 | e25a5822 | ths | static void do_change(const char *device, const char *target) |
424 | e25a5822 | ths | { |
425 | e25a5822 | ths | if (strcmp(device, "vnc") == 0) { |
426 | e25a5822 | ths | do_change_vnc(target); |
427 | e25a5822 | ths | } else {
|
428 | e25a5822 | ths | do_change_block(device, target); |
429 | e25a5822 | ths | } |
430 | e25a5822 | ths | } |
431 | e25a5822 | ths | |
432 | 9307c4c1 | bellard | static void do_screen_dump(const char *filename) |
433 | 59a983b9 | bellard | { |
434 | 95219897 | pbrook | vga_hw_screen_dump(filename); |
435 | 59a983b9 | bellard | } |
436 | 59a983b9 | bellard | |
437 | e735b91c | pbrook | static void do_logfile(const char *filename) |
438 | e735b91c | pbrook | { |
439 | e735b91c | pbrook | cpu_set_log_filename(filename); |
440 | e735b91c | pbrook | } |
441 | e735b91c | pbrook | |
442 | 9307c4c1 | bellard | static void do_log(const char *items) |
443 | f193c797 | bellard | { |
444 | f193c797 | bellard | int mask;
|
445 | 3b46e624 | ths | |
446 | 9307c4c1 | bellard | if (!strcmp(items, "none")) { |
447 | f193c797 | bellard | mask = 0;
|
448 | f193c797 | bellard | } else {
|
449 | 9307c4c1 | bellard | mask = cpu_str_to_log_mask(items); |
450 | f193c797 | bellard | if (!mask) {
|
451 | 9307c4c1 | bellard | help_cmd("log");
|
452 | f193c797 | bellard | return;
|
453 | f193c797 | bellard | } |
454 | f193c797 | bellard | } |
455 | f193c797 | bellard | cpu_set_log(mask); |
456 | f193c797 | bellard | } |
457 | f193c797 | bellard | |
458 | 9307c4c1 | bellard | static void do_stop(void) |
459 | 8a7ddc38 | bellard | { |
460 | 8a7ddc38 | bellard | vm_stop(EXCP_INTERRUPT); |
461 | 8a7ddc38 | bellard | } |
462 | 8a7ddc38 | bellard | |
463 | 9307c4c1 | bellard | static void do_cont(void) |
464 | 8a7ddc38 | bellard | { |
465 | 8a7ddc38 | bellard | vm_start(); |
466 | 8a7ddc38 | bellard | } |
467 | 8a7ddc38 | bellard | |
468 | 67b915a5 | bellard | #ifdef CONFIG_GDBSTUB
|
469 | cfc3475a | pbrook | static void do_gdbserver(const char *port) |
470 | 8a7ddc38 | bellard | { |
471 | cfc3475a | pbrook | if (!port)
|
472 | 9307c4c1 | bellard | port = DEFAULT_GDBSTUB_PORT; |
473 | cfc3475a | pbrook | if (gdbserver_start(port) < 0) { |
474 | cfc3475a | pbrook | qemu_printf("Could not open gdbserver socket on port '%s'\n", port);
|
475 | 8a7ddc38 | bellard | } else {
|
476 | cfc3475a | pbrook | qemu_printf("Waiting gdb connection on port '%s'\n", port);
|
477 | 8a7ddc38 | bellard | } |
478 | 8a7ddc38 | bellard | } |
479 | 67b915a5 | bellard | #endif
|
480 | 8a7ddc38 | bellard | |
481 | 9307c4c1 | bellard | static void term_printc(int c) |
482 | 9307c4c1 | bellard | { |
483 | 9307c4c1 | bellard | term_printf("'");
|
484 | 9307c4c1 | bellard | switch(c) {
|
485 | 9307c4c1 | bellard | case '\'': |
486 | 9307c4c1 | bellard | term_printf("\\'");
|
487 | 9307c4c1 | bellard | break;
|
488 | 9307c4c1 | bellard | case '\\': |
489 | 9307c4c1 | bellard | term_printf("\\\\");
|
490 | 9307c4c1 | bellard | break;
|
491 | 9307c4c1 | bellard | case '\n': |
492 | 9307c4c1 | bellard | term_printf("\\n");
|
493 | 9307c4c1 | bellard | break;
|
494 | 9307c4c1 | bellard | case '\r': |
495 | 9307c4c1 | bellard | term_printf("\\r");
|
496 | 9307c4c1 | bellard | break;
|
497 | 9307c4c1 | bellard | default:
|
498 | 9307c4c1 | bellard | if (c >= 32 && c <= 126) { |
499 | 9307c4c1 | bellard | term_printf("%c", c);
|
500 | 9307c4c1 | bellard | } else {
|
501 | 9307c4c1 | bellard | term_printf("\\x%02x", c);
|
502 | 9307c4c1 | bellard | } |
503 | 9307c4c1 | bellard | break;
|
504 | 9307c4c1 | bellard | } |
505 | 9307c4c1 | bellard | term_printf("'");
|
506 | 9307c4c1 | bellard | } |
507 | 9307c4c1 | bellard | |
508 | 5fafdf24 | ths | static void memory_dump(int count, int format, int wsize, |
509 | 7743e588 | blueswir1 | target_phys_addr_t addr, int is_physical)
|
510 | 9307c4c1 | bellard | { |
511 | 6a00d601 | bellard | CPUState *env; |
512 | 9307c4c1 | bellard | int nb_per_line, l, line_size, i, max_digits, len;
|
513 | 9307c4c1 | bellard | uint8_t buf[16];
|
514 | 9307c4c1 | bellard | uint64_t v; |
515 | 9307c4c1 | bellard | |
516 | 9307c4c1 | bellard | if (format == 'i') { |
517 | 9307c4c1 | bellard | int flags;
|
518 | 9307c4c1 | bellard | flags = 0;
|
519 | 6a00d601 | bellard | env = mon_get_cpu(); |
520 | 6a00d601 | bellard | if (!env && !is_physical)
|
521 | 6a00d601 | bellard | return;
|
522 | 9307c4c1 | bellard | #ifdef TARGET_I386
|
523 | 4c27ba27 | bellard | if (wsize == 2) { |
524 | 9307c4c1 | bellard | flags = 1;
|
525 | 4c27ba27 | bellard | } else if (wsize == 4) { |
526 | 4c27ba27 | bellard | flags = 0;
|
527 | 4c27ba27 | bellard | } else {
|
528 | 6a15fd12 | bellard | /* as default we use the current CS size */
|
529 | 4c27ba27 | bellard | flags = 0;
|
530 | 6a15fd12 | bellard | if (env) {
|
531 | 6a15fd12 | bellard | #ifdef TARGET_X86_64
|
532 | 5fafdf24 | ths | if ((env->efer & MSR_EFER_LMA) &&
|
533 | 6a15fd12 | bellard | (env->segs[R_CS].flags & DESC_L_MASK)) |
534 | 6a15fd12 | bellard | flags = 2;
|
535 | 6a15fd12 | bellard | else
|
536 | 6a15fd12 | bellard | #endif
|
537 | 6a15fd12 | bellard | if (!(env->segs[R_CS].flags & DESC_B_MASK))
|
538 | 6a15fd12 | bellard | flags = 1;
|
539 | 6a15fd12 | bellard | } |
540 | 4c27ba27 | bellard | } |
541 | 4c27ba27 | bellard | #endif
|
542 | 6a00d601 | bellard | monitor_disas(env, addr, count, is_physical, flags); |
543 | 9307c4c1 | bellard | return;
|
544 | 9307c4c1 | bellard | } |
545 | 9307c4c1 | bellard | |
546 | 9307c4c1 | bellard | len = wsize * count; |
547 | 9307c4c1 | bellard | if (wsize == 1) |
548 | 9307c4c1 | bellard | line_size = 8;
|
549 | 9307c4c1 | bellard | else
|
550 | 9307c4c1 | bellard | line_size = 16;
|
551 | 9307c4c1 | bellard | nb_per_line = line_size / wsize; |
552 | 9307c4c1 | bellard | max_digits = 0;
|
553 | 9307c4c1 | bellard | |
554 | 9307c4c1 | bellard | switch(format) {
|
555 | 9307c4c1 | bellard | case 'o': |
556 | 9307c4c1 | bellard | max_digits = (wsize * 8 + 2) / 3; |
557 | 9307c4c1 | bellard | break;
|
558 | 9307c4c1 | bellard | default:
|
559 | 9307c4c1 | bellard | case 'x': |
560 | 9307c4c1 | bellard | max_digits = (wsize * 8) / 4; |
561 | 9307c4c1 | bellard | break;
|
562 | 9307c4c1 | bellard | case 'u': |
563 | 9307c4c1 | bellard | case 'd': |
564 | 9307c4c1 | bellard | max_digits = (wsize * 8 * 10 + 32) / 33; |
565 | 9307c4c1 | bellard | break;
|
566 | 9307c4c1 | bellard | case 'c': |
567 | 9307c4c1 | bellard | wsize = 1;
|
568 | 9307c4c1 | bellard | break;
|
569 | 9307c4c1 | bellard | } |
570 | 9307c4c1 | bellard | |
571 | 9307c4c1 | bellard | while (len > 0) { |
572 | 7743e588 | blueswir1 | if (is_physical)
|
573 | 7743e588 | blueswir1 | term_printf(TARGET_FMT_plx ":", addr);
|
574 | 7743e588 | blueswir1 | else
|
575 | 7743e588 | blueswir1 | term_printf(TARGET_FMT_lx ":", (target_ulong)addr);
|
576 | 9307c4c1 | bellard | l = len; |
577 | 9307c4c1 | bellard | if (l > line_size)
|
578 | 9307c4c1 | bellard | l = line_size; |
579 | 9307c4c1 | bellard | if (is_physical) {
|
580 | 9307c4c1 | bellard | cpu_physical_memory_rw(addr, buf, l, 0);
|
581 | 9307c4c1 | bellard | } else {
|
582 | 6a00d601 | bellard | env = mon_get_cpu(); |
583 | 6a00d601 | bellard | if (!env)
|
584 | 6a00d601 | bellard | break;
|
585 | 6a00d601 | bellard | cpu_memory_rw_debug(env, addr, buf, l, 0);
|
586 | 9307c4c1 | bellard | } |
587 | 5fafdf24 | ths | i = 0;
|
588 | 9307c4c1 | bellard | while (i < l) {
|
589 | 9307c4c1 | bellard | switch(wsize) {
|
590 | 9307c4c1 | bellard | default:
|
591 | 9307c4c1 | bellard | case 1: |
592 | 9307c4c1 | bellard | v = ldub_raw(buf + i); |
593 | 9307c4c1 | bellard | break;
|
594 | 9307c4c1 | bellard | case 2: |
595 | 9307c4c1 | bellard | v = lduw_raw(buf + i); |
596 | 9307c4c1 | bellard | break;
|
597 | 9307c4c1 | bellard | case 4: |
598 | 92a31b1f | bellard | v = (uint32_t)ldl_raw(buf + i); |
599 | 9307c4c1 | bellard | break;
|
600 | 9307c4c1 | bellard | case 8: |
601 | 9307c4c1 | bellard | v = ldq_raw(buf + i); |
602 | 9307c4c1 | bellard | break;
|
603 | 9307c4c1 | bellard | } |
604 | 9307c4c1 | bellard | term_printf(" ");
|
605 | 9307c4c1 | bellard | switch(format) {
|
606 | 9307c4c1 | bellard | case 'o': |
607 | 26a76461 | bellard | term_printf("%#*" PRIo64, max_digits, v);
|
608 | 9307c4c1 | bellard | break;
|
609 | 9307c4c1 | bellard | case 'x': |
610 | 26a76461 | bellard | term_printf("0x%0*" PRIx64, max_digits, v);
|
611 | 9307c4c1 | bellard | break;
|
612 | 9307c4c1 | bellard | case 'u': |
613 | 26a76461 | bellard | term_printf("%*" PRIu64, max_digits, v);
|
614 | 9307c4c1 | bellard | break;
|
615 | 9307c4c1 | bellard | case 'd': |
616 | 26a76461 | bellard | term_printf("%*" PRId64, max_digits, v);
|
617 | 9307c4c1 | bellard | break;
|
618 | 9307c4c1 | bellard | case 'c': |
619 | 9307c4c1 | bellard | term_printc(v); |
620 | 9307c4c1 | bellard | break;
|
621 | 9307c4c1 | bellard | } |
622 | 9307c4c1 | bellard | i += wsize; |
623 | 9307c4c1 | bellard | } |
624 | 9307c4c1 | bellard | term_printf("\n");
|
625 | 9307c4c1 | bellard | addr += l; |
626 | 9307c4c1 | bellard | len -= l; |
627 | 9307c4c1 | bellard | } |
628 | 9307c4c1 | bellard | } |
629 | 9307c4c1 | bellard | |
630 | 92a31b1f | bellard | #if TARGET_LONG_BITS == 64 |
631 | 92a31b1f | bellard | #define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l)) |
632 | 92a31b1f | bellard | #else
|
633 | 92a31b1f | bellard | #define GET_TLONG(h, l) (l)
|
634 | 92a31b1f | bellard | #endif
|
635 | 92a31b1f | bellard | |
636 | 5fafdf24 | ths | static void do_memory_dump(int count, int format, int size, |
637 | 92a31b1f | bellard | uint32_t addrh, uint32_t addrl) |
638 | 9307c4c1 | bellard | { |
639 | 92a31b1f | bellard | target_long addr = GET_TLONG(addrh, addrl); |
640 | 9307c4c1 | bellard | memory_dump(count, format, size, addr, 0);
|
641 | 9307c4c1 | bellard | } |
642 | 9307c4c1 | bellard | |
643 | 7743e588 | blueswir1 | #if TARGET_PHYS_ADDR_BITS > 32 |
644 | 7743e588 | blueswir1 | #define GET_TPHYSADDR(h, l) (((uint64_t)(h) << 32) | (l)) |
645 | 7743e588 | blueswir1 | #else
|
646 | 7743e588 | blueswir1 | #define GET_TPHYSADDR(h, l) (l)
|
647 | 7743e588 | blueswir1 | #endif
|
648 | 7743e588 | blueswir1 | |
649 | 92a31b1f | bellard | static void do_physical_memory_dump(int count, int format, int size, |
650 | 92a31b1f | bellard | uint32_t addrh, uint32_t addrl) |
651 | 92a31b1f | bellard | |
652 | 9307c4c1 | bellard | { |
653 | 7743e588 | blueswir1 | target_phys_addr_t addr = GET_TPHYSADDR(addrh, addrl); |
654 | 9307c4c1 | bellard | memory_dump(count, format, size, addr, 1);
|
655 | 9307c4c1 | bellard | } |
656 | 9307c4c1 | bellard | |
657 | 92a31b1f | bellard | static void do_print(int count, int format, int size, unsigned int valh, unsigned int vall) |
658 | 9307c4c1 | bellard | { |
659 | 7743e588 | blueswir1 | target_phys_addr_t val = GET_TPHYSADDR(valh, vall); |
660 | 7743e588 | blueswir1 | #if TARGET_PHYS_ADDR_BITS == 32 |
661 | 9307c4c1 | bellard | switch(format) {
|
662 | 9307c4c1 | bellard | case 'o': |
663 | 9307c4c1 | bellard | term_printf("%#o", val);
|
664 | 9307c4c1 | bellard | break;
|
665 | 9307c4c1 | bellard | case 'x': |
666 | 9307c4c1 | bellard | term_printf("%#x", val);
|
667 | 9307c4c1 | bellard | break;
|
668 | 9307c4c1 | bellard | case 'u': |
669 | 9307c4c1 | bellard | term_printf("%u", val);
|
670 | 9307c4c1 | bellard | break;
|
671 | 9307c4c1 | bellard | default:
|
672 | 9307c4c1 | bellard | case 'd': |
673 | 9307c4c1 | bellard | term_printf("%d", val);
|
674 | 9307c4c1 | bellard | break;
|
675 | 9307c4c1 | bellard | case 'c': |
676 | 9307c4c1 | bellard | term_printc(val); |
677 | 9307c4c1 | bellard | break;
|
678 | 9307c4c1 | bellard | } |
679 | 92a31b1f | bellard | #else
|
680 | 92a31b1f | bellard | switch(format) {
|
681 | 92a31b1f | bellard | case 'o': |
682 | 26a76461 | bellard | term_printf("%#" PRIo64, val);
|
683 | 92a31b1f | bellard | break;
|
684 | 92a31b1f | bellard | case 'x': |
685 | 26a76461 | bellard | term_printf("%#" PRIx64, val);
|
686 | 92a31b1f | bellard | break;
|
687 | 92a31b1f | bellard | case 'u': |
688 | 26a76461 | bellard | term_printf("%" PRIu64, val);
|
689 | 92a31b1f | bellard | break;
|
690 | 92a31b1f | bellard | default:
|
691 | 92a31b1f | bellard | case 'd': |
692 | 26a76461 | bellard | term_printf("%" PRId64, val);
|
693 | 92a31b1f | bellard | break;
|
694 | 92a31b1f | bellard | case 'c': |
695 | 92a31b1f | bellard | term_printc(val); |
696 | 92a31b1f | bellard | break;
|
697 | 92a31b1f | bellard | } |
698 | 92a31b1f | bellard | #endif
|
699 | 9307c4c1 | bellard | term_printf("\n");
|
700 | 9307c4c1 | bellard | } |
701 | 9307c4c1 | bellard | |
702 | 5fafdf24 | ths | static void do_memory_save(unsigned int valh, unsigned int vall, |
703 | b371dc59 | bellard | uint32_t size, const char *filename) |
704 | b371dc59 | bellard | { |
705 | b371dc59 | bellard | FILE *f; |
706 | b371dc59 | bellard | target_long addr = GET_TLONG(valh, vall); |
707 | b371dc59 | bellard | uint32_t l; |
708 | b371dc59 | bellard | CPUState *env; |
709 | b371dc59 | bellard | uint8_t buf[1024];
|
710 | b371dc59 | bellard | |
711 | b371dc59 | bellard | env = mon_get_cpu(); |
712 | b371dc59 | bellard | if (!env)
|
713 | b371dc59 | bellard | return;
|
714 | b371dc59 | bellard | |
715 | b371dc59 | bellard | f = fopen(filename, "wb");
|
716 | b371dc59 | bellard | if (!f) {
|
717 | b371dc59 | bellard | term_printf("could not open '%s'\n", filename);
|
718 | b371dc59 | bellard | return;
|
719 | b371dc59 | bellard | } |
720 | b371dc59 | bellard | while (size != 0) { |
721 | b371dc59 | bellard | l = sizeof(buf);
|
722 | b371dc59 | bellard | if (l > size)
|
723 | b371dc59 | bellard | l = size; |
724 | b371dc59 | bellard | cpu_memory_rw_debug(env, addr, buf, l, 0);
|
725 | b371dc59 | bellard | fwrite(buf, 1, l, f);
|
726 | b371dc59 | bellard | addr += l; |
727 | b371dc59 | bellard | size -= l; |
728 | b371dc59 | bellard | } |
729 | b371dc59 | bellard | fclose(f); |
730 | b371dc59 | bellard | } |
731 | b371dc59 | bellard | |
732 | e4cf1adc | bellard | static void do_sum(uint32_t start, uint32_t size) |
733 | e4cf1adc | bellard | { |
734 | e4cf1adc | bellard | uint32_t addr; |
735 | e4cf1adc | bellard | uint8_t buf[1];
|
736 | e4cf1adc | bellard | uint16_t sum; |
737 | e4cf1adc | bellard | |
738 | e4cf1adc | bellard | sum = 0;
|
739 | e4cf1adc | bellard | for(addr = start; addr < (start + size); addr++) {
|
740 | e4cf1adc | bellard | cpu_physical_memory_rw(addr, buf, 1, 0); |
741 | e4cf1adc | bellard | /* BSD sum algorithm ('sum' Unix command) */
|
742 | e4cf1adc | bellard | sum = (sum >> 1) | (sum << 15); |
743 | e4cf1adc | bellard | sum += buf[0];
|
744 | e4cf1adc | bellard | } |
745 | e4cf1adc | bellard | term_printf("%05d\n", sum);
|
746 | e4cf1adc | bellard | } |
747 | e4cf1adc | bellard | |
748 | a3a91a35 | bellard | typedef struct { |
749 | a3a91a35 | bellard | int keycode;
|
750 | a3a91a35 | bellard | const char *name; |
751 | a3a91a35 | bellard | } KeyDef; |
752 | a3a91a35 | bellard | |
753 | a3a91a35 | bellard | static const KeyDef key_defs[] = { |
754 | a3a91a35 | bellard | { 0x2a, "shift" }, |
755 | a3a91a35 | bellard | { 0x36, "shift_r" }, |
756 | 3b46e624 | ths | |
757 | a3a91a35 | bellard | { 0x38, "alt" }, |
758 | a3a91a35 | bellard | { 0xb8, "alt_r" }, |
759 | a3a91a35 | bellard | { 0x1d, "ctrl" }, |
760 | a3a91a35 | bellard | { 0x9d, "ctrl_r" }, |
761 | a3a91a35 | bellard | |
762 | a3a91a35 | bellard | { 0xdd, "menu" }, |
763 | a3a91a35 | bellard | |
764 | a3a91a35 | bellard | { 0x01, "esc" }, |
765 | a3a91a35 | bellard | |
766 | a3a91a35 | bellard | { 0x02, "1" }, |
767 | a3a91a35 | bellard | { 0x03, "2" }, |
768 | a3a91a35 | bellard | { 0x04, "3" }, |
769 | a3a91a35 | bellard | { 0x05, "4" }, |
770 | a3a91a35 | bellard | { 0x06, "5" }, |
771 | a3a91a35 | bellard | { 0x07, "6" }, |
772 | a3a91a35 | bellard | { 0x08, "7" }, |
773 | a3a91a35 | bellard | { 0x09, "8" }, |
774 | a3a91a35 | bellard | { 0x0a, "9" }, |
775 | a3a91a35 | bellard | { 0x0b, "0" }, |
776 | 64866c3d | bellard | { 0x0c, "minus" }, |
777 | 64866c3d | bellard | { 0x0d, "equal" }, |
778 | a3a91a35 | bellard | { 0x0e, "backspace" }, |
779 | a3a91a35 | bellard | |
780 | a3a91a35 | bellard | { 0x0f, "tab" }, |
781 | a3a91a35 | bellard | { 0x10, "q" }, |
782 | a3a91a35 | bellard | { 0x11, "w" }, |
783 | a3a91a35 | bellard | { 0x12, "e" }, |
784 | a3a91a35 | bellard | { 0x13, "r" }, |
785 | a3a91a35 | bellard | { 0x14, "t" }, |
786 | a3a91a35 | bellard | { 0x15, "y" }, |
787 | a3a91a35 | bellard | { 0x16, "u" }, |
788 | a3a91a35 | bellard | { 0x17, "i" }, |
789 | a3a91a35 | bellard | { 0x18, "o" }, |
790 | a3a91a35 | bellard | { 0x19, "p" }, |
791 | a3a91a35 | bellard | |
792 | a3a91a35 | bellard | { 0x1c, "ret" }, |
793 | a3a91a35 | bellard | |
794 | a3a91a35 | bellard | { 0x1e, "a" }, |
795 | a3a91a35 | bellard | { 0x1f, "s" }, |
796 | a3a91a35 | bellard | { 0x20, "d" }, |
797 | a3a91a35 | bellard | { 0x21, "f" }, |
798 | a3a91a35 | bellard | { 0x22, "g" }, |
799 | a3a91a35 | bellard | { 0x23, "h" }, |
800 | a3a91a35 | bellard | { 0x24, "j" }, |
801 | a3a91a35 | bellard | { 0x25, "k" }, |
802 | a3a91a35 | bellard | { 0x26, "l" }, |
803 | a3a91a35 | bellard | |
804 | a3a91a35 | bellard | { 0x2c, "z" }, |
805 | a3a91a35 | bellard | { 0x2d, "x" }, |
806 | a3a91a35 | bellard | { 0x2e, "c" }, |
807 | a3a91a35 | bellard | { 0x2f, "v" }, |
808 | a3a91a35 | bellard | { 0x30, "b" }, |
809 | a3a91a35 | bellard | { 0x31, "n" }, |
810 | a3a91a35 | bellard | { 0x32, "m" }, |
811 | 3b46e624 | ths | |
812 | a3a91a35 | bellard | { 0x39, "spc" }, |
813 | 00ffa62a | bellard | { 0x3a, "caps_lock" }, |
814 | a3a91a35 | bellard | { 0x3b, "f1" }, |
815 | a3a91a35 | bellard | { 0x3c, "f2" }, |
816 | a3a91a35 | bellard | { 0x3d, "f3" }, |
817 | a3a91a35 | bellard | { 0x3e, "f4" }, |
818 | a3a91a35 | bellard | { 0x3f, "f5" }, |
819 | a3a91a35 | bellard | { 0x40, "f6" }, |
820 | a3a91a35 | bellard | { 0x41, "f7" }, |
821 | a3a91a35 | bellard | { 0x42, "f8" }, |
822 | a3a91a35 | bellard | { 0x43, "f9" }, |
823 | a3a91a35 | bellard | { 0x44, "f10" }, |
824 | 00ffa62a | bellard | { 0x45, "num_lock" }, |
825 | a3a91a35 | bellard | { 0x46, "scroll_lock" }, |
826 | a3a91a35 | bellard | |
827 | 64866c3d | bellard | { 0xb5, "kp_divide" }, |
828 | 64866c3d | bellard | { 0x37, "kp_multiply" }, |
829 | 0cfec834 | ths | { 0x4a, "kp_subtract" }, |
830 | 64866c3d | bellard | { 0x4e, "kp_add" }, |
831 | 64866c3d | bellard | { 0x9c, "kp_enter" }, |
832 | 64866c3d | bellard | { 0x53, "kp_decimal" }, |
833 | 64866c3d | bellard | |
834 | 64866c3d | bellard | { 0x52, "kp_0" }, |
835 | 64866c3d | bellard | { 0x4f, "kp_1" }, |
836 | 64866c3d | bellard | { 0x50, "kp_2" }, |
837 | 64866c3d | bellard | { 0x51, "kp_3" }, |
838 | 64866c3d | bellard | { 0x4b, "kp_4" }, |
839 | 64866c3d | bellard | { 0x4c, "kp_5" }, |
840 | 64866c3d | bellard | { 0x4d, "kp_6" }, |
841 | 64866c3d | bellard | { 0x47, "kp_7" }, |
842 | 64866c3d | bellard | { 0x48, "kp_8" }, |
843 | 64866c3d | bellard | { 0x49, "kp_9" }, |
844 | 3b46e624 | ths | |
845 | a3a91a35 | bellard | { 0x56, "<" }, |
846 | a3a91a35 | bellard | |
847 | a3a91a35 | bellard | { 0x57, "f11" }, |
848 | a3a91a35 | bellard | { 0x58, "f12" }, |
849 | a3a91a35 | bellard | |
850 | a3a91a35 | bellard | { 0xb7, "print" }, |
851 | a3a91a35 | bellard | |
852 | a3a91a35 | bellard | { 0xc7, "home" }, |
853 | a3a91a35 | bellard | { 0xc9, "pgup" }, |
854 | a3a91a35 | bellard | { 0xd1, "pgdn" }, |
855 | a3a91a35 | bellard | { 0xcf, "end" }, |
856 | a3a91a35 | bellard | |
857 | a3a91a35 | bellard | { 0xcb, "left" }, |
858 | a3a91a35 | bellard | { 0xc8, "up" }, |
859 | a3a91a35 | bellard | { 0xd0, "down" }, |
860 | a3a91a35 | bellard | { 0xcd, "right" }, |
861 | a3a91a35 | bellard | |
862 | a3a91a35 | bellard | { 0xd2, "insert" }, |
863 | a3a91a35 | bellard | { 0xd3, "delete" }, |
864 | a3a91a35 | bellard | { 0, NULL }, |
865 | a3a91a35 | bellard | }; |
866 | a3a91a35 | bellard | |
867 | a3a91a35 | bellard | static int get_keycode(const char *key) |
868 | a3a91a35 | bellard | { |
869 | a3a91a35 | bellard | const KeyDef *p;
|
870 | 64866c3d | bellard | char *endp;
|
871 | 64866c3d | bellard | int ret;
|
872 | a3a91a35 | bellard | |
873 | a3a91a35 | bellard | for(p = key_defs; p->name != NULL; p++) { |
874 | a3a91a35 | bellard | if (!strcmp(key, p->name))
|
875 | a3a91a35 | bellard | return p->keycode;
|
876 | a3a91a35 | bellard | } |
877 | 64866c3d | bellard | if (strstart(key, "0x", NULL)) { |
878 | 64866c3d | bellard | ret = strtoul(key, &endp, 0);
|
879 | 64866c3d | bellard | if (*endp == '\0' && ret >= 0x01 && ret <= 0xff) |
880 | 64866c3d | bellard | return ret;
|
881 | 64866c3d | bellard | } |
882 | a3a91a35 | bellard | return -1; |
883 | a3a91a35 | bellard | } |
884 | a3a91a35 | bellard | |
885 | a3a91a35 | bellard | static void do_send_key(const char *string) |
886 | a3a91a35 | bellard | { |
887 | a3a91a35 | bellard | char keybuf[16], *q; |
888 | a3a91a35 | bellard | uint8_t keycodes[16];
|
889 | a3a91a35 | bellard | const char *p; |
890 | a3a91a35 | bellard | int nb_keycodes, keycode, i;
|
891 | 3b46e624 | ths | |
892 | a3a91a35 | bellard | nb_keycodes = 0;
|
893 | a3a91a35 | bellard | p = string; |
894 | a3a91a35 | bellard | while (*p != '\0') { |
895 | a3a91a35 | bellard | q = keybuf; |
896 | a3a91a35 | bellard | while (*p != '\0' && *p != '-') { |
897 | a3a91a35 | bellard | if ((q - keybuf) < sizeof(keybuf) - 1) { |
898 | a3a91a35 | bellard | *q++ = *p; |
899 | a3a91a35 | bellard | } |
900 | a3a91a35 | bellard | p++; |
901 | a3a91a35 | bellard | } |
902 | a3a91a35 | bellard | *q = '\0';
|
903 | a3a91a35 | bellard | keycode = get_keycode(keybuf); |
904 | a3a91a35 | bellard | if (keycode < 0) { |
905 | a3a91a35 | bellard | term_printf("unknown key: '%s'\n", keybuf);
|
906 | a3a91a35 | bellard | return;
|
907 | a3a91a35 | bellard | } |
908 | a3a91a35 | bellard | keycodes[nb_keycodes++] = keycode; |
909 | a3a91a35 | bellard | if (*p == '\0') |
910 | a3a91a35 | bellard | break;
|
911 | a3a91a35 | bellard | p++; |
912 | a3a91a35 | bellard | } |
913 | a3a91a35 | bellard | /* key down events */
|
914 | a3a91a35 | bellard | for(i = 0; i < nb_keycodes; i++) { |
915 | a3a91a35 | bellard | keycode = keycodes[i]; |
916 | a3a91a35 | bellard | if (keycode & 0x80) |
917 | a3a91a35 | bellard | kbd_put_keycode(0xe0);
|
918 | a3a91a35 | bellard | kbd_put_keycode(keycode & 0x7f);
|
919 | a3a91a35 | bellard | } |
920 | a3a91a35 | bellard | /* key up events */
|
921 | a3a91a35 | bellard | for(i = nb_keycodes - 1; i >= 0; i--) { |
922 | a3a91a35 | bellard | keycode = keycodes[i]; |
923 | a3a91a35 | bellard | if (keycode & 0x80) |
924 | a3a91a35 | bellard | kbd_put_keycode(0xe0);
|
925 | a3a91a35 | bellard | kbd_put_keycode(keycode | 0x80);
|
926 | a3a91a35 | bellard | } |
927 | a3a91a35 | bellard | } |
928 | a3a91a35 | bellard | |
929 | 13224a87 | bellard | static int mouse_button_state; |
930 | 13224a87 | bellard | |
931 | 5fafdf24 | ths | static void do_mouse_move(const char *dx_str, const char *dy_str, |
932 | 13224a87 | bellard | const char *dz_str) |
933 | 13224a87 | bellard | { |
934 | 13224a87 | bellard | int dx, dy, dz;
|
935 | 13224a87 | bellard | dx = strtol(dx_str, NULL, 0); |
936 | 13224a87 | bellard | dy = strtol(dy_str, NULL, 0); |
937 | 13224a87 | bellard | dz = 0;
|
938 | 5fafdf24 | ths | if (dz_str)
|
939 | 13224a87 | bellard | dz = strtol(dz_str, NULL, 0); |
940 | 13224a87 | bellard | kbd_mouse_event(dx, dy, dz, mouse_button_state); |
941 | 13224a87 | bellard | } |
942 | 13224a87 | bellard | |
943 | 13224a87 | bellard | static void do_mouse_button(int button_state) |
944 | 13224a87 | bellard | { |
945 | 13224a87 | bellard | mouse_button_state = button_state; |
946 | 13224a87 | bellard | kbd_mouse_event(0, 0, 0, mouse_button_state); |
947 | 13224a87 | bellard | } |
948 | 13224a87 | bellard | |
949 | 3440557b | bellard | static void do_ioport_read(int count, int format, int size, int addr, int has_index, int index) |
950 | 3440557b | bellard | { |
951 | 3440557b | bellard | uint32_t val; |
952 | 3440557b | bellard | int suffix;
|
953 | 3440557b | bellard | |
954 | 3440557b | bellard | if (has_index) {
|
955 | 3440557b | bellard | cpu_outb(NULL, addr & 0xffff, index & 0xff); |
956 | 3440557b | bellard | addr++; |
957 | 3440557b | bellard | } |
958 | 3440557b | bellard | addr &= 0xffff;
|
959 | 3440557b | bellard | |
960 | 3440557b | bellard | switch(size) {
|
961 | 3440557b | bellard | default:
|
962 | 3440557b | bellard | case 1: |
963 | 3440557b | bellard | val = cpu_inb(NULL, addr);
|
964 | 3440557b | bellard | suffix = 'b';
|
965 | 3440557b | bellard | break;
|
966 | 3440557b | bellard | case 2: |
967 | 3440557b | bellard | val = cpu_inw(NULL, addr);
|
968 | 3440557b | bellard | suffix = 'w';
|
969 | 3440557b | bellard | break;
|
970 | 3440557b | bellard | case 4: |
971 | 3440557b | bellard | val = cpu_inl(NULL, addr);
|
972 | 3440557b | bellard | suffix = 'l';
|
973 | 3440557b | bellard | break;
|
974 | 3440557b | bellard | } |
975 | 3440557b | bellard | term_printf("port%c[0x%04x] = %#0*x\n",
|
976 | 3440557b | bellard | suffix, addr, size * 2, val);
|
977 | 3440557b | bellard | } |
978 | a3a91a35 | bellard | |
979 | e4f9082b | bellard | static void do_system_reset(void) |
980 | e4f9082b | bellard | { |
981 | e4f9082b | bellard | qemu_system_reset_request(); |
982 | e4f9082b | bellard | } |
983 | e4f9082b | bellard | |
984 | 3475187d | bellard | static void do_system_powerdown(void) |
985 | 3475187d | bellard | { |
986 | 3475187d | bellard | qemu_system_powerdown_request(); |
987 | 3475187d | bellard | } |
988 | 3475187d | bellard | |
989 | b86bda5b | bellard | #if defined(TARGET_I386)
|
990 | b86bda5b | bellard | static void print_pte(uint32_t addr, uint32_t pte, uint32_t mask) |
991 | b86bda5b | bellard | { |
992 | 5fafdf24 | ths | term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
|
993 | b86bda5b | bellard | addr, |
994 | b86bda5b | bellard | pte & mask, |
995 | b86bda5b | bellard | pte & PG_GLOBAL_MASK ? 'G' : '-', |
996 | b86bda5b | bellard | pte & PG_PSE_MASK ? 'P' : '-', |
997 | b86bda5b | bellard | pte & PG_DIRTY_MASK ? 'D' : '-', |
998 | b86bda5b | bellard | pte & PG_ACCESSED_MASK ? 'A' : '-', |
999 | b86bda5b | bellard | pte & PG_PCD_MASK ? 'C' : '-', |
1000 | b86bda5b | bellard | pte & PG_PWT_MASK ? 'T' : '-', |
1001 | b86bda5b | bellard | pte & PG_USER_MASK ? 'U' : '-', |
1002 | b86bda5b | bellard | pte & PG_RW_MASK ? 'W' : '-'); |
1003 | b86bda5b | bellard | } |
1004 | b86bda5b | bellard | |
1005 | b86bda5b | bellard | static void tlb_info(void) |
1006 | b86bda5b | bellard | { |
1007 | 6a00d601 | bellard | CPUState *env; |
1008 | b86bda5b | bellard | int l1, l2;
|
1009 | b86bda5b | bellard | uint32_t pgd, pde, pte; |
1010 | b86bda5b | bellard | |
1011 | 6a00d601 | bellard | env = mon_get_cpu(); |
1012 | 6a00d601 | bellard | if (!env)
|
1013 | 6a00d601 | bellard | return;
|
1014 | 6a00d601 | bellard | |
1015 | b86bda5b | bellard | if (!(env->cr[0] & CR0_PG_MASK)) { |
1016 | b86bda5b | bellard | term_printf("PG disabled\n");
|
1017 | b86bda5b | bellard | return;
|
1018 | b86bda5b | bellard | } |
1019 | b86bda5b | bellard | pgd = env->cr[3] & ~0xfff; |
1020 | b86bda5b | bellard | for(l1 = 0; l1 < 1024; l1++) { |
1021 | b86bda5b | bellard | cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4); |
1022 | b86bda5b | bellard | pde = le32_to_cpu(pde); |
1023 | b86bda5b | bellard | if (pde & PG_PRESENT_MASK) {
|
1024 | b86bda5b | bellard | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
1025 | b86bda5b | bellard | print_pte((l1 << 22), pde, ~((1 << 20) - 1)); |
1026 | b86bda5b | bellard | } else {
|
1027 | b86bda5b | bellard | for(l2 = 0; l2 < 1024; l2++) { |
1028 | 5fafdf24 | ths | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
1029 | b86bda5b | bellard | (uint8_t *)&pte, 4);
|
1030 | b86bda5b | bellard | pte = le32_to_cpu(pte); |
1031 | b86bda5b | bellard | if (pte & PG_PRESENT_MASK) {
|
1032 | 5fafdf24 | ths | print_pte((l1 << 22) + (l2 << 12), |
1033 | 5fafdf24 | ths | pte & ~PG_PSE_MASK, |
1034 | b86bda5b | bellard | ~0xfff);
|
1035 | b86bda5b | bellard | } |
1036 | b86bda5b | bellard | } |
1037 | b86bda5b | bellard | } |
1038 | b86bda5b | bellard | } |
1039 | b86bda5b | bellard | } |
1040 | b86bda5b | bellard | } |
1041 | b86bda5b | bellard | |
1042 | 5fafdf24 | ths | static void mem_print(uint32_t *pstart, int *plast_prot, |
1043 | b86bda5b | bellard | uint32_t end, int prot)
|
1044 | b86bda5b | bellard | { |
1045 | 9746b15b | bellard | int prot1;
|
1046 | 9746b15b | bellard | prot1 = *plast_prot; |
1047 | 9746b15b | bellard | if (prot != prot1) {
|
1048 | b86bda5b | bellard | if (*pstart != -1) { |
1049 | b86bda5b | bellard | term_printf("%08x-%08x %08x %c%c%c\n",
|
1050 | 5fafdf24 | ths | *pstart, end, end - *pstart, |
1051 | 9746b15b | bellard | prot1 & PG_USER_MASK ? 'u' : '-', |
1052 | b86bda5b | bellard | 'r',
|
1053 | 9746b15b | bellard | prot1 & PG_RW_MASK ? 'w' : '-'); |
1054 | b86bda5b | bellard | } |
1055 | b86bda5b | bellard | if (prot != 0) |
1056 | b86bda5b | bellard | *pstart = end; |
1057 | b86bda5b | bellard | else
|
1058 | b86bda5b | bellard | *pstart = -1;
|
1059 | b86bda5b | bellard | *plast_prot = prot; |
1060 | b86bda5b | bellard | } |
1061 | b86bda5b | bellard | } |
1062 | b86bda5b | bellard | |
1063 | b86bda5b | bellard | static void mem_info(void) |
1064 | b86bda5b | bellard | { |
1065 | 6a00d601 | bellard | CPUState *env; |
1066 | b86bda5b | bellard | int l1, l2, prot, last_prot;
|
1067 | b86bda5b | bellard | uint32_t pgd, pde, pte, start, end; |
1068 | b86bda5b | bellard | |
1069 | 6a00d601 | bellard | env = mon_get_cpu(); |
1070 | 6a00d601 | bellard | if (!env)
|
1071 | 6a00d601 | bellard | return;
|
1072 | 6a00d601 | bellard | |
1073 | b86bda5b | bellard | if (!(env->cr[0] & CR0_PG_MASK)) { |
1074 | b86bda5b | bellard | term_printf("PG disabled\n");
|
1075 | b86bda5b | bellard | return;
|
1076 | b86bda5b | bellard | } |
1077 | b86bda5b | bellard | pgd = env->cr[3] & ~0xfff; |
1078 | b86bda5b | bellard | last_prot = 0;
|
1079 | b86bda5b | bellard | start = -1;
|
1080 | b86bda5b | bellard | for(l1 = 0; l1 < 1024; l1++) { |
1081 | b86bda5b | bellard | cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4); |
1082 | b86bda5b | bellard | pde = le32_to_cpu(pde); |
1083 | b86bda5b | bellard | end = l1 << 22;
|
1084 | b86bda5b | bellard | if (pde & PG_PRESENT_MASK) {
|
1085 | b86bda5b | bellard | if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { |
1086 | b86bda5b | bellard | prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); |
1087 | b86bda5b | bellard | mem_print(&start, &last_prot, end, prot); |
1088 | b86bda5b | bellard | } else {
|
1089 | b86bda5b | bellard | for(l2 = 0; l2 < 1024; l2++) { |
1090 | 5fafdf24 | ths | cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, |
1091 | b86bda5b | bellard | (uint8_t *)&pte, 4);
|
1092 | b86bda5b | bellard | pte = le32_to_cpu(pte); |
1093 | b86bda5b | bellard | end = (l1 << 22) + (l2 << 12); |
1094 | b86bda5b | bellard | if (pte & PG_PRESENT_MASK) {
|
1095 | b86bda5b | bellard | prot = pte & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK); |
1096 | b86bda5b | bellard | } else {
|
1097 | b86bda5b | bellard | prot = 0;
|
1098 | b86bda5b | bellard | } |
1099 | b86bda5b | bellard | mem_print(&start, &last_prot, end, prot); |
1100 | b86bda5b | bellard | } |
1101 | b86bda5b | bellard | } |
1102 | b86bda5b | bellard | } else {
|
1103 | b86bda5b | bellard | prot = 0;
|
1104 | b86bda5b | bellard | mem_print(&start, &last_prot, end, prot); |
1105 | b86bda5b | bellard | } |
1106 | b86bda5b | bellard | } |
1107 | b86bda5b | bellard | } |
1108 | b86bda5b | bellard | #endif
|
1109 | b86bda5b | bellard | |
1110 | 0f4c6415 | bellard | static void do_info_kqemu(void) |
1111 | 0f4c6415 | bellard | { |
1112 | 0f4c6415 | bellard | #ifdef USE_KQEMU
|
1113 | 6a00d601 | bellard | CPUState *env; |
1114 | 0f4c6415 | bellard | int val;
|
1115 | 0f4c6415 | bellard | val = 0;
|
1116 | 6a00d601 | bellard | env = mon_get_cpu(); |
1117 | 6a00d601 | bellard | if (!env) {
|
1118 | 6a00d601 | bellard | term_printf("No cpu initialized yet");
|
1119 | 6a00d601 | bellard | return;
|
1120 | 6a00d601 | bellard | } |
1121 | 6a00d601 | bellard | val = env->kqemu_enabled; |
1122 | 5f1ce948 | bellard | term_printf("kqemu support: ");
|
1123 | 5f1ce948 | bellard | switch(val) {
|
1124 | 5f1ce948 | bellard | default:
|
1125 | 5f1ce948 | bellard | case 0: |
1126 | 5f1ce948 | bellard | term_printf("disabled\n");
|
1127 | 5f1ce948 | bellard | break;
|
1128 | 5f1ce948 | bellard | case 1: |
1129 | 5f1ce948 | bellard | term_printf("enabled for user code\n");
|
1130 | 5f1ce948 | bellard | break;
|
1131 | 5f1ce948 | bellard | case 2: |
1132 | 5f1ce948 | bellard | term_printf("enabled for user and kernel code\n");
|
1133 | 5f1ce948 | bellard | break;
|
1134 | 5f1ce948 | bellard | } |
1135 | 0f4c6415 | bellard | #else
|
1136 | 5f1ce948 | bellard | term_printf("kqemu support: not compiled\n");
|
1137 | 0f4c6415 | bellard | #endif
|
1138 | 5fafdf24 | ths | } |
1139 | 0f4c6415 | bellard | |
1140 | 5f1ce948 | bellard | #ifdef CONFIG_PROFILER
|
1141 | 5f1ce948 | bellard | |
1142 | 5f1ce948 | bellard | int64_t kqemu_time; |
1143 | 5f1ce948 | bellard | int64_t qemu_time; |
1144 | 5f1ce948 | bellard | int64_t kqemu_exec_count; |
1145 | 5f1ce948 | bellard | int64_t dev_time; |
1146 | 5f1ce948 | bellard | int64_t kqemu_ret_int_count; |
1147 | 5f1ce948 | bellard | int64_t kqemu_ret_excp_count; |
1148 | 5f1ce948 | bellard | int64_t kqemu_ret_intr_count; |
1149 | 5f1ce948 | bellard | |
1150 | 5f1ce948 | bellard | static void do_info_profile(void) |
1151 | 5f1ce948 | bellard | { |
1152 | 5f1ce948 | bellard | int64_t total; |
1153 | 5f1ce948 | bellard | total = qemu_time; |
1154 | 5f1ce948 | bellard | if (total == 0) |
1155 | 5f1ce948 | bellard | total = 1;
|
1156 | 26a76461 | bellard | term_printf("async time %" PRId64 " (%0.3f)\n", |
1157 | 5f1ce948 | bellard | dev_time, dev_time / (double)ticks_per_sec);
|
1158 | 26a76461 | bellard | term_printf("qemu time %" PRId64 " (%0.3f)\n", |
1159 | 5f1ce948 | bellard | qemu_time, qemu_time / (double)ticks_per_sec);
|
1160 | 26a76461 | bellard | term_printf("kqemu time %" PRId64 " (%0.3f %0.1f%%) count=%" PRId64 " int=%" PRId64 " excp=%" PRId64 " intr=%" PRId64 "\n", |
1161 | 5f1ce948 | bellard | kqemu_time, kqemu_time / (double)ticks_per_sec,
|
1162 | 5f1ce948 | bellard | kqemu_time / (double)total * 100.0, |
1163 | 5f1ce948 | bellard | kqemu_exec_count, |
1164 | 5f1ce948 | bellard | kqemu_ret_int_count, |
1165 | 5f1ce948 | bellard | kqemu_ret_excp_count, |
1166 | 5f1ce948 | bellard | kqemu_ret_intr_count); |
1167 | 5f1ce948 | bellard | qemu_time = 0;
|
1168 | 5f1ce948 | bellard | kqemu_time = 0;
|
1169 | 5f1ce948 | bellard | kqemu_exec_count = 0;
|
1170 | 5f1ce948 | bellard | dev_time = 0;
|
1171 | 5f1ce948 | bellard | kqemu_ret_int_count = 0;
|
1172 | 5f1ce948 | bellard | kqemu_ret_excp_count = 0;
|
1173 | 5f1ce948 | bellard | kqemu_ret_intr_count = 0;
|
1174 | 5f1ce948 | bellard | #ifdef USE_KQEMU
|
1175 | 5f1ce948 | bellard | kqemu_record_dump(); |
1176 | 5f1ce948 | bellard | #endif
|
1177 | 5f1ce948 | bellard | } |
1178 | 5f1ce948 | bellard | #else
|
1179 | 5f1ce948 | bellard | static void do_info_profile(void) |
1180 | 5f1ce948 | bellard | { |
1181 | 5f1ce948 | bellard | term_printf("Internal profiler not compiled\n");
|
1182 | 5f1ce948 | bellard | } |
1183 | 5f1ce948 | bellard | #endif
|
1184 | 5f1ce948 | bellard | |
1185 | ec36b695 | bellard | /* Capture support */
|
1186 | ec36b695 | bellard | static LIST_HEAD (capture_list_head, CaptureState) capture_head;
|
1187 | ec36b695 | bellard | |
1188 | ec36b695 | bellard | static void do_info_capture (void) |
1189 | ec36b695 | bellard | { |
1190 | ec36b695 | bellard | int i;
|
1191 | ec36b695 | bellard | CaptureState *s; |
1192 | ec36b695 | bellard | |
1193 | ec36b695 | bellard | for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { |
1194 | ec36b695 | bellard | term_printf ("[%d]: ", i);
|
1195 | ec36b695 | bellard | s->ops.info (s->opaque); |
1196 | ec36b695 | bellard | } |
1197 | ec36b695 | bellard | } |
1198 | ec36b695 | bellard | |
1199 | ec36b695 | bellard | static void do_stop_capture (int n) |
1200 | ec36b695 | bellard | { |
1201 | ec36b695 | bellard | int i;
|
1202 | ec36b695 | bellard | CaptureState *s; |
1203 | ec36b695 | bellard | |
1204 | ec36b695 | bellard | for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) { |
1205 | ec36b695 | bellard | if (i == n) {
|
1206 | ec36b695 | bellard | s->ops.destroy (s->opaque); |
1207 | ec36b695 | bellard | LIST_REMOVE (s, entries); |
1208 | ec36b695 | bellard | qemu_free (s); |
1209 | ec36b695 | bellard | return;
|
1210 | ec36b695 | bellard | } |
1211 | ec36b695 | bellard | } |
1212 | ec36b695 | bellard | } |
1213 | ec36b695 | bellard | |
1214 | ec36b695 | bellard | #ifdef HAS_AUDIO
|
1215 | ec36b695 | bellard | int wav_start_capture (CaptureState *s, const char *path, int freq, |
1216 | ec36b695 | bellard | int bits, int nchannels); |
1217 | ec36b695 | bellard | |
1218 | ec36b695 | bellard | static void do_wav_capture (const char *path, |
1219 | ec36b695 | bellard | int has_freq, int freq, |
1220 | ec36b695 | bellard | int has_bits, int bits, |
1221 | ec36b695 | bellard | int has_channels, int nchannels) |
1222 | ec36b695 | bellard | { |
1223 | ec36b695 | bellard | CaptureState *s; |
1224 | ec36b695 | bellard | |
1225 | ec36b695 | bellard | s = qemu_mallocz (sizeof (*s));
|
1226 | ec36b695 | bellard | if (!s) {
|
1227 | ec36b695 | bellard | term_printf ("Not enough memory to add wave capture\n");
|
1228 | ec36b695 | bellard | return;
|
1229 | ec36b695 | bellard | } |
1230 | ec36b695 | bellard | |
1231 | ec36b695 | bellard | freq = has_freq ? freq : 44100;
|
1232 | ec36b695 | bellard | bits = has_bits ? bits : 16;
|
1233 | ec36b695 | bellard | nchannels = has_channels ? nchannels : 2;
|
1234 | ec36b695 | bellard | |
1235 | ec36b695 | bellard | if (wav_start_capture (s, path, freq, bits, nchannels)) {
|
1236 | ec36b695 | bellard | term_printf ("Faied to add wave capture\n");
|
1237 | ec36b695 | bellard | qemu_free (s); |
1238 | ec36b695 | bellard | } |
1239 | ec36b695 | bellard | LIST_INSERT_HEAD (&capture_head, s, entries); |
1240 | ec36b695 | bellard | } |
1241 | ec36b695 | bellard | #endif
|
1242 | ec36b695 | bellard | |
1243 | 9dc39cba | bellard | static term_cmd_t term_cmds[] = {
|
1244 | 5fafdf24 | ths | { "help|?", "s?", do_help, |
1245 | 9dc39cba | bellard | "[cmd]", "show the help" }, |
1246 | 5fafdf24 | ths | { "commit", "s", do_commit, |
1247 | 7954c734 | bellard | "device|all", "commit changes to the disk images (if -snapshot is used) or backing files" }, |
1248 | 9307c4c1 | bellard | { "info", "s?", do_info, |
1249 | 9dc39cba | bellard | "subcommand", "show various information about the system state" }, |
1250 | 9307c4c1 | bellard | { "q|quit", "", do_quit, |
1251 | 9dc39cba | bellard | "", "quit the emulator" }, |
1252 | 81d0912d | bellard | { "eject", "-fB", do_eject, |
1253 | e598752a | ths | "[-f] device", "eject a removable medium (use -f to force it)" }, |
1254 | 81d0912d | bellard | { "change", "BF", do_change, |
1255 | e598752a | ths | "device filename", "change a removable medium" }, |
1256 | 5fafdf24 | ths | { "screendump", "F", do_screen_dump, |
1257 | 59a983b9 | bellard | "filename", "save screen into PPM image 'filename'" }, |
1258 | e735b91c | pbrook | { "logfile", "s", do_logfile, |
1259 | e735b91c | pbrook | "filename", "output logs to 'filename'" }, |
1260 | 9307c4c1 | bellard | { "log", "s", do_log, |
1261 | 5fafdf24 | ths | "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" }, |
1262 | faea38e7 | bellard | { "savevm", "s?", do_savevm, |
1263 | 5fafdf24 | ths | "tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" }, |
1264 | faea38e7 | bellard | { "loadvm", "s", do_loadvm, |
1265 | 5fafdf24 | ths | "tag|id", "restore a VM snapshot from its tag or id" }, |
1266 | faea38e7 | bellard | { "delvm", "s", do_delvm, |
1267 | 5fafdf24 | ths | "tag|id", "delete a VM snapshot from its tag or id" }, |
1268 | 5fafdf24 | ths | { "stop", "", do_stop, |
1269 | 9307c4c1 | bellard | "", "stop emulation", }, |
1270 | 5fafdf24 | ths | { "c|cont", "", do_cont, |
1271 | 9307c4c1 | bellard | "", "resume emulation", }, |
1272 | 67b915a5 | bellard | #ifdef CONFIG_GDBSTUB
|
1273 | 5fafdf24 | ths | { "gdbserver", "s?", do_gdbserver, |
1274 | 9307c4c1 | bellard | "[port]", "start gdbserver session (default port=1234)", }, |
1275 | 67b915a5 | bellard | #endif
|
1276 | 5fafdf24 | ths | { "x", "/l", do_memory_dump, |
1277 | 9307c4c1 | bellard | "/fmt addr", "virtual memory dump starting at 'addr'", }, |
1278 | 5fafdf24 | ths | { "xp", "/l", do_physical_memory_dump, |
1279 | 9307c4c1 | bellard | "/fmt addr", "physical memory dump starting at 'addr'", }, |
1280 | 5fafdf24 | ths | { "p|print", "/l", do_print, |
1281 | 9307c4c1 | bellard | "/fmt expr", "print expression value (use $reg for CPU register access)", }, |
1282 | 5fafdf24 | ths | { "i", "/ii.", do_ioport_read, |
1283 | 3440557b | bellard | "/fmt addr", "I/O port read" }, |
1284 | 3440557b | bellard | |
1285 | 5fafdf24 | ths | { "sendkey", "s", do_send_key, |
1286 | a3a91a35 | bellard | "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" }, |
1287 | 5fafdf24 | ths | { "system_reset", "", do_system_reset, |
1288 | e4f9082b | bellard | "", "reset the system" }, |
1289 | 5fafdf24 | ths | { "system_powerdown", "", do_system_powerdown, |
1290 | 3475187d | bellard | "", "send system power down event" }, |
1291 | 5fafdf24 | ths | { "sum", "ii", do_sum, |
1292 | e4cf1adc | bellard | "addr size", "compute the checksum of a memory region" }, |
1293 | a594cfbf | bellard | { "usb_add", "s", do_usb_add, |
1294 | a594cfbf | bellard | "device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" }, |
1295 | a594cfbf | bellard | { "usb_del", "s", do_usb_del, |
1296 | a594cfbf | bellard | "device", "remove USB device 'bus.addr'" }, |
1297 | 5fafdf24 | ths | { "cpu", "i", do_cpu_set, |
1298 | 6a00d601 | bellard | "index", "set the default CPU" }, |
1299 | 5fafdf24 | ths | { "mouse_move", "sss?", do_mouse_move, |
1300 | 13224a87 | bellard | "dx dy [dz]", "send mouse move events" }, |
1301 | 5fafdf24 | ths | { "mouse_button", "i", do_mouse_button, |
1302 | 13224a87 | bellard | "state", "change mouse button state (1=L, 2=M, 4=R)" }, |
1303 | 455204eb | ths | { "mouse_set", "i", do_mouse_set, |
1304 | 455204eb | ths | "index", "set which mouse device receives events" }, |
1305 | ec36b695 | bellard | #ifdef HAS_AUDIO
|
1306 | ec36b695 | bellard | { "wavcapture", "si?i?i?", do_wav_capture, |
1307 | ec36b695 | bellard | "path [frequency bits channels]",
|
1308 | ec36b695 | bellard | "capture audio to a wave file (default frequency=44100 bits=16 channels=2)" },
|
1309 | ec36b695 | bellard | #endif
|
1310 | ec36b695 | bellard | { "stopcapture", "i", do_stop_capture, |
1311 | ec36b695 | bellard | "capture index", "stop capture" }, |
1312 | 5fafdf24 | ths | { "memsave", "lis", do_memory_save, |
1313 | b371dc59 | bellard | "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", }, |
1314 | 5fafdf24 | ths | { NULL, NULL, }, |
1315 | 9dc39cba | bellard | }; |
1316 | 9dc39cba | bellard | |
1317 | 9dc39cba | bellard | static term_cmd_t info_cmds[] = {
|
1318 | 9bc9d1c7 | bellard | { "version", "", do_info_version, |
1319 | 9bc9d1c7 | bellard | "", "show the version of qemu" }, |
1320 | 9307c4c1 | bellard | { "network", "", do_info_network, |
1321 | 9dc39cba | bellard | "", "show the network state" }, |
1322 | 9307c4c1 | bellard | { "block", "", do_info_block, |
1323 | 9dc39cba | bellard | "", "show the block devices" }, |
1324 | 9307c4c1 | bellard | { "registers", "", do_info_registers, |
1325 | 9307c4c1 | bellard | "", "show the cpu registers" }, |
1326 | 6a00d601 | bellard | { "cpus", "", do_info_cpus, |
1327 | 6a00d601 | bellard | "", "show infos for each CPU" }, |
1328 | aa455485 | bellard | { "history", "", do_info_history, |
1329 | aa455485 | bellard | "", "show the command line history", }, |
1330 | 4a0fb71e | bellard | { "irq", "", irq_info, |
1331 | 4a0fb71e | bellard | "", "show the interrupts statistics (if available)", }, |
1332 | 4c27ba27 | bellard | { "pic", "", pic_info, |
1333 | 4c27ba27 | bellard | "", "show i8259 (PIC) state", }, |
1334 | 86e0c048 | bellard | { "pci", "", pci_info, |
1335 | 86e0c048 | bellard | "", "show PCI info", }, |
1336 | b86bda5b | bellard | #if defined(TARGET_I386)
|
1337 | b86bda5b | bellard | { "tlb", "", tlb_info, |
1338 | b86bda5b | bellard | "", "show virtual to physical memory mappings", }, |
1339 | b86bda5b | bellard | { "mem", "", mem_info, |
1340 | b86bda5b | bellard | "", "show the active virtual memory mappings", }, |
1341 | b86bda5b | bellard | #endif
|
1342 | e3db7226 | bellard | { "jit", "", do_info_jit, |
1343 | e3db7226 | bellard | "", "show dynamic compiler info", }, |
1344 | 0f4c6415 | bellard | { "kqemu", "", do_info_kqemu, |
1345 | 0f4c6415 | bellard | "", "show kqemu information", }, |
1346 | a594cfbf | bellard | { "usb", "", usb_info, |
1347 | a594cfbf | bellard | "", "show guest USB devices", }, |
1348 | a594cfbf | bellard | { "usbhost", "", usb_host_info, |
1349 | a594cfbf | bellard | "", "show host USB devices", }, |
1350 | 5f1ce948 | bellard | { "profile", "", do_info_profile, |
1351 | 5f1ce948 | bellard | "", "show profiling information", }, |
1352 | ec36b695 | bellard | { "capture", "", do_info_capture, |
1353 | 17100159 | bellard | "", "show capture information" }, |
1354 | faea38e7 | bellard | { "snapshots", "", do_info_snapshots, |
1355 | 17100159 | bellard | "", "show the currently saved VM snapshots" }, |
1356 | 201a51fc | balrog | { "pcmcia", "", pcmcia_info, |
1357 | 201a51fc | balrog | "", "show guest PCMCIA status" }, |
1358 | 455204eb | ths | { "mice", "", do_info_mice, |
1359 | 455204eb | ths | "", "show which guest mouse is receiving events" }, |
1360 | a9ce8590 | bellard | { "vnc", "", do_info_vnc, |
1361 | a9ce8590 | bellard | "", "show the vnc server status"}, |
1362 | c35734b2 | ths | { "name", "", do_info_name, |
1363 | c35734b2 | ths | "", "show the current VM name" }, |
1364 | 76a66253 | j_mayer | #if defined(TARGET_PPC)
|
1365 | 76a66253 | j_mayer | { "cpustats", "", do_info_cpu_stats, |
1366 | 76a66253 | j_mayer | "", "show CPU statistics", }, |
1367 | 76a66253 | j_mayer | #endif
|
1368 | 9dc39cba | bellard | { NULL, NULL, }, |
1369 | 9dc39cba | bellard | }; |
1370 | 9dc39cba | bellard | |
1371 | 9307c4c1 | bellard | /*******************************************************************/
|
1372 | 9307c4c1 | bellard | |
1373 | 9307c4c1 | bellard | static const char *pch; |
1374 | 9307c4c1 | bellard | static jmp_buf expr_env;
|
1375 | 9307c4c1 | bellard | |
1376 | 92a31b1f | bellard | #define MD_TLONG 0 |
1377 | 92a31b1f | bellard | #define MD_I32 1 |
1378 | 92a31b1f | bellard | |
1379 | 9307c4c1 | bellard | typedef struct MonitorDef { |
1380 | 9307c4c1 | bellard | const char *name; |
1381 | 9307c4c1 | bellard | int offset;
|
1382 | 92a31b1f | bellard | target_long (*get_value)(struct MonitorDef *md, int val); |
1383 | 92a31b1f | bellard | int type;
|
1384 | 9307c4c1 | bellard | } MonitorDef; |
1385 | 9307c4c1 | bellard | |
1386 | 57206fd4 | bellard | #if defined(TARGET_I386)
|
1387 | 92a31b1f | bellard | static target_long monitor_get_pc (struct MonitorDef *md, int val) |
1388 | 57206fd4 | bellard | { |
1389 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1390 | 6a00d601 | bellard | if (!env)
|
1391 | 6a00d601 | bellard | return 0; |
1392 | 6a00d601 | bellard | return env->eip + env->segs[R_CS].base;
|
1393 | 57206fd4 | bellard | } |
1394 | 57206fd4 | bellard | #endif
|
1395 | 57206fd4 | bellard | |
1396 | a541f297 | bellard | #if defined(TARGET_PPC)
|
1397 | 92a31b1f | bellard | static target_long monitor_get_ccr (struct MonitorDef *md, int val) |
1398 | a541f297 | bellard | { |
1399 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1400 | a541f297 | bellard | unsigned int u; |
1401 | a541f297 | bellard | int i;
|
1402 | a541f297 | bellard | |
1403 | 6a00d601 | bellard | if (!env)
|
1404 | 6a00d601 | bellard | return 0; |
1405 | 6a00d601 | bellard | |
1406 | a541f297 | bellard | u = 0;
|
1407 | a541f297 | bellard | for (i = 0; i < 8; i++) |
1408 | 6a00d601 | bellard | u |= env->crf[i] << (32 - (4 * i)); |
1409 | a541f297 | bellard | |
1410 | a541f297 | bellard | return u;
|
1411 | a541f297 | bellard | } |
1412 | a541f297 | bellard | |
1413 | 92a31b1f | bellard | static target_long monitor_get_msr (struct MonitorDef *md, int val) |
1414 | a541f297 | bellard | { |
1415 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1416 | 6a00d601 | bellard | if (!env)
|
1417 | 6a00d601 | bellard | return 0; |
1418 | ff937dba | j_mayer | return do_load_msr(env);
|
1419 | a541f297 | bellard | } |
1420 | a541f297 | bellard | |
1421 | 92a31b1f | bellard | static target_long monitor_get_xer (struct MonitorDef *md, int val) |
1422 | a541f297 | bellard | { |
1423 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1424 | 6a00d601 | bellard | if (!env)
|
1425 | 6a00d601 | bellard | return 0; |
1426 | ff937dba | j_mayer | return ppc_load_xer(env);
|
1427 | a541f297 | bellard | } |
1428 | 9fddaa0c | bellard | |
1429 | 92a31b1f | bellard | static target_long monitor_get_decr (struct MonitorDef *md, int val) |
1430 | 9fddaa0c | bellard | { |
1431 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1432 | 6a00d601 | bellard | if (!env)
|
1433 | 6a00d601 | bellard | return 0; |
1434 | 6a00d601 | bellard | return cpu_ppc_load_decr(env);
|
1435 | 9fddaa0c | bellard | } |
1436 | 9fddaa0c | bellard | |
1437 | 92a31b1f | bellard | static target_long monitor_get_tbu (struct MonitorDef *md, int val) |
1438 | 9fddaa0c | bellard | { |
1439 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1440 | 6a00d601 | bellard | if (!env)
|
1441 | 6a00d601 | bellard | return 0; |
1442 | 6a00d601 | bellard | return cpu_ppc_load_tbu(env);
|
1443 | 9fddaa0c | bellard | } |
1444 | 9fddaa0c | bellard | |
1445 | 92a31b1f | bellard | static target_long monitor_get_tbl (struct MonitorDef *md, int val) |
1446 | 9fddaa0c | bellard | { |
1447 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1448 | 6a00d601 | bellard | if (!env)
|
1449 | 6a00d601 | bellard | return 0; |
1450 | 6a00d601 | bellard | return cpu_ppc_load_tbl(env);
|
1451 | 9fddaa0c | bellard | } |
1452 | a541f297 | bellard | #endif
|
1453 | a541f297 | bellard | |
1454 | e95c8d51 | bellard | #if defined(TARGET_SPARC)
|
1455 | 7b936c0c | bellard | #ifndef TARGET_SPARC64
|
1456 | 92a31b1f | bellard | static target_long monitor_get_psr (struct MonitorDef *md, int val) |
1457 | e95c8d51 | bellard | { |
1458 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1459 | 6a00d601 | bellard | if (!env)
|
1460 | 6a00d601 | bellard | return 0; |
1461 | 6a00d601 | bellard | return GET_PSR(env);
|
1462 | e95c8d51 | bellard | } |
1463 | 7b936c0c | bellard | #endif
|
1464 | e95c8d51 | bellard | |
1465 | 92a31b1f | bellard | static target_long monitor_get_reg(struct MonitorDef *md, int val) |
1466 | e95c8d51 | bellard | { |
1467 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1468 | 6a00d601 | bellard | if (!env)
|
1469 | 6a00d601 | bellard | return 0; |
1470 | 6a00d601 | bellard | return env->regwptr[val];
|
1471 | e95c8d51 | bellard | } |
1472 | e95c8d51 | bellard | #endif
|
1473 | e95c8d51 | bellard | |
1474 | 9307c4c1 | bellard | static MonitorDef monitor_defs[] = {
|
1475 | 9307c4c1 | bellard | #ifdef TARGET_I386
|
1476 | 57206fd4 | bellard | |
1477 | 57206fd4 | bellard | #define SEG(name, seg) \
|
1478 | 92a31b1f | bellard | { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\
|
1479 | 57206fd4 | bellard | { name ".base", offsetof(CPUState, segs[seg].base) },\
|
1480 | 92a31b1f | bellard | { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 }, |
1481 | 57206fd4 | bellard | |
1482 | 9307c4c1 | bellard | { "eax", offsetof(CPUState, regs[0]) }, |
1483 | 9307c4c1 | bellard | { "ecx", offsetof(CPUState, regs[1]) }, |
1484 | 9307c4c1 | bellard | { "edx", offsetof(CPUState, regs[2]) }, |
1485 | 9307c4c1 | bellard | { "ebx", offsetof(CPUState, regs[3]) }, |
1486 | 9307c4c1 | bellard | { "esp|sp", offsetof(CPUState, regs[4]) }, |
1487 | 9307c4c1 | bellard | { "ebp|fp", offsetof(CPUState, regs[5]) }, |
1488 | 9307c4c1 | bellard | { "esi", offsetof(CPUState, regs[6]) }, |
1489 | 01038d2a | bellard | { "edi", offsetof(CPUState, regs[7]) }, |
1490 | 92a31b1f | bellard | #ifdef TARGET_X86_64
|
1491 | 92a31b1f | bellard | { "r8", offsetof(CPUState, regs[8]) }, |
1492 | 92a31b1f | bellard | { "r9", offsetof(CPUState, regs[9]) }, |
1493 | 92a31b1f | bellard | { "r10", offsetof(CPUState, regs[10]) }, |
1494 | 92a31b1f | bellard | { "r11", offsetof(CPUState, regs[11]) }, |
1495 | 92a31b1f | bellard | { "r12", offsetof(CPUState, regs[12]) }, |
1496 | 92a31b1f | bellard | { "r13", offsetof(CPUState, regs[13]) }, |
1497 | 92a31b1f | bellard | { "r14", offsetof(CPUState, regs[14]) }, |
1498 | 92a31b1f | bellard | { "r15", offsetof(CPUState, regs[15]) }, |
1499 | 92a31b1f | bellard | #endif
|
1500 | 9307c4c1 | bellard | { "eflags", offsetof(CPUState, eflags) },
|
1501 | 57206fd4 | bellard | { "eip", offsetof(CPUState, eip) },
|
1502 | 57206fd4 | bellard | SEG("cs", R_CS)
|
1503 | 57206fd4 | bellard | SEG("ds", R_DS)
|
1504 | 57206fd4 | bellard | SEG("es", R_ES)
|
1505 | 01038d2a | bellard | SEG("ss", R_SS)
|
1506 | 57206fd4 | bellard | SEG("fs", R_FS)
|
1507 | 57206fd4 | bellard | SEG("gs", R_GS)
|
1508 | 57206fd4 | bellard | { "pc", 0, monitor_get_pc, }, |
1509 | a541f297 | bellard | #elif defined(TARGET_PPC)
|
1510 | ff937dba | j_mayer | /* General purpose registers */
|
1511 | a541f297 | bellard | { "r0", offsetof(CPUState, gpr[0]) }, |
1512 | a541f297 | bellard | { "r1", offsetof(CPUState, gpr[1]) }, |
1513 | a541f297 | bellard | { "r2", offsetof(CPUState, gpr[2]) }, |
1514 | a541f297 | bellard | { "r3", offsetof(CPUState, gpr[3]) }, |
1515 | a541f297 | bellard | { "r4", offsetof(CPUState, gpr[4]) }, |
1516 | a541f297 | bellard | { "r5", offsetof(CPUState, gpr[5]) }, |
1517 | a541f297 | bellard | { "r6", offsetof(CPUState, gpr[6]) }, |
1518 | a541f297 | bellard | { "r7", offsetof(CPUState, gpr[7]) }, |
1519 | a541f297 | bellard | { "r8", offsetof(CPUState, gpr[8]) }, |
1520 | a541f297 | bellard | { "r9", offsetof(CPUState, gpr[9]) }, |
1521 | a541f297 | bellard | { "r10", offsetof(CPUState, gpr[10]) }, |
1522 | a541f297 | bellard | { "r11", offsetof(CPUState, gpr[11]) }, |
1523 | a541f297 | bellard | { "r12", offsetof(CPUState, gpr[12]) }, |
1524 | a541f297 | bellard | { "r13", offsetof(CPUState, gpr[13]) }, |
1525 | a541f297 | bellard | { "r14", offsetof(CPUState, gpr[14]) }, |
1526 | a541f297 | bellard | { "r15", offsetof(CPUState, gpr[15]) }, |
1527 | a541f297 | bellard | { "r16", offsetof(CPUState, gpr[16]) }, |
1528 | a541f297 | bellard | { "r17", offsetof(CPUState, gpr[17]) }, |
1529 | a541f297 | bellard | { "r18", offsetof(CPUState, gpr[18]) }, |
1530 | a541f297 | bellard | { "r19", offsetof(CPUState, gpr[19]) }, |
1531 | a541f297 | bellard | { "r20", offsetof(CPUState, gpr[20]) }, |
1532 | a541f297 | bellard | { "r21", offsetof(CPUState, gpr[21]) }, |
1533 | a541f297 | bellard | { "r22", offsetof(CPUState, gpr[22]) }, |
1534 | a541f297 | bellard | { "r23", offsetof(CPUState, gpr[23]) }, |
1535 | a541f297 | bellard | { "r24", offsetof(CPUState, gpr[24]) }, |
1536 | a541f297 | bellard | { "r25", offsetof(CPUState, gpr[25]) }, |
1537 | a541f297 | bellard | { "r26", offsetof(CPUState, gpr[26]) }, |
1538 | a541f297 | bellard | { "r27", offsetof(CPUState, gpr[27]) }, |
1539 | a541f297 | bellard | { "r28", offsetof(CPUState, gpr[28]) }, |
1540 | a541f297 | bellard | { "r29", offsetof(CPUState, gpr[29]) }, |
1541 | a541f297 | bellard | { "r30", offsetof(CPUState, gpr[30]) }, |
1542 | a541f297 | bellard | { "r31", offsetof(CPUState, gpr[31]) }, |
1543 | ff937dba | j_mayer | /* Floating point registers */
|
1544 | ff937dba | j_mayer | { "f0", offsetof(CPUState, fpr[0]) }, |
1545 | ff937dba | j_mayer | { "f1", offsetof(CPUState, fpr[1]) }, |
1546 | ff937dba | j_mayer | { "f2", offsetof(CPUState, fpr[2]) }, |
1547 | ff937dba | j_mayer | { "f3", offsetof(CPUState, fpr[3]) }, |
1548 | ff937dba | j_mayer | { "f4", offsetof(CPUState, fpr[4]) }, |
1549 | ff937dba | j_mayer | { "f5", offsetof(CPUState, fpr[5]) }, |
1550 | ff937dba | j_mayer | { "f6", offsetof(CPUState, fpr[6]) }, |
1551 | ff937dba | j_mayer | { "f7", offsetof(CPUState, fpr[7]) }, |
1552 | ff937dba | j_mayer | { "f8", offsetof(CPUState, fpr[8]) }, |
1553 | ff937dba | j_mayer | { "f9", offsetof(CPUState, fpr[9]) }, |
1554 | ff937dba | j_mayer | { "f10", offsetof(CPUState, fpr[10]) }, |
1555 | ff937dba | j_mayer | { "f11", offsetof(CPUState, fpr[11]) }, |
1556 | ff937dba | j_mayer | { "f12", offsetof(CPUState, fpr[12]) }, |
1557 | ff937dba | j_mayer | { "f13", offsetof(CPUState, fpr[13]) }, |
1558 | ff937dba | j_mayer | { "f14", offsetof(CPUState, fpr[14]) }, |
1559 | ff937dba | j_mayer | { "f15", offsetof(CPUState, fpr[15]) }, |
1560 | ff937dba | j_mayer | { "f16", offsetof(CPUState, fpr[16]) }, |
1561 | ff937dba | j_mayer | { "f17", offsetof(CPUState, fpr[17]) }, |
1562 | ff937dba | j_mayer | { "f18", offsetof(CPUState, fpr[18]) }, |
1563 | ff937dba | j_mayer | { "f19", offsetof(CPUState, fpr[19]) }, |
1564 | ff937dba | j_mayer | { "f20", offsetof(CPUState, fpr[20]) }, |
1565 | ff937dba | j_mayer | { "f21", offsetof(CPUState, fpr[21]) }, |
1566 | ff937dba | j_mayer | { "f22", offsetof(CPUState, fpr[22]) }, |
1567 | ff937dba | j_mayer | { "f23", offsetof(CPUState, fpr[23]) }, |
1568 | ff937dba | j_mayer | { "f24", offsetof(CPUState, fpr[24]) }, |
1569 | ff937dba | j_mayer | { "f25", offsetof(CPUState, fpr[25]) }, |
1570 | ff937dba | j_mayer | { "f26", offsetof(CPUState, fpr[26]) }, |
1571 | ff937dba | j_mayer | { "f27", offsetof(CPUState, fpr[27]) }, |
1572 | ff937dba | j_mayer | { "f28", offsetof(CPUState, fpr[28]) }, |
1573 | ff937dba | j_mayer | { "f29", offsetof(CPUState, fpr[29]) }, |
1574 | ff937dba | j_mayer | { "f30", offsetof(CPUState, fpr[30]) }, |
1575 | ff937dba | j_mayer | { "f31", offsetof(CPUState, fpr[31]) }, |
1576 | ff937dba | j_mayer | { "fpscr", offsetof(CPUState, fpscr) },
|
1577 | ff937dba | j_mayer | /* Next instruction pointer */
|
1578 | 57206fd4 | bellard | { "nip|pc", offsetof(CPUState, nip) },
|
1579 | a541f297 | bellard | { "lr", offsetof(CPUState, lr) },
|
1580 | a541f297 | bellard | { "ctr", offsetof(CPUState, ctr) },
|
1581 | 9fddaa0c | bellard | { "decr", 0, &monitor_get_decr, }, |
1582 | a541f297 | bellard | { "ccr", 0, &monitor_get_ccr, }, |
1583 | ff937dba | j_mayer | /* Machine state register */
|
1584 | a541f297 | bellard | { "msr", 0, &monitor_get_msr, }, |
1585 | a541f297 | bellard | { "xer", 0, &monitor_get_xer, }, |
1586 | 9fddaa0c | bellard | { "tbu", 0, &monitor_get_tbu, }, |
1587 | 9fddaa0c | bellard | { "tbl", 0, &monitor_get_tbl, }, |
1588 | ff937dba | j_mayer | #if defined(TARGET_PPC64)
|
1589 | ff937dba | j_mayer | /* Address space register */
|
1590 | ff937dba | j_mayer | { "asr", offsetof(CPUState, asr) },
|
1591 | ff937dba | j_mayer | #endif
|
1592 | ff937dba | j_mayer | /* Segment registers */
|
1593 | a541f297 | bellard | { "sdr1", offsetof(CPUState, sdr1) },
|
1594 | a541f297 | bellard | { "sr0", offsetof(CPUState, sr[0]) }, |
1595 | a541f297 | bellard | { "sr1", offsetof(CPUState, sr[1]) }, |
1596 | a541f297 | bellard | { "sr2", offsetof(CPUState, sr[2]) }, |
1597 | a541f297 | bellard | { "sr3", offsetof(CPUState, sr[3]) }, |
1598 | a541f297 | bellard | { "sr4", offsetof(CPUState, sr[4]) }, |
1599 | a541f297 | bellard | { "sr5", offsetof(CPUState, sr[5]) }, |
1600 | a541f297 | bellard | { "sr6", offsetof(CPUState, sr[6]) }, |
1601 | a541f297 | bellard | { "sr7", offsetof(CPUState, sr[7]) }, |
1602 | a541f297 | bellard | { "sr8", offsetof(CPUState, sr[8]) }, |
1603 | a541f297 | bellard | { "sr9", offsetof(CPUState, sr[9]) }, |
1604 | a541f297 | bellard | { "sr10", offsetof(CPUState, sr[10]) }, |
1605 | a541f297 | bellard | { "sr11", offsetof(CPUState, sr[11]) }, |
1606 | a541f297 | bellard | { "sr12", offsetof(CPUState, sr[12]) }, |
1607 | a541f297 | bellard | { "sr13", offsetof(CPUState, sr[13]) }, |
1608 | a541f297 | bellard | { "sr14", offsetof(CPUState, sr[14]) }, |
1609 | a541f297 | bellard | { "sr15", offsetof(CPUState, sr[15]) }, |
1610 | a541f297 | bellard | /* Too lazy to put BATs and SPRs ... */
|
1611 | e95c8d51 | bellard | #elif defined(TARGET_SPARC)
|
1612 | e95c8d51 | bellard | { "g0", offsetof(CPUState, gregs[0]) }, |
1613 | e95c8d51 | bellard | { "g1", offsetof(CPUState, gregs[1]) }, |
1614 | e95c8d51 | bellard | { "g2", offsetof(CPUState, gregs[2]) }, |
1615 | e95c8d51 | bellard | { "g3", offsetof(CPUState, gregs[3]) }, |
1616 | e95c8d51 | bellard | { "g4", offsetof(CPUState, gregs[4]) }, |
1617 | e95c8d51 | bellard | { "g5", offsetof(CPUState, gregs[5]) }, |
1618 | e95c8d51 | bellard | { "g6", offsetof(CPUState, gregs[6]) }, |
1619 | e95c8d51 | bellard | { "g7", offsetof(CPUState, gregs[7]) }, |
1620 | e95c8d51 | bellard | { "o0", 0, monitor_get_reg }, |
1621 | e95c8d51 | bellard | { "o1", 1, monitor_get_reg }, |
1622 | e95c8d51 | bellard | { "o2", 2, monitor_get_reg }, |
1623 | e95c8d51 | bellard | { "o3", 3, monitor_get_reg }, |
1624 | e95c8d51 | bellard | { "o4", 4, monitor_get_reg }, |
1625 | e95c8d51 | bellard | { "o5", 5, monitor_get_reg }, |
1626 | e95c8d51 | bellard | { "o6", 6, monitor_get_reg }, |
1627 | e95c8d51 | bellard | { "o7", 7, monitor_get_reg }, |
1628 | e95c8d51 | bellard | { "l0", 8, monitor_get_reg }, |
1629 | e95c8d51 | bellard | { "l1", 9, monitor_get_reg }, |
1630 | e95c8d51 | bellard | { "l2", 10, monitor_get_reg }, |
1631 | e95c8d51 | bellard | { "l3", 11, monitor_get_reg }, |
1632 | e95c8d51 | bellard | { "l4", 12, monitor_get_reg }, |
1633 | e95c8d51 | bellard | { "l5", 13, monitor_get_reg }, |
1634 | e95c8d51 | bellard | { "l6", 14, monitor_get_reg }, |
1635 | e95c8d51 | bellard | { "l7", 15, monitor_get_reg }, |
1636 | e95c8d51 | bellard | { "i0", 16, monitor_get_reg }, |
1637 | e95c8d51 | bellard | { "i1", 17, monitor_get_reg }, |
1638 | e95c8d51 | bellard | { "i2", 18, monitor_get_reg }, |
1639 | e95c8d51 | bellard | { "i3", 19, monitor_get_reg }, |
1640 | e95c8d51 | bellard | { "i4", 20, monitor_get_reg }, |
1641 | e95c8d51 | bellard | { "i5", 21, monitor_get_reg }, |
1642 | e95c8d51 | bellard | { "i6", 22, monitor_get_reg }, |
1643 | e95c8d51 | bellard | { "i7", 23, monitor_get_reg }, |
1644 | e95c8d51 | bellard | { "pc", offsetof(CPUState, pc) },
|
1645 | e95c8d51 | bellard | { "npc", offsetof(CPUState, npc) },
|
1646 | e95c8d51 | bellard | { "y", offsetof(CPUState, y) },
|
1647 | 7b936c0c | bellard | #ifndef TARGET_SPARC64
|
1648 | e95c8d51 | bellard | { "psr", 0, &monitor_get_psr, }, |
1649 | e95c8d51 | bellard | { "wim", offsetof(CPUState, wim) },
|
1650 | 7b936c0c | bellard | #endif
|
1651 | e95c8d51 | bellard | { "tbr", offsetof(CPUState, tbr) },
|
1652 | e95c8d51 | bellard | { "fsr", offsetof(CPUState, fsr) },
|
1653 | e95c8d51 | bellard | { "f0", offsetof(CPUState, fpr[0]) }, |
1654 | e95c8d51 | bellard | { "f1", offsetof(CPUState, fpr[1]) }, |
1655 | e95c8d51 | bellard | { "f2", offsetof(CPUState, fpr[2]) }, |
1656 | e95c8d51 | bellard | { "f3", offsetof(CPUState, fpr[3]) }, |
1657 | e95c8d51 | bellard | { "f4", offsetof(CPUState, fpr[4]) }, |
1658 | e95c8d51 | bellard | { "f5", offsetof(CPUState, fpr[5]) }, |
1659 | e95c8d51 | bellard | { "f6", offsetof(CPUState, fpr[6]) }, |
1660 | e95c8d51 | bellard | { "f7", offsetof(CPUState, fpr[7]) }, |
1661 | e95c8d51 | bellard | { "f8", offsetof(CPUState, fpr[8]) }, |
1662 | e95c8d51 | bellard | { "f9", offsetof(CPUState, fpr[9]) }, |
1663 | e95c8d51 | bellard | { "f10", offsetof(CPUState, fpr[10]) }, |
1664 | e95c8d51 | bellard | { "f11", offsetof(CPUState, fpr[11]) }, |
1665 | e95c8d51 | bellard | { "f12", offsetof(CPUState, fpr[12]) }, |
1666 | e95c8d51 | bellard | { "f13", offsetof(CPUState, fpr[13]) }, |
1667 | e95c8d51 | bellard | { "f14", offsetof(CPUState, fpr[14]) }, |
1668 | e95c8d51 | bellard | { "f15", offsetof(CPUState, fpr[15]) }, |
1669 | e95c8d51 | bellard | { "f16", offsetof(CPUState, fpr[16]) }, |
1670 | e95c8d51 | bellard | { "f17", offsetof(CPUState, fpr[17]) }, |
1671 | e95c8d51 | bellard | { "f18", offsetof(CPUState, fpr[18]) }, |
1672 | e95c8d51 | bellard | { "f19", offsetof(CPUState, fpr[19]) }, |
1673 | e95c8d51 | bellard | { "f20", offsetof(CPUState, fpr[20]) }, |
1674 | e95c8d51 | bellard | { "f21", offsetof(CPUState, fpr[21]) }, |
1675 | e95c8d51 | bellard | { "f22", offsetof(CPUState, fpr[22]) }, |
1676 | e95c8d51 | bellard | { "f23", offsetof(CPUState, fpr[23]) }, |
1677 | e95c8d51 | bellard | { "f24", offsetof(CPUState, fpr[24]) }, |
1678 | e95c8d51 | bellard | { "f25", offsetof(CPUState, fpr[25]) }, |
1679 | e95c8d51 | bellard | { "f26", offsetof(CPUState, fpr[26]) }, |
1680 | e95c8d51 | bellard | { "f27", offsetof(CPUState, fpr[27]) }, |
1681 | e95c8d51 | bellard | { "f28", offsetof(CPUState, fpr[28]) }, |
1682 | e95c8d51 | bellard | { "f29", offsetof(CPUState, fpr[29]) }, |
1683 | e95c8d51 | bellard | { "f30", offsetof(CPUState, fpr[30]) }, |
1684 | e95c8d51 | bellard | { "f31", offsetof(CPUState, fpr[31]) }, |
1685 | 7b936c0c | bellard | #ifdef TARGET_SPARC64
|
1686 | 7b936c0c | bellard | { "f32", offsetof(CPUState, fpr[32]) }, |
1687 | 7b936c0c | bellard | { "f34", offsetof(CPUState, fpr[34]) }, |
1688 | 7b936c0c | bellard | { "f36", offsetof(CPUState, fpr[36]) }, |
1689 | 7b936c0c | bellard | { "f38", offsetof(CPUState, fpr[38]) }, |
1690 | 7b936c0c | bellard | { "f40", offsetof(CPUState, fpr[40]) }, |
1691 | 7b936c0c | bellard | { "f42", offsetof(CPUState, fpr[42]) }, |
1692 | 7b936c0c | bellard | { "f44", offsetof(CPUState, fpr[44]) }, |
1693 | 7b936c0c | bellard | { "f46", offsetof(CPUState, fpr[46]) }, |
1694 | 7b936c0c | bellard | { "f48", offsetof(CPUState, fpr[48]) }, |
1695 | 7b936c0c | bellard | { "f50", offsetof(CPUState, fpr[50]) }, |
1696 | 7b936c0c | bellard | { "f52", offsetof(CPUState, fpr[52]) }, |
1697 | 7b936c0c | bellard | { "f54", offsetof(CPUState, fpr[54]) }, |
1698 | 7b936c0c | bellard | { "f56", offsetof(CPUState, fpr[56]) }, |
1699 | 7b936c0c | bellard | { "f58", offsetof(CPUState, fpr[58]) }, |
1700 | 7b936c0c | bellard | { "f60", offsetof(CPUState, fpr[60]) }, |
1701 | 7b936c0c | bellard | { "f62", offsetof(CPUState, fpr[62]) }, |
1702 | 7b936c0c | bellard | { "asi", offsetof(CPUState, asi) },
|
1703 | 7b936c0c | bellard | { "pstate", offsetof(CPUState, pstate) },
|
1704 | 7b936c0c | bellard | { "cansave", offsetof(CPUState, cansave) },
|
1705 | 7b936c0c | bellard | { "canrestore", offsetof(CPUState, canrestore) },
|
1706 | 7b936c0c | bellard | { "otherwin", offsetof(CPUState, otherwin) },
|
1707 | 7b936c0c | bellard | { "wstate", offsetof(CPUState, wstate) },
|
1708 | 7b936c0c | bellard | { "cleanwin", offsetof(CPUState, cleanwin) },
|
1709 | 7b936c0c | bellard | { "fprs", offsetof(CPUState, fprs) },
|
1710 | 7b936c0c | bellard | #endif
|
1711 | 9307c4c1 | bellard | #endif
|
1712 | 9307c4c1 | bellard | { NULL },
|
1713 | 9307c4c1 | bellard | }; |
1714 | 9307c4c1 | bellard | |
1715 | 5fafdf24 | ths | static void expr_error(const char *fmt) |
1716 | 9dc39cba | bellard | { |
1717 | 9307c4c1 | bellard | term_printf(fmt); |
1718 | 9307c4c1 | bellard | term_printf("\n");
|
1719 | 9307c4c1 | bellard | longjmp(expr_env, 1);
|
1720 | 9307c4c1 | bellard | } |
1721 | 9307c4c1 | bellard | |
1722 | 6a00d601 | bellard | /* return 0 if OK, -1 if not found, -2 if no CPU defined */
|
1723 | 92a31b1f | bellard | static int get_monitor_def(target_long *pval, const char *name) |
1724 | 9307c4c1 | bellard | { |
1725 | 9307c4c1 | bellard | MonitorDef *md; |
1726 | 92a31b1f | bellard | void *ptr;
|
1727 | 92a31b1f | bellard | |
1728 | 9307c4c1 | bellard | for(md = monitor_defs; md->name != NULL; md++) { |
1729 | 9307c4c1 | bellard | if (compare_cmd(name, md->name)) {
|
1730 | 9307c4c1 | bellard | if (md->get_value) {
|
1731 | e95c8d51 | bellard | *pval = md->get_value(md, md->offset); |
1732 | 9307c4c1 | bellard | } else {
|
1733 | 6a00d601 | bellard | CPUState *env = mon_get_cpu(); |
1734 | 6a00d601 | bellard | if (!env)
|
1735 | 6a00d601 | bellard | return -2; |
1736 | 6a00d601 | bellard | ptr = (uint8_t *)env + md->offset; |
1737 | 92a31b1f | bellard | switch(md->type) {
|
1738 | 92a31b1f | bellard | case MD_I32:
|
1739 | 92a31b1f | bellard | *pval = *(int32_t *)ptr; |
1740 | 92a31b1f | bellard | break;
|
1741 | 92a31b1f | bellard | case MD_TLONG:
|
1742 | 92a31b1f | bellard | *pval = *(target_long *)ptr; |
1743 | 92a31b1f | bellard | break;
|
1744 | 92a31b1f | bellard | default:
|
1745 | 92a31b1f | bellard | *pval = 0;
|
1746 | 92a31b1f | bellard | break;
|
1747 | 92a31b1f | bellard | } |
1748 | 9307c4c1 | bellard | } |
1749 | 9307c4c1 | bellard | return 0; |
1750 | 9307c4c1 | bellard | } |
1751 | 9307c4c1 | bellard | } |
1752 | 9307c4c1 | bellard | return -1; |
1753 | 9307c4c1 | bellard | } |
1754 | 9307c4c1 | bellard | |
1755 | 9307c4c1 | bellard | static void next(void) |
1756 | 9307c4c1 | bellard | { |
1757 | 9307c4c1 | bellard | if (pch != '\0') { |
1758 | 9307c4c1 | bellard | pch++; |
1759 | 9307c4c1 | bellard | while (isspace(*pch))
|
1760 | 9307c4c1 | bellard | pch++; |
1761 | 9307c4c1 | bellard | } |
1762 | 9307c4c1 | bellard | } |
1763 | 9307c4c1 | bellard | |
1764 | c2efc95d | blueswir1 | static int64_t expr_sum(void); |
1765 | 9307c4c1 | bellard | |
1766 | c2efc95d | blueswir1 | static int64_t expr_unary(void) |
1767 | 9307c4c1 | bellard | { |
1768 | c2efc95d | blueswir1 | int64_t n; |
1769 | 9307c4c1 | bellard | char *p;
|
1770 | 6a00d601 | bellard | int ret;
|
1771 | 9307c4c1 | bellard | |
1772 | 9307c4c1 | bellard | switch(*pch) {
|
1773 | 9307c4c1 | bellard | case '+': |
1774 | 9307c4c1 | bellard | next(); |
1775 | 9307c4c1 | bellard | n = expr_unary(); |
1776 | 9307c4c1 | bellard | break;
|
1777 | 9307c4c1 | bellard | case '-': |
1778 | 9307c4c1 | bellard | next(); |
1779 | 9307c4c1 | bellard | n = -expr_unary(); |
1780 | 9307c4c1 | bellard | break;
|
1781 | 9307c4c1 | bellard | case '~': |
1782 | 9307c4c1 | bellard | next(); |
1783 | 9307c4c1 | bellard | n = ~expr_unary(); |
1784 | 9307c4c1 | bellard | break;
|
1785 | 9307c4c1 | bellard | case '(': |
1786 | 9307c4c1 | bellard | next(); |
1787 | 9307c4c1 | bellard | n = expr_sum(); |
1788 | 9307c4c1 | bellard | if (*pch != ')') { |
1789 | 9307c4c1 | bellard | expr_error("')' expected");
|
1790 | 9307c4c1 | bellard | } |
1791 | 9307c4c1 | bellard | next(); |
1792 | 9307c4c1 | bellard | break;
|
1793 | 81d0912d | bellard | case '\'': |
1794 | 81d0912d | bellard | pch++; |
1795 | 81d0912d | bellard | if (*pch == '\0') |
1796 | 81d0912d | bellard | expr_error("character constant expected");
|
1797 | 81d0912d | bellard | n = *pch; |
1798 | 81d0912d | bellard | pch++; |
1799 | 81d0912d | bellard | if (*pch != '\'') |
1800 | 81d0912d | bellard | expr_error("missing terminating \' character");
|
1801 | 81d0912d | bellard | next(); |
1802 | 81d0912d | bellard | break;
|
1803 | 9307c4c1 | bellard | case '$': |
1804 | 9307c4c1 | bellard | { |
1805 | 9307c4c1 | bellard | char buf[128], *q; |
1806 | 7743e588 | blueswir1 | target_long reg; |
1807 | 3b46e624 | ths | |
1808 | 9307c4c1 | bellard | pch++; |
1809 | 9307c4c1 | bellard | q = buf; |
1810 | 9307c4c1 | bellard | while ((*pch >= 'a' && *pch <= 'z') || |
1811 | 9307c4c1 | bellard | (*pch >= 'A' && *pch <= 'Z') || |
1812 | 9307c4c1 | bellard | (*pch >= '0' && *pch <= '9') || |
1813 | 57206fd4 | bellard | *pch == '_' || *pch == '.') { |
1814 | 9307c4c1 | bellard | if ((q - buf) < sizeof(buf) - 1) |
1815 | 9307c4c1 | bellard | *q++ = *pch; |
1816 | 9307c4c1 | bellard | pch++; |
1817 | 9307c4c1 | bellard | } |
1818 | 9307c4c1 | bellard | while (isspace(*pch))
|
1819 | 9307c4c1 | bellard | pch++; |
1820 | 9307c4c1 | bellard | *q = 0;
|
1821 | 7743e588 | blueswir1 | ret = get_monitor_def(®, buf); |
1822 | 6a00d601 | bellard | if (ret == -1) |
1823 | 9307c4c1 | bellard | expr_error("unknown register");
|
1824 | 5fafdf24 | ths | else if (ret == -2) |
1825 | 6a00d601 | bellard | expr_error("no cpu defined");
|
1826 | 7743e588 | blueswir1 | n = reg; |
1827 | 9307c4c1 | bellard | } |
1828 | 9307c4c1 | bellard | break;
|
1829 | 9307c4c1 | bellard | case '\0': |
1830 | 9307c4c1 | bellard | expr_error("unexpected end of expression");
|
1831 | 9307c4c1 | bellard | n = 0;
|
1832 | 9307c4c1 | bellard | break;
|
1833 | 9307c4c1 | bellard | default:
|
1834 | 7743e588 | blueswir1 | #if TARGET_PHYS_ADDR_BITS > 32 |
1835 | 4f4fbf77 | bellard | n = strtoull(pch, &p, 0);
|
1836 | 4f4fbf77 | bellard | #else
|
1837 | 9307c4c1 | bellard | n = strtoul(pch, &p, 0);
|
1838 | 4f4fbf77 | bellard | #endif
|
1839 | 9307c4c1 | bellard | if (pch == p) {
|
1840 | 9307c4c1 | bellard | expr_error("invalid char in expression");
|
1841 | 9307c4c1 | bellard | } |
1842 | 9307c4c1 | bellard | pch = p; |
1843 | 9307c4c1 | bellard | while (isspace(*pch))
|
1844 | 9307c4c1 | bellard | pch++; |
1845 | 9307c4c1 | bellard | break;
|
1846 | 9307c4c1 | bellard | } |
1847 | 9307c4c1 | bellard | return n;
|
1848 | 9307c4c1 | bellard | } |
1849 | 9307c4c1 | bellard | |
1850 | 9307c4c1 | bellard | |
1851 | c2efc95d | blueswir1 | static int64_t expr_prod(void) |
1852 | 9307c4c1 | bellard | { |
1853 | c2efc95d | blueswir1 | int64_t val, val2; |
1854 | 92a31b1f | bellard | int op;
|
1855 | 3b46e624 | ths | |
1856 | 9307c4c1 | bellard | val = expr_unary(); |
1857 | 9307c4c1 | bellard | for(;;) {
|
1858 | 9307c4c1 | bellard | op = *pch; |
1859 | 9307c4c1 | bellard | if (op != '*' && op != '/' && op != '%') |
1860 | 9307c4c1 | bellard | break;
|
1861 | 9307c4c1 | bellard | next(); |
1862 | 9307c4c1 | bellard | val2 = expr_unary(); |
1863 | 9307c4c1 | bellard | switch(op) {
|
1864 | 9307c4c1 | bellard | default:
|
1865 | 9307c4c1 | bellard | case '*': |
1866 | 9307c4c1 | bellard | val *= val2; |
1867 | 9307c4c1 | bellard | break;
|
1868 | 9307c4c1 | bellard | case '/': |
1869 | 9307c4c1 | bellard | case '%': |
1870 | 5fafdf24 | ths | if (val2 == 0) |
1871 | 5b60212f | bellard | expr_error("division by zero");
|
1872 | 9307c4c1 | bellard | if (op == '/') |
1873 | 9307c4c1 | bellard | val /= val2; |
1874 | 9307c4c1 | bellard | else
|
1875 | 9307c4c1 | bellard | val %= val2; |
1876 | 9307c4c1 | bellard | break;
|
1877 | 9307c4c1 | bellard | } |
1878 | 9307c4c1 | bellard | } |
1879 | 9307c4c1 | bellard | return val;
|
1880 | 9307c4c1 | bellard | } |
1881 | 9307c4c1 | bellard | |
1882 | c2efc95d | blueswir1 | static int64_t expr_logic(void) |
1883 | 9307c4c1 | bellard | { |
1884 | c2efc95d | blueswir1 | int64_t val, val2; |
1885 | 92a31b1f | bellard | int op;
|
1886 | 9307c4c1 | bellard | |
1887 | 9307c4c1 | bellard | val = expr_prod(); |
1888 | 9307c4c1 | bellard | for(;;) {
|
1889 | 9307c4c1 | bellard | op = *pch; |
1890 | 9307c4c1 | bellard | if (op != '&' && op != '|' && op != '^') |
1891 | 9307c4c1 | bellard | break;
|
1892 | 9307c4c1 | bellard | next(); |
1893 | 9307c4c1 | bellard | val2 = expr_prod(); |
1894 | 9307c4c1 | bellard | switch(op) {
|
1895 | 9307c4c1 | bellard | default:
|
1896 | 9307c4c1 | bellard | case '&': |
1897 | 9307c4c1 | bellard | val &= val2; |
1898 | 9307c4c1 | bellard | break;
|
1899 | 9307c4c1 | bellard | case '|': |
1900 | 9307c4c1 | bellard | val |= val2; |
1901 | 9307c4c1 | bellard | break;
|
1902 | 9307c4c1 | bellard | case '^': |
1903 | 9307c4c1 | bellard | val ^= val2; |
1904 | 9307c4c1 | bellard | break;
|
1905 | 9307c4c1 | bellard | } |
1906 | 9307c4c1 | bellard | } |
1907 | 9307c4c1 | bellard | return val;
|
1908 | 9307c4c1 | bellard | } |
1909 | 9307c4c1 | bellard | |
1910 | c2efc95d | blueswir1 | static int64_t expr_sum(void) |
1911 | 9307c4c1 | bellard | { |
1912 | c2efc95d | blueswir1 | int64_t val, val2; |
1913 | 92a31b1f | bellard | int op;
|
1914 | 9307c4c1 | bellard | |
1915 | 9307c4c1 | bellard | val = expr_logic(); |
1916 | 9307c4c1 | bellard | for(;;) {
|
1917 | 9307c4c1 | bellard | op = *pch; |
1918 | 9307c4c1 | bellard | if (op != '+' && op != '-') |
1919 | 9307c4c1 | bellard | break;
|
1920 | 9307c4c1 | bellard | next(); |
1921 | 9307c4c1 | bellard | val2 = expr_logic(); |
1922 | 9307c4c1 | bellard | if (op == '+') |
1923 | 9307c4c1 | bellard | val += val2; |
1924 | 9307c4c1 | bellard | else
|
1925 | 9307c4c1 | bellard | val -= val2; |
1926 | 9307c4c1 | bellard | } |
1927 | 9307c4c1 | bellard | return val;
|
1928 | 9307c4c1 | bellard | } |
1929 | 9307c4c1 | bellard | |
1930 | c2efc95d | blueswir1 | static int get_expr(int64_t *pval, const char **pp) |
1931 | 9307c4c1 | bellard | { |
1932 | 9307c4c1 | bellard | pch = *pp; |
1933 | 9307c4c1 | bellard | if (setjmp(expr_env)) {
|
1934 | 9307c4c1 | bellard | *pp = pch; |
1935 | 9307c4c1 | bellard | return -1; |
1936 | 9307c4c1 | bellard | } |
1937 | 9307c4c1 | bellard | while (isspace(*pch))
|
1938 | 9307c4c1 | bellard | pch++; |
1939 | 9307c4c1 | bellard | *pval = expr_sum(); |
1940 | 9307c4c1 | bellard | *pp = pch; |
1941 | 9307c4c1 | bellard | return 0; |
1942 | 9307c4c1 | bellard | } |
1943 | 9307c4c1 | bellard | |
1944 | 9307c4c1 | bellard | static int get_str(char *buf, int buf_size, const char **pp) |
1945 | 9307c4c1 | bellard | { |
1946 | 9307c4c1 | bellard | const char *p; |
1947 | 9307c4c1 | bellard | char *q;
|
1948 | 9307c4c1 | bellard | int c;
|
1949 | 9307c4c1 | bellard | |
1950 | 81d0912d | bellard | q = buf; |
1951 | 9307c4c1 | bellard | p = *pp; |
1952 | 9307c4c1 | bellard | while (isspace(*p))
|
1953 | 9307c4c1 | bellard | p++; |
1954 | 9307c4c1 | bellard | if (*p == '\0') { |
1955 | 9307c4c1 | bellard | fail:
|
1956 | 81d0912d | bellard | *q = '\0';
|
1957 | 9307c4c1 | bellard | *pp = p; |
1958 | 9307c4c1 | bellard | return -1; |
1959 | 9307c4c1 | bellard | } |
1960 | 9307c4c1 | bellard | if (*p == '\"') { |
1961 | 9307c4c1 | bellard | p++; |
1962 | 9307c4c1 | bellard | while (*p != '\0' && *p != '\"') { |
1963 | 9307c4c1 | bellard | if (*p == '\\') { |
1964 | 9307c4c1 | bellard | p++; |
1965 | 9307c4c1 | bellard | c = *p++; |
1966 | 9307c4c1 | bellard | switch(c) {
|
1967 | 9307c4c1 | bellard | case 'n': |
1968 | 9307c4c1 | bellard | c = '\n';
|
1969 | 9307c4c1 | bellard | break;
|
1970 | 9307c4c1 | bellard | case 'r': |
1971 | 9307c4c1 | bellard | c = '\r';
|
1972 | 9307c4c1 | bellard | break;
|
1973 | 9307c4c1 | bellard | case '\\': |
1974 | 9307c4c1 | bellard | case '\'': |
1975 | 9307c4c1 | bellard | case '\"': |
1976 | 9307c4c1 | bellard | break;
|
1977 | 9307c4c1 | bellard | default:
|
1978 | 9307c4c1 | bellard | qemu_printf("unsupported escape code: '\\%c'\n", c);
|
1979 | 9307c4c1 | bellard | goto fail;
|
1980 | 9307c4c1 | bellard | } |
1981 | 9307c4c1 | bellard | if ((q - buf) < buf_size - 1) { |
1982 | 9307c4c1 | bellard | *q++ = c; |
1983 | 9307c4c1 | bellard | } |
1984 | 9307c4c1 | bellard | } else {
|
1985 | 9307c4c1 | bellard | if ((q - buf) < buf_size - 1) { |
1986 | 9307c4c1 | bellard | *q++ = *p; |
1987 | 9307c4c1 | bellard | } |
1988 | 9307c4c1 | bellard | p++; |
1989 | 9307c4c1 | bellard | } |
1990 | 9307c4c1 | bellard | } |
1991 | 9307c4c1 | bellard | if (*p != '\"') { |
1992 | 5b60212f | bellard | qemu_printf("unterminated string\n");
|
1993 | 9307c4c1 | bellard | goto fail;
|
1994 | 9307c4c1 | bellard | } |
1995 | 9307c4c1 | bellard | p++; |
1996 | 9307c4c1 | bellard | } else {
|
1997 | 9307c4c1 | bellard | while (*p != '\0' && !isspace(*p)) { |
1998 | 9307c4c1 | bellard | if ((q - buf) < buf_size - 1) { |
1999 | 9307c4c1 | bellard | *q++ = *p; |
2000 | 9307c4c1 | bellard | } |
2001 | 9307c4c1 | bellard | p++; |
2002 | 9307c4c1 | bellard | } |
2003 | 9307c4c1 | bellard | } |
2004 | 81d0912d | bellard | *q = '\0';
|
2005 | 9307c4c1 | bellard | *pp = p; |
2006 | 9307c4c1 | bellard | return 0; |
2007 | 9307c4c1 | bellard | } |
2008 | 9307c4c1 | bellard | |
2009 | 9307c4c1 | bellard | static int default_fmt_format = 'x'; |
2010 | 9307c4c1 | bellard | static int default_fmt_size = 4; |
2011 | 9307c4c1 | bellard | |
2012 | 9307c4c1 | bellard | #define MAX_ARGS 16 |
2013 | 9307c4c1 | bellard | |
2014 | 7e2515e8 | bellard | static void monitor_handle_command(const char *cmdline) |
2015 | 9307c4c1 | bellard | { |
2016 | 9307c4c1 | bellard | const char *p, *pstart, *typestr; |
2017 | 9307c4c1 | bellard | char *q;
|
2018 | 9307c4c1 | bellard | int c, nb_args, len, i, has_arg;
|
2019 | 9dc39cba | bellard | term_cmd_t *cmd; |
2020 | 9307c4c1 | bellard | char cmdname[256]; |
2021 | 9307c4c1 | bellard | char buf[1024]; |
2022 | 9307c4c1 | bellard | void *str_allocated[MAX_ARGS];
|
2023 | 9307c4c1 | bellard | void *args[MAX_ARGS];
|
2024 | 9dc39cba | bellard | |
2025 | 9dc39cba | bellard | #ifdef DEBUG
|
2026 | 9dc39cba | bellard | term_printf("command='%s'\n", cmdline);
|
2027 | 9dc39cba | bellard | #endif
|
2028 | 3b46e624 | ths | |
2029 | 9307c4c1 | bellard | /* extract the command name */
|
2030 | 9dc39cba | bellard | p = cmdline; |
2031 | 9307c4c1 | bellard | q = cmdname; |
2032 | 9307c4c1 | bellard | while (isspace(*p))
|
2033 | 9307c4c1 | bellard | p++; |
2034 | 9307c4c1 | bellard | if (*p == '\0') |
2035 | 9307c4c1 | bellard | return;
|
2036 | 9307c4c1 | bellard | pstart = p; |
2037 | 9307c4c1 | bellard | while (*p != '\0' && *p != '/' && !isspace(*p)) |
2038 | 9307c4c1 | bellard | p++; |
2039 | 9307c4c1 | bellard | len = p - pstart; |
2040 | 9307c4c1 | bellard | if (len > sizeof(cmdname) - 1) |
2041 | 9307c4c1 | bellard | len = sizeof(cmdname) - 1; |
2042 | 9307c4c1 | bellard | memcpy(cmdname, pstart, len); |
2043 | 9307c4c1 | bellard | cmdname[len] = '\0';
|
2044 | 3b46e624 | ths | |
2045 | 9307c4c1 | bellard | /* find the command */
|
2046 | 9307c4c1 | bellard | for(cmd = term_cmds; cmd->name != NULL; cmd++) { |
2047 | 5fafdf24 | ths | if (compare_cmd(cmdname, cmd->name))
|
2048 | 9307c4c1 | bellard | goto found;
|
2049 | 9307c4c1 | bellard | } |
2050 | 9307c4c1 | bellard | term_printf("unknown command: '%s'\n", cmdname);
|
2051 | 9307c4c1 | bellard | return;
|
2052 | 9307c4c1 | bellard | found:
|
2053 | 9307c4c1 | bellard | |
2054 | 9307c4c1 | bellard | for(i = 0; i < MAX_ARGS; i++) |
2055 | 9307c4c1 | bellard | str_allocated[i] = NULL;
|
2056 | 3b46e624 | ths | |
2057 | 9307c4c1 | bellard | /* parse the parameters */
|
2058 | 9307c4c1 | bellard | typestr = cmd->args_type; |
2059 | 9307c4c1 | bellard | nb_args = 0;
|
2060 | 9dc39cba | bellard | for(;;) {
|
2061 | 9307c4c1 | bellard | c = *typestr; |
2062 | 9307c4c1 | bellard | if (c == '\0') |
2063 | 9dc39cba | bellard | break;
|
2064 | 9307c4c1 | bellard | typestr++; |
2065 | 9307c4c1 | bellard | switch(c) {
|
2066 | 9307c4c1 | bellard | case 'F': |
2067 | 81d0912d | bellard | case 'B': |
2068 | 9307c4c1 | bellard | case 's': |
2069 | 9307c4c1 | bellard | { |
2070 | 9307c4c1 | bellard | int ret;
|
2071 | 9307c4c1 | bellard | char *str;
|
2072 | 3b46e624 | ths | |
2073 | 5fafdf24 | ths | while (isspace(*p))
|
2074 | 9307c4c1 | bellard | p++; |
2075 | 9307c4c1 | bellard | if (*typestr == '?') { |
2076 | 9307c4c1 | bellard | typestr++; |
2077 | 9307c4c1 | bellard | if (*p == '\0') { |
2078 | 9307c4c1 | bellard | /* no optional string: NULL argument */
|
2079 | 9307c4c1 | bellard | str = NULL;
|
2080 | 9307c4c1 | bellard | goto add_str;
|
2081 | 9307c4c1 | bellard | } |
2082 | 9307c4c1 | bellard | } |
2083 | 9307c4c1 | bellard | ret = get_str(buf, sizeof(buf), &p);
|
2084 | 9307c4c1 | bellard | if (ret < 0) { |
2085 | 81d0912d | bellard | switch(c) {
|
2086 | 81d0912d | bellard | case 'F': |
2087 | 9307c4c1 | bellard | term_printf("%s: filename expected\n", cmdname);
|
2088 | 81d0912d | bellard | break;
|
2089 | 81d0912d | bellard | case 'B': |
2090 | 81d0912d | bellard | term_printf("%s: block device name expected\n", cmdname);
|
2091 | 81d0912d | bellard | break;
|
2092 | 81d0912d | bellard | default:
|
2093 | 9307c4c1 | bellard | term_printf("%s: string expected\n", cmdname);
|
2094 | 81d0912d | bellard | break;
|
2095 | 81d0912d | bellard | } |
2096 | 9307c4c1 | bellard | goto fail;
|
2097 | 9307c4c1 | bellard | } |
2098 | 9307c4c1 | bellard | str = qemu_malloc(strlen(buf) + 1);
|
2099 | 9307c4c1 | bellard | strcpy(str, buf); |
2100 | 9307c4c1 | bellard | str_allocated[nb_args] = str; |
2101 | 9307c4c1 | bellard | add_str:
|
2102 | 9307c4c1 | bellard | if (nb_args >= MAX_ARGS) {
|
2103 | 9307c4c1 | bellard | error_args:
|
2104 | 9307c4c1 | bellard | term_printf("%s: too many arguments\n", cmdname);
|
2105 | 9307c4c1 | bellard | goto fail;
|
2106 | 9307c4c1 | bellard | } |
2107 | 9307c4c1 | bellard | args[nb_args++] = str; |
2108 | 9307c4c1 | bellard | } |
2109 | 9dc39cba | bellard | break;
|
2110 | 9307c4c1 | bellard | case '/': |
2111 | 9307c4c1 | bellard | { |
2112 | 9307c4c1 | bellard | int count, format, size;
|
2113 | 3b46e624 | ths | |
2114 | 9307c4c1 | bellard | while (isspace(*p))
|
2115 | 9307c4c1 | bellard | p++; |
2116 | 9307c4c1 | bellard | if (*p == '/') { |
2117 | 9307c4c1 | bellard | /* format found */
|
2118 | 9307c4c1 | bellard | p++; |
2119 | 9307c4c1 | bellard | count = 1;
|
2120 | 9307c4c1 | bellard | if (isdigit(*p)) {
|
2121 | 9307c4c1 | bellard | count = 0;
|
2122 | 9307c4c1 | bellard | while (isdigit(*p)) {
|
2123 | 9307c4c1 | bellard | count = count * 10 + (*p - '0'); |
2124 | 9307c4c1 | bellard | p++; |
2125 | 9307c4c1 | bellard | } |
2126 | 9307c4c1 | bellard | } |
2127 | 9307c4c1 | bellard | size = -1;
|
2128 | 9307c4c1 | bellard | format = -1;
|
2129 | 9307c4c1 | bellard | for(;;) {
|
2130 | 9307c4c1 | bellard | switch(*p) {
|
2131 | 9307c4c1 | bellard | case 'o': |
2132 | 9307c4c1 | bellard | case 'd': |
2133 | 9307c4c1 | bellard | case 'u': |
2134 | 9307c4c1 | bellard | case 'x': |
2135 | 9307c4c1 | bellard | case 'i': |
2136 | 9307c4c1 | bellard | case 'c': |
2137 | 9307c4c1 | bellard | format = *p++; |
2138 | 9307c4c1 | bellard | break;
|
2139 | 9307c4c1 | bellard | case 'b': |
2140 | 9307c4c1 | bellard | size = 1;
|
2141 | 9307c4c1 | bellard | p++; |
2142 | 9307c4c1 | bellard | break;
|
2143 | 9307c4c1 | bellard | case 'h': |
2144 | 9307c4c1 | bellard | size = 2;
|
2145 | 9307c4c1 | bellard | p++; |
2146 | 9307c4c1 | bellard | break;
|
2147 | 9307c4c1 | bellard | case 'w': |
2148 | 9307c4c1 | bellard | size = 4;
|
2149 | 9307c4c1 | bellard | p++; |
2150 | 9307c4c1 | bellard | break;
|
2151 | 9307c4c1 | bellard | case 'g': |
2152 | 9307c4c1 | bellard | case 'L': |
2153 | 9307c4c1 | bellard | size = 8;
|
2154 | 9307c4c1 | bellard | p++; |
2155 | 9307c4c1 | bellard | break;
|
2156 | 9307c4c1 | bellard | default:
|
2157 | 9307c4c1 | bellard | goto next;
|
2158 | 9307c4c1 | bellard | } |
2159 | 9307c4c1 | bellard | } |
2160 | 9307c4c1 | bellard | next:
|
2161 | 9307c4c1 | bellard | if (*p != '\0' && !isspace(*p)) { |
2162 | 9307c4c1 | bellard | term_printf("invalid char in format: '%c'\n", *p);
|
2163 | 9307c4c1 | bellard | goto fail;
|
2164 | 9307c4c1 | bellard | } |
2165 | 9307c4c1 | bellard | if (format < 0) |
2166 | 9307c4c1 | bellard | format = default_fmt_format; |
2167 | 4c27ba27 | bellard | if (format != 'i') { |
2168 | 4c27ba27 | bellard | /* for 'i', not specifying a size gives -1 as size */
|
2169 | 4c27ba27 | bellard | if (size < 0) |
2170 | 4c27ba27 | bellard | size = default_fmt_size; |
2171 | 4c27ba27 | bellard | } |
2172 | 9307c4c1 | bellard | default_fmt_size = size; |
2173 | 9307c4c1 | bellard | default_fmt_format = format; |
2174 | 9307c4c1 | bellard | } else {
|
2175 | 9307c4c1 | bellard | count = 1;
|
2176 | 9307c4c1 | bellard | format = default_fmt_format; |
2177 | 4c27ba27 | bellard | if (format != 'i') { |
2178 | 4c27ba27 | bellard | size = default_fmt_size; |
2179 | 4c27ba27 | bellard | } else {
|
2180 | 4c27ba27 | bellard | size = -1;
|
2181 | 4c27ba27 | bellard | } |
2182 | 9307c4c1 | bellard | } |
2183 | 9307c4c1 | bellard | if (nb_args + 3 > MAX_ARGS) |
2184 | 9307c4c1 | bellard | goto error_args;
|
2185 | 1c5bf3bf | j_mayer | args[nb_args++] = (void*)(long)count; |
2186 | 1c5bf3bf | j_mayer | args[nb_args++] = (void*)(long)format; |
2187 | 1c5bf3bf | j_mayer | args[nb_args++] = (void*)(long)size; |
2188 | 9307c4c1 | bellard | } |
2189 | 9dc39cba | bellard | break;
|
2190 | 9307c4c1 | bellard | case 'i': |
2191 | 92a31b1f | bellard | case 'l': |
2192 | 9307c4c1 | bellard | { |
2193 | c2efc95d | blueswir1 | int64_t val; |
2194 | 7743e588 | blueswir1 | |
2195 | 5fafdf24 | ths | while (isspace(*p))
|
2196 | 9307c4c1 | bellard | p++; |
2197 | 3440557b | bellard | if (*typestr == '?' || *typestr == '.') { |
2198 | 3440557b | bellard | if (*typestr == '?') { |
2199 | 3440557b | bellard | if (*p == '\0') |
2200 | 3440557b | bellard | has_arg = 0;
|
2201 | 3440557b | bellard | else
|
2202 | 3440557b | bellard | has_arg = 1;
|
2203 | 3440557b | bellard | } else {
|
2204 | 3440557b | bellard | if (*p == '.') { |
2205 | 3440557b | bellard | p++; |
2206 | 5fafdf24 | ths | while (isspace(*p))
|
2207 | 3440557b | bellard | p++; |
2208 | 3440557b | bellard | has_arg = 1;
|
2209 | 3440557b | bellard | } else {
|
2210 | 3440557b | bellard | has_arg = 0;
|
2211 | 3440557b | bellard | } |
2212 | 3440557b | bellard | } |
2213 | 13224a87 | bellard | typestr++; |
2214 | 9307c4c1 | bellard | if (nb_args >= MAX_ARGS)
|
2215 | 9307c4c1 | bellard | goto error_args;
|
2216 | 1c5bf3bf | j_mayer | args[nb_args++] = (void *)(long)has_arg; |
2217 | 9307c4c1 | bellard | if (!has_arg) {
|
2218 | 9307c4c1 | bellard | if (nb_args >= MAX_ARGS)
|
2219 | 9307c4c1 | bellard | goto error_args;
|
2220 | 9307c4c1 | bellard | val = -1;
|
2221 | 9307c4c1 | bellard | goto add_num;
|
2222 | 9307c4c1 | bellard | } |
2223 | 9307c4c1 | bellard | } |
2224 | 9307c4c1 | bellard | if (get_expr(&val, &p))
|
2225 | 9307c4c1 | bellard | goto fail;
|
2226 | 9307c4c1 | bellard | add_num:
|
2227 | 92a31b1f | bellard | if (c == 'i') { |
2228 | 92a31b1f | bellard | if (nb_args >= MAX_ARGS)
|
2229 | 92a31b1f | bellard | goto error_args;
|
2230 | 1c5bf3bf | j_mayer | args[nb_args++] = (void *)(long)val; |
2231 | 92a31b1f | bellard | } else {
|
2232 | 92a31b1f | bellard | if ((nb_args + 1) >= MAX_ARGS) |
2233 | 92a31b1f | bellard | goto error_args;
|
2234 | 7743e588 | blueswir1 | #if TARGET_PHYS_ADDR_BITS > 32 |
2235 | 1c5bf3bf | j_mayer | args[nb_args++] = (void *)(long)((val >> 32) & 0xffffffff); |
2236 | 92a31b1f | bellard | #else
|
2237 | 92a31b1f | bellard | args[nb_args++] = (void *)0; |
2238 | 92a31b1f | bellard | #endif
|
2239 | 1c5bf3bf | j_mayer | args[nb_args++] = (void *)(long)(val & 0xffffffff); |
2240 | 92a31b1f | bellard | } |
2241 | 9307c4c1 | bellard | } |
2242 | 9307c4c1 | bellard | break;
|
2243 | 9307c4c1 | bellard | case '-': |
2244 | 9307c4c1 | bellard | { |
2245 | 9307c4c1 | bellard | int has_option;
|
2246 | 9307c4c1 | bellard | /* option */
|
2247 | 3b46e624 | ths | |
2248 | 9307c4c1 | bellard | c = *typestr++; |
2249 | 9307c4c1 | bellard | if (c == '\0') |
2250 | 9307c4c1 | bellard | goto bad_type;
|
2251 | 5fafdf24 | ths | while (isspace(*p))
|
2252 | 9307c4c1 | bellard | p++; |
2253 | 9307c4c1 | bellard | has_option = 0;
|
2254 | 9307c4c1 | bellard | if (*p == '-') { |
2255 | 9307c4c1 | bellard | p++; |
2256 | 9307c4c1 | bellard | if (*p != c) {
|
2257 | 5fafdf24 | ths | term_printf("%s: unsupported option -%c\n",
|
2258 | 9307c4c1 | bellard | cmdname, *p); |
2259 | 9307c4c1 | bellard | goto fail;
|
2260 | 9307c4c1 | bellard | } |
2261 | 9307c4c1 | bellard | p++; |
2262 | 9307c4c1 | bellard | has_option = 1;
|
2263 | 9307c4c1 | bellard | } |
2264 | 9307c4c1 | bellard | if (nb_args >= MAX_ARGS)
|
2265 | 9307c4c1 | bellard | goto error_args;
|
2266 | 1c5bf3bf | j_mayer | args[nb_args++] = (void *)(long)has_option; |
2267 | 9307c4c1 | bellard | } |
2268 | 9307c4c1 | bellard | break;
|
2269 | 9307c4c1 | bellard | default:
|
2270 | 9307c4c1 | bellard | bad_type:
|
2271 | 9307c4c1 | bellard | term_printf("%s: unknown type '%c'\n", cmdname, c);
|
2272 | 9307c4c1 | bellard | goto fail;
|
2273 | 9307c4c1 | bellard | } |
2274 | 9dc39cba | bellard | } |
2275 | 9307c4c1 | bellard | /* check that all arguments were parsed */
|
2276 | 9307c4c1 | bellard | while (isspace(*p))
|
2277 | 9307c4c1 | bellard | p++; |
2278 | 9307c4c1 | bellard | if (*p != '\0') { |
2279 | 5fafdf24 | ths | term_printf("%s: extraneous characters at the end of line\n",
|
2280 | 9307c4c1 | bellard | cmdname); |
2281 | 9307c4c1 | bellard | goto fail;
|
2282 | 9dc39cba | bellard | } |
2283 | 9307c4c1 | bellard | |
2284 | 9307c4c1 | bellard | switch(nb_args) {
|
2285 | 9307c4c1 | bellard | case 0: |
2286 | 9307c4c1 | bellard | cmd->handler(); |
2287 | 9307c4c1 | bellard | break;
|
2288 | 9307c4c1 | bellard | case 1: |
2289 | 9307c4c1 | bellard | cmd->handler(args[0]);
|
2290 | 9307c4c1 | bellard | break;
|
2291 | 9307c4c1 | bellard | case 2: |
2292 | 9307c4c1 | bellard | cmd->handler(args[0], args[1]); |
2293 | 9307c4c1 | bellard | break;
|
2294 | 9307c4c1 | bellard | case 3: |
2295 | 9307c4c1 | bellard | cmd->handler(args[0], args[1], args[2]); |
2296 | 9307c4c1 | bellard | break;
|
2297 | 9307c4c1 | bellard | case 4: |
2298 | 9307c4c1 | bellard | cmd->handler(args[0], args[1], args[2], args[3]); |
2299 | 9307c4c1 | bellard | break;
|
2300 | 9307c4c1 | bellard | case 5: |
2301 | 9307c4c1 | bellard | cmd->handler(args[0], args[1], args[2], args[3], args[4]); |
2302 | 9307c4c1 | bellard | break;
|
2303 | 3440557b | bellard | case 6: |
2304 | 3440557b | bellard | cmd->handler(args[0], args[1], args[2], args[3], args[4], args[5]); |
2305 | 3440557b | bellard | break;
|
2306 | ec36b695 | bellard | case 7: |
2307 | ec36b695 | bellard | cmd->handler(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); |
2308 | ec36b695 | bellard | break;
|
2309 | 9307c4c1 | bellard | default:
|
2310 | 9307c4c1 | bellard | term_printf("unsupported number of arguments: %d\n", nb_args);
|
2311 | 9307c4c1 | bellard | goto fail;
|
2312 | 9dc39cba | bellard | } |
2313 | 9307c4c1 | bellard | fail:
|
2314 | 9307c4c1 | bellard | for(i = 0; i < MAX_ARGS; i++) |
2315 | 9307c4c1 | bellard | qemu_free(str_allocated[i]); |
2316 | 9dc39cba | bellard | return;
|
2317 | 9dc39cba | bellard | } |
2318 | 9dc39cba | bellard | |
2319 | 81d0912d | bellard | static void cmd_completion(const char *name, const char *list) |
2320 | 81d0912d | bellard | { |
2321 | 81d0912d | bellard | const char *p, *pstart; |
2322 | 81d0912d | bellard | char cmd[128]; |
2323 | 81d0912d | bellard | int len;
|
2324 | 81d0912d | bellard | |
2325 | 81d0912d | bellard | p = list; |
2326 | 81d0912d | bellard | for(;;) {
|
2327 | 81d0912d | bellard | pstart = p; |
2328 | 81d0912d | bellard | p = strchr(p, '|');
|
2329 | 81d0912d | bellard | if (!p)
|
2330 | 81d0912d | bellard | p = pstart + strlen(pstart); |
2331 | 81d0912d | bellard | len = p - pstart; |
2332 | 81d0912d | bellard | if (len > sizeof(cmd) - 2) |
2333 | 81d0912d | bellard | len = sizeof(cmd) - 2; |
2334 | 81d0912d | bellard | memcpy(cmd, pstart, len); |
2335 | 81d0912d | bellard | cmd[len] = '\0';
|
2336 | 81d0912d | bellard | if (name[0] == '\0' || !strncmp(name, cmd, strlen(name))) { |
2337 | 81d0912d | bellard | add_completion(cmd); |
2338 | 81d0912d | bellard | } |
2339 | 81d0912d | bellard | if (*p == '\0') |
2340 | 81d0912d | bellard | break;
|
2341 | 81d0912d | bellard | p++; |
2342 | 81d0912d | bellard | } |
2343 | 81d0912d | bellard | } |
2344 | 81d0912d | bellard | |
2345 | 81d0912d | bellard | static void file_completion(const char *input) |
2346 | 81d0912d | bellard | { |
2347 | 81d0912d | bellard | DIR *ffs; |
2348 | 81d0912d | bellard | struct dirent *d;
|
2349 | 81d0912d | bellard | char path[1024]; |
2350 | 81d0912d | bellard | char file[1024], file_prefix[1024]; |
2351 | 81d0912d | bellard | int input_path_len;
|
2352 | 81d0912d | bellard | const char *p; |
2353 | 81d0912d | bellard | |
2354 | 5fafdf24 | ths | p = strrchr(input, '/');
|
2355 | 81d0912d | bellard | if (!p) {
|
2356 | 81d0912d | bellard | input_path_len = 0;
|
2357 | 81d0912d | bellard | pstrcpy(file_prefix, sizeof(file_prefix), input);
|
2358 | 81d0912d | bellard | strcpy(path, ".");
|
2359 | 81d0912d | bellard | } else {
|
2360 | 81d0912d | bellard | input_path_len = p - input + 1;
|
2361 | 81d0912d | bellard | memcpy(path, input, input_path_len); |
2362 | 81d0912d | bellard | if (input_path_len > sizeof(path) - 1) |
2363 | 81d0912d | bellard | input_path_len = sizeof(path) - 1; |
2364 | 81d0912d | bellard | path[input_path_len] = '\0';
|
2365 | 81d0912d | bellard | pstrcpy(file_prefix, sizeof(file_prefix), p + 1); |
2366 | 81d0912d | bellard | } |
2367 | 81d0912d | bellard | #ifdef DEBUG_COMPLETION
|
2368 | 81d0912d | bellard | term_printf("input='%s' path='%s' prefix='%s'\n", input, path, file_prefix);
|
2369 | 81d0912d | bellard | #endif
|
2370 | 81d0912d | bellard | ffs = opendir(path); |
2371 | 81d0912d | bellard | if (!ffs)
|
2372 | 81d0912d | bellard | return;
|
2373 | 81d0912d | bellard | for(;;) {
|
2374 | 81d0912d | bellard | struct stat sb;
|
2375 | 81d0912d | bellard | d = readdir(ffs); |
2376 | 81d0912d | bellard | if (!d)
|
2377 | 81d0912d | bellard | break;
|
2378 | 81d0912d | bellard | if (strstart(d->d_name, file_prefix, NULL)) { |
2379 | 81d0912d | bellard | memcpy(file, input, input_path_len); |
2380 | 81d0912d | bellard | strcpy(file + input_path_len, d->d_name); |
2381 | 81d0912d | bellard | /* stat the file to find out if it's a directory.
|
2382 | 81d0912d | bellard | * In that case add a slash to speed up typing long paths
|
2383 | 81d0912d | bellard | */
|
2384 | 81d0912d | bellard | stat(file, &sb); |
2385 | 81d0912d | bellard | if(S_ISDIR(sb.st_mode))
|
2386 | 81d0912d | bellard | strcat(file, "/");
|
2387 | 81d0912d | bellard | add_completion(file); |
2388 | 81d0912d | bellard | } |
2389 | 81d0912d | bellard | } |
2390 | 81d0912d | bellard | closedir(ffs); |
2391 | 81d0912d | bellard | } |
2392 | 81d0912d | bellard | |
2393 | 81d0912d | bellard | static void block_completion_it(void *opaque, const char *name) |
2394 | 81d0912d | bellard | { |
2395 | 81d0912d | bellard | const char *input = opaque; |
2396 | 81d0912d | bellard | |
2397 | 81d0912d | bellard | if (input[0] == '\0' || |
2398 | 81d0912d | bellard | !strncmp(name, (char *)input, strlen(input))) {
|
2399 | 81d0912d | bellard | add_completion(name); |
2400 | 81d0912d | bellard | } |
2401 | 81d0912d | bellard | } |
2402 | 81d0912d | bellard | |
2403 | 81d0912d | bellard | /* NOTE: this parser is an approximate form of the real command parser */
|
2404 | 81d0912d | bellard | static void parse_cmdline(const char *cmdline, |
2405 | 81d0912d | bellard | int *pnb_args, char **args) |
2406 | 81d0912d | bellard | { |
2407 | 81d0912d | bellard | const char *p; |
2408 | 81d0912d | bellard | int nb_args, ret;
|
2409 | 81d0912d | bellard | char buf[1024]; |
2410 | 81d0912d | bellard | |
2411 | 81d0912d | bellard | p = cmdline; |
2412 | 81d0912d | bellard | nb_args = 0;
|
2413 | 81d0912d | bellard | for(;;) {
|
2414 | 81d0912d | bellard | while (isspace(*p))
|
2415 | 81d0912d | bellard | p++; |
2416 | 81d0912d | bellard | if (*p == '\0') |
2417 | 81d0912d | bellard | break;
|
2418 | 81d0912d | bellard | if (nb_args >= MAX_ARGS)
|
2419 | 81d0912d | bellard | break;
|
2420 | 81d0912d | bellard | ret = get_str(buf, sizeof(buf), &p);
|
2421 | 81d0912d | bellard | args[nb_args] = qemu_strdup(buf); |
2422 | 81d0912d | bellard | nb_args++; |
2423 | 81d0912d | bellard | if (ret < 0) |
2424 | 81d0912d | bellard | break;
|
2425 | 81d0912d | bellard | } |
2426 | 81d0912d | bellard | *pnb_args = nb_args; |
2427 | 81d0912d | bellard | } |
2428 | 81d0912d | bellard | |
2429 | 7e2515e8 | bellard | void readline_find_completion(const char *cmdline) |
2430 | 81d0912d | bellard | { |
2431 | 81d0912d | bellard | const char *cmdname; |
2432 | 81d0912d | bellard | char *args[MAX_ARGS];
|
2433 | 81d0912d | bellard | int nb_args, i, len;
|
2434 | 81d0912d | bellard | const char *ptype, *str; |
2435 | 81d0912d | bellard | term_cmd_t *cmd; |
2436 | 64866c3d | bellard | const KeyDef *key;
|
2437 | 81d0912d | bellard | |
2438 | 81d0912d | bellard | parse_cmdline(cmdline, &nb_args, args); |
2439 | 81d0912d | bellard | #ifdef DEBUG_COMPLETION
|
2440 | 81d0912d | bellard | for(i = 0; i < nb_args; i++) { |
2441 | 81d0912d | bellard | term_printf("arg%d = '%s'\n", i, (char *)args[i]); |
2442 | 81d0912d | bellard | } |
2443 | 81d0912d | bellard | #endif
|
2444 | 81d0912d | bellard | |
2445 | 81d0912d | bellard | /* if the line ends with a space, it means we want to complete the
|
2446 | 81d0912d | bellard | next arg */
|
2447 | 81d0912d | bellard | len = strlen(cmdline); |
2448 | 81d0912d | bellard | if (len > 0 && isspace(cmdline[len - 1])) { |
2449 | 81d0912d | bellard | if (nb_args >= MAX_ARGS)
|
2450 | 81d0912d | bellard | return;
|
2451 | 81d0912d | bellard | args[nb_args++] = qemu_strdup("");
|
2452 | 81d0912d | bellard | } |
2453 | 81d0912d | bellard | if (nb_args <= 1) { |
2454 | 81d0912d | bellard | /* command completion */
|
2455 | 81d0912d | bellard | if (nb_args == 0) |
2456 | 81d0912d | bellard | cmdname = "";
|
2457 | 81d0912d | bellard | else
|
2458 | 81d0912d | bellard | cmdname = args[0];
|
2459 | 81d0912d | bellard | completion_index = strlen(cmdname); |
2460 | 81d0912d | bellard | for(cmd = term_cmds; cmd->name != NULL; cmd++) { |
2461 | 81d0912d | bellard | cmd_completion(cmdname, cmd->name); |
2462 | 81d0912d | bellard | } |
2463 | 81d0912d | bellard | } else {
|
2464 | 81d0912d | bellard | /* find the command */
|
2465 | 81d0912d | bellard | for(cmd = term_cmds; cmd->name != NULL; cmd++) { |
2466 | 81d0912d | bellard | if (compare_cmd(args[0], cmd->name)) |
2467 | 81d0912d | bellard | goto found;
|
2468 | 81d0912d | bellard | } |
2469 | 81d0912d | bellard | return;
|
2470 | 81d0912d | bellard | found:
|
2471 | 81d0912d | bellard | ptype = cmd->args_type; |
2472 | 81d0912d | bellard | for(i = 0; i < nb_args - 2; i++) { |
2473 | 81d0912d | bellard | if (*ptype != '\0') { |
2474 | 81d0912d | bellard | ptype++; |
2475 | 81d0912d | bellard | while (*ptype == '?') |
2476 | 81d0912d | bellard | ptype++; |
2477 | 81d0912d | bellard | } |
2478 | 81d0912d | bellard | } |
2479 | 81d0912d | bellard | str = args[nb_args - 1];
|
2480 | 81d0912d | bellard | switch(*ptype) {
|
2481 | 81d0912d | bellard | case 'F': |
2482 | 81d0912d | bellard | /* file completion */
|
2483 | 81d0912d | bellard | completion_index = strlen(str); |
2484 | 81d0912d | bellard | file_completion(str); |
2485 | 81d0912d | bellard | break;
|
2486 | 81d0912d | bellard | case 'B': |
2487 | 81d0912d | bellard | /* block device name completion */
|
2488 | 81d0912d | bellard | completion_index = strlen(str); |
2489 | 81d0912d | bellard | bdrv_iterate(block_completion_it, (void *)str);
|
2490 | 81d0912d | bellard | break;
|
2491 | 7fe48483 | bellard | case 's': |
2492 | 7fe48483 | bellard | /* XXX: more generic ? */
|
2493 | 7fe48483 | bellard | if (!strcmp(cmd->name, "info")) { |
2494 | 7fe48483 | bellard | completion_index = strlen(str); |
2495 | 7fe48483 | bellard | for(cmd = info_cmds; cmd->name != NULL; cmd++) { |
2496 | 7fe48483 | bellard | cmd_completion(str, cmd->name); |
2497 | 7fe48483 | bellard | } |
2498 | 64866c3d | bellard | } else if (!strcmp(cmd->name, "sendkey")) { |
2499 | 64866c3d | bellard | completion_index = strlen(str); |
2500 | 64866c3d | bellard | for(key = key_defs; key->name != NULL; key++) { |
2501 | 64866c3d | bellard | cmd_completion(str, key->name); |
2502 | 64866c3d | bellard | } |
2503 | 7fe48483 | bellard | } |
2504 | 7fe48483 | bellard | break;
|
2505 | 81d0912d | bellard | default:
|
2506 | 81d0912d | bellard | break;
|
2507 | 81d0912d | bellard | } |
2508 | 81d0912d | bellard | } |
2509 | 81d0912d | bellard | for(i = 0; i < nb_args; i++) |
2510 | 81d0912d | bellard | qemu_free(args[i]); |
2511 | 81d0912d | bellard | } |
2512 | 81d0912d | bellard | |
2513 | 7e2515e8 | bellard | static int term_can_read(void *opaque) |
2514 | 9dc39cba | bellard | { |
2515 | 7e2515e8 | bellard | return 128; |
2516 | 9dc39cba | bellard | } |
2517 | 9dc39cba | bellard | |
2518 | 7e2515e8 | bellard | static void term_read(void *opaque, const uint8_t *buf, int size) |
2519 | 9dc39cba | bellard | { |
2520 | 7e2515e8 | bellard | int i;
|
2521 | 7e2515e8 | bellard | for(i = 0; i < size; i++) |
2522 | 7e2515e8 | bellard | readline_handle_byte(buf[i]); |
2523 | 9dc39cba | bellard | } |
2524 | 9dc39cba | bellard | |
2525 | 7e2515e8 | bellard | static void monitor_start_input(void); |
2526 | 9dc39cba | bellard | |
2527 | 7e2515e8 | bellard | static void monitor_handle_command1(void *opaque, const char *cmdline) |
2528 | aa455485 | bellard | { |
2529 | 7e2515e8 | bellard | monitor_handle_command(cmdline); |
2530 | 7e2515e8 | bellard | monitor_start_input(); |
2531 | aa455485 | bellard | } |
2532 | aa455485 | bellard | |
2533 | 7e2515e8 | bellard | static void monitor_start_input(void) |
2534 | aa455485 | bellard | { |
2535 | 7e2515e8 | bellard | readline_start("(qemu) ", 0, monitor_handle_command1, NULL); |
2536 | aa455485 | bellard | } |
2537 | aa455485 | bellard | |
2538 | 86e94dea | ths | static void term_event(void *opaque, int event) |
2539 | 86e94dea | ths | { |
2540 | 86e94dea | ths | if (event != CHR_EVENT_RESET)
|
2541 | 86e94dea | ths | return;
|
2542 | 86e94dea | ths | |
2543 | 86e94dea | ths | if (!hide_banner)
|
2544 | 86e94dea | ths | term_printf("QEMU %s monitor - type 'help' for more information\n",
|
2545 | 86e94dea | ths | QEMU_VERSION); |
2546 | 86e94dea | ths | monitor_start_input(); |
2547 | 86e94dea | ths | } |
2548 | 86e94dea | ths | |
2549 | 20d8a3ed | ths | static int is_first_init = 1; |
2550 | 20d8a3ed | ths | |
2551 | 7e2515e8 | bellard | void monitor_init(CharDriverState *hd, int show_banner) |
2552 | aa455485 | bellard | { |
2553 | 20d8a3ed | ths | int i;
|
2554 | 20d8a3ed | ths | |
2555 | 20d8a3ed | ths | if (is_first_init) {
|
2556 | 20d8a3ed | ths | for (i = 0; i < MAX_MON; i++) { |
2557 | 20d8a3ed | ths | monitor_hd[i] = NULL;
|
2558 | 20d8a3ed | ths | } |
2559 | 20d8a3ed | ths | is_first_init = 0;
|
2560 | 20d8a3ed | ths | } |
2561 | 20d8a3ed | ths | for (i = 0; i < MAX_MON; i++) { |
2562 | 20d8a3ed | ths | if (monitor_hd[i] == NULL) { |
2563 | 20d8a3ed | ths | monitor_hd[i] = hd; |
2564 | 20d8a3ed | ths | break;
|
2565 | 20d8a3ed | ths | } |
2566 | 20d8a3ed | ths | } |
2567 | 20d8a3ed | ths | |
2568 | 86e94dea | ths | hide_banner = !show_banner; |
2569 | 86e94dea | ths | |
2570 | e5b0bc44 | pbrook | qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL);
|
2571 | aa455485 | bellard | } |
2572 | aa455485 | bellard | |
2573 | 7e2515e8 | bellard | /* XXX: use threads ? */
|
2574 | 7e2515e8 | bellard | /* modal monitor readline */
|
2575 | 7e2515e8 | bellard | static int monitor_readline_started; |
2576 | 7e2515e8 | bellard | static char *monitor_readline_buf; |
2577 | 7e2515e8 | bellard | static int monitor_readline_buf_size; |
2578 | 81d0912d | bellard | |
2579 | 7e2515e8 | bellard | static void monitor_readline_cb(void *opaque, const char *input) |
2580 | 81d0912d | bellard | { |
2581 | 7e2515e8 | bellard | pstrcpy(monitor_readline_buf, monitor_readline_buf_size, input); |
2582 | 7e2515e8 | bellard | monitor_readline_started = 0;
|
2583 | 81d0912d | bellard | } |
2584 | 81d0912d | bellard | |
2585 | 7e2515e8 | bellard | void monitor_readline(const char *prompt, int is_password, |
2586 | 7e2515e8 | bellard | char *buf, int buf_size) |
2587 | 9dc39cba | bellard | { |
2588 | 20d8a3ed | ths | int i;
|
2589 | 20d8a3ed | ths | |
2590 | 7e2515e8 | bellard | if (is_password) {
|
2591 | 20d8a3ed | ths | for (i = 0; i < MAX_MON; i++) |
2592 | 20d8a3ed | ths | if (monitor_hd[i] && monitor_hd[i]->focus == 0) |
2593 | 20d8a3ed | ths | qemu_chr_send_event(monitor_hd[i], CHR_EVENT_FOCUS); |
2594 | 9dc39cba | bellard | } |
2595 | 7e2515e8 | bellard | readline_start(prompt, is_password, monitor_readline_cb, NULL);
|
2596 | 7e2515e8 | bellard | monitor_readline_buf = buf; |
2597 | 7e2515e8 | bellard | monitor_readline_buf_size = buf_size; |
2598 | 7e2515e8 | bellard | monitor_readline_started = 1;
|
2599 | 7e2515e8 | bellard | while (monitor_readline_started) {
|
2600 | 7e2515e8 | bellard | main_loop_wait(10);
|
2601 | 9dc39cba | bellard | } |
2602 | 9dc39cba | bellard | } |