irq_dispatch.S revision 1.3
11.3Sscw/* $NetBSD: irq_dispatch.S,v 1.3 2003/10/25 20:42:49 scw Exp $ */ 21.1Sthorpej 31.1Sthorpej/* 41.1Sthorpej * Copyright (c) 2002 Fujitsu Component Limited 51.1Sthorpej * Copyright (c) 2002 Genetec Corporation 61.1Sthorpej * All rights reserved. 71.1Sthorpej * 81.1Sthorpej * Redistribution and use in source and binary forms, with or without 91.1Sthorpej * modification, are permitted provided that the following conditions 101.1Sthorpej * are met: 111.1Sthorpej * 1. Redistributions of source code must retain the above copyright 121.1Sthorpej * notice, this list of conditions and the following disclaimer. 131.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 141.1Sthorpej * notice, this list of conditions and the following disclaimer in the 151.1Sthorpej * documentation and/or other materials provided with the distribution. 161.1Sthorpej * 3. Neither the name of The Fujitsu Component Limited nor the name of 171.1Sthorpej * Genetec corporation may not be used to endorse or promote products 181.1Sthorpej * derived from this software without specific prior written permission. 191.1Sthorpej * 201.1Sthorpej * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC 211.1Sthorpej * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 221.1Sthorpej * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 231.1Sthorpej * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 241.1Sthorpej * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC 251.1Sthorpej * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 261.1Sthorpej * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 271.1Sthorpej * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 281.1Sthorpej * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 291.1Sthorpej * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 301.1Sthorpej * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 311.1Sthorpej * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.1Sthorpej * SUCH DAMAGE. 331.1Sthorpej */ 341.1Sthorpej 351.1Sthorpej/* 361.1Sthorpej * Copyright (c) 2002, 2003 Wasabi Systems, Inc. 371.1Sthorpej * All rights reserved. 381.1Sthorpej * 391.1Sthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc. 401.1Sthorpej * 411.1Sthorpej * Redistribution and use in source and binary forms, with or without 421.1Sthorpej * modification, are permitted provided that the following conditions 431.1Sthorpej * are met: 441.1Sthorpej * 1. Redistributions of source code must retain the above copyright 451.1Sthorpej * notice, this list of conditions and the following disclaimer. 461.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 471.1Sthorpej * notice, this list of conditions and the following disclaimer in the 481.1Sthorpej * documentation and/or other materials provided with the distribution. 491.1Sthorpej * 3. All advertising materials mentioning features or use of this software 501.1Sthorpej * must display the following acknowledgement: 511.1Sthorpej * This product includes software developed for the NetBSD Project by 521.1Sthorpej * Wasabi Systems, Inc. 531.1Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse 541.1Sthorpej * or promote products derived from this software without specific prior 551.1Sthorpej * written permission. 561.1Sthorpej * 571.1Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 581.1Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 591.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 601.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 611.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 621.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 631.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 641.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 651.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 661.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 671.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 681.1Sthorpej */ 691.1Sthorpej 701.1Sthorpej#include "assym.h" 711.1Sthorpej 721.1Sthorpej#include <machine/asm.h> 731.1Sthorpej#include <machine/cpu.h> 741.1Sthorpej#include <machine/frame.h> 751.1Sthorpej 761.3Sscw#include "opt_compat_netbsd.h" 771.3Sscw#include "opt_execfmt.h" 781.3Sscw#include "opt_multiprocessor.h" 791.3Sscw 801.1Sthorpej#include "opt_arm_intr_impl.h" 811.1Sthorpej#ifdef ARM_INTR_IMPL 821.1Sthorpej#include ARM_INTR_IMPL 831.1Sthorpej#else 841.1Sthorpej#error ARM_INTR_IMPL not defined 851.1Sthorpej#endif 861.1Sthorpej 871.1Sthorpej#ifndef ARM_IRQ_HANDLER 881.1Sthorpej#error ARM_IRQ_HANDLER not defined 891.1Sthorpej#endif 901.1Sthorpej 911.3Sscw#if defined(COMPAT_15) && defined(EXEC_AOUT) 921.3Sscw.Lcpufuncs: 931.3Sscw .word _C_LABEL(cpufuncs) 941.3Sscw#ifndef MULTIPROCESSOR 951.3Sscw.Lcurpcb: 961.3Sscw .word _C_LABEL(curpcb) 971.3Sscw.Lcpu_info_store: 981.3Sscw .word _C_LABEL(cpu_info_store) 991.3Sscw#define GET_CURPCB \ 1001.3Sscw ldr r1, .Lcurpcb ;\ 1011.3Sscw ldr r1, [r1] 1021.3Sscw#define GET_CPUINFO \ 1031.3Sscw ldr r0, .Lcpu_info_store 1041.3Sscw#else 1051.3Sscw.Lcpu_info: 1061.3Sscw .word _C_LABEL(cpu_info) 1071.3Sscw#define GET_CURPCB \ 1081.3Sscw ldr r4, .Lcpu_info ;\ 1091.3Sscw bl _C_LABEL(cpu_number) ;\ 1101.3Sscw ldr r0, [r4, r0, lsl #2] ;\ 1111.3Sscw ldr r1, [r0, #CI_CURPCB] 1121.3Sscw#define GET_CPUINFO /* nothing to do */ 1131.3Sscw#endif 1141.3Sscw#define ENABLE_ALIGNMENT_FAULTS \ 1151.3Sscw GET_CURPCB ;\ 1161.3Sscw ldr r1, [r1, #PCB_FLAGS] /* Fetch curpcb->pcb_flags */ ;\ 1171.3Sscw tst r1, #PCB_NOALIGNFLT ;\ 1181.3Sscw beq 1f /* Alignment faults already enabled */ ;\ 1191.3Sscw GET_CPUINFO ;\ 1201.3Sscw ldr r2, .Lcpufuncs ;\ 1211.3Sscw ldr r1, [r0, #CI_CTRL] /* Fetch control register */ ;\ 1221.3Sscw mov r0, #-1 ;\ 1231.3Sscw mov lr, pc ;\ 1241.3Sscw ldr pc, [r2, #CF_CONTROL] /* Enable alignment faults */ ;\ 1251.3Sscw1: 1261.3Sscw#endif /* COMPAT_15 && EXEC_AOUT */ 1271.3Sscw 1281.1Sthorpej/* 1291.1Sthorpej * irq_entry: 1301.1Sthorpej * Main entry point for the IRQ vector. This is a generic version 1311.1Sthorpej * which can be used by different platforms. 1321.1Sthorpej */ 1331.1Sthorpej .text 1341.1Sthorpej .align 0 1351.1Sthorpej.Lastpending: 1361.1Sthorpej .word _C_LABEL(astpending) 1371.2Sthorpej.Lcurrent_intr_depth: 1381.2Sthorpej .word _C_LABEL(current_intr_depth) 1391.1Sthorpej 1401.1SthorpejASENTRY_NP(irq_entry) 1411.1Sthorpej sub lr, lr, #0x00000004 /* Adjust the lr */ 1421.1Sthorpej 1431.1Sthorpej PUSHFRAMEINSVC /* Push an interrupt frame */ 1441.1Sthorpej 1451.3Sscw#if defined(COMPAT_15) && defined(EXEC_AOUT) 1461.3Sscw and r0, r0, #(PSR_MODE) /* Test for USR32 mode (r0 = spsr_all)*/ 1471.3Sscw teq r0, #(PSR_USR32_MODE) 1481.3Sscw bne 99f /* Not USR mode so skip AFLT check */ 1491.3Sscw ENABLE_ALIGNMENT_FAULTS 1501.3Sscw99: 1511.3Sscw#endif 1521.3Sscw 1531.2Sthorpej /* 1541.2Sthorpej * Increment the interrupt nesting depth and call the interrupt 1551.2Sthorpej * dispatch routine. We've pushed a frame, so we can safely use 1561.2Sthorpej * callee-saved regs here. We use the following registers, which 1571.2Sthorpej * we expect to presist: 1581.2Sthorpej * 1591.2Sthorpej * r5 address of `current_intr_depth' variable 1601.2Sthorpej * r6 old value of `current_intr_depth' 1611.2Sthorpej */ 1621.2Sthorpej ldr r5, .Lcurrent_intr_depth 1631.2Sthorpej mov r0, sp /* arg for dispatcher */ 1641.2Sthorpej ldr r6, [r5] 1651.2Sthorpej add r1, r6, #1 1661.2Sthorpej str r1, [r5] 1671.2Sthorpej 1681.1Sthorpej bl ARM_IRQ_HANDLER 1691.1Sthorpej 1701.1Sthorpej /* 1711.2Sthorpej * Restore the old interrupt depth value (which should be the 1721.2Sthorpej * same as decrementing it at this point). 1731.2Sthorpej */ 1741.2Sthorpej str r6, [r5] 1751.2Sthorpej 1761.2Sthorpej /* 1771.1Sthorpej * If we're returning to user mode, check for pending ASTs. 1781.1Sthorpej */ 1791.1Sthorpej ldr r0, [sp] /* Get the SPSR from stack */ 1801.1Sthorpej and r0, r0, #(PSR_MODE) /* Test for USR32 mode before the IRQ */ 1811.1Sthorpej teq r0, #(PSR_USR32_MODE) 1821.3Sscw bne .Lirq_do_exit /* Nope, get out now */ 1831.3Sscw 1841.3Sscw ldr r5, .Lastpending 1851.3Sscw#if defined(COMPAT_15) && defined(EXEC_AOUT) && !defined(MULTIPROCESSOR) 1861.3Sscw ldr r6, .Lcurpcb 1871.3Sscw ldr r7, .Lcpu_info_store 1881.3Sscw#endif 1891.3Sscw 1901.3Sscw.Lirq_ast_loop: 1911.3Sscw ldr r1, [r5] /* Do we have an AST pending? */ 1921.3Sscw teq r1, #0x00000000 1931.3Sscw bne .Lirq_do_ast /* Yup. Go deal with it */ 1941.1Sthorpej 1951.3Sscw#if defined(COMPAT_15) && defined(EXEC_AOUT) 1961.3Sscw /* Disable alignment faults for the process, if necessary. */ 1971.3Sscw#ifdef MULTIPROCESSOR 1981.3Sscw ldr r7, .Lcpu_info 1991.3Sscw bl _C_LABEL(cpu_number) 2001.3Sscw ldr r7, [r7, r0, lsl #2] 2011.3Sscw ldr r1, [r7, #CI_CURPCB] 2021.3Sscw#else 2031.3Sscw ldr r1, [r6] 2041.3Sscw#endif 2051.3Sscw ldr r1, [r1, #PCB_FLAGS] /* Fetch curpcb->pcb_flags */ 2061.3Sscw tst r1, #PCB_NOALIGNFLT 2071.3Sscw beq 1f /* Keep alignment faults enabled */ 2081.3Sscw ldr r1, [r7, #CI_CTRL] /* Fetch control register */ 2091.3Sscw ldr r2, .Lcpufuncs 2101.3Sscw mov r0, #-1 2111.3Sscw bic r1, r1, #CPU_CONTROL_AFLT_ENABLE /* Disable alignment faults */ 2121.3Sscw mov lr, pc 2131.3Sscw ldr pc, [r2, #CF_CONTROL] /* Set the new control register value */ 2141.1Sthorpej1: 2151.3Sscw#endif 2161.3Sscw 2171.3Sscw.Lirq_do_exit: 2181.3Sscw PULLFRAMEFROMSVCANDEXIT 2191.3Sscw movs pc, lr /* Exit */ 2201.1Sthorpej 2211.3Sscw.Lirq_do_ast: 2221.1Sthorpej mov r1, #0x00000000 2231.3Sscw str r1, [r5] /* Clear astpending */ 2241.1Sthorpej 2251.1Sthorpej mrs r4, cpsr /* save CPSR */ 2261.1Sthorpej bic r0, r4, #(I32_bit) /* Enable IRQs */ 2271.1Sthorpej msr cpsr_c, r0 2281.1Sthorpej 2291.1Sthorpej mov r0, sp 2301.1Sthorpej bl _C_LABEL(ast) /* ast(frame) */ 2311.1Sthorpej 2321.1Sthorpej msr cpsr_c, r4 /* Disable IRQs */ 2331.3Sscw b .Lirq_ast_loop /* Check for more ASTs */ 2341.1Sthorpej 2351.1Sthorpej .bss 2361.1Sthorpej .align 0 2371.1Sthorpej 2381.1Sthorpej .global _C_LABEL(astpending) 2391.1Sthorpej_C_LABEL(astpending): 2401.2Sthorpej .word 0 2411.2Sthorpej 2421.2Sthorpej .global _C_LABEL(current_intr_depth) 2431.2Sthorpej_C_LABEL(current_intr_depth): 2441.1Sthorpej .word 0 2451.1Sthorpej 2461.1Sthorpej /* 2471.1Sthorpej * XXX Provide intrnames/intrcnt for legacy code, but 2481.1Sthorpej * don't actually use them. 2491.1Sthorpej */ 2501.1Sthorpej 2511.1Sthorpej .global _C_LABEL(intrnames), _C_LABEL(eintrnames) 2521.1Sthorpej .global _C_LABEL(intrcnt), _C_LABEL(eintrcnt) 2531.1Sthorpej_C_LABEL(intrnames): 2541.1Sthorpej_C_LABEL(eintrnames): 2551.1Sthorpej 2561.1Sthorpej .global _C_LABEL(intrcnt), _C_LABEL(sintrcnt), _C_LABEL(eintrcnt) 2571.1Sthorpej_C_LABEL(intrcnt): 2581.1Sthorpej_C_LABEL(eintrcnt): 259