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