xref: /netbsd/sys/arch/macppc/macppc/locore.S (revision c4a72b64)
1/*	$NetBSD: locore.S,v 1.47 2002/07/28 07:07:00 chs Exp $	*/
2
3/*
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
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 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 *    derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include "opt_ddb.h"
35#include "opt_kgdb.h"
36#include "opt_ipkdb.h"
37#include "opt_lockdebug.h"
38#include "opt_multiprocessor.h"
39#include "opt_altivec.h"
40#include "assym.h"
41
42#include <sys/syscall.h>
43
44#include <machine/param.h>
45#include <machine/pmap.h>
46#include <machine/psl.h>
47#include <machine/trap.h>
48#include <machine/asm.h>
49#ifndef OLDPMAP
50#include <machine/vmparam.h>
51#endif
52
53#include <powerpc/spr.h>
54/*
55 * Some instructions gas doesn't understand (yet?)
56 */
57#define	bdneq	bdnzf 2,
58
59#if defined(MULTIPROCESSOR)
60/*
61 * Get varios per-cpu values.
62 */
63#if 1
64#define GET_CPUINFO(r)	\
65	mfsprg	r,0
66#else
67#define	GET_CPUINFO(r)						\
68	mfspr	r,SPR_PIR;		/* r = cpu_number() */	\
69	mulli	r,r,CI_SIZE;					\
70	addis	r,r,_C_LABEL(cpu_info)@ha;			\
71	addi	r,r,_C_LABEL(cpu_info)@l;
72#endif
73#endif
74
75#define	INTSTK   8192			/* 8K interrupt stack */
76#define	SPILLSTK 4096			/* 4K spill stack */
77
78/*
79 * Globals
80 */
81	.data
82GLOBAL(esym)
83	.long	0			/* end of symbol table */
84GLOBAL(proc0paddr)
85	.long	0			/* proc0 p_addr */
86
87GLOBAL(intrnames)
88	.asciz	"irq0", "irq1", "irq2", "irq3"
89	.asciz	"irq4", "irq5", "irq6", "irq7"
90	.asciz	"irq8", "irq9", "irq10", "irq11"
91	.asciz	"irq12", "irq13", "irq14", "irq15"
92	.asciz	"irq16", "irq17", "irq18", "irq19"
93	.asciz	"irq20", "irq21", "irq22", "irq23"
94	.asciz	"irq24", "irq25", "irq26", "irq27"
95	.asciz	"irq28", "irq29", "irq30", "irq31"
96	.asciz	"irq32", "irq33", "irq34", "irq35"
97	.asciz	"irq36", "irq37", "irq38", "irq39"
98	.asciz	"irq40", "irq41", "irq42", "irq43"
99	.asciz	"irq44", "irq45", "irq46", "irq47"
100	.asciz	"irq48", "irq49", "irq50", "irq51"
101	.asciz	"irq52", "irq53", "irq54", "irq55"
102	.asciz	"irq56", "irq57", "irq58", "irq59"
103	.asciz	"irq60", "irq61", "irq62", "irq63"
104	.asciz	"clock", "softclock", "softnet", "softserial"
105GLOBAL(eintrnames)
106	.align	4
107GLOBAL(intrcnt)
108	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
109	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
110	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
111	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
112	.long	0,0,0,0
113GLOBAL(eintrcnt)
114
115/*
116 * File-scope for locore.S
117 */
118#if !defined(MULTIPROCESSOR)
119idle_u:
120	.long	0			/* fake uarea during idle after exit */
121#endif
122OF_buffer:
123	.space	NBPG
124
125/*
126 * This symbol is here for the benefit of kvm_mkdb, and is supposed to
127 * mark the start of kernel text.
128 */
129	.text
130	.globl	_C_LABEL(kernel_text)
131_C_LABEL(kernel_text):
132
133/*
134 * Startup entry.  Note, this must be the first thing in the text
135 * segment!
136 */
137	.text
138	.globl	__start
139__start:
140	bl	_C_LABEL(ofwinit)	/* init OF */
141
142	li	0,0
143	mtmsr	0			/* Disable FPU/MMU/exceptions */
144	isync
145
146/* compute end of kernel memory */
147	lis	8,_C_LABEL(end)@ha
148	addi	8,8,_C_LABEL(end)@l
149#ifdef DDB
150	/* skip symbol table */
151	cmpwi	6,0
152	beq	1f
153	add	9,6,7			/* r9 = args + l */
154	lwz	9,-8(9)			/* esym */
155	cmpwi	9,0
156	beq	1f
157	mr	8,9
1581:
159#endif
160	li	9,PGOFSET
161	add	8,8,9
162	andc	8,8,9
163#if defined(MULTIPROCESSOR)
164	lis	9,_C_LABEL(cpu_info)@ha
165	addi	9,9,_C_LABEL(cpu_info)@l
166	addi	8,8,INTSTK
167	stw	8,CI_INTSTK(9)
168	addi	8,8,SPILLSTK
169	stw	8,CI_SPILLSTK(9)
170	stw	8,CI_IDLE_PCB(9)
171	stw	0,USPACE-16(8)		/* terminate idle stack chain */
172#else
173	lis	9,idle_u@ha
174	stw	8,idle_u@l(9)
175#endif
176	addi	8,8,USPACE		/* space for idle_u */
177	lis	9,_C_LABEL(proc0paddr)@ha
178	stw	8,_C_LABEL(proc0paddr)@l(9)
179	addi	1,8,USPACE-FRAMELEN	/* stackpointer for proc0 */
180	mr	4,1			/* end of mem reserved for kernel */
181	xor	0,0,0
182	stwu	0,-16(1)		/* end of stack chain */
183
184	lis	8,OF_buffer@ha
185	addi	8,8,OF_buffer@l
186	lis	9,_C_LABEL(OF_buf)@ha
187	stw	8,_C_LABEL(OF_buf)@l(9)
188
189	lis	3,__start@ha
190	addi	3,3,__start@l
191	mr	5,6			/* args string */
192	bl	_C_LABEL(initppc)
193	bl	_C_LABEL(main)
194	b	_C_LABEL(OF_exit)
195
196#if defined(MULTIPROCESSOR)
197	.globl	_C_LABEL(cpu_spinup_trampoline)
198_C_LABEL(cpu_spinup_trampoline):
199	li	0,0
200	mtmsr	0
201	isync
202
203	lis	3,_C_LABEL(cpu_hatch_stack)@ha
204	lwz	1,_C_LABEL(cpu_hatch_stack)@l(3)
205
206	bl	_C_LABEL(cpu_hatch)
207	bl      _C_LABEL(sched_lock_idle)
208	li      30,0
209	b       _ASM_LABEL(Idle)
210#endif
211
212/*
213 * Pull in common Open Firmware code.
214 */
215#include <powerpc/mpc6xx/ofw_subr.S>
216
217/*
218 * Pull in common switch and setfault code.
219 */
220#include <powerpc/powerpc/locore_subr.S>
221
222/*
223 * Pull in common trap vector code.
224 */
225#if defined(MULTIPROCESSOR)
226#include <powerpc/powerpc/trap_subr_mp.S>
227#else
228#include <powerpc/powerpc/trap_subr.S>
229#endif
230