integrator_machdep.c revision 1.21 1 1.21 thorpej /* $NetBSD: integrator_machdep.c,v 1.21 2002/04/05 16:58:08 thorpej Exp $ */
2 1.1 rearnsha
3 1.1 rearnsha /*
4 1.1 rearnsha * Copyright (c) 2001 ARM Ltd
5 1.1 rearnsha * All rights reserved.
6 1.1 rearnsha *
7 1.1 rearnsha * Redistribution and use in source and binary forms, with or without
8 1.1 rearnsha * modification, are permitted provided that the following conditions
9 1.1 rearnsha * are met:
10 1.1 rearnsha * 1. Redistributions of source code must retain the above copyright
11 1.1 rearnsha * notice, this list of conditions and the following disclaimer.
12 1.1 rearnsha * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 rearnsha * notice, this list of conditions and the following disclaimer in the
14 1.1 rearnsha * documentation and/or other materials provided with the distribution.
15 1.1 rearnsha * 3. The name of the company may not be used to endorse or promote
16 1.1 rearnsha * products derived from this software without specific prior written
17 1.1 rearnsha * permission.
18 1.1 rearnsha *
19 1.1 rearnsha * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 1.1 rearnsha * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 1.1 rearnsha * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.1 rearnsha * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 1.1 rearnsha * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 1.1 rearnsha * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 1.1 rearnsha * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 rearnsha * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 rearnsha * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 rearnsha * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 rearnsha * SUCH DAMAGE.
30 1.1 rearnsha *
31 1.1 rearnsha * Copyright (c) 1997,1998 Mark Brinicombe.
32 1.1 rearnsha * Copyright (c) 1997,1998 Causality Limited.
33 1.1 rearnsha * All rights reserved.
34 1.1 rearnsha *
35 1.1 rearnsha * Redistribution and use in source and binary forms, with or without
36 1.1 rearnsha * modification, are permitted provided that the following conditions
37 1.1 rearnsha * are met:
38 1.1 rearnsha * 1. Redistributions of source code must retain the above copyright
39 1.1 rearnsha * notice, this list of conditions and the following disclaimer.
40 1.1 rearnsha * 2. Redistributions in binary form must reproduce the above copyright
41 1.1 rearnsha * notice, this list of conditions and the following disclaimer in the
42 1.1 rearnsha * documentation and/or other materials provided with the distribution.
43 1.1 rearnsha * 3. All advertising materials mentioning features or use of this software
44 1.1 rearnsha * must display the following acknowledgement:
45 1.1 rearnsha * This product includes software developed by Mark Brinicombe
46 1.1 rearnsha * for the NetBSD Project.
47 1.1 rearnsha * 4. The name of the company nor the name of the author may be used to
48 1.1 rearnsha * endorse or promote products derived from this software without specific
49 1.1 rearnsha * prior written permission.
50 1.1 rearnsha *
51 1.1 rearnsha * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
52 1.1 rearnsha * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 1.1 rearnsha * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 1.1 rearnsha * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
55 1.1 rearnsha * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
56 1.1 rearnsha * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
57 1.1 rearnsha * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 1.1 rearnsha * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 1.1 rearnsha * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 1.1 rearnsha * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 1.1 rearnsha * SUCH DAMAGE.
62 1.1 rearnsha *
63 1.1 rearnsha * Machine dependant functions for kernel setup for integrator board
64 1.1 rearnsha *
65 1.1 rearnsha * Created : 24/11/97
66 1.1 rearnsha */
67 1.1 rearnsha
68 1.1 rearnsha #include "opt_ddb.h"
69 1.1 rearnsha #include "opt_pmap_debug.h"
70 1.1 rearnsha
71 1.1 rearnsha #include <sys/param.h>
72 1.1 rearnsha #include <sys/device.h>
73 1.1 rearnsha #include <sys/systm.h>
74 1.1 rearnsha #include <sys/kernel.h>
75 1.1 rearnsha #include <sys/exec.h>
76 1.1 rearnsha #include <sys/proc.h>
77 1.1 rearnsha #include <sys/msgbuf.h>
78 1.1 rearnsha #include <sys/reboot.h>
79 1.1 rearnsha #include <sys/termios.h>
80 1.1 rearnsha
81 1.1 rearnsha #include <dev/cons.h>
82 1.1 rearnsha
83 1.1 rearnsha #include <machine/db_machdep.h>
84 1.1 rearnsha #include <ddb/db_sym.h>
85 1.1 rearnsha #include <ddb/db_extern.h>
86 1.1 rearnsha
87 1.1 rearnsha #include <machine/bootconfig.h>
88 1.1 rearnsha #include <machine/bus.h>
89 1.1 rearnsha #include <machine/cpu.h>
90 1.1 rearnsha #include <machine/frame.h>
91 1.1 rearnsha #include <machine/intr.h>
92 1.8 thorpej #include <evbarm/ifpga/irqhandler.h> /* XXX XXX XXX */
93 1.6 thorpej #include <arm/undefined.h>
94 1.1 rearnsha
95 1.1 rearnsha #include <evbarm/integrator/integrator_boot.h>
96 1.1 rearnsha
97 1.1 rearnsha #include "opt_ipkdb.h"
98 1.1 rearnsha #include "pci.h"
99 1.1 rearnsha
100 1.1 rearnsha void ifpga_reset(void) __attribute__((noreturn));
101 1.1 rearnsha /*
102 1.1 rearnsha * Address to call from cpu_reset() to reset the machine.
103 1.1 rearnsha * This is machine architecture dependant as it varies depending
104 1.1 rearnsha * on where the ROM appears when you turn the MMU off.
105 1.1 rearnsha */
106 1.1 rearnsha
107 1.1 rearnsha u_int cpu_reset_address = (u_int) ifpga_reset;
108 1.1 rearnsha
109 1.1 rearnsha /* Define various stack sizes in pages */
110 1.1 rearnsha #define IRQ_STACK_SIZE 1
111 1.1 rearnsha #define ABT_STACK_SIZE 1
112 1.1 rearnsha #ifdef IPKDB
113 1.1 rearnsha #define UND_STACK_SIZE 2
114 1.1 rearnsha #else
115 1.1 rearnsha #define UND_STACK_SIZE 1
116 1.1 rearnsha #endif
117 1.1 rearnsha
118 1.1 rearnsha struct intbootinfo intbootinfo;
119 1.1 rearnsha BootConfig bootconfig; /* Boot config storage */
120 1.1 rearnsha static char bootargs[MAX_BOOT_STRING + 1];
121 1.1 rearnsha char *boot_args = NULL;
122 1.1 rearnsha char *boot_file = NULL;
123 1.1 rearnsha
124 1.1 rearnsha vm_offset_t physical_start;
125 1.1 rearnsha vm_offset_t physical_freestart;
126 1.1 rearnsha vm_offset_t physical_freeend;
127 1.1 rearnsha vm_offset_t physical_end;
128 1.1 rearnsha u_int free_pages;
129 1.1 rearnsha vm_offset_t pagetables_start;
130 1.1 rearnsha int physmem = 0;
131 1.1 rearnsha
132 1.1 rearnsha /*int debug_flags;*/
133 1.1 rearnsha #ifndef PMAP_STATIC_L1S
134 1.1 rearnsha int max_processes = 64; /* Default number */
135 1.1 rearnsha #endif /* !PMAP_STATIC_L1S */
136 1.1 rearnsha
137 1.1 rearnsha /* Physical and virtual addresses for some global pages */
138 1.1 rearnsha pv_addr_t systempage;
139 1.1 rearnsha pv_addr_t irqstack;
140 1.1 rearnsha pv_addr_t undstack;
141 1.1 rearnsha pv_addr_t abtstack;
142 1.1 rearnsha pv_addr_t kernelstack;
143 1.1 rearnsha
144 1.1 rearnsha vm_offset_t msgbufphys;
145 1.1 rearnsha
146 1.1 rearnsha extern u_int data_abort_handler_address;
147 1.1 rearnsha extern u_int prefetch_abort_handler_address;
148 1.1 rearnsha extern u_int undefined_handler_address;
149 1.1 rearnsha
150 1.1 rearnsha #ifdef PMAP_DEBUG
151 1.1 rearnsha extern int pmap_debug_level;
152 1.1 rearnsha #endif
153 1.1 rearnsha
154 1.1 rearnsha #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
155 1.1 rearnsha #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
156 1.1 rearnsha #define KERNEL_PT_VMDATA 2 /* Page tables for mapping kernel VM */
157 1.17 chris #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
158 1.1 rearnsha #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
159 1.1 rearnsha
160 1.14 thorpej pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
161 1.1 rearnsha
162 1.1 rearnsha struct user *proc0paddr;
163 1.1 rearnsha
164 1.1 rearnsha /* Prototypes */
165 1.1 rearnsha
166 1.1 rearnsha void consinit __P((void));
167 1.1 rearnsha
168 1.1 rearnsha void process_kernel_args __P((char *));
169 1.1 rearnsha void data_abort_handler __P((trapframe_t *frame));
170 1.1 rearnsha void prefetch_abort_handler __P((trapframe_t *frame));
171 1.1 rearnsha void undefinedinstruction_bounce __P((trapframe_t *frame));
172 1.1 rearnsha extern void configure __P((void));
173 1.1 rearnsha extern void parse_mi_bootargs __P((char *args));
174 1.1 rearnsha extern void dumpsys __P((void));
175 1.1 rearnsha
176 1.1 rearnsha /* A load of console goo. */
177 1.1 rearnsha #include "vga.h"
178 1.1 rearnsha #if (NVGA > 0)
179 1.1 rearnsha #include <dev/ic/mc6845reg.h>
180 1.1 rearnsha #include <dev/ic/pcdisplayvar.h>
181 1.1 rearnsha #include <dev/ic/vgareg.h>
182 1.1 rearnsha #include <dev/ic/vgavar.h>
183 1.1 rearnsha #endif
184 1.1 rearnsha
185 1.1 rearnsha #include "pckbc.h"
186 1.1 rearnsha #if (NPCKBC > 0)
187 1.1 rearnsha #include <dev/ic/i8042reg.h>
188 1.1 rearnsha #include <dev/ic/pckbcvar.h>
189 1.1 rearnsha #endif
190 1.1 rearnsha
191 1.1 rearnsha #include "com.h"
192 1.1 rearnsha #if (NCOM > 0)
193 1.1 rearnsha #include <dev/ic/comreg.h>
194 1.1 rearnsha #include <dev/ic/comvar.h>
195 1.1 rearnsha #ifndef CONCOMADDR
196 1.1 rearnsha #define CONCOMADDR 0x3f8
197 1.1 rearnsha #endif
198 1.1 rearnsha #endif
199 1.1 rearnsha
200 1.1 rearnsha #define CONSPEED B115200
201 1.1 rearnsha #ifndef CONSPEED
202 1.1 rearnsha #define CONSPEED B9600 /* TTYDEF_SPEED */
203 1.1 rearnsha #endif
204 1.1 rearnsha #ifndef CONMODE
205 1.1 rearnsha #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
206 1.1 rearnsha #endif
207 1.1 rearnsha
208 1.1 rearnsha int comcnspeed = CONSPEED;
209 1.1 rearnsha int comcnmode = CONMODE;
210 1.1 rearnsha
211 1.1 rearnsha #include "plcom.h"
212 1.1 rearnsha #if (NPLCOM > 0)
213 1.1 rearnsha #include <evbarm/dev/plcomreg.h>
214 1.1 rearnsha #include <evbarm/dev/plcomvar.h>
215 1.1 rearnsha
216 1.1 rearnsha #include <evbarm/ifpga/ifpgamem.h>
217 1.1 rearnsha #include <evbarm/ifpga/ifpgareg.h>
218 1.1 rearnsha #include <evbarm/ifpga/ifpgavar.h>
219 1.1 rearnsha #endif
220 1.1 rearnsha
221 1.1 rearnsha #ifndef CONSDEVNAME
222 1.1 rearnsha #define CONSDEVNAME "plcom"
223 1.1 rearnsha #endif
224 1.1 rearnsha
225 1.1 rearnsha #ifndef PLCONSPEED
226 1.1 rearnsha #define PLCONSPEED B38400
227 1.1 rearnsha #endif
228 1.1 rearnsha #ifndef PLCONMODE
229 1.1 rearnsha #define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
230 1.1 rearnsha #endif
231 1.1 rearnsha #ifndef PLCOMCNUNIT
232 1.1 rearnsha #define PLCOMCNUNIT -1
233 1.1 rearnsha #endif
234 1.1 rearnsha
235 1.1 rearnsha int plcomcnspeed = PLCONSPEED;
236 1.1 rearnsha int plcomcnmode = PLCONMODE;
237 1.1 rearnsha
238 1.1 rearnsha #if 0
239 1.1 rearnsha extern struct consdev kcomcons;
240 1.1 rearnsha static void kcomcnputc(dev_t, int);
241 1.1 rearnsha #endif
242 1.1 rearnsha
243 1.1 rearnsha /*
244 1.1 rearnsha * void cpu_reboot(int howto, char *bootstr)
245 1.1 rearnsha *
246 1.1 rearnsha * Reboots the system
247 1.1 rearnsha *
248 1.1 rearnsha * Deal with any syncing, unmounting, dumping and shutdown hooks,
249 1.1 rearnsha * then reset the CPU.
250 1.1 rearnsha */
251 1.1 rearnsha
252 1.1 rearnsha void
253 1.1 rearnsha cpu_reboot(howto, bootstr)
254 1.1 rearnsha int howto;
255 1.1 rearnsha char *bootstr;
256 1.1 rearnsha {
257 1.1 rearnsha #ifdef DIAGNOSTIC
258 1.1 rearnsha /* info */
259 1.1 rearnsha printf("boot: howto=%08x curproc=%p\n", howto, curproc);
260 1.1 rearnsha #endif
261 1.1 rearnsha
262 1.1 rearnsha /*
263 1.1 rearnsha * If we are still cold then hit the air brakes
264 1.1 rearnsha * and crash to earth fast
265 1.1 rearnsha */
266 1.1 rearnsha if (cold) {
267 1.1 rearnsha doshutdownhooks();
268 1.1 rearnsha printf("The operating system has halted.\n");
269 1.1 rearnsha printf("Please press any key to reboot.\n\n");
270 1.1 rearnsha cngetc();
271 1.1 rearnsha printf("rebooting...\n");
272 1.1 rearnsha ifpga_reset();
273 1.1 rearnsha /*NOTREACHED*/
274 1.1 rearnsha }
275 1.1 rearnsha
276 1.1 rearnsha /* Disable console buffering */
277 1.1 rearnsha /* cnpollc(1);*/
278 1.1 rearnsha
279 1.1 rearnsha /*
280 1.1 rearnsha * If RB_NOSYNC was not specified sync the discs.
281 1.1 rearnsha * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
282 1.1 rearnsha * It looks like syslogd is getting woken up only to find that it cannot
283 1.1 rearnsha * page part of the binary in as the filesystem has been unmounted.
284 1.1 rearnsha */
285 1.1 rearnsha if (!(howto & RB_NOSYNC))
286 1.1 rearnsha bootsync();
287 1.1 rearnsha
288 1.1 rearnsha /* Say NO to interrupts */
289 1.1 rearnsha splhigh();
290 1.1 rearnsha
291 1.1 rearnsha /* Do a dump if requested. */
292 1.1 rearnsha if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
293 1.1 rearnsha dumpsys();
294 1.1 rearnsha
295 1.1 rearnsha /* Run any shutdown hooks */
296 1.1 rearnsha doshutdownhooks();
297 1.1 rearnsha
298 1.1 rearnsha /* Make sure IRQ's are disabled */
299 1.1 rearnsha IRQdisable;
300 1.1 rearnsha
301 1.1 rearnsha if (howto & RB_HALT) {
302 1.1 rearnsha printf("The operating system has halted.\n");
303 1.1 rearnsha printf("Please press any key to reboot.\n\n");
304 1.1 rearnsha cngetc();
305 1.1 rearnsha }
306 1.1 rearnsha
307 1.1 rearnsha printf("rebooting...\n");
308 1.1 rearnsha ifpga_reset();
309 1.1 rearnsha /*NOTREACHED*/
310 1.1 rearnsha }
311 1.1 rearnsha
312 1.1 rearnsha /*
313 1.1 rearnsha * Mapping table for core kernel memory. This memory is mapped at init
314 1.1 rearnsha * time with section mappings.
315 1.1 rearnsha */
316 1.1 rearnsha struct l1_sec_map {
317 1.1 rearnsha vm_offset_t va;
318 1.1 rearnsha vm_offset_t pa;
319 1.1 rearnsha vm_size_t size;
320 1.12 thorpej vm_prot_t prot;
321 1.9 thorpej int cache;
322 1.1 rearnsha } l1_sec_table[] = {
323 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
324 1.9 thorpej { UART0_BOOT_BASE, IFPGA_IO_BASE + IFPGA_UART0, 1024 * 1024,
325 1.9 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE },
326 1.9 thorpej { UART1_BOOT_BASE, IFPGA_IO_BASE + IFPGA_UART1, 1024 * 1024,
327 1.9 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE },
328 1.1 rearnsha #endif
329 1.1 rearnsha #if NPCI > 0
330 1.9 thorpej { IFPGA_PCI_IO_VBASE, IFPGA_PCI_IO_BASE, IFPGA_PCI_IO_VSIZE,
331 1.9 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE },
332 1.9 thorpej { IFPGA_PCI_CONF_VBASE, IFPGA_PCI_CONF_BASE, IFPGA_PCI_CONF_VSIZE,
333 1.9 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE },
334 1.1 rearnsha #endif
335 1.1 rearnsha
336 1.9 thorpej { 0, 0, 0, 0, 0 }
337 1.1 rearnsha };
338 1.1 rearnsha
339 1.1 rearnsha /*
340 1.1 rearnsha * u_int initarm(struct ebsaboot *bootinfo)
341 1.1 rearnsha *
342 1.1 rearnsha * Initial entry point on startup. This gets called before main() is
343 1.1 rearnsha * entered.
344 1.1 rearnsha * It should be responsible for setting up everything that must be
345 1.1 rearnsha * in place when main is called.
346 1.1 rearnsha * This includes
347 1.1 rearnsha * Taking a copy of the boot configuration structure.
348 1.1 rearnsha * Initialising the physical console so characters can be printed.
349 1.1 rearnsha * Setting up page tables for the kernel
350 1.1 rearnsha * Relocating the kernel to the bottom of physical memory
351 1.1 rearnsha */
352 1.1 rearnsha
353 1.1 rearnsha u_int
354 1.1 rearnsha initarm(bootinfo)
355 1.1 rearnsha struct intbootinfo *bootinfo;
356 1.1 rearnsha {
357 1.1 rearnsha int loop;
358 1.1 rearnsha int loop1;
359 1.1 rearnsha u_int l1pagetable;
360 1.1 rearnsha extern int etext asm ("_etext");
361 1.1 rearnsha extern int end asm ("_end");
362 1.1 rearnsha pv_addr_t kernel_l1pt;
363 1.1 rearnsha pv_addr_t kernel_ptpt;
364 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
365 1.1 rearnsha static struct bus_space plcom_bus_space;
366 1.1 rearnsha #endif
367 1.1 rearnsha
368 1.1 rearnsha
369 1.1 rearnsha #if 0
370 1.1 rearnsha cn_tab = &kcomcons;
371 1.1 rearnsha #endif
372 1.1 rearnsha /*
373 1.1 rearnsha * Heads up ... Setup the CPU / MMU / TLB functions
374 1.1 rearnsha */
375 1.1 rearnsha if (set_cpufuncs())
376 1.1 rearnsha panic("cpu not recognized!");
377 1.1 rearnsha
378 1.1 rearnsha /* - intbootinfo.bt_memstart) / NBPG */;
379 1.1 rearnsha
380 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
381 1.1 rearnsha /*
382 1.1 rearnsha * Initialise the diagnostic serial console
383 1.1 rearnsha * This allows a means of generating output during initarm().
384 1.1 rearnsha * Once all the memory map changes are complete we can call consinit()
385 1.1 rearnsha * and not have to worry about things moving.
386 1.1 rearnsha */
387 1.1 rearnsha
388 1.1 rearnsha if (PLCOMCNUNIT == 0) {
389 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd600000);
390 1.1 rearnsha plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
391 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
392 1.1 rearnsha } else if (PLCOMCNUNIT == 1) {
393 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd700000);
394 1.1 rearnsha plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
395 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
396 1.1 rearnsha }
397 1.1 rearnsha #endif
398 1.1 rearnsha
399 1.1 rearnsha /* Talk to the user */
400 1.1 rearnsha printf("\nNetBSD/integrator booting ...\n");
401 1.1 rearnsha
402 1.1 rearnsha #if 0
403 1.1 rearnsha if (intbootinfo.bt_magic != BT_MAGIC_NUMBER_EBSA
404 1.1 rearnsha && intbootinfo.bt_magic != BT_MAGIC_NUMBER_CATS)
405 1.1 rearnsha panic("Incompatible magic number passed in boot args\n");
406 1.1 rearnsha #endif
407 1.1 rearnsha
408 1.1 rearnsha /* {
409 1.1 rearnsha int loop;
410 1.1 rearnsha for (loop = 0; loop < 8; ++loop) {
411 1.1 rearnsha printf("%08x\n", *(((int *)bootinfo)+loop));
412 1.1 rearnsha }
413 1.1 rearnsha }*/
414 1.1 rearnsha
415 1.1 rearnsha /*
416 1.1 rearnsha * Ok we have the following memory map
417 1.1 rearnsha *
418 1.1 rearnsha * virtual address == physical address apart from the areas:
419 1.1 rearnsha * 0x00000000 -> 0x000fffff which is mapped to
420 1.1 rearnsha * top 1MB of physical memory
421 1.1 rearnsha * 0x00100000 -> 0x0fffffff which is mapped to
422 1.1 rearnsha * physical addresses 0x00100000 -> 0x0fffffff
423 1.1 rearnsha * 0x10000000 -> 0x1fffffff which is mapped to
424 1.1 rearnsha * physical addresses 0x00000000 -> 0x0fffffff
425 1.1 rearnsha * 0x20000000 -> 0xefffffff which is mapped to
426 1.1 rearnsha * physical addresses 0x20000000 -> 0xefffffff
427 1.1 rearnsha * 0xf0000000 -> 0xf03fffff which is mapped to
428 1.1 rearnsha * physical addresses 0x00000000 -> 0x003fffff
429 1.1 rearnsha *
430 1.1 rearnsha * This means that the kernel is mapped suitably for continuing
431 1.1 rearnsha * execution, all I/O is mapped 1:1 virtual to physical and
432 1.1 rearnsha * physical memory is accessible.
433 1.1 rearnsha *
434 1.1 rearnsha * The initarm() has the responsibility for creating the kernel
435 1.1 rearnsha * page tables.
436 1.1 rearnsha * It must also set up various memory pointers that are used
437 1.1 rearnsha * by pmap etc.
438 1.1 rearnsha */
439 1.1 rearnsha
440 1.1 rearnsha /*
441 1.1 rearnsha * Examine the boot args string for options we need to know about
442 1.1 rearnsha * now.
443 1.1 rearnsha */
444 1.1 rearnsha #if 0
445 1.1 rearnsha process_kernel_args((char *)intbootinfo.bt_args);
446 1.1 rearnsha #endif
447 1.1 rearnsha
448 1.1 rearnsha printf("initarm: Configuring system ...\n");
449 1.1 rearnsha
450 1.1 rearnsha /*
451 1.1 rearnsha * Set up the variables that define the availablilty of
452 1.1 rearnsha * physical memory
453 1.1 rearnsha */
454 1.1 rearnsha physical_start = 0 /*intbootinfo.bt_memstart*/;
455 1.1 rearnsha physical_freestart = physical_start;
456 1.1 rearnsha
457 1.1 rearnsha #if 0
458 1.1 rearnsha physical_end = /*intbootinfo.bt_memend*/ /*intbootinfo.bi_nrpages * NBPG */ 32*1024*1024;
459 1.1 rearnsha #else
460 1.1 rearnsha {
461 1.1 rearnsha volatile unsigned long *cm_sdram
462 1.1 rearnsha = (volatile unsigned long *)0x10000020;
463 1.1 rearnsha
464 1.1 rearnsha switch ((*cm_sdram >> 2) & 0x7)
465 1.1 rearnsha {
466 1.1 rearnsha case 0:
467 1.1 rearnsha physical_end = 16 * 1024 * 1024;
468 1.1 rearnsha break;
469 1.1 rearnsha case 1:
470 1.1 rearnsha physical_end = 32 * 1024 * 1024;
471 1.1 rearnsha break;
472 1.1 rearnsha case 2:
473 1.1 rearnsha physical_end = 64 * 1024 * 1024;
474 1.1 rearnsha break;
475 1.1 rearnsha case 3:
476 1.1 rearnsha physical_end = 128 * 1024 * 1024;
477 1.1 rearnsha break;
478 1.1 rearnsha case 4:
479 1.1 rearnsha physical_end = 256 * 1024 * 1024;
480 1.1 rearnsha break;
481 1.1 rearnsha default:
482 1.1 rearnsha printf("CM_SDRAM retuns unknown value, using 16M\n");
483 1.1 rearnsha physical_end = 16 * 1024 * 1024;
484 1.1 rearnsha break;
485 1.1 rearnsha }
486 1.1 rearnsha }
487 1.1 rearnsha #endif
488 1.1 rearnsha
489 1.1 rearnsha physical_freeend = physical_end;
490 1.1 rearnsha free_pages = (physical_end - physical_start) / NBPG;
491 1.1 rearnsha
492 1.1 rearnsha /* Set up the bootconfig structure for the benefit of pmap.c */
493 1.1 rearnsha bootconfig.dramblocks = 1;
494 1.1 rearnsha bootconfig.dram[0].address = physical_start;
495 1.1 rearnsha bootconfig.dram[0].pages = free_pages;
496 1.1 rearnsha
497 1.1 rearnsha physmem = (physical_end - physical_start) / NBPG;
498 1.1 rearnsha
499 1.1 rearnsha /* Tell the user about the memory */
500 1.1 rearnsha printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
501 1.1 rearnsha physical_start, physical_end - 1);
502 1.1 rearnsha
503 1.1 rearnsha /*
504 1.1 rearnsha * Ok the kernel occupies the bottom of physical memory.
505 1.1 rearnsha * The first free page after the kernel can be found in
506 1.1 rearnsha * intbootinfo->bt_memavail
507 1.1 rearnsha * We now need to allocate some fixed page tables to get the kernel
508 1.1 rearnsha * going.
509 1.1 rearnsha * We allocate one page directory and a number page tables and store
510 1.1 rearnsha * the physical addresses in the kernel_pt_table array.
511 1.1 rearnsha *
512 1.1 rearnsha * Ok the next bit of physical allocation may look complex but it is
513 1.1 rearnsha * simple really. I have done it like this so that no memory gets
514 1.1 rearnsha * wasted during the allocation of various pages and tables that are
515 1.1 rearnsha * all different sizes.
516 1.1 rearnsha * The start addresses will be page aligned.
517 1.1 rearnsha * We allocate the kernel page directory on the first free 16KB boundry
518 1.1 rearnsha * we find.
519 1.1 rearnsha * We allocate the kernel page tables on the first 4KB boundry we find.
520 1.1 rearnsha * Since we allocate at least 3 L2 pagetables we know that we must
521 1.1 rearnsha * encounter at least one 16KB aligned address.
522 1.1 rearnsha */
523 1.1 rearnsha
524 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
525 1.1 rearnsha printf("Allocating page tables\n");
526 1.1 rearnsha #endif
527 1.1 rearnsha
528 1.1 rearnsha /* Update the address of the first free 16KB chunk of physical memory */
529 1.1 rearnsha physical_freestart = ((uintptr_t) &end - KERNEL_TEXT_BASE + PGOFSET)
530 1.1 rearnsha & ~PGOFSET;
531 1.1 rearnsha #if 0
532 1.1 rearnsha physical_freestart += (kernexec->a_syms + sizeof(int)
533 1.1 rearnsha + *(u_int *)((int)end + kernexec->a_syms + sizeof(int))
534 1.1 rearnsha + (NBPG - 1)) & ~(NBPG - 1);
535 1.1 rearnsha #endif
536 1.1 rearnsha
537 1.1 rearnsha free_pages -= (physical_freestart - physical_start) / NBPG;
538 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
539 1.1 rearnsha printf("freestart = %#lx, free_pages = %d (%#x)\n",
540 1.1 rearnsha physical_freestart, free_pages, free_pages);
541 1.1 rearnsha #endif
542 1.1 rearnsha
543 1.1 rearnsha /* Define a macro to simplify memory allocation */
544 1.1 rearnsha #define valloc_pages(var, np) \
545 1.1 rearnsha alloc_pages((var).pv_pa, (np)); \
546 1.1 rearnsha (var).pv_va = KERNEL_TEXT_BASE + (var).pv_pa - physical_start;
547 1.1 rearnsha
548 1.1 rearnsha #define alloc_pages(var, np) \
549 1.1 rearnsha (var) = physical_freestart; \
550 1.1 rearnsha physical_freestart += ((np) * NBPG); \
551 1.1 rearnsha free_pages -= (np); \
552 1.1 rearnsha memset((char *)(var), 0, ((np) * NBPG));
553 1.1 rearnsha
554 1.1 rearnsha loop1 = 0;
555 1.1 rearnsha kernel_l1pt.pv_pa = 0;
556 1.1 rearnsha for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
557 1.1 rearnsha /* Are we 16KB aligned for an L1 ? */
558 1.21 thorpej if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0
559 1.1 rearnsha && kernel_l1pt.pv_pa == 0) {
560 1.21 thorpej valloc_pages(kernel_l1pt, L1_TABLE_SIZE / NBPG);
561 1.1 rearnsha } else {
562 1.14 thorpej alloc_pages(kernel_pt_table[loop1].pv_pa,
563 1.21 thorpej L2_TABLE_SIZE / NBPG);
564 1.1 rearnsha ++loop1;
565 1.14 thorpej kernel_pt_table[loop1].pv_va =
566 1.14 thorpej kernel_pt_table[loop1].pv_pa;
567 1.1 rearnsha }
568 1.1 rearnsha }
569 1.1 rearnsha
570 1.1 rearnsha /* This should never be able to happen but better confirm that. */
571 1.21 thorpej if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
572 1.1 rearnsha panic("initarm: Failed to align the kernel page directory\n");
573 1.1 rearnsha
574 1.1 rearnsha /*
575 1.1 rearnsha * Allocate a page for the system page mapped to V0x00000000
576 1.1 rearnsha * This page will just contain the system vectors and can be
577 1.1 rearnsha * shared by all processes.
578 1.1 rearnsha */
579 1.1 rearnsha alloc_pages(systempage.pv_pa, 1);
580 1.1 rearnsha
581 1.1 rearnsha /* Allocate a page for the page table to map kernel page tables*/
582 1.21 thorpej valloc_pages(kernel_ptpt, L2_TABLE_SIZE / NBPG);
583 1.1 rearnsha
584 1.1 rearnsha /* Allocate stacks for all modes */
585 1.1 rearnsha valloc_pages(irqstack, IRQ_STACK_SIZE);
586 1.1 rearnsha valloc_pages(abtstack, ABT_STACK_SIZE);
587 1.1 rearnsha valloc_pages(undstack, UND_STACK_SIZE);
588 1.1 rearnsha valloc_pages(kernelstack, UPAGES);
589 1.1 rearnsha
590 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
591 1.1 rearnsha printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va);
592 1.1 rearnsha printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va);
593 1.1 rearnsha printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va);
594 1.1 rearnsha printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va);
595 1.1 rearnsha #endif
596 1.1 rearnsha
597 1.1 rearnsha alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
598 1.1 rearnsha
599 1.1 rearnsha /*
600 1.1 rearnsha * Ok we have allocated physical pages for the primary kernel
601 1.1 rearnsha * page tables
602 1.1 rearnsha */
603 1.1 rearnsha
604 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
605 1.1 rearnsha printf("Creating L1 page table at %#lx\n", kernel_l1pt.pv_pa);
606 1.1 rearnsha #endif
607 1.1 rearnsha
608 1.1 rearnsha /*
609 1.1 rearnsha * Now we start consturction of the L1 page table
610 1.1 rearnsha * We start by mapping the L2 page tables into the L1.
611 1.1 rearnsha * This means that we can replace L1 mappings later on if necessary
612 1.1 rearnsha */
613 1.1 rearnsha l1pagetable = kernel_l1pt.pv_pa;
614 1.1 rearnsha
615 1.1 rearnsha /* Map the L2 pages tables in the L1 page table */
616 1.11 thorpej pmap_link_l2pt(l1pagetable, 0x00000000,
617 1.14 thorpej &kernel_pt_table[KERNEL_PT_SYS]);
618 1.11 thorpej pmap_link_l2pt(l1pagetable, KERNEL_BASE,
619 1.14 thorpej &kernel_pt_table[KERNEL_PT_KERNEL]);
620 1.1 rearnsha for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
621 1.11 thorpej pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
622 1.14 thorpej &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
623 1.18 thorpej pmap_link_l2pt(l1pagetable, PTE_BASE,
624 1.14 thorpej &kernel_ptpt);
625 1.17 chris
626 1.17 chris /* update the top of the kernel VM */
627 1.19 thorpej pmap_curmaxkvaddr =
628 1.19 thorpej KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
629 1.1 rearnsha
630 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
631 1.1 rearnsha printf("Mapping kernel\n");
632 1.1 rearnsha #endif
633 1.1 rearnsha
634 1.1 rearnsha /* Now we fill in the L2 pagetable for the kernel static code/data */
635 1.1 rearnsha
636 1.1 rearnsha {
637 1.1 rearnsha u_int logical;
638 1.1 rearnsha size_t textsize = (uintptr_t) &etext - KERNEL_TEXT_BASE;
639 1.1 rearnsha size_t totalsize = (uintptr_t) &end - KERNEL_TEXT_BASE;
640 1.1 rearnsha
641 1.1 rearnsha /* Round down text size and round up total size
642 1.1 rearnsha */
643 1.1 rearnsha textsize = textsize & ~PGOFSET;
644 1.1 rearnsha totalsize = (totalsize + PGOFSET) & ~PGOFSET;
645 1.14 thorpej /* logical = pmap_map_chunk(l1pagetable,
646 1.12 thorpej KERNEL_BASE, physical_start, KERNEL_TEXT_BASE - KERNEL_BASE,
647 1.12 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); */
648 1.14 thorpej logical = pmap_map_chunk(l1pagetable,
649 1.1 rearnsha KERNEL_TEXT_BASE, physical_start, textsize,
650 1.12 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
651 1.14 thorpej logical += pmap_map_chunk(l1pagetable,
652 1.1 rearnsha KERNEL_TEXT_BASE + logical, physical_start + logical,
653 1.12 thorpej totalsize - textsize, VM_PROT_READ|VM_PROT_WRITE,
654 1.12 thorpej PTE_CACHE);
655 1.1 rearnsha #if 0
656 1.14 thorpej logical += pmap_map_chunk(l1pagetable,
657 1.13 thorpej KERNEL_BASE + logical,
658 1.1 rearnsha physical_start + logical, kernexec->a_syms + sizeof(int)
659 1.1 rearnsha + *(u_int *)((int)end + kernexec->a_syms + sizeof(int)),
660 1.12 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
661 1.1 rearnsha #endif
662 1.1 rearnsha }
663 1.1 rearnsha
664 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
665 1.1 rearnsha printf("Constructing L2 page tables\n");
666 1.1 rearnsha #endif
667 1.1 rearnsha
668 1.1 rearnsha /* Map the boot arguments page */
669 1.1 rearnsha #if 0
670 1.15 thorpej pmap_map_entry(l1pagetable, intbootinfo.bt_vargp,
671 1.10 thorpej intbootinfo.bt_pargp, VM_PROT_READ, PTE_CACHE);
672 1.1 rearnsha #endif
673 1.1 rearnsha
674 1.1 rearnsha /* Map the stack pages */
675 1.14 thorpej pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
676 1.14 thorpej IRQ_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
677 1.14 thorpej pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
678 1.14 thorpej ABT_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
679 1.14 thorpej pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
680 1.14 thorpej UND_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
681 1.14 thorpej pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
682 1.14 thorpej UPAGES * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
683 1.13 thorpej
684 1.14 thorpej pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
685 1.21 thorpej L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
686 1.1 rearnsha
687 1.1 rearnsha /* Map the page table that maps the kernel pages */
688 1.16 thorpej pmap_map_entry(l1pagetable, kernel_ptpt.pv_va, kernel_ptpt.pv_pa,
689 1.10 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
690 1.1 rearnsha
691 1.1 rearnsha /*
692 1.1 rearnsha * Map entries in the page table used to map PTE's
693 1.1 rearnsha * Basically every kernel page table gets mapped here
694 1.1 rearnsha */
695 1.1 rearnsha /* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
696 1.15 thorpej pmap_map_entry(l1pagetable,
697 1.18 thorpej PTE_BASE + (KERNEL_BASE >> (PGSHIFT-2)),
698 1.14 thorpej kernel_pt_table[KERNEL_PT_KERNEL].pv_pa,
699 1.10 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
700 1.15 thorpej pmap_map_entry(l1pagetable,
701 1.18 thorpej PTE_BASE + (PTE_BASE >> (PGSHIFT-2)),
702 1.10 thorpej kernel_ptpt.pv_pa,
703 1.10 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
704 1.15 thorpej pmap_map_entry(l1pagetable,
705 1.18 thorpej PTE_BASE + (0x00000000 >> (PGSHIFT-2)),
706 1.14 thorpej kernel_pt_table[KERNEL_PT_SYS].pv_pa,
707 1.10 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
708 1.1 rearnsha for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
709 1.15 thorpej pmap_map_entry(l1pagetable,
710 1.18 thorpej PTE_BASE + ((KERNEL_VM_BASE +
711 1.1 rearnsha (loop * 0x00400000)) >> (PGSHIFT-2)),
712 1.14 thorpej kernel_pt_table[KERNEL_PT_VMDATA + loop].pv_pa,
713 1.10 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
714 1.1 rearnsha
715 1.20 thorpej /* Map the vector page. */
716 1.1 rearnsha #if 1
717 1.1 rearnsha /* MULTI-ICE requires that page 0 is NC/NB so that it can download
718 1.1 rearnsha the cache-clean code there. */
719 1.20 thorpej pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
720 1.10 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
721 1.1 rearnsha #else
722 1.20 thorpej pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
723 1.20 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
724 1.1 rearnsha #endif
725 1.1 rearnsha /* Map the core memory needed before autoconfig */
726 1.1 rearnsha loop = 0;
727 1.1 rearnsha while (l1_sec_table[loop].size) {
728 1.1 rearnsha vm_size_t sz;
729 1.1 rearnsha
730 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
731 1.1 rearnsha printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
732 1.1 rearnsha l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
733 1.1 rearnsha l1_sec_table[loop].va);
734 1.1 rearnsha #endif
735 1.21 thorpej for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_S_SIZE)
736 1.9 thorpej pmap_map_section(l1pagetable,
737 1.9 thorpej l1_sec_table[loop].va + sz,
738 1.1 rearnsha l1_sec_table[loop].pa + sz,
739 1.9 thorpej l1_sec_table[loop].prot,
740 1.9 thorpej l1_sec_table[loop].cache);
741 1.1 rearnsha ++loop;
742 1.1 rearnsha }
743 1.1 rearnsha
744 1.1 rearnsha /*
745 1.1 rearnsha * Now we have the real page tables in place so we can switch to them.
746 1.1 rearnsha * Once this is done we will be running with the REAL kernel page tables.
747 1.1 rearnsha */
748 1.1 rearnsha
749 1.1 rearnsha /* Switch tables */
750 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
751 1.1 rearnsha printf("freestart = %#lx, free_pages = %d (%#x)\n",
752 1.1 rearnsha physical_freestart, free_pages, free_pages);
753 1.1 rearnsha printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
754 1.1 rearnsha #endif
755 1.1 rearnsha
756 1.1 rearnsha setttb(kernel_l1pt.pv_pa);
757 1.1 rearnsha
758 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
759 1.1 rearnsha printf("done!\n");
760 1.1 rearnsha #endif
761 1.1 rearnsha
762 1.1 rearnsha #ifdef PLCONSOLE
763 1.1 rearnsha /*
764 1.1 rearnsha * The IFPGA registers have just moved.
765 1.1 rearnsha * Detach the diagnostic serial port and reattach at the new address.
766 1.1 rearnsha */
767 1.1 rearnsha plcomcndetach();
768 1.1 rearnsha #endif
769 1.1 rearnsha
770 1.1 rearnsha /*
771 1.1 rearnsha * XXX this should only be done in main() but it useful to
772 1.1 rearnsha * have output earlier ...
773 1.1 rearnsha */
774 1.1 rearnsha consinit();
775 1.1 rearnsha
776 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
777 1.1 rearnsha printf("bootstrap done.\n");
778 1.1 rearnsha #endif
779 1.1 rearnsha
780 1.20 thorpej arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
781 1.1 rearnsha
782 1.1 rearnsha /*
783 1.1 rearnsha * Pages were allocated during the secondary bootstrap for the
784 1.1 rearnsha * stacks for different CPU modes.
785 1.1 rearnsha * We must now set the r13 registers in the different CPU modes to
786 1.1 rearnsha * point to these stacks.
787 1.1 rearnsha * Since the ARM stacks use STMFD etc. we must set r13 to the top end
788 1.1 rearnsha * of the stack memory.
789 1.1 rearnsha */
790 1.1 rearnsha printf("init subsystems: stacks ");
791 1.1 rearnsha
792 1.1 rearnsha set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
793 1.1 rearnsha set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
794 1.1 rearnsha set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
795 1.1 rearnsha
796 1.1 rearnsha /*
797 1.1 rearnsha * Well we should set a data abort handler.
798 1.1 rearnsha * Once things get going this will change as we will need a proper handler.
799 1.1 rearnsha * Until then we will use a handler that just panics but tells us
800 1.1 rearnsha * why.
801 1.1 rearnsha * Initialisation of the vectors will just panic on a data abort.
802 1.1 rearnsha * This just fills in a slighly better one.
803 1.1 rearnsha */
804 1.1 rearnsha printf("vectors ");
805 1.1 rearnsha data_abort_handler_address = (u_int)data_abort_handler;
806 1.1 rearnsha prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
807 1.1 rearnsha undefined_handler_address = (u_int)undefinedinstruction_bounce;
808 1.1 rearnsha
809 1.1 rearnsha /* At last !
810 1.1 rearnsha * We now have the kernel in physical memory from the bottom upwards.
811 1.1 rearnsha * Kernel page tables are physically above this.
812 1.1 rearnsha * The kernel is mapped to KERNEL_TEXT_BASE
813 1.1 rearnsha * The kernel data PTs will handle the mapping of 0xf1000000-0xf3ffffff
814 1.1 rearnsha * The page tables are mapped to 0xefc00000
815 1.1 rearnsha */
816 1.1 rearnsha
817 1.1 rearnsha /* Initialise the undefined instruction handlers */
818 1.1 rearnsha printf("undefined ");
819 1.1 rearnsha undefined_init();
820 1.1 rearnsha
821 1.1 rearnsha /* Boot strap pmap telling it where the kernel page table is */
822 1.1 rearnsha printf("pmap ");
823 1.1 rearnsha pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
824 1.1 rearnsha
825 1.1 rearnsha /* Setup the IRQ system */
826 1.1 rearnsha printf("irq ");
827 1.1 rearnsha irq_init();
828 1.1 rearnsha
829 1.1 rearnsha printf("done.\n");
830 1.1 rearnsha
831 1.1 rearnsha #ifdef IPKDB
832 1.1 rearnsha /* Initialise ipkdb */
833 1.1 rearnsha ipkdb_init();
834 1.1 rearnsha if (boothowto & RB_KDB)
835 1.1 rearnsha ipkdb_connect(0);
836 1.1 rearnsha #endif
837 1.1 rearnsha
838 1.1 rearnsha #ifdef DDB
839 1.1 rearnsha db_machine_init();
840 1.4 thorpej
841 1.4 thorpej /* Firmware doesn't load symbols. */
842 1.4 thorpej ddb_init(0, NULL, NULL);
843 1.1 rearnsha
844 1.1 rearnsha if (boothowto & RB_KDB)
845 1.1 rearnsha Debugger();
846 1.1 rearnsha #endif
847 1.1 rearnsha
848 1.1 rearnsha /* We return the new stack pointer address */
849 1.1 rearnsha return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
850 1.1 rearnsha }
851 1.1 rearnsha
852 1.1 rearnsha void
853 1.1 rearnsha process_kernel_args(args)
854 1.1 rearnsha char *args;
855 1.1 rearnsha {
856 1.1 rearnsha
857 1.1 rearnsha boothowto = 0;
858 1.1 rearnsha
859 1.1 rearnsha /* Make a local copy of the bootargs */
860 1.1 rearnsha strncpy(bootargs, args, MAX_BOOT_STRING);
861 1.1 rearnsha
862 1.1 rearnsha args = bootargs;
863 1.1 rearnsha boot_file = bootargs;
864 1.1 rearnsha
865 1.1 rearnsha /* Skip the kernel image filename */
866 1.1 rearnsha while (*args != ' ' && *args != 0)
867 1.1 rearnsha ++args;
868 1.1 rearnsha
869 1.1 rearnsha if (*args != 0)
870 1.1 rearnsha *args++ = 0;
871 1.1 rearnsha
872 1.1 rearnsha while (*args == ' ')
873 1.1 rearnsha ++args;
874 1.1 rearnsha
875 1.1 rearnsha boot_args = args;
876 1.1 rearnsha
877 1.1 rearnsha printf("bootfile: %s\n", boot_file);
878 1.1 rearnsha printf("bootargs: %s\n", boot_args);
879 1.1 rearnsha
880 1.1 rearnsha parse_mi_bootargs(boot_args);
881 1.1 rearnsha }
882 1.1 rearnsha
883 1.1 rearnsha void
884 1.1 rearnsha consinit(void)
885 1.1 rearnsha {
886 1.1 rearnsha static int consinit_called = 0;
887 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
888 1.1 rearnsha static struct bus_space plcom_bus_space;
889 1.1 rearnsha #endif
890 1.1 rearnsha #if 0
891 1.1 rearnsha char *console = CONSDEVNAME;
892 1.1 rearnsha #endif
893 1.1 rearnsha
894 1.1 rearnsha if (consinit_called != 0)
895 1.1 rearnsha return;
896 1.1 rearnsha
897 1.1 rearnsha consinit_called = 1;
898 1.1 rearnsha
899 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
900 1.1 rearnsha if (PLCOMCNUNIT == 0) {
901 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space,
902 1.1 rearnsha (void*)UART0_BOOT_BASE);
903 1.1 rearnsha if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
904 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
905 1.1 rearnsha panic("can't init serial console");
906 1.1 rearnsha return;
907 1.1 rearnsha } else if (PLCOMCNUNIT == 1) {
908 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space,
909 1.1 rearnsha (void*)UART0_BOOT_BASE);
910 1.1 rearnsha if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
911 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
912 1.1 rearnsha panic("can't init serial console");
913 1.1 rearnsha return;
914 1.1 rearnsha }
915 1.1 rearnsha #endif
916 1.1 rearnsha #if (NCOM > 0)
917 1.1 rearnsha if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
918 1.1 rearnsha COM_FREQ, comcnmode))
919 1.1 rearnsha panic("can't init serial console @%x", CONCOMADDR);
920 1.1 rearnsha return;
921 1.1 rearnsha #endif
922 1.1 rearnsha panic("No serial console configured");
923 1.1 rearnsha }
924 1.1 rearnsha
925 1.1 rearnsha #if 0
926 1.1 rearnsha static bus_space_handle_t kcom_base = (bus_space_handle_t) (DC21285_PCI_IO_VBASE + CONCOMADDR);
927 1.1 rearnsha
928 1.1 rearnsha u_int8_t footbridge_bs_r_1(void *, bus_space_handle_t, bus_size_t);
929 1.1 rearnsha void footbridge_bs_w_1(void *, bus_space_handle_t, bus_size_t, u_int8_t);
930 1.1 rearnsha
931 1.1 rearnsha #define KCOM_GETBYTE(r) footbridge_bs_r_1(0, kcom_base, (r))
932 1.1 rearnsha #define KCOM_PUTBYTE(r,v) footbridge_bs_w_1(0, kcom_base, (r), (v))
933 1.1 rearnsha
934 1.1 rearnsha static int
935 1.1 rearnsha kcomcngetc(dev_t dev)
936 1.1 rearnsha {
937 1.1 rearnsha int stat, c;
938 1.1 rearnsha
939 1.1 rearnsha /* block until a character becomes available */
940 1.1 rearnsha while (!ISSET(stat = KCOM_GETBYTE(com_lsr), LSR_RXRDY))
941 1.1 rearnsha ;
942 1.1 rearnsha
943 1.1 rearnsha c = KCOM_GETBYTE(com_data);
944 1.1 rearnsha stat = KCOM_GETBYTE(com_iir);
945 1.1 rearnsha return c;
946 1.1 rearnsha }
947 1.1 rearnsha
948 1.1 rearnsha /*
949 1.1 rearnsha * Console kernel output character routine.
950 1.1 rearnsha */
951 1.1 rearnsha static void
952 1.1 rearnsha kcomcnputc(dev_t dev, int c)
953 1.1 rearnsha {
954 1.1 rearnsha int timo;
955 1.1 rearnsha
956 1.1 rearnsha /* wait for any pending transmission to finish */
957 1.1 rearnsha timo = 150000;
958 1.1 rearnsha while (!ISSET(KCOM_GETBYTE(com_lsr), LSR_TXRDY) && --timo)
959 1.1 rearnsha continue;
960 1.1 rearnsha
961 1.1 rearnsha KCOM_PUTBYTE(com_data, c);
962 1.1 rearnsha
963 1.1 rearnsha /* wait for this transmission to complete */
964 1.1 rearnsha timo = 1500000;
965 1.1 rearnsha while (!ISSET(KCOM_GETBYTE(com_lsr), LSR_TXRDY) && --timo)
966 1.1 rearnsha continue;
967 1.1 rearnsha }
968 1.1 rearnsha
969 1.1 rearnsha static void
970 1.1 rearnsha kcomcnpollc(dev_t dev, int on)
971 1.1 rearnsha {
972 1.1 rearnsha }
973 1.1 rearnsha
974 1.1 rearnsha struct consdev kcomcons = {
975 1.1 rearnsha NULL, NULL, kcomcngetc, kcomcnputc, kcomcnpollc, NULL,
976 1.1 rearnsha NODEV, CN_NORMAL
977 1.1 rearnsha };
978 1.1 rearnsha
979 1.1 rearnsha #endif
980