exception_vector.S revision 1.12
11.12Suwe/*	$NetBSD: exception_vector.S,v 1.12 2003/11/24 04:16:51 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.12Suwe__KERNEL_RCSID(0, "$NetBSD: exception_vector.S,v 1.12 2003/11/24 04:16:51 uwe Exp $")
491.12Suwe
501.1Such
511.1Such/*
521.1Such * Exception vectors. following routines are copied to vector addreses.
531.8Such *	sh_vector_generic:	VBR + 0x100
541.9Such *	sh_vector_tlbmiss:	VBR + 0x400
551.1Such *	sh_vector_interrupt:	VBR + 0x600
561.8Such */
571.8Such
581.1Such/*
591.8Such * void sh_vector_generic(void) __attribute__((__noreturn__)):
601.1Such *	copied to VBR+0x100. This code should be relocatable and max 384
611.8Such *	instructions.
621.8Such */
631.1Such	.globl	_C_LABEL(sh_vector_generic), _C_LABEL(sh_vector_generic_end)
641.8Such	.text
651.1Such	.align	2
661.1Such_C_LABEL(sh_vector_generic):
671.5Such	__EXCEPTION_ENTRY
681.9Such	__INTR_MASK(r0, r1)
691.1Such	/* Identify exception cause */
701.1Such	MOV	(EXPEVT, r0)
711.1Such	mov.l	@r0,	r0
721.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */
731.10Sthorpej	/* Get curlwp */
741.9Such	mov.l	3f,	r1
751.9Such	mov.l	@r1,	r4	/* 1st arg */
761.11Suwe	/* Get TEA */
771.11Suwe	MOV	(TEA,	r1)
781.11Suwe	mov.l	@r1,	r6	/* 3rd arg */
791.9Such	/* Check TLB exception or not */
801.9Such	mov.l	_L.TLB_PROT_ST, r1
811.9Such	cmp/hi	r1,	r0
821.9Such	bt	1f
831.11Suwe
841.11Suwe	/* tlb_exception(curlwp, trapframe, trunc_page(TEA)); */
851.9Such	mov.l	_L.VPN_MASK, r1
861.9Such	and	r1,	r6	/* va = trunc_page(va) */
871.2Such	__EXCEPTION_UNBLOCK(r0, r1)
881.9Such	mov.l	_L.tlb, r0
891.1Such	jsr	@r0
901.9Such	 mov	r14,	r5	/* 2nd arg */
911.9Such	bra	2f
921.1Such	 nop
931.11Suwe
941.11Suwe	/* general_exception(curlwp, trapframe, TEA); */
951.9Such1:	mov	r4,	r8
961.1Such#ifdef DDB
971.1Such	mov	#0,	r2
981.1Such	MOV	(BBRA, r1)
991.1Such	mov.w	r2,	@r1	/* disable UBC */
1001.3Such	mov.l	r2,	@(TF_UBC, r14)	/* clear trapframe->tf_ubc */
1011.1Such#endif /* DDB */
1021.2Such	__EXCEPTION_UNBLOCK(r0, r1)
1031.9Such	mov.l	_L.general, r0
1041.1Such	jsr	@r0
1051.11Suwe	 mov	r14,	r5	/* 2nd arg */
1061.1Such
1071.1Such	/* Check for ASTs on exit to user mode. */
1081.9Such	mov	r8,	r4
1091.1Such	mov.l	_L.ast,	r0
1101.1Such	jsr	@r0
1111.9Such	 mov	r14,	r5
1121.8Such#ifdef DDB	/* BBRA = trapframe->tf_ubc */
1131.2Such	__EXCEPTION_BLOCK(r0, r1)
1141.3Such	mov.l	@(TF_UBC, r14), r0
1151.1Such	MOV	(BBRA, r1)
1161.1Such	mov.w	r0,	@r1
1171.1Such#endif /* DDB */
1181.9Such2:	__EXCEPTION_RETURN
1191.1Such	/* NOTREACHED */
1201.1Such	.align	2
1211.10Sthorpej3:		.long	_C_LABEL(curlwp)
1221.1SuchREG_SYMBOL(EXPEVT)
1231.1SuchREG_SYMBOL(BBRA)
1241.9SuchREG_SYMBOL(TEA)
1251.9Such_L.tlb:		.long	_C_LABEL(tlb_exception)
1261.9Such_L.general:	.long	_C_LABEL(general_exception)
1271.1Such_L.ast:		.long	_C_LABEL(ast)
1281.9Such_L.TLB_PROT_ST:	.long	0xc0
1291.9Such_L.VPN_MASK:	.long	0xfffff000
1301.3Such_C_LABEL(sh_vector_generic_end):	.long	0
1311.8Such
1321.3Such#ifdef SH3
1331.8Such/*
1341.8Such * void sh3_vector_tlbmiss(void) __attribute__((__noreturn__)):
1351.1Such *	copied to VBR+0x400. This code should be relocatable and max 256
1361.1Such *	instructions.
1371.1Such */
1381.3Such	.globl	_C_LABEL(sh3_vector_tlbmiss), _C_LABEL(sh3_vector_tlbmiss_end)
1391.8Such	.text
1401.3Such	.align	2
1411.3Such_C_LABEL(sh3_vector_tlbmiss):
1421.8Such	__EXCEPTION_ENTRY
1431.9Such	mov.l	_L.TEA3, r0
1441.9Such	mov.l	@r0,	r6
1451.9Such	mov.l	__L.VPN_MASK, r1
1461.9Such	and	r1,	r6	/* 3rd arg */
1471.3Such#if !defined(P1_STACK)
1481.4Such	/* Load kernel stack */
1491.9Such	tst	r6,	r6	/* check VPN == 0 */
1501.9Such	bt	6f
1511.3Such	mov.l	_L.CURUPTE, r1
1521.9Such	mov.l	@r1,	r1
1531.3Such	mov	#UPAGES,r3
1541.3Such	mov	#1,	r2
1551.9Such4:	mov.l	@r1+,	r7
1561.9Such	cmp/eq	r7,	r6	/* md_upte.addr: u-area VPN */
1571.3Such	bt	5f
1581.3Such	add	#4,	r1	/* skip md_upte.data */
1591.3Such	cmp/eq	r2,	r3
1601.3Such	bf/s	4b
1611.8Such	 add	#1,	r2
1621.3Such	bra	6f
1631.3Such	 nop
1641.3Such5:	mov.l	@r1,	r2	/* md_upte.data: u-area PTE */
1651.3Such	mov.l	_L.PTEL, r1
1661.3Such	mov.l	r2,	@r1
1671.9Such	mov.l	_L.PTEH, r1
1681.9Such	mov.l	@r1,	r2
1691.9Such	mov.l	__L.VPN_MASK, r0
1701.9Such	and	r2,	r0
1711.9Such	mov.l	r0,	@r1	/* ASID 0 */
1721.3Such	ldtlb
1731.9Such	mov.l	r2,	@r1	/* restore ASID */
1741.3Such	bra	3f
1751.3Such	 nop
1761.3Such#endif /* !P1_STACK */
1771.9Such6:	mov.l	_L.EXPEVT3, r0
1781.9Such	mov.l	@r0,	r0
1791.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */
1801.9Such	mov.l	2f,	r0
1811.9Such	mov.l	@r0,	r4	/* 1st arg */
1821.9Such	__INTR_MASK(r0, r1)
1831.9Such	__EXCEPTION_UNBLOCK(r0, r1)
1841.1Such	mov.l	1f,	r0
1851.1Such	jsr	@r0
1861.9Such	 mov	r14,	r5	/* 2nd arg */
1871.9Such3:	__EXCEPTION_RETURN
1881.3Such	.align	2
1891.10Sthorpej2:		.long	_C_LABEL(curlwp)
1901.9Such1:		.long	_C_LABEL(tlb_exception)
1911.9Such_L.EXPEVT3:	.long	SH3_EXPEVT
1921.9Such_L.TEA3:	.long	SH3_TEA
1931.3Such_L.PTEL:	.long	SH3_PTEL
1941.9Such_L.PTEH:	.long	SH3_PTEH
1951.9Such__L.VPN_MASK:	.long	0xfffff000
1961.3Such_L.CURUPTE:	.long	_C_LABEL(curupte)
1971.3Such	.align	2
1981.3Such_C_LABEL(sh3_vector_tlbmiss_end):	.long	0
1991.3Such#endif /* SH3 */
2001.3Such
2011.3Such#ifdef SH4
2021.8Such/*
2031.8Such * void sh4_vector_tlbmiss(void) __attribute__((__noreturn__)):
2041.3Such *	copied to VBR+0x400. This code should be relocatable and max 256
2051.3Such *	instructions.
2061.3Such */
2071.3Such	.globl	_C_LABEL(sh4_vector_tlbmiss), _C_LABEL(sh4_vector_tlbmiss_end)
2081.8Such	.text
2091.3Such	.align	2
2101.3Such_C_LABEL(sh4_vector_tlbmiss):
2111.8Such	__EXCEPTION_ENTRY
2121.9Such	mov.l	_L.TEA4, r0
2131.9Such	mov.l	@r0,	r6
2141.9Such	mov.l	___L.VPN_MASK, r1
2151.9Such	and	r1,	r6	/* va = trunc_page(va) */
2161.9Such	mov.l	_L.EXPEVT4, r0
2171.9Such	mov.l	@r0,	r0
2181.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */
2191.9Such	mov.l	2f,	r0
2201.9Such	mov.l	@r0,	r4	/* 1st arg */
2211.3Such	__INTR_MASK(r0, r1)
2221.3Such	__EXCEPTION_UNBLOCK(r0, r1)
2231.3Such	mov.l	1f,	r0
2241.3Such	jsr	@r0
2251.9Such	 mov	r14,	r5	/* 2nd arg */
2261.5Such	__EXCEPTION_RETURN
2271.1Such	.align	2
2281.9Such1:		.long	_C_LABEL(tlb_exception)
2291.10Sthorpej2:		.long	_C_LABEL(curlwp)
2301.9Such_L.EXPEVT4:	.long	SH4_EXPEVT
2311.9Such_L.TEA4:	.long	SH4_TEA
2321.9Such___L.VPN_MASK:	.long	0xfffff000
2331.3Such_C_LABEL(sh4_vector_tlbmiss_end):	.long	0
2341.3Such#endif /* SH4 */
2351.1Such
2361.1Such/*
2371.8Such * void sh_vector_interrupt(void) __attribute__((__noreturn__)):
2381.1Such *	copied to VBR+0x600. This code should be relocatable.
2391.8Such */
2401.1Such	.globl	_C_LABEL(sh_vector_interrupt), _C_LABEL(sh_vector_interrupt_end)
2411.1Such	.align	2
2421.3Such	.text
2431.1Such_C_LABEL(sh_vector_interrupt):
2441.5Such	__EXCEPTION_ENTRY
2451.9Such	xor	r0,	r0
2461.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* (for debug) */
2471.8Such	stc	r0_bank,r6	/* ssp */
2481.5Such	/* Enable exception for P3 access */
2491.5Such	__INTR_MASK(r0, r1)
2501.5Such	__EXCEPTION_UNBLOCK(r0, r1)
2511.6Such	/* uvmexp.intrs++ */
2521.6Such	mov.l	__L.uvmexp.intrs, r0
2531.6Such	mov.l	@r0,	r1
2541.6Such	add	#1	r1
2551.6Such	mov.l	r1,	@r0
2561.5Such	/* Dispatch interrupt handler */
2571.6Such	mov.l	__L.intc_intr, r0
2581.5Such	jsr	@r0		/* intc_intr(ssr, spc, ssp) */
2591.1Such	 nop
2601.5Such	/* Check for ASTs on exit to user mode. */
2611.9Such	mov.l	1f,	r0
2621.9Such	mov.l	@r0,	r4	/* 1st arg */
2631.6Such	mov.l	__L.ast, r0
2641.5Such	jsr	@r0
2651.9Such	 mov	r14,	r5	/* 2nd arg */
2661.5Such	__EXCEPTION_RETURN
2671.1Such	.align	2
2681.10Sthorpej1:			.long	_C_LABEL(curlwp)
2691.8Such__L.intc_intr:		.long	_C_LABEL(intc_intr)
2701.8Such__L.ast:		.long	_C_LABEL(ast)
2711.6Such__L.uvmexp.intrs:	.long	_C_LABEL(uvmexp) + UVMEXP_INTRS
2721.3Such_C_LABEL(sh_vector_interrupt_end):	.long	0
273