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