srt0.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* $OpenBSD: srt0.S,v 1.4 2010/07/06 20:41:06 miod Exp $ */
  2. /* $NetBSD: srt0.S,v 1.5.4.2 1996/07/17 01:51:46 jtc Exp $ */
  3. /*
  4. * Copyright (c) 1994 Paul Kranenburg
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. All advertising materials mentioning features or use of this software
  16. * must display the following acknowledgement:
  17. * This product includes software developed by Paul Kranenburg.
  18. * 4. The name of the author may not be used to endorse or promote products
  19. * derived from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  22. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  23. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include <machine/param.h>
  33. #include <machine/psl.h>
  34. #include <machine/asm.h>
  35. #define CCFSZ 96
  36. .file "str0.s"
  37. .data
  38. .global _C_LABEL(cputyp), _C_LABEL(nbpg), _C_LABEL(pgofset)
  39. .global _C_LABEL(pgshift)
  40. _C_LABEL(cputyp):
  41. .word CPU_SUN4C
  42. _C_LABEL(nbpg):
  43. .word 1
  44. _C_LABEL(pgofset):
  45. .word 1
  46. _C_LABEL(pgshift):
  47. .word 1
  48. .text
  49. .globl start
  50. start:
  51. /*
  52. * Set up a stack.
  53. */
  54. set start, %o1
  55. save %o1, -CCFSZ, %sp
  56. /*
  57. * Find which address we are at.
  58. */
  59. 1: call 2f
  60. sethi %hi(1b), %l0
  61. 2: or %l0, %lo(1b), %l0
  62. cmp %l0, %o7 ! %o7 contains actual address of 1b
  63. beq 4f ! already there, no need to relocate
  64. nop
  65. /*
  66. * Relocate.
  67. */
  68. add %o7, (start-1b), %l0
  69. set start, %l1
  70. set _C_LABEL(end), %o0
  71. sub %o0, %l1, %l2 ! length
  72. 3: ld [%l0], %o0
  73. add %l0, 4, %l0
  74. st %o0, [%l1]
  75. subcc %l2, 4, %l2
  76. bg 3b
  77. add %l1, 4, %l1
  78. set 4f, %g1
  79. jmp %g1
  80. nop
  81. 4:
  82. #ifdef notyet
  83. /*
  84. * Enable traps
  85. */
  86. wr %g0, 0, %wim ! make sure we can set psr
  87. nop; nop; nop
  88. wr %g0, PSR_S|PSR_PS|PSR_PIL, %psr ! set initial psr
  89. nop; nop; nop
  90. wr %g0, 2, %wim ! set initial %wim (w1 invalid)
  91. rd %psr, %l0
  92. wr %l0, PSR_ET, %psr
  93. nop; nop; nop
  94. #endif
  95. /*
  96. * Clear BSS
  97. */
  98. set _C_LABEL(edata), %o0 ! bzero(edata, end - edata)
  99. set _C_LABEL(end), %o1
  100. /* note: bzero() expanded inline for compactness */
  101. subcc %o1, %o0, %o1
  102. bz 2f ! in case there is no BSS
  103. srl %o1, 2, %o1 ! assume edata and end are aligned
  104. 1:
  105. st %g0, [%o0] ! while (n--)
  106. subcc %o1, 1, %o1 ! *p++ = 0;
  107. bnz 1b
  108. add %o0, 4, %o0
  109. 2:
  110. /*
  111. * Enable interrupts, but only above level 11. This enables "L1-A",
  112. * but avoids spurious interrupt bites from most other devices.
  113. */
  114. rd %psr, %o0
  115. andn %o0, PSR_PIL, %o0
  116. wr %o0, 0xb00, %psr ! (11 << 8)
  117. nop; nop; nop
  118. /*
  119. * Set CPU type that we are running on.
  120. */
  121. sethi %hi(_C_LABEL(cputyp)), %o0
  122. set 0x4000, %g7
  123. cmp %i0, %g7
  124. beq 5f
  125. nop
  126. /*
  127. * Save address of PROM vector (passed in %i0).
  128. */
  129. sethi %hi(_C_LABEL(promvec)), %o1
  130. st %i0, [%o1 + %lo(_C_LABEL(promvec))]
  131. mov CPU_SUN4C, %g4
  132. b,a 6f
  133. 5:
  134. mov CPU_SUN4, %g4
  135. 6:
  136. st %g4, [%o0 + %lo(_C_LABEL(cputyp))]
  137. call _C_LABEL(main)
  138. mov %i0, %o0
  139. ret
  140. restore