xref: /netbsd-src/sys/arch/ofppc/ofppc/locore.S (revision 3f351f34c6d827cf017cdcff3543f6ec0c88b420)
1/*	$NetBSD: locore.S,v 1.52 2021/02/26 02:18:56 thorpej 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_lockdebug.h"
36#include "opt_modular.h"
37#include "opt_multiprocessor.h"
38#include "opt_ppcparam.h"
39#include "assym.h"
40
41#include <sys/syscall.h>
42
43#include <machine/param.h>
44#include <machine/psl.h>
45#include <machine/trap.h>
46#include <machine/asm.h>
47
48#include <powerpc/spr.h>
49#include <powerpc/oea/spr.h>
50
51#include "ksyms.h"
52
53/*
54 * Some instructions gas doesn't understand (yet?)
55 */
56#define	bdneq	bdnzf 2,
57
58/*
59 * Globals
60 */
61	.data
62GLOBAL(esym)
63	.long	0			/* end of symbol table */
64
65/*
66 * This symbol is here for the benefit of kvm_mkdb, and is supposed to
67 * mark the start of kernel text.
68 */
69	.text
70	.globl	_C_LABEL(kernel_text)
71_C_LABEL(kernel_text):
72
73/*
74 * Startup entry.  Note, this must be the first thing in the text
75 * segment!
76 *
77 * Register state as transfer is passed from OpenFirmware / boot loader:
78 *
79 *	%r1	Stack provided by OpenFirmware / boot loader
80 *	%r3	Reserved for platform binding (unused here)
81 *	%r4	Reserved for platform binding (unused here)
82 *	%r5	OpenFirmware client entry point
83 *	%r6	Arguments
84 *	%r7	Arguments length
85 */
86	.text
87	.globl	__start
88__start:
89	/* Save off arguments that we need preserved. */
90	mr	%r13,%r6
91	mr	%r14,%r7
92
93	bl	_C_LABEL(ofwinit)	/* init OF */
94
95	li	%r0,0
96	mtmsr	%r0			/* Disable FPU/MMU/exceptions */
97
98	bl	_C_LABEL(cpu_model_init)
99	lis	%r12,oeacpufeat@ha
100	lwz	%r12,oeacpufeat@l(%r12)
101	andi.	%r12,%r12,OEACPU_64_BRIDGE	/* Compare against OEACPU_64_BRIDGE */
102	beq	2f			/* skip if this is a 32bit part */
103	li	%r0,0
104	sync
105	slbia				/* invalidate the slb table */
106	sync
107	clrldi	%r0,%r0,32		/* clear SF/ISF (high order bits) */
108	mtmsrd	%r0
109	mtspr	0x118,0		/* clear ASR[V] to enable segregs */
1102:
111	isync
112	/* compute end of kernel memory */
113        lis	%r4,_C_LABEL(end)@ha
114        addi	%r4,%r4,_C_LABEL(end)@l
115#if NKSYMS || defined(DDB) || defined(MODULAR)
116	/* skip symbol table */
117	mr	%r6,%r13
118	mr	%r7,%r14
119	cmpwi	%r6,0
120	beq	1f
121	add	%r9,%r6,%r7			/* r9 = args + l */
122	lwz	%r9,-8(%r9)			/* esym */
123	cmpwi	%r9,0
124	beq	1f
125	mr	%r4,%r9
1261:
127#endif
128
129
130	/*
131	 * Initialize cpu_info[0]
132	 */
133	INIT_CPUINFO(%r4,%r1,%r9,%r0)
134
135	lis	%r3,__start@ha
136	addi	%r3,%r3,__start@l
137	mr	%r5,%r6			/* args string */
138	bl	_C_LABEL(initppc)
139	bl	_C_LABEL(main)
140	b	_C_LABEL(OF_exit)
141
142/*
143 * Pull in common OFW code.
144 */
145#include <powerpc/oea/ofw_subr.S>
146
147/*
148 * Pull in common switch / setfault code.
149 */
150#include <powerpc/powerpc/locore_subr.S>
151
152/*
153 * Pull in common trap vector code.
154 */
155#include <powerpc/powerpc/trap_subr.S>
156
157/*
158 * Pull in common pio / bus_space code.
159 */
160#include <powerpc/powerpc/pio_subr.S>
161