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