setjump.inc 2.5 KB

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