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 */
42 .long 0, 0, 0, 0, 0 /* msr/sprg0-3 used in Open Firmware */
45 GLOBAL(openfirmware_entry)
46 .long 0 /* Open Firmware entry point */
48 .long 0 /* RTAS entry point */
57 * Open Firmware Entry Point. May need to enter real mode.
59 * C prototype: int ofwcall(void *callbuffer);
66 /* Record the old MSR */
69 /* GOT pointer in r7 */
70 bl _GLOBAL_OFFSET_TABLE_@local-4
73 /* read client interface handler */
74 lwz %r4,openfirmware_entry@got(%r7)
78 * Set the MSR to the OF value. This has the side effect of disabling
79 * exceptions, which prevents preemption later.
82 lwz %r5,ofmsr@got(%r7)
88 * Set up OF stack. This needs to be potentially accessible in real mode
89 * The pointer to the current kernel stack is placed at the very
90 * top of the stack along with the old MSR so we can get them back
94 lwz %r1,ofwstk@got(%r7)
95 addi %r1,%r1,(OFWSTKSZ-32)
96 stw %r5,20(%r1) /* Save real stack pointer */
97 stw %r2,24(%r1) /* Save curthread */
98 stw %r6,28(%r1) /* Save old MSR */
103 /* Finally, branch to OF */
107 /* Reload stack pointer and MSR from the OFW stack */
112 /* Now set the real MSR */
122 * RTAS Entry Point. Similar to the OF one, but simpler (no separate stack)
124 * C prototype: int rtascall(void *callbuffer, void *rtas_privdat);
131 /* GOT pointer in r7 */
132 bl _GLOBAL_OFFSET_TABLE_@local-4
135 /* Record the old MSR to real-mode-accessible area */
137 lwz %r5,rtas_regsave@got(%r7)
140 /* read client interface handler */
141 lwz %r5,rtas_entry@got(%r7)
144 /* Set the MSR to the RTAS value */
145 lwz %r6,rtasmsr@got(%r7)
154 /* GOT pointer in r7 */
155 bl _GLOBAL_OFFSET_TABLE_@local-4
158 /* Now set the MSR back */
159 lwz %r6,rtas_regsave@got(%r7)