start.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2009 by Pierre Muller,
  4. member of the Free Pascal development team.
  5. Program startup
  6. Adapted from code generated by gcc on opensolaris 2.11
  7. and sparc version in
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. type
  15. TCdeclProcedure = procedure; cdecl;
  16. function atexit(proc:TCdeclProcedure):longint;cdecl;external 'c' name 'atexit'{ @plt };
  17. procedure C_exit;cdecl;external 'c' name 'exit';
  18. procedure _exit;cdecl;external 'c' name '_exit';
  19. //procedure _fini;cdecl;external 'c' name '_fini';
  20. //procedure __fpstart;cdecl;external 'c' name '__fpstart'{ @plt };
  21. //procedure __fsr;cdecl;external 'c' name '__fsr';
  22. //procedure _init;cdecl;external 'c' name '_init';
  23. procedure PascalMain;external name 'PASCALMAIN';
  24. {vars are not correctly transformed :(
  25. var
  26. _DYNAMIC : longint; cvar; external;
  27. __Argv : pointer; cvar; external;
  28. environ : pointer; cvar; external;
  29. __get_exit_frame_monitor_ptr : pointer; cvar; external;
  30. __do_exit_code_ptr : pointer; cvar; external;
  31. }
  32. var
  33. _environ : pointer; cvar; external;
  34. procedure _DYNAMIC;cdecl;external 'c' name '_DYNAMIC'; { should be weak }
  35. procedure __Argv;cdecl;external 'c' name '__Argv';
  36. //procedure environ;cdecl;external 'c' name 'environ';
  37. //procedure __get_exit_frame_monitor_ptr;cdecl;external 'c' name '__get_exit_frame_monitor_ptr';
  38. //procedure __do_exit_code_ptr;cdecl;external 'c' name '__do_exit_code_ptr';
  39. {
  40. (top-gdb) disas _start
  41. Dump of assembler code for function _start: }
  42. procedure _start;assembler;nostackframe;public name '_start';
  43. asm
  44. mov %esp,%eax
  45. mov %eax,StackTopPtr
  46. pushl $0x0
  47. pushl $0x0
  48. mov %esp,%ebp
  49. mov $_DYNAMIC,%eax
  50. test %eax,%eax
  51. je .Label1
  52. push %edx
  53. call atexit {@plt}
  54. add $0x4,%esp
  55. .Label1:
  56. (*
  57. push _fini
  58. call atexit {@plt}
  59. add $0x4,%esp
  60. lea __get_exit_frame_monitor_ptr,%eax
  61. mov (%eax),%eax
  62. test %eax,%eax
  63. je .Label2
  64. lea __do_exit_code_ptr,%eax
  65. mov (%eax),%eax
  66. test %eax,%eax
  67. je .Label2
  68. push %eax
  69. call atexit {@plt}
  70. add $0x4,%esp
  71. *)
  72. .Label2:
  73. mov 0x8(%ebp),%eax
  74. mov %eax,argc
  75. mov _environ,%edx
  76. test %edx,%edx
  77. jne .Label3
  78. lea 0x10(%ebp,%eax,4),%edx
  79. .Label3:
  80. movl %edx,_environ
  81. movl %edx,envp
  82. and $0xfffffff0,%esp
  83. push %edx
  84. lea 0xc(%ebp),%edx
  85. mov %edx,argv
  86. push %edx
  87. push %eax
  88. //call __fpstart {@plt}
  89. //call __fsr
  90. //call _init
  91. call PASCALMAIN {was <main> }
  92. add $0xc,%esp
  93. push %eax
  94. push %eax
  95. call C_exit { was exit@plt }
  96. add $0x4,%esp
  97. call _exit {@plt}
  98. add $0x4,%esp
  99. hlt
  100. end;