ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/mon/src/mon.cpp
(Generate patch)

Comparing mon/src/mon.cpp (file contents):
Revision 1.2 by cebix, 1999-10-04T21:16:02Z vs.
Revision 1.8 by hellwig, 2000-06-10T19:07:36Z

# Line 1 | Line 1
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
# Line 20 | Line 20
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>
# Line 34 | Line 39 | extern "C" {
39  
40   #include "mon.h"
41   #include "mon_cmd.h"
42 < #include "version.h"
42 >
43 > #ifndef VERSION
44 > #define VERSION "2"
45 > #endif
46  
47  
48   // Buffer we're operating on
# Line 191 | Line 199 | bool mon_aborted(void)
199   *  Access to buffer
200   */
201  
202 < uint32 mon_read_byte(uint32 adr)
202 > uint32 (*mon_read_byte)(uint32 adr);
203 >
204 > uint32 mon_read_byte_buffer(uint32 adr)
205   {
206 <        if (mon_use_real_mem)
197 <                return *(uint8 *)adr;
198 <        else
199 <                return mem[adr % mon_mem_size];
206 >        return mem[adr % mon_mem_size];
207   }
208  
209 < void mon_write_byte(uint32 adr, uint32 b)
209 > uint32 mon_read_byte_real(uint32 adr)
210   {
211 <        if (mon_use_real_mem)
212 <                *(uint8 *)adr = b;
213 <        else
214 <                mem[adr % mon_mem_size] = b;
211 >        return *(uint8 *)adr;
212 > }
213 >
214 > void (*mon_write_byte)(uint32 adr, uint32 b);
215 >
216 > void mon_write_byte_buffer(uint32 adr, uint32 b)
217 > {
218 >        mem[adr % mon_mem_size] = b;
219 > }
220 >
221 > void mon_write_byte_real(uint32 adr, uint32 b)
222 > {
223 >        *(uint8 *)adr = b;
224   }
225  
226   uint32 mon_read_half(uint32 adr)
227   {
228 <        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];
228 >        return (mon_read_byte(adr) << 8) | mon_read_byte(adr+1);
229   }
230  
231   void mon_write_half(uint32 adr, uint32 w)
232   {
233 <        if (mon_use_real_mem)
234 <                *(uint16 *)adr = htons(w);
222 <        else {
223 <                mem[adr % mon_mem_size] = w >> 8;
224 <                mem[(adr+1) % mon_mem_size] = w;
225 <        }
233 >        mon_write_byte(adr, w >> 8);
234 >        mon_write_byte(adr+1, w);
235   }
236  
237   uint32 mon_read_word(uint32 adr)
238   {
239 <        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);
239 >        return (mon_read_byte(adr) << 24) | (mon_read_byte(adr+1) << 16) | (mon_read_byte(adr+2) << 8) | mon_read_byte(adr+3);
240   }
241  
242   void mon_write_word(uint32 adr, uint32 l)
243   {
244 <        if (mon_use_real_mem)
245 <                *(uint32 *)adr = htonl(l);
246 <        else {
247 <                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 <        }
244 >        mon_write_byte(adr, l >> 24);
245 >        mon_write_byte(adr+1, l >> 16);
246 >        mon_write_byte(adr+2, l >> 8);
247 >        mon_write_byte(adr+3, l);
248   }
249  
250  
# Line 252 | Line 254 | void mon_write_word(uint32 adr, uint32 l
254  
255   static void read_line(char *prompt)
256   {
257 + #ifdef HAVE_LIBREADLINE
258          static char *line_read = NULL;
259  
260          if (line_read) {
# Line 266 | Line 269 | static void read_line(char *prompt)
269  
270          strncpy(in_ptr = input, line_read, INPUT_LENGTH);
271          input[INPUT_LENGTH-1] = 0;
272 + #else
273 +        fprintf(monout, prompt);
274 +        fflush(monout);
275 +        fgets(in_ptr = input, INPUT_LENGTH, monin);
276 +        char *s = strchr(input, '\n');
277 +        if (s != NULL)
278 +                *s = 0;
279 + #endif
280   }
281  
282  
# Line 823 | Line 834 | static void set_var(void)
834                          fprintf(monout, "No variables defined\n");
835                  else
836                          for (Variable *v=first_var; v; v=v->next)
837 <                                fprintf(monout, "%s = %08lx\n", v->name, v->value);
837 >                                fprintf(monout, "%s = %08x\n", v->name, v->value);
838  
839          } else if (mon_token == T_NAME) {
840                  char var_name[256];
# Line 916 | Line 927 | static void reallocate(void)
927          }
928  
929          if (mon_token == T_END) {
930 <                fprintf(monerr, "Buffer size: %08lx bytes\n", mon_mem_size);
930 >                fprintf(monerr, "Buffer size: %08x bytes\n", mon_mem_size);
931                  return;
932          }
933  
# Line 928 | Line 939 | static void reallocate(void)
939          }
940  
941          if ((mem = (uint8 *)realloc(mem, size)) != NULL)
942 <                fprintf(monerr, "Buffer size: %08lx bytes\n", mon_mem_size = size);
942 >                fprintf(monerr, "Buffer size: %08x bytes\n", mon_mem_size = size);
943          else
944                  fprintf(monerr, "Unable to reallocate buffer\n");
945   }
# Line 970 | Line 981 | static void apply(int size)
981                          read_func = mon_read_word;
982                          write_func = mon_write_word;
983                          break;
984 +                default:
985 +                        abort();
986 +                        break;
987          }
988  
989          while (adr<=end_adr) {
# Line 1052 | Line 1066 | void mon_init(void)
1066          mon_add_command("@", reallocate,                        "@ [size]                 Reallocate buffer\n");
1067          mon_add_command("i", ascii_dump,                        "i [start [end]]          ASCII memory dump\n");
1068          mon_add_command("m", memory_dump,                       "m [start [end]]          Hex/ASCII memory dump\n");
1069 +        mon_add_command("b", binary_dump,                       "b [start [end]]          Binary memory dump\n");
1070          mon_add_command("d", disassemble_ppc,           "d [start [end]]          Disassemble PowerPC code\n");
1071          mon_add_command("d65", disassemble_6502,        "d65 [start [end]]        Disassemble 6502 code\n");
1072          mon_add_command("d68", disassemble_680x0,       "d68 [start [end]]        Disassemble 680x0 code\n");
# Line 1077 | Line 1092 | void mon_init(void)
1092          mon_add_command("]", save_data,                         "] start size \"file\"      Save data to file\n");
1093          mon_add_command("set", set_var,                         "set [var[=value]]        Set/clear/show variables\n");
1094          mon_add_command("cv", clear_vars,                       "cv                       Clear all variables\n");
1095 +
1096 +        mon_read_byte = NULL;
1097 +        mon_write_byte = NULL;
1098   }
1099  
1100  
# Line 1122 | Line 1140 | void mon(int argc, char **argv)
1140                  interactive = (argc == 0);
1141          }
1142  
1143 +        // Set up memory access functions if not supplied by the user
1144 +        if (mon_read_byte == NULL) {
1145 +                if (mon_use_real_mem)
1146 +                        mon_read_byte = mon_read_byte_real;
1147 +                else
1148 +                        mon_read_byte = mon_read_byte_buffer;
1149 +        }
1150 +        if (mon_write_byte == NULL) {
1151 +                if (mon_use_real_mem)
1152 +                        mon_write_byte = mon_write_byte_real;
1153 +                else
1154 +                        mon_write_byte = mon_write_byte_buffer;
1155 +        }
1156 +
1157          // Allocate buffer
1158          if (!mon_use_real_mem) {
1159                  mon_mem_size = 0x100000;
# Line 1129 | Line 1161 | void mon(int argc, char **argv)
1161  
1162                  // Print banner
1163                  if (interactive)
1164 <                        fprintf(monerr, "\n *** mon V%d.%d by Christian Bauer and Marc Hellwig ***\n"
1165 <                                                        " ***              Press 'h' for help              ***\n\n", VERSION_MAJOR, VERSION_MINOR);
1164 >                        fprintf(monerr, "\n *** mon V" VERSION " by Christian Bauer and Marc Hellwig ***\n"
1165 >                                                        " ***               Press 'h' for help               ***\n\n");
1166          }
1167  
1168          init_abort();
# Line 1139 | Line 1171 | void mon(int argc, char **argv)
1171          while (!done) {
1172                  if (interactive) {
1173                          char prompt[16];
1174 <                        sprintf(prompt, "[%08lx]-> ", mon_dot_address);
1174 >                        sprintf(prompt, "[%08x]-> ", mon_dot_address);
1175                          read_line(prompt);
1176                  } else {
1177                          if (argc == 0) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines