setjump.inc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 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) : longint;assembler;nostackframe;[Public, alias : 'FPC_SETJMP']; compilerproc;
  12. asm
  13. {$ifndef REGCALL}
  14. movl 4(%esp),%eax
  15. {$endif}
  16. movl %ebx,Jmp_buf.ebx(%eax)
  17. movl %esi,Jmp_buf.esi(%eax)
  18. movl %edi,Jmp_buf.edi(%eax)
  19. movl %ebp,Jmp_buf.bp(%eax)
  20. {$ifdef REGCALL}
  21. leal 4(%esp),%edi
  22. {$else}
  23. leal 8(%esp),%edi
  24. {$endif}
  25. movl %edi,Jmp_buf.sp(%eax)
  26. movl (%esp),%edi
  27. movl %edi,Jmp_buf.pc(%eax)
  28. movl Jmp_buf.edi(%eax),%edi
  29. xorl %eax,%eax
  30. end;
  31. Procedure fpc_longJmp (Var S : Jmp_buf; value : longint); assembler;nostackframe;[Public, alias : 'FPC_LONGJMP']; compilerproc;
  32. asm
  33. {$ifdef REGCALL}
  34. xchgl %edx,%eax
  35. {$else}
  36. movl 4(%esp),%edx
  37. movl 8(%esp),%eax
  38. {$endif}
  39. movl Jmp_buf.ebx(%edx),%ebx
  40. movl Jmp_buf.esi(%edx),%esi
  41. movl Jmp_buf.edi(%edx),%edi
  42. movl Jmp_buf.bp(%edx),%ebp
  43. movl Jmp_buf.sp(%edx),%esp
  44. // we should also clear the fpu
  45. // fninit no must be done elsewhere PM
  46. // or we should reset the control word also
  47. jmp Jmp_buf.pc(%edx)
  48. end;