dllprt0.as 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. Start-up code for Free Pascal Compiler in a shared library,
  3. not linking with C library.
  4. */
  5. .text
  6. .align 2
  7. .globl _startlib
  8. .type _startlib,#function
  9. _startlib:
  10. .globl FPC_SHARED_LIB_START
  11. .type FPC_SHARED_LIB_START,#function
  12. FPC_SHARED_LIB_START:
  13. stp x29,x30,[sp,#-16]!
  14. /* Get argc, argv, envp */
  15. ldr x1,[x0]
  16. add x2,x0,#8
  17. add x3,x1,#1
  18. add x3,x2,x3,lsl #3
  19. /* Save argc, argv and envp */
  20. adrp x9,:got:operatingsystem_parameter_argc
  21. ldr x9,[x9,#:got_lo12:operatingsystem_parameter_argc]
  22. str x1,[x9]
  23. adrp x9,:got:operatingsystem_parameter_argv
  24. ldr x9,[x9,#:got_lo12:operatingsystem_parameter_argv]
  25. str x2,[x9]
  26. adrp x9,:got:operatingsystem_parameter_envp
  27. ldr x9,[x9,#:got_lo12:operatingsystem_parameter_envp]
  28. str x3,[x9]
  29. /* save environ */
  30. adrp x10,environ
  31. ldr x10,[x10,:lo12:environ]
  32. cbnz x10,.LBB0_2
  33. adrp x10,environ
  34. add x10,x9,:lo12:environ
  35. str x3,[x10]
  36. .LBB0_2:
  37. /* save __progname */
  38. adrp x8,:got:operatingsystem_parameter_argc
  39. ldr x8,[x8,#:got_lo12:operatingsystem_parameter_argc]
  40. cmp x8,#0
  41. cset x8,le
  42. tbnz x8,#0,.LBB0_9
  43. // %bb.1:
  44. adrp x8,operatingsystem_parameter_argv
  45. ldr x8,[x8,:got_lo12:operatingsystem_parameter_argv]
  46. cbz x8,.LBB0_9
  47. // %bb.2:
  48. ldr x2,[x2]
  49. adrp x9,:got:__progname
  50. adrp x10,:got:__progname
  51. add x10,x10,:lo12:__progname
  52. str x2,[x10]
  53. ldr x8,[x9,:got_lo12:__progname]
  54. adrp x9,s
  55. add x9,x9,:lo12:s
  56. str x8,[x9]
  57. .LBB0_3:
  58. adrp x8,s
  59. ldr x8,[x8,:lo12:s]
  60. ldrb w9,[x8]
  61. cbz w9,.LBB0_8
  62. // %bb.4:
  63. adrp x8,s
  64. ldr x8,[x8, :lo12:s]
  65. ldrb w9,[x8]
  66. cmp w9,#47
  67. b.ne .LBB0_6
  68. // %bb.5:
  69. adrp x8,s
  70. ldr x8,[x8,:lo12:s]
  71. add x8,x8,#1
  72. adrp x9,:got:__progname
  73. add x9,x9,:lo12:__progname
  74. str x8,[x9]
  75. .LBB0_6:
  76. // %bb.7:
  77. adrp x8,s
  78. adrp x9,s
  79. add x9,x9,:lo12:s
  80. ldr x8,[x8,:lo12:s]
  81. add x8,x8,#1
  82. str x8,[x9]
  83. b .LBB0_3
  84. .LBB0_8:
  85. .LBB0_9:
  86. /* Save initial stackpointer */
  87. adrp x9,:got:__stkptr
  88. ldr x9,[x9,#:got_lo12:__stkptr]
  89. mov x10,sp
  90. str x10,[x9]
  91. /* Call main */
  92. bl PASCALMAIN
  93. /* Return */
  94. ldp x29,x30,[sp],#16
  95. ret
  96. .globl _haltproc
  97. .type _haltproc,#function
  98. _haltproc:
  99. adrp x0,:got:operatingsystem_result
  100. ldr x0,[x0,#:got_lo12:operatingsystem_result]
  101. ldr w0,[x0]
  102. mov w8,#1 // SYS_exit
  103. svc #0
  104. b _haltproc
  105. /* Define a symbol for the first piece of initialized data. */
  106. .data
  107. .align 3
  108. .globl __data_start
  109. __data_start:
  110. .long 0
  111. .weak data_start
  112. data_start = __data_start
  113. .bss
  114. .align 3
  115. .comm __stkptr,8
  116. .comm operatingsystem_parameter_envp,8
  117. .comm operatingsystem_parameter_argc,8
  118. .comm operatingsystem_parameter_argv,8
  119. .comm environ,8,8
  120. s:
  121. .xword 0
  122. .size s, 8
  123. .section .note.GNU-stack,"",%progbits