gprt0.as 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /* reload the addresses for C startup code */
  28. ld [%sp+22*4], %o1
  29. add %sp, 23*4, %o2
  30. /* Load the addresses of the user entry points. */
  31. sethi %hi(main_stub), %o0
  32. sethi %hi(_init), %o3
  33. sethi %hi(_fini), %o4
  34. or %o0, %lo(main_stub), %o0
  35. or %o3, %lo(_init), %o3
  36. or %o4, %lo(_fini), %o4
  37. /* When starting a binary via the dynamic linker, %g1 contains the
  38. address of the shared library termination function, which will be
  39. registered with atexit(). If we are statically linked, this will
  40. be NULL. */
  41. mov %g1, %o5
  42. /* Let libc do the rest of the initialization, and call main. */
  43. call __libc_start_main
  44. nop
  45. /* Die very horribly if exit returns. */
  46. unimp
  47. .size _start, .-_start
  48. main_stub:
  49. /* Initialize gmon */
  50. sethi %hi(_start), %o0
  51. sethi %hi(_etext), %o1
  52. or %o0, %lo(_start), %o0
  53. or %o1, %lo(_etext), %o1
  54. call monstartup
  55. nop
  56. sethi %hi(_mcleanup), %o0
  57. or %o0, %lo(_mcleanup), %o0
  58. call atexit
  59. nop
  60. /* start the program */
  61. call PASCALMAIN
  62. nop
  63. ba _haltproc
  64. nop
  65. .globl _haltproc
  66. .type _haltproc,@function
  67. _haltproc:
  68. mov 1, %g1 /* "exit" system call */
  69. sethi %hi(operatingsystem_result),%o0
  70. or %o0,%lo(operatingsystem_result),%o0
  71. ldsh [%o0], %o0 /* give exit status to parent process*/
  72. ta 0x10 /* dot the system call */
  73. nop /* delay slot */
  74. /* Die very horribly if exit returns. */
  75. unimp
  76. .data
  77. .comm ___fpc_brk_addr,4 /* heap management */
  78. .comm operatingsystem_parameter_envp,4
  79. .comm operatingsystem_parameter_argc,4
  80. .comm operatingsystem_parameter_argv,4