Tue Mar 30 14:33:10 2021 UTC ()
Use ``for (;;)'' for infinite loop, as required by style.
No binary changes.


(rin)
diff -r1.36 -r1.37 src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c

cvs diff -r1.36 -r1.37 src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c (switch to unified diff)

--- src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c 2021/03/30 01:33:50 1.36
+++ src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c 2021/03/30 14:33:10 1.37
@@ -1,412 +1,412 @@ @@ -1,412 +1,412 @@
1/* $NetBSD: ibm4xx_machdep.c,v 1.36 2021/03/30 01:33:50 rin Exp $ */ 1/* $NetBSD: ibm4xx_machdep.c,v 1.37 2021/03/30 14:33:10 rin Exp $ */
2/* Original: ibm40x_machdep.c,v 1.3 2005/01/17 17:19:36 shige Exp $ */ 2/* Original: ibm40x_machdep.c,v 1.3 2005/01/17 17:19:36 shige Exp $ */
3 3
4/* 4/*
5 * Copyright 2001, 2002 Wasabi Systems, Inc. 5 * Copyright 2001, 2002 Wasabi Systems, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. 8 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software 18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement: 19 * must display the following acknowledgement:
20 * This product includes software developed for the NetBSD Project by 20 * This product includes software developed for the NetBSD Project by
21 * Wasabi Systems, Inc. 21 * Wasabi Systems, Inc.
22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior 23 * or promote products derived from this software without specific prior
24 * written permission. 24 * written permission.
25 * 25 *
26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE. 36 * POSSIBILITY OF SUCH DAMAGE.
37 */ 37 */
38 38
39/* 39/*
40 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 40 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
41 * Copyright (C) 1995, 1996 TooLs GmbH. 41 * Copyright (C) 1995, 1996 TooLs GmbH.
42 * All rights reserved. 42 * All rights reserved.
43 * 43 *
44 * Redistribution and use in source and binary forms, with or without 44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions 45 * modification, are permitted provided that the following conditions
46 * are met: 46 * are met:
47 * 1. Redistributions of source code must retain the above copyright 47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer. 48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright 49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the 50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution. 51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software 52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement: 53 * must display the following acknowledgement:
54 * This product includes software developed by TooLs GmbH. 54 * This product includes software developed by TooLs GmbH.
55 * 4. The name of TooLs GmbH may not be used to endorse or promote products 55 * 4. The name of TooLs GmbH may not be used to endorse or promote products
56 * derived from this software without specific prior written permission. 56 * derived from this software without specific prior written permission.
57 * 57 *
58 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 58 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 61 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 62 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
63 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 63 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
64 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 64 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
65 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 65 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
66 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 66 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
67 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 67 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 */ 68 */
69 69
70#include <sys/cdefs.h> 70#include <sys/cdefs.h>
71__KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.36 2021/03/30 01:33:50 rin Exp $"); 71__KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.37 2021/03/30 14:33:10 rin Exp $");
72 72
73#include "ksyms.h" 73#include "ksyms.h"
74 74
75#ifdef _KERNEL_OPT 75#ifdef _KERNEL_OPT
76#include "opt_ddb.h" 76#include "opt_ddb.h"
77#include "opt_kgdb.h" 77#include "opt_kgdb.h"
78#include "opt_modular.h" 78#include "opt_modular.h"
79#endif 79#endif
80 80
81#include <sys/param.h> 81#include <sys/param.h>
82#include <sys/cpu.h> 82#include <sys/cpu.h>
83#include <sys/ksyms.h> 83#include <sys/ksyms.h>
84#include <sys/mount.h> 84#include <sys/mount.h>
85#include <sys/msgbuf.h> 85#include <sys/msgbuf.h>
86#include <sys/pmf.h> 86#include <sys/pmf.h>
87#include <sys/proc.h> 87#include <sys/proc.h>
88#include <sys/reboot.h> 88#include <sys/reboot.h>
89#include <sys/systm.h> 89#include <sys/systm.h>
90 90
91#include <dev/cons.h> 91#include <dev/cons.h>
92 92
93#include <uvm/uvm_extern.h> 93#include <uvm/uvm_extern.h>
94 94
95#if defined(DDB) 95#if defined(DDB)
96#include <machine/db_machdep.h> 96#include <machine/db_machdep.h>
97#include <ddb/db_extern.h> 97#include <ddb/db_extern.h>
98#endif 98#endif
99 99
100#if defined(KGDB) 100#if defined(KGDB)
101#include <sys/kgdb.h> 101#include <sys/kgdb.h>
102#endif 102#endif
103 103
104#include <machine/powerpc.h> 104#include <machine/powerpc.h>
105#include <machine/trap.h> 105#include <machine/trap.h>
106 106
107#include <powerpc/pcb.h> 107#include <powerpc/pcb.h>
108#include <powerpc/spr.h> 108#include <powerpc/spr.h>
109 109
110#include <powerpc/ibm4xx/cpu.h> 110#include <powerpc/ibm4xx/cpu.h>
111#include <powerpc/ibm4xx/spr.h> 111#include <powerpc/ibm4xx/spr.h>
112 112
113/* 113/*
114 * Global variables used here and there 114 * Global variables used here and there
115 */ 115 */
116paddr_t msgbuf_paddr; 116paddr_t msgbuf_paddr;
117vaddr_t msgbuf_vaddr; 117vaddr_t msgbuf_vaddr;
118char msgbuf[MSGBUFSIZE]; 118char msgbuf[MSGBUFSIZE];
119 119
120#if NKSYMS || defined(DDB) || defined(MODULAR) 120#if NKSYMS || defined(DDB) || defined(MODULAR)
121void *startsym, *endsym; 121void *startsym, *endsym;
122#endif 122#endif
123 123
124#ifdef MODULAR 124#ifdef MODULAR
125register_t cpu_psluserset = PSL_USERSET; 125register_t cpu_psluserset = PSL_USERSET;
126register_t cpu_pslusermod = PSL_USERMOD; 126register_t cpu_pslusermod = PSL_USERMOD;
127register_t cpu_pslusermask = PSL_USERMASK; 127register_t cpu_pslusermask = PSL_USERMASK;
128#endif 128#endif
129 129
130/* 130/*
131 * Trap vectors 131 * Trap vectors
132 */ 132 */
133extern const uint32_t defaulttrap[], defaultsize; 133extern const uint32_t defaulttrap[], defaultsize;
134extern const uint32_t sctrap[], scsize; 134extern const uint32_t sctrap[], scsize;
135extern const uint32_t accesstrap[], accesssize; 135extern const uint32_t accesstrap[], accesssize;
136extern const uint32_t criticaltrap[], criticalsize; 136extern const uint32_t criticaltrap[], criticalsize;
137extern const uint32_t tlbimiss4xx[], tlbim4size; 137extern const uint32_t tlbimiss4xx[], tlbim4size;
138extern const uint32_t tlbdmiss4xx[], tlbdm4size; 138extern const uint32_t tlbdmiss4xx[], tlbdm4size;
139extern const uint32_t pitfitwdog[], pitfitwdogsize; 139extern const uint32_t pitfitwdog[], pitfitwdogsize;
140extern const uint32_t errata51handler[], errata51size; 140extern const uint32_t errata51handler[], errata51size;
141#if defined(DDB) 141#if defined(DDB)
142extern const uint32_t ddblow[], ddbsize; 142extern const uint32_t ddblow[], ddbsize;
143#endif 143#endif
144static const struct exc_info trap_table[] = { 144static const struct exc_info trap_table[] = {
145 { EXC_SC, sctrap, (uintptr_t)&scsize }, 145 { EXC_SC, sctrap, (uintptr_t)&scsize },
146 { EXC_ALI, accesstrap, (uintptr_t)&accesssize }, 146 { EXC_ALI, accesstrap, (uintptr_t)&accesssize },
147 { EXC_DSI, accesstrap, (uintptr_t)&accesssize }, 147 { EXC_DSI, accesstrap, (uintptr_t)&accesssize },
148 { EXC_MCHK, criticaltrap, (uintptr_t)&criticalsize }, 148 { EXC_MCHK, criticaltrap, (uintptr_t)&criticalsize },
149 { EXC_ITMISS, tlbimiss4xx, (uintptr_t)&tlbim4size }, 149 { EXC_ITMISS, tlbimiss4xx, (uintptr_t)&tlbim4size },
150 { EXC_DTMISS, tlbdmiss4xx, (uintptr_t)&tlbdm4size }, 150 { EXC_DTMISS, tlbdmiss4xx, (uintptr_t)&tlbdm4size },
151 { EXC_PIT, pitfitwdog, (uintptr_t)&pitfitwdogsize }, 151 { EXC_PIT, pitfitwdog, (uintptr_t)&pitfitwdogsize },
152 { EXC_DEBUG, criticaltrap, (uintptr_t)&criticalsize }, 152 { EXC_DEBUG, criticaltrap, (uintptr_t)&criticalsize },
153 { (EXC_DTMISS|EXC_ALI), 153 { (EXC_DTMISS|EXC_ALI),
154 errata51handler, (uintptr_t)&errata51size }, 154 errata51handler, (uintptr_t)&errata51size },
155#if defined(DDB) 155#if defined(DDB)
156 { EXC_PGM, ddblow, (uintptr_t)&ddbsize }, 156 { EXC_PGM, ddblow, (uintptr_t)&ddbsize },
157#else 157#else
158 { EXC_PGM, accesstrap, (uintptr_t)&accesssize }, 158 { EXC_PGM, accesstrap, (uintptr_t)&accesssize },
159#endif 159#endif
160}; 160};
161 161
162void 162void
163cpu_reboot(int howto, char *what) 163cpu_reboot(int howto, char *what)
164{ 164{
165 static int syncing; 165 static int syncing;
166 static char str[256]; 166 static char str[256];
167 char *ap = str, *ap1 = ap; 167 char *ap = str, *ap1 = ap;
168 168
169 boothowto = howto; 169 boothowto = howto;
170 if (!cold && !(howto & RB_NOSYNC) && !syncing) { 170 if (!cold && !(howto & RB_NOSYNC) && !syncing) {
171 syncing = 1; 171 syncing = 1;
172 vfs_shutdown(); /* sync */ 172 vfs_shutdown(); /* sync */
173 resettodr(); /* set wall clock */ 173 resettodr(); /* set wall clock */
174 } 174 }
175 175
176 splhigh(); 176 splhigh();
177 177
178 if (!cold && (howto & RB_DUMP)) 178 if (!cold && (howto & RB_DUMP))
179 ibm4xx_dumpsys(); 179 ibm4xx_dumpsys();
180 180
181 doshutdownhooks(); 181 doshutdownhooks();
182 182
183 pmf_system_shutdown(boothowto); 183 pmf_system_shutdown(boothowto);
184 184
185 if ((howto & RB_POWERDOWN) == RB_POWERDOWN) { 185 if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
186 /* Power off here if we know how... */ 186 /* Power off here if we know how... */
187 } 187 }
188 188
189 if (howto & RB_HALT) { 189 if (howto & RB_HALT) {
190 printf("The operating system has halted.\n" 190 printf("The operating system has halted.\n"
191 "Press any key to reboot.\n\n"); 191 "Press any key to reboot.\n\n");
192 192
193 cnpollc(1); 193 cnpollc(1);
194 cngetc(); 194 cngetc();
195 cnpollc(0); 195 cnpollc(0);
196 } 196 }
197 197
198 printf("rebooting...\n\n"); 198 printf("rebooting...\n\n");
199 if (what && *what) { 199 if (what && *what) {
200 if (strlen(what) > sizeof(str) - 5) 200 if (strlen(what) > sizeof(str) - 5)
201 printf("boot string too large, ignored\n"); 201 printf("boot string too large, ignored\n");
202 else { 202 else {
203 strcpy(str, what); 203 strcpy(str, what);
204 ap1 = ap = str + strlen(str); 204 ap1 = ap = str + strlen(str);
205 *ap++ = ' '; 205 *ap++ = ' ';
206 } 206 }
207 } 207 }
208 *ap++ = '-'; 208 *ap++ = '-';
209 if (howto & RB_SINGLE) 209 if (howto & RB_SINGLE)
210 *ap++ = 's'; 210 *ap++ = 's';
211 if (howto & RB_KDB) 211 if (howto & RB_KDB)
212 *ap++ = 'd'; 212 *ap++ = 'd';
213 *ap++ = '\0'; 213 *ap++ = '\0';
214 if (ap[-2] == '-') 214 if (ap[-2] == '-')
215 *ap1 = '\0'; 215 *ap1 = '\0';
216 216
217 /* flush cache for msgbuf */ 217 /* flush cache for msgbuf */
218 __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE)); 218 __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
219 219
220 ppc4xx_reset(); 220 ppc4xx_reset();
221 221
222 printf("ppc4xx_reset() failed!\n"); 222 printf("ppc4xx_reset() failed!\n");
223 223
224 while (1 /* CONSTCOND */) { 224 for (;;) {
225#if defined(DDB) 225#if defined(DDB)
226 Debugger(); 226 Debugger();
227#elif defined(KGDB) 227#elif defined(KGDB)
228 kgdb_connect(1); 228 kgdb_connect(1);
229#else 229#else
230 continue; 230 continue;
231#endif 231#endif
232 } 232 }
233} 233}
234 234
235/* 235/*
236 * Install a trap vector. We cannot use memcpy because the 236 * Install a trap vector. We cannot use memcpy because the
237 * destination may be zero. 237 * destination may be zero.
238 */ 238 */
239static void 239static void
240trap_copy(const uint32_t *src, vaddr_t dest, size_t len) 240trap_copy(const uint32_t *src, vaddr_t dest, size_t len)
241{ 241{
242 uint32_t *dest_p = (void *)dest; 242 uint32_t *dest_p = (void *)dest;
243 243
244 while (len > 0) { 244 while (len > 0) {
245 *dest_p++ = *src++; 245 *dest_p++ = *src++;
246 len -= sizeof(uint32_t); 246 len -= sizeof(uint32_t);
247 } 247 }
248} 248}
249 249
250/* 250/*
251 * ibm4xx_init: 251 * ibm4xx_init:
252 */ 252 */
253void 253void
254ibm4xx_init(vaddr_t startkernel, vaddr_t endkernel, void (*handler)(void)) 254ibm4xx_init(vaddr_t startkernel, vaddr_t endkernel, void (*handler)(void))
255{ 255{
256 /* Initialize cache info for memcpy, etc. */ 256 /* Initialize cache info for memcpy, etc. */
257 cpu_probe_cache(); 257 cpu_probe_cache();
258 258
259 /* 259 /*
260 * Initialize current pcb and pmap pointers. 260 * Initialize current pcb and pmap pointers.
261 */ 261 */
262 KASSERT(curcpu() == &cpu_info[0]); 262 KASSERT(curcpu() == &cpu_info[0]);
263 KASSERT(lwp0.l_cpu == curcpu()); 263 KASSERT(lwp0.l_cpu == curcpu());
264 KASSERT(curlwp == &lwp0); 264 KASSERT(curlwp == &lwp0);
265 265
266 curpcb = lwp_getpcb(curlwp); 266 curpcb = lwp_getpcb(curlwp);
267 memset(curpcb, 0, sizeof(struct pcb)); 267 memset(curpcb, 0, sizeof(struct pcb));
268 268
269 curpcb->pcb_pm = pmap_kernel(); 269 curpcb->pcb_pm = pmap_kernel();
270 270
271 for (uintptr_t exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100) { 271 for (uintptr_t exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100) {
272 trap_copy(defaulttrap, exc, (uintptr_t)&defaultsize); 272 trap_copy(defaulttrap, exc, (uintptr_t)&defaultsize);
273 } 273 }
274 274
275 for (size_t i = 0; i < __arraycount(trap_table); i++) { 275 for (size_t i = 0; i < __arraycount(trap_table); i++) {
276 KASSERT(trap_table[i].exc_size <= 0x100); 276 KASSERT(trap_table[i].exc_size <= 0x100);
277 trap_copy(trap_table[i].exc_addr, trap_table[i].exc_vector, 277 trap_copy(trap_table[i].exc_addr, trap_table[i].exc_vector,
278 trap_table[i].exc_size); 278 trap_table[i].exc_size);
279 } 279 }
280 280
281 __syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100); 281 __syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
282 282
283 mtspr(SPR_EVPR, 0); /* Set Exception vector base */ 283 mtspr(SPR_EVPR, 0); /* Set Exception vector base */
284 284
285 /* Handle trap instruction as PGM exception */ 285 /* Handle trap instruction as PGM exception */
286 mtspr(SPR_DBCR0, mfspr(SPR_DBCR0) & ~DBCR0_TDE); 286 mtspr(SPR_DBCR0, mfspr(SPR_DBCR0) & ~DBCR0_TDE);
287 287
288 /* 288 /*
289 * external interrupt handler install 289 * external interrupt handler install
290 */ 290 */
291 if (handler) 291 if (handler)
292 ibm4xx_install_extint(handler); 292 ibm4xx_install_extint(handler);
293 293
294 /* 294 /*
295 * Now enable translation (and machine checks/recoverable interrupts). 295 * Now enable translation (and machine checks/recoverable interrupts).
296 */ 296 */
297 __asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync" 297 __asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
298 : : "r"(0), "K"(PSL_IR|PSL_DR)); 298 : : "r"(0), "K"(PSL_IR|PSL_DR));
299 /* XXXX PSL_ME - With ME set kernel gets stuck... */ 299 /* XXXX PSL_ME - With ME set kernel gets stuck... */
300 300
301 /* 301 /*
302 * turn on console after enable translation 302 * turn on console after enable translation
303 */ 303 */
304 consinit(); 304 consinit();
305 305
306 uvm_md_init(); 306 uvm_md_init();
307 307
308 /* 308 /*
309 * Initialize pmap module. 309 * Initialize pmap module.
310 */ 310 */
311 pmap_bootstrap(startkernel, endkernel); 311 pmap_bootstrap(startkernel, endkernel);
312 312
313 /* 313 /*
314 * Let's take all the indirect calls via our stubs and patch 314 * Let's take all the indirect calls via our stubs and patch
315 * them to be direct calls. 315 * them to be direct calls.
316 */ 316 */
317 cpu_fixup_stubs(); 317 cpu_fixup_stubs();
318 318
319#if NKSYMS || defined(DDB) || defined(MODULAR) 319#if NKSYMS || defined(DDB) || defined(MODULAR)
320 ksyms_addsyms_elf((uintptr_t)endsym - (uintptr_t)startsym, 320 ksyms_addsyms_elf((uintptr_t)endsym - (uintptr_t)startsym,
321 startsym, endsym); 321 startsym, endsym);
322#endif 322#endif
323} 323}
324 324
325void 325void
326ibm4xx_install_extint(void (*handler)(void)) 326ibm4xx_install_extint(void (*handler)(void))
327{ 327{
328 extern int extint, extsize; 328 extern int extint, extsize;
329 extern u_long extint_call; 329 extern u_long extint_call;
330 u_long offset = (u_long)handler - (u_long)&extint_call; 330 u_long offset = (u_long)handler - (u_long)&extint_call;
331 int msr; 331 int msr;
332 332
333#ifdef DIAGNOSTIC 333#ifdef DIAGNOSTIC
334 if (offset > 0x1ffffff) 334 if (offset > 0x1ffffff)
335 panic("install_extint: too far away"); 335 panic("install_extint: too far away");
336#endif 336#endif
337 __asm volatile ("mfmsr %0; wrteei 0" : "=r"(msr)); 337 __asm volatile ("mfmsr %0; wrteei 0" : "=r"(msr));
338 extint_call = (extint_call & 0xfc000003) | offset; 338 extint_call = (extint_call & 0xfc000003) | offset;
339 memcpy((void *)EXC_EXI, &extint, (size_t)&extsize); 339 memcpy((void *)EXC_EXI, &extint, (size_t)&extsize);
340 __syncicache((void *)&extint_call, sizeof extint_call); 340 __syncicache((void *)&extint_call, sizeof extint_call);
341 __syncicache((void *)EXC_EXI, (int)&extsize); 341 __syncicache((void *)EXC_EXI, (int)&extsize);
342 __asm volatile ("mtmsr %0" :: "r"(msr)); 342 __asm volatile ("mtmsr %0" :: "r"(msr));
343} 343}
344 344
345/* 345/*
346 * ibm4xx_cpu_startup: 346 * ibm4xx_cpu_startup:
347 * Machine dependent startup code. 347 * Machine dependent startup code.
348 */ 348 */
349void 349void
350ibm4xx_cpu_startup(const char *model) 350ibm4xx_cpu_startup(const char *model)
351{ 351{
352 vaddr_t minaddr, maxaddr; 352 vaddr_t minaddr, maxaddr;
353 char pbuf[9]; 353 char pbuf[9];
354 354
355 KASSERT(curcpu() != NULL); 355 KASSERT(curcpu() != NULL);
356 KASSERT(lwp0.l_cpu != NULL); 356 KASSERT(lwp0.l_cpu != NULL);
357 KASSERT(curcpu()->ci_intstk != 0); 357 KASSERT(curcpu()->ci_intstk != 0);
358 KASSERT(curcpu()->ci_idepth == -1); 358 KASSERT(curcpu()->ci_idepth == -1);
359 359
360 /* 360 /*
361 * Initialize error message buffer (at end of core). 361 * Initialize error message buffer (at end of core).
362 */ 362 */
363#if 0 /* For some reason this fails... --Artem 363#if 0 /* For some reason this fails... --Artem
364 * Besides, do we really have to put it at the end of core? 364 * Besides, do we really have to put it at the end of core?
365 * Let's use static buffer for now 365 * Let's use static buffer for now
366 */ 366 */
367 if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE), 367 if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE),
368 0, UVM_KMF_VAONLY))) 368 0, UVM_KMF_VAONLY)))
369 panic("startup: no room for message buffer"); 369 panic("startup: no room for message buffer");
370 for (i = 0; i < btoc(MSGBUFSIZE); i++) 370 for (i = 0; i < btoc(MSGBUFSIZE); i++)
371 pmap_kenter_pa(msgbuf_vaddr + i * PAGE_SIZE, 371 pmap_kenter_pa(msgbuf_vaddr + i * PAGE_SIZE,
372 msgbuf_paddr + i * PAGE_SIZE, 372 msgbuf_paddr + i * PAGE_SIZE,
373 VM_PROT_READ|VM_PROT_WRITE, 0); 373 VM_PROT_READ|VM_PROT_WRITE, 0);
374 initmsgbuf((void *)msgbuf_vaddr, round_page(MSGBUFSIZE)); 374 initmsgbuf((void *)msgbuf_vaddr, round_page(MSGBUFSIZE));
375#else 375#else
376 initmsgbuf((void *)msgbuf, round_page(MSGBUFSIZE)); 376 initmsgbuf((void *)msgbuf, round_page(MSGBUFSIZE));
377#endif 377#endif
378 378
379 printf("%s%s", copyright, version); 379 printf("%s%s", copyright, version);
380 if (model != NULL) 380 if (model != NULL)
381 printf("Model: %s\n", model); 381 printf("Model: %s\n", model);
382 382
383 format_bytes(pbuf, sizeof(pbuf), ctob(physmem)); 383 format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
384 printf("total memory = %s\n", pbuf); 384 printf("total memory = %s\n", pbuf);
385 385
386 minaddr = 0; 386 minaddr = 0;
387 /* 387 /*
388 * Allocate a submap for physio 388 * Allocate a submap for physio
389 */ 389 */
390 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, 390 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
391 VM_PHYS_SIZE, 0, false, NULL); 391 VM_PHYS_SIZE, 0, false, NULL);
392 392
393 /* 393 /*
394 * No need to allocate an mbuf cluster submap. Mbuf clusters 394 * No need to allocate an mbuf cluster submap. Mbuf clusters
395 * are allocated via the pool allocator, and we use direct-mapped 395 * are allocated via the pool allocator, and we use direct-mapped
396 * pool pages. 396 * pool pages.
397 */ 397 */
398 398
399 format_bytes(pbuf, sizeof(pbuf), ptoa(uvm_availmem(false))); 399 format_bytes(pbuf, sizeof(pbuf), ptoa(uvm_availmem(false)));
400 printf("avail memory = %s\n", pbuf); 400 printf("avail memory = %s\n", pbuf);
401} 401}
402 402
403/* 403/*
404 * ibm4xx_dumpsys: 404 * ibm4xx_dumpsys:
405 * Crash dump handling. 405 * Crash dump handling.
406 */ 406 */
407void 407void
408ibm4xx_dumpsys(void) 408ibm4xx_dumpsys(void)
409{ 409{
410 410
411 printf("dumpsys: TBD\n"); 411 printf("dumpsys: TBD\n");
412} 412}