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