dllprt0.as 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. .ent _dynamic_start
  16. .type _dynamic_start,@function
  17. _dynamic_start:
  18. .set noreorder
  19. .cpload $25
  20. /* TODO: check whether this code is correct */
  21. la $v0,__dl_fini
  22. lw $v0,($v0)
  23. lw $v1,%call16(_start)($gp)
  24. move $t9,$v1
  25. jalr $t9
  26. nop
  27. .end _dynamic_start
  28. .size _dynamic_start, .-_dynamic_start
  29. .align 4
  30. .global _start
  31. .set nomips16
  32. .ent _start
  33. .type _start,@function
  34. /* This is the canonical entry point, usually the first thing in the text
  35. segment. The SVR4/Mips ABI (pages 3-31, 3-32) says that when the entry
  36. point runs, most registers' values are unspecified, except for:
  37. v0 ($2) Function pointer of a function to be executed at exit
  38. sp ($29) The stack contains the arguments and environment:
  39. 0(%sp) argc
  40. 4(%sp) argv[0]
  41. ...
  42. (4*argc)(%sp) NULL
  43. (4*(argc+1))(%sp) envp[0]
  44. ...
  45. NULL
  46. ra ($31) Return address set to zero.
  47. */
  48. _start:
  49. /* load fp */
  50. .set noreorder
  51. .cpload $25
  52. addiu $sp,$sp,-32
  53. move $s8,$sp
  54. .cprestore 16
  55. la $t1,__stkptr
  56. sw $s8,($t1)
  57. /* align stack */
  58. li $at,-8
  59. and $sp,$sp,$at
  60. addiu $sp,$sp,-32
  61. lui $s7,0x3d
  62. addiu $s7,$s7,2304
  63. li $at,-8
  64. and $s7,$s7,$at
  65. addiu $s7,$s7,-32
  66. /* store argc */
  67. lw $a0,0($s8)
  68. la $a1,operatingsystem_parameter_argc
  69. sw $a0,($a1)
  70. /* store argv */
  71. addiu $a1,$s8,4
  72. la $a2,operatingsystem_parameter_argv
  73. sw $a1,($a2)
  74. /* store envp */
  75. addiu $a2,$a0,1
  76. sll $a2,$a2,0x2
  77. addu $a2,$a2,$a1
  78. la $a3,operatingsystem_parameter_envp
  79. sw $a2,($a3)
  80. la $t9,PASCALMAIN
  81. jalr $t9
  82. nop
  83. b _haltproc
  84. nop
  85. .end _start
  86. .size _start, .-_start
  87. .globl _haltproc
  88. .ent _haltproc
  89. .type _haltproc,@function
  90. _haltproc:
  91. /* TODO: need to check whether __dl_fini is non-zero and call the function pointer in case */
  92. li $v0,4001
  93. syscall
  94. b _haltproc
  95. nop
  96. .end _haltproc
  97. .size _haltproc, .-_haltproc
  98. .comm __stkptr,4
  99. .comm __dl_fini,4
  100. .comm operatingsystem_parameter_envp,4
  101. .comm operatingsystem_parameter_argc,4
  102. .comm operatingsystem_parameter_argv,4