si_c.inc 3.1 KB

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