1 |
|
/* |
2 |
|
* mon.cpp - mon main program |
3 |
|
* |
4 |
< |
* mon (C) 1997-1999 Christian Bauer, Marc Hellwig |
4 |
> |
* mon (C) 1997-2000 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 |
20 |
|
|
21 |
|
#include "sysdeps.h" |
22 |
|
|
23 |
< |
#ifdef HAVE_READLINE_READLINE_H |
23 |
> |
#include <stdio.h> |
24 |
> |
#include <stdlib.h> |
25 |
> |
#include <signal.h> |
26 |
> |
#include <ctype.h> |
27 |
> |
|
28 |
> |
#if defined(HAVE_READLINE_H) |
29 |
> |
extern "C" { |
30 |
> |
#include <readline.h> |
31 |
> |
} |
32 |
> |
#elif defined(HAVE_READLINE_READLINE_H) |
33 |
|
extern "C" { |
34 |
|
#include <readline/readline.h> |
35 |
|
} |
36 |
|
#endif |
37 |
|
|
38 |
< |
#ifdef HAVE_READLINE_HISTORY_H |
38 |
> |
#if defined(HAVE_HISTORY_H) |
39 |
> |
extern "C" { |
40 |
> |
#include <history.h> |
41 |
> |
} |
42 |
> |
#elif defined(HAVE_READLINE_HISTORY_H) |
43 |
|
extern "C" { |
44 |
|
#include <readline/history.h> |
45 |
|
} |
47 |
|
|
48 |
|
#include "mon.h" |
49 |
|
#include "mon_cmd.h" |
50 |
< |
#include "version.h" |
50 |
> |
|
51 |
> |
#ifndef VERSION |
52 |
> |
#define VERSION "2" |
53 |
> |
#endif |
54 |
|
|
55 |
|
|
56 |
|
// Buffer we're operating on |
207 |
|
* Access to buffer |
208 |
|
*/ |
209 |
|
|
210 |
< |
uint32 mon_read_byte(uint32 adr) |
210 |
> |
uint32 (*mon_read_byte)(uint32 adr); |
211 |
> |
|
212 |
> |
uint32 mon_read_byte_buffer(uint32 adr) |
213 |
|
{ |
214 |
< |
if (mon_use_real_mem) |
197 |
< |
return *(uint8 *)adr; |
198 |
< |
else |
199 |
< |
return mem[adr % mon_mem_size]; |
214 |
> |
return mem[adr % mon_mem_size]; |
215 |
|
} |
216 |
|
|
217 |
< |
void mon_write_byte(uint32 adr, uint32 b) |
217 |
> |
uint32 mon_read_byte_real(uint32 adr) |
218 |
|
{ |
219 |
< |
if (mon_use_real_mem) |
220 |
< |
*(uint8 *)adr = b; |
221 |
< |
else |
222 |
< |
mem[adr % mon_mem_size] = b; |
219 |
> |
return *(uint8 *)adr; |
220 |
> |
} |
221 |
> |
|
222 |
> |
void (*mon_write_byte)(uint32 adr, uint32 b); |
223 |
> |
|
224 |
> |
void mon_write_byte_buffer(uint32 adr, uint32 b) |
225 |
> |
{ |
226 |
> |
mem[adr % mon_mem_size] = b; |
227 |
> |
} |
228 |
> |
|
229 |
> |
void mon_write_byte_real(uint32 adr, uint32 b) |
230 |
> |
{ |
231 |
> |
*(uint8 *)adr = b; |
232 |
|
} |
233 |
|
|
234 |
|
uint32 mon_read_half(uint32 adr) |
235 |
|
{ |
236 |
< |
if (mon_use_real_mem) |
213 |
< |
return ntohs(*(uint16 *)adr); |
214 |
< |
else |
215 |
< |
return mem[adr % mon_mem_size] << 8 | mem[(adr+1) % mon_mem_size]; |
236 |
> |
return (mon_read_byte(adr) << 8) | mon_read_byte(adr+1); |
237 |
|
} |
238 |
|
|
239 |
|
void mon_write_half(uint32 adr, uint32 w) |
240 |
|
{ |
241 |
< |
if (mon_use_real_mem) |
242 |
< |
*(uint16 *)adr = htons(w); |
222 |
< |
else { |
223 |
< |
mem[adr % mon_mem_size] = w >> 8; |
224 |
< |
mem[(adr+1) % mon_mem_size] = w; |
225 |
< |
} |
241 |
> |
mon_write_byte(adr, w >> 8); |
242 |
> |
mon_write_byte(adr+1, w); |
243 |
|
} |
244 |
|
|
245 |
|
uint32 mon_read_word(uint32 adr) |
246 |
|
{ |
247 |
< |
if (mon_use_real_mem) |
231 |
< |
return ntohl(*(uint32 *)adr); |
232 |
< |
else |
233 |
< |
return mon_read_byte(adr) << 24 | mon_read_byte(adr+1) << 16 | mon_read_byte(adr+2) << 8 | mon_read_byte(adr+3); |
247 |
> |
return (mon_read_byte(adr) << 24) | (mon_read_byte(adr+1) << 16) | (mon_read_byte(adr+2) << 8) | mon_read_byte(adr+3); |
248 |
|
} |
249 |
|
|
250 |
|
void mon_write_word(uint32 adr, uint32 l) |
251 |
|
{ |
252 |
< |
if (mon_use_real_mem) |
253 |
< |
*(uint32 *)adr = htonl(l); |
254 |
< |
else { |
255 |
< |
mem[adr % mon_mem_size] = l >> 24; |
242 |
< |
mem[(adr+1) % mon_mem_size] = l >> 16; |
243 |
< |
mem[(adr+2) % mon_mem_size] = l >> 8; |
244 |
< |
mem[(adr+3) % mon_mem_size] = l; |
245 |
< |
} |
252 |
> |
mon_write_byte(adr, l >> 24); |
253 |
> |
mon_write_byte(adr+1, l >> 16); |
254 |
> |
mon_write_byte(adr+2, l >> 8); |
255 |
> |
mon_write_byte(adr+3, l); |
256 |
|
} |
257 |
|
|
258 |
|
|
1074 |
|
mon_add_command("@", reallocate, "@ [size] Reallocate buffer\n"); |
1075 |
|
mon_add_command("i", ascii_dump, "i [start [end]] ASCII memory dump\n"); |
1076 |
|
mon_add_command("m", memory_dump, "m [start [end]] Hex/ASCII memory dump\n"); |
1077 |
+ |
mon_add_command("b", binary_dump, "b [start [end]] Binary memory dump\n"); |
1078 |
|
mon_add_command("d", disassemble_ppc, "d [start [end]] Disassemble PowerPC code\n"); |
1079 |
|
mon_add_command("d65", disassemble_6502, "d65 [start [end]] Disassemble 6502 code\n"); |
1080 |
|
mon_add_command("d68", disassemble_680x0, "d68 [start [end]] Disassemble 680x0 code\n"); |
1100 |
|
mon_add_command("]", save_data, "] start size \"file\" Save data to file\n"); |
1101 |
|
mon_add_command("set", set_var, "set [var[=value]] Set/clear/show variables\n"); |
1102 |
|
mon_add_command("cv", clear_vars, "cv Clear all variables\n"); |
1103 |
+ |
|
1104 |
+ |
mon_read_byte = NULL; |
1105 |
+ |
mon_write_byte = NULL; |
1106 |
|
} |
1107 |
|
|
1108 |
|
|
1133 |
|
monout = stdout; |
1134 |
|
monerr = stdout; |
1135 |
|
|
1136 |
< |
if (argc) { |
1137 |
< |
// Access real memory if mon was started as "rmon" |
1138 |
< |
char *prgname = argv[0]; |
1139 |
< |
char *lastslash; |
1140 |
< |
if ((lastslash = strrchr(prgname, '/')) != NULL) |
1141 |
< |
prgname = lastslash + 1; |
1142 |
< |
if (strcmp(prgname, "rmon") == 0) |
1136 |
> |
// Make argc/argv point to the actual arguments |
1137 |
> |
if (argc) |
1138 |
> |
argc--; argv++; |
1139 |
> |
|
1140 |
> |
// Parse arguments |
1141 |
> |
mon_macos_mode = false; |
1142 |
> |
mon_use_real_mem = false; |
1143 |
> |
while (argc > 0) { |
1144 |
> |
if (strcmp(argv[0], "-m") == 0) |
1145 |
> |
mon_macos_mode = true; |
1146 |
> |
else if (strcmp(argv[0], "-r") == 0) |
1147 |
|
mon_use_real_mem = true; |
1148 |
+ |
else |
1149 |
+ |
break; |
1150 |
+ |
argc--; argv++; |
1151 |
+ |
} |
1152 |
+ |
interactive = (argc == 0); |
1153 |
|
|
1154 |
< |
// Make argc/argv point to the actual arguments |
1155 |
< |
argc--; |
1156 |
< |
argv++; |
1157 |
< |
interactive = (argc == 0); |
1154 |
> |
// Set up memory access functions if not supplied by the user |
1155 |
> |
if (mon_read_byte == NULL) { |
1156 |
> |
if (mon_use_real_mem) |
1157 |
> |
mon_read_byte = mon_read_byte_real; |
1158 |
> |
else |
1159 |
> |
mon_read_byte = mon_read_byte_buffer; |
1160 |
> |
} |
1161 |
> |
if (mon_write_byte == NULL) { |
1162 |
> |
if (mon_use_real_mem) |
1163 |
> |
mon_write_byte = mon_write_byte_real; |
1164 |
> |
else |
1165 |
> |
mon_write_byte = mon_write_byte_buffer; |
1166 |
|
} |
1167 |
|
|
1168 |
|
// Allocate buffer |
1172 |
|
|
1173 |
|
// Print banner |
1174 |
|
if (interactive) |
1175 |
< |
fprintf(monerr, "\n *** mon V%d.%d by Christian Bauer and Marc Hellwig ***\n" |
1176 |
< |
" *** Press 'h' for help ***\n\n", VERSION_MAJOR, VERSION_MINOR); |
1175 |
> |
fprintf(monerr, "\n *** mon V" VERSION " by Christian Bauer and Marc Hellwig ***\n" |
1176 |
> |
" *** Press 'h' for help ***\n\n"); |
1177 |
|
} |
1178 |
|
|
1179 |
|
init_abort(); |