setjump.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. {$ifdef CPUAVR_3_BYTE_PC}
  45. pop r20
  46. st x+,r20
  47. push r20
  48. {$endif CPUAVR_3_BYTE_PC}
  49. push r19
  50. push r18
  51. clr r24
  52. end;
  53. procedure fpc_longjmp(var S : jmp_buf;value : shortint);assembler;[Public, alias : 'FPC_LONGJMP'];compilerproc;
  54. asm
  55. mov r26,r24
  56. mov r27,r25
  57. ld r1,x+
  58. ld r2,x+
  59. ld r3,x+
  60. ld r4,x+
  61. ld r5,x+
  62. ld r6,x+
  63. ld r7,x+
  64. ld r8,x+
  65. ld r9,x+
  66. ld r10,x+
  67. ld r11,x+
  68. ld r12,x+
  69. ld r13,x+
  70. ld r14,x+
  71. ld r15,x+
  72. ld r16,x+
  73. ld r17,x+
  74. ld r28,x+
  75. ld r29,x+
  76. // restore stack pointer
  77. ld r18,x+
  78. ld r19,x+
  79. in r0,63
  80. cli
  81. out 62,r19
  82. out 63,r0
  83. out 61,r18
  84. // restore return address
  85. pop r18
  86. pop r19
  87. ld r18,x+
  88. ld r19,x+
  89. {$ifdef CPUAVR_3_BYTE_PC}
  90. pop r20
  91. ld r20,x+
  92. push r20
  93. {$endif CPUAVR_3_BYTE_PC}
  94. push r19
  95. push r18
  96. mov r24,r22
  97. end;