sysinitcyg.pp 4.0 KB

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