prt0.as 3.3 KB

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