crt1.S 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /* Setup _fini in argument register */
  40. mov x5, x0
  41. /* Load argc and a pointer to argv */
  42. ldr x1, [sp, #0]
  43. add x2, sp, #8
  44. /* Setup stack limit in argument register */
  45. mov x6, sp
  46. #ifdef __PIC__
  47. adrp x0, :got:main
  48. ldr x0, [x0, #:got_lo12:main]
  49. adrp x3, :got:_init
  50. ldr x3, [x3, #:got_lo12:_init]
  51. adrp x4, :got:_fini
  52. ldr x4, [x4, #:got_lo12:_fini]
  53. #else
  54. /* Set up the other arguments in registers */
  55. ldr x0, =main
  56. ldr x3, =_init
  57. ldr x4, =_fini
  58. #endif
  59. /* Let the libc call main and exit with its return code. */
  60. bl __uClibc_main
  61. /* should never get here....*/
  62. bl abort
  63. /* Define a symbol for the first piece of initialized data. */
  64. .data
  65. .globl __data_start
  66. __data_start:
  67. .long 0
  68. .weak data_start
  69. data_start = __data_start