gprt0.as 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. .section ".text"
  2. .align 4
  3. .global _start
  4. .type _start,#function
  5. _start:
  6. /* Terminate the stack frame, and reserve space for functions to
  7. drop their arguments. */
  8. mov %g0, %fp
  9. sub %sp, 6*4, %sp
  10. /* Extract the arguments and environment as encoded on the stack. The
  11. argument info starts after one register window (16 words) past the SP. */
  12. ld [%sp+22*4], %o2
  13. sethi %hi(operatingsystem_parameter_argc),%o1
  14. or %o1,%lo(operatingsystem_parameter_argc),%o1
  15. st %o2, [%o1]
  16. add %sp, 23*4, %o0
  17. sethi %hi(operatingsystem_parameter_argv),%o1
  18. or %o1,%lo(operatingsystem_parameter_argv),%o1
  19. st %o0, [%o1]
  20. /* envp=(argc+1)*4+argv */
  21. inc %o2
  22. sll %o2, 2, %o2
  23. add %o2, %o0, %o2
  24. sethi %hi(operatingsystem_parameter_envp),%o1
  25. or %o1,%lo(operatingsystem_parameter_envp),%o1
  26. st %o2, [%o1]
  27. /* Save initial stackpointer */
  28. sethi %hi(__stkptr),%o1
  29. or %o1,%lo(__stkptr),%o1
  30. st %sp, [%o1]
  31. /* reload the addresses for C startup code */
  32. ld [%sp+22*4], %o1
  33. add %sp, 23*4, %o2
  34. /* Load the addresses of the user entry points. */
  35. sethi %hi(main_stub), %o0
  36. sethi %hi(_init), %o3
  37. sethi %hi(_fini), %o4
  38. or %o0, %lo(main_stub), %o0
  39. or %o3, %lo(_init), %o3
  40. or %o4, %lo(_fini), %o4
  41. /* When starting a binary via the dynamic linker, %g1 contains the
  42. address of the shared library termination function, which will be
  43. registered with atexit(). If we are statically linked, this will
  44. be NULL. */
  45. mov %g1, %o5
  46. /* Let libc do the rest of the initialization, and call main. */
  47. call __libc_start_main
  48. nop
  49. /* Die very horribly if exit returns. */
  50. unimp
  51. .size _start, .-_start
  52. main_stub:
  53. /* Initialize gmon */
  54. sethi %hi(_start), %o0
  55. sethi %hi(_etext), %o1
  56. or %o0, %lo(_start), %o0
  57. or %o1, %lo(_etext), %o1
  58. call monstartup
  59. nop
  60. sethi %hi(_mcleanup), %o0
  61. or %o0, %lo(_mcleanup), %o0
  62. call atexit
  63. nop
  64. /* start the program */
  65. call PASCALMAIN
  66. nop
  67. ba _haltproc
  68. nop
  69. .globl _haltproc
  70. .type _haltproc,@function
  71. _haltproc:
  72. mov 188, %g1 /* "exit" system call */
  73. ta 0x10 /* dot the system call */
  74. nop /* delay slot */
  75. /* Die very horribly if exit returns. */
  76. unimp
  77. .data
  78. .comm __stkptr,4
  79. .comm operatingsystem_parameter_envp,4
  80. .comm operatingsystem_parameter_argc,4
  81. .comm operatingsystem_parameter_argv,4