setjump.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the 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. {$ifdef needsigprocmask}
  13. const
  14. JMPSIG_BLOCK = 0;
  15. JMPSIG_SETMASK = 2;
  16. function JmpSigProcMask(how:longint;nset : pjmpsigset;oset : pjmpsigset):longint; external name 'FPC_SYSC_SIGPROCMASK';
  17. procedure savesigmask(var s:jmp_buf);
  18. begin
  19. jmpsigprocmask(JMPSIG_BLOCK,nil,@s.sigmask);
  20. end;
  21. procedure restoresigmask(var s:jmp_buf);
  22. begin
  23. jmpsigprocmask(JMPSIG_SETMASK,@s.sigmask,nil);
  24. end;
  25. {$endif needsigprocmask}
  26. Function SetJmp (Var S : Jmp_buf) : longint;assembler;[Public, alias : 'FPC_SETJMP'];
  27. asm
  28. {$ifndef REGCALL}
  29. movl 8(%ebp),%eax
  30. {$endif}
  31. movl %ebx,(%eax)
  32. movl %esi,4(%eax)
  33. movl %edi,8(%eax)
  34. movl 4(%ebp),%edi
  35. movl %edi,20(%eax)
  36. movl (%ebp),%edi
  37. movl %edi,12(%eax)
  38. {$ifdef REGCALL}
  39. leal 8(%ebp),%edi
  40. {$else}
  41. leal 12(%ebp),%edi
  42. {$endif}
  43. movl %edi,16(%eax)
  44. movl 8(%eax),%edi
  45. {$ifdef needsigprocmask}
  46. call savesigmask
  47. {$endif needsigprocmask}
  48. xorl %eax,%eax
  49. end['EAX'];
  50. Procedure longJmp (Var S : Jmp_buf; value : longint); assembler;[Public, alias : 'FPC_LONGJMP'];
  51. asm
  52. {$ifdef REGCALL}
  53. {$ifdef needsigprocmask}
  54. movl %edx, %ebx
  55. movl %eax, %esi
  56. call restoresigmask
  57. movl %ebx, %edx
  58. movl %esi, %eax
  59. {$endif needsigprocmask}
  60. xchgl %edx,%eax
  61. {$else}
  62. movl 8(%ebp),%edx
  63. movl 12(%ebp),%eax
  64. {$endif}
  65. movl (%edx),%ebx
  66. movl 4(%edx),%esi
  67. movl 8(%edx),%edi
  68. movl 12(%edx),%ebp
  69. movl 16(%edx),%esp
  70. // we should also clear the fpu
  71. // fninit no must be done elsewhere PM
  72. // or we should reset the control word also
  73. jmp 20(%edx)
  74. end;
  75. {
  76. $Log$
  77. Revision 1.6 2005-01-20 16:38:28 peter
  78. * restore sigprocmask for linux
  79. Revision 1.5 2003/12/04 21:42:07 peter
  80. * register calling updates
  81. Revision 1.4 2003/11/11 21:08:17 peter
  82. * REGCALL define added
  83. Revision 1.3 2002/09/07 16:01:19 peter
  84. * old logs removed and tabs fixed
  85. }