si_g.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2005 by Michael Van Canneyt, Peter Vreman,
  4. & Daniel Mantione, members of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {
  12. Linux ELF startup code for Free Pascal
  13. Stack layout at program start:
  14. nil
  15. envn
  16. ....
  17. .... ENVIRONMENT VARIABLES
  18. env1
  19. env0
  20. nil
  21. argn
  22. ....
  23. .... COMMAND LINE OPTIONS
  24. arg1
  25. arg0
  26. argc <--- esp
  27. }
  28. var
  29. gmon_etext: pointer; external name '_etext';
  30. gmon_monstarted: longint = 0;
  31. procedure gmon_monstartup; external name 'monstartup';
  32. procedure gmon_mcleanup; external name '_mcleanup';
  33. procedure libc_atexit; external name '__libc_atexit';
  34. procedure libc_exit; external name '__libc_exit';
  35. procedure libc_init; external name '__libc_init';
  36. procedure libc_setfpucw; external name '__setfpucw';
  37. procedure libc_start_main; external name '__libc_start_main';
  38. procedure PASCALMAIN; external name 'PASCALMAIN';
  39. {******************************************************************************
  40. Process + profiling start/halt
  41. ******************************************************************************}
  42. {$asmmode ATT}
  43. procedure _FPC_proc_gprof_start; assembler; nostackframe; public name '_start';
  44. asm
  45. { First locate the start of the environment variables }
  46. popl %ecx
  47. movl %esp,%ebx { Points to the arguments }
  48. movl %ecx,%eax
  49. incl %eax
  50. shll $2,%eax
  51. addl %esp,%eax
  52. andl $0xfffffff8,%esp { Align stack }
  53. movl %eax,operatingsystem_parameter_envp { Move the environment pointer }
  54. movl %ecx,operatingsystem_parameter_argc { Move the argument counter }
  55. movl %ebx,operatingsystem_parameter_argv { Move the argument pointer }
  56. finit { initialize fpu }
  57. fwait
  58. fldcw Default8087CW
  59. pushl $gmon_etext { Initialize gmon }
  60. pushl $_FPC_proc_gprof_start
  61. call gmon_monstartup
  62. addl $8,%esp
  63. pushl $gmon_mcleanup
  64. call libc_atexit
  65. addl $4,%esp
  66. { Save initial stackpointer }
  67. movl %esp,initialstkptr
  68. xorl %ebp,%ebp
  69. call PASCALMAIN
  70. end;
  71. procedure _FPC_proc_gprof_haltproc; assembler; nostackframe; public name '_haltproc';
  72. asm
  73. .Lhaltproc:
  74. {$ifdef FPC_PIC}
  75. call fpc_geteipasebx
  76. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  77. movl ExitCode@GOT(%ebx),%ebx
  78. {$if sizeof(ExitCode)=2}
  79. movzwl (%ebx),%ebx
  80. {$else}
  81. mov (%ebx),%ebx
  82. {$endif}
  83. {$else FPC_PIC}
  84. {$if sizeof(ExitCode)=2}
  85. movzwl ExitCode,%ebx
  86. {$else}
  87. mov ExitCode,%ebx
  88. {$endif}
  89. {$endif FPC_PIC}
  90. pushl %ebx
  91. call libc_exit { call libc exit, this will write the gmon.out }
  92. movl syscall_nr_exit_group,%eax
  93. popl %ebx
  94. int $0x80
  95. jmp .Lhaltproc
  96. end;