prt0.as 2.5 KB

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