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