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 */
56 * Open Firmware Real-mode Entry Point. This is a huge pain.
59 ASENTRY_NOPROF(ofwcall)
65 * We need to save the following, because OF's register save/
66 * restore code assumes that the contents of registers are
67 * at most 32 bits wide: lr, cr, r2, r13-r31, the old MSR. These
68 * get placed in that order in the stack.
93 /* Record the old MSR */
96 /* read client interface handler */
97 lis %r4,openfirmware_entry@ha
98 ld %r4,openfirmware_entry@l(%r4)
101 * Set the MSR to the OF value. This has the side effect of disabling
102 * exceptions, which is important for the next few steps.
111 * Set up OF stack. This needs to be accessible in real mode and
112 * use the 32-bit ABI stack frame format. The pointer to the current
113 * kernel stack is placed at the very top of the stack along with
114 * the old MSR so we can get them back later.
117 lis %r1,(ofwstk+OFWSTKSZ-32)@ha
118 addi %r1,%r1,(ofwstk+OFWSTKSZ-32)@l
119 std %r5,8(%r1) /* Save real stack pointer */
120 std %r2,16(%r1) /* Save old TOC */
121 std %r6,24(%r1) /* Save old MSR */
126 /* Finally, branch to OF */
130 /* Reload stack pointer and MSR from the OFW stack */
135 /* Now set the real MSR */
139 /* Sign-extend the return value from OF */
142 /* Restore all the non-volatile registers */
165 /* Restore the stack and link register */
172 * RTAS 32-bit Entry Point. Similar to the OF one, but simpler (no separate
175 * C prototype: int rtascall(void *callbuffer, void *rtas_privdat);
178 ASENTRY_NOPROF(rtascall)
184 * We need to save the following, because RTAS's register save/
185 * restore code assumes that the contents of registers are
186 * at most 32 bits wide: lr, cr, r2, r13-r31, the old MSR. These
187 * get placed in that order in the stack.
212 /* Record the old MSR */
215 /* read client interface handler */
216 lis %r5,rtas_entry@ha
217 ld %r5,rtas_entry@l(%r5)
220 * Set the MSR to the RTAS value. This has the side effect of disabling
221 * exceptions, which is important for the next few steps.
225 ld %r7,rtasmsr@l(%r7)
230 * Set up RTAS register save area, so that we can get back all of
231 * our 64-bit pointers. Save our stack pointer, the TOC, and the MSR.
232 * Put this in r1, since RTAS is obliged to save it. Kernel globals
233 * are below 4 GB, so this is safe.
236 lis %r1,rtas_regsave@ha
237 addi %r1,%r1,rtas_regsave@l
238 std %r7,0(%r1) /* Save 64-bit stack pointer */
239 std %r2,8(%r1) /* Save TOC */
240 std %r6,16(%r1) /* Save MSR */
242 /* Finally, branch to RTAS */
247 * Reload stack pointer and MSR from the reg save area in r1. We are
248 * running in 32-bit mode at this point, so it doesn't matter if r1
249 * has become sign-extended.
255 /* Now set the real MSR */
259 /* Sign-extend the return value from RTAS */
262 /* Restore all the non-volatile registers */
285 /* Restore the stack and link register */