si_dll.inc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2019 by Free Pascal development team
  4. This file implements parts of the startup code for OpenBSD
  5. shared object (.so) libraries.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program 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.
  11. **********************************************************************}
  12. {$asmmode gas}
  13. procedure _init; external name '_init';
  14. procedure _FPC_proc___start; forward;
  15. procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
  16. asm
  17. movq %rbx,%r9
  18. movq %rcx,%r8
  19. movq %rdx,%rcx
  20. movq (%rsp),%rdi
  21. leaq 16(%rsp,%rdi,8),%rdx
  22. leaq 8(%rsp),%rsi
  23. subq $8,%rsp
  24. andq $0xFFFFFFFFFFFFFFF0,%rsp
  25. addq $8,%rsp
  26. jmp _FPC_proc___start
  27. end;
  28. procedure _FPC_proc_haltproc; forward;
  29. function _strrchr(str: PChar; character: LongInt): PChar; forward;
  30. procedure _FPC_proc___start; assembler; nostackframe; public name '___start';
  31. asm
  32. pushq %rbp
  33. movq %rsp, %rbp
  34. subq $64, %rsp
  35. movl %edi, -20(%rbp)
  36. movq %rsi, -32(%rbp)
  37. movq %rdx, -40(%rbp)
  38. movq %rcx, -48(%rbp)
  39. movq %r8, -56(%rbp)
  40. movq %r9, -64(%rbp)
  41. movq environ@GOTPCREL(%rip), %rdx
  42. movq -40(%rbp), %rax
  43. movq %rax, (%rdx)
  44. movq operatingsystem_parameter_envp@GOTPCREL(%rip), %rdx
  45. movq -40(%rbp), %rax
  46. movq %rax, (%rdx)
  47. movl -20(%rbp), %eax
  48. movslq %eax,%rdx
  49. movq operatingsystem_parameter_argc@GOTPCREL(%rip), %rax
  50. movq %rdx, (%rax)
  51. movq operatingsystem_parameter_argv@GOTPCREL(%rip), %rdx
  52. movq -32(%rbp), %rax
  53. movq %rax, (%rdx)
  54. movq -32(%rbp), %rax
  55. movq (%rax), %rax
  56. movq %rax, -8(%rbp)
  57. cmpq $0, -8(%rbp)
  58. je .L2
  59. movq -8(%rbp), %rdi
  60. movl $47, %esi
  61. call _strrchr
  62. movq %rax, %rdx
  63. movq __progname@GOTPCREL(%rip), %rax
  64. movq %rdx, (%rax)
  65. movq __progname@GOTPCREL(%rip), %rax
  66. movq (%rax), %rax
  67. testq %rax, %rax
  68. jne .L4
  69. movq __progname@GOTPCREL(%rip), %rdx
  70. movq -8(%rbp), %rax
  71. movq %rax, (%rdx)
  72. jmp .L6
  73. .L4:
  74. movq __progname@GOTPCREL(%rip), %rax
  75. movq (%rax), %rax
  76. leaq 1(%rax), %rdx
  77. movq __progname@GOTPCREL(%rip), %rax
  78. movq %rdx, (%rax)
  79. .L6:
  80. movq __progname_storage@GOTPCREL(%rip), %rax
  81. movq %rax, -16(%rbp)
  82. jmp .L7
  83. .L8:
  84. movq __progname@GOTPCREL(%rip), %rax
  85. movq (%rax), %rcx
  86. movzbl (%rcx), %edx
  87. movq -16(%rbp), %rax
  88. movb %dl, (%rax)
  89. addq $1, -16(%rbp)
  90. leaq 1(%rcx), %rdx
  91. movq __progname@GOTPCREL(%rip), %rax
  92. movq %rdx, (%rax)
  93. .L7:
  94. movq __progname@GOTPCREL(%rip), %rax
  95. movq (%rax), %rax
  96. movzbl (%rax), %eax
  97. testb %al, %al
  98. je .L9
  99. movq __progname_storage@GOTPCREL(%rip), %rax
  100. leaq 255(%rax), %rax
  101. cmpq %rax, -16(%rbp)
  102. jb .L8
  103. .L9:
  104. movq -16(%rbp), %rax
  105. movb $0, (%rax)
  106. movq __progname@GOTPCREL(%rip), %rdx
  107. movq __progname_storage@GOTPCREL(%rip), %rax
  108. movq %rax, (%rdx)
  109. .L2:
  110. movl $0, %eax
  111. call _init@PLT
  112. movq environ@GOTPCREL(%rip), %rax
  113. movq (%rax), %rdx
  114. movq -32(%rbp), %rsi
  115. movl -20(%rbp), %edi
  116. movl $0, %eax
  117. call PASCALMAIN@PLT
  118. // movl %eax, %edi
  119. // call exit
  120. jmp _FPC_proc_haltproc@PLT
  121. end;
  122. procedure _FPC_proc_haltproc; assembler; nostackframe; public name '_haltproc';
  123. asm
  124. movq $1,%rax
  125. movl operatingsystem_result(%rip),%ebx
  126. pushq %rbx
  127. call .Lactualsyscall
  128. addq $8,%rsp
  129. jmp _FPC_proc_haltproc
  130. .Lactualsyscall:
  131. int $0x80
  132. jb .LErrorcode
  133. xor %rbx,%rbx
  134. ret
  135. .LErrorcode:
  136. movq %rax,%rbx
  137. movq $-1,%rax
  138. end;
  139. function _strrchr(str: PChar; character: LongInt): PChar; assembler; nostackframe; public name '_strrchr';
  140. asm
  141. pushq %rbp
  142. movq %rsp, %rbp
  143. movq %rdi, -24(%rbp)
  144. movb %sil, -25(%rbp)
  145. movq $0, -8(%rbp)
  146. .L13:
  147. movq -24(%rbp), %rdx
  148. movzbl (%rdx), %eax
  149. cmpb -25(%rbp), %al
  150. jne .L14
  151. movq -24(%rbp), %rax
  152. movq %rax, -8(%rbp)
  153. .L14:
  154. movq -24(%rbp), %rdx
  155. movzbl (%rdx), %eax
  156. testb %al, %al
  157. jne .L16
  158. movq -8(%rbp), %rax
  159. movq %rax, -16(%rbp)
  160. jmp .L12
  161. .L16:
  162. addq $1, -24(%rbp)
  163. jmp .L13
  164. .L12:
  165. movq -16(%rbp), %rax
  166. leave
  167. end;