浏览代码

* fixed Z80 setjmp/longjmp

git-svn-id: branches/z80@45100 -
nickysn 5 年之前
父节点
当前提交
3dec4eece8
共有 2 个文件被更改,包括 38 次插入4 次删除
  1. 37 3
      rtl/z80/setjump.inc
  2. 1 1
      rtl/z80/setjumph.inc

+ 37 - 3
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 l, (ix+4)  { (S)   }
     ld h, (ix+5)  { (S+1) }
     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
     add iy, sp
     push iy
     push iy
     pop bc
     pop bc
@@ -32,6 +41,14 @@ function fpc_setjmp(var S : jmp_buf) : shortint;assembler;[Public, alias : 'FPC_
     ld (hl), b
     ld (hl), b
     inc hl
     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
     ld l, 0
 
 
     pop ix
     pop ix
@@ -48,6 +65,16 @@ procedure fpc_longjmp(var S : jmp_buf;value : shortint);assembler;[Public, alias
 
 
     ld l, (ix+4)  { (S)   }
     ld l, (ix+4)  { (S)   }
     ld h, (ix+5)  { (S+1) }
     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)
     ld c, (hl)
     inc hl
     inc hl
     ld b, (hl)
     ld b, (hl)
@@ -56,9 +83,16 @@ procedure fpc_longjmp(var S : jmp_buf;value : shortint);assembler;[Public, alias
     pop iy
     pop iy
     ld sp, 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;
   end;
 
 
 
 

+ 1 - 1
rtl/z80/setjumph.inc

@@ -16,7 +16,7 @@
 
 
 type
 type
    jmp_buf = packed record
    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;}
 {     f,a,b,c,e,d,l,h,ixlo,ixhi,iylo,iyhi,splo,sphi,pclo,pchi : byte;}
    end;
    end;
    pjmp_buf = ^jmp_buf;
    pjmp_buf = ^jmp_buf;