1 |
|
/* |
2 |
< |
* mon.cpp - Machine language monitor |
2 |
> |
* mon.cpp - mon main program |
3 |
|
* |
4 |
< |
* (C) 1997-1999 Christian Bauer |
4 |
> |
* mon (C) 1997-1999 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 |
8 |
> |
* the Free Software Foundation; either version 2 of the License, or |
9 |
> |
* (at your option) any later version. |
10 |
> |
* |
11 |
> |
* This program is distributed in the hope that it will be useful, |
12 |
> |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
> |
* GNU General Public License for more details. |
15 |
> |
* |
16 |
> |
* You should have received a copy of the GNU General Public License |
17 |
> |
* along with this program; if not, write to the Free Software |
18 |
> |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
*/ |
20 |
|
|
21 |
< |
#include <sys/types.h> |
22 |
< |
#include <netinet/in.h> |
21 |
> |
#include "sysdeps.h" |
22 |
> |
|
23 |
|
#include <stdio.h> |
24 |
|
#include <stdlib.h> |
11 |
– |
#include <string.h> |
25 |
|
#include <signal.h> |
26 |
|
#include <ctype.h> |
14 |
– |
#include <unistd.h> |
15 |
– |
#include <errno.h> |
27 |
|
|
28 |
+ |
#ifdef HAVE_READLINE_READLINE_H |
29 |
|
extern "C" { |
30 |
< |
extern char *readline(char *prompt); |
19 |
< |
extern void add_history(char *str); |
30 |
> |
#include <readline/readline.h> |
31 |
|
} |
32 |
+ |
#endif |
33 |
+ |
|
34 |
+ |
#ifdef HAVE_READLINE_HISTORY_H |
35 |
+ |
extern "C" { |
36 |
+ |
#include <readline/history.h> |
37 |
+ |
} |
38 |
+ |
#endif |
39 |
|
|
40 |
|
#include "mon.h" |
41 |
|
#include "mon_cmd.h" |
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) |
183 |
< |
return *(uint8 *)adr; |
184 |
< |
else |
185 |
< |
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) |
199 |
< |
return ntohs(*(uint16 *)adr); |
200 |
< |
else |
201 |
< |
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); |
208 |
< |
else { |
209 |
< |
mem[adr % mon_mem_size] = w >> 8; |
210 |
< |
mem[(adr+1) % mon_mem_size] = w; |
211 |
< |
} |
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) |
217 |
< |
return ntohl(*(uint32 *)adr); |
218 |
< |
else |
219 |
< |
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; |
228 |
< |
mem[(adr+1) % mon_mem_size] = l >> 16; |
229 |
< |
mem[(adr+2) % mon_mem_size] = l >> 8; |
230 |
< |
mem[(adr+3) % mon_mem_size] = l; |
231 |
< |
} |
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 |
|
|
250 |
|
|
251 |
|
static void read_line(char *prompt) |
252 |
|
{ |
253 |
+ |
#ifdef HAVE_LIBREADLINE |
254 |
|
static char *line_read = NULL; |
255 |
|
|
256 |
|
if (line_read) { |
265 |
|
|
266 |
|
strncpy(in_ptr = input, line_read, INPUT_LENGTH); |
267 |
|
input[INPUT_LENGTH-1] = 0; |
268 |
+ |
#else |
269 |
+ |
fprintf(monout, prompt); |
270 |
+ |
fflush(monout); |
271 |
+ |
fgets(in_ptr = input, INPUT_LENGTH, monin); |
272 |
+ |
char *s = strchr(input, '\n'); |
273 |
+ |
if (s != NULL) |
274 |
+ |
*s = 0; |
275 |
+ |
#endif |
276 |
|
} |
277 |
|
|
278 |
|
|
830 |
|
fprintf(monout, "No variables defined\n"); |
831 |
|
else |
832 |
|
for (Variable *v=first_var; v; v=v->next) |
833 |
< |
fprintf(monout, "%s = %08lx\n", v->name, v->value); |
833 |
> |
fprintf(monout, "%s = %08x\n", v->name, v->value); |
834 |
|
|
835 |
|
} else if (mon_token == T_NAME) { |
836 |
|
char var_name[256]; |
923 |
|
} |
924 |
|
|
925 |
|
if (mon_token == T_END) { |
926 |
< |
fprintf(monerr, "Buffer size: %08lx bytes\n", mon_mem_size); |
926 |
> |
fprintf(monerr, "Buffer size: %08x bytes\n", mon_mem_size); |
927 |
|
return; |
928 |
|
} |
929 |
|
|
935 |
|
} |
936 |
|
|
937 |
|
if ((mem = (uint8 *)realloc(mem, size)) != NULL) |
938 |
< |
fprintf(monerr, "Buffer size: %08lx bytes\n", mon_mem_size = size); |
938 |
> |
fprintf(monerr, "Buffer size: %08x bytes\n", mon_mem_size = size); |
939 |
|
else |
940 |
|
fprintf(monerr, "Unable to reallocate buffer\n"); |
941 |
|
} |
977 |
|
read_func = mon_read_word; |
978 |
|
write_func = mon_write_word; |
979 |
|
break; |
980 |
+ |
default: |
981 |
+ |
abort(); |
982 |
+ |
break; |
983 |
|
} |
984 |
|
|
985 |
|
while (adr<=end_adr) { |
1087 |
|
mon_add_command("]", save_data, "] start size \"file\" Save data to file\n"); |
1088 |
|
mon_add_command("set", set_var, "set [var[=value]] Set/clear/show variables\n"); |
1089 |
|
mon_add_command("cv", clear_vars, "cv Clear all variables\n"); |
1090 |
+ |
|
1091 |
+ |
mon_read_byte = NULL; |
1092 |
+ |
mon_write_byte = NULL; |
1093 |
|
} |
1094 |
|
|
1095 |
|
|
1135 |
|
interactive = (argc == 0); |
1136 |
|
} |
1137 |
|
|
1138 |
+ |
// Set up memory access functions if not supplied by the user |
1139 |
+ |
if (mon_read_byte == NULL) { |
1140 |
+ |
if (mon_use_real_mem) |
1141 |
+ |
mon_read_byte = mon_read_byte_real; |
1142 |
+ |
else |
1143 |
+ |
mon_read_byte = mon_read_byte_buffer; |
1144 |
+ |
} |
1145 |
+ |
if (mon_write_byte == NULL) { |
1146 |
+ |
if (mon_use_real_mem) |
1147 |
+ |
mon_write_byte = mon_write_byte_real; |
1148 |
+ |
else |
1149 |
+ |
mon_write_byte = mon_write_byte_buffer; |
1150 |
+ |
} |
1151 |
+ |
|
1152 |
|
// Allocate buffer |
1153 |
|
if (!mon_use_real_mem) { |
1154 |
|
mon_mem_size = 0x100000; |
1156 |
|
|
1157 |
|
// Print banner |
1158 |
|
if (interactive) |
1159 |
< |
fprintf(monerr, "\n *** mon V%d.%d by Christian Bauer ***\n" |
1160 |
< |
" *** Press 'h' for help ***\n\n", MON_VERSION, MON_REVISION); |
1159 |
> |
fprintf(monerr, "\n *** mon V%d.%d by Christian Bauer and Marc Hellwig ***\n" |
1160 |
> |
" *** Press 'h' for help ***\n\n", MON_VERSION_MAJOR, MON_VERSION_MINOR); |
1161 |
|
} |
1162 |
|
|
1163 |
|
init_abort(); |
1166 |
|
while (!done) { |
1167 |
|
if (interactive) { |
1168 |
|
char prompt[16]; |
1169 |
< |
sprintf(prompt, "[%08lx]-> ", mon_dot_address); |
1169 |
> |
sprintf(prompt, "[%08x]-> ", mon_dot_address); |
1170 |
|
read_line(prompt); |
1171 |
|
} else { |
1172 |
|
if (argc == 0) { |