cprt0.as 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. #
  2. # $Id: cprt0.as,v 1.2 2004/01/04 01:13:23 marco Exp $
  3. # This file is part of the Free Pascal run time library.
  4. # Copyright (c) 1999-2000 by Marco van de Voort, Michael Van Canneyt
  5. # and Peter Vreman
  6. # members of the Free Pascal development team.
  7. #
  8. # See the file COPYING.FPC, included in this distribution,
  9. # for details about the copyright.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY;without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. #
  15. #**********************************************************************}
  16. #
  17. # NetBSD standard (shared) ELF/i386 startup code for Free Pascal
  18. #
  19. .file "crt0.c"
  20. .version "01.01"
  21. gcc2_compiled.:
  22. .globl __progname
  23. .section .rodata
  24. .LC0:
  25. .ascii "\0"
  26. .data
  27. .align 4
  28. .type __progname,@object
  29. .size __progname,4
  30. __progname:
  31. .long .LC0
  32. .globl __ps_strings
  33. .align 4
  34. .type __ps_strings,@object
  35. .size __ps_strings,4
  36. __ps_strings:
  37. .long 0
  38. .align 4
  39. ___fpucw:
  40. .long 0x1332
  41. .globl ___fpc_brk_addr /* heap management */
  42. .type ___fpc_brk_addr,@object
  43. .size ___fpc_brk_addr,4
  44. ___fpc_brk_addr:
  45. .long 0
  46. #APP
  47. .weak _DYNAMIC
  48. .text
  49. .align 4
  50. .globl __start
  51. .globl _start
  52. _start:
  53. __start:
  54. pushl %ebx # ps_strings
  55. pushl %ecx # obj
  56. pushl %edx # cleanup
  57. movl 12(%esp),%eax
  58. leal 20(%esp,%eax,4),%ecx
  59. leal 16(%esp),%edx
  60. pushl %ecx
  61. pushl %edx
  62. pushl %eax
  63. movl %eax,U_SYSTEM_ARGC
  64. movl %edx,U_SYSTEM_ARGV
  65. call ___start
  66. #NO_APP
  67. .text
  68. .align 4
  69. .globl ___start
  70. .type ___start,@function
  71. ___start:
  72. pushl %ebp
  73. movl %esp,%ebp
  74. pushl %edi
  75. pushl %esi
  76. pushl %ebx
  77. call .L12
  78. .L12:
  79. popl %ebx
  80. addl $_GLOBAL_OFFSET_TABLE_+[.-.L12],%ebx
  81. movl 12(%ebp),%esi
  82. movl 16(%ebp),%edx
  83. movl 28(%ebp),%edi
  84. movl environ@GOT(%ebx),%eax
  85. movl %edx,(%eax)
  86. movl %edx,U_SYSTEM_ENVP
  87. movl __progname@GOT(%ebx),%edx
  88. movl (%esi),%eax
  89. movl %eax,(%edx)
  90. testl %eax,%eax
  91. je .L6
  92. pushl $47
  93. movl __progname@GOT(%ebx),%eax
  94. pushl (%eax)
  95. call _strrchr@PLT
  96. movl %eax,%edx
  97. movl __progname@GOT(%ebx),%eax
  98. movl %edx,(%eax)
  99. addl $8,%esp
  100. testl %edx,%edx
  101. jne .L7
  102. movl __progname@GOT(%ebx),%edx
  103. movl (%esi),%eax
  104. movl %eax,(%edx)
  105. jmp .L6
  106. .align 4
  107. .L7:
  108. movl __progname@GOT(%ebx),%eax
  109. incl %edx
  110. movl %edx,(%eax)
  111. .L6:
  112. testl %edi,%edi
  113. je .L9
  114. movl __ps_strings@GOT(%ebx),%eax
  115. movl %edi,(%eax)
  116. .L9:
  117. cmpl $0,_DYNAMIC@GOT(%ebx)
  118. je .L10
  119. pushl 24(%ebp)
  120. pushl 20(%ebp)
  121. call _rtld_setup@PLT
  122. addl $8,%esp
  123. .L10:
  124. pushl _fini@GOT(%ebx)
  125. call atexit@PLT
  126. call _init@PLT
  127. # movl environ@GOT(%ebx),%eax
  128. # pushl (%eax)
  129. # pushl %esi
  130. # pushl 8(%ebp)
  131. # call main@PLT
  132. finit /* initialize fpu */
  133. fwait
  134. fldcw ___fpucw
  135. // xorl %ebp,%ebp /* Detect main from nested */
  136. /* procs/unwinding? */
  137. pushl (%eax)
  138. pushl (%esi)
  139. pushl 8(%ebp)
  140. call main
  141. pushl %eax
  142. pushl %eax
  143. call exit@PLT
  144. .p2align 2,0x90
  145. .globl _haltproc
  146. .type _haltproc,@function
  147. _haltproc:
  148. mov $1,%eax
  149. movzwl U_SYSTEM_EXITCODE,%ebx
  150. pushl %ebx
  151. call _actualsyscall
  152. addl $4,%esp
  153. jmp _haltproc
  154. _actualsyscall:
  155. int $0x80
  156. jb .LErrorcode
  157. xor %ebx,%ebx
  158. ret
  159. .LErrorcode:
  160. mov %eax,%ebx
  161. mov $-1,%eax
  162. ret
  163. .p2align 2,0x90
  164. .Lfe1:
  165. .size ___start,.Lfe1-___start
  166. .align 4
  167. .type _strrchr,@function
  168. _strrchr:
  169. pushl %ebp
  170. movl %esp,%ebp
  171. subl $4,%esp
  172. pushl %esi
  173. movl 8(%ebp),%eax
  174. movb 12(%ebp),%cl
  175. movb %cl,-1(%ebp)
  176. xorl %esi,%esi
  177. .align 4
  178. .L14:
  179. movb (%eax),%dl
  180. cmpb -1(%ebp),%dl
  181. jne .L17
  182. movl %eax,%esi
  183. .L17:
  184. testb %dl,%dl
  185. je .L16
  186. incl %eax
  187. jmp .L14
  188. .align 4
  189. .L16:
  190. movl %esi,%eax
  191. movl -8(%ebp),%esi
  192. leave
  193. ret
  194. .Lfe2:
  195. .size _strrchr,.Lfe2-_strrchr
  196. .section .rodata
  197. .align 32
  198. .LC1:
  199. .ascii "Corrupt Obj_Entry pointer in GOT\0"
  200. .align 32
  201. .LC2:
  202. .ascii "Dynamic linker version mismatch\0"
  203. .text
  204. .align 4
  205. .globl _rtld_setup
  206. .type _rtld_setup,@function
  207. _rtld_setup:
  208. pushl %ebp
  209. movl %esp,%ebp
  210. pushl %esi
  211. pushl %ebx
  212. call .L35
  213. .L35:
  214. popl %ebx
  215. addl $_GLOBAL_OFFSET_TABLE_+[.-.L35],%ebx
  216. movl 12(%ebp),%esi
  217. testl %esi,%esi
  218. je .L22
  219. cmpl $-716130182,(%esi)
  220. je .L21
  221. .L22:
  222. pushl $33
  223. leal .LC1@GOTOFF(%ebx),%eax
  224. pushl %eax
  225. pushl $2
  226. pushl $4
  227. call __syscall@PLT
  228. pushl $1
  229. pushl $1
  230. call __syscall@PLT
  231. addl $24,%esp
  232. .align 4
  233. .L21:
  234. cmpl $1,4(%esi)
  235. je .L28
  236. pushl $32
  237. leal .LC2@GOTOFF(%ebx),%eax
  238. pushl %eax
  239. pushl $2
  240. pushl $4
  241. call __syscall@PLT
  242. pushl $1
  243. pushl $1
  244. call __syscall@PLT
  245. addl $24,%esp
  246. .align 4
  247. .L28:
  248. pushl 8(%ebp)
  249. call atexit@PLT
  250. leal -8(%ebp),%esp
  251. popl %ebx
  252. popl %esi
  253. leave
  254. ret
  255. .Lfe3:
  256. .size _rtld_setup,.Lfe3-_rtld_setup
  257. #APP
  258. .weak dlopen ; dlopen = _dlopen
  259. .weak dlclose ; dlclose = _dlclose
  260. .weak dlsym ; dlsym = _dlsym
  261. .weak dlerror ; dlerror = _dlerror
  262. .weak dladdr ; dladdr = _dladdr
  263. #NO_APP
  264. .align 4
  265. .globl _dlopen
  266. .type _dlopen,@function
  267. _dlopen:
  268. pushl %ebp
  269. movl %esp,%ebp
  270. pushl %ebx
  271. call .L40
  272. .L40:
  273. popl %ebx
  274. addl $_GLOBAL_OFFSET_TABLE_+[.-.L40],%ebx
  275. movl __mainprog_obj@GOT(%ebx),%eax
  276. movl (%eax),%eax
  277. testl %eax,%eax
  278. je .L37
  279. pushl 12(%ebp)
  280. pushl 8(%ebp)
  281. movl 80(%eax),%eax
  282. call *%eax
  283. jmp .L38
  284. .align 4
  285. .L37:
  286. xorl %eax,%eax
  287. .L38:
  288. movl -4(%ebp),%ebx
  289. leave
  290. ret
  291. .Lfe4:
  292. .size _dlopen,.Lfe4-_dlopen
  293. .align 4
  294. .globl _dlclose
  295. .type _dlclose,@function
  296. _dlclose:
  297. pushl %ebp
  298. movl %esp,%ebp
  299. pushl %ebx
  300. call .L45
  301. .L45:
  302. popl %ebx
  303. addl $_GLOBAL_OFFSET_TABLE_+[.-.L45],%ebx
  304. movl __mainprog_obj@GOT(%ebx),%eax
  305. movl (%eax),%eax
  306. testl %eax,%eax
  307. je .L42
  308. pushl 8(%ebp)
  309. movl 92(%eax),%eax
  310. call *%eax
  311. jmp .L43
  312. .align 4
  313. .L42:
  314. movl $-1,%eax
  315. .L43:
  316. movl -4(%ebp),%ebx
  317. leave
  318. ret
  319. .Lfe5:
  320. .size _dlclose,.Lfe5-_dlclose
  321. .align 4
  322. .globl _dlsym
  323. .type _dlsym,@function
  324. _dlsym:
  325. pushl %ebp
  326. movl %esp,%ebp
  327. pushl %ebx
  328. call .L50
  329. .L50:
  330. popl %ebx
  331. addl $_GLOBAL_OFFSET_TABLE_+[.-.L50],%ebx
  332. movl __mainprog_obj@GOT(%ebx),%eax
  333. movl (%eax),%eax
  334. testl %eax,%eax
  335. je .L47
  336. pushl 12(%ebp)
  337. pushl 8(%ebp)
  338. movl 84(%eax),%eax
  339. call *%eax
  340. jmp .L48
  341. .align 4
  342. .L47:
  343. xorl %eax,%eax
  344. .L48:
  345. movl -4(%ebp),%ebx
  346. leave
  347. ret
  348. .Lfe6:
  349. .size _dlsym,.Lfe6-_dlsym
  350. .section .rodata
  351. .align 32
  352. .LC3:
  353. .ascii "Dynamic linker interface not available\0"
  354. .text
  355. .align 4
  356. .globl _dlerror
  357. .type _dlerror,@function
  358. _dlerror:
  359. pushl %ebp
  360. movl %esp,%ebp
  361. pushl %ebx
  362. call .L55
  363. .L55:
  364. popl %ebx
  365. addl $_GLOBAL_OFFSET_TABLE_+[.-.L55],%ebx
  366. movl __mainprog_obj@GOT(%ebx),%eax
  367. movl (%eax),%eax
  368. testl %eax,%eax
  369. je .L52
  370. movl 88(%eax),%eax
  371. call *%eax
  372. jmp .L53
  373. .align 4
  374. .L52:
  375. leal .LC3@GOTOFF(%ebx),%eax
  376. .L53:
  377. movl -4(%ebp),%ebx
  378. leave
  379. ret
  380. .Lfe7:
  381. .size _dlerror,.Lfe7-_dlerror
  382. .align 4
  383. .globl _dladdr
  384. .type _dladdr,@function
  385. _dladdr:
  386. pushl %ebp
  387. movl %esp,%ebp
  388. pushl %ebx
  389. call .L60
  390. .L60:
  391. popl %ebx
  392. addl $_GLOBAL_OFFSET_TABLE_+[.-.L60],%ebx
  393. movl __mainprog_obj@GOT(%ebx),%eax
  394. movl (%eax),%eax
  395. testl %eax,%eax
  396. je .L57
  397. pushl 12(%ebp)
  398. pushl 8(%ebp)
  399. movl 96(%eax),%eax
  400. call *%eax
  401. jmp .L58
  402. .align 4
  403. .L57:
  404. movl $-1,%eax
  405. .L58:
  406. movl -4(%ebp),%ebx
  407. leave
  408. ret
  409. .Lfe8:
  410. .size _dladdr,.Lfe8-_dladdr
  411. .comm environ,4,4
  412. .comm __mainprog_obj,4,4
  413. # This section is needed for NetBSD to recognize a NetBSD binary as such.
  414. # otherwise it will be startup in Linux emulation mode.
  415. .section ".note.netbsd.ident","a"
  416. .p2align 2
  417. .long 7
  418. .long 4
  419. # ELF NOTE TYPE NETBSD TAG
  420. .long 1
  421. .ascii "NetBSD\0\0"
  422. .long 199905