prt0.as 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #
  2. # $Id$
  3. # This file is part of the Free Pascal run time library.
  4. # Copyright (c) 1999-2004 by Michael Van Canneyt, Peter Vreman,
  5. # & Daniel Mantione, 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 "prt0.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. leal operatingsystem_parameters,%edi
  46. stosl /* Move the environment pointer */
  47. xchg %ecx,%eax
  48. stosl /* Move the argument counter */
  49. xchg %ebx,%eax
  50. stosl /* Move the argument pointer */
  51. fninit /* initialize fpu */
  52. fwait
  53. fldcw ___fpucw
  54. xorl %ebp,%ebp
  55. call PASCALMAIN
  56. .globl _haltproc
  57. .type _haltproc,@function
  58. _haltproc:
  59. _haltproc2: # GAS <= 2.15 bug: generates larger jump if a label is exported
  60. xorl %eax,%eax
  61. incl %eax /* eax=1, exit call */
  62. movzwl operatingsystem_result,%ebx
  63. int $0x80
  64. jmp _haltproc2
  65. .data
  66. ___fpucw:
  67. .long 0x1332
  68. .bss
  69. .type ___fpc_brk_addr,@object
  70. .comm ___fpc_brk_addr,4 /* heap management */
  71. operatingsystem_parameters:
  72. .skip 3*4
  73. .global operatingsystem_parameter_envp
  74. .global operatingsystem_parameter_argc
  75. .global operatingsystem_parameter_argv
  76. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  77. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  78. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  79. #
  80. # $Log$
  81. # Revision 1.4 2004-07-03 21:50:31 daniel
  82. # * Modified bootstrap code so separate prt0.as/prt0_10.as files are no
  83. # longer necessary
  84. #
  85. # Revision 1.3 2002/09/07 16:01:20 peter
  86. # * old logs removed and tabs fixed
  87. #