/* $NetBSD: trap_subr.S,v 1.30 2022/09/12 08:02:44 rin Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
* Copyright (C) 1995, 1996 TooLs GmbH.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* NOTICE: This is not a standalone file. to use it, #include it in
* your port's locore.S, like so:
*
* #include <powerpc/ibm4xx/trap_subr.S>
*/
/*
* This one for the external interrupt handler.
*/
.globl _C_LABEL(extint),_C_LABEL(extsize)
_C_LABEL(extint):
INTR_PROLOG(CI_TEMPSAVE)
ba extintr
_C_LABEL(extsize) = .-_C_LABEL(extint)
#if defined(DDB) || defined(KGDB)
/*
* In case of DDB we want a separate trap catcher for it
*/
.globl _C_LABEL(ddblow),_C_LABEL(ddbsize)
_C_LABEL(ddblow):
ACCESS_PROLOG(CI_DDBSAVE)
bla ddbtrap
_C_LABEL(ddbsize) = .-_C_LABEL(ddblow)
#endif /* DDB || KGDB */
intrleave_to_kernel:
FRAME_RESTORE /* old SP is now in sprg1 */
mtsprg2 %r30
mtsprg3 %r31
mfmsr %r30
li %r31,(PSL_DR|PSL_IR)@l
andc %r30,%r30,%r31
lwz %r31,FRAME_PID(%r1)
TRAP_IF_ZERO(%r31)
/*
* Now that we are done with the trapframe, we can load the original SP
*/
mfsprg1 %r1
mtmsr %r30 /* disable translation */
isync
mtspr SPR_PID,%r31
mfsprg3 %r31
mfsprg2 %r30
IBM405_ERRATA77_SYNC
rfi
ba . /* Protect against prefetch */
/*
* We are returning to userspace so we need to switch PIDs.
* Since the kernel executes out of what would be userspace,
* we need to turn off translation before we set the PID.
*
* Alterantively, we could map a kernel page at 0xfffff000
* that had the mtpid code in it and branch to it and avoid
* all this. (ba foo; foo: mtpid %r31; mfsprg3 %r31; rfi;)
*/
mtsprg2 %r30
mtsprg3 %r31
mfmsr %r30
li %r31,(PSL_DR|PSL_IR)@l
andc %r30,%r30,%r31
lwz %r31,FRAME_PID(%r1)
TRAP_IF_ZERO(%r31)
/*
* Now that we are done with the trapframe, we can load the original SP
*/
mfsprg1 %r1
mtmsr %r30 /* disable translation */
isync
mtspr SPR_PID,%r31
mfsprg3 %r31
mfsprg2 %r30
IBM405_ERRATA77_SYNC
rfi
ba . /* Protect against prefetch */
.globl _C_LABEL(sctrap),_C_LABEL(scsize),_C_LABEL(sctrapexit)
_C_LABEL(sctrap):
STANDARD_PROLOG(CI_TEMPSAVE)
bla s_sctrap
_C_LABEL(scsize) = .-_C_LABEL(sctrap)
s_sctrap:
FRAME_SETUP(CI_TEMPSAVE)
/* Now we can recover interrupts again: */
wrteei 1 /* Enable interrupts */
/* Call the appropriate syscall handler: */
addi %r3,%r1,FRAME_TF
lwz %r4,L_PROC(%r13)
lwz %r4,P_MD_SYSCALL(%r4)
mtctr %r4
bctrl
_C_LABEL(sctrapexit):
b trapexit
lwz %r4,FRAME_SRR1(%r1)
/* Returning to user mode? */
mtcr %r4 /* saved SRR1 */
bf MSR_PR,intrleave_to_kernel /* branch if MSR[PR] is false */
lwz %r4,L_MD_ASTPENDING(%r13)/* Test AST pending */
andi. %r4,%r4,1
beq intrleave_to_user
FRAME_SAVE_CALLEE /* save rest of callee registers */
li %r6,EXC_AST
stw %r6,FRAME_EXC(%r1)
lwz %r31,FRAME_SRR1(%r1) /* move SRR1 to R31 */
b trapagain