cprt0.as 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #
  2. # $Id$
  3. # This file is part of the Free Pascal run time library.
  4. # Copyright (c) 1999-2000 by Michael Van Canneyt and Peter Vreman
  5. # members of the Free Pascal development team.
  6. #
  7. # See the file COPYING.FPC, included in this distribution,
  8. # for details about the copyright.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY;without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. #**********************************************************************}
  15. #
  16. # Linux ELF startup code for Free Pascal
  17. #
  18. #
  19. # Stack layout at program start:
  20. #
  21. # nil
  22. # envn
  23. # ....
  24. # .... ENVIRONMENT VARIABLES
  25. # env1
  26. # env0
  27. # nil
  28. # argn
  29. # ....
  30. # .... COMMAND LINE OPTIONS
  31. # arg1
  32. # arg0
  33. # argc <--- esp
  34. #
  35. .file "cprt0.as"
  36. .text
  37. .globl _start
  38. .type _start,@function
  39. _start:
  40. /* First locate the start of the environment variables */
  41. popl %ecx /* Get argc in ecx */
  42. movl %esp,%ebx /* Esp now points to the arguments */
  43. leal 4(%esp,%ecx,4),%eax /* The start of the environment is: esp+4*eax+8 */
  44. andl $0xfffffff8,%esp /* Align stack */
  45. movl %eax,operatingsystem_parameter_envp /* Move the environment pointer */
  46. movl %ecx,operatingsystem_parameter_argc /* Move the argument counter */
  47. movl %ebx,operatingsystem_parameter_argv /* Move the argument pointer */
  48. movl %eax,__environ /* libc environ */
  49. pushl %eax
  50. pushl %ebx
  51. pushl %ecx
  52. call __libc_init /* init libc */
  53. movzwl __fpu_control,%eax
  54. pushl %eax
  55. call __setfpucw
  56. popl %eax
  57. pushl $_fini
  58. call atexit
  59. popl %eax
  60. call _init
  61. popl %eax
  62. popl %eax
  63. xorl %ebp,%ebp
  64. call PASCALMAIN /* start the program */
  65. .globl _haltproc
  66. .type _haltproc,@function
  67. _haltproc:
  68. _haltproc2: # GAS <= 2.15 bug: generates larger jump if a label is exported
  69. movzwl operatingsystem_result,%ebx
  70. pushl %ebx
  71. call exit
  72. xorl %eax,%eax
  73. incl %eax /* eax=1, exit call */
  74. popl %ebx
  75. int $0x80
  76. jmp _haltproc2
  77. .data
  78. .bss
  79. .type ___fpc_brk_addr,@object
  80. .comm ___fpc_brk_addr,4 /* heap management */
  81. .comm operatingsystem_parameter_envp,4
  82. .comm operatingsystem_parameter_argc,4
  83. .comm operatingsystem_parameter_argv,4
  84. #
  85. # $Log$
  86. # Revision 1.4 2004-07-03 21:50:31 daniel
  87. # * Modified bootstrap code so separate prt0.as/prt0_10.as files are no
  88. # longer necessary
  89. #
  90. # Revision 1.3 2002/09/07 16:01:20 peter
  91. # * old logs removed and tabs fixed
  92. #