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