xref: /netbsd/sys/arch/evbppc/obs405/obs200_locore.S (revision 361e68bb)
1*361e68bbSmaxv/*	$NetBSD: obs200_locore.S,v 1.13 2018/07/15 05:16:42 maxv Exp $	*/
2a38e26c7Sshige/*	Original Tag: locore.S,v 1.1 2003/09/23 15:21:58 shige Exp	*/
3a38e26c7Sshige/*	$OpenBSD: locore.S,v 1.4 1997/01/26 09:06:38 rahnds Exp $	*/
4a38e26c7Sshige
5a38e26c7Sshige/*
6a38e26c7Sshige * Copyright 2001 Wasabi Systems, Inc.
7a38e26c7Sshige * All rights reserved.
8a38e26c7Sshige *
9a38e26c7Sshige * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
10a38e26c7Sshige *
11a38e26c7Sshige * Redistribution and use in source and binary forms, with or without
12a38e26c7Sshige * modification, are permitted provided that the following conditions
13a38e26c7Sshige * are met:
14a38e26c7Sshige * 1. Redistributions of source code must retain the above copyright
15a38e26c7Sshige *    notice, this list of conditions and the following disclaimer.
16a38e26c7Sshige * 2. Redistributions in binary form must reproduce the above copyright
17a38e26c7Sshige *    notice, this list of conditions and the following disclaimer in the
18a38e26c7Sshige *    documentation and/or other materials provided with the distribution.
19a38e26c7Sshige * 3. All advertising materials mentioning features or use of this software
20a38e26c7Sshige *    must display the following acknowledgement:
21a38e26c7Sshige *      This product includes software developed for the NetBSD Project by
22a38e26c7Sshige *      Wasabi Systems, Inc.
23a38e26c7Sshige * 4. The name of Wasabi Systems, Inc. may not be used to endorse
24a38e26c7Sshige *    or promote products derived from this software without specific prior
25a38e26c7Sshige *    written permission.
26a38e26c7Sshige *
27a38e26c7Sshige * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
28a38e26c7Sshige * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29a38e26c7Sshige * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30a38e26c7Sshige * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
31a38e26c7Sshige * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32a38e26c7Sshige * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33a38e26c7Sshige * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34a38e26c7Sshige * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35a38e26c7Sshige * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36a38e26c7Sshige * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37a38e26c7Sshige * POSSIBILITY OF SUCH DAMAGE.
38a38e26c7Sshige */
39a38e26c7Sshige
40a38e26c7Sshige/*
41a38e26c7Sshige * Copyright (C) 1995, 1996 Wolfgang Solfrank.
42a38e26c7Sshige * Copyright (C) 1995, 1996 TooLs GmbH.
43a38e26c7Sshige * All rights reserved.
44a38e26c7Sshige *
45a38e26c7Sshige * Redistribution and use in source and binary forms, with or without
46a38e26c7Sshige * modification, are permitted provided that the following conditions
47a38e26c7Sshige * are met:
48a38e26c7Sshige * 1. Redistributions of source code must retain the above copyright
49a38e26c7Sshige *    notice, this list of conditions and the following disclaimer.
50a38e26c7Sshige * 2. Redistributions in binary form must reproduce the above copyright
51a38e26c7Sshige *    notice, this list of conditions and the following disclaimer in the
52a38e26c7Sshige *    documentation and/or other materials provided with the distribution.
53a38e26c7Sshige * 3. All advertising materials mentioning features or use of this software
54a38e26c7Sshige *    must display the following acknowledgement:
55a38e26c7Sshige *	This product includes software developed by TooLs GmbH.
56a38e26c7Sshige * 4. The name of TooLs GmbH may not be used to endorse or promote products
57a38e26c7Sshige *    derived from this software without specific prior written permission.
58a38e26c7Sshige *
59a38e26c7Sshige * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
60a38e26c7Sshige * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61a38e26c7Sshige * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62a38e26c7Sshige * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
63a38e26c7Sshige * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
64a38e26c7Sshige * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
65a38e26c7Sshige * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
66a38e26c7Sshige * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
67a38e26c7Sshige * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
68a38e26c7Sshige * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69a38e26c7Sshige */
70a38e26c7Sshige
71a38e26c7Sshige#undef PPC_4XX_NOCACHE
72a38e26c7Sshige
73a38e26c7Sshige#include "opt_ddb.h"
74a38e26c7Sshige#include "opt_lockdebug.h"
750cc72e51Sapb#include "opt_modular.h"
76a38e26c7Sshige#include "opt_multiprocessor.h"
77a38e26c7Sshige#include "opt_ppcarch.h"
78a38e26c7Sshige#include "opt_ppcparam.h"
79a38e26c7Sshige#include "assym.h"
80a38e26c7Sshige#include "ksyms.h"
81a38e26c7Sshige
82a38e26c7Sshige#include <sys/syscall.h>
83a38e26c7Sshige
84a38e26c7Sshige#include <machine/param.h>
85a38e26c7Sshige#include <machine/psl.h>
86a38e26c7Sshige#include <machine/trap.h>
87a38e26c7Sshige#include <machine/asm.h>
88a38e26c7Sshige
89a38e26c7Sshige#include <powerpc/spr.h>
90ec4306c9Smatt#include <powerpc/ibm4xx/spr.h>
912692e2e2Skiyohara#include <powerpc/ibm4xx/dcr4xx.h>
92a38e26c7Sshige
93a38e26c7Sshige/* Function pointer for requesting board_config_data from OpenBlockS S/R BIOS */
94a38e26c7Sshige#define BOARD_CFG_FP	(0x00100000)
95a38e26c7Sshige
96a38e26c7Sshige/*
97a38e26c7Sshige * Some instructions gas doesn't understand (yet?)
98a38e26c7Sshige */
99a38e26c7Sshige#define	bdneq	bdnzf 2,
100a38e26c7Sshige
101a38e26c7Sshige/*
102a38e26c7Sshige * This symbol is here for the benefit of kvm_mkdb, and is supposed to
103a38e26c7Sshige * mark the start of kernel text.
104a38e26c7Sshige */
105a38e26c7Sshige	.text
106a38e26c7Sshige	.globl	_C_LABEL(kernel_text)
107a38e26c7Sshige_C_LABEL(kernel_text):
108a38e26c7Sshige
109a38e26c7Sshige/*
110a38e26c7Sshige * Startup entry.  Note, this must be the first thing in the text
111a38e26c7Sshige * segment!
112a38e26c7Sshige */
113a38e26c7Sshige	.text
114a38e26c7Sshige	.globl	__start
115a38e26c7Sshige__start:
116a38e26c7Sshige	b	1f
117a38e26c7Sshige	/* Reserve some space for info_block required for IBM eval board bootloader */
118a38e26c7Sshige	nop
119a38e26c7Sshige	nop
120a38e26c7Sshige	nop
121a38e26c7Sshige	nop
122a38e26c7Sshige	nop
123a38e26c7Sshige	nop
124a38e26c7Sshige	nop
125a38e26c7Sshige	nop
126a38e26c7Sshige	nop
127a38e26c7Sshige	nop
128a38e26c7Sshige
129a38e26c7Sshige1:
130a38e26c7Sshige	/* Get the board_config_data from openbios */
131a38e26c7Sshige	lis	%r3,BOARD_CFG_FP@h
132a38e26c7Sshige	ori	%r3,%r3,BOARD_CFG_FP@l
133a38e26c7Sshige	mr	%r31,%r3		/* Save value in r31 */
134a38e26c7Sshige
135a38e26c7Sshige	li	%r0,0
136a38e26c7Sshige	mtmsr	%r0			/* Disable FPU/MMU/exceptions */
137a38e26c7Sshige	isync
138a38e26c7Sshige
139a38e26c7Sshige	/* PPC405GP errata, item #58.
140a38e26c7Sshige	 * Load string instructions may write incorrect data into the last GPR
141a38e26c7Sshige	 * targeted in the operation.
142a38e26c7Sshige	 * Workaround: set OCM0_DSCNTL[DSEN]=0 and OCM0_DSCNTL[DOF]=0 */
143a38e26c7Sshige	mtdcr	DCR_OCM0_DSCNTL, %r0  	/* Disable Data access to OCM */
144a38e26c7Sshige	mtdcr	DCR_OCM0_ISCNTL, %r0  	/* Disable Instruction access to OCM. Just in case */
145a38e26c7Sshige/*
146a38e26c7Sshige * Cpu detect.
147a38e26c7Sshige *
148a38e26c7Sshige */
149a38e26c7Sshige__start_cpu0:
150a38e26c7Sshige#ifdef PPC_4XX_NOCACHE
151a38e26c7Sshige	/* Disable all caches for physical addresses */
152a38e26c7Sshige	li	%r0,0
153a38e26c7Sshige#else
154a38e26c7Sshige	/* Allow cacheing for only the first 2GB of RAM */
155a38e26c7Sshige	lis	%r0,0xffff
156a38e26c7Sshige#endif
157a38e26c7Sshige	mtdccr	%r0
158a38e26c7Sshige	mticcr	%r0
159a38e26c7Sshige
160a38e26c7Sshige	/* Invalidate all TLB entries */
161a38e26c7Sshige	tlbia
162a38e26c7Sshige	sync
163a38e26c7Sshige	isync
164a38e26c7Sshige/* get start of bss */
165a38e26c7Sshige	lis	%r3,_C_LABEL(_edata)-4@ha
166a38e26c7Sshige	addi	%r3,%r3,_C_LABEL(_edata)-4@l
167a38e26c7Sshige/* get end of kernel memory */
168a38e26c7Sshige	lis	%r8,_C_LABEL(end)@ha
169a38e26c7Sshige	addi	%r8,%r8,_C_LABEL(end)@l
170a38e26c7Sshige/* zero bss */
171a38e26c7Sshige	li	%r4,0
1721175f9a7Sjoerg2:	stwu	%r4,4(%r3)
173a38e26c7Sshige	cmpw	%r3,%r8
174a38e26c7Sshige	bne+	2b
175a38e26c7Sshige
1765b57d1bcSad#if NKSYMS || defined(DDB) || defined(MODULAR)
177a38e26c7Sshige	/* If we had symbol table location we'd store it here and would've adjusted r8 here */
178a38e26c7Sshige	lis	%r7,_C_LABEL(startsym)@ha
179a38e26c7Sshige	addi	%r7,%r7,_C_LABEL(startsym)@l
180a38e26c7Sshige	stw	%r8,0(%r7)
181a38e26c7Sshige	lis	%r7,_C_LABEL(endsym)@ha
182a38e26c7Sshige	addi	%r7,%r7,_C_LABEL(endsym)@l
183a38e26c7Sshige	stw	%r8,0(%r7)
184a38e26c7Sshige#endif
185a38e26c7Sshige
186471efec8Skiyohara	/* Set kernel MMU context. */
187471efec8Skiyohara	li	%r0,KERNEL_PID
188a38e26c7Sshige	mtpid	%r0
189a38e26c7Sshige	sync
190a38e26c7Sshige
191a38e26c7Sshige	INIT_CPUINFO(8,1,9,0)
192a38e26c7Sshige	mr	%r4,%r8
193a38e26c7Sshige
194a38e26c7Sshige	lis	%r3,__start@ha
195a38e26c7Sshige	addi	%r3,%r3,__start@l
196a38e26c7Sshige
197a38e26c7Sshige	mr	%r6,%r31		/* info_block address */
198a38e26c7Sshige	bl	_C_LABEL(initppc)
199a38e26c7Sshige	bl	_C_LABEL(main)
200a38e26c7Sshige
201a38e26c7Sshigeloop:	b	loop			/* XXX not reached */
202a38e26c7Sshige
203a38e26c7Sshige#include <powerpc/ibm4xx/4xx_locore.S>
204