si_prc.pp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2016 by the Free Pascal development team
  4. System Entry point for MorphOS, Pascal only programs
  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. unit si_prc;
  12. interface
  13. implementation
  14. const
  15. abox_signature: dword = 1; public name '__abox__';
  16. var
  17. MOS_ExecBase: Pointer; public name '_ExecBase';
  18. realExecBase: Pointer absolute $4;
  19. StkLen: LongInt; external name '__stklen';
  20. sysinit_jmpbuf: jmp_buf;
  21. ExitCode: LongInt;
  22. { the definitions in there need MOS_Execbase }
  23. {$include execd.inc}
  24. {$include execf.inc}
  25. procedure PascalMainEntry; cdecl; forward;
  26. { this function must be the first in this unit which contains code }
  27. { the startup code is forced to be in .text section, because the default
  28. linker script of MorphOS' GNU LD puts .text section first, and then
  29. all .text.* section, so if we link any object with an unnamed .text
  30. section, this won't be at the start of the executable, and we get
  31. crashes. (KB) }
  32. function _FPC_proc_start: longint; cdecl; public name '_start'; section '.text';
  33. var
  34. sst: TStackSwapStruct;
  35. newStack: Pointer;
  36. newStackAligned: Pointer;
  37. begin
  38. // prevent removal of the __abox__ symbol by --gc-sections
  39. abox_signature := 1;
  40. //
  41. MOS_ExecBase:=realExecBase;
  42. newStack:=AllocVecTaskPooled(StkLen+16);
  43. newStackAligned:=align(newStack,16);
  44. sst.stk_Lower:=newStackAligned;
  45. sst.stk_Upper:=newStackAligned+StkLen;
  46. sst.stk_Pointer:=newStackAligned+StkLen;
  47. NewPPCStackSwap(@sst,@PascalMainEntry,nil);
  48. FreeVecTaskPooled(newStack);
  49. _FPC_proc_start:=ExitCode;
  50. end;
  51. procedure _FPC_proc_halt(_ExitCode: longint); cdecl; public name '_haltproc';
  52. begin
  53. ExitCode:=_ExitCode;
  54. longjmp(sysinit_jmpbuf,1);
  55. end;
  56. procedure PascalMain; external name 'PASCALMAIN';
  57. procedure PascalMainEntry; cdecl;
  58. begin
  59. if setjmp(sysinit_jmpbuf) = 0 then
  60. PascalMain;
  61. end;
  62. end.