setjump.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. {$ifndef CPUAVR_16_REGS}
  16. st x+,r1
  17. st x+,r2
  18. st x+,r3
  19. st x+,r4
  20. st x+,r5
  21. st x+,r6
  22. st x+,r7
  23. st x+,r8
  24. st x+,r9
  25. st x+,r10
  26. st x+,r11
  27. st x+,r12
  28. st x+,r13
  29. st x+,r14
  30. st x+,r15
  31. {$endif CPUAVR_16_REGS}
  32. st x+,r16
  33. st x+,r17
  34. {$ifdef CPUAVR_16_REGS}
  35. st x+,r18
  36. st x+,r19
  37. {$endif CPUAVR_16_REGS}
  38. st x+,r28
  39. st x+,r29
  40. // store stack pointer
  41. in r18,61
  42. in r19,62
  43. st x+,r18
  44. st x+,r19
  45. // store return address
  46. pop r18
  47. pop r19
  48. st x+,r18
  49. st x+,r19
  50. {$ifdef CPUAVR_3_BYTE_PC}
  51. pop r20
  52. st x+,r20
  53. push r20
  54. {$endif CPUAVR_3_BYTE_PC}
  55. push r19
  56. push r18
  57. clr r24
  58. end;
  59. procedure fpc_longjmp(var S : jmp_buf;value : shortint);assembler;[Public, alias : 'FPC_LONGJMP'];compilerproc;
  60. asm
  61. mov r26,r24
  62. mov r27,r25
  63. {$ifndef CPUAVR_16_REGS}
  64. ld r1,x+
  65. ld r2,x+
  66. ld r3,x+
  67. ld r4,x+
  68. ld r5,x+
  69. ld r6,x+
  70. ld r7,x+
  71. ld r8,x+
  72. ld r9,x+
  73. ld r10,x+
  74. ld r11,x+
  75. ld r12,x+
  76. ld r13,x+
  77. ld r14,x+
  78. ld r15,x+
  79. {$endif CPUAVR_16_REGS}
  80. ld r16,x+
  81. ld r17,x+
  82. {$ifdef CPUAVR_16_REGS}
  83. ld r18,x+
  84. ld r19,x+
  85. {$endif CPUAVR_16_REGS}
  86. ld r28,x+
  87. ld r29,x+
  88. // restore stack pointer
  89. ld r18,x+
  90. ld r19,x+
  91. {$ifdef CPUAVR_16_REGS}
  92. in r16,63
  93. {$else CPUAVR_16_REGS}
  94. in r0,63
  95. {$endif CPUAVR_16_REGS}
  96. cli
  97. out 62,r19
  98. {$ifdef CPUAVR_16_REGS}
  99. out 63,r16
  100. {$else CPUAVR_16_REGS}
  101. out 63,r0
  102. {$endif CPUAVR_16_REGS}
  103. out 61,r18
  104. // restore return address
  105. pop r18
  106. pop r19
  107. ld r18,x+
  108. ld r19,x+
  109. {$ifdef CPUAVR_3_BYTE_PC}
  110. pop r20
  111. ld r20,x+
  112. push r20
  113. {$endif CPUAVR_3_BYTE_PC}
  114. push r19
  115. push r18
  116. mov r24,r22
  117. end;