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