1 /* $NetBSD: ofw_subr.S,v 1.7 2008/02/14 19:41:54 garbled Exp $ */
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 .globl openfirmware_entry
42 .long 0,0,0,0,0 /* msr & sprg[0-3] used in OF */
47 GLOBAL(ofwreal_incharge)
51 .comm OF_buffer,NBPG,4
52 .comm openfirmware_entry,4,4 /* openfirmware entry point */
53 .comm ofwsrsave,64,4 /* openfirmware SR savearea */
56 * Called by start to save the initial OFW state so we can restore it
57 * when call back to OFW.
59 ENTRY_NOPROFILE(ofwinit)
62 andi. %r0,%r0,PSL_IR|PSL_DR
66 lis %r9,ofwreal_incharge@ha
67 stw %r8,ofwreal_incharge@l(9)
70 bl _C_LABEL(ofwr_init)
74 lis %r8,openfirmware_entry@ha
75 stw %r5,openfirmware_entry@l(%r8) /* save client interface handler*/
79 stwu %r0,ofmsr@l(%r9) /* save initial MSR value */
81 mfsprg %r0,0 /* save SPRGs */
91 addi %r8,%r8,OF_buffer@l
92 lis %r9,_C_LABEL(OF_buf)@ha
93 stw %r8,_C_LABEL(OF_buf)@l(%r9)
98 * OpenFirmware entry point
102 mflr %r0 /* save return address */
104 stwu %r1,-16(%r1) /* setup stack frame */
106 lis %r4,openfirmware_entry@ha /* get firmware entry point */
107 lwz %r4,openfirmware_entry@l(%r4)
110 mfsprg %r5,0 /* save current sprg0 (curcpu) */
111 lis %r4,ofwsprg0save@ha
112 addi %r4,%r4,ofwsprg0save@l
116 lis %r4,ofwreal_incharge@ha
117 lwz %r4,ofwreal_incharge@l(%r4)
124 mfmsr %r4 /* save msr */
127 li %r0,0 /* clear battable translations */
129 #if defined (PPC_OEA) || defined (PPC_OEA64_BRIDGE)
136 lis %r4,ofwsrsave@ha /* save current SRs */
137 addi %r4,%r4,ofwsrsave@l
142 addis %r5,%r5,0x10000000@h
146 lis %r4,_C_LABEL(ofw_pmap)@ha /* load OFW SR */
147 addi %r4,%r4,_C_LABEL(ofw_pmap)@l
148 lwz %r0,PM_KERNELSR(%r4)
149 cmpwi %r0,0 /* pm_sr[KERNEL_SR] == 0? */
150 beq 2f /* then skip (not initialized yet) */
155 addis %r5,%r5,0x10000000@h
159 lis %r4,ofmsr@ha /* Open Firmware msr + sprg[0-3] */
160 lwzu %r5,ofmsr+16@l(%r4)
172 blrl /* call Open Firmware */
174 lis %r4,ofwsrsave@ha /* restore saved SRs */
175 addi %r4,%r4,ofwsrsave@l
180 addis %r5,%r5,0x10000000@h
184 lwz %r4,8(%r1) /* restore msr */
188 lis %r4,ofwsprg0save@ha /* restore saved sprg0 (curcpu) */
189 addi %r4,%r4,ofwsprg0save@l
193 lwz %r1,0(%r1) /* and return */
199 * Switch to/from OpenFirmware real mode stack
201 * Note: has to be called as the very first thing in OpenFirmware interface
225 * if (openfirmware(&args) < 0)
232 mfmsr %r8 /* turn off interrupts */
233 andi. %r0,%r8,~(PSL_EE|PSL_RI)@l
235 stw %r8,4(%r1) /* abuse return address slot */
237 lwz %r5,0(%r1) /* get length of stack frame */
240 lis %r7,firmstk+NBPG-8@ha
241 addi %r7,%r7,firmstk+NBPG-8@l
243 addi %r6,%r6,ofw_back@l
244 subf %r4,%r5,%r7 /* make room for stack frame on
246 stw %r6,-4(%r7) /* setup return pointer */
255 b _C_LABEL(ofbcopy) /* and copy it */
258 lwz %r1,0(%r1) /* get callers original stack pointer */
260 lwz %r0,4(%r1) /* get saved msr from abused slot */
263 lwz %r1,0(%r1) /* return */