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