cprt0.as 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. .ifdef PIC
  11. /* Set %l7 to _GLOBAL_OFFSET_TABLE value */
  12. sethi %hi(_GLOBAL_OFFSET_TABLE_-8),%l7
  13. or %l7,%lo(_GLOBAL_OFFSET_TABLE_-4),%l7
  14. call FPC_GETGOT
  15. nop
  16. .endif
  17. /* Extract the arguments and environment as encoded on the stack. The
  18. argument info starts after one register window (16 words) past the SP. */
  19. ld [%sp+22*4], %o2
  20. sethi %hi(operatingsystem_parameter_argc),%o1
  21. or %o1,%lo(operatingsystem_parameter_argc),%o1
  22. .ifdef PIC
  23. ld [%o1+%l7],%o1
  24. .endif
  25. st %o2, [%o1]
  26. add %sp, 23*4, %o0
  27. sethi %hi(operatingsystem_parameter_argv),%o1
  28. or %o1,%lo(operatingsystem_parameter_argv),%o1
  29. .ifdef PIC
  30. ld [%o1+%l7],%o1
  31. .endif
  32. st %o0, [%o1]
  33. /* envp=(argc+1)*4+argv */
  34. inc %o2
  35. sll %o2, 2, %o2
  36. add %o2, %o0, %o2
  37. sethi %hi(operatingsystem_parameter_envp),%o1
  38. or %o1,%lo(operatingsystem_parameter_envp),%o1
  39. .ifdef PIC
  40. ld [%o1+%l7],%o1
  41. .endif
  42. st %o2, [%o1]
  43. /* Save initial stackpointer */
  44. sethi %hi(__stkptr),%o1
  45. or %o1,%lo(__stkptr),%o1
  46. .ifdef PIC
  47. ld [%o1+%l7],%o1
  48. .endif
  49. st %sp, [%o1]
  50. /* reload the addresses for C startup code */
  51. ld [%sp+22*4], %o1
  52. add %sp, 23*4, %o2
  53. /* Load the addresses of the user entry points. */
  54. sethi %hi(PASCALMAIN), %o0
  55. sethi %hi(_init), %o3
  56. sethi %hi(_fini), %o4
  57. or %o0, %lo(PASCALMAIN), %o0
  58. .ifdef PIC
  59. ld [%o0+%l7],%o0
  60. .endif
  61. or %o3, %lo(_init), %o3
  62. .ifdef PIC
  63. ld [%o3+%l7],%o3
  64. .endif
  65. or %o4, %lo(_fini), %o4
  66. .ifdef PIC
  67. ld [%o4+%l7],%o4
  68. .endif
  69. /* When starting a binary via the dynamic linker, %g1 contains the
  70. address of the shared library termination function, which will be
  71. registered with atexit(). If we are statically linked, this will
  72. be NULL. */
  73. mov %g1, %o5
  74. /* Let libc do the rest of the initialization, and call main. */
  75. call __libc_start_main
  76. nop
  77. /* Die very horribly if exit returns. */
  78. unimp
  79. .size _start, .-_start
  80. .globl _haltproc
  81. .type _haltproc,@function
  82. _haltproc:
  83. mov 188, %g1 /* "exit" system call */
  84. ta 0x10 /* dot the system call */
  85. nop /* delay slot */
  86. /* Die very horribly if exit returns. */
  87. unimp
  88. .data
  89. .comm __stkptr,4
  90. .comm operatingsystem_parameter_envp,4
  91. .comm operatingsystem_parameter_argc,4
  92. .comm operatingsystem_parameter_argv,4