exception_vector.S revision 1.11
11.11Suwe/*	$NetBSD: exception_vector.S,v 1.11 2003/11/24 03:06:01 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.1Such
481.1Such/*
491.1Such * Exception vectors. following routines are copied to vector addreses.
501.8Such *	sh_vector_generic:	VBR + 0x100
511.9Such *	sh_vector_tlbmiss:	VBR + 0x400
521.1Such *	sh_vector_interrupt:	VBR + 0x600
531.8Such */
541.8Such
551.1Such/*
561.8Such * void sh_vector_generic(void) __attribute__((__noreturn__)):
571.1Such *	copied to VBR+0x100. This code should be relocatable and max 384
581.8Such *	instructions.
591.8Such */
601.1Such	.globl	_C_LABEL(sh_vector_generic), _C_LABEL(sh_vector_generic_end)
611.8Such	.text
621.1Such	.align	2
631.1Such_C_LABEL(sh_vector_generic):
641.5Such	__EXCEPTION_ENTRY
651.9Such	__INTR_MASK(r0, r1)
661.1Such	/* Identify exception cause */
671.1Such	MOV	(EXPEVT, r0)
681.1Such	mov.l	@r0,	r0
691.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */
701.10Sthorpej	/* Get curlwp */
711.9Such	mov.l	3f,	r1
721.9Such	mov.l	@r1,	r4	/* 1st arg */
731.11Suwe	/* Get TEA */
741.11Suwe	MOV	(TEA,	r1)
751.11Suwe	mov.l	@r1,	r6	/* 3rd arg */
761.9Such	/* Check TLB exception or not */
771.9Such	mov.l	_L.TLB_PROT_ST, r1
781.9Such	cmp/hi	r1,	r0
791.9Such	bt	1f
801.11Suwe
811.11Suwe	/* tlb_exception(curlwp, trapframe, trunc_page(TEA)); */
821.9Such	mov.l	_L.VPN_MASK, r1
831.9Such	and	r1,	r6	/* va = trunc_page(va) */
841.2Such	__EXCEPTION_UNBLOCK(r0, r1)
851.9Such	mov.l	_L.tlb, r0
861.1Such	jsr	@r0
871.9Such	 mov	r14,	r5	/* 2nd arg */
881.9Such	bra	2f
891.1Such	 nop
901.11Suwe
911.11Suwe	/* general_exception(curlwp, trapframe, TEA); */
921.9Such1:	mov	r4,	r8
931.1Such#ifdef DDB
941.1Such	mov	#0,	r2
951.1Such	MOV	(BBRA, r1)
961.1Such	mov.w	r2,	@r1	/* disable UBC */
971.3Such	mov.l	r2,	@(TF_UBC, r14)	/* clear trapframe->tf_ubc */
981.1Such#endif /* DDB */
991.2Such	__EXCEPTION_UNBLOCK(r0, r1)
1001.9Such	mov.l	_L.general, r0
1011.1Such	jsr	@r0
1021.11Suwe	 mov	r14,	r5	/* 2nd arg */
1031.1Such
1041.1Such	/* Check for ASTs on exit to user mode. */
1051.9Such	mov	r8,	r4
1061.1Such	mov.l	_L.ast,	r0
1071.1Such	jsr	@r0
1081.9Such	 mov	r14,	r5
1091.8Such#ifdef DDB	/* BBRA = trapframe->tf_ubc */
1101.2Such	__EXCEPTION_BLOCK(r0, r1)
1111.3Such	mov.l	@(TF_UBC, r14), r0
1121.1Such	MOV	(BBRA, r1)
1131.1Such	mov.w	r0,	@r1
1141.1Such#endif /* DDB */
1151.9Such2:	__EXCEPTION_RETURN
1161.1Such	/* NOTREACHED */
1171.1Such	.align	2
1181.10Sthorpej3:		.long	_C_LABEL(curlwp)
1191.1SuchREG_SYMBOL(EXPEVT)
1201.1SuchREG_SYMBOL(BBRA)
1211.9SuchREG_SYMBOL(TEA)
1221.9Such_L.tlb:		.long	_C_LABEL(tlb_exception)
1231.9Such_L.general:	.long	_C_LABEL(general_exception)
1241.1Such_L.ast:		.long	_C_LABEL(ast)
1251.9Such_L.TLB_PROT_ST:	.long	0xc0
1261.9Such_L.VPN_MASK:	.long	0xfffff000
1271.3Such_C_LABEL(sh_vector_generic_end):	.long	0
1281.8Such
1291.3Such#ifdef SH3
1301.8Such/*
1311.8Such * void sh3_vector_tlbmiss(void) __attribute__((__noreturn__)):
1321.1Such *	copied to VBR+0x400. This code should be relocatable and max 256
1331.1Such *	instructions.
1341.1Such */
1351.3Such	.globl	_C_LABEL(sh3_vector_tlbmiss), _C_LABEL(sh3_vector_tlbmiss_end)
1361.8Such	.text
1371.3Such	.align	2
1381.3Such_C_LABEL(sh3_vector_tlbmiss):
1391.8Such	__EXCEPTION_ENTRY
1401.9Such	mov.l	_L.TEA3, r0
1411.9Such	mov.l	@r0,	r6
1421.9Such	mov.l	__L.VPN_MASK, r1
1431.9Such	and	r1,	r6	/* 3rd arg */
1441.3Such#if !defined(P1_STACK)
1451.4Such	/* Load kernel stack */
1461.9Such	tst	r6,	r6	/* check VPN == 0 */
1471.9Such	bt	6f
1481.3Such	mov.l	_L.CURUPTE, r1
1491.9Such	mov.l	@r1,	r1
1501.3Such	mov	#UPAGES,r3
1511.3Such	mov	#1,	r2
1521.9Such4:	mov.l	@r1+,	r7
1531.9Such	cmp/eq	r7,	r6	/* md_upte.addr: u-area VPN */
1541.3Such	bt	5f
1551.3Such	add	#4,	r1	/* skip md_upte.data */
1561.3Such	cmp/eq	r2,	r3
1571.3Such	bf/s	4b
1581.8Such	 add	#1,	r2
1591.3Such	bra	6f
1601.3Such	 nop
1611.3Such5:	mov.l	@r1,	r2	/* md_upte.data: u-area PTE */
1621.3Such	mov.l	_L.PTEL, r1
1631.3Such	mov.l	r2,	@r1
1641.9Such	mov.l	_L.PTEH, r1
1651.9Such	mov.l	@r1,	r2
1661.9Such	mov.l	__L.VPN_MASK, r0
1671.9Such	and	r2,	r0
1681.9Such	mov.l	r0,	@r1	/* ASID 0 */
1691.3Such	ldtlb
1701.9Such	mov.l	r2,	@r1	/* restore ASID */
1711.3Such	bra	3f
1721.3Such	 nop
1731.3Such#endif /* !P1_STACK */
1741.9Such6:	mov.l	_L.EXPEVT3, r0
1751.9Such	mov.l	@r0,	r0
1761.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */
1771.9Such	mov.l	2f,	r0
1781.9Such	mov.l	@r0,	r4	/* 1st arg */
1791.9Such	__INTR_MASK(r0, r1)
1801.9Such	__EXCEPTION_UNBLOCK(r0, r1)
1811.1Such	mov.l	1f,	r0
1821.1Such	jsr	@r0
1831.9Such	 mov	r14,	r5	/* 2nd arg */
1841.9Such3:	__EXCEPTION_RETURN
1851.3Such	.align	2
1861.10Sthorpej2:		.long	_C_LABEL(curlwp)
1871.9Such1:		.long	_C_LABEL(tlb_exception)
1881.9Such_L.EXPEVT3:	.long	SH3_EXPEVT
1891.9Such_L.TEA3:	.long	SH3_TEA
1901.3Such_L.PTEL:	.long	SH3_PTEL
1911.9Such_L.PTEH:	.long	SH3_PTEH
1921.9Such__L.VPN_MASK:	.long	0xfffff000
1931.3Such_L.CURUPTE:	.long	_C_LABEL(curupte)
1941.3Such	.align	2
1951.3Such_C_LABEL(sh3_vector_tlbmiss_end):	.long	0
1961.3Such#endif /* SH3 */
1971.3Such
1981.3Such#ifdef SH4
1991.8Such/*
2001.8Such * void sh4_vector_tlbmiss(void) __attribute__((__noreturn__)):
2011.3Such *	copied to VBR+0x400. This code should be relocatable and max 256
2021.3Such *	instructions.
2031.3Such */
2041.3Such	.globl	_C_LABEL(sh4_vector_tlbmiss), _C_LABEL(sh4_vector_tlbmiss_end)
2051.8Such	.text
2061.3Such	.align	2
2071.3Such_C_LABEL(sh4_vector_tlbmiss):
2081.8Such	__EXCEPTION_ENTRY
2091.9Such	mov.l	_L.TEA4, r0
2101.9Such	mov.l	@r0,	r6
2111.9Such	mov.l	___L.VPN_MASK, r1
2121.9Such	and	r1,	r6	/* va = trunc_page(va) */
2131.9Such	mov.l	_L.EXPEVT4, r0
2141.9Such	mov.l	@r0,	r0
2151.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */
2161.9Such	mov.l	2f,	r0
2171.9Such	mov.l	@r0,	r4	/* 1st arg */
2181.3Such	__INTR_MASK(r0, r1)
2191.3Such	__EXCEPTION_UNBLOCK(r0, r1)
2201.3Such	mov.l	1f,	r0
2211.3Such	jsr	@r0
2221.9Such	 mov	r14,	r5	/* 2nd arg */
2231.5Such	__EXCEPTION_RETURN
2241.1Such	.align	2
2251.9Such1:		.long	_C_LABEL(tlb_exception)
2261.10Sthorpej2:		.long	_C_LABEL(curlwp)
2271.9Such_L.EXPEVT4:	.long	SH4_EXPEVT
2281.9Such_L.TEA4:	.long	SH4_TEA
2291.9Such___L.VPN_MASK:	.long	0xfffff000
2301.3Such_C_LABEL(sh4_vector_tlbmiss_end):	.long	0
2311.3Such#endif /* SH4 */
2321.1Such
2331.1Such/*
2341.8Such * void sh_vector_interrupt(void) __attribute__((__noreturn__)):
2351.1Such *	copied to VBR+0x600. This code should be relocatable.
2361.8Such */
2371.1Such	.globl	_C_LABEL(sh_vector_interrupt), _C_LABEL(sh_vector_interrupt_end)
2381.1Such	.align	2
2391.3Such	.text
2401.1Such_C_LABEL(sh_vector_interrupt):
2411.5Such	__EXCEPTION_ENTRY
2421.9Such	xor	r0,	r0
2431.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* (for debug) */
2441.8Such	stc	r0_bank,r6	/* ssp */
2451.5Such	/* Enable exception for P3 access */
2461.5Such	__INTR_MASK(r0, r1)
2471.5Such	__EXCEPTION_UNBLOCK(r0, r1)
2481.6Such	/* uvmexp.intrs++ */
2491.6Such	mov.l	__L.uvmexp.intrs, r0
2501.6Such	mov.l	@r0,	r1
2511.6Such	add	#1	r1
2521.6Such	mov.l	r1,	@r0
2531.5Such	/* Dispatch interrupt handler */
2541.6Such	mov.l	__L.intc_intr, r0
2551.5Such	jsr	@r0		/* intc_intr(ssr, spc, ssp) */
2561.1Such	 nop
2571.5Such	/* Check for ASTs on exit to user mode. */
2581.9Such	mov.l	1f,	r0
2591.9Such	mov.l	@r0,	r4	/* 1st arg */
2601.6Such	mov.l	__L.ast, r0
2611.5Such	jsr	@r0
2621.9Such	 mov	r14,	r5	/* 2nd arg */
2631.5Such	__EXCEPTION_RETURN
2641.1Such	.align	2
2651.10Sthorpej1:			.long	_C_LABEL(curlwp)
2661.8Such__L.intc_intr:		.long	_C_LABEL(intc_intr)
2671.8Such__L.ast:		.long	_C_LABEL(ast)
2681.6Such__L.uvmexp.intrs:	.long	_C_LABEL(uvmexp) + UVMEXP_INTRS
2691.3Such_C_LABEL(sh_vector_interrupt_end):	.long	0
270