prt0.as 2.9 KB

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