start.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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;cdecl;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. pushl $0x0
  45. pushl $0x0
  46. mov %esp,%ebp
  47. mov $_DYNAMIC,%eax
  48. test %eax,%eax
  49. je .Label1
  50. push %edx
  51. call atexit {@plt}
  52. add $0x4,%esp
  53. .Label1:
  54. (*
  55. push _fini
  56. call atexit {@plt}
  57. add $0x4,%esp
  58. lea __get_exit_frame_monitor_ptr,%eax
  59. mov (%eax),%eax
  60. test %eax,%eax
  61. je .Label2
  62. lea __do_exit_code_ptr,%eax
  63. mov (%eax),%eax
  64. test %eax,%eax
  65. je .Label2
  66. push %eax
  67. call atexit {@plt}
  68. add $0x4,%esp
  69. *)
  70. .Label2:
  71. mov 0x8(%ebp),%eax
  72. mov %eax,argc
  73. mov _environ,%edx
  74. test %edx,%edx
  75. jne .Label3
  76. lea 0x10(%ebp,%eax,4),%edx
  77. .Label3:
  78. movl %edx,_environ
  79. movl %edx,envp
  80. and $0xfffffff0,%esp
  81. push %edx
  82. lea 0xc(%ebp),%edx
  83. mov %edx,argv
  84. push %edx
  85. push %eax
  86. //call __fpstart {@plt}
  87. //call __fsr
  88. //call _init
  89. call PASCALMAIN {was <main> }
  90. add $0xc,%esp
  91. push %eax
  92. push %eax
  93. call C_exit { was exit@plt }
  94. add $0x4,%esp
  95. call _exit {@plt}
  96. add $0x4,%esp
  97. hlt
  98. end;