setjump.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. movl %ebx,Jmp_buf.ebx(%eax)
  14. movl %esi,Jmp_buf.esi(%eax)
  15. movl %edi,Jmp_buf.edi(%eax)
  16. movl %ebp,Jmp_buf.bp(%eax)
  17. leal 4(%esp),%edi
  18. movl %edi,Jmp_buf.sp(%eax)
  19. movl (%esp),%edi
  20. movl %edi,Jmp_buf.pc(%eax)
  21. {$ifdef FPC_USE_WIN32_SEH}
  22. movl %fs:(0),%edi
  23. movl %edi,Jmp_buf.exhead(%eax)
  24. {$endif FPC_USE_WIN32_SEH}
  25. movl Jmp_buf.edi(%eax),%edi
  26. xorl %eax,%eax
  27. end;
  28. Procedure fpc_longJmp (Var S : Jmp_buf; value : longint); assembler;nostackframe;[Public, alias : 'FPC_LONGJMP']; compilerproc;
  29. asm
  30. xchgl %edx,%eax
  31. cmpl $1,%eax
  32. adcl $0,%eax // if result<1 then inc(result) -- never return zero.
  33. {$ifdef FPC_USE_WIN32_SEH}
  34. movl Jmp_buf.exhead(%edx),%edi
  35. movl %edi,%fs:(0)
  36. {$endif FPC_USE_WIN32_SEH}
  37. movl Jmp_buf.ebx(%edx),%ebx
  38. movl Jmp_buf.esi(%edx),%esi
  39. movl Jmp_buf.edi(%edx),%edi
  40. movl Jmp_buf.bp(%edx),%ebp
  41. movl Jmp_buf.sp(%edx),%esp
  42. // we should also clear the fpu
  43. // fninit no must be done elsewhere PM
  44. // or we should reset the control word also
  45. jmp Jmp_buf.pc(%edx)
  46. end;