diff options
author | nickysn <nickysn@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2020-04-26 14:39:27 +0000 |
---|---|---|
committer | nickysn <nickysn@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2020-04-26 14:39:27 +0000 |
commit | 87b1acb7b251f676487660834e6c7cac71c4f9a0 (patch) | |
tree | e3de4cf356e04ca3a8ca79a71aa3acca57627852 | |
parent | fa8a6621c46207488055097aaa9287711e81179a (diff) | |
download | fpc-87b1acb7b251f676487660834e6c7cac71c4f9a0.tar.gz |
* fixed Z80 setjmp/longjmp
git-svn-id: https://svn.freepascal.org/svn/fpc/branches/z80@45100 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r-- | rtl/z80/setjump.inc | 40 | ||||
-rw-r--r-- | 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; |