sysinitgprof.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. EXE_Entry(EntryInformation);
  58. end;
  59. procedure CMainDLL;cdecl;
  60. begin
  61. asm
  62. subl $0x8,%esp
  63. andl $0xfffffff0,%esp
  64. end;
  65. DLLgmon_start;
  66. __main;
  67. SetupEntryInformation;
  68. DLL_Entry(EntryInformation);
  69. end;
  70. procedure _FPC_mainCRTStartup;stdcall;public name '_mainCRTStartup';
  71. begin
  72. IsConsole:=true;
  73. asm
  74. subl $0x8,%esp
  75. andl $0xfffffff0,%esp
  76. end;
  77. { it seems cygwin messed around with the console mode so we've to
  78. store the startup console mode before cygwin can do anything (FK)
  79. }
  80. GetConsoleMode(GetStdHandle((Std_Input_Handle)),StartupConsoleMode);
  81. Cygwin_crt0(@CMainEXE);
  82. end;
  83. procedure _FPC_WinMainCRTStartup;stdcall;public name '_WinMainCRTStartup';
  84. begin
  85. IsConsole:=false;
  86. asm
  87. subl $0x8,%esp
  88. andl $0xfffffff0,%esp
  89. end;
  90. Cygwin_crt0(@CMainEXE);
  91. end;
  92. procedure _FPC_DLLMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLMainCRTStartup';
  93. begin
  94. IsConsole:=true;
  95. sysinstance:=_hinstance;
  96. dllreason:=_dllreason;
  97. dllparam:=_dllparam;
  98. asm
  99. subl $0x8,%esp
  100. andl $0xfffffff0,%esp
  101. end;
  102. Cygwin_crt0(@CMainDLL);
  103. end;
  104. procedure _FPC_DLLWinMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLWinMainCRTStartup';
  105. begin
  106. IsConsole:=false;
  107. sysinstance:=_hinstance;
  108. dllreason:=_dllreason;
  109. dllparam:=_dllparam;
  110. asm
  111. subl $0x8,%esp
  112. andl $0xfffffff0,%esp
  113. end;
  114. Cygwin_crt0(@CMainDLL);
  115. end;
  116. {$warnings off}
  117. {$linklib c}
  118. {$linklib gmon}
  119. {$linklib cygwin}
  120. {$linklib user32}
  121. {$linklib kernel32}
  122. {$linklib gcc}
  123. end.