From 3dec4eece8caeb654239e64ea1b6f715fde2c2d2 Mon Sep 17 00:00:00 2001 From: nickysn Date: Sun, 26 Apr 2020 14:39:27 +0000 Subject: [PATCH] * fixed Z80 setjmp/longjmp git-svn-id: branches/z80@45100 - --- rtl/z80/setjump.inc | 40 +++++++++++++++++++++++++++++++++++++--- rtl/z80/setjumph.inc | 2 +- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/rtl/z80/setjump.inc b/rtl/z80/setjump.inc index 2801c8af23..b17459700d 100644 --- a/rtl/z80/setjump.inc +++ b/rtl/z80/setjump.inc @@ -23,7 +23,16 @@ function fpc_setjmp(var S : jmp_buf) : shortint;assembler;[Public, alias : 'FPC_ ld l, (ix+4) { (S) } ld h, (ix+5) { (S+1) } - ld iy, 0 + { save caller ix } + ld c, (ix) + ld b, (ix+1) + ld (hl), c + inc hl + ld (hl), b + inc hl + + { save caller sp (i.e. what its value was, right before the call instrunction) } + ld iy, 4 add iy, sp push iy pop bc @@ -32,6 +41,14 @@ function fpc_setjmp(var S : jmp_buf) : shortint;assembler;[Public, alias : 'FPC_ ld (hl), b inc hl + { save ret address } + ld c, (ix+2) + ld b, (ix+3) + ld (hl), c + inc hl + ld (hl), b + inc hl + ld l, 0 pop ix @@ -48,6 +65,16 @@ procedure fpc_longjmp(var S : jmp_buf;value : shortint);assembler;[Public, alias ld l, (ix+4) { (S) } ld h, (ix+5) { (S+1) } + + { restore ix } + ld c, (hl) + inc hl + ld b, (hl) + inc hl + push bc + pop ix + + { restore sp } ld c, (hl) inc hl ld b, (hl) @@ -56,9 +83,16 @@ procedure fpc_longjmp(var S : jmp_buf;value : shortint);assembler;[Public, alias pop iy ld sp, iy - ld l, d + { restore pc } + ld c, (hl) + inc hl + ld b, (hl) + inc hl + { prepare the new return address, will be popped by the ret instruction } + push bc - pop ix + { return result } + ld l, d end; diff --git a/rtl/z80/setjumph.inc b/rtl/z80/setjumph.inc index 2e60fae7ac..609962c72b 100644 --- a/rtl/z80/setjumph.inc +++ b/rtl/z80/setjumph.inc @@ -16,7 +16,7 @@ type jmp_buf = packed record - sp: word; + ix,sp,pc: word; { f,a,b,c,e,d,l,h,ixlo,ixhi,iylo,iyhi,splo,sphi,pclo,pchi : byte;} end; pjmp_buf = ^jmp_buf;