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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
/* $FreeBSD$ */
/* $NetBSD: locore.S,v 1.24 2000/05/31 05:09:17 thorpej Exp $ */
/*
* Copyright (C) 2001 Benno Rice
* All rights reserved.
*
* 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 Benno Rice ``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 TOOLS GMBH 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.
*/
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
* Copyright (C) 1995, 1996 TooLs GmbH.
* All rights reserved.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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 "opt_ddb.h"
#include "opt_ipkdb.h"
#include "assym.s"
#include <sys/syscall.h>
#include <machine/trap.h>
#include <machine/param.h>
#include <machine/sr.h>
#include <machine/spr.h>
#include <machine/psl.h>
#include <machine/asm.h>
/*
* Some instructions gas doesn't understand (yet?)
*/
#define bdneq bdnzf 2,
/*
* Globals
*/
.data
GLOBAL(tmpstk)
.space 8208
GLOBAL(esym)
.long 0 /* end of symbol table */
GLOBAL(proc0paddr)
.long 0 /* proc0 p_addr */
GLOBAL(PTmap)
.long 0 /* PTmap */
GLOBAL(decrnest)
.long 0
GLOBAL(intrnames)
.asciz "irq0", "irq1", "irq2", "irq3"
.asciz "irq4", "irq5", "irq6", "irq7"
.asciz "irq8", "irq9", "irq10", "irq11"
.asciz "irq12", "irq13", "irq14", "irq15"
.asciz "irq16", "irq17", "irq18", "irq19"
.asciz "irq20", "irq21", "irq22", "irq23"
.asciz "irq24", "irq25", "irq26", "irq27"
.asciz "irq28", "irq29", "irq30", "irq31"
.asciz "irq32", "irq33", "irq34", "irq35"
.asciz "irq36", "irq37", "irq38", "irq39"
.asciz "irq40", "irq41", "irq42", "irq43"
.asciz "irq44", "irq45", "irq46", "irq47"
.asciz "irq48", "irq49", "irq50", "irq51"
.asciz "irq52", "irq53", "irq54", "irq55"
.asciz "irq56", "irq57", "irq58", "irq59"
.asciz "irq60", "irq61", "irq62", "irq63"
.asciz "clock", "softclock", "softnet", "softserial"
GLOBAL(eintrnames)
.align 4
GLOBAL(intrcnt)
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.long 0,0,0,0
GLOBAL(eintrcnt)
GLOBAL(ofmsr)
.long 0 /* msr used in Open Firmware */
GLOBAL(powersave)
.long 0
#define INTSTK 8192 /* 8K interrupt stack */
#define SPILLSTK 4096 /* 4K spill stack */
/*
* File-scope for locore.S
*/
idle_u:
.long 0 /* fake uarea during idle after exit */
openfirmware_entry:
.long 0 /* openfirmware entry point */
srsave:
.long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
/*
* This symbol is here for the benefit of kvm_mkdb, and is supposed to
* mark the start of kernel text.
*/
.text
.globl kernel_text
kernel_text:
/*
* Startup entry. Note, this must be the first thing in the text
* segment!
*/
.text
.globl __start
__start:
#ifdef FIRMWORKSBUGS
mfmsr 0
andi. 0,0,PSL_IR|PSL_DR
beq 1f
bl ofwr_init
1:
#endif
li 8,0
li 9,0x100
mtctr 9
1:
dcbf 0,8
icbi 0,8
addi 8,8,0x20
bdnz 1b
sync
isync
mtibatu 0,0
mtibatu 1,0
mtibatu 2,0
mtibatu 3,0
mtdbatu 0,0
mtdbatu 1,0
mtdbatu 2,0
mtdbatu 3,0
li 9,0x12
mtibatl 0,9
mtdbatl 0,9
li 9,0x1ffe
mtibatu 0,9
mtdbatu 0,9
isync
lis 8,openfirmware_entry@ha
stw 5,openfirmware_entry@l(8) /* save client interface handler */
mr 3,5
lis 1,tmpstk@ha
addi 1,1,tmpstk@l
addi 1,1,8192
mfmsr 0
lis 9,ofmsr@ha
stw 0,ofmsr@l(9)
bl OF_init
lis 4,end@ha
addi 4,4,end@l
mr 5,4
li 9,PAGE_MASK
add 4,4,9
andc 4,4,9
lis 9,OF_buf@ha
stw 4,OF_buf@l(9)
addi 4,4,PAGE_SIZE
lis 9,proc0paddr@ha
stw 4,proc0paddr@l(9)
addi 4,4,USPACE-FRAMELEN
mr 1,4
xor 0,0,0
stwu 0,-16(1)
lis 3,kernel_text@ha
addi 3,3,kernel_text@l
#if 0
mr 5,6
#endif
bl powerpc_init
bl mi_startup
b OF_exit
#if 0 /* XXX: We may switch back to this in the future. */
/*
* OpenFirmware entry point
*/
ENTRY(openfirmware)
mflr 0 /* save return address */
stw 0,4(1)
stwu 1,-16(1) /* setup stack frame */
mfmsr 4 /* save msr */
stw 4,8(1)
lis 4,openfirmware_entry@ha /* get firmware entry point */
lwz 4,openfirmware_entry@l(4)
mtlr 4
li 0,0 /* clear battable translations */
mtdbatu 2,0
mtdbatu 3,0
mtibatu 2,0
mtibatu 3,0
lis 4,ofmsr@ha /* Open Firmware msr */
lwz 4,ofmsr@l(4)
mtmsr 4
isync
lis 4,srsave@ha /* save old SR */
addi 4,4,srsave@l
li 5,0
1: mfsrin 0,5
stw 0,0(4)
addi 4,4,4
addis 5,5,0x10000000@h
cmpwi 5,0
bne 1b
lis 4,ofw_pmap@ha /* load OFW SR */
addi 4,4,ofw_pmap@l
lwz 0,PM_KERNELSR(4)
cmpwi 0,0 /* pm_sr[KERNEL_SR] == 0? */
beq 2f /* then skip (not initialized yet) */
li 5,0
1: lwz 0,0(4)
mtsrin 0,5
addi 4,4,4
addis 5,5,0x10000000@h
cmpwi 5,0
bne 1b
2:
blrl /* call Open Firmware */
mfmsr 4
li 5,PSL_IR|PSL_DR
andc 4,4,5
mtmsr 4
isync
lis 4,srsave@ha /* restore saved SR */
addi 4,4,srsave@l
li 5,0
1: lwz 0,0(4)
mtsrin 0,5
addi 4,4,4
addis 5,5,0x10000000@h
cmpwi 5,0
bne 1b
lwz 4,8(1) /* restore msr */
mtmsr 4
isync
lwz 1,0(1) /* and return */
lwz 0,4(1)
mtlr 0
blr
#endif
/*
* Switch to/from OpenFirmware real mode stack
*
* Note: has to be called as the very first thing in OpenFirmware interface
* routines.
* E.g.:
* int
* OF_xxx(arg1, arg2)
* type arg1, arg2;
* {
* static struct {
* char *name;
* int nargs;
* int nreturns;
* char *method;
* int arg1;
* int arg2;
* int ret;
* } args = {
* "xxx",
* 2,
* 1,
* };
*
* ofw_stack();
* args.arg1 = arg1;
* args.arg2 = arg2;
* if (openfirmware(&args) < 0)
* return -1;
* return args.ret;
* }
*/
.local firmstk
.comm firmstk,PAGE_SIZE,8
ENTRY(ofw_stack)
mfmsr 8 /* turn off interrupts */
andi. 0,8,~(PSL_EE|PSL_RI)@l
mtmsr 0
stw 8,4(1) /* abuse return address slot */
lwz 5,0(1) /* get length of stack frame */
subf 5,1,5
lis 7,firmstk+PAGE_SIZE-8@ha
addi 7,7,firmstk+PAGE_SIZE-8@l
lis 6,ofw_back@ha
addi 6,6,ofw_back@l
subf 4,5,7 /* make room for stack frame on
new stack */
stw 6,-4(7) /* setup return pointer */
stwu 1,-8(7)
stw 7,-8(4)
addi 3,1,8
addi 1,4,-8
subi 5,5,8
cmpw 3,4
beqlr
mr 0,5
addi 5,5,-1
cmpwi 0,0
beqlr
1: lwz 0,0(3)
stw 0,0(4)
addi 3,3,1
addi 4,4,1
mr 0,5
addi 5,5,-1
cmpwi 0,0
bne 1b
blr
ofw_back:
lwz 1,0(1) /* get callers original stack pointer */
lwz 0,4(1) /* get saved msr from abused slot */
mtmsr 0
lwz 1,0(1) /* return */
lwz 0,4(1)
mtlr 0
blr
/*
* int setfault()
*
* Similar to setjmp to setup for handling faults on accesses to user memory.
* Any routine using this may only call bcopy, either the form below,
* or the (currently used) C code optimized, so it doesn't use any non-volatile
* registers.
*/
.globl setfault
setfault:
mflr 0
mfcr 12
mfsprg 4,0
lwz 4,PC_CURTHREAD(4)
lwz 4,TD_PCB(4)
stw 3,PCB_ONFAULT(4)
stw 0,0(3)
stw 1,4(3)
stw 2,8(3)
stmw 12,12(3)
xor 3,3,3
blr
#include <powerpc/powerpc/trap_subr.S>
|