summaryrefslogtreecommitdiff
path: root/fpcsrc/rtl/freebsd/x86_64/si_c.inc
blob: f629e50a4a59ff28663bc9e773cd3c8ec630c015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

Type
    TCleanup = procedure; cdecl;

var 
  environ : ppchar; cvar; public  name '__environ';
  progname: pchar = #0#0; cvar; public name '__progname';
  dynamic : pchar;  external name '_DYNAMIC'; // #pragma weak

procedure atexit(prc:TCleanup); cdecl external name 'atexit';
procedure cleanup(prc:TCleanup); cdecl external name 'cleanup';			
procedure init_tls; cdecl; external name 'init_tls';
procedure fini; cdecl; external name '_fini';
procedure init; cdecl; external name '_init';
procedure libc_exit(exitcode:longint);cdecl; external name 'exit';
function  main(nrarg:longint;pp:ppchar;env:ppchar):longint; cdecl; external name 'main';

{$ifdef gcrt}
 procedure cmcleanup; cdecl; external name '_mcleanup';
 procedure monstratup(p,p2:pointer); cdecl; external name 'monstartup';

var 
 eprol:longint; external name 'eprol'; 
 etext:longint; external name 'etext';
{$endif}

procedure start(ap:ppchar;cleanup:TCleanup);

var argc: longint;
    argv: ppchar;
    env : ppchar;
    s   : pchar;
begin
  argc:=plongint(ap)^; 
  argv:=ppchar(ap[1]);
  env:=	ppchar(ap[2+argc]);
  environ:=env;
  if (argc>0) and (argv[0]<>#0) Then
   begin
     progname:=argv[0];
     s:=progname;
     while s^<>#0 do
        begin
          if s^='/' then
            progname:=@s[1];
          inc(s);
	end; 
    end;
  if assigned(pchar(@dynamic)) then // I suspect this is a trick to find
				    // out runtime if we are shared
				    // linking, so the same code can be used
				    // for static and shared linking
    atexit(cleanup)
  else
    init_tls;
  {$ifdef GCRT}
    atexit(@_mcleanup);
  {$endif}
  atexit(@fini);
  {$ifdef GCRT}
    monstartup(@eprol,@etext);
   asm
    eprol:
   end;
  {$endif} 
  init;
  libc_exit(main(argc,argv,env)); // doesn't return
 asm
     { We need this stuff to make gdb behave itself, otherwise
      gdb will chokes with SIGILL when trying to debug apps.
    }
    .section ".note.ABI-tag", "a"
    .align 4
    .long 8
    .long 4 
    .long  1
    .asciz "FreeBSD"
    .align 4
    .long	900044
    .align 4
    .section	.note.GNU-stack,"",@progbits
  end;
end;



begin
end.