prt0.as 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #
  2. # This file is part of the Free Pascal run time library.
  3. # Copyright (c) 1999-2004 by Michael Van Canneyt, Peter Vreman,
  4. # & Daniel Mantione, members of the Free Pascal development team.
  5. #
  6. # See the file COPYING.FPC, included in this distribution,
  7. # for details about the copyright.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY;without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. #
  13. #**********************************************************************}
  14. #
  15. # Linux ELF startup code for Free Pascal
  16. #
  17. # The code in this file is the default startup code, it is used unless
  18. # libc is linked in, profiling is enabled or you are compiling a shared
  19. # library.
  20. #
  21. #
  22. # Stack layout at program start:
  23. #
  24. # nil
  25. # envn
  26. # ....
  27. # .... ENVIRONMENT VARIABLES
  28. # env1
  29. # env0
  30. # nil
  31. # argn
  32. # ....
  33. # .... COMMAND LINE OPTIONS
  34. # arg1
  35. # arg0
  36. # argc <--- esp
  37. #
  38. .file "prt0.as"
  39. .text
  40. .globl _start
  41. .type _start,@function
  42. _start:
  43. /* First locate the start of the environment variables */
  44. popl %ecx /* Get argc in ecx */
  45. movl %esp,%ebx /* Esp now points to the arguments */
  46. leal 4(%esp,%ecx,4),%eax /* The start of the environment is: esp+4*eax+4 */
  47. andl $0xfffffff8,%esp /* Align stack */
  48. leal operatingsystem_parameters,%edi
  49. stosl /* Move the environment pointer */
  50. xchg %ecx,%eax
  51. stosl /* Move the argument counter */
  52. xchg %ebx,%eax
  53. stosl /* Move the argument pointer */
  54. fninit /* initialize fpu */
  55. fwait
  56. fldcw ___fpucw
  57. # /* Initialize gs for thread local storage */
  58. # movw %ds,%ax
  59. # movw %ax,%gs
  60. /* Save initial stackpointer */
  61. movl %esp,__stkptr
  62. xorl %ebp,%ebp
  63. call PASCALMAIN
  64. .globl _haltproc
  65. .type _haltproc,@function
  66. _haltproc:
  67. _haltproc2: # GAS <= 2.15 bug: generates larger jump if a label is exported
  68. movl $252,%eax /* exit_group */
  69. movzwl operatingsystem_result,%ebx
  70. int $0x80
  71. movl $1,%eax /* exit */
  72. movzwl operatingsystem_result,%ebx
  73. int $0x80
  74. jmp _haltproc2
  75. .data
  76. ___fpucw:
  77. .long 0x1332
  78. .bss
  79. .type __stkptr,@object
  80. .size __stkptr,4
  81. .global __stkptr
  82. __stkptr:
  83. .skip 4
  84. .type operatingsystem_parameters,@object
  85. .size operatingsystem_parameters,12
  86. operatingsystem_parameters:
  87. .skip 3*4
  88. .global operatingsystem_parameter_envp
  89. .global operatingsystem_parameter_argc
  90. .global operatingsystem_parameter_argv
  91. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  92. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  93. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  94. //.section .threadvar,"aw",@nobits
  95. .comm ___fpc_threadvar_offset,4