integrator_machdep.c revision 1.8 1 1.8 thorpej /* $NetBSD: integrator_machdep.c,v 1.8 2002/01/30 04:00:47 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.1 rearnsha #define KERNEL_PT_VMDATA_NUM (KERNEL_VM_SIZE >> (PDSHIFT + 2))
158 1.1 rearnsha #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
159 1.1 rearnsha
160 1.1 rearnsha pt_entry_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 map_section __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa,
169 1.1 rearnsha int cacheable));
170 1.1 rearnsha void map_pagetable __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
171 1.1 rearnsha void map_entry __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
172 1.1 rearnsha void map_entry_nc __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
173 1.1 rearnsha void map_entry_ro __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
174 1.1 rearnsha vm_size_t map_chunk __P((vm_offset_t pd, vm_offset_t pt, vm_offset_t va,
175 1.1 rearnsha vm_offset_t pa, vm_size_t size, u_int acc,
176 1.1 rearnsha u_int flg));
177 1.1 rearnsha
178 1.1 rearnsha void process_kernel_args __P((char *));
179 1.1 rearnsha void data_abort_handler __P((trapframe_t *frame));
180 1.1 rearnsha void prefetch_abort_handler __P((trapframe_t *frame));
181 1.1 rearnsha void undefinedinstruction_bounce __P((trapframe_t *frame));
182 1.1 rearnsha extern void configure __P((void));
183 1.1 rearnsha extern void parse_mi_bootargs __P((char *args));
184 1.1 rearnsha extern void dumpsys __P((void));
185 1.1 rearnsha
186 1.1 rearnsha /* A load of console goo. */
187 1.1 rearnsha #include "vga.h"
188 1.1 rearnsha #if (NVGA > 0)
189 1.1 rearnsha #include <dev/ic/mc6845reg.h>
190 1.1 rearnsha #include <dev/ic/pcdisplayvar.h>
191 1.1 rearnsha #include <dev/ic/vgareg.h>
192 1.1 rearnsha #include <dev/ic/vgavar.h>
193 1.1 rearnsha #endif
194 1.1 rearnsha
195 1.1 rearnsha #include "pckbc.h"
196 1.1 rearnsha #if (NPCKBC > 0)
197 1.1 rearnsha #include <dev/ic/i8042reg.h>
198 1.1 rearnsha #include <dev/ic/pckbcvar.h>
199 1.1 rearnsha #endif
200 1.1 rearnsha
201 1.1 rearnsha #include "com.h"
202 1.1 rearnsha #if (NCOM > 0)
203 1.1 rearnsha #include <dev/ic/comreg.h>
204 1.1 rearnsha #include <dev/ic/comvar.h>
205 1.1 rearnsha #ifndef CONCOMADDR
206 1.1 rearnsha #define CONCOMADDR 0x3f8
207 1.1 rearnsha #endif
208 1.1 rearnsha #endif
209 1.1 rearnsha
210 1.1 rearnsha #define CONSPEED B115200
211 1.1 rearnsha #ifndef CONSPEED
212 1.1 rearnsha #define CONSPEED B9600 /* TTYDEF_SPEED */
213 1.1 rearnsha #endif
214 1.1 rearnsha #ifndef CONMODE
215 1.1 rearnsha #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
216 1.1 rearnsha #endif
217 1.1 rearnsha
218 1.1 rearnsha int comcnspeed = CONSPEED;
219 1.1 rearnsha int comcnmode = CONMODE;
220 1.1 rearnsha
221 1.1 rearnsha #include "plcom.h"
222 1.1 rearnsha #if (NPLCOM > 0)
223 1.1 rearnsha #include <evbarm/dev/plcomreg.h>
224 1.1 rearnsha #include <evbarm/dev/plcomvar.h>
225 1.1 rearnsha
226 1.1 rearnsha #include <evbarm/ifpga/ifpgamem.h>
227 1.1 rearnsha #include <evbarm/ifpga/ifpgareg.h>
228 1.1 rearnsha #include <evbarm/ifpga/ifpgavar.h>
229 1.1 rearnsha #endif
230 1.1 rearnsha
231 1.1 rearnsha #ifndef CONSDEVNAME
232 1.1 rearnsha #define CONSDEVNAME "plcom"
233 1.1 rearnsha #endif
234 1.1 rearnsha
235 1.1 rearnsha #ifndef PLCONSPEED
236 1.1 rearnsha #define PLCONSPEED B38400
237 1.1 rearnsha #endif
238 1.1 rearnsha #ifndef PLCONMODE
239 1.1 rearnsha #define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
240 1.1 rearnsha #endif
241 1.1 rearnsha #ifndef PLCOMCNUNIT
242 1.1 rearnsha #define PLCOMCNUNIT -1
243 1.1 rearnsha #endif
244 1.1 rearnsha
245 1.1 rearnsha int plcomcnspeed = PLCONSPEED;
246 1.1 rearnsha int plcomcnmode = PLCONMODE;
247 1.1 rearnsha
248 1.1 rearnsha #if 0
249 1.1 rearnsha extern struct consdev kcomcons;
250 1.1 rearnsha static void kcomcnputc(dev_t, int);
251 1.1 rearnsha #endif
252 1.1 rearnsha
253 1.1 rearnsha /*
254 1.1 rearnsha * void cpu_reboot(int howto, char *bootstr)
255 1.1 rearnsha *
256 1.1 rearnsha * Reboots the system
257 1.1 rearnsha *
258 1.1 rearnsha * Deal with any syncing, unmounting, dumping and shutdown hooks,
259 1.1 rearnsha * then reset the CPU.
260 1.1 rearnsha */
261 1.1 rearnsha
262 1.1 rearnsha void
263 1.1 rearnsha cpu_reboot(howto, bootstr)
264 1.1 rearnsha int howto;
265 1.1 rearnsha char *bootstr;
266 1.1 rearnsha {
267 1.1 rearnsha #ifdef DIAGNOSTIC
268 1.1 rearnsha /* info */
269 1.1 rearnsha printf("boot: howto=%08x curproc=%p\n", howto, curproc);
270 1.1 rearnsha #endif
271 1.1 rearnsha
272 1.1 rearnsha /*
273 1.1 rearnsha * If we are still cold then hit the air brakes
274 1.1 rearnsha * and crash to earth fast
275 1.1 rearnsha */
276 1.1 rearnsha if (cold) {
277 1.1 rearnsha doshutdownhooks();
278 1.1 rearnsha printf("The operating system has halted.\n");
279 1.1 rearnsha printf("Please press any key to reboot.\n\n");
280 1.1 rearnsha cngetc();
281 1.1 rearnsha printf("rebooting...\n");
282 1.1 rearnsha ifpga_reset();
283 1.1 rearnsha /*NOTREACHED*/
284 1.1 rearnsha }
285 1.1 rearnsha
286 1.1 rearnsha /* Disable console buffering */
287 1.1 rearnsha /* cnpollc(1);*/
288 1.1 rearnsha
289 1.1 rearnsha /*
290 1.1 rearnsha * If RB_NOSYNC was not specified sync the discs.
291 1.1 rearnsha * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
292 1.1 rearnsha * It looks like syslogd is getting woken up only to find that it cannot
293 1.1 rearnsha * page part of the binary in as the filesystem has been unmounted.
294 1.1 rearnsha */
295 1.1 rearnsha if (!(howto & RB_NOSYNC))
296 1.1 rearnsha bootsync();
297 1.1 rearnsha
298 1.1 rearnsha /* Say NO to interrupts */
299 1.1 rearnsha splhigh();
300 1.1 rearnsha
301 1.1 rearnsha /* Do a dump if requested. */
302 1.1 rearnsha if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
303 1.1 rearnsha dumpsys();
304 1.1 rearnsha
305 1.1 rearnsha /* Run any shutdown hooks */
306 1.1 rearnsha doshutdownhooks();
307 1.1 rearnsha
308 1.1 rearnsha /* Make sure IRQ's are disabled */
309 1.1 rearnsha IRQdisable;
310 1.1 rearnsha
311 1.1 rearnsha if (howto & RB_HALT) {
312 1.1 rearnsha printf("The operating system has halted.\n");
313 1.1 rearnsha printf("Please press any key to reboot.\n\n");
314 1.1 rearnsha cngetc();
315 1.1 rearnsha }
316 1.1 rearnsha
317 1.1 rearnsha printf("rebooting...\n");
318 1.1 rearnsha ifpga_reset();
319 1.1 rearnsha /*NOTREACHED*/
320 1.1 rearnsha }
321 1.1 rearnsha
322 1.1 rearnsha /*
323 1.1 rearnsha * Mapping table for core kernel memory. This memory is mapped at init
324 1.1 rearnsha * time with section mappings.
325 1.1 rearnsha */
326 1.1 rearnsha struct l1_sec_map {
327 1.1 rearnsha vm_offset_t va;
328 1.1 rearnsha vm_offset_t pa;
329 1.1 rearnsha vm_size_t size;
330 1.1 rearnsha int flags;
331 1.1 rearnsha } l1_sec_table[] = {
332 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
333 1.1 rearnsha { UART0_BOOT_BASE, IFPGA_IO_BASE + IFPGA_UART0, 1024 * 1024, 0},
334 1.1 rearnsha { UART1_BOOT_BASE, IFPGA_IO_BASE + IFPGA_UART1, 1024 * 1024, 0},
335 1.1 rearnsha #endif
336 1.1 rearnsha #if NPCI > 0
337 1.1 rearnsha { IFPGA_PCI_IO_VBASE, IFPGA_PCI_IO_BASE, IFPGA_PCI_IO_VSIZE, 0},
338 1.1 rearnsha { IFPGA_PCI_CONF_VBASE, IFPGA_PCI_CONF_BASE, IFPGA_PCI_CONF_VSIZE, 0},
339 1.1 rearnsha #endif
340 1.1 rearnsha
341 1.1 rearnsha { 0, 0, 0, 0 }
342 1.1 rearnsha };
343 1.1 rearnsha
344 1.1 rearnsha /*
345 1.1 rearnsha * u_int initarm(struct ebsaboot *bootinfo)
346 1.1 rearnsha *
347 1.1 rearnsha * Initial entry point on startup. This gets called before main() is
348 1.1 rearnsha * entered.
349 1.1 rearnsha * It should be responsible for setting up everything that must be
350 1.1 rearnsha * in place when main is called.
351 1.1 rearnsha * This includes
352 1.1 rearnsha * Taking a copy of the boot configuration structure.
353 1.1 rearnsha * Initialising the physical console so characters can be printed.
354 1.1 rearnsha * Setting up page tables for the kernel
355 1.1 rearnsha * Relocating the kernel to the bottom of physical memory
356 1.1 rearnsha */
357 1.1 rearnsha
358 1.1 rearnsha u_int
359 1.1 rearnsha initarm(bootinfo)
360 1.1 rearnsha struct intbootinfo *bootinfo;
361 1.1 rearnsha {
362 1.1 rearnsha int loop;
363 1.1 rearnsha int loop1;
364 1.1 rearnsha u_int l1pagetable;
365 1.1 rearnsha u_int l2pagetable;
366 1.1 rearnsha extern char page0[], page0_end[];
367 1.1 rearnsha extern int etext asm ("_etext");
368 1.1 rearnsha extern int end asm ("_end");
369 1.1 rearnsha pv_addr_t kernel_l1pt;
370 1.1 rearnsha pv_addr_t kernel_ptpt;
371 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
372 1.1 rearnsha static struct bus_space plcom_bus_space;
373 1.1 rearnsha #endif
374 1.1 rearnsha
375 1.1 rearnsha
376 1.1 rearnsha #if 0
377 1.1 rearnsha cn_tab = &kcomcons;
378 1.1 rearnsha #endif
379 1.1 rearnsha /*
380 1.1 rearnsha * Heads up ... Setup the CPU / MMU / TLB functions
381 1.1 rearnsha */
382 1.1 rearnsha if (set_cpufuncs())
383 1.1 rearnsha panic("cpu not recognized!");
384 1.1 rearnsha
385 1.1 rearnsha /* - intbootinfo.bt_memstart) / NBPG */;
386 1.1 rearnsha
387 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
388 1.1 rearnsha /*
389 1.1 rearnsha * Initialise the diagnostic serial console
390 1.1 rearnsha * This allows a means of generating output during initarm().
391 1.1 rearnsha * Once all the memory map changes are complete we can call consinit()
392 1.1 rearnsha * and not have to worry about things moving.
393 1.1 rearnsha */
394 1.1 rearnsha
395 1.1 rearnsha if (PLCOMCNUNIT == 0) {
396 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd600000);
397 1.1 rearnsha plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
398 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
399 1.1 rearnsha } else if (PLCOMCNUNIT == 1) {
400 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd700000);
401 1.1 rearnsha plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
402 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
403 1.1 rearnsha }
404 1.1 rearnsha #endif
405 1.1 rearnsha
406 1.1 rearnsha /* Talk to the user */
407 1.1 rearnsha printf("\nNetBSD/integrator booting ...\n");
408 1.1 rearnsha
409 1.1 rearnsha #if 0
410 1.1 rearnsha if (intbootinfo.bt_magic != BT_MAGIC_NUMBER_EBSA
411 1.1 rearnsha && intbootinfo.bt_magic != BT_MAGIC_NUMBER_CATS)
412 1.1 rearnsha panic("Incompatible magic number passed in boot args\n");
413 1.1 rearnsha #endif
414 1.1 rearnsha
415 1.1 rearnsha /* {
416 1.1 rearnsha int loop;
417 1.1 rearnsha for (loop = 0; loop < 8; ++loop) {
418 1.1 rearnsha printf("%08x\n", *(((int *)bootinfo)+loop));
419 1.1 rearnsha }
420 1.1 rearnsha }*/
421 1.1 rearnsha
422 1.1 rearnsha /*
423 1.1 rearnsha * Ok we have the following memory map
424 1.1 rearnsha *
425 1.1 rearnsha * virtual address == physical address apart from the areas:
426 1.1 rearnsha * 0x00000000 -> 0x000fffff which is mapped to
427 1.1 rearnsha * top 1MB of physical memory
428 1.1 rearnsha * 0x00100000 -> 0x0fffffff which is mapped to
429 1.1 rearnsha * physical addresses 0x00100000 -> 0x0fffffff
430 1.1 rearnsha * 0x10000000 -> 0x1fffffff which is mapped to
431 1.1 rearnsha * physical addresses 0x00000000 -> 0x0fffffff
432 1.1 rearnsha * 0x20000000 -> 0xefffffff which is mapped to
433 1.1 rearnsha * physical addresses 0x20000000 -> 0xefffffff
434 1.1 rearnsha * 0xf0000000 -> 0xf03fffff which is mapped to
435 1.1 rearnsha * physical addresses 0x00000000 -> 0x003fffff
436 1.1 rearnsha *
437 1.1 rearnsha * This means that the kernel is mapped suitably for continuing
438 1.1 rearnsha * execution, all I/O is mapped 1:1 virtual to physical and
439 1.1 rearnsha * physical memory is accessible.
440 1.1 rearnsha *
441 1.1 rearnsha * The initarm() has the responsibility for creating the kernel
442 1.1 rearnsha * page tables.
443 1.1 rearnsha * It must also set up various memory pointers that are used
444 1.1 rearnsha * by pmap etc.
445 1.1 rearnsha */
446 1.1 rearnsha
447 1.1 rearnsha /*
448 1.1 rearnsha * Examine the boot args string for options we need to know about
449 1.1 rearnsha * now.
450 1.1 rearnsha */
451 1.1 rearnsha #if 0
452 1.1 rearnsha process_kernel_args((char *)intbootinfo.bt_args);
453 1.1 rearnsha #endif
454 1.1 rearnsha
455 1.1 rearnsha printf("initarm: Configuring system ...\n");
456 1.1 rearnsha
457 1.1 rearnsha /*
458 1.1 rearnsha * Set up the variables that define the availablilty of
459 1.1 rearnsha * physical memory
460 1.1 rearnsha */
461 1.1 rearnsha physical_start = 0 /*intbootinfo.bt_memstart*/;
462 1.1 rearnsha physical_freestart = physical_start;
463 1.1 rearnsha
464 1.1 rearnsha #if 0
465 1.1 rearnsha physical_end = /*intbootinfo.bt_memend*/ /*intbootinfo.bi_nrpages * NBPG */ 32*1024*1024;
466 1.1 rearnsha #else
467 1.1 rearnsha {
468 1.1 rearnsha volatile unsigned long *cm_sdram
469 1.1 rearnsha = (volatile unsigned long *)0x10000020;
470 1.1 rearnsha
471 1.1 rearnsha switch ((*cm_sdram >> 2) & 0x7)
472 1.1 rearnsha {
473 1.1 rearnsha case 0:
474 1.1 rearnsha physical_end = 16 * 1024 * 1024;
475 1.1 rearnsha break;
476 1.1 rearnsha case 1:
477 1.1 rearnsha physical_end = 32 * 1024 * 1024;
478 1.1 rearnsha break;
479 1.1 rearnsha case 2:
480 1.1 rearnsha physical_end = 64 * 1024 * 1024;
481 1.1 rearnsha break;
482 1.1 rearnsha case 3:
483 1.1 rearnsha physical_end = 128 * 1024 * 1024;
484 1.1 rearnsha break;
485 1.1 rearnsha case 4:
486 1.1 rearnsha physical_end = 256 * 1024 * 1024;
487 1.1 rearnsha break;
488 1.1 rearnsha default:
489 1.1 rearnsha printf("CM_SDRAM retuns unknown value, using 16M\n");
490 1.1 rearnsha physical_end = 16 * 1024 * 1024;
491 1.1 rearnsha break;
492 1.1 rearnsha }
493 1.1 rearnsha }
494 1.1 rearnsha #endif
495 1.1 rearnsha
496 1.1 rearnsha physical_freeend = physical_end;
497 1.1 rearnsha free_pages = (physical_end - physical_start) / NBPG;
498 1.1 rearnsha
499 1.1 rearnsha /* Set up the bootconfig structure for the benefit of pmap.c */
500 1.1 rearnsha bootconfig.dramblocks = 1;
501 1.1 rearnsha bootconfig.dram[0].address = physical_start;
502 1.1 rearnsha bootconfig.dram[0].pages = free_pages;
503 1.1 rearnsha
504 1.1 rearnsha physmem = (physical_end - physical_start) / NBPG;
505 1.1 rearnsha
506 1.1 rearnsha /* Tell the user about the memory */
507 1.1 rearnsha printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
508 1.1 rearnsha physical_start, physical_end - 1);
509 1.1 rearnsha
510 1.1 rearnsha /*
511 1.1 rearnsha * Ok the kernel occupies the bottom of physical memory.
512 1.1 rearnsha * The first free page after the kernel can be found in
513 1.1 rearnsha * intbootinfo->bt_memavail
514 1.1 rearnsha * We now need to allocate some fixed page tables to get the kernel
515 1.1 rearnsha * going.
516 1.1 rearnsha * We allocate one page directory and a number page tables and store
517 1.1 rearnsha * the physical addresses in the kernel_pt_table array.
518 1.1 rearnsha *
519 1.1 rearnsha * Ok the next bit of physical allocation may look complex but it is
520 1.1 rearnsha * simple really. I have done it like this so that no memory gets
521 1.1 rearnsha * wasted during the allocation of various pages and tables that are
522 1.1 rearnsha * all different sizes.
523 1.1 rearnsha * The start addresses will be page aligned.
524 1.1 rearnsha * We allocate the kernel page directory on the first free 16KB boundry
525 1.1 rearnsha * we find.
526 1.1 rearnsha * We allocate the kernel page tables on the first 4KB boundry we find.
527 1.1 rearnsha * Since we allocate at least 3 L2 pagetables we know that we must
528 1.1 rearnsha * encounter at least one 16KB aligned address.
529 1.1 rearnsha */
530 1.1 rearnsha
531 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
532 1.1 rearnsha printf("Allocating page tables\n");
533 1.1 rearnsha #endif
534 1.1 rearnsha
535 1.1 rearnsha /* Update the address of the first free 16KB chunk of physical memory */
536 1.1 rearnsha physical_freestart = ((uintptr_t) &end - KERNEL_TEXT_BASE + PGOFSET)
537 1.1 rearnsha & ~PGOFSET;
538 1.1 rearnsha #if 0
539 1.1 rearnsha physical_freestart += (kernexec->a_syms + sizeof(int)
540 1.1 rearnsha + *(u_int *)((int)end + kernexec->a_syms + sizeof(int))
541 1.1 rearnsha + (NBPG - 1)) & ~(NBPG - 1);
542 1.1 rearnsha #endif
543 1.1 rearnsha
544 1.1 rearnsha free_pages -= (physical_freestart - physical_start) / NBPG;
545 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
546 1.1 rearnsha printf("freestart = %#lx, free_pages = %d (%#x)\n",
547 1.1 rearnsha physical_freestart, free_pages, free_pages);
548 1.1 rearnsha #endif
549 1.1 rearnsha
550 1.1 rearnsha /* Define a macro to simplify memory allocation */
551 1.1 rearnsha #define valloc_pages(var, np) \
552 1.1 rearnsha alloc_pages((var).pv_pa, (np)); \
553 1.1 rearnsha (var).pv_va = KERNEL_TEXT_BASE + (var).pv_pa - physical_start;
554 1.1 rearnsha
555 1.1 rearnsha #define alloc_pages(var, np) \
556 1.1 rearnsha (var) = physical_freestart; \
557 1.1 rearnsha physical_freestart += ((np) * NBPG); \
558 1.1 rearnsha free_pages -= (np); \
559 1.1 rearnsha memset((char *)(var), 0, ((np) * NBPG));
560 1.1 rearnsha
561 1.1 rearnsha loop1 = 0;
562 1.1 rearnsha kernel_l1pt.pv_pa = 0;
563 1.1 rearnsha for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
564 1.1 rearnsha /* Are we 16KB aligned for an L1 ? */
565 1.1 rearnsha if ((physical_freestart & (PD_SIZE - 1)) == 0
566 1.1 rearnsha && kernel_l1pt.pv_pa == 0) {
567 1.1 rearnsha valloc_pages(kernel_l1pt, PD_SIZE / NBPG);
568 1.1 rearnsha } else {
569 1.1 rearnsha alloc_pages(kernel_pt_table[loop1], PT_SIZE / NBPG);
570 1.1 rearnsha ++loop1;
571 1.1 rearnsha }
572 1.1 rearnsha }
573 1.1 rearnsha
574 1.1 rearnsha /* This should never be able to happen but better confirm that. */
575 1.1 rearnsha if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (PD_SIZE-1)) != 0)
576 1.1 rearnsha panic("initarm: Failed to align the kernel page directory\n");
577 1.1 rearnsha
578 1.1 rearnsha /*
579 1.1 rearnsha * Allocate a page for the system page mapped to V0x00000000
580 1.1 rearnsha * This page will just contain the system vectors and can be
581 1.1 rearnsha * shared by all processes.
582 1.1 rearnsha */
583 1.1 rearnsha alloc_pages(systempage.pv_pa, 1);
584 1.1 rearnsha
585 1.1 rearnsha /* Allocate a page for the page table to map kernel page tables*/
586 1.1 rearnsha valloc_pages(kernel_ptpt, PT_SIZE / NBPG);
587 1.1 rearnsha
588 1.1 rearnsha /* Allocate stacks for all modes */
589 1.1 rearnsha valloc_pages(irqstack, IRQ_STACK_SIZE);
590 1.1 rearnsha valloc_pages(abtstack, ABT_STACK_SIZE);
591 1.1 rearnsha valloc_pages(undstack, UND_STACK_SIZE);
592 1.1 rearnsha valloc_pages(kernelstack, UPAGES);
593 1.1 rearnsha
594 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
595 1.1 rearnsha printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va);
596 1.1 rearnsha printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va);
597 1.1 rearnsha printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va);
598 1.1 rearnsha printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va);
599 1.1 rearnsha #endif
600 1.1 rearnsha
601 1.1 rearnsha alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
602 1.1 rearnsha
603 1.1 rearnsha /*
604 1.1 rearnsha * Ok we have allocated physical pages for the primary kernel
605 1.1 rearnsha * page tables
606 1.1 rearnsha */
607 1.1 rearnsha
608 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
609 1.1 rearnsha printf("Creating L1 page table at %#lx\n", kernel_l1pt.pv_pa);
610 1.1 rearnsha #endif
611 1.1 rearnsha
612 1.1 rearnsha /*
613 1.1 rearnsha * Now we start consturction of the L1 page table
614 1.1 rearnsha * We start by mapping the L2 page tables into the L1.
615 1.1 rearnsha * This means that we can replace L1 mappings later on if necessary
616 1.1 rearnsha */
617 1.1 rearnsha l1pagetable = kernel_l1pt.pv_pa;
618 1.1 rearnsha
619 1.1 rearnsha /* Map the L2 pages tables in the L1 page table */
620 1.1 rearnsha map_pagetable(l1pagetable, 0x00000000,
621 1.1 rearnsha kernel_pt_table[KERNEL_PT_SYS]);
622 1.1 rearnsha map_pagetable(l1pagetable, KERNEL_BASE,
623 1.1 rearnsha kernel_pt_table[KERNEL_PT_KERNEL]);
624 1.1 rearnsha for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
625 1.1 rearnsha map_pagetable(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
626 1.1 rearnsha kernel_pt_table[KERNEL_PT_VMDATA + loop]);
627 1.1 rearnsha map_pagetable(l1pagetable, PROCESS_PAGE_TBLS_BASE,
628 1.1 rearnsha kernel_ptpt.pv_pa);
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 l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL];
636 1.1 rearnsha
637 1.1 rearnsha {
638 1.1 rearnsha u_int logical;
639 1.1 rearnsha size_t textsize = (uintptr_t) &etext - KERNEL_TEXT_BASE;
640 1.1 rearnsha size_t totalsize = (uintptr_t) &end - KERNEL_TEXT_BASE;
641 1.1 rearnsha
642 1.1 rearnsha /* Round down text size and round up total size
643 1.1 rearnsha */
644 1.1 rearnsha textsize = textsize & ~PGOFSET;
645 1.1 rearnsha totalsize = (totalsize + PGOFSET) & ~PGOFSET;
646 1.1 rearnsha /* logical = map_chunk(l1pagetable, l2pagetable, KERNEL_BASE,
647 1.1 rearnsha physical_start, KERNEL_TEXT_BASE - KERNEL_BASE,
648 1.1 rearnsha AP_KRW, PT_CACHEABLE); */
649 1.1 rearnsha logical = map_chunk(l1pagetable, l2pagetable,
650 1.1 rearnsha KERNEL_TEXT_BASE, physical_start, textsize,
651 1.1 rearnsha AP_KRW, PT_CACHEABLE);
652 1.1 rearnsha logical += map_chunk(l1pagetable, l2pagetable,
653 1.1 rearnsha KERNEL_TEXT_BASE + logical, physical_start + logical,
654 1.1 rearnsha totalsize - textsize, AP_KRW, PT_CACHEABLE);
655 1.1 rearnsha #if 0
656 1.1 rearnsha logical += map_chunk(0, l2pagetable, KERNEL_BASE + logical,
657 1.1 rearnsha physical_start + logical, kernexec->a_syms + sizeof(int)
658 1.1 rearnsha + *(u_int *)((int)end + kernexec->a_syms + sizeof(int)),
659 1.1 rearnsha AP_KRW, PT_CACHEABLE);
660 1.1 rearnsha #endif
661 1.1 rearnsha }
662 1.1 rearnsha
663 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
664 1.1 rearnsha printf("Constructing L2 page tables\n");
665 1.1 rearnsha #endif
666 1.1 rearnsha
667 1.1 rearnsha /* Map the boot arguments page */
668 1.1 rearnsha #if 0
669 1.1 rearnsha map_entry_ro(l2pagetable, intbootinfo.bt_vargp, intbootinfo.bt_pargp);
670 1.1 rearnsha #endif
671 1.1 rearnsha
672 1.1 rearnsha /* Map the stack pages */
673 1.1 rearnsha map_chunk(0, l2pagetable, irqstack.pv_va, irqstack.pv_pa,
674 1.1 rearnsha IRQ_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
675 1.1 rearnsha map_chunk(0, l2pagetable, abtstack.pv_va, abtstack.pv_pa,
676 1.1 rearnsha ABT_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
677 1.1 rearnsha map_chunk(0, l2pagetable, undstack.pv_va, undstack.pv_pa,
678 1.1 rearnsha UND_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
679 1.1 rearnsha map_chunk(0, l2pagetable, kernelstack.pv_va, kernelstack.pv_pa,
680 1.1 rearnsha UPAGES * NBPG, AP_KRW, PT_CACHEABLE);
681 1.1 rearnsha map_chunk(0, l2pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
682 1.1 rearnsha PD_SIZE, AP_KRW, 0);
683 1.1 rearnsha
684 1.1 rearnsha /* Map the page table that maps the kernel pages */
685 1.1 rearnsha map_entry_nc(l2pagetable, kernel_ptpt.pv_pa, kernel_ptpt.pv_pa);
686 1.1 rearnsha
687 1.1 rearnsha /*
688 1.1 rearnsha * Map entries in the page table used to map PTE's
689 1.1 rearnsha * Basically every kernel page table gets mapped here
690 1.1 rearnsha */
691 1.1 rearnsha /* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
692 1.1 rearnsha l2pagetable = kernel_ptpt.pv_pa;
693 1.1 rearnsha map_entry_nc(l2pagetable, (KERNEL_BASE >> (PGSHIFT-2)),
694 1.1 rearnsha kernel_pt_table[KERNEL_PT_KERNEL]);
695 1.1 rearnsha map_entry_nc(l2pagetable, (PROCESS_PAGE_TBLS_BASE >> (PGSHIFT-2)),
696 1.1 rearnsha kernel_ptpt.pv_pa);
697 1.1 rearnsha map_entry_nc(l2pagetable, (0x00000000 >> (PGSHIFT-2)),
698 1.1 rearnsha kernel_pt_table[KERNEL_PT_SYS]);
699 1.1 rearnsha for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
700 1.1 rearnsha map_entry_nc(l2pagetable, ((KERNEL_VM_BASE +
701 1.1 rearnsha (loop * 0x00400000)) >> (PGSHIFT-2)),
702 1.1 rearnsha kernel_pt_table[KERNEL_PT_VMDATA + loop]);
703 1.1 rearnsha
704 1.1 rearnsha /*
705 1.1 rearnsha * Map the system page in the kernel page table for the bottom 1Meg
706 1.1 rearnsha * of the virtual memory map.
707 1.1 rearnsha */
708 1.1 rearnsha l2pagetable = kernel_pt_table[KERNEL_PT_SYS];
709 1.1 rearnsha #if 1
710 1.1 rearnsha /* MULTI-ICE requires that page 0 is NC/NB so that it can download
711 1.1 rearnsha the cache-clean code there. */
712 1.1 rearnsha map_entry_nc(l2pagetable, 0x00000000, systempage.pv_pa);
713 1.1 rearnsha #else
714 1.1 rearnsha map_entry_nc(l2pagetable, 0x00000000, systempage.pv_pa);
715 1.1 rearnsha #endif
716 1.1 rearnsha /* Map the core memory needed before autoconfig */
717 1.1 rearnsha loop = 0;
718 1.1 rearnsha while (l1_sec_table[loop].size) {
719 1.1 rearnsha vm_size_t sz;
720 1.1 rearnsha
721 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
722 1.1 rearnsha printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
723 1.1 rearnsha l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
724 1.1 rearnsha l1_sec_table[loop].va);
725 1.1 rearnsha #endif
726 1.1 rearnsha for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_SEC_SIZE)
727 1.1 rearnsha map_section(l1pagetable, l1_sec_table[loop].va + sz,
728 1.1 rearnsha l1_sec_table[loop].pa + sz,
729 1.1 rearnsha l1_sec_table[loop].flags);
730 1.1 rearnsha ++loop;
731 1.1 rearnsha }
732 1.1 rearnsha
733 1.1 rearnsha /*
734 1.1 rearnsha * Now we have the real page tables in place so we can switch to them.
735 1.1 rearnsha * Once this is done we will be running with the REAL kernel page tables.
736 1.1 rearnsha */
737 1.1 rearnsha
738 1.1 rearnsha /* Switch tables */
739 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
740 1.1 rearnsha printf("freestart = %#lx, free_pages = %d (%#x)\n",
741 1.1 rearnsha physical_freestart, free_pages, free_pages);
742 1.1 rearnsha printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
743 1.1 rearnsha #endif
744 1.1 rearnsha
745 1.1 rearnsha setttb(kernel_l1pt.pv_pa);
746 1.1 rearnsha
747 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
748 1.1 rearnsha printf("done!\n");
749 1.1 rearnsha #endif
750 1.1 rearnsha
751 1.1 rearnsha #ifdef PLCONSOLE
752 1.1 rearnsha /*
753 1.1 rearnsha * The IFPGA registers have just moved.
754 1.1 rearnsha * Detach the diagnostic serial port and reattach at the new address.
755 1.1 rearnsha */
756 1.1 rearnsha plcomcndetach();
757 1.1 rearnsha #endif
758 1.1 rearnsha
759 1.1 rearnsha /*
760 1.1 rearnsha * XXX this should only be done in main() but it useful to
761 1.1 rearnsha * have output earlier ...
762 1.1 rearnsha */
763 1.1 rearnsha consinit();
764 1.1 rearnsha
765 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
766 1.1 rearnsha printf("bootstrap done.\n");
767 1.1 rearnsha #endif
768 1.1 rearnsha
769 1.1 rearnsha /* Right set up the vectors at the bottom of page 0 */
770 1.1 rearnsha memcpy((char *)0x00000000, page0, page0_end - page0);
771 1.1 rearnsha
772 1.1 rearnsha /* We have modified a text page so sync the icache */
773 1.7 thorpej cpu_icache_sync_all();
774 1.1 rearnsha
775 1.1 rearnsha /*
776 1.1 rearnsha * Pages were allocated during the secondary bootstrap for the
777 1.1 rearnsha * stacks for different CPU modes.
778 1.1 rearnsha * We must now set the r13 registers in the different CPU modes to
779 1.1 rearnsha * point to these stacks.
780 1.1 rearnsha * Since the ARM stacks use STMFD etc. we must set r13 to the top end
781 1.1 rearnsha * of the stack memory.
782 1.1 rearnsha */
783 1.1 rearnsha printf("init subsystems: stacks ");
784 1.1 rearnsha
785 1.1 rearnsha set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
786 1.1 rearnsha set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
787 1.1 rearnsha set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
788 1.1 rearnsha
789 1.1 rearnsha /*
790 1.1 rearnsha * Well we should set a data abort handler.
791 1.1 rearnsha * Once things get going this will change as we will need a proper handler.
792 1.1 rearnsha * Until then we will use a handler that just panics but tells us
793 1.1 rearnsha * why.
794 1.1 rearnsha * Initialisation of the vectors will just panic on a data abort.
795 1.1 rearnsha * This just fills in a slighly better one.
796 1.1 rearnsha */
797 1.1 rearnsha printf("vectors ");
798 1.1 rearnsha data_abort_handler_address = (u_int)data_abort_handler;
799 1.1 rearnsha prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
800 1.1 rearnsha undefined_handler_address = (u_int)undefinedinstruction_bounce;
801 1.1 rearnsha
802 1.1 rearnsha /* At last !
803 1.1 rearnsha * We now have the kernel in physical memory from the bottom upwards.
804 1.1 rearnsha * Kernel page tables are physically above this.
805 1.1 rearnsha * The kernel is mapped to KERNEL_TEXT_BASE
806 1.1 rearnsha * The kernel data PTs will handle the mapping of 0xf1000000-0xf3ffffff
807 1.1 rearnsha * The page tables are mapped to 0xefc00000
808 1.1 rearnsha */
809 1.1 rearnsha
810 1.1 rearnsha /* Initialise the undefined instruction handlers */
811 1.1 rearnsha printf("undefined ");
812 1.1 rearnsha undefined_init();
813 1.1 rearnsha
814 1.1 rearnsha /* Boot strap pmap telling it where the kernel page table is */
815 1.1 rearnsha printf("pmap ");
816 1.1 rearnsha pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
817 1.1 rearnsha
818 1.1 rearnsha /* Setup the IRQ system */
819 1.1 rearnsha printf("irq ");
820 1.1 rearnsha irq_init();
821 1.1 rearnsha
822 1.1 rearnsha printf("done.\n");
823 1.1 rearnsha
824 1.1 rearnsha #ifdef IPKDB
825 1.1 rearnsha /* Initialise ipkdb */
826 1.1 rearnsha ipkdb_init();
827 1.1 rearnsha if (boothowto & RB_KDB)
828 1.1 rearnsha ipkdb_connect(0);
829 1.1 rearnsha #endif
830 1.1 rearnsha
831 1.1 rearnsha #ifdef DDB
832 1.1 rearnsha db_machine_init();
833 1.4 thorpej
834 1.4 thorpej /* Firmware doesn't load symbols. */
835 1.4 thorpej ddb_init(0, NULL, NULL);
836 1.1 rearnsha
837 1.1 rearnsha if (boothowto & RB_KDB)
838 1.1 rearnsha Debugger();
839 1.1 rearnsha #endif
840 1.1 rearnsha
841 1.1 rearnsha /* We return the new stack pointer address */
842 1.1 rearnsha return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
843 1.1 rearnsha }
844 1.1 rearnsha
845 1.1 rearnsha void
846 1.1 rearnsha process_kernel_args(args)
847 1.1 rearnsha char *args;
848 1.1 rearnsha {
849 1.1 rearnsha
850 1.1 rearnsha boothowto = 0;
851 1.1 rearnsha
852 1.1 rearnsha /* Make a local copy of the bootargs */
853 1.1 rearnsha strncpy(bootargs, args, MAX_BOOT_STRING);
854 1.1 rearnsha
855 1.1 rearnsha args = bootargs;
856 1.1 rearnsha boot_file = bootargs;
857 1.1 rearnsha
858 1.1 rearnsha /* Skip the kernel image filename */
859 1.1 rearnsha while (*args != ' ' && *args != 0)
860 1.1 rearnsha ++args;
861 1.1 rearnsha
862 1.1 rearnsha if (*args != 0)
863 1.1 rearnsha *args++ = 0;
864 1.1 rearnsha
865 1.1 rearnsha while (*args == ' ')
866 1.1 rearnsha ++args;
867 1.1 rearnsha
868 1.1 rearnsha boot_args = args;
869 1.1 rearnsha
870 1.1 rearnsha printf("bootfile: %s\n", boot_file);
871 1.1 rearnsha printf("bootargs: %s\n", boot_args);
872 1.1 rearnsha
873 1.1 rearnsha parse_mi_bootargs(boot_args);
874 1.1 rearnsha }
875 1.1 rearnsha
876 1.1 rearnsha void
877 1.1 rearnsha consinit(void)
878 1.1 rearnsha {
879 1.1 rearnsha static int consinit_called = 0;
880 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
881 1.1 rearnsha static struct bus_space plcom_bus_space;
882 1.1 rearnsha #endif
883 1.1 rearnsha #if 0
884 1.1 rearnsha char *console = CONSDEVNAME;
885 1.1 rearnsha #endif
886 1.1 rearnsha
887 1.1 rearnsha if (consinit_called != 0)
888 1.1 rearnsha return;
889 1.1 rearnsha
890 1.1 rearnsha consinit_called = 1;
891 1.1 rearnsha
892 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
893 1.1 rearnsha if (PLCOMCNUNIT == 0) {
894 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space,
895 1.1 rearnsha (void*)UART0_BOOT_BASE);
896 1.1 rearnsha if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
897 1.1 rearnsha IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
898 1.1 rearnsha panic("can't init serial console");
899 1.1 rearnsha return;
900 1.1 rearnsha } else if (PLCOMCNUNIT == 1) {
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 }
908 1.1 rearnsha #endif
909 1.1 rearnsha #if (NCOM > 0)
910 1.1 rearnsha if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
911 1.1 rearnsha COM_FREQ, comcnmode))
912 1.1 rearnsha panic("can't init serial console @%x", CONCOMADDR);
913 1.1 rearnsha return;
914 1.1 rearnsha #endif
915 1.1 rearnsha panic("No serial console configured");
916 1.1 rearnsha }
917 1.1 rearnsha
918 1.1 rearnsha #if 0
919 1.1 rearnsha static bus_space_handle_t kcom_base = (bus_space_handle_t) (DC21285_PCI_IO_VBASE + CONCOMADDR);
920 1.1 rearnsha
921 1.1 rearnsha u_int8_t footbridge_bs_r_1(void *, bus_space_handle_t, bus_size_t);
922 1.1 rearnsha void footbridge_bs_w_1(void *, bus_space_handle_t, bus_size_t, u_int8_t);
923 1.1 rearnsha
924 1.1 rearnsha #define KCOM_GETBYTE(r) footbridge_bs_r_1(0, kcom_base, (r))
925 1.1 rearnsha #define KCOM_PUTBYTE(r,v) footbridge_bs_w_1(0, kcom_base, (r), (v))
926 1.1 rearnsha
927 1.1 rearnsha static int
928 1.1 rearnsha kcomcngetc(dev_t dev)
929 1.1 rearnsha {
930 1.1 rearnsha int stat, c;
931 1.1 rearnsha
932 1.1 rearnsha /* block until a character becomes available */
933 1.1 rearnsha while (!ISSET(stat = KCOM_GETBYTE(com_lsr), LSR_RXRDY))
934 1.1 rearnsha ;
935 1.1 rearnsha
936 1.1 rearnsha c = KCOM_GETBYTE(com_data);
937 1.1 rearnsha stat = KCOM_GETBYTE(com_iir);
938 1.1 rearnsha return c;
939 1.1 rearnsha }
940 1.1 rearnsha
941 1.1 rearnsha /*
942 1.1 rearnsha * Console kernel output character routine.
943 1.1 rearnsha */
944 1.1 rearnsha static void
945 1.1 rearnsha kcomcnputc(dev_t dev, int c)
946 1.1 rearnsha {
947 1.1 rearnsha int timo;
948 1.1 rearnsha
949 1.1 rearnsha /* wait for any pending transmission to finish */
950 1.1 rearnsha timo = 150000;
951 1.1 rearnsha while (!ISSET(KCOM_GETBYTE(com_lsr), LSR_TXRDY) && --timo)
952 1.1 rearnsha continue;
953 1.1 rearnsha
954 1.1 rearnsha KCOM_PUTBYTE(com_data, c);
955 1.1 rearnsha
956 1.1 rearnsha /* wait for this transmission to complete */
957 1.1 rearnsha timo = 1500000;
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
962 1.1 rearnsha static void
963 1.1 rearnsha kcomcnpollc(dev_t dev, int on)
964 1.1 rearnsha {
965 1.1 rearnsha }
966 1.1 rearnsha
967 1.1 rearnsha struct consdev kcomcons = {
968 1.1 rearnsha NULL, NULL, kcomcngetc, kcomcnputc, kcomcnpollc, NULL,
969 1.1 rearnsha NODEV, CN_NORMAL
970 1.1 rearnsha };
971 1.1 rearnsha
972 1.1 rearnsha #endif
973