si_c.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. libc_environ: pchar; external name '__environ';
  30. libc_fpu_control: word; external name '__fpu_control';
  31. libc_init_proc: procedure; external name '_init';
  32. libc_fini_proc: procedure; external name '_fini';
  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. C library start/halt
  41. ******************************************************************************}
  42. {$asmmode ATT}
  43. procedure _FPC_libc_start; assembler; nostackframe; public name '_start';
  44. asm
  45. { First locate the start of the environment variables }
  46. popl %ecx { Get argc in ecx }
  47. movl %esp,%ebx { Esp now points to the arguments }
  48. leal 4(%esp,%ecx,4),%eax { The start of the environment is: esp+4*eax+8 }
  49. andl $0xfffffff8,%esp { Align stack }
  50. movl %eax,operatingsystem_parameter_envp { Move the environment pointer }
  51. movl %ecx,operatingsystem_parameter_argc { Move the argument counter }
  52. movl %ebx,operatingsystem_parameter_argv { Move the argument pointer }
  53. movl %eax,libc_environ { libc environ }
  54. pushl %eax
  55. pushl %ebx
  56. pushl %ecx
  57. call libc_init { init libc }
  58. movzwl libc_fpu_control,%eax
  59. pushl %eax
  60. call libc_setfpucw
  61. popl %eax
  62. pushl $libc_fini_proc
  63. call libc_atexit
  64. popl %eax
  65. call libc_init_proc
  66. popl %eax
  67. popl %eax
  68. { Save initial stackpointer }
  69. movl %esp,initialstkptr
  70. xorl %ebp,%ebp
  71. call PASCALMAIN { start the program }
  72. end;
  73. procedure _FPC_libc_haltproc; assembler; nostackframe; public name '_haltproc';
  74. asm
  75. .Lhaltproc:
  76. {$if sizeof(ExitCode)=2}
  77. movzwl ExitCode,%ebx
  78. {$else}
  79. mov ExitCode,%ebx
  80. {$endif}
  81. pushl %ebx
  82. call libc_exit
  83. xorl %eax,%eax
  84. incl %eax { eax=1, exit call }
  85. popl %ebx
  86. int $0x80
  87. jmp .Lhaltproc
  88. end;