machdep.c revision 1.123.2.2 1 1.123.2.2 rmind /* $NetBSD: machdep.c,v 1.123.2.2 2011/03/05 20:52:13 rmind Exp $ */
2 1.1 gwr
3 1.1 gwr /*
4 1.123.2.2 rmind * Copyright (c) 1988 University of Utah.
5 1.1 gwr * Copyright (c) 1982, 1986, 1990, 1993
6 1.1 gwr * The Regents of the University of California. All rights reserved.
7 1.1 gwr *
8 1.1 gwr * This code is derived from software contributed to Berkeley by
9 1.1 gwr * the Systems Programming Group of the University of Utah Computer
10 1.1 gwr * Science Department.
11 1.1 gwr *
12 1.1 gwr * Redistribution and use in source and binary forms, with or without
13 1.1 gwr * modification, are permitted provided that the following conditions
14 1.1 gwr * are met:
15 1.1 gwr * 1. Redistributions of source code must retain the above copyright
16 1.1 gwr * notice, this list of conditions and the following disclaimer.
17 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 gwr * notice, this list of conditions and the following disclaimer in the
19 1.1 gwr * documentation and/or other materials provided with the distribution.
20 1.91 agc * 3. Neither the name of the University nor the names of its contributors
21 1.91 agc * may be used to endorse or promote products derived from this software
22 1.91 agc * without specific prior written permission.
23 1.91 agc *
24 1.91 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.91 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.91 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.91 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.91 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.91 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.91 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.91 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.91 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.91 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.91 agc * SUCH DAMAGE.
35 1.91 agc *
36 1.91 agc * from: Utah Hdr: machdep.c 1.74 92/12/20
37 1.91 agc * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94
38 1.91 agc */
39 1.90 lukem
40 1.90 lukem #include <sys/cdefs.h>
41 1.123.2.2 rmind __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.123.2.2 2011/03/05 20:52:13 rmind Exp $");
42 1.1 gwr
43 1.35 jonathan #include "opt_ddb.h"
44 1.69 lukem #include "opt_kgdb.h"
45 1.118 apb #include "opt_modular.h"
46 1.34 gwr
47 1.1 gwr #include <sys/param.h>
48 1.1 gwr #include <sys/systm.h>
49 1.1 gwr #include <sys/kernel.h>
50 1.1 gwr #include <sys/proc.h>
51 1.1 gwr #include <sys/buf.h>
52 1.1 gwr #include <sys/reboot.h>
53 1.1 gwr #include <sys/conf.h>
54 1.1 gwr #include <sys/file.h>
55 1.37 kleink #include <sys/device.h>
56 1.1 gwr #include <sys/malloc.h>
57 1.1 gwr #include <sys/mbuf.h>
58 1.1 gwr #include <sys/msgbuf.h>
59 1.1 gwr #include <sys/ioctl.h>
60 1.1 gwr #include <sys/tty.h>
61 1.1 gwr #include <sys/mount.h>
62 1.1 gwr #include <sys/exec.h>
63 1.119 matt #include <sys/exec_aout.h> /* for MID_* */
64 1.1 gwr #include <sys/core.h>
65 1.1 gwr #include <sys/kcore.h>
66 1.1 gwr #include <sys/vnode.h>
67 1.1 gwr #include <sys/syscallargs.h>
68 1.87 ragge #include <sys/ksyms.h>
69 1.123.2.2 rmind #include <sys/module.h>
70 1.8 gwr #ifdef KGDB
71 1.8 gwr #include <sys/kgdb.h>
72 1.8 gwr #endif
73 1.26 hannken
74 1.42 mrg #include <uvm/uvm_extern.h>
75 1.34 gwr
76 1.26 hannken #include <sys/sysctl.h>
77 1.1 gwr
78 1.1 gwr #include <dev/cons.h>
79 1.123.2.1 rmind #include <dev/mm.h>
80 1.1 gwr
81 1.1 gwr #include <machine/cpu.h>
82 1.29 gwr #include <machine/dvma.h>
83 1.29 gwr #include <machine/idprom.h>
84 1.29 gwr #include <machine/kcore.h>
85 1.1 gwr #include <machine/reg.h>
86 1.123.2.2 rmind #include <machine/pcb.h>
87 1.1 gwr #include <machine/psl.h>
88 1.1 gwr #include <machine/pte.h>
89 1.123.2.1 rmind #include <machine/mon.h>
90 1.29 gwr
91 1.41 kleink #if defined(DDB)
92 1.1 gwr #include <machine/db_machdep.h>
93 1.33 gwr #include <ddb/db_sym.h>
94 1.32 tv #include <ddb/db_extern.h>
95 1.41 kleink #endif
96 1.1 gwr
97 1.29 gwr #include <sun3/sun3/machdep.h>
98 1.1 gwr
99 1.87 ragge #include "ksyms.h"
100 1.87 ragge
101 1.1 gwr /* Defined in locore.s */
102 1.1 gwr extern char kernel_text[];
103 1.1 gwr /* Defined by the linker */
104 1.1 gwr extern char etext[];
105 1.56 thorpej
106 1.123.2.2 rmind /* kernel_arch specific values required by module(9) */
107 1.123.2.2 rmind const vaddr_t kernbase = KERNBASE3X;
108 1.123.2.2 rmind const vaddr_t kern_end = KERN_END3X;
109 1.123.2.2 rmind
110 1.56 thorpej /* Our exported CPU info; we can have only one. */
111 1.56 thorpej struct cpu_info cpu_info_store;
112 1.1 gwr
113 1.70 chs struct vm_map *phys_map = NULL;
114 1.34 gwr
115 1.1 gwr int physmem;
116 1.9 gwr int fputype;
117 1.107 christos void * msgbufaddr;
118 1.1 gwr
119 1.29 gwr /* Virtual page frame for /dev/mem (see mem.c) */
120 1.73 tsutsui vaddr_t vmmap;
121 1.79 lukem
122 1.1 gwr /*
123 1.1 gwr * safepri is a safe priority for sleep to set for a spin-wait
124 1.1 gwr * during autoconfiguration or after a panic.
125 1.1 gwr */
126 1.1 gwr int safepri = PSL_LOWIPL;
127 1.1 gwr
128 1.29 gwr u_char cpu_machine_id = 0;
129 1.100 tsutsui const char *cpu_string = NULL;
130 1.15 gwr int cpu_has_vme = 0;
131 1.15 gwr int has_iocache = 0;
132 1.15 gwr
133 1.66 chs vaddr_t dumppage;
134 1.66 chs
135 1.97 chs static void identifycpu(void);
136 1.97 chs static void initcpu(void);
137 1.1 gwr
138 1.1 gwr /*
139 1.1 gwr * Console initialization: called early on from main,
140 1.15 gwr * before vm init or cpu_startup. This system is able
141 1.29 gwr * to use the console for output immediately (via PROM)
142 1.29 gwr * but can not use it for input until after this point.
143 1.1 gwr */
144 1.97 chs void
145 1.97 chs consinit(void)
146 1.1 gwr {
147 1.29 gwr
148 1.29 gwr /*
149 1.29 gwr * Switch from the PROM console (output only)
150 1.29 gwr * to our own console driver.
151 1.29 gwr */
152 1.29 gwr cninit();
153 1.1 gwr
154 1.113 ad #if NKSYMS || defined(DDB) || defined(MODULAR)
155 1.32 tv {
156 1.63 chs extern int nsym;
157 1.63 chs extern char *ssym, *esym;
158 1.32 tv
159 1.115 martin ksyms_addsyms_elf(nsym, ssym, esym);
160 1.32 tv }
161 1.72 simonb #endif /* DDB */
162 1.31 gwr
163 1.31 gwr /*
164 1.31 gwr * Now that the console can do input as well as
165 1.31 gwr * output, consider stopping for a debugger.
166 1.31 gwr */
167 1.31 gwr if (boothowto & RB_KDB) {
168 1.31 gwr #ifdef KGDB
169 1.31 gwr /* XXX - Ask on console for kgdb_dev? */
170 1.31 gwr /* Note: this will just return if kgdb_dev==NODEV */
171 1.31 gwr kgdb_connect(1);
172 1.31 gwr #else /* KGDB */
173 1.31 gwr /* Either DDB or no debugger (just PROM). */
174 1.1 gwr Debugger();
175 1.31 gwr #endif /* KGDB */
176 1.31 gwr }
177 1.1 gwr }
178 1.1 gwr
179 1.1 gwr /*
180 1.1 gwr * cpu_startup: allocate memory for variable-sized tables,
181 1.95 wiz * initialize CPU, and do autoconfiguration.
182 1.1 gwr *
183 1.1 gwr * This is called early in init_main.c:main(), after the
184 1.1 gwr * kernel memory allocator is ready for use, but before
185 1.1 gwr * the creation of processes 1,2, and mountroot, etc.
186 1.1 gwr */
187 1.97 chs void
188 1.97 chs cpu_startup(void)
189 1.1 gwr {
190 1.108 tsutsui char *v;
191 1.73 tsutsui vaddr_t minaddr, maxaddr;
192 1.50 lukem char pbuf[9];
193 1.1 gwr
194 1.1 gwr /*
195 1.1 gwr * Initialize message buffer (for kernel printf).
196 1.1 gwr * This is put in physical page zero so it will
197 1.1 gwr * always be in the same place after a reboot.
198 1.1 gwr * Its mapping was prepared in pmap_bootstrap().
199 1.1 gwr * Also, offset some to avoid PROM scribbles.
200 1.1 gwr */
201 1.123.2.2 rmind v = (char *)KERNBASE3X;
202 1.108 tsutsui msgbufaddr = v + MSGBUFOFF;
203 1.23 gwr initmsgbuf(msgbufaddr, MSGBUFSIZE);
204 1.1 gwr
205 1.1 gwr /*
206 1.1 gwr * Good {morning,afternoon,evening,night}.
207 1.1 gwr */
208 1.99 lukem printf("%s%s", copyright, version);
209 1.1 gwr identifycpu();
210 1.1 gwr initfpu(); /* also prints FPU type */
211 1.1 gwr
212 1.50 lukem format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
213 1.50 lukem printf("total memory = %s\n", pbuf);
214 1.1 gwr
215 1.1 gwr /*
216 1.66 chs * Get scratch page for dumpsys().
217 1.66 chs */
218 1.98 yamt dumppage = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED);
219 1.98 yamt if (dumppage == 0)
220 1.66 chs panic("startup: alloc dumppage");
221 1.66 chs
222 1.94 pk minaddr = 0;
223 1.1 gwr
224 1.1 gwr /*
225 1.84 chs * Allocate a submap for physio
226 1.1 gwr */
227 1.84 chs phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
228 1.106 thorpej VM_PHYS_SIZE, 0, false, NULL);
229 1.1 gwr
230 1.50 lukem format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
231 1.50 lukem printf("avail memory = %s\n", pbuf);
232 1.1 gwr
233 1.1 gwr /*
234 1.1 gwr * Allocate a virtual page (for use by /dev/mem)
235 1.1 gwr * This page is handed to pmap_enter() therefore
236 1.1 gwr * it has to be in the normal kernel VA range.
237 1.1 gwr */
238 1.98 yamt vmmap = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
239 1.98 yamt UVM_KMF_VAONLY | UVM_KMF_WAITVA);
240 1.1 gwr
241 1.1 gwr /*
242 1.1 gwr * Create the DVMA maps.
243 1.1 gwr */
244 1.1 gwr dvma_init();
245 1.1 gwr
246 1.1 gwr /*
247 1.1 gwr * Set up CPU-specific registers, cache, etc.
248 1.1 gwr */
249 1.1 gwr initcpu();
250 1.1 gwr }
251 1.1 gwr
252 1.1 gwr /*
253 1.1 gwr * Set registers on exec.
254 1.1 gwr */
255 1.97 chs void
256 1.122 matt setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack)
257 1.1 gwr {
258 1.85 thorpej struct trapframe *tf = (struct trapframe *)l->l_md.md_regs;
259 1.121 rmind struct pcb *pcb = lwp_getpcb(l);
260 1.1 gwr
261 1.21 mycroft tf->tf_sr = PSL_USERSET;
262 1.5 gwr tf->tf_pc = pack->ep_entry & ~1;
263 1.20 mycroft tf->tf_regs[D0] = 0;
264 1.20 mycroft tf->tf_regs[D1] = 0;
265 1.20 mycroft tf->tf_regs[D2] = 0;
266 1.20 mycroft tf->tf_regs[D3] = 0;
267 1.20 mycroft tf->tf_regs[D4] = 0;
268 1.20 mycroft tf->tf_regs[D5] = 0;
269 1.20 mycroft tf->tf_regs[D6] = 0;
270 1.20 mycroft tf->tf_regs[D7] = 0;
271 1.20 mycroft tf->tf_regs[A0] = 0;
272 1.20 mycroft tf->tf_regs[A1] = 0;
273 1.123.2.2 rmind tf->tf_regs[A2] = l->l_proc->p_psstrp;
274 1.20 mycroft tf->tf_regs[A3] = 0;
275 1.20 mycroft tf->tf_regs[A4] = 0;
276 1.20 mycroft tf->tf_regs[A5] = 0;
277 1.20 mycroft tf->tf_regs[A6] = 0;
278 1.5 gwr tf->tf_regs[SP] = stack;
279 1.1 gwr
280 1.1 gwr /* restore a null state frame */
281 1.121 rmind pcb->pcb_fpregs.fpf_null = 0;
282 1.19 mycroft if (fputype)
283 1.121 rmind m68881_restore(&pcb->pcb_fpregs);
284 1.19 mycroft
285 1.85 thorpej l->l_md.md_flags = 0;
286 1.1 gwr }
287 1.1 gwr
288 1.1 gwr /*
289 1.1 gwr * Info for CTL_HW
290 1.1 gwr */
291 1.46 gwr char machine[16] = MACHINE; /* from <machine/param.h> */
292 1.46 gwr char kernel_arch[16] = "sun3x"; /* XXX needs a sysctl node */
293 1.1 gwr char cpu_model[120];
294 1.15 gwr
295 1.15 gwr /*
296 1.15 gwr * XXX - Should empirically estimate the divisor...
297 1.15 gwr * Note that the value of delay_divisor is roughly
298 1.15 gwr * 2048 / cpuclock (where cpuclock is in MHz).
299 1.15 gwr */
300 1.16 gwr int delay_divisor = 62; /* assume the fastest (33 MHz) */
301 1.1 gwr
302 1.97 chs void
303 1.97 chs identifycpu(void)
304 1.1 gwr {
305 1.29 gwr u_char machtype;
306 1.1 gwr
307 1.15 gwr machtype = identity_prom.idp_machtype;
308 1.29 gwr if ((machtype & IDM_ARCH_MASK) != IDM_ARCH_SUN3X) {
309 1.29 gwr printf("Bad IDPROM arch!\n");
310 1.15 gwr sunmon_abort();
311 1.15 gwr }
312 1.15 gwr
313 1.29 gwr cpu_machine_id = machtype;
314 1.15 gwr switch (cpu_machine_id) {
315 1.15 gwr
316 1.101 thorpej case ID_SUN3X_80:
317 1.15 gwr cpu_string = "80"; /* Hydra */
318 1.16 gwr delay_divisor = 102; /* 20 MHz */
319 1.106 thorpej cpu_has_vme = false;
320 1.15 gwr break;
321 1.15 gwr
322 1.101 thorpej case ID_SUN3X_470:
323 1.15 gwr cpu_string = "470"; /* Pegasus */
324 1.15 gwr delay_divisor = 62; /* 33 MHz */
325 1.106 thorpej cpu_has_vme = true;
326 1.15 gwr break;
327 1.15 gwr
328 1.15 gwr default:
329 1.15 gwr printf("unknown sun3x model\n");
330 1.15 gwr sunmon_abort();
331 1.15 gwr }
332 1.15 gwr
333 1.15 gwr /* Other stuff? (VAC, mc6888x version, etc.) */
334 1.46 gwr /* Note: miniroot cares about the kernel_arch part. */
335 1.46 gwr sprintf(cpu_model, "%s %s", kernel_arch, cpu_string);
336 1.1 gwr
337 1.29 gwr printf("Model: %s\n", cpu_model);
338 1.1 gwr }
339 1.1 gwr
340 1.1 gwr /*
341 1.1 gwr * machine dependent system variables.
342 1.1 gwr */
343 1.93 atatat #if 0 /* XXX - Not yet... */
344 1.93 atatat static int
345 1.93 atatat sysctl_machdep_root_device(SYSCTLFN_ARGS)
346 1.1 gwr {
347 1.93 atatat struct sysctlnode node = *rnode;
348 1.1 gwr
349 1.93 atatat node.sysctl_data = some permutation on root_device;
350 1.93 atatat node.sysctl_size = strlen(root_device) + 1;
351 1.93 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
352 1.93 atatat }
353 1.1 gwr
354 1.93 atatat static int
355 1.93 atatat sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
356 1.93 atatat {
357 1.93 atatat struct sysctlnode node = *rnode;
358 1.1 gwr
359 1.93 atatat node.sysctl_data = some permutation on booted_kernel;
360 1.93 atatat node.sysctl_size = strlen(booted_kernel) + 1;
361 1.93 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
362 1.93 atatat }
363 1.1 gwr #endif
364 1.1 gwr
365 1.93 atatat SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
366 1.93 atatat {
367 1.93 atatat
368 1.96 atatat sysctl_createv(clog, 0, NULL, NULL,
369 1.96 atatat CTLFLAG_PERMANENT,
370 1.93 atatat CTLTYPE_NODE, "machdep", NULL,
371 1.93 atatat NULL, 0, NULL, 0,
372 1.93 atatat CTL_MACHDEP, CTL_EOL);
373 1.93 atatat
374 1.96 atatat sysctl_createv(clog, 0, NULL, NULL,
375 1.96 atatat CTLFLAG_PERMANENT,
376 1.93 atatat CTLTYPE_STRUCT, "console_device", NULL,
377 1.93 atatat sysctl_consdev, 0, NULL, sizeof(dev_t),
378 1.93 atatat CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
379 1.93 atatat #if 0 /* XXX - Not yet... */
380 1.96 atatat sysctl_createv(clog, 0, NULL, NULL,
381 1.96 atatat CTLFLAG_PERMANENT,
382 1.93 atatat CTLTYPE_STRING, "root_device", NULL,
383 1.93 atatat sysctl_machdep_root_device, 0, NULL, 0,
384 1.93 atatat CTL_MACHDEP, CPU_ROOT_DEVICE, CTL_EOL);
385 1.96 atatat sysctl_createv(clog, 0, NULL, NULL,
386 1.96 atatat CTLFLAG_PERMANENT,
387 1.93 atatat CTLTYPE_STRING, "booted_kernel", NULL,
388 1.93 atatat sysctl_machdep_booted_kernel, 0, NULL, 0,
389 1.93 atatat CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL);
390 1.93 atatat #endif
391 1.1 gwr }
392 1.1 gwr
393 1.7 gwr /* See: sig_machdep.c */
394 1.1 gwr
395 1.1 gwr /*
396 1.1 gwr * Do a sync in preparation for a reboot.
397 1.1 gwr * XXX - This could probably be common code.
398 1.1 gwr * XXX - And now, most of it is in vfs_shutdown()
399 1.1 gwr * XXX - Put waittime checks in there too?
400 1.1 gwr */
401 1.1 gwr int waittime = -1; /* XXX - Who else looks at this? -gwr */
402 1.1 gwr static void
403 1.97 chs reboot_sync(void)
404 1.1 gwr {
405 1.1 gwr
406 1.1 gwr /* Check waittime here to localize its use to this function. */
407 1.1 gwr if (waittime >= 0)
408 1.1 gwr return;
409 1.1 gwr waittime = 0;
410 1.1 gwr vfs_shutdown();
411 1.1 gwr }
412 1.1 gwr
413 1.1 gwr /*
414 1.1 gwr * Common part of the BSD and SunOS reboot system calls.
415 1.1 gwr */
416 1.97 chs __dead void
417 1.97 chs cpu_reboot(int howto, char *user_boot_string)
418 1.1 gwr {
419 1.2 gwr /* Note: this string MUST be static! */
420 1.2 gwr static char bootstr[128];
421 1.2 gwr char *p;
422 1.1 gwr
423 1.1 gwr /* If system is cold, just halt. (early panic?) */
424 1.1 gwr if (cold)
425 1.1 gwr goto haltsys;
426 1.1 gwr
427 1.24 gwr /* Un-blank the screen if appropriate. */
428 1.24 gwr cnpollc(1);
429 1.24 gwr
430 1.1 gwr if ((howto & RB_NOSYNC) == 0) {
431 1.1 gwr reboot_sync();
432 1.1 gwr /*
433 1.1 gwr * If we've been adjusting the clock, the todr
434 1.1 gwr * will be out of synch; adjust it now.
435 1.1 gwr *
436 1.1 gwr * XXX - However, if the kernel has been sitting in ddb,
437 1.1 gwr * the time will be way off, so don't set the HW clock!
438 1.1 gwr * XXX - Should do sanity check against HW clock. -gwr
439 1.1 gwr */
440 1.1 gwr /* resettodr(); */
441 1.1 gwr }
442 1.1 gwr
443 1.1 gwr /* Disable interrupts. */
444 1.1 gwr splhigh();
445 1.1 gwr
446 1.1 gwr /* Write out a crash dump if asked. */
447 1.1 gwr if (howto & RB_DUMP)
448 1.1 gwr dumpsys();
449 1.1 gwr
450 1.1 gwr /* run any shutdown hooks */
451 1.1 gwr doshutdownhooks();
452 1.1 gwr
453 1.112 dyoung pmf_system_shutdown(boothowto);
454 1.112 dyoung
455 1.1 gwr if (howto & RB_HALT) {
456 1.1 gwr haltsys:
457 1.63 chs printf("halted.\n");
458 1.61 tsutsui sunmon_halt();
459 1.1 gwr }
460 1.1 gwr
461 1.1 gwr /*
462 1.1 gwr * Automatic reboot.
463 1.1 gwr */
464 1.2 gwr if (user_boot_string)
465 1.2 gwr strncpy(bootstr, user_boot_string, sizeof(bootstr));
466 1.2 gwr else {
467 1.1 gwr /*
468 1.1 gwr * Build our own boot string with an empty
469 1.1 gwr * boot device/file and (maybe) some flags.
470 1.1 gwr * The PROM will supply the device/file name.
471 1.1 gwr */
472 1.2 gwr p = bootstr;
473 1.2 gwr *p = '\0';
474 1.1 gwr if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
475 1.1 gwr /* Append the boot flags. */
476 1.1 gwr *p++ = ' ';
477 1.1 gwr *p++ = '-';
478 1.1 gwr if (howto & RB_KDB)
479 1.1 gwr *p++ = 'd';
480 1.1 gwr if (howto & RB_ASKNAME)
481 1.1 gwr *p++ = 'a';
482 1.1 gwr if (howto & RB_SINGLE)
483 1.1 gwr *p++ = 's';
484 1.1 gwr *p = '\0';
485 1.1 gwr }
486 1.1 gwr }
487 1.63 chs printf("rebooting...\n");
488 1.3 gwr sunmon_reboot(bootstr);
489 1.1 gwr for (;;) ;
490 1.1 gwr /*NOTREACHED*/
491 1.1 gwr }
492 1.1 gwr
493 1.1 gwr /*
494 1.1 gwr * These variables are needed by /sbin/savecore
495 1.1 gwr */
496 1.97 chs uint32_t dumpmag = 0x8fca0101; /* magic number */
497 1.1 gwr int dumpsize = 0; /* pages */
498 1.1 gwr long dumplo = 0; /* blocks */
499 1.1 gwr
500 1.71 tsutsui #define DUMP_EXTRA 1 /* CPU-dependent extra pages */
501 1.71 tsutsui
502 1.1 gwr /*
503 1.11 gwr * This is called by main to set dumplo, dumpsize.
504 1.86 thorpej * Dumps always skip the first PAGE_SIZE of disk space
505 1.1 gwr * in case there might be a disk label stored there.
506 1.1 gwr * If there is extra space, put dump at the end to
507 1.1 gwr * reduce the chance that swapping trashes it.
508 1.1 gwr */
509 1.97 chs void
510 1.97 chs cpu_dumpconf(void)
511 1.1 gwr {
512 1.81 gehenna const struct bdevsw *bdev;
513 1.71 tsutsui int devblks; /* size of dump device in blocks */
514 1.71 tsutsui int dumpblks; /* size of dump image in blocks */
515 1.97 chs int (*getsize)(dev_t);
516 1.1 gwr
517 1.1 gwr if (dumpdev == NODEV)
518 1.1 gwr return;
519 1.1 gwr
520 1.81 gehenna bdev = bdevsw_lookup(dumpdev);
521 1.104 mrg if (bdev == NULL) {
522 1.104 mrg dumpdev = NODEV;
523 1.104 mrg return;
524 1.104 mrg }
525 1.81 gehenna getsize = bdev->d_psize;
526 1.1 gwr if (getsize == NULL)
527 1.1 gwr return;
528 1.71 tsutsui devblks = (*getsize)(dumpdev);
529 1.71 tsutsui if (devblks <= ctod(1))
530 1.1 gwr return;
531 1.71 tsutsui devblks &= ~(ctod(1) - 1);
532 1.71 tsutsui
533 1.71 tsutsui /*
534 1.71 tsutsui * Note: savecore expects dumpsize to be the
535 1.71 tsutsui * number of pages AFTER the dump header.
536 1.71 tsutsui */
537 1.71 tsutsui dumpsize = physmem; /* pages */
538 1.1 gwr
539 1.1 gwr /* Position dump image near end of space, page aligned. */
540 1.71 tsutsui dumpblks = ctod(physmem + DUMP_EXTRA);
541 1.71 tsutsui dumplo = devblks - dumpblks;
542 1.1 gwr
543 1.1 gwr /* If it does not fit, truncate it by moving dumplo. */
544 1.1 gwr /* Note: Must force signed comparison. */
545 1.1 gwr if (dumplo < ((long)ctod(1))) {
546 1.1 gwr dumplo = ctod(1);
547 1.71 tsutsui dumpsize = dtoc(devblks - dumplo) - DUMP_EXTRA;
548 1.1 gwr }
549 1.1 gwr }
550 1.1 gwr
551 1.13 gwr /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
552 1.1 gwr struct pcb dumppcb;
553 1.1 gwr
554 1.1 gwr /*
555 1.1 gwr * Write a crash dump. The format while in swap is:
556 1.1 gwr * kcore_seg_t cpu_hdr;
557 1.1 gwr * cpu_kcore_hdr_t cpu_data;
558 1.86 thorpej * padding (PAGE_SIZE-sizeof(kcore_seg_t))
559 1.86 thorpej * pagemap (2*PAGE_SIZE)
560 1.1 gwr * physical memory...
561 1.1 gwr */
562 1.97 chs void
563 1.97 chs dumpsys(void)
564 1.1 gwr {
565 1.81 gehenna const struct bdevsw *dsw;
566 1.66 chs kcore_seg_t *kseg_p;
567 1.10 gwr cpu_kcore_hdr_t *chdr_p;
568 1.14 thorpej struct sun3x_kcore_hdr *sh;
569 1.14 thorpej phys_ram_seg_t *crs_p;
570 1.1 gwr char *vaddr;
571 1.73 tsutsui paddr_t paddr;
572 1.10 gwr int psize, todo, seg, segsz;
573 1.1 gwr daddr_t blkno;
574 1.1 gwr int error = 0;
575 1.1 gwr
576 1.1 gwr if (dumpdev == NODEV)
577 1.1 gwr return;
578 1.81 gehenna dsw = bdevsw_lookup(dumpdev);
579 1.81 gehenna if (dsw == NULL || dsw->d_psize == NULL)
580 1.81 gehenna return;
581 1.1 gwr
582 1.1 gwr /*
583 1.1 gwr * For dumps during autoconfiguration,
584 1.1 gwr * if dump device has already configured...
585 1.1 gwr */
586 1.1 gwr if (dumpsize == 0)
587 1.11 gwr cpu_dumpconf();
588 1.28 mycroft if (dumplo <= 0) {
589 1.117 he printf("\ndump to dev %u,%u not possible\n",
590 1.116 tsutsui major(dumpdev), minor(dumpdev));
591 1.1 gwr return;
592 1.28 mycroft }
593 1.1 gwr savectx(&dumppcb);
594 1.1 gwr
595 1.1 gwr psize = (*(dsw->d_psize))(dumpdev);
596 1.1 gwr if (psize == -1) {
597 1.1 gwr printf("dump area unavailable\n");
598 1.1 gwr return;
599 1.1 gwr }
600 1.1 gwr
601 1.117 he printf("\ndumping to dev %u,%u offset %ld\n",
602 1.116 tsutsui major(dumpdev), minor(dumpdev), dumplo);
603 1.1 gwr
604 1.1 gwr /*
605 1.71 tsutsui * Prepare the dump header
606 1.1 gwr */
607 1.71 tsutsui blkno = dumplo;
608 1.71 tsutsui todo = dumpsize; /* pages */
609 1.71 tsutsui vaddr = (char *)dumppage;
610 1.86 thorpej memset(vaddr, 0, PAGE_SIZE);
611 1.25 gwr
612 1.25 gwr /* Set pointers to all three parts. */
613 1.71 tsutsui kseg_p = (kcore_seg_t *)vaddr;
614 1.66 chs chdr_p = (cpu_kcore_hdr_t *)(kseg_p + 1);
615 1.14 thorpej sh = &chdr_p->un._sun3x;
616 1.25 gwr
617 1.25 gwr /* Fill in kcore_seg_t part. */
618 1.10 gwr CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
619 1.71 tsutsui kseg_p->c_size = (ctob(DUMP_EXTRA) - sizeof(*kseg_p));
620 1.25 gwr
621 1.25 gwr /* Fill in cpu_kcore_hdr_t part. */
622 1.46 gwr strncpy(chdr_p->name, kernel_arch, sizeof(chdr_p->name));
623 1.86 thorpej chdr_p->page_size = PAGE_SIZE;
624 1.123.2.2 rmind chdr_p->kernbase = KERNBASE3X;
625 1.25 gwr
626 1.25 gwr /* Fill in the sun3x_kcore_hdr part. */
627 1.25 gwr pmap_kcore_hdr(sh);
628 1.10 gwr
629 1.71 tsutsui /* Write out the dump header. */
630 1.86 thorpej error = (*dsw->d_dump)(dumpdev, blkno, vaddr, PAGE_SIZE);
631 1.71 tsutsui if (error)
632 1.71 tsutsui goto fail;
633 1.86 thorpej blkno += btodb(PAGE_SIZE);
634 1.71 tsutsui
635 1.10 gwr /*
636 1.10 gwr * Now dump physical memory. Note that physical memory
637 1.10 gwr * might NOT be congiguous, so do it by segments.
638 1.10 gwr */
639 1.10 gwr
640 1.66 chs vaddr = (char *)vmmap; /* Borrow /dev/mem VA */
641 1.1 gwr
642 1.14 thorpej for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
643 1.14 thorpej crs_p = &sh->ram_segs[seg];
644 1.10 gwr paddr = crs_p->start;
645 1.10 gwr segsz = crs_p->size;
646 1.1 gwr
647 1.10 gwr while (todo && (segsz > 0)) {
648 1.1 gwr
649 1.10 gwr /* Print pages left after every 16. */
650 1.10 gwr if ((todo & 0xf) == 0)
651 1.114 ad printf_nolog("\r%4d", todo);
652 1.10 gwr
653 1.10 gwr /* Make a temporary mapping for the page. */
654 1.120 he pmap_kenter_pa(vmmap, paddr | PMAP_NC, VM_PROT_READ, 0);
655 1.75 chris pmap_update(pmap_kernel());
656 1.86 thorpej error = (*dsw->d_dump)(dumpdev, blkno, vaddr,
657 1.86 thorpej PAGE_SIZE);
658 1.86 thorpej pmap_kremove(vmmap, PAGE_SIZE);
659 1.75 chris pmap_update(pmap_kernel());
660 1.10 gwr if (error)
661 1.10 gwr goto fail;
662 1.86 thorpej paddr += PAGE_SIZE;
663 1.86 thorpej segsz -= PAGE_SIZE;
664 1.86 thorpej blkno += btodb(PAGE_SIZE);
665 1.10 gwr todo--;
666 1.10 gwr }
667 1.10 gwr }
668 1.1 gwr printf("\rdump succeeded\n");
669 1.1 gwr return;
670 1.1 gwr fail:
671 1.1 gwr printf(" dump error=%d\n", error);
672 1.1 gwr }
673 1.1 gwr
674 1.97 chs static void
675 1.97 chs initcpu(void)
676 1.1 gwr {
677 1.1 gwr /* XXX: Enable RAM parity/ECC checking? */
678 1.1 gwr /* XXX: parityenable(); */
679 1.1 gwr
680 1.1 gwr #ifdef HAVECACHE
681 1.1 gwr cache_enable();
682 1.1 gwr #endif
683 1.1 gwr }
684 1.1 gwr
685 1.8 gwr /* straptrap() in trap.c */
686 1.1 gwr
687 1.1 gwr /* from hp300: badaddr() */
688 1.15 gwr /* peek_byte(), peek_word() moved to bus_subr.c */
689 1.1 gwr
690 1.1 gwr /* XXX: parityenable() ? */
691 1.7 gwr /* regdump() moved to regdump.c */
692 1.1 gwr
693 1.1 gwr /*
694 1.1 gwr * cpu_exec_aout_makecmds():
695 1.95 wiz * CPU-dependent a.out format hook for execve().
696 1.1 gwr *
697 1.1 gwr * Determine if the given exec package refers to something which we
698 1.1 gwr * understand and, if so, set up the vmcmds for it.
699 1.1 gwr */
700 1.97 chs int
701 1.102 christos cpu_exec_aout_makecmds(struct lwp *l, struct exec_package *epp)
702 1.1 gwr {
703 1.27 tv return ENOEXEC;
704 1.1 gwr }
705 1.123.2.1 rmind
706 1.123.2.1 rmind int
707 1.123.2.1 rmind mm_md_physacc(paddr_t pa, vm_prot_t prot)
708 1.123.2.1 rmind {
709 1.123.2.1 rmind
710 1.123.2.1 rmind return pmap_pa_exists(pa) ? 0 : EFAULT;
711 1.123.2.1 rmind }
712 1.123.2.1 rmind
713 1.123.2.1 rmind bool
714 1.123.2.1 rmind mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr)
715 1.123.2.1 rmind {
716 1.123.2.1 rmind extern paddr_t avail_start;
717 1.123.2.1 rmind
718 1.123.2.1 rmind if (paddr >= avail_start)
719 1.123.2.1 rmind return false;
720 1.123.2.1 rmind *vaddr = KERNBASE + paddr;
721 1.123.2.1 rmind return true;
722 1.123.2.1 rmind }
723 1.123.2.1 rmind
724 1.123.2.1 rmind /*
725 1.123.2.1 rmind * Allow access to the PROM mapping similiar to uvm_kernacc().
726 1.123.2.1 rmind */
727 1.123.2.1 rmind int
728 1.123.2.1 rmind mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled)
729 1.123.2.1 rmind {
730 1.123.2.1 rmind
731 1.123.2.1 rmind if ((vaddr_t)ptr < SUN3X_PROM_BASE || (vaddr_t)ptr > SUN3X_MONEND) {
732 1.123.2.1 rmind *handled = false;
733 1.123.2.1 rmind return 0;
734 1.123.2.1 rmind }
735 1.123.2.1 rmind
736 1.123.2.1 rmind *handled = true;
737 1.123.2.1 rmind /* Read in the PROM itself is OK. */
738 1.123.2.1 rmind if ((prot & VM_PROT_WRITE) == 0)
739 1.123.2.1 rmind return 0;
740 1.123.2.1 rmind
741 1.123.2.1 rmind /* PROM data page is OK for read/write. */
742 1.123.2.1 rmind if ((vaddr_t)ptr >= SUN3X_MONDATA &&
743 1.123.2.1 rmind (vaddr_t)ptr < SUN3X_MONDATA + PAGE_SIZE)
744 1.123.2.1 rmind return 0;
745 1.123.2.1 rmind return EFAULT;
746 1.123.2.1 rmind }
747 1.123.2.2 rmind
748 1.123.2.2 rmind #ifdef MODULAR
749 1.123.2.2 rmind /*
750 1.123.2.2 rmind * Push any modules loaded by the bootloader etc.
751 1.123.2.2 rmind */
752 1.123.2.2 rmind void
753 1.123.2.2 rmind module_init_md(void)
754 1.123.2.2 rmind {
755 1.123.2.2 rmind }
756 1.123.2.2 rmind #endif
757