From: Michel Pollet Date: Mon, 7 Nov 2016 08:49:07 +0000 (+0000) Subject: core: Fix rjmp/rcall wrapping around flash boundaries X-Git-Tag: v1.4~5 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=16164f65b9d5d4679301faa6852b69cfa52c316e;p=sx%2Fsimavr.git core: Fix rjmp/rcall wrapping around flash boundaries As per PR #127, spliced Signed-off-by: Michel Pollet --- 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();