| 1 | #
|
|---|
| 2 | # Copyright (c) 2006 Martin Decky
|
|---|
| 3 | # Copyright (c) 2006 Jakub Jermar
|
|---|
| 4 | # All rights reserved.
|
|---|
| 5 | #
|
|---|
| 6 | # Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | # modification, are permitted provided that the following conditions
|
|---|
| 8 | # are met:
|
|---|
| 9 | #
|
|---|
| 10 | # - Redistributions of source code must retain the above copyright
|
|---|
| 11 | # notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | # - 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 | # - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | # derived from this software without specific prior written permission.
|
|---|
| 17 | #
|
|---|
| 18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | #
|
|---|
| 29 |
|
|---|
| 30 | #include <abi/asmtool.h>
|
|---|
| 31 | #include <arch/arch.h>
|
|---|
| 32 |
|
|---|
| 33 | #if defined(PROCESSOR_us) || defined(PROCESSOR_us3)
|
|---|
| 34 | #define ICACHE_SIZE 8192
|
|---|
| 35 | #define ICACHE_LINE_SIZE 32
|
|---|
| 36 | #define ICACHE_SET_BIT (1 << 13)
|
|---|
| 37 | #define ASI_ICACHE_TAG 0x67
|
|---|
| 38 | #endif /* PROCESSOR_us || PROCESSOR_us3 */
|
|---|
| 39 |
|
|---|
| 40 | .register %g2, #scratch
|
|---|
| 41 | .register %g3, #scratch
|
|---|
| 42 | .register %g6, #scratch
|
|---|
| 43 | .register %g7, #scratch
|
|---|
| 44 |
|
|---|
| 45 | .section BOOTSTRAP, "ax"
|
|---|
| 46 |
|
|---|
| 47 | SYMBOL(start)
|
|---|
| 48 | ba %xcc, 1f
|
|---|
| 49 | nop
|
|---|
| 50 |
|
|---|
| 51 | /*
|
|---|
| 52 | * This header forces SILO to load the image at 0x4000.
|
|---|
| 53 | * More precisely, SILO will think this is an old version of Linux.
|
|---|
| 54 | */
|
|---|
| 55 | .ascii "HdrS"
|
|---|
| 56 | .word 0
|
|---|
| 57 | .half 0
|
|---|
| 58 | .half 0
|
|---|
| 59 | .half 0
|
|---|
| 60 | .half 0
|
|---|
| 61 | .word 0
|
|---|
| 62 | .word 0
|
|---|
| 63 |
|
|---|
| 64 | .align 8
|
|---|
| 65 | 1:
|
|---|
| 66 | ! Disable interrupts and disable address masking.
|
|---|
| 67 |
|
|---|
| 68 | wrpr %g0, PSTATE_PRIV_BIT, %pstate
|
|---|
| 69 |
|
|---|
| 70 | wrpr %g0, NWINDOWS - 2, %cansave ! Set maximum saveable windows
|
|---|
| 71 | wrpr %g0, 0, %canrestore ! Get rid of windows we will never need again
|
|---|
| 72 | wrpr %g0, 0, %otherwin ! Make sure the window state is consistent
|
|---|
| 73 | wrpr %g0, NWINDOWS - 1, %cleanwin ! Prevent needless clean_window traps for kernel
|
|---|
| 74 |
|
|---|
| 75 | set initial_stack, %sp
|
|---|
| 76 | add %sp, -STACK_BIAS, %sp
|
|---|
| 77 |
|
|---|
| 78 | set ofw_cif, %l0
|
|---|
| 79 |
|
|---|
| 80 | ! Initialize OpenFirmware
|
|---|
| 81 |
|
|---|
| 82 | call ofw_init
|
|---|
| 83 | stx %o4, [%l0]
|
|---|
| 84 |
|
|---|
| 85 | ba %xcc, bootstrap
|
|---|
| 86 | nop
|
|---|
| 87 |
|
|---|
| 88 | .align STACK_ALIGNMENT
|
|---|
| 89 | .space STACK_SIZE
|
|---|
| 90 | initial_stack:
|
|---|
| 91 | .space STACK_WINDOW_SAVE_AREA_SIZE
|
|---|
| 92 |
|
|---|
| 93 | .text
|
|---|
| 94 |
|
|---|
| 95 | FUNCTION_BEGIN(halt)
|
|---|
| 96 | ba %xcc, halt
|
|---|
| 97 | nop
|
|---|
| 98 | FUNCTION_END(halt)
|
|---|
| 99 |
|
|---|
| 100 | FUNCTION_BEGIN(jump_to_kernel)
|
|---|
| 101 | /*
|
|---|
| 102 | * Guarantee cache coherence:
|
|---|
| 103 | * 1. Make sure that the code we have moved has drained to main memory.
|
|---|
| 104 | * 2. Invalidate I-cache.
|
|---|
| 105 | * 3. Flush instruction pipeline.
|
|---|
| 106 | */
|
|---|
| 107 |
|
|---|
| 108 | /*
|
|---|
| 109 | * US3 processors have a write-invalidate cache, so explicitly
|
|---|
| 110 | * invalidating it is not required. Whether to invalidate I-cache
|
|---|
| 111 | * or not is decided according to the value of the 3rd argument
|
|---|
| 112 | * (subarch).
|
|---|
| 113 | */
|
|---|
| 114 | cmp %o2, SUBARCH_US3
|
|---|
| 115 | be %xcc, 1f
|
|---|
| 116 | nop
|
|---|
| 117 |
|
|---|
| 118 | 0:
|
|---|
| 119 | call icache_flush
|
|---|
| 120 | nop
|
|---|
| 121 |
|
|---|
| 122 | 1:
|
|---|
| 123 | membar #StoreStore
|
|---|
| 124 |
|
|---|
| 125 | /*
|
|---|
| 126 | * Flush the instruction pipeline.
|
|---|
| 127 | */
|
|---|
| 128 | flush %i7
|
|---|
| 129 |
|
|---|
| 130 | ! Jump to kernel
|
|---|
| 131 | jmp %o3
|
|---|
| 132 | nop
|
|---|
| 133 | FUNCTION_END(jump_to_kernel)
|
|---|
| 134 |
|
|---|
| 135 | # Flush I-cache
|
|---|
| 136 | icache_flush:
|
|---|
| 137 | #if defined(PROCESSOR_us) || defined(PROCESSOR_us3)
|
|---|
| 138 | set ((ICACHE_SIZE - ICACHE_LINE_SIZE) | ICACHE_SET_BIT), %g1
|
|---|
| 139 | stxa %g0, [%g1] ASI_ICACHE_TAG
|
|---|
| 140 |
|
|---|
| 141 | 0:
|
|---|
| 142 | membar #Sync
|
|---|
| 143 | subcc %g1, ICACHE_LINE_SIZE, %g1
|
|---|
| 144 | bnz,pt %xcc, 0b
|
|---|
| 145 |
|
|---|
| 146 | stxa %g0, [%g1] ASI_ICACHE_TAG
|
|---|
| 147 | membar #Sync
|
|---|
| 148 | retl
|
|---|
| 149 |
|
|---|
| 150 | ! SF Erratum #51
|
|---|
| 151 |
|
|---|
| 152 | nop
|
|---|
| 153 | #else
|
|---|
| 154 | // TODO: sun4v
|
|---|
| 155 | retl
|
|---|
| 156 | nop
|
|---|
| 157 | #endif /* PROCESSOR_us || PROCESSOR_us3 */
|
|---|
| 158 |
|
|---|
| 159 | FUNCTION_BEGIN(ofw)
|
|---|
| 160 | save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE), %sp
|
|---|
| 161 | set ofw_cif, %l0
|
|---|
| 162 | ldx [%l0], %l0
|
|---|
| 163 |
|
|---|
| 164 | rdpr %pstate, %l1
|
|---|
| 165 | and %l1, ~PSTATE_AM_BIT, %l2
|
|---|
| 166 | wrpr %l2, 0, %pstate
|
|---|
| 167 |
|
|---|
| 168 | jmpl %l0, %o7
|
|---|
| 169 | mov %i0, %o0
|
|---|
| 170 |
|
|---|
| 171 | wrpr %l1, 0, %pstate
|
|---|
| 172 |
|
|---|
| 173 | ret
|
|---|
| 174 | restore %o0, 0, %o0
|
|---|
| 175 | FUNCTION_END(ofw)
|
|---|