si_prc.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. {$asmmode att}
  12. {
  13. Linux ELF startup code for Free Pascal
  14. Stack layout at program start:
  15. nil
  16. envn
  17. ....
  18. .... ENVIRONMENT VARIABLES
  19. env1
  20. env0
  21. nil
  22. argn
  23. ....
  24. .... COMMAND LINE OPTIONS
  25. arg1
  26. arg0
  27. argc <--- esp
  28. }
  29. {******************************************************************************
  30. Process start/halt
  31. ******************************************************************************}
  32. var
  33. dlexitproc : pointer;
  34. {$ifdef FPC_PIC}
  35. function fpc_geteipasebxlocal : pointer; [external name 'fpc_geteipasebx'];
  36. {$endif}
  37. procedure InitTLS; [external name 'FPC_INITTLS'];
  38. procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
  39. asm
  40. { First locate the start of the environment variables }
  41. popl %ecx { Get argc in ecx }
  42. movl %esp,%ebx { Esp now points to the arguments }
  43. leal 4(%esp,%ecx,4),%eax { The start of the environment is: esp+4*eax+4 }
  44. andl $0xfffffff0,%esp { Align stack to 16 bytes }
  45. {$ifdef FPC_PIC}
  46. pushl %ebx
  47. pushl %ecx
  48. call fpc_geteipasebxlocal
  49. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  50. movl operatingsystem_parameter_envp@GOT(%ebx),%ecx
  51. movl %eax,(%ecx)
  52. movl operatingsystem_parameter_argc@GOT(%ebx),%edx
  53. popl %ecx
  54. movl %ecx,(%edx)
  55. movl operatingsystem_parameter_argv@GOT(%ebx),%edx
  56. popl %ebx
  57. movl %ebx,(%edx)
  58. {$else FPC_PIC}
  59. movl %eax,operatingsystem_parameter_envp
  60. movl %ecx,operatingsystem_parameter_argc
  61. movl %ebx,operatingsystem_parameter_argv
  62. {$endif FPC_PIC}
  63. { Initialize FPU }
  64. call SysResetFPU
  65. { Save initial stackpointer }
  66. {$ifdef FPC_PIC}
  67. pushl %ebx
  68. call fpc_geteipasebxlocal
  69. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  70. movl initialstkptr@GOT(%ebx),%ebx
  71. movl %esp,(%ebx)
  72. popl %ebx
  73. {$else FPC_PIC}
  74. movl %esp,initialstkptr
  75. {$endif FPC_PIC}
  76. {$if FPC_FULLVERSION>30200}
  77. call InitTLS
  78. {$endif FPC_FULLVERSION>30200}
  79. xorl %ebp,%ebp
  80. call PASCALMAIN
  81. end;
  82. procedure _FPC_dynamic_proc_start; assembler; nostackframe; public name '_dynamic_start';
  83. asm
  84. {$ifdef FPC_PIC}
  85. pushl %ebx
  86. call fpc_geteipasebxlocal
  87. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  88. movl dlexitproc@GOT(%ebx),%ebx
  89. movl %edx,(%ebx)
  90. popl %ebx
  91. {$else}
  92. movl %edx, dlexitproc
  93. {$endif}
  94. jmp _FPC_proc_start
  95. end;
  96. procedure _FPC_proc_haltproc(e:longint); cdecl; assembler; public name '_haltproc';
  97. asm
  98. //addl $12, %esp { align stack back to 16 bytes }
  99. {$ifdef FPC_PIC}
  100. call fpc_geteipasebxlocal
  101. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  102. movl dlexitproc@GOT(%ebx),%eax
  103. movl (%eax),%eax
  104. {$else FPC_PIC}
  105. movl dlexitproc,%eax
  106. {$endif FPC_PIC}
  107. testl %eax,%eax
  108. je .Lnodlexitproc
  109. call *%eax
  110. .Lnodlexitproc:
  111. movl syscall_nr_exit_group,%eax
  112. movl e,%ebx
  113. int $0x80
  114. movl syscall_nr_exit,%eax
  115. movl e,%ebx
  116. int $0x80
  117. jmp .Lnodlexitproc
  118. end;