1{
2    This file is part of the Free Pascal run time library.
3    Copyright (c) 1999-2006 by Florian Klaempfl and Pavel Ozerski
4    member of the Free Pascal development team.
5
6    Win32 cygwin profiler startup code
7
8    See the file COPYING.FPC, included in this distribution,
9    for details about the copyright.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 **********************************************************************}
16{$asmmode att}
17unit SysInitGProf;
18
19  interface
20
21  implementation
22
23    const
24      monstarted : dword = 0;
25
26    var
27      stext : record end;external name '__text_start__';
28      etext : record end;external name 'etext';
29
30    procedure Cygwin_crt0(p : pointer);cdecl;external name 'cygwin_crt0';
31    procedure __main;cdecl;external name '__main';
32    procedure _mcleanup;cdecl;external name '_mcleanup';
33
34    procedure monstartup(main,etext : pointer);cdecl;external name 'monstartup';
35
36    procedure CMainEXE;cdecl;forward;
37    procedure CMainDLL;cdecl;forward;
38
39    procedure asm_exit;stdcall;public name 'asm_exit';
40      begin
41        _mcleanup;
42      end;
43
44{$i sysinit.inc}
45
46    procedure EXEgmon_start;
47      begin
48        if monstarted=0 then
49          begin
50            inc(monstarted);
51            monstartup(@stext,@etext);
52          end;
53      end;
54
55
56    procedure DLLgmon_start;
57      begin
58        if monstarted=0 then
59          begin
60            inc(monstarted);
61            monstartup(@stext,@etext);
62          end;
63      end;
64
65
66    procedure CMainEXE;cdecl;
67      begin
68        asm
69          subl   $0x8,%esp
70          andl   $0xfffffff0,%esp
71        end;
72        EXEgmon_start;
73        __main;
74        SetupEntryInformation;
75{$ifdef FPC_USE_TLS_DIRECTORY}
76        LinkIn(@tlsdir,@tls_callback_end,@tls_callback);
77{$endif}
78        EXE_Entry(SysInitEntryInformation);
79      end;
80
81
82    procedure CMainDLL;cdecl;
83      begin
84        asm
85          subl   $0x8,%esp
86          andl   $0xfffffff0,%esp
87        end;
88        DLLgmon_start;
89        __main;
90        SetupEntryInformation;
91        DLL_Entry(SysInitEntryInformation);
92      end;
93
94
95    procedure _FPC_mainCRTStartup;stdcall;public name '_mainCRTStartup';
96      begin
97        IsConsole:=true;
98        asm
99          subl   $0x8,%esp
100          andl   $0xfffffff0,%esp
101        end;
102        { it seems cygwin messed around with the console mode so we've to
103          store the startup console mode before cygwin can do anything (FK)
104        }
105        GetConsoleMode(GetStdHandle((Std_Input_Handle)),StartupConsoleMode);
106        Cygwin_crt0(@CMainEXE);
107      end;
108
109
110    procedure _FPC_WinMainCRTStartup;stdcall;public name '_WinMainCRTStartup';
111      begin
112        IsConsole:=false;
113        asm
114          subl   $0x8,%esp
115          andl   $0xfffffff0,%esp
116        end;
117        Cygwin_crt0(@CMainEXE);
118      end;
119
120
121    procedure _FPC_DLLMainCRTStartup(_hinstance : longint;_dllreason : dword;_dllparam:Pointer);stdcall;public name '_DLLMainCRTStartup';
122      begin
123        IsConsole:=true;
124        sysinstance:=_hinstance;
125        dllreason:=_dllreason;
126        dllparam:=PtrInt(_dllparam);
127        asm
128          subl   $0x8,%esp
129          andl   $0xfffffff0,%esp
130        end;
131        Cygwin_crt0(@CMainDLL);
132      end;
133
134
135    procedure _FPC_DLLWinMainCRTStartup(_hinstance : longint;_dllreason : dword;_dllparam:Pointer);stdcall;public name '_DLLWinMainCRTStartup';
136      begin
137        IsConsole:=false;
138        sysinstance:=_hinstance;
139        dllreason:=_dllreason;
140        dllparam:=PtrInt(_dllparam);
141        asm
142          subl   $0x8,%esp
143          andl   $0xfffffff0,%esp
144        end;
145        Cygwin_crt0(@CMainDLL);
146      end;
147
148{$warnings off}
149    {$linklib c}
150    {$linklib gmon}
151    {$linklib cygwin}
152    {$linklib user32}
153    {$linklib kernel32}
154    {$linklib gcc}
155
156end.
157