crt1.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Copyright (C) 1995-2016 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /* This is the canonical entry point, usually the first thing in the text
  15. segment.
  16. Note that the code in the .init section has already been run.
  17. This includes _init and _libc_init
  18. At this entry point, most registers' values are unspecified, except:
  19. x0 Contains a function pointer to be registered with `atexit'.
  20. This is how the dynamic linker arranges to have DT_FINI
  21. functions called for shared libraries that have been loaded
  22. before this code runs.
  23. sp The stack contains the arguments and environment:
  24. 0(sp) argc
  25. 8(sp) argv[0]
  26. ...
  27. (8*argc)(sp) NULL
  28. (8*(argc+1))(sp) envp[0]
  29. ...
  30. NULL
  31. */
  32. .text
  33. .globl _start
  34. .type _start,#function
  35. _start:
  36. /* Create an initial frame with 0 LR and FP */
  37. mov x29, #0
  38. mov x30, #0
  39. #ifdef L_rcrt1
  40. /* Save off the atexit pointer */
  41. mov x19, x0
  42. /* Calculate load address... idk how this works, but it does */
  43. adrp x0, _start
  44. /* Do relocations */
  45. bl reloc_static_pie
  46. /* restore atexit pointer */
  47. mov x0, x19
  48. #endif
  49. /* Setup _fini in argument register */
  50. mov x5, x0
  51. /* Load argc and a pointer to argv */
  52. ldr x1, [sp, #0]
  53. add x2, sp, #8
  54. /* Setup stack limit in argument register */
  55. mov x6, sp
  56. #ifdef __PIC__
  57. adrp x0, :got:main
  58. ldr x0, [x0, #:got_lo12:main]
  59. adrp x3, :got:_init
  60. ldr x3, [x3, #:got_lo12:_init]
  61. adrp x4, :got:_fini
  62. ldr x4, [x4, #:got_lo12:_fini]
  63. #else
  64. /* Set up the other arguments in registers */
  65. ldr x0, =main
  66. ldr x3, =_init
  67. ldr x4, =_fini
  68. #endif
  69. /* Let the libc call main and exit with its return code. */
  70. bl __uClibc_main
  71. /* should never get here....*/
  72. bl abort
  73. /* Define a symbol for the first piece of initialized data. */
  74. .data
  75. .globl __data_start
  76. __data_start:
  77. .long 0
  78. .weak data_start
  79. data_start = __data_start