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