prt0.as 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* Startup code for elf32-sparc
  2. Copyright (C) 1997, 1998 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Richard Henderson <[email protected]>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library 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. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. MA 02111-1301, USA. */
  17. .section ".text"
  18. .align 4
  19. .global _dynamic_start
  20. .type _dynamic_start,#function
  21. _dynamic_start:
  22. .ifdef PIC
  23. call 1f
  24. sethi %hi(_GLOBAL_OFFSET_TABLE_+4),%o0
  25. 1: or %o0,%lo(_GLOBAL_OFFSET_TABLE_+8),%o0
  26. add %o0,%o7,%o0
  27. sethi %hi(__dl_fini),%o1
  28. or %o0,%lo(__dl_fini),%o1
  29. ld [%o0+%o1],%o0
  30. b _start
  31. st %g1,[%o0]
  32. .else
  33. sethi %hi(__dl_fini),%o0
  34. b _start
  35. st %g1,[%o0+%lo(__dl_fini)]
  36. .endif
  37. .align 4
  38. .global _start
  39. .type _start,#function
  40. _start:
  41. /* Terminate the stack frame, and reserve space for functions to
  42. drop their arguments. */
  43. mov %g0, %fp
  44. sub %sp, 6*4, %sp
  45. .ifdef PIC
  46. /* Set %l7 to _GLOBAL_OFFSET_TABLE value */
  47. sethi %hi(_GLOBAL_OFFSET_TABLE_-8),%l7
  48. or %l7,%lo(_GLOBAL_OFFSET_TABLE_-4),%l7
  49. call FPC_GETGOT
  50. nop
  51. .endif
  52. /* Extract the arguments and environment as encoded on the stack. The
  53. argument info starts after one register window (16 words) past the SP. */
  54. ld [%sp+22*4], %o2
  55. sethi %hi(operatingsystem_parameter_argc),%o1
  56. or %o1,%lo(operatingsystem_parameter_argc),%o1
  57. .ifdef PIC
  58. ld [%o1+%l7],%o1
  59. .endif
  60. st %o2, [%o1]
  61. add %sp, 23*4, %o0
  62. sethi %hi(operatingsystem_parameter_argv),%o1
  63. or %o1,%lo(operatingsystem_parameter_argv),%o1
  64. .ifdef PIC
  65. ld [%o1+%l7],%o1
  66. .endif
  67. st %o0, [%o1]
  68. /* envp=(argc+1)*4+argv */
  69. inc %o2
  70. sll %o2, 2, %o2
  71. add %o2, %o0, %o2
  72. sethi %hi(operatingsystem_parameter_envp),%o1
  73. or %o1,%lo(operatingsystem_parameter_envp),%o1
  74. .ifdef PIC
  75. ld [%o1+%l7],%o1
  76. .endif
  77. st %o2, [%o1]
  78. /* Save initial stackpointer */
  79. sethi %hi(__stkptr),%o1
  80. or %o1,%lo(__stkptr),%o1
  81. .ifdef PIC
  82. ld [%o1+%l7],%o1
  83. .endif
  84. st %sp, [%o1]
  85. /* Call the user program entry point. */
  86. call PASCALMAIN
  87. nop
  88. /* Die very horribly if main returns. */
  89. unimp
  90. .size _start, .-_start
  91. .globl _haltproc
  92. .type _haltproc,@function
  93. _haltproc:
  94. save %o6,-96,%o6
  95. .ifdef PIC
  96. call 1f
  97. sethi %hi(_GLOBAL_OFFSET_TABLE_+4),%l7
  98. 1: or %l7,%lo(_GLOBAL_OFFSET_TABLE_+8),%l7
  99. add %l7,%o7,%l7
  100. .endif
  101. mov %i0,%l0
  102. sethi %hi(__dl_fini),%o0
  103. or %o0,%lo(__dl_fini),%o0
  104. .ifdef PIC
  105. ld [%o0+%l7],%o0
  106. .endif
  107. ld [%o0],%o0
  108. subcc %o0,%g0,%g0
  109. beq 2f
  110. nop
  111. call %o0
  112. nop
  113. 2:
  114. mov %i0,%o0 /* i0 contains the exitcode */
  115. mov 188, %g1 /* "exit_group" system call */
  116. ta 0x10 /* do the system call */
  117. unimp /* Die very horribly if exit returns. */
  118. .size _haltproc,.-_haltproc
  119. .comm __stkptr,4
  120. .comm __dl_fini,4
  121. .comm operatingsystem_parameter_envp,4
  122. .comm operatingsystem_parameter_argc,4
  123. .comm operatingsystem_parameter_argv,4
  124. .section .note.GNU-stack,"",@progbits