setjump.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by xxxx
  4. member of the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {**********************************************************************
  12. Set_Jmp/Long_jmp
  13. **********************************************************************}
  14. {$warning Fix register handling in case of nostackframe }
  15. Function fpc_SetJmp (Var S : Jmp_buf) : longint;assembler;nostackframe;[Public, alias : 'FPC_SETJMP'];compilerproc;
  16. asm
  17. // Temporarily store a0 into d0
  18. move.l a0,d0
  19. // load S to a0
  20. move.l 4(sp),a0
  21. // Save data registers d1..d7
  22. movem.l d1/d2/d3/d4/d5/d6/d7,12(a0)
  23. // Save address registers (a0-a5/a6, a0 is in d0 now)
  24. {$if defined(amiga)}
  25. movem.l d0/a1/a2/a3/a4/a6,40(a0) { amiga uses a5 as fp }
  26. {$else}
  27. movem.l d0/a1/a2/a3/a4/a5,40(a0)
  28. {$endif}
  29. // save return address (PC) and pop S off the stack
  30. move.l (sp)+,d0
  31. move.l d0,(sp)
  32. move.l d0,8(a0)
  33. // save FP
  34. move.l fp,(a0)
  35. // save SP
  36. move.l sp,d0
  37. // 4 bytes already popped, 4 to go.
  38. addq.l #4,d0
  39. move.l d0,4(a0)
  40. // restore a0
  41. move.l 40(a0),a0
  42. // return 0
  43. clr.l d0
  44. end;
  45. Procedure fpc_longJmp (Var S : Jmp_buf; value : longint); assembler;nostackframe;[Public, alias : 'FPC_LONGJMP'];compilerproc;
  46. asm
  47. // load S to a0
  48. move.l 4(sp),a0
  49. // load 'value' to d0
  50. move.l 8(sp),d0
  51. // don't return zero
  52. tst.l d0
  53. seq d1
  54. and.l #1,d1
  55. or.l d1,d0
  56. // restore FP
  57. move.l (a0),fp
  58. // restore SP
  59. move.l 4(a0),sp
  60. // jump to PC
  61. move.l 8(a0),-(sp)
  62. // Restore data registers
  63. movem.l 12(a0),d1/d2/d3/d4/d5/d6/d7
  64. // Restore address registers
  65. {$if defined(amiga)}
  66. movem.l 40(a0),a0/a1/a2/a3/a4/a6 { amiga uses a5 as fp }
  67. {$else}
  68. movem.l 40(a0),a0/a1/a2/a3/a4/a5
  69. {$endif}
  70. // new return pc is at (sp)
  71. end;