si_prc.pp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2017 by the Free Pascal development team
  4. System Entry point for AROS, 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. var
  15. AOS_ExecBase: Pointer; public name '_ExecBase';
  16. StkLen: LongInt; external name '__stklen';
  17. sysinit_jmpbuf: jmp_buf;
  18. ExitCode: LongInt;
  19. {$include execd.inc}
  20. {$include execf.inc}
  21. procedure PascalMainEntry; cdecl; forward;
  22. { this function must be the first in this unit which contains code }
  23. function _FPC_proc_start(argv: pointer; argc: ptrint; argExecBase: Pointer): longint; cdecl; public name '_start';
  24. var
  25. sst: TStackSwapStruct;
  26. ssp: TStackSwapArgs;
  27. newStack: Pointer;
  28. newStackAligned: Pointer;
  29. task: PTask;
  30. begin
  31. AOS_ExecBase:=argExecBase;
  32. newStack:=nil;
  33. newStackAligned:=nil;
  34. task:=FindTask(nil);
  35. if (task^.tc_SPUpper-task^.tc_SPLower < StkLen) then
  36. begin
  37. newStack:=AllocVec(StkLen+16, MEMF_ANY);
  38. newStackAligned:=align(newStack,16);
  39. sst.stk_Lower:=newStackAligned;
  40. sst.stk_Upper:=newStackAligned+StkLen;
  41. sst.stk_Pointer:=newStackAligned+StkLen;
  42. FillChar(ssp,sizeof(ssp),0);
  43. NewStackSwap(@sst,@PascalMainEntry,@ssp);
  44. FreeVec(newStack);
  45. end
  46. else
  47. PascalMainEntry;
  48. _FPC_proc_start:=ExitCode;
  49. end;
  50. procedure _FPC_proc_halt(_ExitCode: longint); cdecl; public name '_haltproc';
  51. begin
  52. ExitCode:=_ExitCode;
  53. longjmp(sysinit_jmpbuf,1);
  54. end;
  55. procedure PascalMain; external name 'PASCALMAIN';
  56. procedure PascalMainEntry; cdecl;
  57. begin
  58. if setjmp(sysinit_jmpbuf) = 0 then
  59. PascalMain;
  60. end;
  61. end.