1 |
|
/* |
2 |
< |
* mon_cmd.cpp - mon standard commands |
2 |
> |
* mon_cmd.cpp - cxmon standard commands |
3 |
|
* |
4 |
< |
* mon (C) 1997-1999 Christian Bauer, Marc Hellwig |
4 |
> |
* cxmon (C) 1997-2003 Christian Bauer, Marc Hellwig |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
24 |
|
|
25 |
|
#include "mon.h" |
26 |
|
#include "mon_cmd.h" |
27 |
< |
#include "mon_ppc.h" |
28 |
< |
#include "mon_68k.h" |
29 |
< |
#include "mon_x86.h" |
30 |
< |
#include "mon_6502.h" |
31 |
< |
#include "mon_8080.h" |
27 |
> |
#include "mon_disass.h" |
28 |
> |
|
29 |
> |
#ifndef VERSION |
30 |
> |
#define VERSION "3" |
31 |
> |
#endif |
32 |
|
|
33 |
|
|
34 |
|
/* |
40 |
|
* true: OK, false: Error |
41 |
|
*/ |
42 |
|
|
43 |
< |
static bool range_args(uint32 *adr, uint32 *end_adr, uint32 def_range) |
43 |
> |
static bool range_args(uintptr *adr, uintptr *end_adr, uint32 def_range) |
44 |
|
{ |
45 |
|
*adr = mon_dot_address; |
46 |
|
*end_adr = mon_dot_address + def_range; |
67 |
|
* byte_string = (expression | STRING) {COMMA (expression | STRING)} END |
68 |
|
*/ |
69 |
|
|
70 |
< |
static bool byte_string(uint8 *s, uint32 &len) |
70 |
> |
static bool byte_string(uint8 *s, uintptr &len) |
71 |
|
{ |
72 |
< |
uint32 value; |
72 |
> |
uintptr value; |
73 |
|
|
74 |
|
len = 0; |
75 |
|
goto start; |
161 |
|
|
162 |
|
void print_expr(void) |
163 |
|
{ |
164 |
< |
uint32 val; |
164 |
> |
uintptr val; |
165 |
|
|
166 |
|
if (!mon_expression(&val)) |
167 |
|
return; |
213 |
|
|
214 |
|
void memory_dump(void) |
215 |
|
{ |
216 |
< |
uint32 adr, end_adr; |
216 |
> |
uintptr adr, end_adr; |
217 |
|
uint8 mem[MEMDUMP_BPL + 1]; |
218 |
|
|
219 |
|
mem[MEMDUMP_BPL] = 0; |
222 |
|
return; |
223 |
|
|
224 |
|
while (adr <= end_adr && !mon_aborted()) { |
225 |
< |
fprintf(monout, "%08x:", mon_use_real_mem ? adr: adr % mon_mem_size); |
225 |
> |
fprintf(monout, "%0*lx:", 2 * sizeof(adr), mon_use_real_mem ? adr: adr % mon_mem_size); |
226 |
|
for (int i=0; i<MEMDUMP_BPL; i++, adr++) { |
227 |
|
if (i % 4 == 0) |
228 |
|
fprintf(monout, " %08x", mon_read_word(adr)); |
244 |
|
|
245 |
|
void ascii_dump(void) |
246 |
|
{ |
247 |
< |
uint32 adr, end_adr; |
247 |
> |
uintptr adr, end_adr; |
248 |
|
uint8 str[ASCIIDUMP_BPL + 1]; |
249 |
|
|
250 |
|
str[ASCIIDUMP_BPL] = 0; |
253 |
|
return; |
254 |
|
|
255 |
|
while (adr <= end_adr && !mon_aborted()) { |
256 |
< |
fprintf(monout, "%08x:", mon_use_real_mem ? adr : adr % mon_mem_size); |
256 |
> |
fprintf(monout, "%0*lx:", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
257 |
|
for (int i=0; i<ASCIIDUMP_BPL; i++, adr++) |
258 |
|
str[i] = char2print(mon_read_byte(adr)); |
259 |
|
fprintf(monout, " '%s'\n", str); |
270 |
|
|
271 |
|
void binary_dump(void) |
272 |
|
{ |
273 |
< |
uint32 adr, end_adr; |
273 |
> |
uintptr adr, end_adr; |
274 |
|
uint8 str[9]; |
275 |
|
|
276 |
|
str[8] = 0; |
279 |
|
return; |
280 |
|
|
281 |
|
while (adr <= end_adr && !mon_aborted()) { |
282 |
< |
fprintf(monout, "%08x:", mon_use_real_mem ? adr : adr % mon_mem_size); |
282 |
> |
fprintf(monout, "%0*lx:", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
283 |
|
uint8 b = mon_read_byte(adr); |
284 |
|
for (int m=0x80, i=0; i<8; m>>=1, i++) |
285 |
|
str[i] = (b & m) ? '*' : '.'; |
298 |
|
* d68 [start [end]] |
299 |
|
* d80 [start [end]] |
300 |
|
* d86 [start [end]] |
301 |
+ |
* d8086 [start [end]] |
302 |
|
*/ |
303 |
|
|
304 |
|
enum CPUType { |
305 |
|
CPU_PPC, |
306 |
|
CPU_6502, |
307 |
|
CPU_680x0, |
308 |
< |
CPU_8080, |
309 |
< |
CPU_80x86 |
308 |
> |
CPU_Z80, |
309 |
> |
CPU_80x86_32, |
310 |
> |
CPU_80x86_16, |
311 |
> |
CPU_x86_64 |
312 |
|
}; |
313 |
|
|
314 |
|
static void disassemble(CPUType type) |
315 |
|
{ |
316 |
< |
uint32 adr, end_adr; |
316 |
> |
uintptr adr, end_adr; |
317 |
|
|
318 |
|
if (!range_args(&adr, &end_adr, 16 * 4 - 1)) // 16 lines unless end address specified |
319 |
|
return; |
322 |
|
case CPU_PPC: |
323 |
|
while (adr <= end_adr && !mon_aborted()) { |
324 |
|
uint32 w = mon_read_word(adr); |
325 |
< |
fprintf(monout, "%08x: %08x\t", mon_use_real_mem ? adr : adr % mon_mem_size, w); |
325 |
> |
fprintf(monout, "%0*lx: %08x\t", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size, w); |
326 |
|
disass_ppc(monout, mon_use_real_mem ? adr : adr % mon_mem_size, w); |
327 |
|
adr += 4; |
328 |
|
} |
333 |
|
uint8 op = mon_read_byte(adr); |
334 |
|
uint8 lo = mon_read_byte(adr + 1); |
335 |
|
uint8 hi = mon_read_byte(adr + 2); |
336 |
< |
fprintf(monout, "%08x: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
336 |
> |
fprintf(monout, "%0*lx: ", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
337 |
|
adr += disass_6502(monout, mon_use_real_mem ? adr : adr % mon_mem_size, op, lo, hi); |
338 |
|
} |
339 |
|
break; |
340 |
|
|
341 |
|
case CPU_680x0: |
342 |
|
while (adr <= end_adr && !mon_aborted()) { |
343 |
< |
uint16 buf[8]; |
344 |
< |
buf[0] = mon_read_half(adr); |
342 |
< |
buf[1] = mon_read_half(adr + 2); |
343 |
< |
buf[2] = mon_read_half(adr + 4); |
344 |
< |
buf[3] = mon_read_half(adr + 6); |
345 |
< |
buf[4] = mon_read_half(adr + 8); |
346 |
< |
buf[5] = mon_read_half(adr + 10); |
347 |
< |
buf[6] = mon_read_half(adr + 12); |
348 |
< |
buf[7] = mon_read_half(adr + 14); |
349 |
< |
fprintf(monout, "%08x: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
350 |
< |
adr += disass_68k(monout, mon_use_real_mem ? adr : adr % mon_mem_size, buf); |
343 |
> |
fprintf(monout, "%0*lx: ", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
344 |
> |
adr += disass_68k(monout, mon_use_real_mem ? adr : adr % mon_mem_size); |
345 |
|
} |
346 |
|
break; |
347 |
|
|
348 |
< |
case CPU_8080: |
348 |
> |
case CPU_Z80: |
349 |
|
while (adr <= end_adr && !mon_aborted()) { |
350 |
< |
uint8 op = mon_read_byte(adr); |
351 |
< |
uint8 lo = mon_read_byte(adr + 1); |
358 |
< |
uint8 hi = mon_read_byte(adr + 2); |
359 |
< |
fprintf(monout, "%08x: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
360 |
< |
adr += disass_8080(monout, mon_use_real_mem ? adr : adr % mon_mem_size, op, lo, hi); |
350 |
> |
fprintf(monout, "%0*lx: ", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
351 |
> |
adr += disass_z80(monout, mon_use_real_mem ? adr : adr % mon_mem_size); |
352 |
|
} |
353 |
|
break; |
354 |
|
|
355 |
< |
case CPU_80x86: |
355 |
> |
case CPU_x86_64: |
356 |
|
while (adr <= end_adr && !mon_aborted()) { |
357 |
< |
uint8 buf[16]; |
358 |
< |
for (int i=0; i<16; i++) |
368 |
< |
buf[i] = mon_read_byte(adr + i); |
369 |
< |
fprintf(monout, "%08x: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
370 |
< |
adr += disass_x86(monout, mon_use_real_mem ? adr : adr % mon_mem_size, buf); |
357 |
> |
fprintf(monout, "%0*lx: ", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
358 |
> |
adr += disass_x86(monout, mon_use_real_mem ? adr : adr % mon_mem_size, 64); |
359 |
|
} |
360 |
|
break; |
361 |
+ |
|
362 |
+ |
case CPU_80x86_32: |
363 |
+ |
while (adr <= end_adr && !mon_aborted()) { |
364 |
+ |
fprintf(monout, "%0*lx: ", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
365 |
+ |
adr += disass_x86(monout, mon_use_real_mem ? adr : adr % mon_mem_size, 32); |
366 |
+ |
} |
367 |
+ |
break; |
368 |
+ |
|
369 |
+ |
case CPU_80x86_16: |
370 |
+ |
while (adr <= end_adr && !mon_aborted()) { |
371 |
+ |
fprintf(monout, "%0*lx: ", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
372 |
+ |
adr += disass_x86(monout, mon_use_real_mem ? adr : adr % mon_mem_size, 16); |
373 |
+ |
} |
374 |
|
} |
375 |
|
|
376 |
|
mon_dot_address = adr; |
391 |
|
disassemble(CPU_680x0); |
392 |
|
} |
393 |
|
|
394 |
< |
void disassemble_8080(void) |
394 |
> |
void disassemble_z80(void) |
395 |
> |
{ |
396 |
> |
disassemble(CPU_Z80); |
397 |
> |
} |
398 |
> |
|
399 |
> |
void disassemble_80x86_32(void) |
400 |
> |
{ |
401 |
> |
disassemble(CPU_80x86_32); |
402 |
> |
} |
403 |
> |
|
404 |
> |
void disassemble_80x86_16(void) |
405 |
|
{ |
406 |
< |
disassemble(CPU_8080); |
406 |
> |
disassemble(CPU_80x86_16); |
407 |
|
} |
408 |
|
|
409 |
< |
void disassemble_80x86(void) |
409 |
> |
void disassemble_x86_64(void) |
410 |
|
{ |
411 |
< |
disassemble(CPU_80x86); |
411 |
> |
disassemble(CPU_x86_64); |
412 |
|
} |
413 |
|
|
414 |
|
|
419 |
|
|
420 |
|
void modify(void) |
421 |
|
{ |
422 |
< |
uint32 adr, len, src_adr = 0; |
422 |
> |
uintptr adr, len, src_adr = 0; |
423 |
|
uint8 str[256]; |
424 |
|
|
425 |
|
if (!mon_expression(&adr)) |
441 |
|
|
442 |
|
void fill(void) |
443 |
|
{ |
444 |
< |
uint32 adr, end_adr, len, src_adr = 0; |
444 |
> |
uintptr adr, end_adr, len, src_adr = 0; |
445 |
|
uint8 str[256]; |
446 |
|
|
447 |
|
if (!mon_expression(&adr)) |
463 |
|
|
464 |
|
void transfer(void) |
465 |
|
{ |
466 |
< |
uint32 adr, end_adr, dest; |
466 |
> |
uintptr adr, end_adr, dest; |
467 |
|
int num; |
468 |
|
|
469 |
|
if (!mon_expression(&adr)) |
497 |
|
|
498 |
|
void compare(void) |
499 |
|
{ |
500 |
< |
uint32 adr, end_adr, dest; |
500 |
> |
uintptr adr, end_adr, dest; |
501 |
|
int num = 0; |
502 |
|
|
503 |
|
if (!mon_expression(&adr)) |
513 |
|
|
514 |
|
while (adr <= end_adr && !mon_aborted()) { |
515 |
|
if (mon_read_byte(adr) != mon_read_byte(dest)) { |
516 |
< |
fprintf(monout, "%08x ", mon_use_real_mem ? adr : adr % mon_mem_size); |
516 |
> |
fprintf(monout, "%0*lx ", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
517 |
|
num++; |
518 |
|
if (!(num & 7)) |
519 |
|
fputc('\n', monout); |
534 |
|
|
535 |
|
void hunt(void) |
536 |
|
{ |
537 |
< |
uint32 adr, end_adr, len; |
537 |
> |
uintptr adr, end_adr, len; |
538 |
|
uint8 str[256]; |
539 |
|
int num = 0; |
540 |
|
|
553 |
|
break; |
554 |
|
|
555 |
|
if (i == len) { |
556 |
< |
fprintf(monout, "%08x ", mon_use_real_mem ? adr : adr % mon_mem_size); |
556 |
> |
fprintf(monout, "%0*lx ", 2 * sizeof(adr), mon_use_real_mem ? adr : adr % mon_mem_size); |
557 |
|
num++; |
558 |
|
if (num == 1) |
559 |
|
mon_dot_address = adr; |
576 |
|
|
577 |
|
void load_data(void) |
578 |
|
{ |
579 |
< |
uint32 start_adr; |
579 |
> |
uintptr start_adr; |
580 |
|
FILE *file; |
581 |
|
int fc; |
582 |
|
|
599 |
|
if (!(file = fopen(mon_string, "rb"))) |
600 |
|
mon_error("Unable to open file"); |
601 |
|
else { |
602 |
< |
uint32 adr = start_adr; |
602 |
> |
uintptr adr = start_adr; |
603 |
|
|
604 |
|
while ((fc = fgetc(file)) != EOF) |
605 |
|
mon_write_byte(adr++, fc); |
606 |
|
fclose(file); |
607 |
|
|
608 |
< |
fprintf(monerr, "%08x bytes read from %08x to %08x\n", adr - start_adr, mon_use_real_mem ? start_adr : start_adr % mon_mem_size, mon_use_real_mem ? adr-1 : (adr-1) % mon_mem_size); |
608 |
> |
fprintf(monerr, "%08x bytes read from %0*lx to %0*lx\n", adr - start_adr, 2 * sizeof(adr), mon_use_real_mem ? start_adr : start_adr % mon_mem_size, 2 * sizeof(adr), mon_use_real_mem ? adr-1 : (adr-1) % mon_mem_size); |
609 |
|
mon_dot_address = adr; |
610 |
|
} |
611 |
|
} |
618 |
|
|
619 |
|
void save_data(void) |
620 |
|
{ |
621 |
< |
uint32 start_adr, size; |
621 |
> |
uintptr start_adr, size; |
622 |
|
FILE *file; |
623 |
|
|
624 |
|
if (!mon_expression(&start_adr)) |
642 |
|
if (!(file = fopen(mon_string, "wb"))) |
643 |
|
mon_error("Unable to create file"); |
644 |
|
else { |
645 |
< |
uint32 adr = start_adr, end_adr = start_adr + size - 1; |
645 |
> |
uintptr adr = start_adr, end_adr = start_adr + size - 1; |
646 |
|
|
647 |
|
while (adr <= end_adr) |
648 |
|
fputc(mon_read_byte(adr++), file); |
649 |
|
fclose(file); |
650 |
|
|
651 |
< |
fprintf(monerr, "%08x bytes written from %08x to %08x\n", size, mon_use_real_mem ? start_adr : start_adr % mon_mem_size, mon_use_real_mem ? end_adr : end_adr % mon_mem_size); |
651 |
> |
fprintf(monerr, "%08x bytes written from %0*lx to %0*lx\n", size, 2 * sizeof(adr), mon_use_real_mem ? start_adr : start_adr % mon_mem_size, 2 * sizeof(adr), mon_use_real_mem ? end_adr : end_adr % mon_mem_size); |
652 |
|
} |
653 |
|
} |