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