#include "memory.h"
#include "psw.h"
#include "disasm.h"
+#include "options.h"
#include "instructions_8051.h"
+extern struct options_t options;
+
/* Check if the address is a breakpoint */
int
IsBreakpoint(unsigned int address)
return 0;
}
+/* Check if the address is a stop point */
+int
+IsStoppoint(unsigned int address)
+{
+ if ((options.stop_address != 0) && (options.stop_address == address))
+ return 1;
+ else
+ return 0;
+}
+
/* Show Breakpoints list */
void
ShowBreakpoints(void)
int
IsBreakpoint(unsigned int Address);
+int
+IsStoppoint(unsigned int address);
+
void
ShowBreakpoints(void);
if (STREQ(Address, "PC"))
cpu8051.pc = Ascii2Hex(Address, strlen(Address));
- if (strlen(NumberInst) != 0)
- NbInst = Ascii2Hex(NumberInst, strlen(NumberInst));
+ if (NumberInst)
+ if (strlen(NumberInst) != 0)
+ NbInst = Ascii2Hex(NumberInst, strlen(NumberInst));
InitUnixKB();
cpu8051_Exec();
if (NbInst > 0)
NbInst--;
- } while (!IsBreakpoint(cpu8051.pc) && (NbInst != 0) && !kbhit());
+ } while (!IsBreakpoint(cpu8051.pc) && !IsStoppoint(cpu8051.pc) &&
+ (NbInst != 0) && !kbhit());
if (kbhit()) {
(void) getch(); /* Flush key */
log_info("Caught break signal!");
log_info("Number of instructions reached! Stopping!");
if (IsBreakpoint(cpu8051.pc))
log_info("Breakpoint hit at %.4X! Stopping!", cpu8051.pc);
+ if (IsStoppoint(cpu8051.pc))
+ log_info("Stoppoint hit at %.4X! Stopping!", cpu8051.pc);
ResetUnixKB();
}
log_info("Resetting...");
cpu8051_Reset();
log_info("Done");
- console_show_registers();
}
/* CPU trace and Console UI update */
" [number of instructions]",
" Reset processor............. Z", 0 };
- Index = 0;
- while (Title[Index] != 0)
- printf("%s\n", Title[Index++]);
-
- Index = 0;
- while (Menu[Index] != 0)
- printf("%s\n", Menu[Index++]);
-
console_reset();
+ if (options.stop_address != 0) {
+ /* Automatically run program and stop at specified address. */
+ console_exec("0x0000", NULL);
+ console_show_registers();
+ QuitRequest = 1;
+ } else {
+ Index = 0;
+ while (Title[Index] != 0)
+ printf("%s\n", Title[Index++]);
+
+ Index = 0;
+ while (Menu[Index] != 0)
+ printf("%s\n", Menu[Index++]);
+
+ console_show_registers();
+ }
+
while (!QuitRequest) {
int slen;
size_t len = 0;
{"iram", 'i', "size", 0, "Set internal ram size" },
{"pram", 'p', "size", 0, "Set program memory size" },
{"xram", 'x', "size", 0, "Set external ram size (default is 1024)" },
+ {"stop", 's', "addr", 0, "Automatically run program and stop at address" },
{ 0 }
};
}
}
+static void
+decode_address(char *arg, struct argp_state *state, uint16_t *dest)
+{
+ char *endptr;
+
+ *dest = strtol(arg, &endptr, 0);
+
+ if (*endptr != '\0') {
+ log_err("Invalid address");
+ argp_usage(state);
+ }
+}
+
/* Parse a single option. */
static error_t
parse_opt(int key, char *arg, struct argp_state *state)
case 'p':
decode_memory_size(arg, state, PGM_MEM_ID);
break;
+ case 's':
+ decode_address(arg, state, &options.stop_address);
+ break;
case 'x':
decode_memory_size(arg, state, EXT_MEM_ID);
break;
options.iram_size = INT_MEM_MAX_SIZE;
options.xram_size = EXT_MEM_DEFAULT_SIZE;
options.log = LOG_LEVEL_ERR;
+ options.stop_address = 0; /* 0 means stop address is disabled. */
/* Parse our arguments. */
argp_parse(&argp, argc, argv, 0, 0, NULL);
int xram_size; /* Maximum external ram size. */
char *filename;
int log;
+ uint16_t stop_address; /* Run program up to that adress and exit. */
} options_t;
void