exception_vector.S revision 1.21
1/* $NetBSD: exception_vector.S,v 1.21 2007/03/14 22:38:00 uwe Exp $ */ 2 3/*- 4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the NetBSD 18 * Foundation, Inc. and its contributors. 19 * 4. Neither the name of The NetBSD Foundation nor the names of its 20 * contributors may be used to endorse or promote products derived 21 * from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36#include "opt_cputype.h" 37#include "opt_ddb.h" 38#include "assym.h" 39 40#include <sh3/param.h> 41#include <sh3/asm.h> 42#include <sh3/locore.h> 43#include <sh3/exception.h> 44#include <sh3/ubcreg.h> 45#include <sh3/mmu_sh3.h> 46#include <sh3/mmu_sh4.h> 47 48__KERNEL_RCSID(0, "$NetBSD: exception_vector.S,v 1.21 2007/03/14 22:38:00 uwe Exp $") 49 50 51/* 52 * Exception vectors. The following routines are copied to vector addreses. 53 * sh_vector_generic: VBR + 0x100 54 * sh_vector_tlbmiss: VBR + 0x400 55 * sh_vector_interrupt: VBR + 0x600 56 */ 57 58#define VECTOR_END_MARKER(sym) \ 59 .globl _C_LABEL(sym); \ 60 _C_LABEL(sym): 61 62 63/* 64 * LINTSTUB: Var: char sh_vector_generic[1]; 65 * 66 * void sh_vector_generic(void) __attribute__((__noreturn__)) 67 * Copied to VBR+0x100. This code should be position independent 68 * and no more than 786 bytes long (== 0x400 - 0x100). 69 */ 70NENTRY(sh_vector_generic) 71 __EXCEPTION_ENTRY 72 __INTR_MASK(r0, r1) 73 /* Identify exception cause */ 74 MOV (EXPEVT, r0) 75 mov.l @r0, r0 76 mov.l r0, @(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */ 77 /* Get curlwp */ 78 mov.l _L.curlwp, r1 79 mov.l @r1, r4 /* 1st arg */ 80 /* Get TEA */ 81 MOV (TEA, r1) 82 mov.l @r1, r6 /* 3rd arg */ 83 /* Check TLB exception or not */ 84 mov.l _L.TLB_PROT_ST, r1 85 cmp/hi r1, r0 86 bt 1f 87 88 /* tlb_exception(curlwp, trapframe, TEA); */ 89 __EXCEPTION_UNBLOCK(r0, r1) 90 mov.l _L.tlb, r0 91 jsr @r0 92 mov r14, r5 /* 2nd arg */ 93 bra 2f 94 nop 95 96 /* general_exception(curlwp, trapframe, TEA); */ 971: mov r4, r8 98#ifdef DDB 99 mov #0, r2 100 MOV (BBRA, r1) 101 mov.w r2, @r1 /* disable UBC */ 102 mov.l r2, @(TF_UBC, r14) /* clear trapframe->tf_ubc */ 103#endif /* DDB */ 104 __EXCEPTION_UNBLOCK(r0, r1) 105 mov.l _L.general, r0 106 jsr @r0 107 mov r14, r5 /* 2nd arg */ 108 109 /* Check for ASTs on exit to user mode. */ 110 mov r8, r4 111 mov.l _L.ast, r0 112 jsr @r0 113 mov r14, r5 114#ifdef DDB /* BBRA = trapframe->tf_ubc */ 115 __EXCEPTION_BLOCK(r0, r1) 116 mov.l @(TF_UBC, r14), r0 117 MOV (BBRA, r1) 118 mov.w r0, @r1 119#endif /* DDB */ 1202: __EXCEPTION_RETURN 121 /* NOTREACHED */ 122 .align 2 123_L.curlwp: .long _C_LABEL(curlwp) 124REG_SYMBOL(EXPEVT) 125REG_SYMBOL(BBRA) 126REG_SYMBOL(TEA) 127_L.tlb: .long _C_LABEL(tlb_exception) 128_L.general: .long _C_LABEL(general_exception) 129_L.ast: .long _C_LABEL(ast) 130_L.TLB_PROT_ST: .long 0xc0 131 132/* LINTSTUB: Var: char sh_vector_generic_end[1]; */ 133VECTOR_END_MARKER(sh_vector_generic_end) 134 SET_ENTRY_SIZE(sh_vector_generic) 135 136 137#ifdef SH3 138/* 139 * LINTSTUB: Var: char sh3_vector_tlbmiss[1]; 140 * 141 * void sh3_vector_tlbmiss(void) __attribute__((__noreturn__)) 142 * Copied to VBR+0x400. This code should be position independent 143 * and no more than 512 bytes long (== 0x600 - 0x400). 144 */ 145NENTRY(sh3_vector_tlbmiss) 146 __EXCEPTION_ENTRY 147 mov #(SH3_TEA & 0xff), r0 148 mov.l @r0, r6 /* 3rd arg: va = TEA */ 149#if !defined(P1_STACK) 150 /* Load kernel stack */ 151 mov.l __L.VPN_MASK, r0 152 and r6, r0 153 tst r0, r0 /* check VPN == 0 */ 154 bt 6f 155 mov.l _L.CURUPTE, r1 156 mov.l @r1, r1 157 mov #UPAGES, r3 158 mov #1, r2 1594: mov.l @r1+, r7 160 cmp/eq r7, r0 /* md_upte.addr: u-area VPN */ 161 bt 5f 162 add #4, r1 /* skip md_upte.data */ 163 cmp/eq r2, r3 164 bf/s 4b 165 add #1, r2 166 bra 7f /* pull insn at 6f into delay slot */ 167 mov #(SH3_EXPEVT & 0xff), r0 1685: mov.l @r1, r2 /* md_upte.data: u-area PTE */ 169 mov #(SH3_PTEL & 0xff), r1 170 mov.l r2, @r1 171 mov #(SH3_PTEH & 0xff), r1 172 mov.l @r1, r2 173 mov.l __L.VPN_MASK, r0 174 and r2, r0 175 mov.l r0, @r1 /* ASID 0 */ 176 ldtlb 177 bra 3f 178 mov.l r2, @r1 /* restore ASID */ 179#endif /* !P1_STACK */ 1806: mov #(SH3_EXPEVT & 0xff), r0 1817: mov.l @r0, r0 182 mov.l r0, @(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */ 183 mov.l 2f, r0 184 mov.l @r0, r4 /* 1st arg */ 185 __INTR_MASK(r0, r1) 186 __EXCEPTION_UNBLOCK(r0, r1) 187 mov.l 1f, r0 188 jsr @r0 189 mov r14, r5 /* 2nd arg */ 1903: __EXCEPTION_RETURN 191 .align 2 1922: .long _C_LABEL(curlwp) 1931: .long _C_LABEL(tlb_exception) 194__L.VPN_MASK: .long 0xfffff000 195_L.CURUPTE: .long _C_LABEL(curupte) 196 197/* LINTSTUB: Var: char sh3_vector_tlbmiss_end[1]; */ 198VECTOR_END_MARKER(sh3_vector_tlbmiss_end) 199 SET_ENTRY_SIZE(sh3_vector_tlbmiss) 200#endif /* SH3 */ 201 202 203#ifdef SH4 204/* 205 * LINTSTUB: Var: char sh4_vector_tlbmiss[1]; 206 * 207 * void sh4_vector_tlbmiss(void) __attribute__((__noreturn__)) 208 * Copied to VBR+0x400. This code should be position independent 209 * and no more than 512 bytes long (== 0x600 - 0x400). 210 */ 211NENTRY(sh4_vector_tlbmiss) 212 __EXCEPTION_ENTRY 213 mov.l _L.TEA4, r0 214 mov.l @r0, r6 215 mov.l _L.EXPEVT4, r0 216 mov.l @r0, r0 217 mov.l r0, @(TF_EXPEVT, r14) /* trapframe->tf_expevt = EXPEVT */ 218 mov.l 2f, r0 219 mov.l @r0, r4 /* 1st arg */ 220 __INTR_MASK(r0, r1) 221 __EXCEPTION_UNBLOCK(r0, r1) 222 mov.l 1f, r0 223 jsr @r0 224 mov r14, r5 /* 2nd arg */ 225 __EXCEPTION_RETURN 226 .align 2 2271: .long _C_LABEL(tlb_exception) 2282: .long _C_LABEL(curlwp) 229_L.EXPEVT4: .long SH4_EXPEVT 230_L.TEA4: .long SH4_TEA 231 232/* LINTSTUB: Var: char sh4_vector_tlbmiss_end[1]; */ 233VECTOR_END_MARKER(sh4_vector_tlbmiss_end) 234 SET_ENTRY_SIZE(sh4_vector_tlbmiss) 235#endif /* SH4 */ 236 237 238/* 239 * LINTSTUB: Var: char sh_vector_interrupt[1]; 240 * 241 * void sh_vector_interrupt(void) __attribute__((__noreturn__)): 242 * copied to VBR+0x600. This code should be relocatable. 243 */ 244NENTRY(sh_vector_interrupt) 245 __EXCEPTION_ENTRY 246 xor r0, r0 247 mov.l r0, @(TF_EXPEVT, r14) /* (for debug) */ 248 stc r0_bank, r6 /* ssp */ 249 /* Enable exception for P3 access */ 250 __INTR_MASK(r0, r1) 251 __EXCEPTION_UNBLOCK(r0, r1) 252 /* uvmexp.intrs++ */ 253 mov.l __L.uvmexp.intrs, r0 254 mov.l @r0, r1 255 add #1 r1 256 mov.l r1, @r0 257 /* Dispatch interrupt handler */ 258 mov.l __L.intc_intr, r0 259 jsr @r0 /* intc_intr(ssr, spc, ssp) */ 260 nop 261 /* Check for ASTs on exit to user mode. */ 262 mov.l 1f, r0 263 mov.l @r0, r4 /* 1st arg */ 264 mov.l __L.ast, r0 265 jsr @r0 266 mov r14, r5 /* 2nd arg */ 267 __EXCEPTION_RETURN 268 .align 2 2691: .long _C_LABEL(curlwp) 270__L.intc_intr: .long _C_LABEL(intc_intr) 271__L.ast: .long _C_LABEL(ast) 272__L.uvmexp.intrs: .long _C_LABEL(uvmexp) + UVMEXP_INTRS 273 274/* LINTSTUB: Var: char sh_vector_interrupt_end[1]; */ 275VECTOR_END_MARKER(sh_vector_interrupt_end) 276 SET_ENTRY_SIZE(sh_vector_interrupt) 277