xref: /netbsd-src/sys/arch/powerpc/ibm4xx/4xx_trap_subr.S (revision 5cc603a58f8fe3fd36ca1b10a556087025c0efd5)
1*5cc603a5Srin/*	$NetBSD: 4xx_trap_subr.S,v 1.10 2022/09/12 08:02:44 rin Exp $	*/
218b2f7e6Ssimonb
318b2f7e6Ssimonb/*
418b2f7e6Ssimonb * Copyright 2001 Wasabi Systems, Inc.
518b2f7e6Ssimonb * All rights reserved.
618b2f7e6Ssimonb *
718b2f7e6Ssimonb * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
818b2f7e6Ssimonb *
918b2f7e6Ssimonb * Redistribution and use in source and binary forms, with or without
1018b2f7e6Ssimonb * modification, are permitted provided that the following conditions
1118b2f7e6Ssimonb * are met:
1218b2f7e6Ssimonb * 1. Redistributions of source code must retain the above copyright
1318b2f7e6Ssimonb *    notice, this list of conditions and the following disclaimer.
1418b2f7e6Ssimonb * 2. Redistributions in binary form must reproduce the above copyright
1518b2f7e6Ssimonb *    notice, this list of conditions and the following disclaimer in the
1618b2f7e6Ssimonb *    documentation and/or other materials provided with the distribution.
1718b2f7e6Ssimonb * 3. All advertising materials mentioning features or use of this software
1818b2f7e6Ssimonb *    must display the following acknowledgement:
1918b2f7e6Ssimonb *      This product includes software developed for the NetBSD Project by
2018b2f7e6Ssimonb *      Wasabi Systems, Inc.
2118b2f7e6Ssimonb * 4. The name of Wasabi Systems, Inc. may not be used to endorse
2218b2f7e6Ssimonb *    or promote products derived from this software without specific prior
2318b2f7e6Ssimonb *    written permission.
2418b2f7e6Ssimonb *
2518b2f7e6Ssimonb * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
2618b2f7e6Ssimonb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2718b2f7e6Ssimonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2818b2f7e6Ssimonb * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
2918b2f7e6Ssimonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3018b2f7e6Ssimonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3118b2f7e6Ssimonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3218b2f7e6Ssimonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3318b2f7e6Ssimonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3418b2f7e6Ssimonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3518b2f7e6Ssimonb * POSSIBILITY OF SUCH DAMAGE.
3618b2f7e6Ssimonb */
3718b2f7e6Ssimonb
3818b2f7e6Ssimonb/* This file provides necessary handlers for 405GP CPU
396041a292Srin * It should be included in locore.S after powerpc/ibm4xx/trap_subr.S
4018b2f7e6Ssimonb */
4118b2f7e6Ssimonb
4218b2f7e6Ssimonb	.text
4318b2f7e6Ssimonb	.globl	_C_LABEL(pitfitwdog),_C_LABEL(pitfitwdogsize)
4418b2f7e6Ssimonb
4518b2f7e6Ssimonb	.align 4
4618b2f7e6Ssimonb_C_LABEL(pitfitwdog):
4718b2f7e6Ssimonb	sync
4818b2f7e6Ssimonb	ba	pitint
4918b2f7e6Ssimonb	.align 4
5018b2f7e6Ssimonb	sync
5118b2f7e6Ssimonb	ba	fitint
5218b2f7e6Ssimonb	.align 4
5318b2f7e6Ssimonb	sync
5418b2f7e6Ssimonb	ba	wdoghandler
5518b2f7e6Ssimonb_C_LABEL(pitfitwdogsize) = .-_C_LABEL(pitfitwdog)
5618b2f7e6Ssimonb
5718b2f7e6Ssimonbpithandler:
58fd255ae5Srin	IBM405_ERRATA77_SYNC
5918b2f7e6Ssimonb	rfi
6018b2f7e6Ssimonb	ba	.	/* Protect against prefetch */
6118b2f7e6Ssimonb
6218b2f7e6Ssimonbwdoghandler:
63fd255ae5Srin	IBM405_ERRATA77_SYNC
6418b2f7e6Ssimonb	rfi
6518b2f7e6Ssimonb	ba	.	/* Protect against prefetch */
6618b2f7e6Ssimonb
67b8ea2c8cSmatt#define	TLBSTK	0x1000
68b8ea2c8cSmatt	.lcomm	tlbstack,TLBSTK,4
69b8ea2c8cSmatt	.type	tlbstack,@object
7018b2f7e6Ssimonb
71b8ea2c8cSmatt	.text
7218b2f7e6Ssimonb/* If an unaligned excception (0x600) and DTLB miss exception (0x1100)
7318b2f7e6Ssimonb   occur at the same time, the interrupt vector offsets of the two
7418b2f7e6Ssimonb   exceptions are logically OR'ed together to produce 0x1700.
7518b2f7e6Ssimonb   See PPC405GP Rev D/E Errata item 51 */
7618b2f7e6Ssimonb
7718b2f7e6Ssimonb	.globl _C_LABEL(errata51handler),_C_LABEL(errata51size)
7818b2f7e6Ssimonb_C_LABEL(errata51handler):
7918b2f7e6Ssimonb	ba	0x1100
8018b2f7e6Ssimonb_C_LABEL(errata51size) = .-_C_LABEL(errata51handler)
8118b2f7e6Ssimonb
8218b2f7e6Ssimonb	.globl _C_LABEL(tlbdmiss4xx),_C_LABEL(tlbdm4size)
8318b2f7e6Ssimonb_C_LABEL(tlbdmiss4xx):
84b8ea2c8cSmatt	ACCESS_PROLOG(CI_TLBMISSSAVE)
8518b2f7e6Ssimonb	bla	s4xx_miss
8618b2f7e6Ssimonb_C_LABEL(tlbdm4size) = .-_C_LABEL(tlbdmiss4xx)
8718b2f7e6Ssimonb
8818b2f7e6Ssimonb	.globl _C_LABEL(tlbimiss4xx),_C_LABEL(tlbim4size)
8918b2f7e6Ssimonb_C_LABEL(tlbimiss4xx):
90b8ea2c8cSmatt	ACCESS_PROLOG(CI_TLBMISSSAVE)
9118b2f7e6Ssimonb	bla	s4xx_miss
9244b1e07eShannken_C_LABEL(tlbim4size) = .-_C_LABEL(tlbimiss4xx)
9318b2f7e6Ssimonb
9418b2f7e6Ssimonbs4xx_miss:
9518b2f7e6Ssimonb	.globl	_C_LABEL(pmap_tlbmiss)
9618b2f7e6Ssimonb
9718b2f7e6Ssimonb	/* If the kernel stack would fault, don't use it. */
98*5cc603a5Srin	mfspr	%r30,SPR_PID
99f77f1feeSeeh	li	%r31,KERNEL_PID
100*5cc603a5Srin	mtspr	SPR_PID,%r31
101f77f1feeSeeh	li	%r31,-FRAMELEN
102f77f1feeSeeh	tlbsx.	%r31,%r31,%r1
103*5cc603a5Srin	mtspr	SPR_PID,%r30
10418b2f7e6Ssimonb	beq	1f
10518b2f7e6Ssimonb
10618b2f7e6Ssimonb	/*
107b8ea2c8cSmatt	 * The kernel stack we want to switch to is not in the TLB.
10818b2f7e6Ssimonb	 * To solve this problem, we will simulate a kernel
10918b2f7e6Ssimonb	 * fault on the kernel stack and let the miss handler
11018b2f7e6Ssimonb	 * bring it in, and return from the trap handler.  The
11118b2f7e6Ssimonb	 * processor will immediately take the original fault,
11218b2f7e6Ssimonb	 * which we should be able to handle with the now-valid
11318b2f7e6Ssimonb	 * kernel stack.
11418b2f7e6Ssimonb	 */
11518b2f7e6Ssimonb
11618b2f7e6Ssimonb	/* Switch to tlbstack */
117f77f1feeSeeh	addi	%r30,%r1,-FRAMELEN
118b8ea2c8cSmatt	lis	%r1,tlbstack+TLBSTK-CALLFRAMELEN@ha
119b8ea2c8cSmatt	addi	%r1,%r1,tlbstack+TLBSTK-CALLFRAMELEN@l
120b8ea2c8cSmatt	stw	%r30,0(%r1)
12118b2f7e6Ssimonb
122b8ea2c8cSmatt	FRAME_SETUP(CI_TLBMISSSAVE)
12318b2f7e6Ssimonb
12418b2f7e6Ssimonb	/* Take an explicit fault at (kernelstack,pid) */
125b8ea2c8cSmatt	lwz	%r3,FRAMELEN(%r1)
126f77f1feeSeeh	li	%r4,KERNEL_PID
12718b2f7e6Ssimonb	bl	_C_LABEL(pmap_tlbmiss)
12818b2f7e6Ssimonb	/*
12918b2f7e6Ssimonb	 * We can retry the old fault or switch stacks and
13018b2f7e6Ssimonb	 * take it now.  It's easier to retry.
13118b2f7e6Ssimonb	 */
132f77f1feeSeeh	mr.	%r3,%r3
133b8ea2c8cSmatt	beq	trapexit
13418b2f7e6Ssimonb
13518b2f7e6Ssimonb	/* kernel stack not in the pmap? we should panic */
13618b2f7e6Ssimonb	trap
137b8ea2c8cSmatt	b	trapagain
13818b2f7e6Ssimonb1:
139b8ea2c8cSmatt	FRAME_SETUP(CI_TLBMISSSAVE)
14024f1286eSkiyohara	li	%r3,EXC_DTMISS
14124f1286eSkiyohara	lwz	%r4,FRAME_EXC(%r1)
14224f1286eSkiyohara	cmpw	%r3,%r4
143b8ea2c8cSmatt	lwz	%r3,FRAME_DEAR(%r1)
14424f1286eSkiyohara	beq	2f
14524f1286eSkiyohara	lwz	%r3,FRAME_SRR0(%r1) /* ITMISS case, TLB miss address in SRR0 */
14624f1286eSkiyohara2:
147b8ea2c8cSmatt	lwz	%r4,FRAME_PID(%r1)
14818b2f7e6Ssimonb	bl	_C_LABEL(pmap_tlbmiss)
149f77f1feeSeeh	mr.	%r3,%r3
150b8ea2c8cSmatt	beq	trapexit
15118b2f7e6Ssimonb
15218b2f7e6Ssimonb	/* XXX DEBUG -- make sure we're not on tlbstack */
153b8ea2c8cSmatt	lis	%r3,tlbstack@ha
154b8ea2c8cSmatt	addi	%r3,%r3,tlbstack@l
155b8ea2c8cSmatt	sub	%r7,%r1,%r3
156b8ea2c8cSmatt	twllei	%r7,TLBSTK
15718b2f7e6Ssimonb
15818b2f7e6Ssimonb	/* PTE not found, time to cause a fault */
159b8ea2c8cSmatt	b	trapagain
160