xref: /netbsd/sys/arch/ofppc/ofppc/locore.S (revision c4a72b64)
1/*	$NetBSD: locore.S,v 1.28 2002/07/14 20:56:12 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_ipkdb.h"
36#include "opt_lockdebug.h"
37#include "opt_multiprocessor.h"
38#include "assym.h"
39
40#include <sys/syscall.h>
41
42#include <machine/param.h>
43#include <machine/pmap.h>
44#include <machine/psl.h>
45#include <machine/trap.h>
46#include <machine/asm.h>
47
48#ifndef OLDPMAP
49#include <machine/vmparam.h>
50#endif
51
52#include <powerpc/spr.h>
53/*
54 * Some instructions gas doesn't understand (yet?)
55 */
56#define	bdneq	bdnzf 2,
57
58#define	INTSTK	(8*1024)	/* 8K interrupt stack */
59#define	SPILLSTK 1024		/* 1K spill stack */
60
61/*
62 * Globals
63 */
64GLOBAL(startsym)
65	.long	0			/* start of symbol table */
66GLOBAL(endsym)
67	.long	0			/* end of symbol table */
68GLOBAL(proc0paddr)
69	.long	0			/* proc0 p_addr */
70
71/*
72 * File-scope for locore.S
73 */
74	.data
75idle_u:
76	.long	0			/* fake uarea during idle after exit */
77OF_buffer:
78	.space	NBPG
79
80/*
81 * This symbol is here for the benefit of kvm_mkdb, and is supposed to
82 * mark the start of kernel text.
83 */
84	.text
85	.globl	_C_LABEL(kernel_text)
86_C_LABEL(kernel_text):
87
88/*
89 * Startup entry.  Note, this must be the first thing in the text
90 * segment!
91 */
92	.text
93	.globl	__start
94__start:
95	bl	_C_LABEL(ofwinit)	/* init our OF hooks */
96
97	li	0,0
98	mtmsr	0			/* Disable FPU/MMU/exceptions */
99	isync
100
101	/* compute end of kernel memory */
102#ifdef DDB
103	/* skip symbol table */
104	cmpwi	6,0
105	beq	1f
106	add	9,6,7			/* r9 = args + l */
107
108	/* If the resulting address is misaligned, abort. */
109	andi.	8,9,3
110	bne	1f			/* misaligned */
111
112	/* First, see if the loader even put the symbols there. */
113	lwz	9,-12(9)
114	lis	8,0x19730224@h		/* magic number */
115	ori	8,8,0x19730224@l
116	cmplw	8,9
117	bne	1f			/* nope */
118
119	/* Okay, ssym and esym are here -- fetch them. */
120	add	9,6,7
121	lwz	9,-8(9)
122	lis	8,_C_LABEL(startsym)@ha
123	stw	9,_C_LABEL(startsym)@l(8)
124
125	add	9,6,7
126	lwz	9,-4(9)
127	lis	8,_C_LABEL(endsym)@ha
128	stw	9,_C_LABEL(endsym)@l(8)
129
130	mr	8,9			/* r8 = end of kernel + symbols */
131	b	2f
1321:
133#endif
134	lis	8,_C_LABEL(end)@ha
135	addi	8,8,_C_LABEL(end)@l
1362:
137	li	9,PGOFSET
138	add	8,8,9
139	andc	8,8,9
140
141	lis	9,idle_u@ha
142	stw	8,idle_u@l(9)
143	addi	8,8,USPACE		/* space for idle_u */
144	lis	9,_C_LABEL(proc0paddr)@ha
145	stw	8,_C_LABEL(proc0paddr)@l(9)
146	addi	1,8,USPACE-FRAMELEN	/* stackpointer for proc0 */
147	mr	4,1			/* end of mem reserved for kernel */
148	xor	0,0,0
149	stwu	0,-16(1)		/* end of stack chain */
150
151	lis	8,OF_buffer@ha
152	addi	8,8,OF_buffer@l
153	lis	9,_C_LABEL(OF_buf)@ha
154	stw	8,_C_LABEL(OF_buf)@l(9)
155
156	lis	3,__start@ha
157	addi	3,3,__start@l
158	mr	5,6			/* args string */
159	bl	_C_LABEL(initppc)
160	bl	_C_LABEL(main)
161	b	_C_LABEL(OF_exit)
162
163/*
164 * Pull in common OFW code.
165 */
166#include <powerpc/mpc6xx/ofw_subr.S>
167
168/*
169 * Pull in common switch / setfault code.
170 */
171#include <powerpc/powerpc/locore_subr.S>
172
173/*
174 * Pull in common trap vector code.
175 */
176#include <powerpc/powerpc/trap_subr.S>
177