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