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 |
+ |
#include <stdio.h> |
24 |
+ |
#include <stdlib.h> |
25 |
+ |
#include <signal.h> |
26 |
+ |
#include <ctype.h> |
27 |
+ |
|
28 |
|
#ifdef HAVE_READLINE_READLINE_H |
29 |
|
extern "C" { |
30 |
|
#include <readline/readline.h> |
39 |
|
|
40 |
|
#include "mon.h" |
41 |
|
#include "mon_cmd.h" |
37 |
– |
#include "version.h" |
42 |
|
|
43 |
|
|
44 |
|
// Buffer we're operating on |
195 |
|
* Access to buffer |
196 |
|
*/ |
197 |
|
|
198 |
< |
uint32 mon_read_byte(uint32 adr) |
198 |
> |
uint32 (*mon_read_byte)(uint32 adr); |
199 |
> |
|
200 |
> |
uint32 mon_read_byte_buffer(uint32 adr) |
201 |
|
{ |
202 |
< |
if (mon_use_real_mem) |
197 |
< |
return *(uint8 *)adr; |
198 |
< |
else |
199 |
< |
return mem[adr % mon_mem_size]; |
202 |
> |
return mem[adr % mon_mem_size]; |
203 |
|
} |
204 |
|
|
205 |
< |
void mon_write_byte(uint32 adr, uint32 b) |
205 |
> |
uint32 mon_read_byte_real(uint32 adr) |
206 |
|
{ |
207 |
< |
if (mon_use_real_mem) |
208 |
< |
*(uint8 *)adr = b; |
209 |
< |
else |
210 |
< |
mem[adr % mon_mem_size] = b; |
207 |
> |
return *(uint8 *)adr; |
208 |
> |
} |
209 |
> |
|
210 |
> |
void (*mon_write_byte)(uint32 adr, uint32 b); |
211 |
> |
|
212 |
> |
void mon_write_byte_buffer(uint32 adr, uint32 b) |
213 |
> |
{ |
214 |
> |
mem[adr % mon_mem_size] = b; |
215 |
> |
} |
216 |
> |
|
217 |
> |
void mon_write_byte_real(uint32 adr, uint32 b) |
218 |
> |
{ |
219 |
> |
*(uint8 *)adr = b; |
220 |
|
} |
221 |
|
|
222 |
|
uint32 mon_read_half(uint32 adr) |
223 |
|
{ |
224 |
< |
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]; |
224 |
> |
return (mon_read_byte(adr) << 8) | mon_read_byte(adr+1); |
225 |
|
} |
226 |
|
|
227 |
|
void mon_write_half(uint32 adr, uint32 w) |
228 |
|
{ |
229 |
< |
if (mon_use_real_mem) |
230 |
< |
*(uint16 *)adr = htons(w); |
222 |
< |
else { |
223 |
< |
mem[adr % mon_mem_size] = w >> 8; |
224 |
< |
mem[(adr+1) % mon_mem_size] = w; |
225 |
< |
} |
229 |
> |
mon_write_byte(adr, w >> 8); |
230 |
> |
mon_write_byte(adr+1, w); |
231 |
|
} |
232 |
|
|
233 |
|
uint32 mon_read_word(uint32 adr) |
234 |
|
{ |
235 |
< |
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); |
235 |
> |
return (mon_read_byte(adr) << 24) | (mon_read_byte(adr+1) << 16) | (mon_read_byte(adr+2) << 8) | mon_read_byte(adr+3); |
236 |
|
} |
237 |
|
|
238 |
|
void mon_write_word(uint32 adr, uint32 l) |
239 |
|
{ |
240 |
< |
if (mon_use_real_mem) |
241 |
< |
*(uint32 *)adr = htonl(l); |
242 |
< |
else { |
243 |
< |
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 |
< |
} |
240 |
> |
mon_write_byte(adr, l >> 24); |
241 |
> |
mon_write_byte(adr+1, l >> 16); |
242 |
> |
mon_write_byte(adr+2, l >> 8); |
243 |
> |
mon_write_byte(adr+3, l); |
244 |
|
} |
245 |
|
|
246 |
|
|
1062 |
|
mon_add_command("@", reallocate, "@ [size] Reallocate buffer\n"); |
1063 |
|
mon_add_command("i", ascii_dump, "i [start [end]] ASCII memory dump\n"); |
1064 |
|
mon_add_command("m", memory_dump, "m [start [end]] Hex/ASCII memory dump\n"); |
1065 |
+ |
mon_add_command("b", binary_dump, "b [start [end]] Binary memory dump\n"); |
1066 |
|
mon_add_command("d", disassemble_ppc, "d [start [end]] Disassemble PowerPC code\n"); |
1067 |
|
mon_add_command("d65", disassemble_6502, "d65 [start [end]] Disassemble 6502 code\n"); |
1068 |
|
mon_add_command("d68", disassemble_680x0, "d68 [start [end]] Disassemble 680x0 code\n"); |
1088 |
|
mon_add_command("]", save_data, "] start size \"file\" Save data to file\n"); |
1089 |
|
mon_add_command("set", set_var, "set [var[=value]] Set/clear/show variables\n"); |
1090 |
|
mon_add_command("cv", clear_vars, "cv Clear all variables\n"); |
1091 |
+ |
|
1092 |
+ |
mon_read_byte = NULL; |
1093 |
+ |
mon_write_byte = NULL; |
1094 |
|
} |
1095 |
|
|
1096 |
|
|
1136 |
|
interactive = (argc == 0); |
1137 |
|
} |
1138 |
|
|
1139 |
+ |
// Set up memory access functions if not supplied by the user |
1140 |
+ |
if (mon_read_byte == NULL) { |
1141 |
+ |
if (mon_use_real_mem) |
1142 |
+ |
mon_read_byte = mon_read_byte_real; |
1143 |
+ |
else |
1144 |
+ |
mon_read_byte = mon_read_byte_buffer; |
1145 |
+ |
} |
1146 |
+ |
if (mon_write_byte == NULL) { |
1147 |
+ |
if (mon_use_real_mem) |
1148 |
+ |
mon_write_byte = mon_write_byte_real; |
1149 |
+ |
else |
1150 |
+ |
mon_write_byte = mon_write_byte_buffer; |
1151 |
+ |
} |
1152 |
+ |
|
1153 |
|
// Allocate buffer |
1154 |
|
if (!mon_use_real_mem) { |
1155 |
|
mon_mem_size = 0x100000; |
1157 |
|
|
1158 |
|
// Print banner |
1159 |
|
if (interactive) |
1160 |
< |
fprintf(monerr, "\n *** mon V%d.%d by Christian Bauer and Marc Hellwig ***\n" |
1161 |
< |
" *** Press 'h' for help ***\n\n", VERSION_MAJOR, VERSION_MINOR); |
1160 |
> |
fprintf(monerr, "\n *** mon V" VERSION " by Christian Bauer and Marc Hellwig ***\n" |
1161 |
> |
" *** Press 'h' for help ***\n\n"); |
1162 |
|
} |
1163 |
|
|
1164 |
|
init_abort(); |