si_g.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. {******************************************************************************
  39. Process + profiling start/halt
  40. ******************************************************************************}
  41. {$asmmode ATT}
  42. procedure _FPC_proc_gprof_start; assembler; nostackframe; public name '_start';
  43. asm
  44. { First locate the start of the environment variables }
  45. popl %ecx
  46. movl %esp,%ebx { Points to the arguments }
  47. movl %ecx,%eax
  48. incl %eax
  49. shll $2,%eax
  50. addl %esp,%eax
  51. andl $0xfffffff8,%esp { Align stack }
  52. movl %eax,operatingsystem_parameter_envp { Move the environment pointer }
  53. movl %ecx,operatingsystem_parameter_argc { Move the argument counter }
  54. movl %ebx,operatingsystem_parameter_argv { Move the argument pointer }
  55. finit { initialize fpu }
  56. fwait
  57. fldcw Default8087CW
  58. pushl $gmon_etext { Initialize gmon }
  59. pushl $_FPC_proc_gprof_start
  60. call gmon_monstartup
  61. addl $8,%esp
  62. pushl $gmon_mcleanup
  63. call libc_atexit
  64. addl $4,%esp
  65. { Save initial stackpointer }
  66. movl %esp,initialstkptr
  67. xorl %ebp,%ebp
  68. call PASCALMAIN
  69. end;
  70. procedure _FPC_proc_gprof_haltproc; assembler; nostackframe; public name '_haltproc';
  71. asm
  72. .Lhaltproc:
  73. {$ifdef FPC_PIC}
  74. call fpc_geteipasebx
  75. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  76. movl ExitCode@GOT(%ebx),%ebx
  77. {$if sizeof(ExitCode)=2}
  78. movzwl (%ebx),%ebx
  79. {$else}
  80. mov (%ebx),%ebx
  81. {$endif}
  82. {$else FPC_PIC}
  83. {$if sizeof(ExitCode)=2}
  84. movzwl ExitCode,%ebx
  85. {$else}
  86. mov ExitCode,%ebx
  87. {$endif}
  88. {$endif FPC_PIC}
  89. pushl %ebx
  90. call libc_exit { call libc exit, this will write the gmon.out }
  91. movl syscall_nr_exit_group,%eax
  92. popl %ebx
  93. int $0x80
  94. jmp .Lhaltproc
  95. end;