setjump.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 fpc_setjmp(var S:jmp_buf):longint;assembler;[public,alias:'FPC_SETJMP'];nostackframe;compilerproc;
  13. asm
  14. {$ifdef win64}
  15. // xmm6..xmm15, xmm control word and FPU control word are nonvolatile in win64.
  16. // Using movdqu because 16-byte aligning of local records with XMM members
  17. // was broken the last time I checked it (Sergei)
  18. movq %rbx,jmp_buf.rbx(%rcx)
  19. movq %rbp,jmp_buf.rbp(%rcx)
  20. movq %r12,jmp_buf.r12(%rcx)
  21. movq %r13,jmp_buf.r13(%rcx)
  22. movq %r14,jmp_buf.r14(%rcx)
  23. movq %r15,jmp_buf.r15(%rcx)
  24. movq %rsi,jmp_buf.rsi(%rcx)
  25. movq %rdi,jmp_buf.rdi(%rcx)
  26. leaq 8(%rsp),%rax
  27. movq %rax,jmp_buf.rsp(%rcx)
  28. movq (%rsp),%rax
  29. movq %rax,jmp_buf.rip(%rcx)
  30. movdqu %xmm6,jmp_buf.xmm6(%rcx)
  31. movdqu %xmm7,jmp_buf.xmm7(%rcx)
  32. movdqu %xmm8,jmp_buf.xmm8(%rcx)
  33. movdqu %xmm9,jmp_buf.xmm9(%rcx)
  34. movdqu %xmm10,jmp_buf.xmm10(%rcx)
  35. movdqu %xmm11,jmp_buf.xmm11(%rcx)
  36. movdqu %xmm12,jmp_buf.xmm12(%rcx)
  37. movdqu %xmm13,jmp_buf.xmm13(%rcx)
  38. movdqu %xmm14,jmp_buf.xmm14(%rcx)
  39. movdqu %xmm15,jmp_buf.xmm15(%rcx)
  40. stmxcsr jmp_buf.mxcsr(%rcx)
  41. fnstcw jmp_buf.fpucw(%rcx)
  42. {$else win64}
  43. movq %rbx,jmp_buf.rbx(%rdi)
  44. movq %rbp,jmp_buf.rbp(%rdi)
  45. movq %r12,jmp_buf.r12(%rdi)
  46. movq %r13,jmp_buf.r13(%rdi)
  47. movq %r14,jmp_buf.r14(%rdi)
  48. movq %r15,jmp_buf.r15(%rdi)
  49. leaq 8(%rsp),%rax
  50. movq %rax,jmp_buf.rsp(%rdi)
  51. movq (%rsp),%rax
  52. movq %rax,jmp_buf.rip(%rdi)
  53. {$endif win64}
  54. xorl %eax,%eax
  55. end;
  56. procedure fpc_longjmp(var S:jmp_buf;value:longint);assembler;[public,alias:'FPC_LONGJMP'];nostackframe;compilerproc;
  57. asm
  58. {$ifdef win64}
  59. cmpl $1,%edx
  60. adcl $0,%edx
  61. movl %edx,%eax
  62. movq jmp_buf.rbx(%rcx),%rbx
  63. movq jmp_buf.rbp(%rcx),%rbp
  64. movq jmp_buf.r12(%rcx),%r12
  65. movq jmp_buf.r13(%rcx),%r13
  66. movq jmp_buf.r14(%rcx),%r14
  67. movq jmp_buf.r15(%rcx),%r15
  68. movq jmp_buf.rsi(%rcx),%rsi
  69. movq jmp_buf.rdi(%rcx),%rdi
  70. movq jmp_buf.rsp(%rcx),%rsp
  71. movdqu jmp_buf.xmm6(%rcx),%xmm6
  72. movdqu jmp_buf.xmm7(%rcx),%xmm7
  73. movdqu jmp_buf.xmm8(%rcx),%xmm8
  74. movdqu jmp_buf.xmm9(%rcx),%xmm9
  75. movdqu jmp_buf.xmm10(%rcx),%xmm10
  76. movdqu jmp_buf.xmm11(%rcx),%xmm11
  77. movdqu jmp_buf.xmm12(%rcx),%xmm12
  78. movdqu jmp_buf.xmm13(%rcx),%xmm13
  79. movdqu jmp_buf.xmm14(%rcx),%xmm14
  80. movdqu jmp_buf.xmm15(%rcx),%xmm15
  81. ldmxcsr jmp_buf.mxcsr(%rcx)
  82. fnclex
  83. fldcw jmp_buf.fpucw(%rcx)
  84. jmpq jmp_buf.rip(%rcx)
  85. {$else win64}
  86. cmpl $1,%esi
  87. adcl $0,%esi
  88. movl %esi,%eax
  89. movq jmp_buf.rbx(%rdi),%rbx
  90. movq jmp_buf.rbp(%rdi),%rbp
  91. movq jmp_buf.r12(%rdi),%r12
  92. movq jmp_buf.r13(%rdi),%r13
  93. movq jmp_buf.r14(%rdi),%r14
  94. movq jmp_buf.r15(%rdi),%r15
  95. movq jmp_buf.rsp(%rdi),%rsp
  96. jmpq jmp_buf.rip(%rdi)
  97. {$endif win64}
  98. end;