locore.S revision 1.3
1/*	$NetBSD: locore.S,v 1.3 2006/10/16 18:14:37 kiyohara Exp $	*/
2/*	$OpenBSD: locore.S,v 1.4 1997/01/26 09:06:38 rahnds Exp $	*/
3
4/*
5 * Copyright 2001 Wasabi Systems, Inc.
6 * All rights reserved.
7 *
8 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
9 *
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.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *      This product includes software developed for the NetBSD Project by
21 *      Wasabi Systems, Inc.
22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 *    or promote products derived from this software without specific prior
24 *    written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39/*
40 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
41 * Copyright (C) 1995, 1996 TooLs GmbH.
42 * All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 *    notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 *    notice, this list of conditions and the following disclaimer in the
51 *    documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 *    must display the following acknowledgement:
54 *	This product includes software developed by TooLs GmbH.
55 * 4. The name of TooLs GmbH may not be used to endorse or promote products
56 *    derived from this software without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
63 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
64 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
65 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
66 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
67 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 */
69
70#undef PPC_4XX_NOCACHE
71#define _NOREGNAMES
72
73#include "opt_ddb.h"
74#include "opt_ipkdb.h"
75#include "opt_lockdebug.h"
76#include "opt_multiprocessor.h"
77#include "opt_ppcarch.h"
78#include "opt_ppcparam.h"
79#include "assym.h"
80#include "ksyms.h"
81
82#include <sys/syscall.h>
83
84#include <machine/param.h>
85#include <machine/psl.h>
86#include <machine/trap.h>
87#include <machine/asm.h>
88
89#include <powerpc/spr.h>
90#include <powerpc/ibm4xx/dcr405gp.h>
91#include <powerpc/ibm4xx/pmap.h>
92
93/* Function pointer for requesting board_config_data from openbios*/
94#define BOARD_CFG_FP       0xFFFE0B50
95
96/*
97 * Some instructions gas doesn't understand (yet?)
98 */
99#define	bdneq	bdnzf 2,
100
101/*
102 * Globals
103 */
104GLOBAL(proc0paddr)
105	.long	0			/* proc0 p_addr */
106
107GLOBAL(intrnames)
108	.asciz	"clock", "irq1", "irq2", "irq3"
109	.asciz	"irq4", "irq5", "irq6", "irq7"
110	.asciz	"irq8", "irq9", "irq10", "irq11"
111	.asciz	"irq12", "irq13", "irq14", "irq15"
112	.asciz	"irq16", "irq17", "irq18", "irq19"
113	.asciz	"irq20", "irq21", "irq22", "irq23"
114	.asciz	"irq24", "irq25", "irq26", "irq27"
115	.asciz	"irq28", "softnet", "softclock", "softserial"
116	.asciz  "statclock"
117GLOBAL(eintrnames)
118	.align	4
119GLOBAL(intrcnt)
120	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
121	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
122	.long	0
123GLOBAL(eintrcnt)
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	b	1f
141	/* Reserve some space for info_block required for IBM eval board bootloader */
142	nop
143	nop
144	nop
145	nop
146	nop
147	nop
148	nop
149	nop
150	nop
151	nop
152
1531:
154	/* Get the board_config_data from openbios */
155	lis	%r3,BOARD_CFG_FP@h
156	ori	%r3,%r3,BOARD_CFG_FP@l
157	lwz     %r0,0x0(%r3)
158	mtctr   %r0
159	bctrl				/* call the xcoff function */
160	mr	%r31,%r3		/* Save value in r31 */
161
162	li	%r0,0
163	mtmsr	%r0			/* Disable FPU/MMU/exceptions */
164	isync
165
166	/* PPC405GP errata, item #58.
167	 * Load string instructions may write incorrect data into the last GPR
168	 * targeted in the operation.
169	 * Workaround: set OCM0_DSCNTL[DSEN]=0 and OCM0_DSCNTL[DOF]=0 */
170	mtdcr	DCR_OCM0_DSCNTL, %r0  	/* Disable Data access to OCM */
171	mtdcr	DCR_OCM0_ISCNTL, %r0  	/* Disable Instruction access to OCM. Just in case */
172/*
173 * Cpu detect.
174 *
175 */
176__start_cpu0:
177#ifdef PPC_4XX_NOCACHE
178	/* Disable all caches for physical addresses */
179	li	%r0,0
180#else
181	/* Allow cacheing for only the first 2GB of RAM */
182	lis	%r0,0xffff
183#endif
184	mtdccr	%r0
185	mticcr	%r0
186
187	/* Invalidate all TLB entries */
188	tlbia
189	sync
190	isync
191/* get start of bss */
192	lis	%r3,_C_LABEL(_edata)-4@ha
193	addi	%r3,%r3,_C_LABEL(_edata)-4@l
194/* get end of kernel memory */
195	lis	%r8,_C_LABEL(end)@ha
196	addi	%r8,%r8,_C_LABEL(end)@l
197/* zero bss */
198	li	%r4,0
1992:	stwu	%r4,%r4(3)
200	cmpw	%r3,%r8
201	bne+	2b
202
203#if NKSYMS || defined(DDB) || defined(LKM)
204	/* If we had symbol table location we'd store it here and would've adjusted r8 here */
205	lis	%r7,_C_LABEL(startsym)@ha
206	addi	%r7,%r7,_C_LABEL(startsym)@l
207	stw	%r8,0(%r7)
208	lis	%r7,_C_LABEL(endsym)@ha
209	addi	%r7,%r7,_C_LABEL(endsym)@l
210	stw	%r8,0(%r7)
211#endif
212
213	/* Set kernel MMU context. */
214	li	%r0,KERNEL_PID
215	mtpid	%r0
216	sync
217
218	INIT_CPUINFO(8,1,9,0)
219	mr	%r4,%r8
220
221	lis	%r3,__start@ha
222	addi	%r3,%r3,__start@l
223
224	mr	%r6,%r31		/* info_block address */
225	bl	_C_LABEL(initppc)
226	bl	_C_LABEL(main)
227
228loop:	b	loop			/* XXX not reached */
229
230#include <powerpc/ibm4xx/4xx_locore.S>
231