1/*	$NetBSD: locore.S,v 1.47 2011/06/18 21:17:29 matt 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_modular.h"
38#include "opt_multiprocessor.h"
39#include "opt_ppcparam.h"
40#include "assym.h"
41
42#include <sys/syscall.h>
43
44#include <machine/param.h>
45#include <machine/psl.h>
46#include <machine/trap.h>
47#include <machine/asm.h>
48
49#include <powerpc/spr.h>
50#include <powerpc/oea/spr.h>
51
52#include "ksyms.h"
53
54/*
55 * Some instructions gas doesn't understand (yet?)
56 */
57#define	bdneq	bdnzf 2,
58
59/*
60 * Globals
61 */
62	.data
63GLOBAL(esym)
64	.long	0			/* end of symbol table */
65GLOBAL(oeacpufeat)
66	.long	0			/* cpu features */
67
68/*
69 * This symbol is here for the benefit of kvm_mkdb, and is supposed to
70 * mark the start of kernel text.
71 */
72	.text
73	.globl	_C_LABEL(kernel_text)
74_C_LABEL(kernel_text):
75
76/*
77 * Startup entry.  Note, this must be the first thing in the text
78 * segment!
79 */
80	.text
81	.globl	__start
82__start:
83	bl	_C_LABEL(ofwinit)	/* init our OF hooks */
84
85	li	%r0,0
86	mtmsr	%r0			/* Disable FPU/MMU/exceptions */
87
88	bl	_C_LABEL(cpu_model_init)
89	lis	%r12,oeacpufeat@ha
90	lwz	%r12,oeacpufeat@l(%r12)
91	andi.	%r12,%r12,OEACPU_64_BRIDGE	/* Compare against OEACPU_64_BRIDGE */
92	beq	2f			/* skip if this is a 32bit part */
93	li	%r0,0
94	sync
95	slbia				/* invalidate the slb table */
96	sync
97	clrldi	%r0,%r0,32		/* clear SF/ISF (high order bits) */
98	mtmsrd	%r0
99	mtspr	0x118,0		/* clear ASR[V] to enable segregs */
1002:
101	isync
102	/* compute end of kernel memory */
103        lis	%r4,_C_LABEL(end)@ha
104        addi	%r4,%r4,_C_LABEL(end)@l
105#if NKSYMS || defined(DDB) || defined(MODULAR)
106	/* skip symbol table */
107	cmpwi	%r6,0
108	beq	1f
109	add	%r9,%r6,%r7			/* r9 = args + l */
110	lwz	%r9,-8(%r9)			/* esym */
111	cmpwi	%r9,0
112	beq	1f
113	mr	%r4,%r9
1141:
115#endif
116
117
118	/*
119	 * Initialize cpu_info[0]
120	 */
121	INIT_CPUINFO(%r4,%r1,%r9,%r0)
122
123	lis	%r3,__start@ha
124	addi	%r3,%r3,__start@l
125	mr	%r5,%r6			/* args string */
126	bl	_C_LABEL(initppc)
127	bl	_C_LABEL(main)
128	b	_C_LABEL(OF_exit)
129
130/*
131 * Pull in common OFW code.
132 */
133#include <powerpc/oea/ofw_subr.S>
134
135/*
136 * Pull in common switch / setfault code.
137 */
138#include <powerpc/powerpc/locore_subr.S>
139
140/*
141 * Pull in common trap vector code.
142 */
143#include <powerpc/powerpc/trap_subr.S>
144
145/*
146 * Pull in common pio / bus_space code.
147 */
148#include <powerpc/powerpc/pio_subr.S>
149