| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * Hypervisor Software File: crt0.s |
| 5 | * |
| 6 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 7 | * |
| 8 | * - Do no alter or remove copyright notices |
| 9 | * |
| 10 | * - Redistribution and use of this software in source and binary forms, with |
| 11 | * or without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistribution of source code must retain the above copyright notice, |
| 15 | * this list of conditions and the following disclaimer. |
| 16 | * |
| 17 | * - Redistribution in binary form must reproduce the above copyright notice, |
| 18 | * this list of conditions and the following disclaimer in the |
| 19 | * documentation and/or other materials provided with the distribution. |
| 20 | * |
| 21 | * Neither the name of Sun Microsystems, Inc. or the names of contributors |
| 22 | * may be used to endorse or promote products derived from this software |
| 23 | * without specific prior written permission. |
| 24 | * |
| 25 | * This software is provided "AS IS," without a warranty of any kind. |
| 26 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, |
| 27 | * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A |
| 28 | * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN |
| 29 | * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR |
| 30 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR |
| 31 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN |
| 32 | * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR |
| 33 | * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE |
| 34 | * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, |
| 35 | * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF |
| 36 | * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
| 37 | * |
| 38 | * You acknowledge that this software is not designed, licensed or |
| 39 | * intended for use in the design, construction, operation or maintenance of |
| 40 | * any nuclear facility. |
| 41 | * |
| 42 | * ========== Copyright Header End ============================================ |
| 43 | */ |
| 44 | /* |
| 45 | * Copyright (c) 1986-1995, 2003 Sun Microsystems, Inc. All Rights Reserved |
| 46 | * Use is subject to license terms. |
| 47 | */ |
| 48 | |
| 49 | #pragma ident "@(#)srt0.s 1.4 01/03/26 SMI" |
| 50 | |
| 51 | /* |
| 52 | * srt0.s - standalone startup code |
| 53 | * Generate the code with a fake a.out header if INETBOOT is defined. |
| 54 | * inetboot is loaded directly by the PROM, other booters are loaded via |
| 55 | * a bootblk and don't need the fake a.out header. |
| 56 | */ |
| 57 | |
| 58 | #include <sys/asm_linkage.h> |
| 59 | #include <sys/cpu.h> |
| 60 | #include <sys/privregs.h> |
| 61 | #include <sys/stack.h> |
| 62 | |
| 63 | .seg ".text" |
| 64 | .align 8 |
| 65 | .global end |
| 66 | .global edata |
| 67 | .global main |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | * The following variables are machine-dependent and are set in fiximp. |
| 72 | * Space is allocated there. |
| 73 | */ |
| 74 | .seg ".data" |
| 75 | .align 8 |
| 76 | |
| 77 | _local_p1275cif: |
| 78 | .word 0 |
| 79 | |
| 80 | #define STACK_SIZE 0x14000 |
| 81 | .skip STACK_SIZE |
| 82 | .ebootstack: ! end (top) of boot stack |
| 83 | |
| 84 | /* |
| 85 | * The following variables are more or less machine-independent |
| 86 | * (or are set outside of fiximp). |
| 87 | */ |
| 88 | |
| 89 | .seg ".text" |
| 90 | .align 8 |
| 91 | .global prom_exit_to_mon |
| 92 | .type prom_exit_to_mon, #function |
| 93 | |
| 94 | |
| 95 | ! Each standalone program is responsible for its own stack. Our strategy |
| 96 | ! is that each program which uses this runtime code creates a stack just |
| 97 | ! below its relocation address. Previous windows may (and probably do) |
| 98 | ! have frames allocated on the prior stack; leave them alone. Starting with |
| 99 | ! this window, allocate our own stack frames for our windows. (Overflows |
| 100 | ! or a window flush would then pass seamlessly from our stack to the old.) |
| 101 | ! RESTRICTION: A program running at some relocation address must not exec |
| 102 | ! another which will run at the very same address: the stacks would collide. |
| 103 | ! |
| 104 | ! Careful: don't touch %o4 until the save, since it contains the |
| 105 | ! address of the IEEE 1275 SPARC v9 CIF handler (linkage to the prom). |
| 106 | ! |
| 107 | ! |
| 108 | ! We cannot write to any symbols until we are relocated. |
| 109 | ! Note that with the advent of 5.x boot, we no longer have to |
| 110 | ! relocate ourselves, but this code is kept around cuz we *know* |
| 111 | ! someone would scream if we did the obvious. |
| 112 | ! |
| 113 | |
| 114 | |
| 115 | #ifndef INETBOOT |
| 116 | |
| 117 | ! |
| 118 | ! Enter here for all booters loaded by a bootblk program. |
| 119 | ! Careful, do not lose value of the SPARC v9 P1275 CIF handler in %o4 |
| 120 | ! Setup temporary 32 bit stack at _start. |
| 121 | ! |
| 122 | ! NB: Until the common startup code, AM may not be set. |
| 123 | ! |
| 124 | |
| 125 | ENTRY_NP(_start) |
| 126 | set _start - 0x10000, %o1 |
| 127 | ! and %o1, ~(STACK_ALIGN64-1), %o1 |
| 128 | ! save %o1, -SA(MINFRAME64), %sp ! %i4: 1275 sparcv9 CIF handler |
| 129 | and %o6, (STACK_ALIGN64-1), %o2 |
| 130 | add %o1, -SA(MINFRAME64), %o1 |
| 131 | save %o1, %o2, %sp ! %i4: 1275 sparcv9 CIF handler |
| 132 | ! ta 0x7f |
| 133 | ! |
| 134 | ! zero the bss |
| 135 | ! |
| 136 | sethi %hi(edata), %o0 ! Beginning of bss |
| 137 | or %o0, %lo(edata), %o0 |
| 138 | set end, %i2 |
| 139 | call bzero |
| 140 | sub %i2, %o0, %o1 ! end - edata = size of bss |
| 141 | |
| 142 | #endif !INETBOOT |
| 143 | |
| 144 | ! |
| 145 | ! All booters end up here... |
| 146 | ! |
| 147 | |
| 148 | 9: |
| 149 | #ifndef __sparcv9 |
| 150 | /* |
| 151 | * Use our own 32 bit stack now. But, zero it first (do we have to?) |
| 152 | */ |
| 153 | set .ebootstack, %o0 |
| 154 | set STACK_SIZE, %o1 |
| 155 | sub %o0, %o1, %o1 |
| 156 | 1: dec 4, %o0 |
| 157 | st %g0, [%o0] |
| 158 | cmp %o0, %o1 |
| 159 | bne 1b |
| 160 | nop |
| 161 | |
| 162 | set .ebootstack, %o0 |
| 163 | and %o0, ~(STACK_ALIGN64-1), %o0 |
| 164 | sub %o0, SA64(MINFRAME64), %sp |
| 165 | |
| 166 | /* |
| 167 | * Set the psr into a known state: |
| 168 | * Set AM, supervisor mode, interrupt level >= 13, traps enabled |
| 169 | */ |
| 170 | wrpr %g0, 13, %pil |
| 171 | wr %g0, FPRS_FEF, %fprs |
| 172 | wrpr %g0, PSTATE_PEF+PSTATE_AM+PSTATE_PRIV+PSTATE_IE, %pstate |
| 173 | nop; nop; nop |
| 174 | sethi %hi(_local_p1275cif), %o2 |
| 175 | st %i4, [%o2 + %lo(_local_p1275cif)] |
| 176 | #else |
| 177 | wrpr %g0, 13, %pil |
| 178 | wr %g0, FPRS_FEF, %fprs |
| 179 | wrpr %g0, PSTATE_PEF+PSTATE_PRIV+PSTATE_IE, %pstate |
| 180 | nop; nop; nop |
| 181 | sethi %hi(_local_p1275cif), %o2 |
| 182 | stx %i4, [%o2 + %lo(_local_p1275cif)] |
| 183 | #endif |
| 184 | |
| 185 | mov %g0, %o0 |
| 186 | call prom_init ! prom-init(NULL, prom-cookie) |
| 187 | mov %i4, %o1 ! SPARCV9/CIF |
| 188 | |
| 189 | mov %g0, %o0 |
| 190 | call main ! main(0) |
| 191 | mov %g0, %o1 ! |
| 192 | |
| 193 | call prom_exit_to_mon ! can't happen .. :-) |
| 194 | nop |
| 195 | SET_SIZE(_start) |
| 196 | |
| 197 | |
| 198 | /* |
| 199 | * The interface for a 32-bit client program |
| 200 | * calling the 64-bit romvec OBP. |
| 201 | */ |
| 202 | |
| 203 | #if defined(lint) |
| 204 | #include <sys/promif.h> |
| 205 | |
| 206 | /* ARGSUSED */ |
| 207 | int |
| 208 | client_handler(void *cif_handler, cell_t **) |
| 209 | {} |
| 210 | |
| 211 | #else /* !lint */ |
| 212 | |
| 213 | ENTRY_NP(client_handler) |
| 214 | save %sp, -SA64(MINFRAME64), %sp ! 32 bit frame, 64 bit sized |
| 215 | #ifndef __sparcv9 |
| 216 | mov %i1, %o0 |
| 217 | rdpr %pstate, %l1 ! Get the present pstate value |
| 218 | wrpr %l1, PSTATE_AM, %pstate ! Set PSTATE_AM = 0 |
| 219 | jmpl %i0, %o7 ! Call cif handler |
| 220 | sub %sp, V9BIAS64, %sp ! delay; Now a 64 bit frame |
| 221 | rdpr %pstate, %l1 ! Get the present pstate value |
| 222 | wrpr %l1, PSTATE_AM, %pstate ! Set PSTATE_AM = 1 |
| 223 | #else |
| 224 | mov %i1, %o0 |
| 225 | jmpl %i0, %o7 ! Call cif handler |
| 226 | nop |
| 227 | #endif |
| 228 | ret ! Return result ... |
| 229 | restore %o0, %g0, %o0 ! delay; result in %o0 |
| 230 | |
| 231 | SET_SIZE(client_handler) |
| 232 | |
| 233 | |
| 234 | ENTRY_NP(set_intr) ! Set the interrupt level. |
| 235 | rdpr %pil, %o1 ! Save existing intr level. |
| 236 | wrpr %o0, 0, %pil ! Write new intr level. |
| 237 | retl |
| 238 | mov %o1, %o0 ! Return old intr level. |
| 239 | |
| 240 | SET_SIZE(set_intr) |
| 241 | |
| 242 | #endif /* !lint */ |