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