exception_vector.S revision 1.10
11.10Sthorpej/*	$NetBSD: exception_vector.S,v 1.10 2003/01/18 06:33:43 thorpej 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.9Such	/* Check TLB exception or not */
741.9Such	mov.l	_L.TLB_PROT_ST, r1
751.9Such	cmp/hi	r1,	r0
761.9Such	bt	1f
771.9Such	MOV	(TEA,	r0)
781.9Such	mov.l	@r0,	r6	/* 3rd arg */
791.9Such	mov.l	_L.VPN_MASK, r1
801.9Such	and	r1,	r6	/* va = trunc_page(va) */
811.2Such	__EXCEPTION_UNBLOCK(r0, r1)
821.9Such	mov.l	_L.tlb, r0
831.1Such	jsr	@r0
841.9Such	 mov	r14,	r5	/* 2nd arg */
851.9Such	bra	2f
861.1Such	 nop
871.9Such1:	mov	r4,	r8
881.1Such#ifdef DDB
891.1Such	mov	#0,	r2
901.1Such	MOV	(BBRA, r1)
911.1Such	mov.w	r2,	@r1	/* disable UBC */
921.3Such	mov.l	r2,	@(TF_UBC, r14)	/* clear trapframe->tf_ubc */
931.1Such#endif /* DDB */
941.2Such	__EXCEPTION_UNBLOCK(r0, r1)
951.9Such	mov.l	_L.general, r0
961.1Such	jsr	@r0
971.9Such	 mov	r14,	r5
981.1Such
991.1Such	/* Check for ASTs on exit to user mode. */
1001.9Such	mov	r8,	r4
1011.1Such	mov.l	_L.ast,	r0
1021.1Such	jsr	@r0
1031.9Such	 mov	r14,	r5
1041.8Such#ifdef DDB	/* BBRA = trapframe->tf_ubc */
1051.2Such	__EXCEPTION_BLOCK(r0, r1)
1061.3Such	mov.l	@(TF_UBC, r14), r0
1071.1Such	MOV	(BBRA, r1)
1081.1Such	mov.w	r0,	@r1
1091.1Such#endif /* DDB */
1101.9Such2:	__EXCEPTION_RETURN
1111.1Such	/* NOTREACHED */
1121.1Such	.align	2
1131.10Sthorpej3:		.long	_C_LABEL(curlwp)
1141.1SuchREG_SYMBOL(EXPEVT)
1151.1SuchREG_SYMBOL(BBRA)
1161.9SuchREG_SYMBOL(TEA)
1171.9Such_L.tlb:		.long	_C_LABEL(tlb_exception)
1181.9Such_L.general:	.long	_C_LABEL(general_exception)
1191.1Such_L.ast:		.long	_C_LABEL(ast)
1201.9Such_L.TLB_PROT_ST:	.long	0xc0
1211.9Such_L.VPN_MASK:	.long	0xfffff000
1221.3Such_C_LABEL(sh_vector_generic_end):	.long	0
1231.8Such
1241.3Such#ifdef SH3
1251.8Such/*
1261.8Such * void sh3_vector_tlbmiss(void) __attribute__((__noreturn__)):
1271.1Such *	copied to VBR+0x400. This code should be relocatable and max 256
1281.1Such *	instructions.
1291.1Such */
1301.3Such	.globl	_C_LABEL(sh3_vector_tlbmiss), _C_LABEL(sh3_vector_tlbmiss_end)
1311.8Such	.text
1321.3Such	.align	2
1331.3Such_C_LABEL(sh3_vector_tlbmiss):
1341.8Such	__EXCEPTION_ENTRY
1351.9Such	mov.l	_L.TEA3, r0
1361.9Such	mov.l	@r0,	r6
1371.9Such	mov.l	__L.VPN_MASK, r1
1381.9Such	and	r1,	r6	/* 3rd arg */
1391.3Such#if !defined(P1_STACK)
1401.4Such	/* Load kernel stack */
1411.9Such	tst	r6,	r6	/* check VPN == 0 */
1421.9Such	bt	6f
1431.3Such	mov.l	_L.CURUPTE, r1
1441.9Such	mov.l	@r1,	r1
1451.3Such	mov	#UPAGES,r3
1461.3Such	mov	#1,	r2
1471.9Such4:	mov.l	@r1+,	r7
1481.9Such	cmp/eq	r7,	r6	/* md_upte.addr: u-area VPN */
1491.3Such	bt	5f
1501.3Such	add	#4,	r1	/* skip md_upte.data */
1511.3Such	cmp/eq	r2,	r3
1521.3Such	bf/s	4b
1531.8Such	 add	#1,	r2
1541.3Such	bra	6f
1551.3Such	 nop
1561.3Such5:	mov.l	@r1,	r2	/* md_upte.data: u-area PTE */
1571.3Such	mov.l	_L.PTEL, r1
1581.3Such	mov.l	r2,	@r1
1591.9Such	mov.l	_L.PTEH, r1
1601.9Such	mov.l	@r1,	r2
1611.9Such	mov.l	__L.VPN_MASK, r0
1621.9Such	and	r2,	r0
1631.9Such	mov.l	r0,	@r1	/* ASID 0 */
1641.3Such	ldtlb
1651.9Such	mov.l	r2,	@r1	/* restore ASID */
1661.3Such	bra	3f
1671.3Such	 nop
1681.3Such#endif /* !P1_STACK */
1691.9Such6:	mov.l	_L.EXPEVT3, r0
1701.9Such	mov.l	@r0,	r0
1711.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */
1721.9Such	mov.l	2f,	r0
1731.9Such	mov.l	@r0,	r4	/* 1st arg */
1741.9Such	__INTR_MASK(r0, r1)
1751.9Such	__EXCEPTION_UNBLOCK(r0, r1)
1761.1Such	mov.l	1f,	r0
1771.1Such	jsr	@r0
1781.9Such	 mov	r14,	r5	/* 2nd arg */
1791.9Such3:	__EXCEPTION_RETURN
1801.3Such	.align	2
1811.10Sthorpej2:		.long	_C_LABEL(curlwp)
1821.9Such1:		.long	_C_LABEL(tlb_exception)
1831.9Such_L.EXPEVT3:	.long	SH3_EXPEVT
1841.9Such_L.TEA3:	.long	SH3_TEA
1851.3Such_L.PTEL:	.long	SH3_PTEL
1861.9Such_L.PTEH:	.long	SH3_PTEH
1871.9Such__L.VPN_MASK:	.long	0xfffff000
1881.3Such_L.CURUPTE:	.long	_C_LABEL(curupte)
1891.3Such	.align	2
1901.3Such_C_LABEL(sh3_vector_tlbmiss_end):	.long	0
1911.3Such#endif /* SH3 */
1921.3Such
1931.3Such#ifdef SH4
1941.8Such/*
1951.8Such * void sh4_vector_tlbmiss(void) __attribute__((__noreturn__)):
1961.3Such *	copied to VBR+0x400. This code should be relocatable and max 256
1971.3Such *	instructions.
1981.3Such */
1991.3Such	.globl	_C_LABEL(sh4_vector_tlbmiss), _C_LABEL(sh4_vector_tlbmiss_end)
2001.8Such	.text
2011.3Such	.align	2
2021.3Such_C_LABEL(sh4_vector_tlbmiss):
2031.8Such	__EXCEPTION_ENTRY
2041.9Such	mov.l	_L.TEA4, r0
2051.9Such	mov.l	@r0,	r6
2061.9Such	mov.l	___L.VPN_MASK, r1
2071.9Such	and	r1,	r6	/* va = trunc_page(va) */
2081.9Such	mov.l	_L.EXPEVT4, r0
2091.9Such	mov.l	@r0,	r0
2101.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */
2111.9Such	mov.l	2f,	r0
2121.9Such	mov.l	@r0,	r4	/* 1st arg */
2131.3Such	__INTR_MASK(r0, r1)
2141.3Such	__EXCEPTION_UNBLOCK(r0, r1)
2151.3Such	mov.l	1f,	r0
2161.3Such	jsr	@r0
2171.9Such	 mov	r14,	r5	/* 2nd arg */
2181.5Such	__EXCEPTION_RETURN
2191.1Such	.align	2
2201.9Such1:		.long	_C_LABEL(tlb_exception)
2211.10Sthorpej2:		.long	_C_LABEL(curlwp)
2221.9Such_L.EXPEVT4:	.long	SH4_EXPEVT
2231.9Such_L.TEA4:	.long	SH4_TEA
2241.9Such___L.VPN_MASK:	.long	0xfffff000
2251.3Such_C_LABEL(sh4_vector_tlbmiss_end):	.long	0
2261.3Such#endif /* SH4 */
2271.1Such
2281.1Such/*
2291.8Such * void sh_vector_interrupt(void) __attribute__((__noreturn__)):
2301.1Such *	copied to VBR+0x600. This code should be relocatable.
2311.8Such */
2321.1Such	.globl	_C_LABEL(sh_vector_interrupt), _C_LABEL(sh_vector_interrupt_end)
2331.1Such	.align	2
2341.3Such	.text
2351.1Such_C_LABEL(sh_vector_interrupt):
2361.5Such	__EXCEPTION_ENTRY
2371.9Such	xor	r0,	r0
2381.9Such	mov.l	r0,	@(TF_EXPEVT, r14) /* (for debug) */
2391.8Such	stc	r0_bank,r6	/* ssp */
2401.5Such	/* Enable exception for P3 access */
2411.5Such	__INTR_MASK(r0, r1)
2421.5Such	__EXCEPTION_UNBLOCK(r0, r1)
2431.6Such	/* uvmexp.intrs++ */
2441.6Such	mov.l	__L.uvmexp.intrs, r0
2451.6Such	mov.l	@r0,	r1
2461.6Such	add	#1	r1
2471.6Such	mov.l	r1,	@r0
2481.5Such	/* Dispatch interrupt handler */
2491.6Such	mov.l	__L.intc_intr, r0
2501.5Such	jsr	@r0		/* intc_intr(ssr, spc, ssp) */
2511.1Such	 nop
2521.5Such	/* Check for ASTs on exit to user mode. */
2531.9Such	mov.l	1f,	r0
2541.9Such	mov.l	@r0,	r4	/* 1st arg */
2551.6Such	mov.l	__L.ast, r0
2561.5Such	jsr	@r0
2571.9Such	 mov	r14,	r5	/* 2nd arg */
2581.5Such	__EXCEPTION_RETURN
2591.1Such	.align	2
2601.10Sthorpej1:			.long	_C_LABEL(curlwp)
2611.8Such__L.intc_intr:		.long	_C_LABEL(intc_intr)
2621.8Such__L.ast:		.long	_C_LABEL(ast)
2631.6Such__L.uvmexp.intrs:	.long	_C_LABEL(uvmexp) + UVMEXP_INTRS
2641.3Such_C_LABEL(sh_vector_interrupt_end):	.long	0
265