sysinitgprof.pp 3.8 KB

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