2 * Copyright (C) 2009-2011 Nathan Whitehorn
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/syscall.h>
30 #include <machine/trap.h>
31 #include <machine/param.h>
32 #include <machine/spr.h>
33 #include <machine/asm.h>
35 #define OFWSTKSZ 4096 /* 4K Open Firmware stack */
45 .space 24 /* 3 * sizeof(register_t) */
47 .llong 0, 0, 0, 0, 0 /* msr/sprg0-3 used in Open Firmware */
50 GLOBAL(openfirmware_entry)
51 .llong 0 /* Open Firmware entry point */
53 .llong 0 /* RTAS entry point */
58 TOC_ENTRY(openfirmware_entry)
60 TOC_ENTRY(rtas_regsave)
63 * Open Firmware Real-mode Entry Point. This is a huge pain.
66 ASENTRY_NOPROF(ofwcall)
72 * We need to save the following, because OF's register save/
73 * restore code assumes that the contents of registers are
74 * at most 32 bits wide: lr, cr, r2, r13-r31, the old MSR. These
75 * get placed in that order in the stack.
100 /* Record the old MSR */
103 /* read client interface handler */
104 ld %r4,TOC_REF(openfirmware_entry)(%r2)
107 /* Get OF stack pointer */
108 ld %r7,TOC_REF(ofwstk)(%r2)
109 addi %r7,%r7,OFWSTKSZ-32
112 * Set the MSR to the OF value. This has the side effect of disabling
113 * exceptions, which is important for the next few steps.
116 ld %r5,TOC_REF(ofmsr)(%r2)
122 * Set up OF stack. This needs to be accessible in real mode and
123 * use the 32-bit ABI stack frame format. The pointer to the current
124 * kernel stack is placed at the very top of the stack along with
125 * the old MSR so we can get them back later.
129 std %r5,8(%r1) /* Save real stack pointer */
130 std %r2,16(%r1) /* Save old TOC */
131 std %r6,24(%r1) /* Save old MSR */
136 /* Finally, branch to OF */
140 /* Reload stack pointer and MSR from the OFW stack */
145 /* Now set the real MSR */
149 /* Sign-extend the return value from OF */
152 /* Restore all the non-volatile registers */
175 /* Restore the stack and link register */
182 * RTAS 32-bit Entry Point. Similar to the OF one, but simpler (no separate
185 * C prototype: int rtascall(void *callbuffer, void *rtas_privdat);
188 ASENTRY_NOPROF(rtascall)
194 * We need to save the following, because RTAS's register save/
195 * restore code assumes that the contents of registers are
196 * at most 32 bits wide: lr, cr, r2, r13-r31, the old MSR. These
197 * get placed in that order in the stack.
222 /* Record the old MSR */
225 /* Read RTAS entry and reg save area pointers */
226 ld %r5,TOC_REF(rtas_entry)(%r2)
228 ld %r8,TOC_REF(rtas_regsave)(%r2)
231 * Set the MSR to the RTAS value. This has the side effect of disabling
232 * exceptions, which is important for the next few steps.
235 ld %r7,TOC_REF(rtasmsr)(%r2)
241 * Set up RTAS register save area, so that we can get back all of
242 * our 64-bit pointers. Save our stack pointer, the TOC, and the MSR.
243 * Put this in r1, since RTAS is obliged to save it. Kernel globals
244 * are below 4 GB, so this is safe.
248 std %r7,0(%r1) /* Save 64-bit stack pointer */
249 std %r2,8(%r1) /* Save TOC */
250 std %r6,16(%r1) /* Save MSR */
252 /* Finally, branch to RTAS */
257 * Reload stack pointer and MSR from the reg save area in r1. We are
258 * running in 32-bit mode at this point, so it doesn't matter if r1
259 * has become sign-extended.
265 /* Now set the real MSR */
269 /* Sign-extend the return value from RTAS */
272 /* Restore all the non-volatile registers */
295 /* Restore the stack and link register */