ofw_subr.S revision 1.13 1 1.13 thorpej /* $NetBSD: ofw_subr.S,v 1.13 2021/02/13 01:48:33 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.1 matt .local firmstk
39 1.3 sanjayl .globl openfirmware_entry
40 1.10 macallan .globl ofwmsr
41 1.1 matt .local ofwsrsave
42 1.1 matt .local OF_buffer
43 1.1 matt
44 1.9 matt .lcomm firmstk,NBPG,16
45 1.11 macallan .lcomm OF_buffer,NBPG + 36,4
46 1.1 matt .comm openfirmware_entry,4,4 /* openfirmware entry point */
47 1.9 matt .lcomm ofwsrsave,64,4 /* openfirmware SR savearea */
48 1.10 macallan .comm ofwmsr,20,4 /* msr & sprg[0-3] used in OF */
49 1.9 matt .comm ofwreal_incharge,4,4
50 1.1 matt
51 1.1 matt /*
52 1.1 matt * Called by start to save the initial OFW state so we can restore it
53 1.1 matt * when call back to OFW.
54 1.1 matt */
55 1.1 matt ENTRY_NOPROFILE(ofwinit)
56 1.1 matt #ifdef FIRMWORKSBUGS
57 1.7 garbled mfmsr %r0
58 1.7 garbled andi. %r0,%r0,PSL_IR|PSL_DR
59 1.1 matt beq 1f
60 1.1 matt
61 1.7 garbled li %r8,1
62 1.7 garbled lis %r9,ofwreal_incharge@ha
63 1.9 matt stw %r8,ofwreal_incharge@l(%r9)
64 1.4 aymeric
65 1.7 garbled mflr %r30
66 1.1 matt bl _C_LABEL(ofwr_init)
67 1.7 garbled mtlr %r30
68 1.1 matt 1:
69 1.1 matt #endif
70 1.7 garbled lis %r8,openfirmware_entry@ha
71 1.7 garbled stw %r5,openfirmware_entry@l(%r8) /* save client interface handler*/
72 1.1 matt
73 1.7 garbled mfmsr %r0
74 1.10 macallan /*
75 1.10 macallan * XXX
76 1.10 macallan * doing this here instead of later on in ofwoea_initppc() after setting
77 1.10 macallan * up the console and such makes my PowerBook 3400c hang.
78 1.10 macallan * Probably just another OF 2.0 weirdness
79 1.10 macallan */
80 1.10 macallan /*li %r8,PSL_IP*/
81 1.10 macallan /*andc %r0,%r0,%r8*/ /* make sure PSL_IP is off */
82 1.9 matt lis %r9,ofwmsr@ha
83 1.9 matt stwu %r0,ofwmsr@l(%r9) /* save initial MSR value */
84 1.9 matt
85 1.9 matt mfsprg0 %r0 /* save SPRGs */
86 1.9 matt stw %r0,4(%r9)
87 1.9 matt mfsprg1 %r0
88 1.9 matt stw %r0,8(%r9)
89 1.9 matt mfsprg2 %r0
90 1.9 matt stw %r0,12(%r9)
91 1.9 matt mfsprg3 %r0
92 1.9 matt stw %r0,16(%r9)
93 1.7 garbled
94 1.7 garbled lis %r8,OF_buffer@ha
95 1.7 garbled addi %r8,%r8,OF_buffer@l
96 1.7 garbled lis %r9,_C_LABEL(OF_buf)@ha
97 1.7 garbled stw %r8,_C_LABEL(OF_buf)@l(%r9)
98 1.1 matt
99 1.1 matt blr
100 1.1 matt
101 1.1 matt /*
102 1.1 matt * OpenFirmware entry point
103 1.1 matt */
104 1.1 matt .text
105 1.1 matt ENTRY(openfirmware)
106 1.13 thorpej mflr %r0
107 1.13 thorpej stw %r0,4(%r1) /* save return address */
108 1.13 thorpej
109 1.13 thorpej /*
110 1.13 thorpej * Switch to OpenFirmware stack.
111 1.13 thorpej *
112 1.13 thorpej * -48 == -16 to stack old SP and align, -32 for save area
113 1.13 thorpej */
114 1.13 thorpej lis %r7,firmstk+NBPG-48@ha
115 1.13 thorpej addi %r7,%r7,firmstk+NBPG-48@l
116 1.13 thorpej stw %r1,32(%r7) /* stash away prev stack pointer */
117 1.13 thorpej mr %r1,%r7
118 1.7 garbled
119 1.7 garbled lis %r4,openfirmware_entry@ha /* get firmware entry point */
120 1.7 garbled lwz %r4,openfirmware_entry@l(%r4)
121 1.7 garbled mtlr %r4
122 1.7 garbled
123 1.9 matt mfsprg0 %r5 /* save current sprg0 (curcpu) */
124 1.9 matt stw %r5,16(%r1)
125 1.9 matt mfsprg1 %r5 /* save current sprg1 */
126 1.9 matt stw %r5,20(%r1)
127 1.9 matt mfsprg2 %r5 /* save current sprg1 */
128 1.9 matt stw %r5,24(%r1)
129 1.9 matt mfsprg3 %r5 /* save current sprg3 */
130 1.9 matt stw %r5,28(%r1)
131 1.4 aymeric
132 1.4 aymeric #ifdef FIRMWORKSBUGS
133 1.7 garbled lis %r4,ofwreal_incharge@ha
134 1.7 garbled lwz %r4,ofwreal_incharge@l(%r4)
135 1.7 garbled cmpwi %r4,1
136 1.4 aymeric bne 1f
137 1.4 aymeric blrl
138 1.6 garbled b 4f
139 1.4 aymeric 1:
140 1.6 garbled #endif
141 1.7 garbled mfmsr %r4 /* save msr */
142 1.7 garbled stw %r4,8(%r1)
143 1.4 aymeric
144 1.7 garbled li %r0,0 /* clear battable translations */
145 1.8 garbled mtmsr %r0
146 1.6 garbled #if defined (PPC_OEA) || defined (PPC_OEA64_BRIDGE)
147 1.7 garbled mtdbatu 2,%r0
148 1.7 garbled mtdbatu 3,%r0
149 1.7 garbled mtibatu 2,%r0
150 1.7 garbled mtibatu 3,%r0
151 1.3 sanjayl #endif /* PPC_OEA */
152 1.1 matt
153 1.7 garbled lis %r4,ofwsrsave@ha /* save current SRs */
154 1.7 garbled addi %r4,%r4,ofwsrsave@l
155 1.7 garbled li %r5,0
156 1.7 garbled 1: mfsrin %r0,%r5
157 1.7 garbled stw %r0,0(%r4)
158 1.7 garbled addi %r4,%r4,4
159 1.7 garbled addis %r5,%r5,0x10000000@h
160 1.7 garbled cmpwi %r5,0
161 1.1 matt bne 1b
162 1.1 matt
163 1.7 garbled lis %r4,_C_LABEL(ofw_pmap)@ha /* load OFW SR */
164 1.7 garbled addi %r4,%r4,_C_LABEL(ofw_pmap)@l
165 1.7 garbled lwz %r0,PM_KERNELSR(%r4)
166 1.7 garbled cmpwi %r0,0 /* pm_sr[KERNEL_SR] == 0? */
167 1.1 matt beq 2f /* then skip (not initialized yet) */
168 1.7 garbled li %r5,0
169 1.7 garbled 1: lwz %r0,0(%r4)
170 1.7 garbled mtsrin %r0,%r5
171 1.7 garbled addi %r4,%r4,4
172 1.7 garbled addis %r5,%r5,0x10000000@h
173 1.7 garbled cmpwi %r5,0
174 1.1 matt bne 1b
175 1.1 matt 2:
176 1.9 matt lis %r4,ofwmsr+16@ha /* Open Firmware msr + sprg[0-3] */
177 1.9 matt lwzu %r5,ofwmsr+16@l(%r4)
178 1.9 matt mtsprg3 %r5
179 1.7 garbled lwz %r5,-4(%r4)
180 1.9 matt mtsprg2 %r5
181 1.9 matt lwz %r5,-8(%r4)
182 1.9 matt mtsprg1 %r5
183 1.9 matt lwz %r5,-12(%r4)
184 1.9 matt mtsprg0 %r5
185 1.9 matt lwz %r5,-16(%r4)
186 1.7 garbled mtmsr %r5
187 1.1 matt isync
188 1.1 matt
189 1.1 matt blrl /* call Open Firmware */
190 1.1 matt
191 1.7 garbled lis %r4,ofwsrsave@ha /* restore saved SRs */
192 1.7 garbled addi %r4,%r4,ofwsrsave@l
193 1.7 garbled li %r5,0
194 1.7 garbled 1: lwz %r0,0(%r4)
195 1.7 garbled mtsrin %r0,%r5
196 1.7 garbled addi %r4,%r4,4
197 1.7 garbled addis %r5,%r5,0x10000000@h
198 1.7 garbled cmpwi %r5,0
199 1.1 matt bne 1b
200 1.1 matt
201 1.7 garbled lwz %r4,8(%r1) /* restore msr */
202 1.7 garbled mtmsr %r4
203 1.1 matt isync
204 1.6 garbled 4:
205 1.9 matt lwz %r5,16(%r1) /* restore saved sprgs (curcpu) */
206 1.9 matt mtsprg0 %r5
207 1.9 matt lwz %r5,20(%r1)
208 1.9 matt mtsprg1 %r5
209 1.9 matt lwz %r5,24(%r1)
210 1.9 matt mtsprg2 %r5
211 1.9 matt lwz %r5,28(%r1)
212 1.9 matt mtsprg3 %r5
213 1.7 garbled
214 1.13 thorpej lwz %r1,32(%r1) /* restore previous stack pointer */
215 1.13 thorpej lwz %r0,4(%r1) /* return address */
216 1.7 garbled mtlr %r0
217 1.1 matt blr
218