Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / sun3 / sun3x / locore2.c
blob197f1d46873fc2d32648410f06cc7add7089d2a5
1 /* $NetBSD: locore2.c,v 1.37 2009/11/27 03:23:14 rmind Exp $ */
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross and Jeremy Cooper.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: locore2.c,v 1.37 2009/11/27 03:23:14 rmind Exp $");
35 #include "opt_ddb.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/proc.h>
40 #include <sys/reboot.h>
41 #define ELFSIZE 32
42 #include <sys/exec_elf.h>
44 #include <uvm/uvm_extern.h>
46 #include <machine/cpu.h>
47 #include <machine/db_machdep.h>
48 #include <machine/dvma.h>
49 #include <machine/idprom.h>
50 #include <machine/leds.h>
51 #include <machine/mon.h>
52 #include <machine/pmap.h>
53 #include <machine/pte.h>
55 #include <sun3/sun3/interreg.h>
56 #include <sun3/sun3/machdep.h>
57 #include <sun68k/sun68k/vector.h>
59 /* This is defined in locore.s */
60 extern char kernel_text[];
62 /* These are defined by the linker */
63 extern char etext[], edata[], end[];
64 int nsym;
65 char *ssym, *esym;
68 * XXX: m68k common code needs these...
69 * ... but this port does not need to deal with anything except
70 * an mc68030, so these two variables are always ignored.
72 int cputype = CPU_68030;
73 int mmutype = MMU_68030;
76 * Now our own stuff.
79 extern struct pcb *curpcb;
81 /* First C code called by locore.s */
82 void _bootstrap(void);
84 static void _vm_init(void);
86 #if defined(DDB)
87 static void _save_symtab(void);
90 * Preserve DDB symbols and strings by setting esym.
92 static void
93 _save_symtab(void)
95 int i;
96 Elf_Ehdr *ehdr;
97 Elf_Shdr *shp;
98 vaddr_t minsym, maxsym;
101 * Check the ELF headers.
104 ehdr = (void *)end;
105 if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0 ||
106 ehdr->e_ident[EI_CLASS] != ELFCLASS32) {
107 mon_printf("_save_symtab: bad ELF magic\n");
108 return;
112 * Find the end of the symbols and strings.
115 maxsym = 0;
116 minsym = ~maxsym;
117 shp = (Elf_Shdr *)(end + ehdr->e_shoff);
118 for (i = 0; i < ehdr->e_shnum; i++) {
119 if (shp[i].sh_type != SHT_SYMTAB &&
120 shp[i].sh_type != SHT_STRTAB) {
121 continue;
123 minsym = min(minsym, (vaddr_t)end + shp[i].sh_offset);
124 maxsym = max(maxsym, (vaddr_t)end + shp[i].sh_offset +
125 shp[i].sh_size);
127 nsym = 1;
128 ssym = (char *)ehdr;
129 esym = (char *)maxsym;
131 #endif /* DDB */
134 * This function is called from _bootstrap() to initialize
135 * pre-vm-sytem virtual memory. All this really does is to
136 * set virtual_avail to the first page following preloaded
137 * data (i.e. the kernel and its symbol table) and special
138 * things that may be needed very early (lwp0 upages).
139 * Once that is done, pmap_bootstrap() is called to do the
140 * usual preparations for our use of the MMU.
142 static void
143 _vm_init(void)
145 vaddr_t nextva;
148 * First preserve our symbol table, which might have been
149 * loaded after our BSS area by the boot loader. However,
150 * if DDB is not part of this kernel, ignore the symbols.
152 esym = end + 4;
153 #if defined(DDB)
154 /* This will advance esym past the symbols. */
155 _save_symtab();
156 #endif
159 * Steal some special-purpose, already mapped pages.
160 * Note: msgbuf is setup in machdep.c:cpu_startup()
162 nextva = m68k_round_page(esym);
165 * Setup the u-area pages (stack, etc.) for lwp0.
166 * This is done very early (here) to make sure the
167 * fault handler works in case we hit an early bug.
168 * (The fault handler may reference lwp0 stuff.)
170 uvm_lwp_setuarea(&lwp0, nextva);
171 memset((void *)nextva, 0, USPACE);
173 nextva += USPACE;
176 * Now that lwp0 exists, make it the "current" one.
178 curlwp = &lwp0;
179 curpcb = lwp_getpcb(&lwp0);
181 /* This does most of the real work. */
182 pmap_bootstrap(nextva);
186 * This is called from locore.s just after the kernel is remapped
187 * to its proper address, but before the call to main(). The work
188 * done here corresponds to various things done in locore.s on the
189 * hp300 port (and other m68k) but which we prefer to do in C code.
190 * Also do setup specific to the Sun PROM monitor and IDPROM here.
192 void
193 _bootstrap(void)
196 /* First, Clear BSS. */
197 memset(edata, 0, end - edata);
199 /* Set v_handler, get boothowto. */
200 sunmon_init();
202 /* Handle kernel mapping, pmap_bootstrap(), etc. */
203 _vm_init();
206 * Find and save OBIO mappings needed early,
207 * and call some init functions.
209 obio_init();
212 * Point interrupts/exceptions to our vector table.
213 * (Until now, we use the one setup by the PROM.)
215 * This is done after obio_init() / intreg_init() finds
216 * the interrupt register and disables the NMI clock so
217 * it will not cause "spurrious level 7" complaints.
218 * Done after _vm_init so the PROM can debug that.
220 setvbr((void **)vector_table);
221 /* Interrupts are enabled later, after autoconfig. */
224 * Find the IDPROM and copy it to memory.
225 * Needs obio_init and setvbr earlier.
227 idprom_init();
230 * Turn on the LEDs so we know power is on.
231 * Needs idprom_init and obio_init earlier.
233 leds_init();