// DEBUG ONLY
int trace;
+
+#if CONFIG_SIMAVR_TRACE
struct avr_symbol_t ** codeline;
/* DEBUG ONLY
// keeps track of which registers gets touched by instructions
// reset before each new instructions. Allows meaningful traces
uint32_t touched[256 / 32]; // debug
+#endif
// gdb hooking structure. Only present when gdb server is active
struct avr_gdb_t * gdb;
* This is used only for debugging purposes to be able to
* print the effects of each instructions on registers
*/
+#if CONFIG_SIMAVR_TRACE
#define REG_TOUCH(a, r) (a)->touched[(r) >> 5] |= (1 << ((r) & 0x1f))
#define REG_ISTOUCHED(a, r) ((a)->touched[(r) >> 5] & (1 << ((r) & 0x1f)))
printf("%c", avr->sreg[_sbi] ? toupper(_sreg_bit_name[_sbi]) : '.');\
printf("\n");\
}
+#else
+#define REG_TOUCH(a, r)
+#define STATE(_f, args...)
+#define SREG()
+#endif
/*
* Set a register (r < 256)
*/
static void _avr_invalid_opcode(avr_t * avr)
{
+#if CONFIG_SIMAVR_TRACE
printf("\e[31m*** %04x: %-25s Invalid Opcode SP=%04x O=%04x \e[0m\n",
avr->pc, avr->codeline[avr->pc>>1]->symbol, _avr_sp_get(avr), avr->flash[avr->pc] | (avr->flash[avr->pc+1]<<8));
+#else
+ printf("\e[31m*** %04x: Invalid Opcode SP=%04x O=%04x \e[0m\n",
+ avr->pc, _avr_sp_get(avr), avr->flash[avr->pc] | (avr->flash[avr->pc+1]<<8));
+#endif
}
+#if CONFIG_SIMAVR_TRACE
/*
* Dump changed registers when tracing
*/
}
printf("\n");
}
+#endif
#define get_r_d_10(o) \
const uint8_t r = ((o >> 5) & 0x10) | (o & 0xf); \
/*
* Add a "jump" address to the jump trace buffer
*/
+#if CONFIG_SIMAVR_TRACE
#define TRACE_JUMP()\
avr->old[avr->old_pci].pc = avr->pc;\
avr->old[avr->old_pci].sp = _avr_sp_get(avr);\
#else
#define STACK_FRAME_PUSH()
#define STACK_FRAME_POP()
+#endif
+#else /* CONFIG_SIMAVR_TRACE */
+
+#define TRACE_JUMP()
+#define STACK_FRAME_PUSH()
+#define STACK_FRAME_POP()
+
#endif
/****************************************************************************\
uint32_t new_pc = avr->pc + 2; // future "default" pc
int cycle = 1;
+#if CONFIG_SIMAVR_TRACE
avr->touched[0] = avr->touched[1] = avr->touched[2] = 0;
+#endif
switch (opcode & 0xf000) {
case 0x0000: {
void _avr_sp_set(avr_t * avr, uint16_t sp);
void _avr_push16(avr_t * avr, uint16_t v);
+#if CONFIG_SIMAVR_TRACE
+
/*
* Get a "pretty" register name
*/
DUMP_STACK();\
avr_sadly_crashed(avr, 0);\
}
+#else /* CONFIG_SIMAVR_TRACE */
+
+#define CRASH() { \
+ avr_sadly_crashed(avr, 0);\
+ }
+#define DUMP_STACK()
+#define DUMP_REG();
+
+#endif
#endif /* SIM_CORE_H_ */
void avr_load_firmware(avr_t * avr, elf_firmware_t * firmware)
{
avr->frequency = firmware->mmcu.f_cpu;
+#if CONFIG_SIMAVR_TRACE
avr->codeline = firmware->codeline;
+#endif
avr_loadcode(avr, firmware->flash, firmware->flashsize, 0);
avr->codeend = firmware->flashsize - firmware->datasize;
if (firmware->eeprom && firmware->eesize) {