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