sysinitcyg.pp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 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 sysinitcyg;
  14. interface
  15. implementation
  16. var
  17. SysInstance : Longint;external name '_FPC_SysInstance';
  18. EntryInformation : TEntryInformation;
  19. InitFinalTable : record end; external name 'INITFINAL';
  20. ThreadvarTablesTable : record end; external name 'FPC_THREADVARTABLES';
  21. valgrind_used : boolean;external name '__fpc_valgrind';
  22. procedure EXE_Entry; external name '_FPC_EXE_Entry';
  23. function DLL_Entry : longbool; external name '_FPC_DLL_Entry';
  24. procedure Cygwin_crt0(p : pointer);cdecl;external name 'cygwin_crt0';
  25. procedure __main;cdecl;external name '__main';
  26. const
  27. STD_INPUT_HANDLE = dword(-10);
  28. function GetStdHandle(nStdHandle:DWORD) : THandle; stdcall; external 'kernel32' name 'GetStdHandle';
  29. function GetConsoleMode(hConsoleHandle: THandle; var lpMode: DWORD): Boolean; stdcall; external 'kernel32' name 'GetConsoleMode';
  30. procedure EXE_Entry(const info : TEntryInformation); external name '_FPC_EXE_Entry';
  31. function DLL_entry(const info : TEntryInformation) : longbool; external name '_FPC_DLL_Entry';
  32. procedure PascalMain;stdcall;external name 'PASCALMAIN';
  33. procedure asm_exit;stdcall;public name 'asm_exit';
  34. begin
  35. end;
  36. procedure SetupEntryInformation;
  37. begin
  38. EntryInformation.InitFinalTable:=@InitFinalTable;
  39. EntryInformation.ThreadvarTablesTable:=@ThreadvarTablesTable;
  40. EntryInformation.asm_exit:=@asm_exit;
  41. EntryInformation.PascalMain:=@PascalMain;
  42. EntryInformation.valgrind_used:=valgrind_used;
  43. end;
  44. procedure CMainEXE;cdecl;
  45. begin
  46. asm
  47. subl $0x8,%esp
  48. andl $0xfffffff0,%esp
  49. end;
  50. __main;
  51. SetupEntryInformation;
  52. EXE_Entry(EntryInformation);
  53. end;
  54. procedure CMainDLL;cdecl;
  55. begin
  56. asm
  57. subl $0x8,%esp
  58. andl $0xfffffff0,%esp
  59. end;
  60. __main;
  61. SetupEntryInformation;
  62. DLL_Entry(EntryInformation);
  63. end;
  64. procedure _FPC_mainCRTStartup;stdcall;public name '_mainCRTStartup';
  65. begin
  66. IsConsole:=true;
  67. asm
  68. subl $0x8,%esp
  69. andl $0xfffffff0,%esp
  70. end;
  71. { it seems cygwin messed around with the console mode so we've to
  72. store the startup console mode before cygwin can do anything (FK)
  73. }
  74. GetConsoleMode(GetStdHandle((Std_Input_Handle)),StartupConsoleMode);
  75. Cygwin_crt0(@CMainEXE);
  76. end;
  77. procedure _FPC_WinMainCRTStartup;stdcall;public name '_WinMainCRTStartup';
  78. begin
  79. IsConsole:=false;
  80. asm
  81. subl $0x8,%esp
  82. andl $0xfffffff0,%esp
  83. end;
  84. Cygwin_crt0(@CMainEXE);
  85. end;
  86. procedure _FPC_DLLMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLMainCRTStartup';
  87. begin
  88. IsConsole:=true;
  89. sysinstance:=_hinstance;
  90. dllreason:=_dllreason;
  91. dllparam:=_dllparam;
  92. asm
  93. subl $0x8,%esp
  94. andl $0xfffffff0,%esp
  95. end;
  96. Cygwin_crt0(@CMainDLL);
  97. end;
  98. procedure _FPC_DLLWinMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLWinMainCRTStartup';
  99. begin
  100. IsConsole:=false;
  101. sysinstance:=_hinstance;
  102. dllreason:=_dllreason;
  103. dllparam:=_dllparam;
  104. asm
  105. subl $0x8,%esp
  106. andl $0xfffffff0,%esp
  107. end;
  108. Cygwin_crt0(@CMainDLL);
  109. end;
  110. end.