xref: /netbsd-src/sys/arch/powerpc/ibm4xx/openbios/locore.S (revision 331e73520e93df1a41c605a367f94e2dc1b2d6d1)
1/*	$NetBSD: locore.S,v 1.17 2021/03/30 01:57:20 rin 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#ifdef PPC_4XX_NOCACHE
71#error "Fix me"
72#endif
73
74#include "assym.h"
75#include "ksyms.h"
76
77#ifdef _KERNEL_OPT
78#include "opt_ddb.h"
79#include "opt_modular.h"
80#include "opt_ppcparam.h"
81#endif
82
83#include <sys/syscall.h>
84
85#include <machine/param.h>
86#include <machine/psl.h>
87#include <machine/trap.h>
88#include <machine/asm.h>
89
90#include <powerpc/spr.h>
91#include <powerpc/ibm4xx/spr.h>
92#include <powerpc/ibm4xx/dcr4xx.h>
93
94/* Function pointer for requesting board_config_data from openbios*/
95#define BOARD_CFG_FP       0xFFFE0B50
96
97/*
98 * This symbol is here for the benefit of kvm_mkdb, and is supposed to
99 * mark the start of kernel text.
100 */
101	.text
102	.globl	_C_LABEL(kernel_text)
103_C_LABEL(kernel_text):
104
105/*
106 * Startup entry.  Note, this must be the first thing in the text
107 * segment!
108 */
109	.text
110	.globl	__start
111__start:
112	b	1f
113	/* Reserve some space for info_block required for IBM eval board bootloader */
114	nop
115	nop
116	nop
117	nop
118	nop
119	nop
120	nop
121	nop
122	nop
123	nop
124
1251:
126	/* Get the board_config_data from openbios */
127	lis	%r3,BOARD_CFG_FP@h
128	ori	%r3,%r3,BOARD_CFG_FP@l
129	lwz     %r0,0x0(%r3)
130	mtctr   %r0
131	bctrl				/* call the xcoff function */
132	mr	%r31,%r3		/* Save value in r31 */
133
134	li	%r0,0
135	mtmsr	%r0			/* Disable FPU/MMU/exceptions */
136	isync
137
138	/* PPC405GP errata, item #58.
139	 * Load string instructions may write incorrect data into the last GPR
140	 * targeted in the operation.
141	 * Workaround: set OCM0_DSCNTL[DSEN]=0 and OCM0_DSCNTL[DOF]=0 */
142	mtdcr	DCR_OCM0_DSCNTL, %r0  	/* Disable Data access to OCM */
143	mtdcr	DCR_OCM0_ISCNTL, %r0  	/* Disable Instruction access to OCM. Just in case */
144/*
145 * Cpu detect.
146 *
147 */
148__start_cpu0:
149#ifdef PPC_4XX_NOCACHE
150	/* Disable all caches for physical addresses */
151	li	%r0,0
152#else
153	/* Allow cacheing for only the first 2GB of RAM */
154	lis	%r0,0xffff
155#endif
156	mtdccr	%r0
157	mticcr	%r0
158
159	/* Invalidate all TLB entries */
160	tlbia
161	sync
162	isync
163/* get start of bss */
164	lis	%r3,_C_LABEL(_edata)-4@ha
165	addi	%r3,%r3,_C_LABEL(_edata)-4@l
166/* get end of kernel memory */
167	lis	%r8,_C_LABEL(end)@ha
168	addi	%r8,%r8,_C_LABEL(end)@l
169/* zero bss */
170	li	%r4,0
1712:	stwu	%r4,4(%r3)
172	cmpw	%r3,%r8
173	bne+	2b
174
175#if NKSYMS || defined(DDB) || defined(MODULAR)
176	/* If we had symbol table location we'd store it here and would've adjusted r8 here */
177	lis	%r7,_C_LABEL(startsym)@ha
178	addi	%r7,%r7,_C_LABEL(startsym)@l
179	stw	%r8,0(%r7)
180	lis	%r7,_C_LABEL(endsym)@ha
181	addi	%r7,%r7,_C_LABEL(endsym)@l
182	stw	%r8,0(%r7)
183#endif
184
185	/* Set kernel MMU context. */
186	li	%r0,KERNEL_PID
187	mtpid	%r0
188	sync
189
190	INIT_CPUINFO(%r8,%r1,%r9,%r0)
191	mr	%r4,%r8
192
193	lis	%r3,__start@ha
194	addi	%r3,%r3,__start@l
195
196	mr	%r6,%r31		/* info_block address */
197	bl	_C_LABEL(initppc)
198	bl	_C_LABEL(main)
199
200loop:	b	loop			/* XXX not reached */
201
202#include <powerpc/ibm4xx/4xx_locore.S>
203