exception_vector.S revision 1.22
11.22Suwe/*	$NetBSD: exception_vector.S,v 1.22 2007/03/15 00:00:38 uwe Exp $	*/
21.1Such
31.1Such/*-
41.1Such * Copyright (c) 2002 The NetBSD Foundation, Inc.
51.1Such * All rights reserved.
61.1Such *
71.1Such * Redistribution and use in source and binary forms, with or without
81.1Such * modification, are permitted provided that the following conditions
91.1Such * are met:
101.1Such * 1. Redistributions of source code must retain the above copyright
111.1Such *    notice, this list of conditions and the following disclaimer.
121.1Such * 2. Redistributions in binary form must reproduce the above copyright
131.1Such *    notice, this list of conditions and the following disclaimer in the
141.1Such *    documentation and/or other materials provided with the distribution.
151.1Such * 3. All advertising materials mentioning features or use of this software
161.1Such *    must display the following acknowledgement:
171.1Such *        This product includes software developed by the NetBSD
181.1Such *        Foundation, Inc. and its contributors.
191.1Such * 4. Neither the name of The NetBSD Foundation nor the names of its
201.1Such *    contributors may be used to endorse or promote products derived
211.1Such *    from this software without specific prior written permission.
221.1Such *
231.1Such * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
241.1Such * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
251.1Such * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
261.1Such * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
271.1Such * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
281.1Such * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
291.1Such * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
301.1Such * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
311.1Such * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
321.1Such * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
331.1Such * POSSIBILITY OF SUCH DAMAGE.
341.1Such */
351.1Such
361.9Such#include "opt_cputype.h"
371.9Such#include "opt_ddb.h"
381.1Such#include "assym.h"
391.7Such
401.3Such#include <sh3/param.h>
411.1Such#include <sh3/asm.h>
421.1Such#include <sh3/locore.h>
431.8Such#include <sh3/exception.h>
441.2Such#include <sh3/ubcreg.h>
451.3Such#include <sh3/mmu_sh3.h>
461.3Such#include <sh3/mmu_sh4.h>
471.12Suwe
481.22Suwe__KERNEL_RCSID(0, "$NetBSD: exception_vector.S,v 1.22 2007/03/15 00:00:38 uwe Exp $")
491.12Suwe
501.1Such
511.1Such/*
521.22Suwe * Exception vectors.
531.22Suwe * The following routines are copied to vector addresses.
541.8Such *	sh_vector_generic:	VBR + 0x100
551.9Such *	sh_vector_tlbmiss:	VBR + 0x400
561.1Such *	sh_vector_interrupt:	VBR + 0x600
571.8Such */
581.8Such
591.15Suwe#define VECTOR_END_MARKER(sym)			\
601.15Suwe		.globl	_C_LABEL(sym);		\
611.15Suwe	_C_LABEL(sym):
621.15Suwe
631.15Suwe
641.1Such/*
651.15Suwe * LINTSTUB: Var: char sh_vector_generic[1];
661.15Suwe *
671.22Suwe * void sh_vector_generic(void);
681.15Suwe *	Copied to VBR+0x100.  This code should be position independent
691.22Suwe *	and maximum 786 bytes long (== 0x400 - 0x100).
701.8Such */
711.15SuweNENTRY(sh_vector_generic)
721.5Such	__EXCEPTION_ENTRY
731.9Such	__INTR_MASK(r0, r1)
741.1Such	/* Identify exception cause */
751.1Such	MOV	(EXPEVT, r0)
761.21Suwe	mov.l	@r0, r0
771.22Suwe	mov.l	r0, @(TF_EXPEVT, r14)	/* tf->tf_expevt = EXPEVT */
781.10Sthorpej	/* Get curlwp */
791.22Suwe	mov.l	.Lg_curlwp, r1
801.21Suwe	mov.l	@r1, r4			/* 1st arg */
811.11Suwe	/* Get TEA */
821.21Suwe	MOV	(TEA, r1)
831.21Suwe	mov.l	@r1, r6			/* 3rd arg */
841.9Such	/* Check TLB exception or not */
851.22Suwe	mov.l	.Lg_TLB_PROT_ST, r1
861.21Suwe	cmp/hi	r1, r0
871.9Such	bt	1f
881.11Suwe
891.22Suwe	/* tlb_exception(curlwp, tf, TEA); */
901.2Such	__EXCEPTION_UNBLOCK(r0, r1)
911.22Suwe	mov.l	.Lg_tlb_exception, r0
921.1Such	jsr	@r0
931.21Suwe	 mov	r14, r5			/* 2nd arg */
941.9Such	bra	2f
951.1Such	 nop
961.11Suwe
971.22Suwe	/* general_exception(curlwp, tf, TEA); */
981.21Suwe1:	mov	r4, r8
991.1Such#ifdef DDB
1001.21Suwe	mov	#0, r2
1011.1Such	MOV	(BBRA, r1)
1021.21Suwe	mov.w	r2, @r1			/* disable UBC */
1031.22Suwe	mov.l	r2, @(TF_UBC, r14)	/* clear tf->tf_ubc */
1041.1Such#endif /* DDB */
1051.2Such	__EXCEPTION_UNBLOCK(r0, r1)
1061.22Suwe	mov.l	.Lg_general_exception, r0
1071.1Such	jsr	@r0
1081.21Suwe	 mov	r14, r5			/* 2nd arg */
1091.1Such
1101.1Such	/* Check for ASTs on exit to user mode. */
1111.21Suwe	mov	r8, r4
1121.22Suwe	mov.l	.Lg_ast, r0
1131.1Such	jsr	@r0
1141.21Suwe	 mov	r14, r5
1151.22Suwe#ifdef DDB	/* BBRA = tf->tf_ubc */
1161.2Such	__EXCEPTION_BLOCK(r0, r1)
1171.3Such	mov.l	@(TF_UBC, r14), r0
1181.1Such	MOV	(BBRA, r1)
1191.21Suwe	mov.w	r0, @r1
1201.1Such#endif /* DDB */
1211.9Such2:	__EXCEPTION_RETURN
1221.22Suwe
1231.1Such	.align	2
1241.22Suwe.Lg_curlwp:		.long	_C_LABEL(curlwp)
1251.1SuchREG_SYMBOL(EXPEVT)
1261.1SuchREG_SYMBOL(BBRA)
1271.9SuchREG_SYMBOL(TEA)
1281.22Suwe.Lg_tlb_exception:	.long	_C_LABEL(tlb_exception)
1291.22Suwe.Lg_general_exception:	.long	_C_LABEL(general_exception)
1301.22Suwe.Lg_ast:		.long	_C_LABEL(ast)
1311.22Suwe.Lg_TLB_PROT_ST:	.long	EXPEVT_TLB_PROT_ST
1321.15Suwe
1331.15Suwe/* LINTSTUB: Var: char sh_vector_generic_end[1]; */
1341.15SuweVECTOR_END_MARKER(sh_vector_generic_end)
1351.15Suwe	SET_ENTRY_SIZE(sh_vector_generic)
1361.15Suwe
1371.8Such
1381.3Such#ifdef SH3
1391.8Such/*
1401.15Suwe * LINTSTUB: Var: char sh3_vector_tlbmiss[1];
1411.15Suwe *
1421.22Suwe * void sh3_vector_tlbmiss(void);
1431.15Suwe *	Copied to VBR+0x400.  This code should be position independent
1441.22Suwe *	and maximum 512 bytes long (== 0x600 - 0x400).
1451.1Such */
1461.15SuweNENTRY(sh3_vector_tlbmiss)
1471.8Such	__EXCEPTION_ENTRY
1481.17Suwe	mov	#(SH3_TEA & 0xff), r0
1491.21Suwe	mov.l	@r0, r6		/* 3rd arg: va = TEA */
1501.3Such#if !defined(P1_STACK)
1511.4Such	/* Load kernel stack */
1521.22Suwe	mov.l	.L3_VPN_MASK, r0
1531.21Suwe	and	r6, r0
1541.21Suwe	tst	r0, r0		/* check VPN == 0 */
1551.9Such	bt	6f
1561.22Suwe	mov.l	.L3_CURUPTE, r1
1571.21Suwe	mov.l	@r1, r1
1581.21Suwe	mov	#UPAGES, r3
1591.21Suwe	mov	#1, r2
1601.21Suwe4:	mov.l	@r1+, r7
1611.21Suwe	cmp/eq	r7, r0		/* md_upte.addr: u-area VPN */
1621.3Such	bt	5f
1631.21Suwe	add	#4, r1		/* skip md_upte.data */
1641.21Suwe	cmp/eq	r2, r3
1651.3Such	bf/s	4b
1661.21Suwe	 add	#1, r2
1671.18Suwe	bra	7f		/* pull insn at 6f into delay slot */
1681.18Suwe	 mov	#(SH3_EXPEVT & 0xff), r0
1691.21Suwe5:	mov.l	@r1, r2		/* md_upte.data: u-area PTE */
1701.17Suwe	mov	#(SH3_PTEL & 0xff), r1
1711.21Suwe	mov.l	r2, @r1
1721.17Suwe	mov	#(SH3_PTEH & 0xff), r1
1731.21Suwe	mov.l	@r1, r2
1741.22Suwe	mov.l	.L3_VPN_MASK, r0
1751.21Suwe	and	r2, r0
1761.21Suwe	mov.l	r0, @r1		/* ASID 0 */
1771.3Such	ldtlb
1781.3Such	bra	3f
1791.21Suwe	 mov.l	r2, @r1		/* restore ASID */
1801.3Such#endif /* !P1_STACK */
1811.17Suwe6:	mov	#(SH3_EXPEVT & 0xff), r0
1821.21Suwe7:	mov.l	@r0, r0
1831.22Suwe	mov.l	r0, @(TF_EXPEVT, r14)	/* tf->tf_expevt = EXPEVT */
1841.22Suwe	mov.l	.L3_curlwp, r0
1851.21Suwe	mov.l	@r0, r4		/* 1st arg */
1861.9Such	__INTR_MASK(r0, r1)
1871.9Such	__EXCEPTION_UNBLOCK(r0, r1)
1881.22Suwe	mov.l	.L3_tlb_exception, r0
1891.1Such	jsr	@r0
1901.21Suwe	 mov	r14, r5		/* 2nd arg */
1911.9Such3:	__EXCEPTION_RETURN
1921.22Suwe
1931.3Such	.align	2
1941.22Suwe.L3_curlwp:		.long	_C_LABEL(curlwp)
1951.22Suwe.L3_tlb_exception:	.long	_C_LABEL(tlb_exception)
1961.22Suwe.L3_VPN_MASK:		.long	0xfffff000
1971.22Suwe.L3_CURUPTE:		.long	_C_LABEL(curupte)
1981.15Suwe
1991.15Suwe/* LINTSTUB: Var: char sh3_vector_tlbmiss_end[1]; */
2001.15SuweVECTOR_END_MARKER(sh3_vector_tlbmiss_end)
2011.15Suwe	SET_ENTRY_SIZE(sh3_vector_tlbmiss)
2021.3Such#endif /* SH3 */
2031.3Such
2041.15Suwe
2051.3Such#ifdef SH4
2061.8Such/*
2071.15Suwe * LINTSTUB: Var: char sh4_vector_tlbmiss[1];
2081.15Suwe *
2091.22Suwe * void sh4_vector_tlbmiss(void);
2101.15Suwe *	Copied to VBR+0x400.  This code should be position independent
2111.22Suwe *	and maximum 512 bytes long (== 0x600 - 0x400).
2121.3Such */
2131.15SuweNENTRY(sh4_vector_tlbmiss)
2141.8Such	__EXCEPTION_ENTRY
2151.22Suwe	mov.l	.L4_TEA4, r0
2161.21Suwe	mov.l	@r0, r6
2171.22Suwe	mov.l	.L4_EXPEVT4, r0
2181.21Suwe	mov.l	@r0, r0
2191.22Suwe	mov.l	r0, @(TF_EXPEVT, r14)	/* tf->tf_expevt = EXPEVT */
2201.22Suwe	mov.l	.L4_curlwp, r0
2211.21Suwe	mov.l	@r0, r4			/* 1st arg */
2221.3Such	__INTR_MASK(r0, r1)
2231.3Such	__EXCEPTION_UNBLOCK(r0, r1)
2241.22Suwe	mov.l	.L4_tlb_exception, r0
2251.3Such	jsr	@r0
2261.21Suwe	 mov	r14, r5			/* 2nd arg */
2271.5Such	__EXCEPTION_RETURN
2281.22Suwe
2291.1Such	.align	2
2301.22Suwe.L4_tlb_exception:	.long	_C_LABEL(tlb_exception)
2311.22Suwe.L4_curlwp:		.long	_C_LABEL(curlwp)
2321.22Suwe.L4_EXPEVT4:		.long	SH4_EXPEVT
2331.22Suwe.L4_TEA4:		.long	SH4_TEA
2341.15Suwe
2351.15Suwe/* LINTSTUB: Var: char sh4_vector_tlbmiss_end[1]; */
2361.15SuweVECTOR_END_MARKER(sh4_vector_tlbmiss_end)
2371.15Suwe	SET_ENTRY_SIZE(sh4_vector_tlbmiss)
2381.3Such#endif /* SH4 */
2391.1Such
2401.15Suwe
2411.1Such/*
2421.15Suwe * LINTSTUB: Var: char sh_vector_interrupt[1];
2431.15Suwe *
2441.22Suwe * void sh_vector_interrupt(void);
2451.22Suwe *	Copied to VBR+0x600.  This code should be position independent.
2461.8Such */
2471.15SuweNENTRY(sh_vector_interrupt)
2481.5Such	__EXCEPTION_ENTRY
2491.21Suwe	xor	r0, r0
2501.21Suwe	mov.l	r0, @(TF_EXPEVT, r14)	/* (for debug) */
2511.21Suwe	stc	r0_bank, r6		/* ssp */
2521.22Suwe	/* Enable exceptions for P3 access */
2531.5Such	__INTR_MASK(r0, r1)
2541.5Such	__EXCEPTION_UNBLOCK(r0, r1)
2551.22Suwe	/* ++uvmexp.intrs */
2561.22Suwe	mov.l	.Li_uvmexp_intrs, r0
2571.21Suwe	mov.l	@r0, r1
2581.21Suwe	add	#1 r1
2591.21Suwe	mov.l	r1, @r0
2601.5Such	/* Dispatch interrupt handler */
2611.22Suwe	mov.l	.Li_intc_intr, r0
2621.5Such	jsr	@r0		/* intc_intr(ssr, spc, ssp) */
2631.1Such	 nop
2641.5Such	/* Check for ASTs on exit to user mode. */
2651.22Suwe	mov.l	.Li_curlwp, r0
2661.21Suwe	mov.l	@r0, r4		/* 1st arg */
2671.22Suwe	mov.l	.Li_ast, r0
2681.5Such	jsr	@r0
2691.21Suwe	 mov	r14, r5		/* 2nd arg */
2701.5Such	__EXCEPTION_RETURN
2711.22Suwe
2721.1Such	.align	2
2731.22Suwe.Li_curlwp:		.long	_C_LABEL(curlwp)
2741.22Suwe.Li_intc_intr:		.long	_C_LABEL(intc_intr)
2751.22Suwe.Li_ast:		.long	_C_LABEL(ast)
2761.22Suwe.Li_uvmexp_intrs:	.long	_C_LABEL(uvmexp) + UVMEXP_INTRS
2771.15Suwe
2781.15Suwe/* LINTSTUB: Var: char sh_vector_interrupt_end[1]; */
2791.15SuweVECTOR_END_MARKER(sh_vector_interrupt_end)
2801.15Suwe	SET_ENTRY_SIZE(sh_vector_interrupt)
281