From 16164f65b9d5d4679301faa6852b69cfa52c316e Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Mon, 7 Nov 2016 08:49:07 +0000 Subject: [PATCH] core: Fix rjmp/rcall wrapping around flash boundaries As per PR #127, spliced Signed-off-by: Michel Pollet --- simavr/sim/sim_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simavr/sim/sim_core.c b/simavr/sim/sim_core.c index 9d46738..c40cf54 100644 --- a/simavr/sim/sim_core.c +++ b/simavr/sim/sim_core.c @@ -1326,7 +1326,7 @@ run_one_again: case 0xc000: { // RJMP -- 1100 kkkk kkkk kkkk get_o12(opcode); STATE("rjmp .%d [%04x]\n", o >> 1, new_pc + o); - new_pc = new_pc + o; + new_pc = (new_pc + o) % (avr->flashend+1); cycle++; TRACE_JUMP(); } break; @@ -1335,7 +1335,7 @@ run_one_again: get_o12(opcode); STATE("rcall .%d [%04x]\n", o >> 1, new_pc + o); cycle += _avr_push_addr(avr, new_pc); - new_pc = new_pc + o; + new_pc = (new_pc + o) % (avr->flashend+1); // 'rcall .1' is used as a cheap "push 16 bits of room on the stack" if (o != 0) { TRACE_JUMP(); -- 2.39.5