setjump.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2008 by the Free Pascal development team.
  4. SetJmp and LongJmp implementation for exception handling
  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. function fpc_setjmp(var S : jmp_buf) : shortint;assembler;[Public, alias : 'FPC_SETJMP'];nostackframe;compilerproc;
  12. asm
  13. mov r26,r24
  14. mov r27,r25
  15. st x+,r1
  16. st x+,r2
  17. st x+,r3
  18. st x+,r4
  19. st x+,r5
  20. st x+,r6
  21. st x+,r7
  22. st x+,r8
  23. st x+,r9
  24. st x+,r10
  25. st x+,r11
  26. st x+,r12
  27. st x+,r13
  28. st x+,r14
  29. st x+,r15
  30. st x+,r16
  31. st x+,r17
  32. st x+,r28
  33. st x+,r29
  34. // store stack pointer
  35. in r18,61
  36. in r19,62
  37. st x+,r18
  38. st x+,r19
  39. // store return address
  40. pop r18
  41. pop r19
  42. st x+,r18
  43. st x+,r19
  44. push r19
  45. push r18
  46. clr r24
  47. end;
  48. procedure fpc_longjmp(var S : jmp_buf;value : shortint);assembler;[Public, alias : 'FPC_LONGJMP'];compilerproc;
  49. asm
  50. mov r26,r24
  51. mov r27,r25
  52. ld r1,x+
  53. ld r2,x+
  54. ld r3,x+
  55. ld r4,x+
  56. ld r5,x+
  57. ld r6,x+
  58. ld r7,x+
  59. ld r8,x+
  60. ld r9,x+
  61. ld r10,x+
  62. ld r11,x+
  63. ld r12,x+
  64. ld r13,x+
  65. ld r14,x+
  66. ld r15,x+
  67. ld r16,x+
  68. ld r17,x+
  69. ld r28,x+
  70. ld r29,x+
  71. // restore stack pointer
  72. ld r18,x+
  73. ld r19,x+
  74. in r0,63
  75. cli
  76. out 62,r19
  77. out 63,r0
  78. out 61,r18
  79. // restore return address
  80. pop r18
  81. pop r19
  82. ld r18,x+
  83. ld r19,x+
  84. push r19
  85. push r18
  86. mov r24,r22
  87. end;