machdep.c revision 1.2.2.2 1 1.2.2.2 yamt /* $NetBSD: machdep.c,v 1.2.2.2 2006/04/11 12:20:51 yamt Exp $ */
2 1.2.2.2 yamt
3 1.2.2.2 yamt /*
4 1.2.2.2 yamt * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
5 1.2.2.2 yamt * Copyright (c) 2006 Garrett D'Amore.
6 1.2.2.2 yamt * All rights reserved.
7 1.2.2.2 yamt *
8 1.2.2.2 yamt * Portions of this code were written by Garrett D'Amore for the
9 1.2.2.2 yamt * Champaign-Urbana Community Wireless Network Project.
10 1.2.2.2 yamt *
11 1.2.2.2 yamt * Redistribution and use in source and binary forms, with or
12 1.2.2.2 yamt * without modification, are permitted provided that the following
13 1.2.2.2 yamt * conditions are met:
14 1.2.2.2 yamt * 1. Redistributions of source code must retain the above copyright
15 1.2.2.2 yamt * notice, this list of conditions and the following disclaimer.
16 1.2.2.2 yamt * 2. Redistributions in binary form must reproduce the above
17 1.2.2.2 yamt * copyright notice, this list of conditions and the following
18 1.2.2.2 yamt * disclaimer in the documentation and/or other materials provided
19 1.2.2.2 yamt * with the distribution.
20 1.2.2.2 yamt * 3. All advertising materials mentioning features or use of this
21 1.2.2.2 yamt * software must display the following acknowledgements:
22 1.2.2.2 yamt * This product includes software developed by the Urbana-Champaign
23 1.2.2.2 yamt * Independent Media Center.
24 1.2.2.2 yamt * This product includes software developed by Garrett D'Amore.
25 1.2.2.2 yamt * 4. Urbana-Champaign Independent Media Center's name and Garrett
26 1.2.2.2 yamt * D'Amore's name may not be used to endorse or promote products
27 1.2.2.2 yamt * derived from this software without specific prior written permission.
28 1.2.2.2 yamt *
29 1.2.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
30 1.2.2.2 yamt * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
31 1.2.2.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 1.2.2.2 yamt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 1.2.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
34 1.2.2.2 yamt * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
35 1.2.2.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 1.2.2.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 1.2.2.2 yamt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38 1.2.2.2 yamt * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.2.2.2 yamt * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 1.2.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 1.2.2.2 yamt * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 1.2.2.2 yamt */
43 1.2.2.2 yamt /*-
44 1.2.2.2 yamt * Copyright (c) 2006 Itronix Inc.
45 1.2.2.2 yamt * All rights reserved.
46 1.2.2.2 yamt *
47 1.2.2.2 yamt * Portions written by Garrett D'Amore for Itronix Inc.
48 1.2.2.2 yamt *
49 1.2.2.2 yamt * Redistribution and use in source and binary forms, with or without
50 1.2.2.2 yamt * modification, are permitted provided that the following conditions
51 1.2.2.2 yamt * are met:
52 1.2.2.2 yamt * 1. Redistributions of source code must retain the above copyright
53 1.2.2.2 yamt * notice, this list of conditions and the following disclaimer.
54 1.2.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
55 1.2.2.2 yamt * notice, this list of conditions and the following disclaimer in the
56 1.2.2.2 yamt * documentation and/or other materials provided with the distribution.
57 1.2.2.2 yamt * 3. The name of Itronix Inc. may not be used to endorse
58 1.2.2.2 yamt * or promote products derived from this software without specific
59 1.2.2.2 yamt * prior written permission.
60 1.2.2.2 yamt *
61 1.2.2.2 yamt * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
62 1.2.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
63 1.2.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
64 1.2.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
65 1.2.2.2 yamt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
66 1.2.2.2 yamt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
67 1.2.2.2 yamt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
68 1.2.2.2 yamt * ON ANY THEORY OF LIABILITY, WHETHER IN
69 1.2.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
70 1.2.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
71 1.2.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
72 1.2.2.2 yamt */
73 1.2.2.2 yamt /*
74 1.2.2.2 yamt * Copyright (c) 1992, 1993
75 1.2.2.2 yamt * The Regents of the University of California. All rights reserved.
76 1.2.2.2 yamt *
77 1.2.2.2 yamt * This code is derived from software contributed to Berkeley by
78 1.2.2.2 yamt * the Systems Programming Group of the University of Utah Computer
79 1.2.2.2 yamt * Science Department, The Mach Operating System project at
80 1.2.2.2 yamt * Carnegie-Mellon University and Ralph Campbell.
81 1.2.2.2 yamt *
82 1.2.2.2 yamt * Redistribution and use in source and binary forms, with or without
83 1.2.2.2 yamt * modification, are permitted provided that the following conditions
84 1.2.2.2 yamt * are met:
85 1.2.2.2 yamt * 1. Redistributions of source code must retain the above copyright
86 1.2.2.2 yamt * notice, this list of conditions and the following disclaimer.
87 1.2.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
88 1.2.2.2 yamt * notice, this list of conditions and the following disclaimer in the
89 1.2.2.2 yamt * documentation and/or other materials provided with the distribution.
90 1.2.2.2 yamt * 3. Neither the name of the University nor the names of its contributors
91 1.2.2.2 yamt * may be used to endorse or promote products derived from this software
92 1.2.2.2 yamt * without specific prior written permission.
93 1.2.2.2 yamt *
94 1.2.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
95 1.2.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 1.2.2.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97 1.2.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
98 1.2.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
99 1.2.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
100 1.2.2.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
101 1.2.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
102 1.2.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
103 1.2.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
104 1.2.2.2 yamt * SUCH DAMAGE.
105 1.2.2.2 yamt *
106 1.2.2.2 yamt * @(#)machdep.c 8.3 (Berkeley) 1/12/94
107 1.2.2.2 yamt * from: Utah Hdr: machdep.c 1.63 91/04/24
108 1.2.2.2 yamt */
109 1.2.2.2 yamt /*
110 1.2.2.2 yamt * Copyright (c) 1988 University of Utah.
111 1.2.2.2 yamt *
112 1.2.2.2 yamt * This code is derived from software contributed to Berkeley by
113 1.2.2.2 yamt * the Systems Programming Group of the University of Utah Computer
114 1.2.2.2 yamt * Science Department, The Mach Operating System project at
115 1.2.2.2 yamt * Carnegie-Mellon University and Ralph Campbell.
116 1.2.2.2 yamt *
117 1.2.2.2 yamt * Redistribution and use in source and binary forms, with or without
118 1.2.2.2 yamt * modification, are permitted provided that the following conditions
119 1.2.2.2 yamt * are met:
120 1.2.2.2 yamt * 1. Redistributions of source code must retain the above copyright
121 1.2.2.2 yamt * notice, this list of conditions and the following disclaimer.
122 1.2.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
123 1.2.2.2 yamt * notice, this list of conditions and the following disclaimer in the
124 1.2.2.2 yamt * documentation and/or other materials provided with the distribution.
125 1.2.2.2 yamt * 3. All advertising materials mentioning features or use of this software
126 1.2.2.2 yamt * must display the following acknowledgement:
127 1.2.2.2 yamt * This product includes software developed by the University of
128 1.2.2.2 yamt * California, Berkeley and its contributors.
129 1.2.2.2 yamt * 4. Neither the name of the University nor the names of its contributors
130 1.2.2.2 yamt * may be used to endorse or promote products derived from this software
131 1.2.2.2 yamt * without specific prior written permission.
132 1.2.2.2 yamt *
133 1.2.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
134 1.2.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
135 1.2.2.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
136 1.2.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
137 1.2.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
138 1.2.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
139 1.2.2.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
140 1.2.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
141 1.2.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
142 1.2.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
143 1.2.2.2 yamt * SUCH DAMAGE.
144 1.2.2.2 yamt *
145 1.2.2.2 yamt * @(#)machdep.c 8.3 (Berkeley) 1/12/94
146 1.2.2.2 yamt * from: Utah Hdr: machdep.c 1.63 91/04/24
147 1.2.2.2 yamt */
148 1.2.2.2 yamt
149 1.2.2.2 yamt #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
150 1.2.2.2 yamt __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.2.2.2 2006/04/11 12:20:51 yamt Exp $");
151 1.2.2.2 yamt
152 1.2.2.2 yamt #include "opt_ddb.h"
153 1.2.2.2 yamt #include "opt_kgdb.h"
154 1.2.2.2 yamt
155 1.2.2.2 yamt #include "opt_memsize.h"
156 1.2.2.2 yamt #include "opt_ethaddr.h"
157 1.2.2.2 yamt
158 1.2.2.2 yamt #include <sys/param.h>
159 1.2.2.2 yamt #include <sys/systm.h>
160 1.2.2.2 yamt #include <sys/kernel.h>
161 1.2.2.2 yamt #include <sys/buf.h>
162 1.2.2.2 yamt #include <sys/reboot.h>
163 1.2.2.2 yamt #include <sys/user.h>
164 1.2.2.2 yamt #include <sys/mount.h>
165 1.2.2.2 yamt #include <sys/kcore.h>
166 1.2.2.2 yamt #include <sys/boot_flag.h>
167 1.2.2.2 yamt #include <sys/termios.h>
168 1.2.2.2 yamt #include <sys/ksyms.h>
169 1.2.2.2 yamt
170 1.2.2.2 yamt #include <net/if.h>
171 1.2.2.2 yamt #include <net/if_ether.h>
172 1.2.2.2 yamt
173 1.2.2.2 yamt #include <uvm/uvm_extern.h>
174 1.2.2.2 yamt
175 1.2.2.2 yamt #include <dev/cons.h>
176 1.2.2.2 yamt
177 1.2.2.2 yamt #include "ksyms.h"
178 1.2.2.2 yamt
179 1.2.2.2 yamt #if NKSYMS || defined(DDB) || defined(LKM)
180 1.2.2.2 yamt #include <machine/db_machdep.h>
181 1.2.2.2 yamt #include <ddb/db_extern.h>
182 1.2.2.2 yamt #endif
183 1.2.2.2 yamt
184 1.2.2.2 yamt #include <mips/cache.h>
185 1.2.2.2 yamt #include <mips/locore.h>
186 1.2.2.2 yamt #include <mips/cpuregs.h>
187 1.2.2.2 yamt
188 1.2.2.2 yamt #include <mips/atheros/include/ar531xreg.h>
189 1.2.2.2 yamt #include <mips/atheros/include/ar531xvar.h>
190 1.2.2.2 yamt #include <mips/atheros/include/arbusvar.h>
191 1.2.2.2 yamt #include "com.h"
192 1.2.2.2 yamt
193 1.2.2.2 yamt /* The following are used externally (sysctl_hw). */
194 1.2.2.2 yamt extern char cpu_model[];
195 1.2.2.2 yamt
196 1.2.2.2 yamt struct user *proc0paddr;
197 1.2.2.2 yamt
198 1.2.2.2 yamt /* Our exported CPU info; we can have only one. */
199 1.2.2.2 yamt struct cpu_info cpu_info_store;
200 1.2.2.2 yamt
201 1.2.2.2 yamt /* Maps for VM objects. */
202 1.2.2.2 yamt struct vm_map *exec_map = NULL;
203 1.2.2.2 yamt struct vm_map *mb_map = NULL;
204 1.2.2.2 yamt struct vm_map *phys_map = NULL;
205 1.2.2.2 yamt
206 1.2.2.2 yamt int physmem; /* # pages of physical memory */
207 1.2.2.2 yamt int maxmem; /* max memory per process */
208 1.2.2.2 yamt
209 1.2.2.2 yamt int mem_cluster_cnt;
210 1.2.2.2 yamt phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
211 1.2.2.2 yamt
212 1.2.2.2 yamt void mach_init(void); /* XXX */
213 1.2.2.2 yamt
214 1.2.2.2 yamt void mdputc(char);
215 1.2.2.2 yamt void mdputs(const char *);
216 1.2.2.2 yamt void mdputx(int n);
217 1.2.2.2 yamt void mdputn(int n);
218 1.2.2.2 yamt
219 1.2.2.2 yamt extern struct consdev com_arbus_consdev;
220 1.2.2.2 yamt
221 1.2.2.2 yamt void
222 1.2.2.2 yamt mach_init(void)
223 1.2.2.2 yamt {
224 1.2.2.2 yamt caddr_t kernend;
225 1.2.2.2 yamt u_long first, last;
226 1.2.2.2 yamt caddr_t v;
227 1.2.2.2 yamt uint32_t memcfg, bank0, bank1;
228 1.2.2.2 yamt uint32_t memsize;
229 1.2.2.2 yamt struct ar531x_board_info *infop;
230 1.2.2.2 yamt
231 1.2.2.2 yamt extern char edata[], end[]; /* XXX */
232 1.2.2.2 yamt
233 1.2.2.2 yamt /* clear the BSS segment */
234 1.2.2.2 yamt kernend = (caddr_t)mips_round_page(end);
235 1.2.2.2 yamt
236 1.2.2.2 yamt memset(edata, 0, kernend - (caddr_t)edata);
237 1.2.2.2 yamt
238 1.2.2.2 yamt infop = ar531x_board_info();
239 1.2.2.2 yamt if (infop == NULL)
240 1.2.2.2 yamt panic("No board info!");
241 1.2.2.2 yamt
242 1.2.2.2 yamt /* set CPU model info for sysctl_hw */
243 1.2.2.2 yamt snprintf(cpu_model, 64, "%s", infop->ab_name);
244 1.2.2.2 yamt
245 1.2.2.2 yamt /*
246 1.2.2.2 yamt * Set up the exception vectors and CPU-specific function
247 1.2.2.2 yamt * vectors early on. We need the wbflush() vector set up
248 1.2.2.2 yamt * before comcnattach() is called (or at least before the
249 1.2.2.2 yamt * first printf() after that is called).
250 1.2.2.2 yamt * Sets up mips_cpu_flags that may be queried by other
251 1.2.2.2 yamt * functions called during startup.
252 1.2.2.2 yamt * Also clears the I+D caches.
253 1.2.2.2 yamt */
254 1.2.2.2 yamt mips_vector_init();
255 1.2.2.2 yamt
256 1.2.2.2 yamt /*
257 1.2.2.2 yamt * Calibrate timers.
258 1.2.2.2 yamt */
259 1.2.2.2 yamt ar531x_cal_timer();
260 1.2.2.2 yamt
261 1.2.2.2 yamt /*
262 1.2.2.2 yamt * Set the VM page size.
263 1.2.2.2 yamt */
264 1.2.2.2 yamt uvm_setpagesize();
265 1.2.2.2 yamt
266 1.2.2.2 yamt /*
267 1.2.2.2 yamt * Look at arguments passed to us and compute boothowto.
268 1.2.2.2 yamt */
269 1.2.2.2 yamt boothowto = RB_AUTOBOOT;
270 1.2.2.2 yamt #ifdef KADB
271 1.2.2.2 yamt boothowto |= RB_KDB;
272 1.2.2.2 yamt #endif
273 1.2.2.2 yamt
274 1.2.2.2 yamt /*
275 1.2.2.2 yamt * This would be a good place to parse a boot command line, bif
276 1.2.2.2 yamt * we got one from the bootloader. Right now we have no way to
277 1.2.2.2 yamt * get one from e.g. vxworks.
278 1.2.2.2 yamt */
279 1.2.2.2 yamt
280 1.2.2.2 yamt /*
281 1.2.2.2 yamt * Determine the memory size. Use the `memsize' PMON
282 1.2.2.2 yamt * variable. If that's not available, panic.
283 1.2.2.2 yamt *
284 1.2.2.2 yamt * Note: Reserve the first page! That's where the trap
285 1.2.2.2 yamt * vectors are located.
286 1.2.2.2 yamt */
287 1.2.2.2 yamt memcfg = GETSDRAMREG(AR531X_SDRAMCTL_MEM_CFG1);
288 1.2.2.2 yamt bank0 = (memcfg & AR531X_MEM_CFG1_BANK0_MASK) >>
289 1.2.2.2 yamt AR531X_MEM_CFG1_BANK0_SHIFT;
290 1.2.2.2 yamt bank1 = (memcfg & AR531X_MEM_CFG1_BANK1_MASK) >>
291 1.2.2.2 yamt AR531X_MEM_CFG1_BANK1_SHIFT;
292 1.2.2.2 yamt
293 1.2.2.2 yamt memsize = (bank0 ? (1 << (bank0 + 1)) : 0) +
294 1.2.2.2 yamt (bank1 ? (1 << (bank1 + 1)) : 0);
295 1.2.2.2 yamt memsize <<= 20;
296 1.2.2.2 yamt
297 1.2.2.2 yamt /* allow compile time override */
298 1.2.2.2 yamt #if defined(MEMSIZE)
299 1.2.2.2 yamt memsize = MEMSIZE;
300 1.2.2.2 yamt #endif
301 1.2.2.2 yamt
302 1.2.2.2 yamt printf("Memory size: 0x%08x\n", memsize);
303 1.2.2.2 yamt physmem = btoc(memsize);
304 1.2.2.2 yamt
305 1.2.2.2 yamt mem_clusters[mem_cluster_cnt].start = PAGE_SIZE;
306 1.2.2.2 yamt mem_clusters[mem_cluster_cnt].size =
307 1.2.2.2 yamt memsize - mem_clusters[mem_cluster_cnt].start;
308 1.2.2.2 yamt mem_cluster_cnt++;
309 1.2.2.2 yamt
310 1.2.2.2 yamt /*
311 1.2.2.2 yamt * Load the rest of the available pages into the VM system.
312 1.2.2.2 yamt */
313 1.2.2.2 yamt first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
314 1.2.2.2 yamt last = mem_clusters[0].start + mem_clusters[0].size;
315 1.2.2.2 yamt uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
316 1.2.2.2 yamt VM_FREELIST_DEFAULT);
317 1.2.2.2 yamt
318 1.2.2.2 yamt /*
319 1.2.2.2 yamt * Initialize message buffer (at end of core).
320 1.2.2.2 yamt */
321 1.2.2.2 yamt mips_init_msgbuf();
322 1.2.2.2 yamt
323 1.2.2.2 yamt /*
324 1.2.2.2 yamt * Initialize the virtual memory system.
325 1.2.2.2 yamt */
326 1.2.2.2 yamt pmap_bootstrap();
327 1.2.2.2 yamt
328 1.2.2.2 yamt /*
329 1.2.2.2 yamt * Init mapping for u page(s) for proc0.
330 1.2.2.2 yamt */
331 1.2.2.2 yamt v = (caddr_t) uvm_pageboot_alloc(USPACE);
332 1.2.2.2 yamt lwp0.l_addr = proc0paddr = (struct user *)v;
333 1.2.2.2 yamt lwp0.l_md.md_regs = (struct frame *)(v + USPACE) - 1;
334 1.2.2.2 yamt curpcb = &lwp0.l_addr->u_pcb;
335 1.2.2.2 yamt curpcb->pcb_context[11] = MIPS_INT_MASK | MIPS_SR_INT_IE; /* SR */
336 1.2.2.2 yamt
337 1.2.2.2 yamt /*
338 1.2.2.2 yamt * Clear previous AHB errors
339 1.2.2.2 yamt */
340 1.2.2.2 yamt GETSYSREG(AR531X_SYSREG_AHBPERR);
341 1.2.2.2 yamt GETSYSREG(AR531X_SYSREG_AHBDMAE);
342 1.2.2.2 yamt
343 1.2.2.2 yamt /*
344 1.2.2.2 yamt * Turn off (ignore) the hardware watchdog. If we got this
345 1.2.2.2 yamt * far, then we shouldn't need it anymore.
346 1.2.2.2 yamt */
347 1.2.2.2 yamt PUTSYSREG(AR531X_SYSREG_WDOG_CTL, AR531X_WDOG_CTL_IGNORE);
348 1.2.2.2 yamt
349 1.2.2.2 yamt /*
350 1.2.2.2 yamt * Turn off watchpoint that may have been enabled by the
351 1.2.2.2 yamt * PROM. VxWorks bootloader seems to leave one set.
352 1.2.2.2 yamt */
353 1.2.2.2 yamt __asm volatile (
354 1.2.2.2 yamt "mtc0 $0, $" ___STRING(MIPS_COP_0_WATCH_LO) " \n\t"
355 1.2.2.2 yamt "nop\n\t"
356 1.2.2.2 yamt "nop\n\t");
357 1.2.2.2 yamt
358 1.2.2.2 yamt /*
359 1.2.2.2 yamt * Initialize debuggers, and break into them, if appropriate.
360 1.2.2.2 yamt */
361 1.2.2.2 yamt #if NKSYMS || defined(DDB) || defined(LKM)
362 1.2.2.2 yamt ksyms_init(0, 0, 0);
363 1.2.2.2 yamt #endif
364 1.2.2.2 yamt
365 1.2.2.2 yamt #ifdef DDB
366 1.2.2.2 yamt if (boothowto & RB_KDB)
367 1.2.2.2 yamt Debugger();
368 1.2.2.2 yamt #endif
369 1.2.2.2 yamt }
370 1.2.2.2 yamt
371 1.2.2.2 yamt void
372 1.2.2.2 yamt consinit(void)
373 1.2.2.2 yamt {
374 1.2.2.2 yamt
375 1.2.2.2 yamt /*
376 1.2.2.2 yamt * Everything related to console initialization is done
377 1.2.2.2 yamt * in mach_init().
378 1.2.2.2 yamt */
379 1.2.2.2 yamt #if NCOM > 0
380 1.2.2.2 yamt /* Setup polled serial for early console I/O */
381 1.2.2.2 yamt /* XXX: pass in CONSPEED? */
382 1.2.2.2 yamt com_arbus_cnattach(AR531X_UART0_BASE);
383 1.2.2.2 yamt #else
384 1.2.2.2 yamt panic("Not configured to use serial console!\n");
385 1.2.2.2 yamt /* not going to see that message now, are we? */
386 1.2.2.2 yamt #endif
387 1.2.2.2 yamt }
388 1.2.2.2 yamt
389 1.2.2.2 yamt void
390 1.2.2.2 yamt cpu_startup(void)
391 1.2.2.2 yamt {
392 1.2.2.2 yamt char pbuf[9];
393 1.2.2.2 yamt vaddr_t minaddr, maxaddr;
394 1.2.2.2 yamt #ifdef DEBUG
395 1.2.2.2 yamt extern int pmapdebug; /* XXX */
396 1.2.2.2 yamt int opmapdebug = pmapdebug;
397 1.2.2.2 yamt
398 1.2.2.2 yamt pmapdebug = 0; /* Shut up pmap debug during bootstrap */
399 1.2.2.2 yamt #endif
400 1.2.2.2 yamt
401 1.2.2.2 yamt /*
402 1.2.2.2 yamt * Good {morning,afternoon,evening,night}.
403 1.2.2.2 yamt */
404 1.2.2.2 yamt printf("%s%s", copyright, version);
405 1.2.2.2 yamt printf("%s\n", cpu_model);
406 1.2.2.2 yamt format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
407 1.2.2.2 yamt printf("total memory = %s\n", pbuf);
408 1.2.2.2 yamt
409 1.2.2.2 yamt minaddr = 0;
410 1.2.2.2 yamt /*
411 1.2.2.2 yamt * Allocate a submap for exec arguments. This map effectively
412 1.2.2.2 yamt * limits the number of processes exec'ing at any time.
413 1.2.2.2 yamt */
414 1.2.2.2 yamt exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
415 1.2.2.2 yamt 16 * NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
416 1.2.2.2 yamt
417 1.2.2.2 yamt /*
418 1.2.2.2 yamt * Allocate a submap for physio
419 1.2.2.2 yamt */
420 1.2.2.2 yamt phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
421 1.2.2.2 yamt VM_PHYS_SIZE, 0, FALSE, NULL);
422 1.2.2.2 yamt
423 1.2.2.2 yamt /*
424 1.2.2.2 yamt * No need to allocate an mbuf cluster submap. Mbuf clusters
425 1.2.2.2 yamt * are allocated via the pool allocator, and we use KSEG to
426 1.2.2.2 yamt * map those pages.
427 1.2.2.2 yamt */
428 1.2.2.2 yamt
429 1.2.2.2 yamt #ifdef DEBUG
430 1.2.2.2 yamt pmapdebug = opmapdebug;
431 1.2.2.2 yamt #endif
432 1.2.2.2 yamt format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
433 1.2.2.2 yamt printf("avail memory = %s\n", pbuf);
434 1.2.2.2 yamt }
435 1.2.2.2 yamt
436 1.2.2.2 yamt void
437 1.2.2.2 yamt cpu_reboot(int howto, char *bootstr)
438 1.2.2.2 yamt {
439 1.2.2.2 yamt static int waittime = -1;
440 1.2.2.2 yamt
441 1.2.2.2 yamt /* Take a snapshot before clobbering any registers. */
442 1.2.2.2 yamt if (curproc)
443 1.2.2.2 yamt savectx((struct user *)curpcb);
444 1.2.2.2 yamt
445 1.2.2.2 yamt /* If "always halt" was specified as a boot flag, obey. */
446 1.2.2.2 yamt if (boothowto & RB_HALT)
447 1.2.2.2 yamt howto |= RB_HALT;
448 1.2.2.2 yamt
449 1.2.2.2 yamt boothowto = howto;
450 1.2.2.2 yamt
451 1.2.2.2 yamt /* If system is cold, just halt. */
452 1.2.2.2 yamt if (cold) {
453 1.2.2.2 yamt boothowto |= RB_HALT;
454 1.2.2.2 yamt goto haltsys;
455 1.2.2.2 yamt }
456 1.2.2.2 yamt
457 1.2.2.2 yamt if ((boothowto & RB_NOSYNC) == 0 && waittime < 0) {
458 1.2.2.2 yamt waittime = 0;
459 1.2.2.2 yamt
460 1.2.2.2 yamt /*
461 1.2.2.2 yamt * Synchronize the disks....
462 1.2.2.2 yamt */
463 1.2.2.2 yamt vfs_shutdown();
464 1.2.2.2 yamt
465 1.2.2.2 yamt /*
466 1.2.2.2 yamt * If we've been adjusting the clock, the todr
467 1.2.2.2 yamt * will be out of synch; adjust it now.
468 1.2.2.2 yamt */
469 1.2.2.2 yamt resettodr();
470 1.2.2.2 yamt }
471 1.2.2.2 yamt
472 1.2.2.2 yamt /* Disable interrupts. */
473 1.2.2.2 yamt splhigh();
474 1.2.2.2 yamt
475 1.2.2.2 yamt if (boothowto & RB_DUMP)
476 1.2.2.2 yamt dumpsys();
477 1.2.2.2 yamt
478 1.2.2.2 yamt haltsys:
479 1.2.2.2 yamt /* Run any shutdown hooks. */
480 1.2.2.2 yamt doshutdownhooks();
481 1.2.2.2 yamt
482 1.2.2.2 yamt #if 0
483 1.2.2.2 yamt if ((boothowto & RB_POWERDOWN) == RB_POWERDOWN)
484 1.2.2.2 yamt if (board && board->ab_poweroff)
485 1.2.2.2 yamt board->ab_poweroff();
486 1.2.2.2 yamt #endif
487 1.2.2.2 yamt
488 1.2.2.2 yamt /*
489 1.2.2.2 yamt * Firmware may autoboot (depending on settings), and we cannot pass
490 1.2.2.2 yamt * flags to it (at least I haven't figured out how to yet), so
491 1.2.2.2 yamt * we "pseudo-halt" now.
492 1.2.2.2 yamt */
493 1.2.2.2 yamt if (boothowto & RB_HALT) {
494 1.2.2.2 yamt printf("\n");
495 1.2.2.2 yamt printf("The operating system has halted.\n");
496 1.2.2.2 yamt printf("Please press any key to reboot.\n\n");
497 1.2.2.2 yamt cnpollc(1); /* For proper keyboard command handling */
498 1.2.2.2 yamt cngetc();
499 1.2.2.2 yamt cnpollc(0);
500 1.2.2.2 yamt }
501 1.2.2.2 yamt
502 1.2.2.2 yamt printf("reseting board...\n\n");
503 1.2.2.2 yamt mips_icache_sync_all();
504 1.2.2.2 yamt mips_dcache_wbinv_all();
505 1.2.2.2 yamt __asm volatile("jr %0" :: "r"(MIPS_RESET_EXC_VEC));
506 1.2.2.2 yamt printf("Oops, back from reset\n\nSpinning...");
507 1.2.2.2 yamt for (;;)
508 1.2.2.2 yamt /* spin forever */ ; /* XXX */
509 1.2.2.2 yamt /*NOTREACHED*/
510 1.2.2.2 yamt }
511