si_prc.pp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2021 by Free Pascal development team
  4. This file implements the startup code for WebAssembly programs that
  5. don't link to the C library.
  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. unit si_prc;
  13. {$if defined(FPC_WASM_BRANCHFUL_EXCEPTIONS) or defined(FPC_WASM_NATIVE_EXCEPTIONS)}
  14. {$MODESWITCH EXCEPTIONS}
  15. {$endif}
  16. interface
  17. procedure _start;
  18. implementation
  19. procedure PASCALMAIN; external 'PASCALMAIN';
  20. {$if defined(FPC_WASM_BRANCHFUL_EXCEPTIONS) or defined(FPC_WASM_NATIVE_EXCEPTIONS)}
  21. Procedure DoUnHandledException; external name 'FPC_DOUNHANDLEDEXCEPTION';
  22. procedure _start_pascal;
  23. begin
  24. try
  25. PASCALMAIN;
  26. except
  27. DoUnhandledException;
  28. end;
  29. end;
  30. {$else}
  31. procedure _start_pascal;
  32. begin
  33. PASCALMAIN;
  34. end;
  35. {$endif}
  36. procedure SetInitialHeapBlockStart(p: Pointer); external name 'FPC_WASM_SETINITIALHEAPBLOCKSTART';
  37. { TODO: remove this, when calling SetInitialHeapBlockStart works directly from within inline asm }
  38. procedure SetInitialHeapBlockStart2(p: Pointer);
  39. begin
  40. SetInitialHeapBlockStart(p);
  41. end;
  42. procedure _start; assembler; nostackframe;
  43. asm
  44. global.get $__stack_pointer
  45. call $SetInitialHeapBlockStart2
  46. call $_start_pascal
  47. end;
  48. exports
  49. _start;
  50. end.