1 |
|
/* |
2 |
< |
* mon.cpp - Machine language monitor |
2 |
> |
* mon.cpp - cxmon main program |
3 |
|
* |
4 |
< |
* (C) 1997-1999 Christian Bauer |
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 |
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> |
27 |
< |
#include <unistd.h> |
28 |
< |
#include <errno.h> |
27 |
> |
#include <string> |
28 |
> |
#include <map> |
29 |
|
|
30 |
+ |
#if defined(HAVE_READLINE_H) |
31 |
+ |
extern "C" { |
32 |
+ |
#include <readline.h> |
33 |
+ |
} |
34 |
+ |
#elif defined(HAVE_READLINE_READLINE_H) |
35 |
+ |
extern "C" { |
36 |
+ |
#include <readline/readline.h> |
37 |
+ |
} |
38 |
+ |
#endif |
39 |
+ |
|
40 |
+ |
#if defined(HAVE_HISTORY_H) |
41 |
+ |
extern "C" { |
42 |
+ |
#include <history.h> |
43 |
+ |
} |
44 |
+ |
#elif defined(HAVE_READLINE_HISTORY_H) |
45 |
|
extern "C" { |
46 |
< |
extern char *readline(char *prompt); |
19 |
< |
extern void add_history(char *str); |
46 |
> |
#include <readline/history.h> |
47 |
|
} |
48 |
+ |
#endif |
49 |
|
|
50 |
|
#include "mon.h" |
51 |
|
#include "mon_cmd.h" |
52 |
+ |
#include "mon_lowmem.h" |
53 |
+ |
|
54 |
+ |
#ifndef VERSION |
55 |
+ |
#define VERSION "3" |
56 |
+ |
#endif |
57 |
|
|
58 |
|
|
59 |
|
// Buffer we're operating on |
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 |
< |
struct Variable { |
100 |
< |
Variable *next; // Pointer to next variable (must be first element of struct) |
68 |
< |
char *name; // Variable name |
69 |
< |
uint32 value; // Variable value |
70 |
< |
}; |
71 |
< |
|
72 |
< |
static Variable *first_var; // Pointer to first variable |
99 |
> |
typedef std::map<std::string, uintptr> var_map; |
100 |
> |
static var_map vars; |
101 |
|
|
102 |
|
|
103 |
|
// Prototypes |
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); |
94 |
< |
static Variable *lookup_var(const char *s); |
95 |
< |
static Variable *insert_var(const char *s); |
96 |
< |
static void remove_var(const char *s); |
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(uintptr adr) |
208 |
|
{ |
209 |
< |
if (mon_use_real_mem) |
183 |
< |
return *(uint8 *)adr; |
184 |
< |
else |
185 |
< |
return mem[adr % mon_mem_size]; |
209 |
> |
return mem[adr % mon_mem_size]; |
210 |
|
} |
211 |
|
|
212 |
< |
void mon_write_byte(uint32 adr, uint32 b) |
212 |
> |
uint32 mon_read_byte_real(uintptr adr) |
213 |
|
{ |
214 |
< |
if (mon_use_real_mem) |
191 |
< |
*(uint8 *)adr = b; |
192 |
< |
else |
193 |
< |
mem[adr % mon_mem_size] = b; |
214 |
> |
return *(uint8 *)adr; |
215 |
|
} |
216 |
|
|
217 |
< |
uint32 mon_read_half(uint32 adr) |
217 |
> |
void (*mon_write_byte)(uintptr adr, uint32 b); |
218 |
> |
|
219 |
> |
void mon_write_byte_buffer(uintptr adr, uint32 b) |
220 |
|
{ |
221 |
< |
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]; |
221 |
> |
mem[adr % mon_mem_size] = b; |
222 |
|
} |
223 |
|
|
224 |
< |
void mon_write_half(uint32 adr, uint32 w) |
224 |
> |
void mon_write_byte_real(uintptr adr, uint32 b) |
225 |
|
{ |
226 |
< |
if (mon_use_real_mem) |
207 |
< |
*(uint16 *)adr = htons(w); |
208 |
< |
else { |
209 |
< |
mem[adr % mon_mem_size] = w >> 8; |
210 |
< |
mem[(adr+1) % mon_mem_size] = w; |
211 |
< |
} |
226 |
> |
*(uint8 *)adr = b; |
227 |
|
} |
228 |
|
|
229 |
< |
uint32 mon_read_word(uint32 adr) |
229 |
> |
uint32 mon_read_half(uintptr adr) |
230 |
|
{ |
231 |
< |
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); |
231 |
> |
return (mon_read_byte(adr) << 8) | mon_read_byte(adr+1); |
232 |
|
} |
233 |
|
|
234 |
< |
void mon_write_word(uint32 adr, uint32 l) |
234 |
> |
void mon_write_half(uintptr adr, uint32 w) |
235 |
|
{ |
236 |
< |
if (mon_use_real_mem) |
237 |
< |
*(uint32 *)adr = htonl(l); |
238 |
< |
else { |
239 |
< |
mem[adr % mon_mem_size] = l >> 24; |
240 |
< |
mem[(adr+1) % mon_mem_size] = l >> 16; |
241 |
< |
mem[(adr+2) % mon_mem_size] = l >> 8; |
242 |
< |
mem[(adr+3) % mon_mem_size] = l; |
243 |
< |
} |
236 |
> |
mon_write_byte(adr, w >> 8); |
237 |
> |
mon_write_byte(adr+1, w); |
238 |
> |
} |
239 |
> |
|
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(uintptr adr, uint32 l) |
246 |
> |
{ |
247 |
> |
mon_write_byte(adr, l >> 24); |
248 |
> |
mon_write_byte(adr+1, l >> 16); |
249 |
> |
mon_write_byte(adr+2, l >> 8); |
250 |
> |
mon_write_byte(adr+3, l); |
251 |
|
} |
252 |
|
|
253 |
|
|
257 |
|
|
258 |
|
static void read_line(char *prompt) |
259 |
|
{ |
260 |
+ |
#ifdef HAVE_LIBREADLINE |
261 |
|
static char *line_read = NULL; |
262 |
|
|
263 |
|
if (line_read) { |
267 |
|
|
268 |
|
line_read = readline(prompt); |
269 |
|
|
270 |
< |
if (line_read && *line_read) |
271 |
< |
add_history(line_read); |
270 |
> |
if (line_read) { |
271 |
> |
|
272 |
> |
if (*line_read) |
273 |
> |
add_history(line_read); |
274 |
> |
|
275 |
> |
strncpy(in_ptr = input, line_read, INPUT_LENGTH); |
276 |
> |
input[INPUT_LENGTH-1] = 0; |
277 |
|
|
278 |
< |
strncpy(in_ptr = input, line_read, INPUT_LENGTH); |
279 |
< |
input[INPUT_LENGTH-1] = 0; |
278 |
> |
} else { |
279 |
> |
|
280 |
> |
// EOF, quit cxmon |
281 |
> |
fprintf(monout, "x\n"); |
282 |
> |
input[0] = 'x'; |
283 |
> |
input[1] = 0; |
284 |
> |
in_ptr = input; |
285 |
> |
} |
286 |
> |
#else |
287 |
> |
fprintf(monout, prompt); |
288 |
> |
fflush(monout); |
289 |
> |
fgets(in_ptr = input, INPUT_LENGTH, monin); |
290 |
> |
char *s = strchr(input, '\n'); |
291 |
> |
if (s != NULL) |
292 |
> |
*s = 0; |
293 |
> |
#endif |
294 |
|
} |
295 |
|
|
296 |
|
|
396 |
|
} |
397 |
|
} |
398 |
|
|
399 |
< |
static enum Token get_hex_number(uint32 &i) |
399 |
> |
static enum Token get_hex_number(uintptr &i) |
400 |
|
{ |
401 |
|
char c = get_char(); |
402 |
|
|
405 |
|
return T_NULL; |
406 |
|
|
407 |
|
do { |
408 |
+ |
c = tolower(c); |
409 |
|
if (c < 'a') |
410 |
|
i = (i << 4) + (c - '0'); |
411 |
|
else |
421 |
|
} |
422 |
|
} |
423 |
|
|
424 |
< |
static enum Token get_dec_number(uint32 &i) |
424 |
> |
static enum Token get_dec_number(uintptr &i) |
425 |
|
{ |
426 |
|
char c = get_char(); |
427 |
|
|
442 |
|
} |
443 |
|
} |
444 |
|
|
445 |
< |
static enum Token get_char_number(uint32 &i) |
445 |
> |
static enum Token get_char_number(uintptr &i) |
446 |
|
{ |
447 |
|
char c; |
448 |
|
|
473 |
|
return T_NULL; |
474 |
|
} |
475 |
|
|
476 |
< |
static enum Token get_hex_or_name(uint32 &i, char *name) |
476 |
> |
static enum Token get_hex_or_name(uintptr &i, char *name) |
477 |
|
{ |
478 |
|
char *old_in_ptr = in_ptr; |
479 |
|
char c; |
501 |
|
* true: OK, false: Error |
502 |
|
*/ |
503 |
|
|
504 |
< |
bool mon_expression(uint32 *number) |
504 |
> |
bool mon_expression(uintptr *number) |
505 |
|
{ |
506 |
< |
uint32 accu, expr; |
506 |
> |
uintptr accu, expr; |
507 |
|
|
508 |
|
if (!eor_expr(&accu)) |
509 |
|
return false; |
529 |
|
* true: OK, false: Error |
530 |
|
*/ |
531 |
|
|
532 |
< |
static bool eor_expr(uint32 *number) |
532 |
> |
static bool eor_expr(uintptr *number) |
533 |
|
{ |
534 |
< |
uint32 accu, expr; |
534 |
> |
uintptr accu, expr; |
535 |
|
|
536 |
|
if (!and_expr(&accu)) |
537 |
|
return false; |
557 |
|
* true: OK, false: Error |
558 |
|
*/ |
559 |
|
|
560 |
< |
static bool and_expr(uint32 *number) |
560 |
> |
static bool and_expr(uintptr *number) |
561 |
|
{ |
562 |
< |
uint32 accu, expr; |
562 |
> |
uintptr accu, expr; |
563 |
|
|
564 |
|
if (!shift_expr(&accu)) |
565 |
|
return false; |
585 |
|
* true: OK, false: Error |
586 |
|
*/ |
587 |
|
|
588 |
< |
static bool shift_expr(uint32 *number) |
588 |
> |
static bool shift_expr(uintptr *number) |
589 |
|
{ |
590 |
< |
uint32 accu, expr; |
590 |
> |
uintptr accu, expr; |
591 |
|
|
592 |
|
if (!add_expr(&accu)) |
593 |
|
return false; |
620 |
|
* true: OK, false: Error |
621 |
|
*/ |
622 |
|
|
623 |
< |
static bool add_expr(uint32 *number) |
623 |
> |
static bool add_expr(uintptr *number) |
624 |
|
{ |
625 |
< |
uint32 accu, expr; |
625 |
> |
uintptr accu, expr; |
626 |
|
|
627 |
|
if (!mul_expr(&accu)) |
628 |
|
return false; |
655 |
|
* true: OK, false: Error |
656 |
|
*/ |
657 |
|
|
658 |
< |
static bool mul_expr(uint32 *number) |
658 |
> |
static bool mul_expr(uintptr *number) |
659 |
|
{ |
660 |
< |
uint32 accu, fact; |
660 |
> |
uintptr accu, fact; |
661 |
|
|
662 |
|
if (!factor(&accu)) |
663 |
|
return false; |
705 |
|
* true: OK, false: Error |
706 |
|
*/ |
707 |
|
|
708 |
< |
static bool factor(uint32 *number) |
708 |
> |
static bool factor(uintptr *number) |
709 |
|
{ |
710 |
|
switch (mon_token) { |
711 |
|
case T_NUMBER: |
714 |
|
return true; |
715 |
|
|
716 |
|
case T_NAME:{ |
717 |
< |
Variable *var; |
718 |
< |
if ((var = lookup_var(mon_name)) != NULL) { |
719 |
< |
*number = var->value; |
717 |
> |
var_map::const_iterator v = vars.find(mon_name); |
718 |
> |
if (v == vars.end()) |
719 |
> |
return false; |
720 |
> |
else { |
721 |
> |
*number = v->second; |
722 |
|
mon_get_token(); |
723 |
|
return true; |
724 |
< |
} else |
683 |
< |
return false; |
724 |
> |
} |
725 |
|
} |
726 |
|
|
727 |
|
case T_DOT: |
781 |
|
|
782 |
|
|
783 |
|
/* |
743 |
– |
* Lookup the value of a variable |
744 |
– |
*/ |
745 |
– |
|
746 |
– |
static Variable *lookup_var(const char *s) |
747 |
– |
{ |
748 |
– |
// Lookup variable |
749 |
– |
for (Variable *var=first_var; var; var=var->next) |
750 |
– |
if (!strcmp(s, var->name)) |
751 |
– |
return var; |
752 |
– |
|
753 |
– |
// Not found, error |
754 |
– |
mon_error("Undefined variable"); |
755 |
– |
return NULL; |
756 |
– |
} |
757 |
– |
|
758 |
– |
|
759 |
– |
/* |
760 |
– |
* Insert new variable (or redefine old) |
761 |
– |
*/ |
762 |
– |
|
763 |
– |
static Variable *insert_var(const char *s) |
764 |
– |
{ |
765 |
– |
// Lookup variable |
766 |
– |
for (Variable *var=first_var; var; var=var->next) |
767 |
– |
if (!strcmp(s, var->name)) |
768 |
– |
return var; |
769 |
– |
|
770 |
– |
// Insert new variable |
771 |
– |
Variable *var = new Variable; |
772 |
– |
var->name = strdup(s); |
773 |
– |
var->next = first_var; |
774 |
– |
first_var = var; |
775 |
– |
return var; |
776 |
– |
} |
777 |
– |
|
778 |
– |
|
779 |
– |
/* |
780 |
– |
* Remove variable |
781 |
– |
*/ |
782 |
– |
|
783 |
– |
static void remove_var(const char *s) |
784 |
– |
{ |
785 |
– |
Variable *var, *prev = (Variable *)&first_var; |
786 |
– |
|
787 |
– |
// Lookup variable and remove it |
788 |
– |
for (var=prev->next; var; prev=var, var=var->next) |
789 |
– |
if (!strcmp(s, var->name)) { |
790 |
– |
prev->next = var->next; |
791 |
– |
free(var->name); |
792 |
– |
free(var); |
793 |
– |
return; |
794 |
– |
} |
795 |
– |
} |
796 |
– |
|
797 |
– |
|
798 |
– |
/* |
784 |
|
* Set/clear/show variables |
785 |
|
* set [var[=value]] |
786 |
|
*/ |
790 |
|
if (mon_token == T_END) { |
791 |
|
|
792 |
|
// Show all variables |
793 |
< |
if (first_var == NULL) |
793 |
> |
if (vars.empty()) |
794 |
|
fprintf(monout, "No variables defined\n"); |
795 |
< |
else |
796 |
< |
for (Variable *v=first_var; v; v=v->next) |
797 |
< |
fprintf(monout, "%s = %08lx\n", v->name, v->value); |
795 |
> |
else { |
796 |
> |
var_map::const_iterator v = vars.begin(), end = vars.end(); |
797 |
> |
for (v=vars.begin(); v!=end; ++v) |
798 |
> |
fprintf(monout, "%s = %08x\n", v->first.c_str(), v->second); |
799 |
> |
} |
800 |
|
|
801 |
|
} else if (mon_token == T_NAME) { |
802 |
< |
char var_name[256]; |
816 |
< |
strcpy(var_name, mon_name); |
802 |
> |
std::string var_name = mon_name; |
803 |
|
mon_get_token(); |
804 |
|
if (mon_token == T_ASSIGN) { |
805 |
|
|
806 |
|
// Set variable |
807 |
< |
uint32 value; |
807 |
> |
uintptr value; |
808 |
|
mon_get_token(); |
809 |
|
if (!mon_expression(&value)) |
810 |
|
return; |
812 |
|
mon_error("Too many arguments"); |
813 |
|
return; |
814 |
|
} |
815 |
< |
insert_var(var_name)->value = value; |
815 |
> |
vars[var_name] = value; |
816 |
|
|
817 |
|
} else if (mon_token == T_END) { |
818 |
|
|
819 |
|
// Clear variable |
820 |
< |
remove_var(var_name); |
820 |
> |
vars.erase(var_name); |
821 |
|
|
822 |
|
} else |
823 |
|
mon_error("'=' expected"); |
833 |
|
|
834 |
|
static void clear_vars(void) |
835 |
|
{ |
836 |
< |
Variable *var, *next; |
851 |
< |
for (var=first_var; var; var=next) { |
852 |
< |
free(var->name); |
853 |
< |
next = var->next; |
854 |
< |
free(var); |
855 |
< |
} |
856 |
< |
first_var = NULL; |
836 |
> |
vars.clear(); |
837 |
|
} |
838 |
|
|
839 |
|
|
874 |
|
|
875 |
|
static void reallocate(void) |
876 |
|
{ |
877 |
< |
uint32 size; |
877 |
> |
uintptr size; |
878 |
|
|
879 |
|
if (mon_use_real_mem) { |
880 |
|
fprintf(monerr, "Cannot reallocate buffer in real mode\n"); |
882 |
|
} |
883 |
|
|
884 |
|
if (mon_token == T_END) { |
885 |
< |
fprintf(monerr, "Buffer size: %08lx bytes\n", mon_mem_size); |
885 |
> |
fprintf(monerr, "Buffer size: %08x bytes\n", mon_mem_size); |
886 |
|
return; |
887 |
|
} |
888 |
|
|
894 |
|
} |
895 |
|
|
896 |
|
if ((mem = (uint8 *)realloc(mem, size)) != NULL) |
897 |
< |
fprintf(monerr, "Buffer size: %08lx bytes\n", mon_mem_size = size); |
897 |
> |
fprintf(monerr, "Buffer size: %08x bytes\n", mon_mem_size = size); |
898 |
|
else |
899 |
|
fprintf(monerr, "Unable to reallocate buffer\n"); |
900 |
|
} |
907 |
|
|
908 |
|
static void apply(int size) |
909 |
|
{ |
910 |
< |
uint32 adr, end_adr, value; |
910 |
> |
uintptr adr, end_adr, value; |
911 |
|
char c; |
912 |
|
|
913 |
|
if (!mon_expression(&adr)) |
921 |
|
return; |
922 |
|
} |
923 |
|
|
924 |
< |
uint32 (*read_func)(uint32 adr); |
925 |
< |
void (*write_func)(uint32 adr, uint32 val); |
924 |
> |
uint32 (*read_func)(uintptr adr); |
925 |
> |
void (*write_func)(uintptr adr, uint32 val); |
926 |
|
switch (size) { |
927 |
|
case 1: |
928 |
|
read_func = mon_read_byte; |
936 |
|
read_func = mon_read_word; |
937 |
|
write_func = mon_write_word; |
938 |
|
break; |
939 |
+ |
default: |
940 |
+ |
abort(); |
941 |
+ |
break; |
942 |
|
} |
943 |
|
|
944 |
|
while (adr<=end_adr) { |
1015 |
|
num_cmds = 0; |
1016 |
|
cmd_help = NULL; |
1017 |
|
|
1018 |
< |
mon_add_command("??", mon_cmd_list, "?? Show list of commands\n"); |
1019 |
< |
mon_add_command("ver", version, "ver Show version\n"); |
1020 |
< |
mon_add_command("?", print_expr, "? expression Calculate expression\n"); |
1021 |
< |
mon_add_command("@", reallocate, "@ [size] Reallocate buffer\n"); |
1022 |
< |
mon_add_command("i", ascii_dump, "i [start [end]] ASCII memory dump\n"); |
1023 |
< |
mon_add_command("m", memory_dump, "m [start [end]] Hex/ASCII memory dump\n"); |
1024 |
< |
mon_add_command("d", disassemble_ppc, "d [start [end]] Disassemble PowerPC code\n"); |
1025 |
< |
mon_add_command("d65", disassemble_6502, "d65 [start [end]] Disassemble 6502 code\n"); |
1026 |
< |
mon_add_command("d68", disassemble_680x0, "d68 [start [end]] Disassemble 680x0 code\n"); |
1027 |
< |
mon_add_command("d80", disassemble_8080, "d80 [start [end]] Disassemble 8080 code\n"); |
1028 |
< |
mon_add_command("d86", disassemble_80x86, "d86 [start [end]] Disassemble 80x86 code\n"); |
1029 |
< |
mon_add_command(":", modify, ": start string Modify memory\n"); |
1030 |
< |
mon_add_command("f", fill, "f start end string Fill memory\n"); |
1031 |
< |
mon_add_command("y", apply_byte, "y[b|h|w] start end expr Apply expression to memory\n"); |
1018 |
> |
mon_add_command("??", mon_cmd_list, "?? Show list of commands\n"); |
1019 |
> |
mon_add_command("ver", version, "ver Show version\n"); |
1020 |
> |
mon_add_command("?", print_expr, "? expression Calculate expression\n"); |
1021 |
> |
mon_add_command("@", reallocate, "@ [size] Reallocate buffer\n"); |
1022 |
> |
mon_add_command("i", ascii_dump, "i [start [end]] ASCII memory dump\n"); |
1023 |
> |
mon_add_command("m", memory_dump, "m [start [end]] Hex/ASCII memory dump\n"); |
1024 |
> |
mon_add_command("b", binary_dump, "b [start [end]] Binary memory dump\n"); |
1025 |
> |
mon_add_command("d", disassemble_ppc, "d [start [end]] Disassemble PowerPC code\n"); |
1026 |
> |
mon_add_command("d65", disassemble_6502, "d65 [start [end]] Disassemble 6502 code\n"); |
1027 |
> |
mon_add_command("d68", disassemble_680x0, "d68 [start [end]] Disassemble 680x0 code\n"); |
1028 |
> |
mon_add_command("d80", disassemble_z80, "d80 [start [end]] Disassemble Z80 code\n"); |
1029 |
> |
mon_add_command("d86", disassemble_80x86_32, "d86 [start [end]] Disassemble 80x86 (32-bit) code\n"); |
1030 |
> |
mon_add_command("d8086", disassemble_80x86_16, "d8086 [start [end]] Disassemble 80x86 (16-bit) code\n"); |
1031 |
> |
mon_add_command("d8664", disassemble_x86_64, "d8664 [start [end]] Disassemble x86-64 code\n"); |
1032 |
> |
mon_add_command(":", modify, ": start string Modify memory\n"); |
1033 |
> |
mon_add_command("f", fill, "f start end string Fill memory\n"); |
1034 |
> |
mon_add_command("y", apply_byte, "y[b|h|w] start end expr Apply expression to memory\n"); |
1035 |
|
mon_add_command("yb", apply_byte, NULL); |
1036 |
|
mon_add_command("yh", apply_half, NULL); |
1037 |
|
mon_add_command("yw", apply_word, NULL); |
1038 |
< |
mon_add_command("t", transfer, "t start end dest Transfer memory\n"); |
1039 |
< |
mon_add_command("c", compare, "c start end dest Compare memory\n"); |
1040 |
< |
mon_add_command("h", help_or_hunt, "h start end string Search for byte string\n"); |
1041 |
< |
mon_add_command("\\", shell_command, "\\ \"command\" Execute shell command\n"); |
1042 |
< |
mon_add_command("ls", mon_exec, "ls [args] List directory contents\n"); |
1043 |
< |
mon_add_command("rm", mon_exec, "rm [args] Remove file(s)\n"); |
1044 |
< |
mon_add_command("cp", mon_exec, "cp [args] Copy file(s)\n"); |
1045 |
< |
mon_add_command("mv", mon_exec, "mv [args] Move file(s)\n"); |
1046 |
< |
mon_add_command("cd", mon_change_dir, "cd directory Change current directory\n"); |
1047 |
< |
mon_add_command("o", redir_output, "o [\"file\"] Redirect output\n"); |
1048 |
< |
mon_add_command("[", load_data, "[ start \"file\" Load data from file\n"); |
1049 |
< |
mon_add_command("]", save_data, "] start size \"file\" Save data to file\n"); |
1050 |
< |
mon_add_command("set", set_var, "set [var[=value]] Set/clear/show variables\n"); |
1051 |
< |
mon_add_command("cv", clear_vars, "cv Clear all variables\n"); |
1038 |
> |
mon_add_command("t", transfer, "t start end dest Transfer memory\n"); |
1039 |
> |
mon_add_command("c", compare, "c start end dest Compare memory\n"); |
1040 |
> |
mon_add_command("h", help_or_hunt, "h start end string Search for byte string\n"); |
1041 |
> |
mon_add_command("\\", shell_command, "\\ \"command\" Execute shell command\n"); |
1042 |
> |
mon_add_command("ls", mon_exec, "ls [args] List directory contents\n"); |
1043 |
> |
mon_add_command("rm", mon_exec, "rm [args] Remove file(s)\n"); |
1044 |
> |
mon_add_command("cp", mon_exec, "cp [args] Copy file(s)\n"); |
1045 |
> |
mon_add_command("mv", mon_exec, "mv [args] Move file(s)\n"); |
1046 |
> |
mon_add_command("cd", mon_change_dir, "cd directory Change current directory\n"); |
1047 |
> |
mon_add_command("o", redir_output, "o [\"file\"] Redirect output\n"); |
1048 |
> |
mon_add_command("[", load_data, "[ start \"file\" Load data from file\n"); |
1049 |
> |
mon_add_command("]", save_data, "] start size \"file\" Save data to file\n"); |
1050 |
> |
mon_add_command("set", set_var, "set [var[=value]] Set/clear/show variables\n"); |
1051 |
> |
mon_add_command("cv", clear_vars, "cv Clear all variables\n"); |
1052 |
> |
|
1053 |
> |
mon_read_byte = NULL; |
1054 |
> |
mon_write_byte = NULL; |
1055 |
|
} |
1056 |
|
|
1057 |
|
|
1082 |
|
monout = stdout; |
1083 |
|
monerr = stdout; |
1084 |
|
|
1085 |
< |
if (argc) { |
1086 |
< |
// Access real memory if mon was started as "rmon" |
1087 |
< |
char *prgname = argv[0]; |
1088 |
< |
char *lastslash; |
1089 |
< |
if ((lastslash = strrchr(prgname, '/')) != NULL) |
1090 |
< |
prgname = lastslash + 1; |
1091 |
< |
if (strcmp(prgname, "rmon") == 0) |
1085 |
> |
// Make argc/argv point to the actual arguments |
1086 |
> |
const char *prg_name = argv[0]; |
1087 |
> |
if (argc) |
1088 |
> |
argc--; argv++; |
1089 |
> |
|
1090 |
> |
// Parse arguments |
1091 |
> |
mon_macos_mode = false; |
1092 |
> |
mon_use_real_mem = false; |
1093 |
> |
while (argc > 0) { |
1094 |
> |
if (strcmp(argv[0], "-h") == 0 || strcmp(argv[0], "--help") == 0) { |
1095 |
> |
printf("Usage: %s [-m] [-r] [command...]\n", prg_name); |
1096 |
> |
exit(0); |
1097 |
> |
} else if (strcmp(argv[0], "-m") == 0) |
1098 |
> |
mon_macos_mode = true; |
1099 |
> |
else if (strcmp(argv[0], "-r") == 0) |
1100 |
|
mon_use_real_mem = true; |
1101 |
+ |
else |
1102 |
+ |
break; |
1103 |
+ |
argc--; argv++; |
1104 |
+ |
} |
1105 |
+ |
interactive = (argc == 0); |
1106 |
|
|
1107 |
< |
// Make argc/argv point to the actual arguments |
1108 |
< |
argc--; |
1109 |
< |
argv++; |
1110 |
< |
interactive = (argc == 0); |
1107 |
> |
// Set up memory access functions if not supplied by the user |
1108 |
> |
if (mon_read_byte == NULL) { |
1109 |
> |
if (mon_use_real_mem) |
1110 |
> |
mon_read_byte = mon_read_byte_real; |
1111 |
> |
else |
1112 |
> |
mon_read_byte = mon_read_byte_buffer; |
1113 |
> |
} |
1114 |
> |
if (mon_write_byte == NULL) { |
1115 |
> |
if (mon_use_real_mem) |
1116 |
> |
mon_write_byte = mon_write_byte_real; |
1117 |
> |
else |
1118 |
> |
mon_write_byte = mon_write_byte_buffer; |
1119 |
|
} |
1120 |
|
|
1121 |
|
// Allocate buffer |
1125 |
|
|
1126 |
|
// Print banner |
1127 |
|
if (interactive) |
1128 |
< |
fprintf(monerr, "\n *** mon V%d.%d by Christian Bauer ***\n" |
1129 |
< |
" *** Press 'h' for help ***\n\n", MON_VERSION, MON_REVISION); |
1128 |
> |
fprintf(monerr, "\n *** cxmon V" VERSION " by Christian Bauer and Marc Hellwig ***\n" |
1129 |
> |
" *** Press 'h' for help ***\n\n"); |
1130 |
> |
} |
1131 |
> |
|
1132 |
> |
// Clear variables |
1133 |
> |
vars.clear(); |
1134 |
> |
|
1135 |
> |
// In MacOS mode, pull in the lowmem globals as variables |
1136 |
> |
if (mon_macos_mode) { |
1137 |
> |
const lowmem_info *l = lowmem; |
1138 |
> |
while (l->name) { |
1139 |
> |
vars[l->name] = l->addr; |
1140 |
> |
l++; |
1141 |
> |
} |
1142 |
|
} |
1143 |
|
|
1144 |
|
init_abort(); |
1147 |
|
while (!done) { |
1148 |
|
if (interactive) { |
1149 |
|
char prompt[16]; |
1150 |
< |
sprintf(prompt, "[%08lx]-> ", mon_dot_address); |
1150 |
> |
sprintf(prompt, "[%0*lx]-> ", 2 * sizeof(mon_dot_address), mon_dot_address); |
1151 |
|
read_line(prompt); |
1152 |
|
} else { |
1153 |
|
if (argc == 0) { |