setjump.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2003 by Florian Klaempfl and other members of the
  4. Free Pascal development team
  5. SetJmp and LongJmp implementation for exception handling
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. function setjmp(var S : jmp_buf) : longint;assembler;[Public, alias : 'FPC_SETJMP'];nostackframe;
  13. asm
  14. // Save registers.
  15. movq %rbx,(%rdi)
  16. movq %rbp,8(%rdi)
  17. movq %r12,16(%rdi)
  18. movq %r13,24(%rdi)
  19. movq %r14,32(%rdi)
  20. movq %r15,40(%rdi)
  21. leaq 8(%rsp),%rdx // Save SP as it will be after we return.
  22. movq %rdx,48(%rdi)
  23. movq 0(%rsp),%rsi // Save PC we are returning to now.
  24. movq %rsi,56(%rdi)
  25. xorq %rax,%rax
  26. end;
  27. procedure longjmp(var S : jmp_buf;value : longint);assembler;[Public, alias : 'FPC_LONGJMP'];
  28. asm
  29. // Restore registers.
  30. movq (%rdi),%rbx
  31. movq 8(%rdi),%rbp
  32. movq 16(%rdi),%r12
  33. movq 24(%rdi),%r13
  34. movq 32(%rdi),%r14
  35. movq 40(%rdi),%r15
  36. // Set return value for setjmp.
  37. test %esi,%esi
  38. mov $01,%eax
  39. cmove %eax,%esi
  40. mov %esi,%eax
  41. movq 56(%rdi),%rdx
  42. movq 48(%rdi),%rsp
  43. jmpq *%rdx
  44. end;