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