git-svn-id: branches/z80@45100 -
@@ -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
+
+ { 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 l, 0
pop ix
@@ -48,6 +65,16 @@ procedure fpc_longjmp(var S : jmp_buf;value : shortint);assembler;[Public, alias
+ { restore ix }
+ ld c, (hl)
+ ld b, (hl)
+ push bc
+ pop ix
+ { restore sp }
ld c, (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 }
+ { prepare the new return address, will be popped by the ret instruction }
- pop ix
+ { return result }
+ ld l, d
end;
@@ -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;}
pjmp_buf = ^jmp_buf;