si_prc.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 _FPC_proc_start; assembler; nostackframe; public name '_start';
  38. asm
  39. { First locate the start of the environment variables }
  40. popl %ecx { Get argc in ecx }
  41. movl %esp,%ebx { Esp now points to the arguments }
  42. leal 4(%esp,%ecx,4),%eax { The start of the environment is: esp+4*eax+4 }
  43. andl $0xfffffff0,%esp { Align stack to 16 bytes }
  44. {$ifdef FPC_PIC}
  45. pushl %ebx
  46. pushl %ecx
  47. call fpc_geteipasebxlocal
  48. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  49. movl operatingsystem_parameter_envp@GOT(%ebx),%ecx
  50. movl %eax,(%ecx)
  51. movl operatingsystem_parameter_argc@GOT(%ebx),%edx
  52. popl %ecx
  53. movl %ecx,(%edx)
  54. movl operatingsystem_parameter_argv@GOT(%ebx),%edx
  55. popl %ebx
  56. movl %ebx,(%edx)
  57. {$else FPC_PIC}
  58. movl %eax,operatingsystem_parameter_envp
  59. movl %ecx,operatingsystem_parameter_argc
  60. movl %ebx,operatingsystem_parameter_argv
  61. {$endif FPC_PIC}
  62. { Initialize FPU }
  63. call SysResetFPU
  64. { Save initial stackpointer }
  65. {$ifdef FPC_PIC}
  66. pushl %ebx
  67. call fpc_geteipasebxlocal
  68. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  69. movl initialstkptr@GOT(%ebx),%ebx
  70. movl %esp,(%ebx)
  71. popl %ebx
  72. {$else FPC_PIC}
  73. movl %esp,initialstkptr
  74. {$endif FPC_PIC}
  75. xorl %ebp,%ebp
  76. call PASCALMAIN
  77. end;
  78. procedure _FPC_dynamic_proc_start; assembler; nostackframe; public name '_dynamic_start';
  79. asm
  80. {$ifdef FPC_PIC}
  81. pushl %ebx
  82. call fpc_geteipasebxlocal
  83. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  84. movl dlexitproc@GOT(%ebx),%ebx
  85. movl %edx,(%ebx)
  86. popl %ebx
  87. {$else}
  88. movl %edx, dlexitproc
  89. {$endif}
  90. jmp _FPC_proc_start
  91. end;
  92. procedure _FPC_proc_haltproc(e:longint); cdecl; assembler; public name '_haltproc';
  93. asm
  94. //addl $12, %esp { align stack back to 16 bytes }
  95. {$ifdef FPC_PIC}
  96. call fpc_geteipasebxlocal
  97. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  98. movl dlexitproc@GOT(%ebx),%eax
  99. movl (%eax),%eax
  100. {$else FPC_PIC}
  101. movl dlexitproc,%eax
  102. {$endif FPC_PIC}
  103. testl %eax,%eax
  104. je .Lnodlexitproc
  105. call *%eax
  106. .Lnodlexitproc:
  107. movl syscall_nr_exit_group,%eax
  108. movl e,%ebx
  109. int $0x80
  110. movl syscall_nr_exit,%eax
  111. movl e,%ebx
  112. int $0x80
  113. jmp .Lnodlexitproc
  114. end;