Added a special opcode at the end of flash to catch PC overflow, and
'wrap it'. Also log the condition.
This allow that case to be handled without having to add a
modulo/division for each instruction.
Signed-off-by: Michel Pollet <buserror@gmail.com>
3 files changed:
avr_init(
avr_t * avr)
{
- avr->flash = malloc(avr->flashend + 1);
+ avr->flash = malloc(avr->flashend + 4);
memset(avr->flash, 0xff, avr->flashend + 1);
+ *((uint16_t*)&avr->flash[avr->flashend + 1]) = AVR_OVERFLOW_OPCODE;
avr->codeend = avr->flashend;
avr->data = malloc(avr->ramend + 1);
memset(avr->data, 0, avr->ramend + 1);
case 0xf000: {
switch (opcode & 0xfe00) {
+ case 0xf100: { /* simavr special opcodes */
+ if (opcode == 0xf1f1) { // AVR_OVERFLOW_OPCODE
+ printf("FLASH overflow, soft reset\n");
+ new_pc = 0;
+ TRACE_JUMP();
+ }
+ } break;
case 0xf000:
case 0xf200:
case 0xf400:
avr_sreg_set(avr, i, (src & (1 << i)) != 0); \
}
+/*
+ * Opcode is sitting at the end of the flash to catch PC overflows.
+ * Apparently it's used by some code to simulate soft reset?
+ */
+#define AVR_OVERFLOW_OPCODE 0xf1f1
+
#ifdef __cplusplus
};
#endif