machdep.c revision 1.72 1 1.72 thorpej /* $NetBSD: machdep.c,v 1.72 2001/10/23 01:36:32 thorpej Exp $ */
2 1.1 ws
3 1.1 ws /*
4 1.1 ws * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 1.1 ws * Copyright (C) 1995, 1996 TooLs GmbH.
6 1.1 ws * All rights reserved.
7 1.1 ws *
8 1.1 ws * Redistribution and use in source and binary forms, with or without
9 1.1 ws * modification, are permitted provided that the following conditions
10 1.1 ws * are met:
11 1.1 ws * 1. Redistributions of source code must retain the above copyright
12 1.1 ws * notice, this list of conditions and the following disclaimer.
13 1.1 ws * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 ws * notice, this list of conditions and the following disclaimer in the
15 1.1 ws * documentation and/or other materials provided with the distribution.
16 1.1 ws * 3. All advertising materials mentioning features or use of this software
17 1.1 ws * must display the following acknowledgement:
18 1.1 ws * This product includes software developed by TooLs GmbH.
19 1.1 ws * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 1.1 ws * derived from this software without specific prior written permission.
21 1.1 ws *
22 1.1 ws * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 1.1 ws * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 ws * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 ws * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 ws * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 1.1 ws * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 1.1 ws * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.1 ws * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 1.1 ws * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 1.1 ws * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 ws */
33 1.21 jonathan
34 1.27 thorpej #include "opt_compat_netbsd.h"
35 1.21 jonathan #include "opt_ddb.h"
36 1.1 ws
37 1.1 ws #include <sys/param.h>
38 1.1 ws #include <sys/buf.h>
39 1.1 ws #include <sys/exec.h>
40 1.1 ws #include <sys/malloc.h>
41 1.1 ws #include <sys/map.h>
42 1.1 ws #include <sys/mbuf.h>
43 1.1 ws #include <sys/mount.h>
44 1.1 ws #include <sys/msgbuf.h>
45 1.1 ws #include <sys/proc.h>
46 1.1 ws #include <sys/reboot.h>
47 1.1 ws #include <sys/syscallargs.h>
48 1.1 ws #include <sys/syslog.h>
49 1.1 ws #include <sys/systm.h>
50 1.43 thorpej #include <sys/kernel.h>
51 1.1 ws #include <sys/user.h>
52 1.59 jdolecek #include <sys/boot_flag.h>
53 1.1 ws
54 1.19 sakamoto #include <uvm/uvm_extern.h>
55 1.19 sakamoto
56 1.1 ws #include <net/netisr.h>
57 1.1 ws
58 1.72 thorpej #include <machine/db_machdep.h>
59 1.72 thorpej #include <ddb/db_extern.h>
60 1.72 thorpej
61 1.70 thorpej #include <dev/ofw/openfirm.h>
62 1.70 thorpej
63 1.68 matt #include <machine/autoconf.h>
64 1.1 ws #include <machine/bat.h>
65 1.1 ws #include <machine/pmap.h>
66 1.1 ws #include <machine/powerpc.h>
67 1.1 ws #include <machine/trap.h>
68 1.54 thorpej
69 1.71 thorpej #include <machine/platform.h>
70 1.71 thorpej
71 1.68 matt #include <dev/cons.h>
72 1.1 ws
73 1.1 ws /*
74 1.1 ws * Global variables used here and there
75 1.1 ws */
76 1.65 chs struct vm_map *exec_map = NULL;
77 1.65 chs struct vm_map *mb_map = NULL;
78 1.65 chs struct vm_map *phys_map = NULL;
79 1.19 sakamoto
80 1.1 ws struct pcb *curpcb;
81 1.1 ws struct pmap *curpm;
82 1.1 ws struct proc *fpuproc;
83 1.1 ws
84 1.1 ws extern struct user *proc0paddr;
85 1.1 ws
86 1.1 ws struct bat battable[16];
87 1.1 ws
88 1.1 ws int astpending;
89 1.1 ws
90 1.1 ws char *bootpath;
91 1.1 ws
92 1.39 thorpej paddr_t msgbuf_paddr;
93 1.39 thorpej vaddr_t msgbuf_vaddr;
94 1.18 sakamoto
95 1.60 thorpej int lcsplx(int); /* called from locore.S */
96 1.60 thorpej
97 1.7 thorpej static int fake_spl __P((void));
98 1.7 thorpej static int fake_splx __P((int));
99 1.7 thorpej static void fake_setsoft __P((void));
100 1.7 thorpej static void fake_clock_return __P((struct clockframe *, int));
101 1.1 ws static void fake_irq_establish __P((int, int, void (*)(void *), void *));
102 1.1 ws
103 1.1 ws struct machvec machine_interface = {
104 1.44 wrstuden fake_spl,
105 1.7 thorpej fake_spl,
106 1.7 thorpej fake_spl,
107 1.7 thorpej fake_spl,
108 1.7 thorpej fake_spl,
109 1.7 thorpej fake_spl,
110 1.7 thorpej fake_spl,
111 1.7 thorpej fake_spl,
112 1.7 thorpej fake_spl,
113 1.7 thorpej fake_spl,
114 1.1 ws fake_splx,
115 1.7 thorpej fake_setsoft,
116 1.7 thorpej fake_setsoft,
117 1.7 thorpej fake_clock_return,
118 1.1 ws fake_irq_establish,
119 1.1 ws };
120 1.1 ws
121 1.71 thorpej void ofppc_bootstrap_console(void);
122 1.70 thorpej
123 1.1 ws void
124 1.1 ws initppc(startkernel, endkernel, args)
125 1.1 ws u_int startkernel, endkernel;
126 1.1 ws char *args;
127 1.1 ws {
128 1.68 matt extern int trapcode, trapsize;
129 1.68 matt extern int alitrap, alisize;
130 1.68 matt extern int dsitrap, dsisize;
131 1.68 matt extern int isitrap, isisize;
132 1.68 matt extern int decrint, decrsize;
133 1.68 matt extern int tlbimiss, tlbimsize;
134 1.68 matt extern int tlbdlmiss, tlbdlmsize;
135 1.68 matt extern int tlbdsmiss, tlbdsmsize;
136 1.14 sakamoto #ifdef DDB
137 1.68 matt extern int ddblow, ddbsize;
138 1.72 thorpej extern void *startsym, *endsym;
139 1.14 sakamoto #endif
140 1.53 ws #ifdef IPKDB
141 1.68 matt extern int ipkdblow, ipkdbsize;
142 1.1 ws #endif
143 1.71 thorpej int exc, scratch;
144 1.1 ws
145 1.1 ws proc0.p_addr = proc0paddr;
146 1.66 wiz memset(proc0.p_addr, 0, sizeof *proc0.p_addr);
147 1.29 sakamoto
148 1.1 ws curpcb = &proc0paddr->u_pcb;
149 1.29 sakamoto
150 1.1 ws curpm = curpcb->pcb_pmreal = curpcb->pcb_pm = pmap_kernel();
151 1.70 thorpej
152 1.71 thorpej /* Initialize the bootstrap console. */
153 1.71 thorpej ofppc_bootstrap_console();
154 1.71 thorpej
155 1.71 thorpej /* Initialize the platform structure. */
156 1.71 thorpej platform_init();
157 1.29 sakamoto
158 1.1 ws /*
159 1.71 thorpej * Now that we know what platform we're running on, initialize
160 1.71 thorpej * the console.
161 1.1 ws */
162 1.71 thorpej (*platform.cons_init)();
163 1.1 ws
164 1.71 thorpej #ifdef __notyet__ /* Needs some rethinking regarding real/virtual OFW */
165 1.1 ws OF_set_callback(callback);
166 1.1 ws #endif
167 1.71 thorpej
168 1.1 ws /*
169 1.1 ws * Initialize BAT registers to unmapped to not generate
170 1.1 ws * overlapping mappings below.
171 1.1 ws */
172 1.1 ws asm volatile ("mtibatu 0,%0" :: "r"(0));
173 1.1 ws asm volatile ("mtibatu 1,%0" :: "r"(0));
174 1.1 ws asm volatile ("mtibatu 2,%0" :: "r"(0));
175 1.1 ws asm volatile ("mtibatu 3,%0" :: "r"(0));
176 1.1 ws asm volatile ("mtdbatu 0,%0" :: "r"(0));
177 1.1 ws asm volatile ("mtdbatu 1,%0" :: "r"(0));
178 1.1 ws asm volatile ("mtdbatu 2,%0" :: "r"(0));
179 1.1 ws asm volatile ("mtdbatu 3,%0" :: "r"(0));
180 1.29 sakamoto
181 1.1 ws /*
182 1.1 ws * Set up initial BAT table to only map the lowest 256 MB area
183 1.1 ws */
184 1.49 thorpej battable[0].batl = BATL(0x00000000, BAT_M, BAT_PP_RW);
185 1.49 thorpej battable[0].batu = BATU(0x00000000, BAT_BL_256M, BAT_Vs);
186 1.1 ws
187 1.1 ws /*
188 1.1 ws * Now setup fixed bat registers
189 1.1 ws *
190 1.1 ws * Note that we still run in real mode, and the BAT
191 1.1 ws * registers were cleared above.
192 1.1 ws */
193 1.1 ws /* IBAT0 used for initial 256 MB segment */
194 1.1 ws asm volatile ("mtibatl 0,%0; mtibatu 0,%1"
195 1.1 ws :: "r"(battable[0].batl), "r"(battable[0].batu));
196 1.1 ws /* DBAT0 used similar */
197 1.1 ws asm volatile ("mtdbatl 0,%0; mtdbatu 0,%1"
198 1.1 ws :: "r"(battable[0].batl), "r"(battable[0].batu));
199 1.29 sakamoto
200 1.1 ws /*
201 1.1 ws * Set up trap vectors
202 1.1 ws */
203 1.1 ws for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
204 1.1 ws switch (exc) {
205 1.1 ws default:
206 1.66 wiz memcpy((void *)exc, &trapcode, (size_t)&trapsize);
207 1.1 ws break;
208 1.1 ws case EXC_EXI:
209 1.1 ws /*
210 1.1 ws * This one is (potentially) installed during autoconf
211 1.1 ws */
212 1.50 danw break;
213 1.50 danw case EXC_ALI:
214 1.66 wiz memcpy((void *)EXC_ALI, &alitrap, (size_t)&alisize);
215 1.1 ws break;
216 1.1 ws case EXC_DSI:
217 1.66 wiz memcpy((void *)EXC_DSI, &dsitrap, (size_t)&dsisize);
218 1.1 ws break;
219 1.1 ws case EXC_ISI:
220 1.66 wiz memcpy((void *)EXC_ISI, &isitrap, (size_t)&isisize);
221 1.1 ws break;
222 1.1 ws case EXC_DECR:
223 1.66 wiz memcpy((void *)EXC_DECR, &decrint, (size_t)&decrsize);
224 1.1 ws break;
225 1.1 ws case EXC_IMISS:
226 1.66 wiz memcpy((void *)EXC_IMISS, &tlbimiss, (size_t)&tlbimsize);
227 1.1 ws break;
228 1.1 ws case EXC_DLMISS:
229 1.66 wiz memcpy((void *)EXC_DLMISS, &tlbdlmiss, (size_t)&tlbdlmsize);
230 1.1 ws break;
231 1.1 ws case EXC_DSMISS:
232 1.66 wiz memcpy((void *)EXC_DSMISS, &tlbdsmiss, (size_t)&tlbdsmsize);
233 1.1 ws break;
234 1.53 ws #if defined(DDB) || defined(IPKDB)
235 1.14 sakamoto case EXC_PGM:
236 1.14 sakamoto case EXC_TRC:
237 1.14 sakamoto case EXC_BPT:
238 1.15 thorpej #if defined(DDB)
239 1.66 wiz memcpy((void *)exc, &ddblow, (size_t)&ddbsize);
240 1.15 thorpej #else
241 1.66 wiz memcpy((void *)exc, &ipkdblow, (size_t)&ipkdbsize);
242 1.14 sakamoto #endif
243 1.1 ws break;
244 1.53 ws #endif /* DDB || IPKDB */
245 1.1 ws }
246 1.1 ws
247 1.38 ws __syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
248 1.1 ws
249 1.1 ws /*
250 1.1 ws * Now enable translation (and machine checks/recoverable interrupts).
251 1.1 ws */
252 1.1 ws asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
253 1.1 ws : "=r"(scratch) : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
254 1.1 ws
255 1.1 ws /*
256 1.1 ws * Parse arg string.
257 1.1 ws */
258 1.1 ws bootpath = args;
259 1.7 thorpej while (*++args && *args != ' ');
260 1.1 ws if (*args) {
261 1.59 jdolecek for(*args++ = 0; *args; args++)
262 1.59 jdolecek BOOT_FLAG(*args, boothowto);
263 1.29 sakamoto }
264 1.1 ws
265 1.72 thorpej /*
266 1.72 thorpej * Set the page size.
267 1.72 thorpej */
268 1.72 thorpej uvm_setpagesize();
269 1.72 thorpej
270 1.72 thorpej /*
271 1.72 thorpej * Initialize pmap module.
272 1.72 thorpej */
273 1.72 thorpej pmap_bootstrap(startkernel, endkernel);
274 1.72 thorpej
275 1.14 sakamoto #ifdef DDB
276 1.72 thorpej ddb_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
277 1.72 thorpej if (boothowto & RB_KDB)
278 1.72 thorpej Debugger();
279 1.14 sakamoto #endif
280 1.53 ws #ifdef IPKDB
281 1.1 ws /*
282 1.4 ws * Now trap to IPKDB
283 1.1 ws */
284 1.4 ws ipkdb_init();
285 1.1 ws if (boothowto & RB_KDB)
286 1.4 ws ipkdb_connect(0);
287 1.1 ws #endif
288 1.1 ws }
289 1.1 ws
290 1.1 ws /*
291 1.1 ws * This should probably be in autoconf! XXX
292 1.1 ws */
293 1.1 ws int cpu;
294 1.9 veego char machine[] = MACHINE; /* from <machine/param.h> */
295 1.9 veego char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
296 1.1 ws
297 1.1 ws void
298 1.1 ws install_extint(handler)
299 1.1 ws void (*handler) __P((void));
300 1.1 ws {
301 1.68 matt extern int extint, extsize;
302 1.1 ws extern u_long extint_call;
303 1.1 ws u_long offset = (u_long)handler - (u_long)&extint_call;
304 1.1 ws int omsr, msr;
305 1.29 sakamoto
306 1.1 ws #ifdef DIAGNOSTIC
307 1.1 ws if (offset > 0x1ffffff)
308 1.1 ws panic("install_extint: too far away");
309 1.1 ws #endif
310 1.7 thorpej asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
311 1.1 ws : "=r"(omsr), "=r"(msr) : "K"((u_short)~PSL_EE));
312 1.1 ws extint_call = (extint_call & 0xfc000003) | offset;
313 1.66 wiz memcpy((void *)EXC_EXI, &extint, (size_t)&extsize);
314 1.38 ws __syncicache((void *)&extint_call, sizeof extint_call);
315 1.38 ws __syncicache((void *)EXC_EXI, (int)&extsize);
316 1.1 ws asm volatile ("mtmsr %0" :: "r"(omsr));
317 1.1 ws }
318 1.1 ws
319 1.1 ws /*
320 1.1 ws * Machine dependent startup code.
321 1.1 ws */
322 1.1 ws void
323 1.1 ws cpu_startup()
324 1.1 ws {
325 1.1 ws int sz, i;
326 1.1 ws caddr_t v;
327 1.26 sakamoto paddr_t minaddr, maxaddr;
328 1.1 ws int base, residual;
329 1.40 lukem char pbuf[9];
330 1.18 sakamoto
331 1.39 thorpej proc0.p_addr = proc0paddr;
332 1.39 thorpej v = (caddr_t)proc0paddr + USPACE;
333 1.39 thorpej
334 1.18 sakamoto /*
335 1.18 sakamoto * Initialize error message buffer (at end of core).
336 1.18 sakamoto */
337 1.39 thorpej if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE))))
338 1.39 thorpej panic("startup: no room for message buffer");
339 1.39 thorpej for (i = 0; i < btoc(MSGBUFSIZE); i++)
340 1.39 thorpej pmap_enter(pmap_kernel(), msgbuf_vaddr + i * NBPG,
341 1.45 thorpej msgbuf_paddr + i * NBPG, VM_PROT_READ|VM_PROT_WRITE,
342 1.45 thorpej VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
343 1.69 chris pmap_update(pmap_kernel());
344 1.39 thorpej initmsgbuf((caddr_t)msgbuf_vaddr, round_page(MSGBUFSIZE));
345 1.1 ws
346 1.3 christos printf("%s", version);
347 1.68 matt cpu_identify(NULL, 0);
348 1.29 sakamoto
349 1.40 lukem format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
350 1.40 lukem printf("total memory = %s\n", pbuf);
351 1.19 sakamoto
352 1.1 ws /*
353 1.1 ws * Find out how much space we need, allocate it,
354 1.1 ws * and then give everything true virtual addresses.
355 1.1 ws */
356 1.40 lukem sz = (int)allocsys(NULL, NULL);
357 1.19 sakamoto if ((v = (caddr_t)uvm_km_zalloc(kernel_map, round_page(sz))) == 0)
358 1.19 sakamoto panic("startup: no room for tables");
359 1.40 lukem if (allocsys(v, NULL) - v != sz)
360 1.1 ws panic("startup: table size inconsistency");
361 1.19 sakamoto
362 1.1 ws /*
363 1.1 ws * Now allocate buffers proper. They are different than the above
364 1.1 ws * in that they usually occupy more virtual memory than physical.
365 1.1 ws */
366 1.1 ws sz = MAXBSIZE * nbuf;
367 1.26 sakamoto if (uvm_map(kernel_map, (vaddr_t *)&buffers, round_page(sz),
368 1.58 thorpej NULL, UVM_UNKNOWN_OFFSET, 0,
369 1.19 sakamoto UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
370 1.63 chs UVM_ADV_NORMAL, 0)) != 0)
371 1.19 sakamoto panic("startup: cannot allocate VM for buffers");
372 1.29 sakamoto minaddr = (vaddr_t)buffers;
373 1.1 ws base = bufpages / nbuf;
374 1.1 ws residual = bufpages % nbuf;
375 1.1 ws if (base >= MAXBSIZE) {
376 1.1 ws /* Don't want to alloc more physical mem than ever needed */
377 1.1 ws base = MAXBSIZE;
378 1.1 ws residual = 0;
379 1.1 ws }
380 1.1 ws for (i = 0; i < nbuf; i++) {
381 1.26 sakamoto vsize_t curbufsize;
382 1.26 sakamoto vaddr_t curbuf;
383 1.19 sakamoto struct vm_page *pg;
384 1.19 sakamoto
385 1.19 sakamoto /*
386 1.19 sakamoto * Each buffer has MAXBSIZE bytes of VM space allocated. Of
387 1.19 sakamoto * that MAXBSIZE space, we allocate and map (base+1) pages
388 1.19 sakamoto * for the first "residual" buffers, and then we allocate
389 1.19 sakamoto * "base" pages for the rest.
390 1.19 sakamoto */
391 1.26 sakamoto curbuf = (vaddr_t) buffers + (i * MAXBSIZE);
392 1.48 ragge curbufsize = NBPG * ((i < residual) ? (base+1) : base);
393 1.19 sakamoto
394 1.19 sakamoto while (curbufsize) {
395 1.36 chs pg = uvm_pagealloc(NULL, 0, NULL, 0);
396 1.19 sakamoto if (pg == NULL)
397 1.19 sakamoto panic("startup: not enough memory for "
398 1.19 sakamoto "buffer cache");
399 1.67 chs pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg),
400 1.67 chs VM_PROT_READ | VM_PROT_WRITE);
401 1.19 sakamoto curbuf += PAGE_SIZE;
402 1.19 sakamoto curbufsize -= PAGE_SIZE;
403 1.19 sakamoto }
404 1.1 ws }
405 1.69 chris pmap_update(kernel_map->pmap);
406 1.1 ws
407 1.1 ws /*
408 1.1 ws * Allocate a submap for exec arguments. This map effectively
409 1.1 ws * limits the number of processes exec'ing at any time.
410 1.1 ws */
411 1.19 sakamoto exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
412 1.41 thorpej 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
413 1.1 ws
414 1.1 ws /*
415 1.1 ws * Allocate a submap for physio
416 1.1 ws */
417 1.19 sakamoto phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
418 1.41 thorpej VM_PHYS_SIZE, 0, FALSE, NULL);
419 1.19 sakamoto
420 1.1 ws /*
421 1.37 thorpej * No need to allocate an mbuf cluster submap. Mbuf clusters
422 1.37 thorpej * are allocated via the pool allocator, and we use direct-mapped
423 1.37 thorpej * pool pages.
424 1.1 ws */
425 1.19 sakamoto
426 1.40 lukem format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
427 1.40 lukem printf("avail memory = %s\n", pbuf);
428 1.48 ragge format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
429 1.40 lukem printf("using %d buffers containing %s of memory\n", nbuf, pbuf);
430 1.29 sakamoto
431 1.1 ws /*
432 1.1 ws * Set up the buffers.
433 1.1 ws */
434 1.1 ws bufinit();
435 1.1 ws
436 1.1 ws /*
437 1.1 ws * Now allow hardware interrupts.
438 1.1 ws */
439 1.1 ws {
440 1.1 ws int msr;
441 1.29 sakamoto
442 1.1 ws splhigh();
443 1.7 thorpej asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
444 1.7 thorpej : "=r"(msr) : "K"((u_short)(PSL_EE|PSL_RI)));
445 1.1 ws }
446 1.1 ws }
447 1.1 ws
448 1.1 ws void
449 1.1 ws consinit()
450 1.1 ws {
451 1.29 sakamoto
452 1.71 thorpej /* Nothing to do; console is already initialized. */
453 1.71 thorpej }
454 1.71 thorpej
455 1.71 thorpej int ofppc_cngetc(dev_t);
456 1.71 thorpej void ofppc_cnputc(dev_t, int);
457 1.71 thorpej
458 1.71 thorpej struct consdev ofppc_bootcons = {
459 1.71 thorpej NULL, NULL, ofppc_cngetc, ofppc_cnputc, nullcnpollc, NULL,
460 1.71 thorpej makedev(0,0), 1,
461 1.71 thorpej };
462 1.71 thorpej
463 1.71 thorpej int ofppc_stdin_ihandle, ofppc_stdout_ihandle;
464 1.71 thorpej int ofppc_stdin_phandle, ofppc_stdout_phandle;
465 1.71 thorpej
466 1.71 thorpej void
467 1.71 thorpej ofppc_bootstrap_console(void)
468 1.71 thorpej {
469 1.71 thorpej int chosen;
470 1.71 thorpej char data[4];
471 1.71 thorpej
472 1.71 thorpej chosen = OF_finddevice("/chosen");
473 1.71 thorpej
474 1.71 thorpej if (OF_getprop(chosen, "stdin", data, sizeof(data)) != sizeof(int))
475 1.71 thorpej goto nocons;
476 1.71 thorpej ofppc_stdin_ihandle = of_decode_int(data);
477 1.71 thorpej ofppc_stdin_phandle = OF_instance_to_package(ofppc_stdin_ihandle);
478 1.71 thorpej
479 1.71 thorpej if (OF_getprop(chosen, "stdout", data, sizeof(data)) != sizeof(int))
480 1.71 thorpej goto nocons;
481 1.71 thorpej ofppc_stdout_ihandle = of_decode_int(data);
482 1.71 thorpej ofppc_stdout_phandle = OF_instance_to_package(ofppc_stdout_ihandle);
483 1.71 thorpej
484 1.71 thorpej cn_tab = &ofppc_bootcons;
485 1.71 thorpej
486 1.71 thorpej nocons:
487 1.71 thorpej return;
488 1.71 thorpej }
489 1.71 thorpej
490 1.71 thorpej int
491 1.71 thorpej ofppc_cngetc(dev_t dev)
492 1.71 thorpej {
493 1.71 thorpej u_char ch = '\0';
494 1.71 thorpej int l;
495 1.71 thorpej
496 1.71 thorpej while ((l = OF_read(ofppc_stdin_ihandle, &ch, 1)) != 1)
497 1.71 thorpej if (l != -2 && l != 0)
498 1.71 thorpej return (-1);
499 1.71 thorpej
500 1.71 thorpej return (ch);
501 1.71 thorpej }
502 1.71 thorpej
503 1.71 thorpej void
504 1.71 thorpej ofppc_cnputc(dev_t dev, int c)
505 1.71 thorpej {
506 1.71 thorpej char ch = c;
507 1.71 thorpej
508 1.71 thorpej OF_write(ofppc_stdout_ihandle, &ch, 1);
509 1.1 ws }
510 1.1 ws
511 1.1 ws /*
512 1.1 ws * Crash dump handling.
513 1.1 ws */
514 1.1 ws
515 1.1 ws void
516 1.1 ws dumpsys()
517 1.1 ws {
518 1.3 christos printf("dumpsys: TBD\n");
519 1.1 ws }
520 1.1 ws
521 1.1 ws /*
522 1.1 ws * Soft networking interrupts.
523 1.1 ws */
524 1.1 ws void
525 1.1 ws softnet()
526 1.1 ws {
527 1.1 ws int isr = netisr;
528 1.1 ws
529 1.1 ws netisr = 0;
530 1.52 erh
531 1.52 erh #define DONETISR(bit, fn) do { \
532 1.52 erh if (isr & (1 << bit)) \
533 1.52 erh fn(); \
534 1.52 erh } while (0)
535 1.52 erh
536 1.52 erh #include <net/netisr_dispatch.h>
537 1.52 erh
538 1.52 erh #undef DONETISR
539 1.1 ws }
540 1.1 ws
541 1.1 ws /*
542 1.1 ws * Stray interrupts.
543 1.1 ws */
544 1.1 ws void
545 1.1 ws strayintr(irq)
546 1.1 ws int irq;
547 1.1 ws {
548 1.1 ws log(LOG_ERR, "stray interrupt %d\n", irq);
549 1.1 ws }
550 1.1 ws
551 1.1 ws /*
552 1.1 ws * Halt or reboot the machine after syncing/dumping according to howto.
553 1.1 ws */
554 1.1 ws void
555 1.5 gwr cpu_reboot(howto, what)
556 1.1 ws int howto;
557 1.1 ws char *what;
558 1.1 ws {
559 1.1 ws static int syncing;
560 1.1 ws static char str[256];
561 1.1 ws char *ap = str, *ap1 = ap;
562 1.1 ws
563 1.1 ws boothowto = howto;
564 1.1 ws if (!cold && !(howto & RB_NOSYNC) && !syncing) {
565 1.1 ws syncing = 1;
566 1.1 ws vfs_shutdown(); /* sync */
567 1.1 ws resettodr(); /* set wall clock */
568 1.1 ws }
569 1.1 ws splhigh();
570 1.1 ws if (howto & RB_HALT) {
571 1.1 ws doshutdownhooks();
572 1.3 christos printf("halted\n\n");
573 1.1 ws ppc_exit();
574 1.1 ws }
575 1.1 ws if (!cold && (howto & RB_DUMP))
576 1.1 ws dumpsys();
577 1.1 ws doshutdownhooks();
578 1.3 christos printf("rebooting\n\n");
579 1.1 ws if (what && *what) {
580 1.1 ws if (strlen(what) > sizeof str - 5)
581 1.3 christos printf("boot string too large, ignored\n");
582 1.1 ws else {
583 1.1 ws strcpy(str, what);
584 1.1 ws ap1 = ap = str + strlen(str);
585 1.1 ws *ap++ = ' ';
586 1.1 ws }
587 1.1 ws }
588 1.1 ws *ap++ = '-';
589 1.1 ws if (howto & RB_SINGLE)
590 1.1 ws *ap++ = 's';
591 1.1 ws if (howto & RB_KDB)
592 1.1 ws *ap++ = 'd';
593 1.1 ws *ap++ = 0;
594 1.1 ws if (ap[-2] == '-')
595 1.1 ws *ap1 = 0;
596 1.1 ws ppc_boot(str);
597 1.1 ws }
598 1.1 ws
599 1.68 matt #ifdef notyet
600 1.1 ws /*
601 1.1 ws * OpenFirmware callback routine
602 1.1 ws */
603 1.1 ws void
604 1.1 ws callback(p)
605 1.1 ws void *p;
606 1.1 ws {
607 1.1 ws panic("callback"); /* for now XXX */
608 1.60 thorpej }
609 1.68 matt #endif
610 1.60 thorpej
611 1.60 thorpej /*
612 1.60 thorpej * Perform an `splx()' for locore.
613 1.60 thorpej */
614 1.60 thorpej int
615 1.60 thorpej lcsplx(int ipl)
616 1.60 thorpej {
617 1.60 thorpej
618 1.60 thorpej return (splx(ipl));
619 1.1 ws }
620 1.1 ws
621 1.1 ws /*
622 1.7 thorpej * Initial Machine Interface.
623 1.1 ws */
624 1.7 thorpej static int
625 1.7 thorpej fake_spl()
626 1.7 thorpej {
627 1.7 thorpej int scratch;
628 1.7 thorpej
629 1.7 thorpej asm volatile ("mfmsr %0; andi. %0,%0,%1; mtmsr %0; isync"
630 1.7 thorpej : "=r"(scratch) : "K"((u_short)~(PSL_EE|PSL_ME)));
631 1.29 sakamoto return (-1);
632 1.7 thorpej }
633 1.7 thorpej
634 1.1 ws static void
635 1.7 thorpej fake_setsoft()
636 1.7 thorpej {
637 1.7 thorpej /* Do nothing */
638 1.7 thorpej }
639 1.7 thorpej
640 1.7 thorpej static int
641 1.1 ws fake_splx(new)
642 1.1 ws int new;
643 1.1 ws {
644 1.29 sakamoto return (fake_spl());
645 1.7 thorpej }
646 1.7 thorpej
647 1.7 thorpej static void
648 1.7 thorpej fake_clock_return(frame, nticks)
649 1.7 thorpej struct clockframe *frame;
650 1.7 thorpej int nticks;
651 1.7 thorpej {
652 1.7 thorpej /* Do nothing */
653 1.1 ws }
654 1.1 ws
655 1.1 ws static void
656 1.1 ws fake_irq_establish(irq, level, handler, arg)
657 1.1 ws int irq, level;
658 1.1 ws void (*handler) __P((void *));
659 1.1 ws void *arg;
660 1.1 ws {
661 1.1 ws panic("fake_irq_establish");
662 1.1 ws }
663