prt0.as 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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
  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. .type _dynamic_start,@function
  16. _dynamic_start:
  17. /* TODO: check whether this code is correct */
  18. lui $a2,%hi(__dl_fini)
  19. sw $v0,%lo(__dl_fini)($a2)
  20. b _start
  21. .align 4
  22. .global _start
  23. .type _start,@function
  24. /* This is the canonical entry point, usually the first thing in the text
  25. segment. The SVR4/Mips ABI (pages 3-31, 3-32) says that when the entry
  26. point runs, most registers' values are unspecified, except for:
  27. v0 ($2) Contains a function pointer to be registered with `atexit'.
  28. This is how the dynamic linker arranges to have DT_FINI
  29. functions called for shared libraries that have been loaded
  30. before this code runs.
  31. sp ($29) The stack contains the arguments and environment:
  32. 0(%esp) argc
  33. 4(%esp) argv[0]
  34. ...
  35. (4*argc)(%esp) NULL
  36. (4*(argc+1))(%esp) envp[0]
  37. ...
  38. NULL
  39. ra ($31) The return address register is set to zero so that programs
  40. that search backword through stack frames recognize the last
  41. stack frame.
  42. _start:
  43. /* load fp */
  44. move $s8,$sp
  45. /* align stack */
  46. li $at,-8
  47. and $sp,$sp,$at
  48. addiu $sp,$sp,-32
  49. lui $s7,0x3d
  50. addiu $s7,$s7,2304
  51. li $at,-8
  52. and $s7,$s7,$at
  53. addiu $s7,$s7,-32
  54. /* store argc */
  55. lw $a0,0($s8)
  56. lui $a1,%hi(operatingsystem_parameter_argc)
  57. sw $a0,%lo(operatingsystem_parameter_argc)($a1)
  58. /* store argv */
  59. addiu $a1,$s8,4
  60. lui $a2,%hi(operatingsystem_parameter_argv)
  61. sw $a1,%lo(operatingsystem_parameter_argv)($a2)
  62. /* store envp */
  63. addiu $a2,$a0,1
  64. sll $a2,$a2,0x2
  65. addu $a2,$a2,$a1
  66. lui $a3,$hi(operatingsystem_parameter_envp)
  67. jal PASCALMAIN
  68. sw $a2,%lo(operatingsystem_parameter_envp)($a3)
  69. nop
  70. .globl _haltproc
  71. .type _haltproc,@function
  72. _haltproc:
  73. /* TODO: need to check whether __dl_fini is non-zero and call the function pointer in case */
  74. li $v0,4001
  75. lui $a0,0x0
  76. lw $a0,0($a0)
  77. syscall
  78. b _haltproc
  79. nop
  80. .size _start, .-_start
  81. .comm __stkptr,4
  82. .comm __dl_fini,4
  83. .comm operatingsystem_parameter_envp,4
  84. .comm operatingsystem_parameter_argc,4
  85. .comm operatingsystem_parameter_argv,4