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