si_uc.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/uClibc startup code for Free Pascal
  13. taken from uClibc/sysdeps/linux/i386/crt1.S
  14. %edx Contains a function pointer to be registered with `atexit'.
  15. This is how the dynamic linker arranges to have DT_FINI
  16. functions called for shared libraries that have been loaded
  17. before this code runs.
  18. Stack layout at program start:
  19. nil
  20. envn
  21. ....
  22. .... ENVIRONMENT VARIABLES
  23. env1
  24. env0
  25. nil
  26. argn
  27. ....
  28. .... COMMAND LINE OPTIONS
  29. arg1
  30. arg0
  31. argc <--- esp
  32. }
  33. procedure libc_init; external name '__uClibc_init';
  34. procedure libc_fini; external name '__uClibc_fini';
  35. procedure libc_exit; external name '_exit';
  36. procedure libc_main; external name '__uClibc_main';
  37. procedure PASCALMAIN; external name 'PASCALMAIN';
  38. {******************************************************************************
  39. C library start/halt
  40. ******************************************************************************}
  41. {$asmmode ATT}
  42. procedure _FPC_libc_start; assembler; nostackframe; public name '_start';
  43. asm
  44. xorl %ebp,%ebp { clear outer most frame for backtraces }
  45. popl %esi { Get argc in ecx }
  46. movl %esp,%ecx { Esp now points to the arguments }
  47. leal 4(%esp,%esi,4),%eax { The start of the environment is: esp+4*eax+8 }
  48. andl $0xfffffff0,%esp { Align stack }
  49. pushl %eax { push garbage, so we push 32 bytes in total }
  50. movl %eax,operatingsystem_parameter_envp { save the environment pointer }
  51. movl %esi,operatingsystem_parameter_argc { save the argument counter }
  52. movl %ecx,operatingsystem_parameter_argv { save the argument pointer }
  53. movl %esp,initialstkptr { save initial stack pointer }
  54. pushl %esp { provide highest stack address to C library }
  55. pushl %edx { push address of shared library finalization }
  56. {$ifdef PIC}
  57. call .L0
  58. .L0:
  59. pop %ebx
  60. addl $_GLOBAL_OFFSET_TABLE_+[.-.L0],%ebx
  61. pushl _fini@GOT(%ebx) { push address of entry points }
  62. pushl _init@GOT(%ebx)
  63. pushl %ecx { push argv }
  64. pushl %esi { push argc }
  65. pushl $PASCALMAIN { push fpc main procedure }
  66. call libc_main { let fpc main be called from libc startup }
  67. {$else}
  68. pushl $libc_fini { push address of entry points }
  69. pushl $libc_init
  70. pushl %ecx { push argv }
  71. pushl %esi { push argc }
  72. pushl $PASCALMAIN { push fpc main procedure }
  73. call libc_main { let fpc main be called from libc startup }
  74. {$endif}
  75. end;
  76. procedure _FPC_libc_haltproc; assembler; nostackframe; public name '_haltproc';
  77. asm
  78. .Lhaltproc:
  79. {$if sizeof(ExitCode)=2}
  80. movzwl ExitCode,%ebx
  81. {$else}
  82. mov ExitCode,%ebx
  83. {$endif}
  84. pushl %ebx
  85. call libc_exit
  86. xorl %eax,%eax
  87. incl %eax { eax=1, exit call }
  88. popl %ebx
  89. int $0x80
  90. jmp .Lhaltproc
  91. end;