start.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* start, OpenRISC version.
  2. Copyright (C) 2022-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The GNU Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. Note that people who make modified versions of this file are not
  17. obligated to grant this special exception for their modified
  18. versions; it is their choice whether to do so. The GNU Lesser
  19. General Public License gives permission to release a modified
  20. version without this exception; this exception also makes it
  21. possible to release a modified version which carries forward this
  22. exception.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. /* This is the canonical entry point, usually the first thing in the text
  31. segment.
  32. sp The stack contains the arguments and environment:
  33. 0(sp) argc
  34. 4(sp) argv[0]
  35. ...
  36. (4*argc)(sp) NULL
  37. (4*(argc+1))(sp) envp[0]
  38. ...
  39. NULL
  40. */
  41. #define __ASSEMBLY__
  42. #include <sysdep.h>
  43. #include <entry.h>
  44. ENTRY (ENTRY_POINT)
  45. /* Setup Arguments to the __libc_start_main function. */
  46. /* Take values for argc and argv off the stack.
  47. These will be passed as arguments two and three to main
  48. and thus go in registers r4 and r5, respectively. */
  49. l.lwz r4, 0(r1)
  50. l.addi r5, r1, 4
  51. /* Pass in rtld_fini from dl-start.S. */
  52. l.or r8, r3, r3
  53. #ifdef PIC
  54. /* Obtain a pointer to .got in r16 */
  55. l.jal 0x8
  56. l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
  57. l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
  58. l.add r16, r16, r9
  59. /* Pass in the the main symbol. */
  60. l.lwz r3, got(main)(r16)
  61. #else
  62. /* Pass in the the main symbol. */
  63. l.movhi r3, hi(main)
  64. l.ori r3, r3, lo(main)
  65. #endif
  66. /* Used to be init and fini. */
  67. l.movhi r6, 0x0
  68. l.movhi r7, 0x0
  69. /* Push stack limit onto the stack.
  70. This provides the highest stack address to user code (as stack grows
  71. downwards.
  72. This is the seventh argument to __libc_start_main and thus needs to
  73. be passed on the stack. */
  74. l.sw -4(r1), r1
  75. /* Adjust stack to account for a total of 7 args (i.e. the last one is
  76. on the stack. */
  77. l.addi r1, r1, -4
  78. /* Clear the frame pointer and link register since this is the
  79. outermost frame. */
  80. l.movhi r2, 0x0
  81. l.movhi r9, 0x0
  82. /* Let the libc call main and exit with its return code. */
  83. #ifdef PIC
  84. l.j plt(__libc_start_main)
  85. #else
  86. l.j __libc_start_main
  87. #endif
  88. l.nop
  89. END (ENTRY_POINT)
  90. /* Define a symbol for the first piece of initialized data. */
  91. .data
  92. .globl __data_start
  93. __data_start:
  94. .long 0
  95. .weak data_start
  96. data_start = __data_start