cprt0.as 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. Start-up code for Free Pascal Compiler when linking with C library.
  3. Written by Edmund Grimley Evans in 2015 and released into the public domain.
  4. */
  5. .text
  6. .align 2
  7. .globl __libc_csu_init
  8. .type __libc_csu_init,#function
  9. .weak __libc_csu_init
  10. __libc_csu_init:
  11. ret
  12. .globl __libc_csu_fini
  13. .type __libc_csu_fini,#function
  14. .weak __libc_csu_fini
  15. __libc_csu_fini:
  16. ret
  17. .globl _start
  18. .type _start,#function
  19. _start:
  20. /* Initialise FP to zero */
  21. mov x29,#0
  22. /* This is rtld_fini */
  23. mov x5,x0
  24. /* Get argc, argv, envp */
  25. ldr x1,[sp]
  26. add x2,sp,#8
  27. add x11,x1,#1
  28. add x11,x2,x11,lsl #3
  29. /* Save argc, argv, envp, and initial stack pointer */
  30. adrp x10,:got:operatingsystem_parameter_argc
  31. ldr x10,[x10,#:got_lo12:operatingsystem_parameter_argc]
  32. str x1,[x10]
  33. adrp x10,:got:operatingsystem_parameter_argv
  34. ldr x10,[x10,#:got_lo12:operatingsystem_parameter_argv]
  35. str x2,[x10]
  36. adrp x10,:got:operatingsystem_parameter_envp
  37. ldr x10,[x10,#:got_lo12:operatingsystem_parameter_envp]
  38. str x11,[x10]
  39. adrp x10,:got:__stkptr
  40. ldr x10,[x10,#:got_lo12:__stkptr]
  41. mov x6,sp
  42. str x6,[x10]
  43. /* __libc_start_main(main, argc, argv,
  44. init, fini, rtld_fini, stack_end) */
  45. adrp x0,:got:PASCALMAIN
  46. ldr x0,[x0,#:got_lo12:PASCALMAIN]
  47. adrp x3,:got:__libc_csu_init
  48. ldr x3,[x3,#:got_lo12:__libc_csu_init]
  49. adrp x4,:got:__libc_csu_fini
  50. ldr x4,[x4,#:got_lo12:__libc_csu_fini]
  51. bl __libc_start_main
  52. /* This should never happen */
  53. b abort
  54. .globl _haltproc
  55. .type _haltproc,#function
  56. _haltproc:
  57. adrp x0,:got:operatingsystem_result
  58. ldr x0,[x0,#:got_lo12:operatingsystem_result]
  59. ldr w0,[x0]
  60. mov w8,#94 // syscall_nr_exit_group
  61. svc #0
  62. b _haltproc
  63. /* Define a symbol for the first piece of initialized data. */
  64. .data
  65. .align 3
  66. .globl __data_start
  67. __data_start:
  68. .long 0
  69. .weak data_start
  70. data_start = __data_start
  71. .bss
  72. .align 3
  73. .comm __stkptr,8
  74. .comm operatingsystem_parameter_envp,8
  75. .comm operatingsystem_parameter_argc,8
  76. .comm operatingsystem_parameter_argv,8
  77. .section .note.GNU-stack,"",%progbits