si_c.inc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. Type
  2. TCleanup = procedure; cdecl;
  3. var
  4. environ : ppchar; cvar; public name '__environ';
  5. progname: pchar = #0#0; cvar; public name '__progname';
  6. dynamic : pchar; external name '_DYNAMIC'; // #pragma weak
  7. procedure atexit(prc:TCleanup); cdecl external name 'atexit';
  8. procedure cleanup(prc:TCleanup); cdecl external name 'cleanup';
  9. procedure init_tls; cdecl; external name 'init_tls';
  10. procedure fini; cdecl; external name '_fini';
  11. procedure init; cdecl; external name '_init';
  12. procedure libc_exit(exitcode:longint);cdecl; external name 'exit';
  13. function main(nrarg:longint;pp:ppchar;env:ppchar):longint; cdecl; external name 'main';
  14. {$ifdef gcrt}
  15. procedure cmcleanup; cdecl; external name '_mcleanup';
  16. procedure monstratup(p,p2:pointer); cdecl; external name 'monstartup';
  17. var
  18. eprol:longint; external name 'eprol';
  19. etext:longint; external name 'etext';
  20. {$endif}
  21. procedure start(ap:ppchar;cleanup:TCleanup);
  22. var argc: longint;
  23. argv: ppchar;
  24. env : ppchar;
  25. s : pchar;
  26. begin
  27. argc:=plongint(ap)^;
  28. argv:=ppchar(ap[1]);
  29. env:= ppchar(ap[2+argc]);
  30. environ:=env;
  31. if (argc>0) and (argv[0]<>#0) Then
  32. begin
  33. progname:=argv[0];
  34. s:=progname;
  35. while s^<>#0 do
  36. begin
  37. if s^='/' then
  38. progname:=@s[1];
  39. inc(s);
  40. end;
  41. end;
  42. if assigned(pchar(@dynamic)) then // I suspect this is a trick to find
  43. // out runtime if we are shared
  44. // linking, so the same code can be used
  45. // for static and shared linking
  46. atexit(cleanup)
  47. else
  48. init_tls;
  49. {$ifdef GCRT}
  50. atexit(@_mcleanup);
  51. {$endif}
  52. atexit(@fini);
  53. {$ifdef GCRT}
  54. monstartup(@eprol,@etext);
  55. asm
  56. eprol:
  57. end;
  58. {$endif}
  59. init;
  60. libc_exit(main(argc,argv,env)); // doesn't return
  61. asm
  62. { We need this stuff to make gdb behave itself, otherwise
  63. gdb will chokes with SIGILL when trying to debug apps.
  64. }
  65. .section ".note.ABI-tag", "a"
  66. .align 4
  67. .long 8
  68. .long 4
  69. .long 1
  70. .asciz "FreeBSD"
  71. .align 4
  72. .long 900044
  73. .align 4
  74. .section .note.GNU-stack,"",@progbits
  75. end;
  76. end;
  77. begin
  78. end.