setjump.inc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2013 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) : smallint;assembler;nostackframe;[Public, alias : 'FPC_SETJMP']; compilerproc;
  12. asm
  13. mov ax, bp
  14. mov di, sp
  15. push bp
  16. mov bp, sp
  17. mov bx, ss:[bp + 4 + extra_param_offset] // S
  18. mov word [bx + Jmp_buf.bp], ax
  19. mov word [bx + Jmp_buf.sp], di
  20. mov cx, word ss:[di]
  21. mov word [bx + Jmp_buf.ip], cx
  22. {$ifdef FPC_X86_CODE_FAR}
  23. mov cx, word ss:[di + 2]
  24. mov word [bx + Jmp_buf.cs], cx
  25. {$endif FPC_X86_CODE_FAR}
  26. xor ax, ax
  27. pop bp
  28. end;
  29. Procedure fpc_longJmp (Var S : Jmp_buf; value : smallint); assembler;nostackframe;[Public, alias : 'FPC_LONGJMP']; compilerproc;
  30. asm
  31. push bp
  32. mov bp, sp
  33. mov bx, ss:[bp + 6 + extra_param_offset] // S
  34. mov ax, ss:[bp + 4 + extra_param_offset] // value
  35. test ax, ax
  36. jnz @@L1
  37. inc ax
  38. @@L1:
  39. mov bp, word [bx + Jmp_buf.bp]
  40. mov sp, word [bx + Jmp_buf.sp]
  41. // we should also clear the fpu
  42. // fninit no must be done elsewhere PM
  43. // or we should reset the control word also
  44. {$ifdef FPC_X86_CODE_NEAR}
  45. jmp word [bx + Jmp_buf.ip]
  46. {$else FPC_X86_CODE_NEAR}
  47. // the inline asm doesn't support jmp far yet, so we use db for now
  48. // jmp far [bx + Jmp_buf.ip]
  49. db 0FFh, 06Fh, Jmp_buf.ip
  50. {$endif FPC_X86_CODE_NEAR}
  51. end;