cprt0.as 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* Startup code for ARM & ELF
  2. Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002 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. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. /* This is the canonical entry point, usually the first thing in the text
  17. segment.
  18. Note that the code in the .init section has already been run.
  19. This includes _init and _libc_init
  20. At this entry point, most registers' values are unspecified, except:
  21. a0 Contains a function pointer to be registered with `atexit'.
  22. This is how the dynamic linker arranges to have DT_FINI
  23. functions called for shared libraries that have been loaded
  24. before this code runs.
  25. sp The stack contains the arguments and environment:
  26. 0(sp) argc
  27. 8(sp) argv[0]
  28. ...
  29. (8*argc)(sp) NULL
  30. (8*(argc+1))(sp) envp[0]
  31. ...
  32. NULL
  33. */
  34. .text
  35. .globl _start
  36. .type _start,function
  37. _start:
  38. .option push
  39. .option norelax
  40. 1:auipc gp, %pcrel_hi(__global_pointer$)
  41. addi gp, gp, %pcrel_lo(1b)
  42. .option pop
  43. /* Store rtld_fini in a5 */
  44. addi a5, a0, 0
  45. /* Clear the frame pointer since this is the outermost frame. */
  46. addi x8, x0, 0
  47. /* Pop argc off the stack, and save argc, argv and envp */
  48. ld a1, 0(sp)
  49. addi a2, sp, 8
  50. addi a4, a1, 1
  51. slli a4, a4, 3
  52. add a4, a2, a4
  53. 1:auipc x8,%pcrel_hi(operatingsystem_parameter_argc)
  54. sw a1,%pcrel_lo(1b)(x8)
  55. 1:auipc x8,%pcrel_hi(operatingsystem_parameter_argv)
  56. sd a2,%pcrel_lo(1b)(x8)
  57. 1:auipc x8,%pcrel_hi(operatingsystem_parameter_envp)
  58. sd a4,%pcrel_lo(1b)(x8)
  59. /* Save initial stackpointer */
  60. 1:auipc x8,%pcrel_hi(__stkptr)
  61. sd sp,%pcrel_lo(1b)(x8)
  62. /* Fetch address of fini */
  63. 1:auipc x8,%pcrel_hi(__libc_csu_fini)
  64. addi a4,x8,%pcrel_lo(1b)
  65. addi a6, sp, 0
  66. /* Set up the other arguments in registers */
  67. 1:auipc x8,%pcrel_hi(PASCALMAIN)
  68. addi a0, x8, %pcrel_lo(1b)
  69. 1:auipc x8,%pcrel_hi(__libc_csu_init)
  70. addi a3, x8, %pcrel_lo(1b)
  71. /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
  72. /* Let the libc call main and exit with its return code. */
  73. 1:auipc x8,%pcrel_hi(__libc_start_main)
  74. jalr ra, x8, %pcrel_lo(1b)
  75. /* should never get here....*/
  76. 1:auipc x8,%pcrel_hi(abort)
  77. jalr ra, x8, %pcrel_lo(1b)
  78. .globl _haltproc
  79. .type _haltproc,function
  80. _haltproc:
  81. 1:auipc x8,%pcrel_hi(operatingsystem_result)
  82. lbu x1,%pcrel_lo(1b)(x8)
  83. addi x17, x0, 94
  84. ecall
  85. jal x0, _haltproc
  86. /* Define a symbol for the first piece of initialized data. */
  87. .data
  88. .globl __data_start
  89. __data_start:
  90. .long 0
  91. .weak data_start
  92. data_start = __data_start
  93. .bss
  94. .comm __stkptr,8
  95. .comm operatingsystem_parameter_envp,8
  96. .comm operatingsystem_parameter_argc,4
  97. .comm operatingsystem_parameter_argv,8
  98. .section ".comment"
  99. .byte 0
  100. .ascii "generated by FPC http://www.freepascal.org\0"
  101. /* We need this stuff to make gdb behave itself, otherwise
  102. gdb will chokes with SIGILL when trying to debug apps.
  103. */
  104. .section ".note.ABI-tag", "a"
  105. .align 4
  106. .long 1f - 0f
  107. .long 3f - 2f
  108. .long 1
  109. 0: .asciz "GNU"
  110. 1: .align 4
  111. 2: .long 0
  112. .long 2,0,0
  113. 3: .align 4
  114. .section .note.GNU-stack,"",%progbits