]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/powerpc/aim/locore.S
This commit was generated by cvs2svn to compensate for changes in r98675,
[FreeBSD/FreeBSD.git] / sys / powerpc / aim / locore.S
1 /* $FreeBSD$ */
2 /* $NetBSD: locore.S,v 1.24 2000/05/31 05:09:17 thorpej Exp $ */
3
4 /*
5  * Copyright (C) 2001 Benno Rice
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 /*
29  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
30  * Copyright (C) 1995, 1996 TooLs GmbH.
31  * All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions
35  * are met:
36  * 1. Redistributions of source code must retain the above copyright
37  *    notice, this list of conditions and the following disclaimer.
38  * 2. Redistributions in binary form must reproduce the above copyright
39  *    notice, this list of conditions and the following disclaimer in the
40  *    documentation and/or other materials provided with the distribution.
41  * 3. All advertising materials mentioning features or use of this software
42  *    must display the following acknowledgement:
43  *      This product includes software developed by TooLs GmbH.
44  * 4. The name of TooLs GmbH may not be used to endorse or promote products
45  *    derived from this software without specific prior written permission.
46  *
47  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
48  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
52  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
53  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
54  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
55  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
56  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57  */
58
59 #include "opt_ddb.h"
60 #include "opt_ipkdb.h"
61 #include "assym.s"
62
63 #include <sys/syscall.h>
64
65 #include <machine/trap.h>
66 #include <machine/param.h>
67 #include <machine/sr.h>
68 #include <machine/spr.h>
69 #include <machine/psl.h>
70 #include <machine/asm.h>
71
72 /*
73  * Some instructions gas doesn't understand (yet?)
74  */
75 #define bdneq   bdnzf 2,
76
77 /*
78  * Globals
79  */
80         .data
81 GLOBAL(tmpstk)
82         .space  8208
83 GLOBAL(esym)
84         .long   0                       /* end of symbol table */
85 GLOBAL(proc0paddr)
86         .long   0                       /* proc0 p_addr */
87 GLOBAL(PTmap)
88         .long   0                       /* PTmap */
89 GLOBAL(decrnest)
90         .long   0
91
92 GLOBAL(intrnames)
93         .asciz  "irq0", "irq1", "irq2", "irq3"
94         .asciz  "irq4", "irq5", "irq6", "irq7"
95         .asciz  "irq8", "irq9", "irq10", "irq11"
96         .asciz  "irq12", "irq13", "irq14", "irq15"
97         .asciz  "irq16", "irq17", "irq18", "irq19"
98         .asciz  "irq20", "irq21", "irq22", "irq23"
99         .asciz  "irq24", "irq25", "irq26", "irq27"
100         .asciz  "irq28", "irq29", "irq30", "irq31"
101         .asciz  "irq32", "irq33", "irq34", "irq35"
102         .asciz  "irq36", "irq37", "irq38", "irq39"
103         .asciz  "irq40", "irq41", "irq42", "irq43"
104         .asciz  "irq44", "irq45", "irq46", "irq47"
105         .asciz  "irq48", "irq49", "irq50", "irq51"
106         .asciz  "irq52", "irq53", "irq54", "irq55"
107         .asciz  "irq56", "irq57", "irq58", "irq59"
108         .asciz  "irq60", "irq61", "irq62", "irq63"
109         .asciz  "clock", "softclock", "softnet", "softserial"
110 GLOBAL(eintrnames)
111         .align  4
112 GLOBAL(intrcnt)
113         .long   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
114         .long   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
115         .long   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
116         .long   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
117         .long   0,0,0,0
118 GLOBAL(eintrcnt)
119
120 GLOBAL(ofmsr)
121         .long   0                       /* msr used in Open Firmware */
122
123 GLOBAL(powersave)
124         .long   0
125
126 #define INTSTK          8192            /* 8K interrupt stack */
127 #define SPILLSTK        4096            /* 4K spill stack */
128
129 /*
130  * File-scope for locore.S
131  */
132 idle_u:
133         .long   0                       /* fake uarea during idle after exit */
134 openfirmware_entry:
135         .long   0                       /* openfirmware entry point */
136 srsave:
137         .long   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
138
139 /*
140  * This symbol is here for the benefit of kvm_mkdb, and is supposed to
141  * mark the start of kernel text.
142  */
143         .text
144         .globl  kernel_text
145 kernel_text:
146
147 /*
148  * Startup entry.  Note, this must be the first thing in the text
149  * segment!
150  */
151         .text
152         .globl  __start
153 __start:
154 #ifdef  FIRMWORKSBUGS
155         mfmsr   0
156         andi.   0,0,PSL_IR|PSL_DR
157         beq     1f
158
159         bl      ofwr_init
160 1:
161 #endif
162         li      8,0
163         li      9,0x100
164         mtctr   9
165 1:
166         dcbf    0,8
167         icbi    0,8
168         addi    8,8,0x20
169         bdnz    1b
170         sync
171         isync
172
173         mtibatu 0,0
174         mtibatu 1,0
175         mtibatu 2,0
176         mtibatu 3,0
177         mtdbatu 0,0
178         mtdbatu 1,0
179         mtdbatu 2,0
180         mtdbatu 3,0
181
182         li      9,0x12
183         mtibatl 0,9
184         mtdbatl 0,9
185         li      9,0x1ffe
186         mtibatu 0,9
187         mtdbatu 0,9
188         isync
189
190         lis     8,openfirmware_entry@ha
191         stw     5,openfirmware_entry@l(8) /* save client interface handler */
192         mr      3,5
193
194         lis     1,tmpstk@ha
195         addi    1,1,tmpstk@l
196         addi    1,1,8192
197
198         mfmsr   0
199         lis     9,ofmsr@ha
200         stw     0,ofmsr@l(9)
201
202         bl      OF_init
203
204         lis     4,end@ha
205         addi    4,4,end@l
206         mr      5,4
207         li      9,PAGE_MASK
208         add     4,4,9
209         andc    4,4,9
210         lis     9,OF_buf@ha
211         stw     4,OF_buf@l(9)
212         addi    4,4,PAGE_SIZE
213         lis     9,proc0paddr@ha
214         stw     4,proc0paddr@l(9)
215         addi    4,4,USPACE-FRAMELEN
216         mr      1,4
217         xor     0,0,0
218         stwu    0,-16(1)
219
220         lis     3,kernel_text@ha
221         addi    3,3,kernel_text@l
222 #if 0
223         mr      5,6
224 #endif
225
226         bl      powerpc_init
227         bl      mi_startup
228         b       OF_exit
229
230 #if 0 /* XXX: We may switch back to this in the future. */
231 /*
232  * OpenFirmware entry point
233  */
234 ENTRY(openfirmware)
235         mflr    0                       /* save return address */
236         stw     0,4(1)
237         stwu    1,-16(1)                /* setup stack frame */
238
239         mfmsr   4                       /* save msr */
240         stw     4,8(1)
241
242         lis     4,openfirmware_entry@ha /* get firmware entry point */
243         lwz     4,openfirmware_entry@l(4)
244         mtlr    4
245
246         li      0,0                     /* clear battable translations */
247         mtdbatu 2,0
248         mtdbatu 3,0
249         mtibatu 2,0
250         mtibatu 3,0
251
252         lis     4,ofmsr@ha              /* Open Firmware msr */
253         lwz     4,ofmsr@l(4)
254         mtmsr   4
255         isync
256
257         lis     4,srsave@ha             /* save old SR */
258         addi    4,4,srsave@l
259         li      5,0
260 1:      mfsrin  0,5
261         stw     0,0(4)
262         addi    4,4,4
263         addis   5,5,0x10000000@h
264         cmpwi   5,0
265         bne     1b
266
267         lis     4,ofw_pmap@ha           /* load OFW SR */
268         addi    4,4,ofw_pmap@l
269         lwz     0,PM_KERNELSR(4)
270         cmpwi   0,0                     /* pm_sr[KERNEL_SR] == 0? */
271         beq     2f                      /* then skip (not initialized yet) */
272         li      5,0
273 1:      lwz     0,0(4)
274         mtsrin  0,5
275         addi    4,4,4
276         addis   5,5,0x10000000@h
277         cmpwi   5,0
278         bne     1b
279 2:
280         blrl                            /* call Open Firmware */
281
282         mfmsr   4
283         li      5,PSL_IR|PSL_DR
284         andc    4,4,5
285         mtmsr   4
286         isync
287
288         lis     4,srsave@ha             /* restore saved SR */
289         addi    4,4,srsave@l
290         li      5,0
291 1:      lwz     0,0(4)
292         mtsrin  0,5
293         addi    4,4,4
294         addis   5,5,0x10000000@h
295         cmpwi   5,0
296         bne     1b
297
298         lwz     4,8(1)                  /* restore msr */
299         mtmsr   4
300         isync
301
302         lwz     1,0(1)                  /* and return */
303         lwz     0,4(1)
304         mtlr    0
305         blr
306 #endif
307
308 /*
309  * Switch to/from OpenFirmware real mode stack
310  *
311  * Note: has to be called as the very first thing in OpenFirmware interface
312  * routines.
313  * E.g.:
314  * int
315  * OF_xxx(arg1, arg2)
316  * type arg1, arg2;
317  * {
318  *      static struct {
319  *              char *name;
320  *              int nargs;
321  *              int nreturns;
322  *              char *method;
323  *              int arg1;
324  *              int arg2;
325  *              int ret;
326  *      } args = {
327  *              "xxx",
328  *              2,
329  *              1,
330  *      };
331  *
332  *      ofw_stack();
333  *      args.arg1 = arg1;
334  *      args.arg2 = arg2;
335  *      if (openfirmware(&args) < 0)
336  *              return -1;
337  *      return args.ret;
338  * }
339  */
340
341         .local  firmstk
342         .comm   firmstk,PAGE_SIZE,8
343
344 ENTRY(ofw_stack)
345         mfmsr   8                       /* turn off interrupts */
346         andi.   0,8,~(PSL_EE|PSL_RI)@l
347         mtmsr   0
348         stw     8,4(1)                  /* abuse return address slot */
349
350         lwz     5,0(1)                  /* get length of stack frame */
351         subf    5,1,5
352
353         lis     7,firmstk+PAGE_SIZE-8@ha
354         addi    7,7,firmstk+PAGE_SIZE-8@l
355         lis     6,ofw_back@ha
356         addi    6,6,ofw_back@l
357         subf    4,5,7                   /* make room for stack frame on
358                                            new stack */
359         stw     6,-4(7)                 /* setup return pointer */
360         stwu    1,-8(7)
361         
362         stw     7,-8(4)
363
364         addi    3,1,8
365         addi    1,4,-8
366         subi    5,5,8
367
368         cmpw    3,4
369         beqlr
370
371         mr      0,5
372         addi    5,5,-1
373         cmpwi   0,0
374         beqlr
375
376 1:      lwz     0,0(3)
377         stw     0,0(4)
378         addi    3,3,1
379         addi    4,4,1
380         mr      0,5
381         addi    5,5,-1
382         cmpwi   0,0
383         bne     1b
384         blr
385
386 ofw_back:
387         lwz     1,0(1)                  /* get callers original stack pointer */
388
389         lwz     0,4(1)                  /* get saved msr from abused slot */
390         mtmsr   0
391         
392         lwz     1,0(1)                  /* return */
393         lwz     0,4(1)
394         mtlr    0
395         blr
396
397 /*
398  * int setfault()
399  *
400  * Similar to setjmp to setup for handling faults on accesses to user memory.
401  * Any routine using this may only call bcopy, either the form below,
402  * or the (currently used) C code optimized, so it doesn't use any non-volatile
403  * registers.
404  */
405         .globl  setfault
406 setfault:
407         mflr    0
408         mfcr    12
409         mfsprg  4,0
410         lwz     4,PC_CURTHREAD(4)
411         lwz     4,TD_PCB(4)
412         stw     3,PCB_ONFAULT(4)
413         stw     0,0(3)
414         stw     1,4(3)
415         stw     2,8(3)
416         stmw    12,12(3)
417         xor     3,3,3
418         blr
419
420 #include <powerpc/powerpc/trap_subr.S>