71 |
|
char *mon_args_ptr; |
72 |
|
|
73 |
|
// Current address, value of '.' in expressions |
74 |
< |
uint32 mon_dot_address; |
74 |
> |
uintptr mon_dot_address; |
75 |
|
|
76 |
|
// Current value of ':' in expression |
77 |
|
static uint32 colon_value; |
79 |
|
|
80 |
|
// Scanner variables |
81 |
|
enum Token mon_token; // Last token read |
82 |
< |
uint32 mon_number; // Contains the number if mon_token==T_NUMBER |
82 |
> |
uintptr mon_number; // Contains the number if mon_token==T_NUMBER |
83 |
|
char mon_string[INPUT_LENGTH]; // Contains the string if mon_token==T_STRING |
84 |
|
char mon_name[INPUT_LENGTH]; // Contains the variable name if mon_token==T_NAME |
85 |
|
|
96 |
|
|
97 |
|
|
98 |
|
// List of variables |
99 |
< |
typedef std::map<std::string, uint32> var_map; |
99 |
> |
typedef std::map<std::string, uintptr> var_map; |
100 |
|
static var_map vars; |
101 |
|
|
102 |
|
|
107 |
|
static void read_line(char *prompt); // Scanner |
108 |
|
static char get_char(void); |
109 |
|
static void put_back(char c); |
110 |
< |
static enum Token get_hex_number(uint32 &i); |
111 |
< |
static enum Token get_dec_number(uint32 &i); |
112 |
< |
static enum Token get_char_number(uint32 &i); |
110 |
> |
static enum Token get_hex_number(uintptr &i); |
111 |
> |
static enum Token get_dec_number(uintptr &i); |
112 |
> |
static enum Token get_char_number(uintptr &i); |
113 |
|
static enum Token get_string(char *str); |
114 |
< |
static enum Token get_hex_or_name(uint32 &i, char *name); |
114 |
> |
static enum Token get_hex_or_name(uintptr &i, char *name); |
115 |
|
|
116 |
< |
static bool eor_expr(uint32 *number); // Parser |
117 |
< |
static bool and_expr(uint32 *number); |
118 |
< |
static bool shift_expr(uint32 *number); |
119 |
< |
static bool add_expr(uint32 *number); |
120 |
< |
static bool mul_expr(uint32 *number); |
121 |
< |
static bool factor(uint32 *number); |
116 |
> |
static bool eor_expr(uintptr *number); // Parser |
117 |
> |
static bool and_expr(uintptr *number); |
118 |
> |
static bool shift_expr(uintptr *number); |
119 |
> |
static bool add_expr(uintptr *number); |
120 |
> |
static bool mul_expr(uintptr *number); |
121 |
> |
static bool factor(uintptr *number); |
122 |
|
|
123 |
|
|
124 |
|
/* |
202 |
|
* Access to buffer |
203 |
|
*/ |
204 |
|
|
205 |
< |
uint32 (*mon_read_byte)(uint32 adr); |
205 |
> |
uint32 (*mon_read_byte)(uintptr adr); |
206 |
|
|
207 |
< |
uint32 mon_read_byte_buffer(uint32 adr) |
207 |
> |
uint32 mon_read_byte_buffer(uintptr adr) |
208 |
|
{ |
209 |
|
return mem[adr % mon_mem_size]; |
210 |
|
} |
211 |
|
|
212 |
< |
uint32 mon_read_byte_real(uint32 adr) |
212 |
> |
uint32 mon_read_byte_real(uintptr adr) |
213 |
|
{ |
214 |
|
return *(uint8 *)adr; |
215 |
|
} |
216 |
|
|
217 |
< |
void (*mon_write_byte)(uint32 adr, uint32 b); |
217 |
> |
void (*mon_write_byte)(uintptr adr, uint32 b); |
218 |
|
|
219 |
< |
void mon_write_byte_buffer(uint32 adr, uint32 b) |
219 |
> |
void mon_write_byte_buffer(uintptr adr, uint32 b) |
220 |
|
{ |
221 |
|
mem[adr % mon_mem_size] = b; |
222 |
|
} |
223 |
|
|
224 |
< |
void mon_write_byte_real(uint32 adr, uint32 b) |
224 |
> |
void mon_write_byte_real(uintptr adr, uint32 b) |
225 |
|
{ |
226 |
|
*(uint8 *)adr = b; |
227 |
|
} |
228 |
|
|
229 |
< |
uint32 mon_read_half(uint32 adr) |
229 |
> |
uint32 mon_read_half(uintptr adr) |
230 |
|
{ |
231 |
|
return (mon_read_byte(adr) << 8) | mon_read_byte(adr+1); |
232 |
|
} |
233 |
|
|
234 |
< |
void mon_write_half(uint32 adr, uint32 w) |
234 |
> |
void mon_write_half(uintptr adr, uint32 w) |
235 |
|
{ |
236 |
|
mon_write_byte(adr, w >> 8); |
237 |
|
mon_write_byte(adr+1, w); |
238 |
|
} |
239 |
|
|
240 |
< |
uint32 mon_read_word(uint32 adr) |
240 |
> |
uint32 mon_read_word(uintptr adr) |
241 |
|
{ |
242 |
|
return (mon_read_byte(adr) << 24) | (mon_read_byte(adr+1) << 16) | (mon_read_byte(adr+2) << 8) | mon_read_byte(adr+3); |
243 |
|
} |
244 |
|
|
245 |
< |
void mon_write_word(uint32 adr, uint32 l) |
245 |
> |
void mon_write_word(uintptr adr, uint32 l) |
246 |
|
{ |
247 |
|
mon_write_byte(adr, l >> 24); |
248 |
|
mon_write_byte(adr+1, l >> 16); |
385 |
|
} |
386 |
|
} |
387 |
|
|
388 |
< |
static enum Token get_hex_number(uint32 &i) |
388 |
> |
static enum Token get_hex_number(uintptr &i) |
389 |
|
{ |
390 |
|
char c = get_char(); |
391 |
|
|
410 |
|
} |
411 |
|
} |
412 |
|
|
413 |
< |
static enum Token get_dec_number(uint32 &i) |
413 |
> |
static enum Token get_dec_number(uintptr &i) |
414 |
|
{ |
415 |
|
char c = get_char(); |
416 |
|
|
431 |
|
} |
432 |
|
} |
433 |
|
|
434 |
< |
static enum Token get_char_number(uint32 &i) |
434 |
> |
static enum Token get_char_number(uintptr &i) |
435 |
|
{ |
436 |
|
char c; |
437 |
|
|
462 |
|
return T_NULL; |
463 |
|
} |
464 |
|
|
465 |
< |
static enum Token get_hex_or_name(uint32 &i, char *name) |
465 |
> |
static enum Token get_hex_or_name(uintptr &i, char *name) |
466 |
|
{ |
467 |
|
char *old_in_ptr = in_ptr; |
468 |
|
char c; |
490 |
|
* true: OK, false: Error |
491 |
|
*/ |
492 |
|
|
493 |
< |
bool mon_expression(uint32 *number) |
493 |
> |
bool mon_expression(uintptr *number) |
494 |
|
{ |
495 |
< |
uint32 accu, expr; |
495 |
> |
uintptr accu, expr; |
496 |
|
|
497 |
|
if (!eor_expr(&accu)) |
498 |
|
return false; |
518 |
|
* true: OK, false: Error |
519 |
|
*/ |
520 |
|
|
521 |
< |
static bool eor_expr(uint32 *number) |
521 |
> |
static bool eor_expr(uintptr *number) |
522 |
|
{ |
523 |
< |
uint32 accu, expr; |
523 |
> |
uintptr accu, expr; |
524 |
|
|
525 |
|
if (!and_expr(&accu)) |
526 |
|
return false; |
546 |
|
* true: OK, false: Error |
547 |
|
*/ |
548 |
|
|
549 |
< |
static bool and_expr(uint32 *number) |
549 |
> |
static bool and_expr(uintptr *number) |
550 |
|
{ |
551 |
< |
uint32 accu, expr; |
551 |
> |
uintptr accu, expr; |
552 |
|
|
553 |
|
if (!shift_expr(&accu)) |
554 |
|
return false; |
574 |
|
* true: OK, false: Error |
575 |
|
*/ |
576 |
|
|
577 |
< |
static bool shift_expr(uint32 *number) |
577 |
> |
static bool shift_expr(uintptr *number) |
578 |
|
{ |
579 |
< |
uint32 accu, expr; |
579 |
> |
uintptr accu, expr; |
580 |
|
|
581 |
|
if (!add_expr(&accu)) |
582 |
|
return false; |
609 |
|
* true: OK, false: Error |
610 |
|
*/ |
611 |
|
|
612 |
< |
static bool add_expr(uint32 *number) |
612 |
> |
static bool add_expr(uintptr *number) |
613 |
|
{ |
614 |
< |
uint32 accu, expr; |
614 |
> |
uintptr accu, expr; |
615 |
|
|
616 |
|
if (!mul_expr(&accu)) |
617 |
|
return false; |
644 |
|
* true: OK, false: Error |
645 |
|
*/ |
646 |
|
|
647 |
< |
static bool mul_expr(uint32 *number) |
647 |
> |
static bool mul_expr(uintptr *number) |
648 |
|
{ |
649 |
< |
uint32 accu, fact; |
649 |
> |
uintptr accu, fact; |
650 |
|
|
651 |
|
if (!factor(&accu)) |
652 |
|
return false; |
694 |
|
* true: OK, false: Error |
695 |
|
*/ |
696 |
|
|
697 |
< |
static bool factor(uint32 *number) |
697 |
> |
static bool factor(uintptr *number) |
698 |
|
{ |
699 |
|
switch (mon_token) { |
700 |
|
case T_NUMBER: |
793 |
|
if (mon_token == T_ASSIGN) { |
794 |
|
|
795 |
|
// Set variable |
796 |
< |
uint32 value; |
796 |
> |
uintptr value; |
797 |
|
mon_get_token(); |
798 |
|
if (!mon_expression(&value)) |
799 |
|
return; |
863 |
|
|
864 |
|
static void reallocate(void) |
865 |
|
{ |
866 |
< |
uint32 size; |
866 |
> |
uintptr size; |
867 |
|
|
868 |
|
if (mon_use_real_mem) { |
869 |
|
fprintf(monerr, "Cannot reallocate buffer in real mode\n"); |
896 |
|
|
897 |
|
static void apply(int size) |
898 |
|
{ |
899 |
< |
uint32 adr, end_adr, value; |
899 |
> |
uintptr adr, end_adr, value; |
900 |
|
char c; |
901 |
|
|
902 |
|
if (!mon_expression(&adr)) |
910 |
|
return; |
911 |
|
} |
912 |
|
|
913 |
< |
uint32 (*read_func)(uint32 adr); |
914 |
< |
void (*write_func)(uint32 adr, uint32 val); |
913 |
> |
uint32 (*read_func)(uintptr adr); |
914 |
> |
void (*write_func)(uintptr adr, uint32 val); |
915 |
|
switch (size) { |
916 |
|
case 1: |
917 |
|
read_func = mon_read_byte; |
1135 |
|
while (!done) { |
1136 |
|
if (interactive) { |
1137 |
|
char prompt[16]; |
1138 |
< |
sprintf(prompt, "[%08x]-> ", mon_dot_address); |
1138 |
> |
sprintf(prompt, "[%0*lx]-> ", 2 * sizeof(mon_dot_address), mon_dot_address); |
1139 |
|
read_line(prompt); |
1140 |
|
} else { |
1141 |
|
if (argc == 0) { |