ofw_subr.S revision 1.19 1 1.19 thorpej /* $NetBSD: ofw_subr.S,v 1.19 2021/02/24 17:35:39 thorpej Exp $ */
2 1.1 matt
3 1.1 matt /*
4 1.1 matt * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 1.1 matt * Copyright (C) 1995, 1996 TooLs GmbH.
6 1.1 matt * All rights reserved.
7 1.1 matt *
8 1.1 matt * Redistribution and use in source and binary forms, with or without
9 1.1 matt * modification, are permitted provided that the following conditions
10 1.1 matt * are met:
11 1.1 matt * 1. Redistributions of source code must retain the above copyright
12 1.1 matt * notice, this list of conditions and the following disclaimer.
13 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer in the
15 1.1 matt * documentation and/or other materials provided with the distribution.
16 1.1 matt * 3. All advertising materials mentioning features or use of this software
17 1.1 matt * must display the following acknowledgement:
18 1.1 matt * This product includes software developed by TooLs GmbH.
19 1.1 matt * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 1.1 matt * derived from this software without specific prior written permission.
21 1.1 matt *
22 1.1 matt * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 1.1 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 matt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 matt * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 matt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 1.1 matt * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 1.1 matt * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.1 matt * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 1.1 matt * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 1.1 matt * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 matt */
33 1.1 matt
34 1.12 rin #ifdef _KERNEL_OPT
35 1.12 rin #include "opt_ppcarch.h"
36 1.12 rin #endif
37 1.1 matt
38 1.14 thorpej /* Stack used to call into OpenFirmware. */
39 1.14 thorpej .lcomm firmstk,NBPG,16
40 1.1 matt
41 1.14 thorpej /* Buffer used to pass data to/from OpenFirmware. */
42 1.11 macallan .lcomm OF_buffer,NBPG + 36,4
43 1.14 thorpej
44 1.14 thorpej /* The OpenFirmware entry point, provided by OpenFirmware. */
45 1.14 thorpej .lcomm ofentry,4,4
46 1.14 thorpej
47 1.14 thorpej /* Entry trampoline used by openfirmware(). */
48 1.14 thorpej .lcomm oftramp,4,4
49 1.14 thorpej
50 1.19 thorpej /* Client SR save area */
51 1.19 thorpej .lcomm clsrsave,64,4
52 1.14 thorpej
53 1.19 thorpej /* MSR used in OpenFirmware */
54 1.14 thorpej .globl ofwmsr
55 1.18 thorpej .comm ofwmsr,4,4
56 1.1 matt
57 1.16 thorpej #ifdef FIRMWORKSBUGS
58 1.17 thorpej .lcomm ofwreal_incharge,4,4
59 1.16 thorpej #endif
60 1.16 thorpej
61 1.1 matt /*
62 1.1 matt * Called by start to save the initial OFW state so we can restore it
63 1.1 matt * when call back to OFW.
64 1.14 thorpej *
65 1.14 thorpej * We expect the registers to be as for the entry point into the kernel:
66 1.14 thorpej *
67 1.14 thorpej * %r1 Stack provided by OpenFirmware / boot loader
68 1.14 thorpej * %r5 OpenFirmware client entry point
69 1.14 thorpej *
70 1.14 thorpej * (others -- don't care)
71 1.1 matt */
72 1.1 matt ENTRY_NOPROFILE(ofwinit)
73 1.14 thorpej /* Save return address, Push a stack frame. */
74 1.14 thorpej mflr %r0
75 1.14 thorpej stw %r0,4(%r1)
76 1.14 thorpej stwu %r1,-16(%r1)
77 1.14 thorpej
78 1.14 thorpej #ifdef FIRMWORKSBUGS
79 1.7 garbled mfmsr %r0
80 1.7 garbled andi. %r0,%r0,PSL_IR|PSL_DR
81 1.1 matt beq 1f
82 1.1 matt
83 1.7 garbled li %r8,1
84 1.7 garbled lis %r9,ofwreal_incharge@ha
85 1.9 matt stw %r8,ofwreal_incharge@l(%r9)
86 1.4 aymeric
87 1.1 matt bl _C_LABEL(ofwr_init)
88 1.1 matt 1:
89 1.1 matt #endif
90 1.1 matt
91 1.14 thorpej lis %r8,ofentry@ha
92 1.14 thorpej stw %r5,ofentry@l(%r8) /* save client interface handler */
93 1.14 thorpej
94 1.14 thorpej /*
95 1.14 thorpej * Call directly into OpenFirmware until we're ready to use
96 1.14 thorpej * the trampoline.
97 1.14 thorpej */
98 1.14 thorpej lis %r8,oftramp@ha
99 1.14 thorpej stw %r5,oftramp@l(%r8)
100 1.14 thorpej
101 1.14 thorpej /* Save the MSR that OpenFirmware is using. */
102 1.7 garbled mfmsr %r0
103 1.9 matt lis %r9,ofwmsr@ha
104 1.18 thorpej stw %r0,ofwmsr@l(%r9)
105 1.7 garbled
106 1.7 garbled lis %r8,OF_buffer@ha
107 1.7 garbled addi %r8,%r8,OF_buffer@l
108 1.7 garbled lis %r9,_C_LABEL(OF_buf)@ha
109 1.7 garbled stw %r8,_C_LABEL(OF_buf)@l(%r9)
110 1.1 matt
111 1.15 thorpej /*
112 1.15 thorpej * Call into C code to perform additional early initialization.
113 1.15 thorpej */
114 1.15 thorpej lis %r8,_C_LABEL(ofw_bootstrap)@ha
115 1.15 thorpej addi %r8,%r8,_C_LABEL(ofw_bootstrap)@l
116 1.15 thorpej mtctr %r8
117 1.15 thorpej bctrl
118 1.14 thorpej
119 1.14 thorpej /*
120 1.14 thorpej * Jump off the trampoline for all subsequent calls
121 1.14 thorpej * into OpenFirmware.
122 1.14 thorpej */
123 1.14 thorpej lis %r5,_C_LABEL(openfirmware_trampoline)@ha
124 1.14 thorpej addi %r5,%r5,_C_LABEL(openfirmware_trampoline)@l
125 1.14 thorpej lis %r8,oftramp@ha
126 1.14 thorpej stw %r5,oftramp@l(%r8)
127 1.14 thorpej
128 1.14 thorpej /* Retrieve LR, pop stack frame. */
129 1.14 thorpej addi %r1,%r1,16
130 1.14 thorpej lwz %r0,4(%r1)
131 1.14 thorpej mtlr %r0
132 1.14 thorpej
133 1.1 matt blr
134 1.1 matt
135 1.1 matt /*
136 1.14 thorpej * OpenFirmware trampoline. We are already on the OpenFirmware stack.
137 1.1 matt */
138 1.14 thorpej ENTRY_NOPROFILE(openfirmware_trampoline)
139 1.13 thorpej mflr %r0
140 1.13 thorpej stw %r0,4(%r1) /* save return address */
141 1.13 thorpej
142 1.13 thorpej /*
143 1.14 thorpej * Push stack frame and save area:
144 1.13 thorpej *
145 1.14 thorpej * [SP+8 save area]
146 1.14 thorpej * [SP+4 slot for saved LR in callee]
147 1.14 thorpej * [SP+0 saved SP]
148 1.13 thorpej */
149 1.14 thorpej stwu %r1,-48(%r1)
150 1.7 garbled
151 1.14 thorpej lis %r4,ofentry@ha /* get firmware entry point */
152 1.14 thorpej lwz %r4,ofentry@l(%r4)
153 1.7 garbled mtlr %r4
154 1.7 garbled
155 1.4 aymeric #ifdef FIRMWORKSBUGS
156 1.7 garbled lis %r4,ofwreal_incharge@ha
157 1.7 garbled lwz %r4,ofwreal_incharge@l(%r4)
158 1.7 garbled cmpwi %r4,1
159 1.4 aymeric bne 1f
160 1.4 aymeric blrl
161 1.6 garbled b 4f
162 1.4 aymeric 1:
163 1.6 garbled #endif
164 1.7 garbled mfmsr %r4 /* save msr */
165 1.7 garbled stw %r4,8(%r1)
166 1.4 aymeric
167 1.7 garbled li %r0,0 /* clear battable translations */
168 1.8 garbled mtmsr %r0
169 1.6 garbled #if defined (PPC_OEA) || defined (PPC_OEA64_BRIDGE)
170 1.7 garbled mtdbatu 2,%r0
171 1.7 garbled mtdbatu 3,%r0
172 1.7 garbled mtibatu 2,%r0
173 1.7 garbled mtibatu 3,%r0
174 1.3 sanjayl #endif /* PPC_OEA */
175 1.1 matt
176 1.19 thorpej lis %r4,clsrsave@ha /* save current SRs */
177 1.19 thorpej addi %r4,%r4,clsrsave@l
178 1.7 garbled li %r5,0
179 1.7 garbled 1: mfsrin %r0,%r5
180 1.7 garbled stw %r0,0(%r4)
181 1.7 garbled addi %r4,%r4,4
182 1.7 garbled addis %r5,%r5,0x10000000@h
183 1.7 garbled cmpwi %r5,0
184 1.1 matt bne 1b
185 1.1 matt
186 1.7 garbled lis %r4,_C_LABEL(ofw_pmap)@ha /* load OFW SR */
187 1.7 garbled addi %r4,%r4,_C_LABEL(ofw_pmap)@l
188 1.7 garbled lwz %r0,PM_KERNELSR(%r4)
189 1.7 garbled cmpwi %r0,0 /* pm_sr[KERNEL_SR] == 0? */
190 1.1 matt beq 2f /* then skip (not initialized yet) */
191 1.7 garbled li %r5,0
192 1.7 garbled 1: lwz %r0,0(%r4)
193 1.7 garbled mtsrin %r0,%r5
194 1.7 garbled addi %r4,%r4,4
195 1.7 garbled addis %r5,%r5,0x10000000@h
196 1.7 garbled cmpwi %r5,0
197 1.1 matt bne 1b
198 1.1 matt 2:
199 1.18 thorpej /* curcpu()->ci_battable = &ofw_battable */
200 1.18 thorpej GET_CPUINFO(%r4)
201 1.18 thorpej lis %r5,_C_LABEL(ofw_battable)@ha
202 1.18 thorpej addi %r5,%r5,_C_LABEL(ofw_battable)@l
203 1.18 thorpej stw %r5,CI_BATTABLE(%r4)
204 1.18 thorpej
205 1.18 thorpej lis %r4,ofwmsr@ha /* Open Firmware msr */
206 1.18 thorpej lwz %r5,ofwmsr@l(%r4)
207 1.7 garbled mtmsr %r5
208 1.1 matt isync
209 1.1 matt
210 1.1 matt blrl /* call Open Firmware */
211 1.1 matt
212 1.18 thorpej /* curcpu()->ci_battable = &battable */
213 1.18 thorpej GET_CPUINFO(%r4)
214 1.18 thorpej lis %r5,_C_LABEL(battable)@ha
215 1.18 thorpej addi %r5,%r5,_C_LABEL(battable)@l
216 1.18 thorpej stw %r5,CI_BATTABLE(%r4)
217 1.18 thorpej
218 1.19 thorpej lis %r4,clsrsave@ha /* restore saved SRs */
219 1.19 thorpej addi %r4,%r4,clsrsave@l
220 1.7 garbled li %r5,0
221 1.7 garbled 1: lwz %r0,0(%r4)
222 1.7 garbled mtsrin %r0,%r5
223 1.7 garbled addi %r4,%r4,4
224 1.7 garbled addis %r5,%r5,0x10000000@h
225 1.7 garbled cmpwi %r5,0
226 1.1 matt bne 1b
227 1.1 matt
228 1.7 garbled lwz %r4,8(%r1) /* restore msr */
229 1.7 garbled mtmsr %r4
230 1.1 matt isync
231 1.6 garbled 4:
232 1.14 thorpej addi %r1,%r1,48 /* pop stack frame and save area */
233 1.14 thorpej lwz %r0,4(%r1) /* return address */
234 1.14 thorpej mtlr %r0
235 1.14 thorpej blr
236 1.14 thorpej
237 1.14 thorpej /*
238 1.14 thorpej * Call into OpenFirmware.
239 1.14 thorpej */
240 1.14 thorpej ENTRY_NOPROFILE(openfirmware)
241 1.14 thorpej mflr %r0
242 1.14 thorpej stw %r0,4(%r1) /* save return address */
243 1.14 thorpej
244 1.14 thorpej /* Switch to OpenFirmware stack. */
245 1.14 thorpej lis %r7,firmstk+NBPG-16@ha
246 1.14 thorpej addi %r7,%r7,firmstk+NBPG-16@l
247 1.14 thorpej stw %r1,0(%r7) /* stash away prev stack pointer */
248 1.14 thorpej mr %r1,%r7
249 1.14 thorpej
250 1.14 thorpej lis %r4,oftramp@ha
251 1.14 thorpej lwz %r4,oftramp@l(%r4)
252 1.14 thorpej
253 1.14 thorpej mtctr %r4
254 1.14 thorpej bctrl
255 1.14 thorpej
256 1.14 thorpej lwz %r1,0(%r1) /* restore previous stack pointer */
257 1.13 thorpej lwz %r0,4(%r1) /* return address */
258 1.7 garbled mtlr %r0
259 1.1 matt blr
260