setjump.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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]
  18. mov word [bx + Jmp_buf.bp], ax
  19. mov word [bx + Jmp_buf.sp], di
  20. mov di, word ss:[di]
  21. mov word [bx + Jmp_buf.pc], di
  22. xor ax, ax
  23. pop bp
  24. end;
  25. Procedure fpc_longJmp (Var S : Jmp_buf; value : smallint); assembler;nostackframe;[Public, alias : 'FPC_LONGJMP']; compilerproc;
  26. asm
  27. push bp
  28. mov bp, sp
  29. mov bx, ss:[bp + 6]
  30. mov ax, ss:[bp + 4]
  31. test ax, ax
  32. jnz @@L1
  33. inc ax
  34. @@L1:
  35. mov dx, word [bx + Jmp_buf.pc]
  36. mov bp, word [bx + Jmp_buf.bp]
  37. mov sp, word [bx + Jmp_buf.sp]
  38. // we should also clear the fpu
  39. // fninit no must be done elsewhere PM
  40. // or we should reset the control word also
  41. jmp dx
  42. end;