dllprt0.as 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2009 by Michael Van Canneyt and David Zhang
  4. Startup code for elf32-mipsel/elf32-mips
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. */
  11. .set noat
  12. .section ".text"
  13. .align 4
  14. .global _dynamic_start
  15. .global FPC_SHARED_LIB_START
  16. .type _dynamic_start,@function
  17. .type FPC_SHARED_LIB_START,@function
  18. FPC_SHARED_LIB_START:
  19. _dynamic_start:
  20. .ent _dynamic_start
  21. .set noreorder
  22. .cpload $25
  23. /* TODO: check whether this code is correct */
  24. la $v0,__dl_fini
  25. lw $v0,($v0)
  26. la $t9,_start
  27. jr $t9
  28. nop
  29. .end _dynamic_start
  30. .size _dynamic_start, .-_dynamic_start
  31. .align 4
  32. .global _start
  33. .set nomips16
  34. .type _start,@function
  35. /* This is the canonical entry point, usually the first thing in the text
  36. segment. The SVR4/Mips ABI (pages 3-31, 3-32) says that when the entry
  37. point runs, most registers' values are unspecified, except for:
  38. v0 ($2) Function pointer of a function to be executed at exit
  39. sp ($29) The stack contains the arguments and environment:
  40. 0(%sp) argc
  41. 4(%sp) argv[0]
  42. ...
  43. (4*argc)(%sp) NULL
  44. (4*(argc+1))(%sp) envp[0]
  45. ...
  46. NULL
  47. ra ($31) Return address set to zero.
  48. */
  49. _start:
  50. .ent _start
  51. .frame $sp,40,$ra
  52. /* load fp */
  53. .set noreorder
  54. .cpload $25
  55. /* Record $sp into $t1,
  56. to cope with unknown alignment value. */
  57. move $t1,$sp
  58. /* align stack */
  59. li $at,-8
  60. and $sp,$sp,$at
  61. addiu $sp,$sp,-40
  62. /* Save needed regs:
  63. $t1, at offset 20
  64. $gp ($28), at offset 24
  65. $s8 ($30), at offset 28
  66. $ra ($31), at offset 32
  67. */
  68. /* Compute and save sp offset */
  69. subu $t1,$t1,$sp
  70. sw $t1,20($sp)
  71. /* Save $gp register */
  72. .cprestore 24
  73. /* Save previous $s8 at offset 28 */
  74. sw $s8,28($sp)
  75. /* Save $ra register */
  76. sw $ra,32($sp)
  77. /* Set __stkptr variable */
  78. move $s8,$sp
  79. la $t1,__stkptr
  80. sw $s8,($t1)
  81. /* store argc, which is in $a0 */
  82. lw $a0,0($s8)
  83. la $t1,operatingsystem_parameter_argc
  84. sw $a0,($t1)
  85. /* store argv which is in $a1 */
  86. addiu $a1,$s8,4
  87. la $t1,operatingsystem_parameter_argv
  88. sw $a1,($t1)
  89. /* store envp which is in $a2 */
  90. la $t1,operatingsystem_parameter_envp
  91. sw $a2,($t1)
  92. /* Set IsLibrary to one */
  93. la $t1,operatingsystem_islibrary
  94. li $t2,1
  95. sb $t2,($t1)
  96. /* Jump to PASCALMAIN */
  97. la $t9,PASCALMAIN
  98. jal $t9
  99. nop
  100. /* Restore $ra */
  101. lw $ra,32($sp)
  102. /* Restore $s8 */
  103. lw $s8,28($sp)
  104. /* Restore old $sp */
  105. lw $t1,20($sp)
  106. addu $sp,$sp,$t1
  107. /* Return to caller */
  108. jr $ra
  109. nop
  110. .end _start
  111. .size _start, .-_start
  112. .globl _haltproc
  113. .ent _haltproc
  114. .type _haltproc,@function
  115. _haltproc:
  116. /* TODO: need to check whether __dl_fini is non-zero and call the function pointer in case */
  117. li $v0,4001
  118. syscall
  119. b _haltproc
  120. nop
  121. .end _haltproc
  122. .size _haltproc, .-_haltproc
  123. .comm __stkptr,4
  124. .comm __dl_fini,4
  125. .comm operatingsystem_parameter_envp,4
  126. .comm operatingsystem_parameter_argc,4
  127. .comm operatingsystem_parameter_argv,4
  128. .section .note.GNU-stack,"",@progbits