si_prc.pp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Amiga/68k, 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. realExecBase: Pointer absolute $4;
  17. StkLen: LongInt; external name '__stklen';
  18. sysinit_jmpbuf: jmp_buf;
  19. ExitCode: LongInt;
  20. { the definitions in there need AOS_Execbase }
  21. {$include execd.inc}
  22. {$include execf.inc}
  23. var
  24. sst: TStackSwapStruct;
  25. procedure PascalMain; external name 'PASCALMAIN';
  26. { this function must be the first in this unit which contains code }
  27. function _FPC_proc_start: longint; cdecl; public name '_start';
  28. var
  29. newStack: Pointer;
  30. task: PTask;
  31. begin
  32. AOS_ExecBase:=realExecBase;
  33. newStack:=nil;
  34. task:=FindTask(nil);
  35. if (task^.tc_SPUpper-task^.tc_SPLower < StkLen) then
  36. begin
  37. newStack:=AllocVec(StkLen,MEMF_ANY);
  38. sst.stk_Lower:=newStack;
  39. sst.stk_Upper:=newStack+StkLen;
  40. sst.stk_Pointer:=newStack+StkLen;
  41. StackSwap(@sst);
  42. end;
  43. { Note: code between the two stackswaps only works because of the
  44. nature of the generated code. We're accessing globals which is
  45. safe, and the locals are either kept in reg, or accessed via
  46. the base pointer (A5), and because we don't use the stack for
  47. call arguments, only regs. If this CG behavior changes, this
  48. code might break. In that case an asm-written StackSwap+call
  49. wrapper code is the solution. (Basically the reimplementation
  50. of AROS' NewStackSwap or MorphOS' NewPPCStackSwap.) (KB) }
  51. if setjmp(sysinit_jmpbuf) = 0 then
  52. PascalMain;
  53. if newStack <> nil then
  54. begin
  55. StackSwap(@sst);
  56. FreeVec(newStack);
  57. end;
  58. _FPC_proc_start:=ExitCode;
  59. end;
  60. procedure _FPC_proc_halt(_ExitCode: longint); cdecl; public name '_haltproc';
  61. begin
  62. ExitCode:=_ExitCode;
  63. longjmp(sysinit_jmpbuf,1);
  64. end;
  65. end.