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