11da177e4SLinus Torvalds/* 21da177e4SLinus Torvalds * linux/arch/arm/kernel/entry-armv.S 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1996,1997,1998 Russell King. 51da177e4SLinus Torvalds * ARM700 fix by Matthew Godbolt (linux-user@willothewisp.demon.co.uk) 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 81da177e4SLinus Torvalds * it under the terms of the GNU General Public License version 2 as 91da177e4SLinus Torvalds * published by the Free Software Foundation. 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * Low-level vector interface routines 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction that causes 141da177e4SLinus Torvalds * it to save wrong values... Be aware! 151da177e4SLinus Torvalds */ 161da177e4SLinus Torvalds#include <linux/config.h> 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds#include <asm/glue.h> 191da177e4SLinus Torvalds#include <asm/vfpmacros.h> 2041e46d6aSNicolas Pitre#include <asm/hardware.h> /* should be moved into entry-macro.S */ 2141e46d6aSNicolas Pitre#include <asm/arch/irqs.h> /* should be moved into entry-macro.S */ 22bce495d8SRussell King#include <asm/arch/entry-macro.S> 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds#include "entry-header.S" 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds/* 27187a51adSRussell King * Interrupt handling. Preserves r7, r8, r9 28187a51adSRussell King */ 29187a51adSRussell King .macro irq_handler 30187a51adSRussell King1: get_irqnr_and_base r0, r6, r5, lr 31187a51adSRussell King movne r1, sp 32187a51adSRussell King @ 33187a51adSRussell King @ routine called with r0 = irq number, r1 = struct pt_regs * 34187a51adSRussell King @ 35187a51adSRussell King adrne lr, 1b 36187a51adSRussell King bne asm_do_IRQ 37791be9b9SRussell King 38791be9b9SRussell King#ifdef CONFIG_SMP 39791be9b9SRussell King /* 40791be9b9SRussell King * XXX 41791be9b9SRussell King * 42791be9b9SRussell King * this macro assumes that irqstat (r6) and base (r5) are 43791be9b9SRussell King * preserved from get_irqnr_and_base above 44791be9b9SRussell King */ 45791be9b9SRussell King test_for_ipi r0, r6, r5, lr 46791be9b9SRussell King movne r0, sp 47791be9b9SRussell King adrne lr, 1b 48791be9b9SRussell King bne do_IPI 49791be9b9SRussell King#endif 50791be9b9SRussell King 51187a51adSRussell King .endm 52187a51adSRussell King 53187a51adSRussell King/* 541da177e4SLinus Torvalds * Invalid mode handlers 551da177e4SLinus Torvalds */ 56*ccea7a19SRussell King .macro inv_entry, reason 57*ccea7a19SRussell King sub sp, sp, #S_FRAME_SIZE 58*ccea7a19SRussell King stmib sp, {r1 - lr} 591da177e4SLinus Torvalds mov r1, #\reason 601da177e4SLinus Torvalds .endm 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds__pabt_invalid: 63*ccea7a19SRussell King inv_entry BAD_PREFETCH 64*ccea7a19SRussell King b common_invalid 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds__dabt_invalid: 67*ccea7a19SRussell King inv_entry BAD_DATA 68*ccea7a19SRussell King b common_invalid 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds__irq_invalid: 71*ccea7a19SRussell King inv_entry BAD_IRQ 72*ccea7a19SRussell King b common_invalid 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds__und_invalid: 75*ccea7a19SRussell King inv_entry BAD_UNDEFINSTR 761da177e4SLinus Torvalds 77*ccea7a19SRussell King @ 78*ccea7a19SRussell King @ XXX fall through to common_invalid 79*ccea7a19SRussell King @ 80*ccea7a19SRussell King 81*ccea7a19SRussell King@ 82*ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers) 83*ccea7a19SRussell King@ 84*ccea7a19SRussell Kingcommon_invalid: 85*ccea7a19SRussell King zero_fp 86*ccea7a19SRussell King 87*ccea7a19SRussell King ldmia r0, {r4 - r6} 88*ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 89*ccea7a19SRussell King mov r7, #-1 @ "" "" "" "" 90*ccea7a19SRussell King str r4, [sp] @ save preserved r0 91*ccea7a19SRussell King stmia r0, {r5 - r7} @ lr_<exception>, 92*ccea7a19SRussell King @ cpsr_<exception>, "old_r0" 93*ccea7a19SRussell King 941da177e4SLinus Torvalds mov r0, sp 95*ccea7a19SRussell King and r2, r6, #0x1f 961da177e4SLinus Torvalds b bad_mode 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds/* 991da177e4SLinus Torvalds * SVC mode handlers 1001da177e4SLinus Torvalds */ 101*ccea7a19SRussell King .macro svc_entry 1021da177e4SLinus Torvalds sub sp, sp, #S_FRAME_SIZE 103*ccea7a19SRussell King stmib sp, {r1 - r12} 104*ccea7a19SRussell King 105*ccea7a19SRussell King ldmia r0, {r1 - r3} 106*ccea7a19SRussell King add r5, sp, #S_SP @ here for interlock avoidance 107*ccea7a19SRussell King mov r4, #-1 @ "" "" "" "" 108*ccea7a19SRussell King add r0, sp, #S_FRAME_SIZE @ "" "" "" "" 109*ccea7a19SRussell King str r1, [sp] @ save the "real" r0 copied 110*ccea7a19SRussell King @ from the exception stack 111*ccea7a19SRussell King 1121da177e4SLinus Torvalds mov r1, lr 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds @ 1151da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 1161da177e4SLinus Torvalds @ 1171da177e4SLinus Torvalds @ r0 - sp_svc 1181da177e4SLinus Torvalds @ r1 - lr_svc 1191da177e4SLinus Torvalds @ r2 - lr_<exception>, already fixed up for correct return/restart 1201da177e4SLinus Torvalds @ r3 - spsr_<exception> 1211da177e4SLinus Torvalds @ r4 - orig_r0 (see pt_regs definition in ptrace.h) 1221da177e4SLinus Torvalds @ 1231da177e4SLinus Torvalds stmia r5, {r0 - r4} 1241da177e4SLinus Torvalds .endm 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds .align 5 1271da177e4SLinus Torvalds__dabt_svc: 128*ccea7a19SRussell King svc_entry 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds @ 1311da177e4SLinus Torvalds @ get ready to re-enable interrupts if appropriate 1321da177e4SLinus Torvalds @ 1331da177e4SLinus Torvalds mrs r9, cpsr 1341da177e4SLinus Torvalds tst r3, #PSR_I_BIT 1351da177e4SLinus Torvalds biceq r9, r9, #PSR_I_BIT 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds @ 1381da177e4SLinus Torvalds @ Call the processor-specific abort handler: 1391da177e4SLinus Torvalds @ 1401da177e4SLinus Torvalds @ r2 - aborted context pc 1411da177e4SLinus Torvalds @ r3 - aborted context cpsr 1421da177e4SLinus Torvalds @ 1431da177e4SLinus Torvalds @ The abort handler must return the aborted address in r0, and 1441da177e4SLinus Torvalds @ the fault status register in r1. r9 must be preserved. 1451da177e4SLinus Torvalds @ 1461da177e4SLinus Torvalds#ifdef MULTI_ABORT 1471da177e4SLinus Torvalds ldr r4, .LCprocfns 1481da177e4SLinus Torvalds mov lr, pc 1491da177e4SLinus Torvalds ldr pc, [r4] 1501da177e4SLinus Torvalds#else 1511da177e4SLinus Torvalds bl CPU_ABORT_HANDLER 1521da177e4SLinus Torvalds#endif 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds @ 1551da177e4SLinus Torvalds @ set desired IRQ state, then call main handler 1561da177e4SLinus Torvalds @ 1571da177e4SLinus Torvalds msr cpsr_c, r9 1581da177e4SLinus Torvalds mov r2, sp 1591da177e4SLinus Torvalds bl do_DataAbort 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds @ 1621da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 1631da177e4SLinus Torvalds @ 1641ec42c0cSRussell King disable_irq 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds @ 1671da177e4SLinus Torvalds @ restore SPSR and restart the instruction 1681da177e4SLinus Torvalds @ 1691da177e4SLinus Torvalds ldr r0, [sp, #S_PSR] 1701da177e4SLinus Torvalds msr spsr_cxsf, r0 1711da177e4SLinus Torvalds ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds .align 5 1741da177e4SLinus Torvalds__irq_svc: 175*ccea7a19SRussell King svc_entry 176*ccea7a19SRussell King 1771da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 178706fdd9fSRussell King get_thread_info tsk 179706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 180706fdd9fSRussell King add r7, r8, #1 @ increment it 181706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] 1821da177e4SLinus Torvalds#endif 183*ccea7a19SRussell King 184187a51adSRussell King irq_handler 1851da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 186706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get flags 1871da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 1881da177e4SLinus Torvalds blne svc_preempt 1891da177e4SLinus Torvaldspreempt_return: 190706fdd9fSRussell King ldr r0, [tsk, #TI_PREEMPT] @ read preempt value 191706fdd9fSRussell King str r8, [tsk, #TI_PREEMPT] @ restore preempt count 1921da177e4SLinus Torvalds teq r0, r7 1931da177e4SLinus Torvalds strne r0, [r0, -r0] @ bug() 1941da177e4SLinus Torvalds#endif 1951da177e4SLinus Torvalds ldr r0, [sp, #S_PSR] @ irqs are already disabled 1961da177e4SLinus Torvalds msr spsr_cxsf, r0 1971da177e4SLinus Torvalds ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds .ltorg 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 2021da177e4SLinus Torvaldssvc_preempt: 203706fdd9fSRussell King teq r8, #0 @ was preempt count = 0 2041da177e4SLinus Torvalds ldreq r6, .LCirq_stat 2051da177e4SLinus Torvalds movne pc, lr @ no 2061da177e4SLinus Torvalds ldr r0, [r6, #4] @ local_irq_count 2071da177e4SLinus Torvalds ldr r1, [r6, #8] @ local_bh_count 2081da177e4SLinus Torvalds adds r0, r0, r1 2091da177e4SLinus Torvalds movne pc, lr 2101da177e4SLinus Torvalds mov r7, #0 @ preempt_schedule_irq 211706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] @ expects preempt_count == 0 2121da177e4SLinus Torvalds1: bl preempt_schedule_irq @ irq en/disable is done inside 213706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS 2141da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2151da177e4SLinus Torvalds beq preempt_return @ go again 2161da177e4SLinus Torvalds b 1b 2171da177e4SLinus Torvalds#endif 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds .align 5 2201da177e4SLinus Torvalds__und_svc: 221*ccea7a19SRussell King svc_entry 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds @ 2241da177e4SLinus Torvalds @ call emulation code, which returns using r9 if it has emulated 2251da177e4SLinus Torvalds @ the instruction, or the more conventional lr if we are to treat 2261da177e4SLinus Torvalds @ this as a real undefined instruction 2271da177e4SLinus Torvalds @ 2281da177e4SLinus Torvalds @ r0 - instruction 2291da177e4SLinus Torvalds @ 2301da177e4SLinus Torvalds ldr r0, [r2, #-4] 2311da177e4SLinus Torvalds adr r9, 1f 2321da177e4SLinus Torvalds bl call_fpe 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds mov r0, sp @ struct pt_regs *regs 2351da177e4SLinus Torvalds bl do_undefinstr 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds @ 2381da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 2391da177e4SLinus Torvalds @ 2401ec42c0cSRussell King1: disable_irq 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds @ 2431da177e4SLinus Torvalds @ restore SPSR and restart the instruction 2441da177e4SLinus Torvalds @ 2451da177e4SLinus Torvalds ldr lr, [sp, #S_PSR] @ Get SVC cpsr 2461da177e4SLinus Torvalds msr spsr_cxsf, lr 2471da177e4SLinus Torvalds ldmia sp, {r0 - pc}^ @ Restore SVC registers 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds .align 5 2501da177e4SLinus Torvalds__pabt_svc: 251*ccea7a19SRussell King svc_entry 2521da177e4SLinus Torvalds 2531da177e4SLinus Torvalds @ 2541da177e4SLinus Torvalds @ re-enable interrupts if appropriate 2551da177e4SLinus Torvalds @ 2561da177e4SLinus Torvalds mrs r9, cpsr 2571da177e4SLinus Torvalds tst r3, #PSR_I_BIT 2581da177e4SLinus Torvalds biceq r9, r9, #PSR_I_BIT 2591da177e4SLinus Torvalds msr cpsr_c, r9 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds @ 2621da177e4SLinus Torvalds @ set args, then call main handler 2631da177e4SLinus Torvalds @ 2641da177e4SLinus Torvalds @ r0 - address of faulting instruction 2651da177e4SLinus Torvalds @ r1 - pointer to registers on stack 2661da177e4SLinus Torvalds @ 2671da177e4SLinus Torvalds mov r0, r2 @ address (pc) 2681da177e4SLinus Torvalds mov r1, sp @ regs 2691da177e4SLinus Torvalds bl do_PrefetchAbort @ call abort handler 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds @ 2721da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 2731da177e4SLinus Torvalds @ 2741ec42c0cSRussell King disable_irq 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds @ 2771da177e4SLinus Torvalds @ restore SPSR and restart the instruction 2781da177e4SLinus Torvalds @ 2791da177e4SLinus Torvalds ldr r0, [sp, #S_PSR] 2801da177e4SLinus Torvalds msr spsr_cxsf, r0 2811da177e4SLinus Torvalds ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds .align 5 28449f680eaSRussell King.LCcralign: 28549f680eaSRussell King .word cr_alignment 2861da177e4SLinus Torvalds#ifdef MULTI_ABORT 2871da177e4SLinus Torvalds.LCprocfns: 2881da177e4SLinus Torvalds .word processor 2891da177e4SLinus Torvalds#endif 2901da177e4SLinus Torvalds.LCfp: 2911da177e4SLinus Torvalds .word fp_enter 2921da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 2931da177e4SLinus Torvalds.LCirq_stat: 2941da177e4SLinus Torvalds .word irq_stat 2951da177e4SLinus Torvalds#endif 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds/* 2981da177e4SLinus Torvalds * User mode handlers 2991da177e4SLinus Torvalds */ 300*ccea7a19SRussell King .macro usr_entry 301*ccea7a19SRussell King sub sp, sp, #S_FRAME_SIZE 302*ccea7a19SRussell King stmib sp, {r1 - r12} 303*ccea7a19SRussell King 304*ccea7a19SRussell King ldmia r0, {r1 - r3} 305*ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 306*ccea7a19SRussell King mov r4, #-1 @ "" "" "" "" 307*ccea7a19SRussell King 308*ccea7a19SRussell King str r1, [sp] @ save the "real" r0 copied 309*ccea7a19SRussell King @ from the exception stack 3101da177e4SLinus Torvalds 3112d2669b6SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6 3122d2669b6SNicolas Pitre @ make sure our user space atomic helper is aborted 3132d2669b6SNicolas Pitre cmp r2, #VIRT_OFFSET 3142d2669b6SNicolas Pitre bichs r3, r3, #PSR_Z_BIT 3152d2669b6SNicolas Pitre#endif 3162d2669b6SNicolas Pitre 3171da177e4SLinus Torvalds @ 3181da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 3191da177e4SLinus Torvalds @ 3201da177e4SLinus Torvalds @ r2 - lr_<exception>, already fixed up for correct return/restart 3211da177e4SLinus Torvalds @ r3 - spsr_<exception> 3221da177e4SLinus Torvalds @ r4 - orig_r0 (see pt_regs definition in ptrace.h) 3231da177e4SLinus Torvalds @ 3241da177e4SLinus Torvalds @ Also, separately save sp_usr and lr_usr 3251da177e4SLinus Torvalds @ 326*ccea7a19SRussell King stmia r0, {r2 - r4} 327*ccea7a19SRussell King stmdb r0, {sp, lr}^ 3281da177e4SLinus Torvalds 3291da177e4SLinus Torvalds @ 3301da177e4SLinus Torvalds @ Enable the alignment trap while in kernel mode 3311da177e4SLinus Torvalds @ 33249f680eaSRussell King alignment_trap r0 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds @ 3351da177e4SLinus Torvalds @ Clear FP to mark the first stack frame 3361da177e4SLinus Torvalds @ 3371da177e4SLinus Torvalds zero_fp 3381da177e4SLinus Torvalds .endm 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds .align 5 3411da177e4SLinus Torvalds__dabt_usr: 342*ccea7a19SRussell King usr_entry 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds @ 3451da177e4SLinus Torvalds @ Call the processor-specific abort handler: 3461da177e4SLinus Torvalds @ 3471da177e4SLinus Torvalds @ r2 - aborted context pc 3481da177e4SLinus Torvalds @ r3 - aborted context cpsr 3491da177e4SLinus Torvalds @ 3501da177e4SLinus Torvalds @ The abort handler must return the aborted address in r0, and 3511da177e4SLinus Torvalds @ the fault status register in r1. 3521da177e4SLinus Torvalds @ 3531da177e4SLinus Torvalds#ifdef MULTI_ABORT 3541da177e4SLinus Torvalds ldr r4, .LCprocfns 3551da177e4SLinus Torvalds mov lr, pc 3561da177e4SLinus Torvalds ldr pc, [r4] 3571da177e4SLinus Torvalds#else 3581da177e4SLinus Torvalds bl CPU_ABORT_HANDLER 3591da177e4SLinus Torvalds#endif 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds @ 3621da177e4SLinus Torvalds @ IRQs on, then call the main handler 3631da177e4SLinus Torvalds @ 3641ec42c0cSRussell King enable_irq 3651da177e4SLinus Torvalds mov r2, sp 3661da177e4SLinus Torvalds adr lr, ret_from_exception 3671da177e4SLinus Torvalds b do_DataAbort 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds .align 5 3701da177e4SLinus Torvalds__irq_usr: 371*ccea7a19SRussell King usr_entry 3721da177e4SLinus Torvalds 373706fdd9fSRussell King get_thread_info tsk 3741da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 375706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 376706fdd9fSRussell King add r7, r8, #1 @ increment it 377706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] 3781da177e4SLinus Torvalds#endif 379*ccea7a19SRussell King 380187a51adSRussell King irq_handler 3811da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 382706fdd9fSRussell King ldr r0, [tsk, #TI_PREEMPT] 383706fdd9fSRussell King str r8, [tsk, #TI_PREEMPT] 3841da177e4SLinus Torvalds teq r0, r7 3851da177e4SLinus Torvalds strne r0, [r0, -r0] 3861da177e4SLinus Torvalds#endif 387*ccea7a19SRussell King 3881da177e4SLinus Torvalds mov why, #0 3891da177e4SLinus Torvalds b ret_to_user 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds .ltorg 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds .align 5 3941da177e4SLinus Torvalds__und_usr: 395*ccea7a19SRussell King usr_entry 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds tst r3, #PSR_T_BIT @ Thumb mode? 3981da177e4SLinus Torvalds bne fpundefinstr @ ignore FP 3991da177e4SLinus Torvalds sub r4, r2, #4 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds @ 4021da177e4SLinus Torvalds @ fall through to the emulation code, which returns using r9 if 4031da177e4SLinus Torvalds @ it has emulated the instruction, or the more conventional lr 4041da177e4SLinus Torvalds @ if we are to treat this as a real undefined instruction 4051da177e4SLinus Torvalds @ 4061da177e4SLinus Torvalds @ r0 - instruction 4071da177e4SLinus Torvalds @ 4081da177e4SLinus Torvalds1: ldrt r0, [r4] 4091da177e4SLinus Torvalds adr r9, ret_from_exception 4101da177e4SLinus Torvalds adr lr, fpundefinstr 4111da177e4SLinus Torvalds @ 4121da177e4SLinus Torvalds @ fallthrough to call_fpe 4131da177e4SLinus Torvalds @ 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds/* 4161da177e4SLinus Torvalds * The out of line fixup for the ldrt above. 4171da177e4SLinus Torvalds */ 4181da177e4SLinus Torvalds .section .fixup, "ax" 4191da177e4SLinus Torvalds2: mov pc, r9 4201da177e4SLinus Torvalds .previous 4211da177e4SLinus Torvalds .section __ex_table,"a" 4221da177e4SLinus Torvalds .long 1b, 2b 4231da177e4SLinus Torvalds .previous 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds/* 4261da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction. 4271da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler. 4281da177e4SLinus Torvalds * 4291da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor 4301da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well 4311da177e4SLinus Torvalds * defined. The only instructions that should fault are the 4321da177e4SLinus Torvalds * co-processor instructions. However, we have to watch out 4331da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug. 4341da177e4SLinus Torvalds * 4351da177e4SLinus Torvalds * Emulators may wish to make use of the following registers: 4361da177e4SLinus Torvalds * r0 = instruction opcode. 4371da177e4SLinus Torvalds * r2 = PC+4 4381da177e4SLinus Torvalds * r10 = this threads thread_info structure. 4391da177e4SLinus Torvalds */ 4401da177e4SLinus Torvaldscall_fpe: 4411da177e4SLinus Torvalds tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27 4421da177e4SLinus Torvalds#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710) 4431da177e4SLinus Torvalds and r8, r0, #0x0f000000 @ mask out op-code bits 4441da177e4SLinus Torvalds teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)? 4451da177e4SLinus Torvalds#endif 4461da177e4SLinus Torvalds moveq pc, lr 4471da177e4SLinus Torvalds get_thread_info r10 @ get current thread 4481da177e4SLinus Torvalds and r8, r0, #0x00000f00 @ mask out CP number 4491da177e4SLinus Torvalds mov r7, #1 4501da177e4SLinus Torvalds add r6, r10, #TI_USED_CP 4511da177e4SLinus Torvalds strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[] 4521da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT 4531da177e4SLinus Torvalds @ Test if we need to give access to iWMMXt coprocessors 4541da177e4SLinus Torvalds ldr r5, [r10, #TI_FLAGS] 4551da177e4SLinus Torvalds rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only 4561da177e4SLinus Torvalds movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1) 4571da177e4SLinus Torvalds bcs iwmmxt_task_enable 4581da177e4SLinus Torvalds#endif 4591ec42c0cSRussell King enable_irq 4601da177e4SLinus Torvalds add pc, pc, r8, lsr #6 4611da177e4SLinus Torvalds mov r0, r0 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds mov pc, lr @ CP#0 4641da177e4SLinus Torvalds b do_fpe @ CP#1 (FPE) 4651da177e4SLinus Torvalds b do_fpe @ CP#2 (FPE) 4661da177e4SLinus Torvalds mov pc, lr @ CP#3 4671da177e4SLinus Torvalds mov pc, lr @ CP#4 4681da177e4SLinus Torvalds mov pc, lr @ CP#5 4691da177e4SLinus Torvalds mov pc, lr @ CP#6 4701da177e4SLinus Torvalds mov pc, lr @ CP#7 4711da177e4SLinus Torvalds mov pc, lr @ CP#8 4721da177e4SLinus Torvalds mov pc, lr @ CP#9 4731da177e4SLinus Torvalds#ifdef CONFIG_VFP 4741da177e4SLinus Torvalds b do_vfp @ CP#10 (VFP) 4751da177e4SLinus Torvalds b do_vfp @ CP#11 (VFP) 4761da177e4SLinus Torvalds#else 4771da177e4SLinus Torvalds mov pc, lr @ CP#10 (VFP) 4781da177e4SLinus Torvalds mov pc, lr @ CP#11 (VFP) 4791da177e4SLinus Torvalds#endif 4801da177e4SLinus Torvalds mov pc, lr @ CP#12 4811da177e4SLinus Torvalds mov pc, lr @ CP#13 4821da177e4SLinus Torvalds mov pc, lr @ CP#14 (Debug) 4831da177e4SLinus Torvalds mov pc, lr @ CP#15 (Control) 4841da177e4SLinus Torvalds 4851da177e4SLinus Torvaldsdo_fpe: 4861da177e4SLinus Torvalds ldr r4, .LCfp 4871da177e4SLinus Torvalds add r10, r10, #TI_FPSTATE @ r10 = workspace 4881da177e4SLinus Torvalds ldr pc, [r4] @ Call FP module USR entry point 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds/* 4911da177e4SLinus Torvalds * The FP module is called with these registers set: 4921da177e4SLinus Torvalds * r0 = instruction 4931da177e4SLinus Torvalds * r2 = PC+4 4941da177e4SLinus Torvalds * r9 = normal "successful" return address 4951da177e4SLinus Torvalds * r10 = FP workspace 4961da177e4SLinus Torvalds * lr = unrecognised FP instruction return address 4971da177e4SLinus Torvalds */ 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds .data 5001da177e4SLinus TorvaldsENTRY(fp_enter) 5011da177e4SLinus Torvalds .word fpundefinstr 5021da177e4SLinus Torvalds .text 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvaldsfpundefinstr: 5051da177e4SLinus Torvalds mov r0, sp 5061da177e4SLinus Torvalds adr lr, ret_from_exception 5071da177e4SLinus Torvalds b do_undefinstr 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds .align 5 5101da177e4SLinus Torvalds__pabt_usr: 511*ccea7a19SRussell King usr_entry 5121da177e4SLinus Torvalds 5131ec42c0cSRussell King enable_irq @ Enable interrupts 5141da177e4SLinus Torvalds mov r0, r2 @ address (pc) 5151da177e4SLinus Torvalds mov r1, sp @ regs 5161da177e4SLinus Torvalds bl do_PrefetchAbort @ call abort handler 5171da177e4SLinus Torvalds /* fall through */ 5181da177e4SLinus Torvalds/* 5191da177e4SLinus Torvalds * This is the return code to user mode for abort handlers 5201da177e4SLinus Torvalds */ 5211da177e4SLinus TorvaldsENTRY(ret_from_exception) 5221da177e4SLinus Torvalds get_thread_info tsk 5231da177e4SLinus Torvalds mov why, #0 5241da177e4SLinus Torvalds b ret_to_user 5251da177e4SLinus Torvalds 5261da177e4SLinus Torvalds/* 5271da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors 5281da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info 5291da177e4SLinus Torvalds * previous and next are guaranteed not to be the same. 5301da177e4SLinus Torvalds */ 5311da177e4SLinus TorvaldsENTRY(__switch_to) 5321da177e4SLinus Torvalds add ip, r1, #TI_CPU_SAVE 5331da177e4SLinus Torvalds ldr r3, [r2, #TI_TP_VALUE] 5341da177e4SLinus Torvalds stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack 5351da177e4SLinus Torvalds ldr r6, [r2, #TI_CPU_DOMAIN]! 5361da177e4SLinus Torvalds#if defined(CONFIG_CPU_XSCALE) && !defined(CONFIG_IWMMXT) 5371da177e4SLinus Torvalds mra r4, r5, acc0 5381da177e4SLinus Torvalds stmia ip, {r4, r5} 5391da177e4SLinus Torvalds#endif 5404b0e07a5SNicolas Pitre#if defined(CONFIG_HAS_TLS_REG) 5412d2669b6SNicolas Pitre mcr p15, 0, r3, c13, c0, 3 @ set TLS register 5424b0e07a5SNicolas Pitre#elif !defined(CONFIG_TLS_REG_EMUL) 5431da177e4SLinus Torvalds mov r4, #0xffff0fff 5442d2669b6SNicolas Pitre str r3, [r4, #-15] @ TLS val at 0xffff0ff0 5452d2669b6SNicolas Pitre#endif 5461da177e4SLinus Torvalds mcr p15, 0, r6, c3, c0, 0 @ Set domain register 5471da177e4SLinus Torvalds#ifdef CONFIG_VFP 5481da177e4SLinus Torvalds @ Always disable VFP so we can lazily save/restore the old 5491da177e4SLinus Torvalds @ state. This occurs in the context of the previous thread. 5501da177e4SLinus Torvalds VFPFMRX r4, FPEXC 5511da177e4SLinus Torvalds bic r4, r4, #FPEXC_ENABLE 5521da177e4SLinus Torvalds VFPFMXR FPEXC, r4 5531da177e4SLinus Torvalds#endif 5541da177e4SLinus Torvalds#if defined(CONFIG_IWMMXT) 5551da177e4SLinus Torvalds bl iwmmxt_task_switch 5561da177e4SLinus Torvalds#elif defined(CONFIG_CPU_XSCALE) 5571da177e4SLinus Torvalds add r4, r2, #40 @ cpu_context_save->extra 5581da177e4SLinus Torvalds ldmib r4, {r4, r5} 5591da177e4SLinus Torvalds mar acc0, r4, r5 5601da177e4SLinus Torvalds#endif 5611da177e4SLinus Torvalds ldmib r2, {r4 - sl, fp, sp, pc} @ Load all regs saved previously 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds __INIT 5642d2669b6SNicolas Pitre 5652d2669b6SNicolas Pitre/* 5662d2669b6SNicolas Pitre * User helpers. 5672d2669b6SNicolas Pitre * 5682d2669b6SNicolas Pitre * These are segment of kernel provided user code reachable from user space 5692d2669b6SNicolas Pitre * at a fixed address in kernel memory. This is used to provide user space 5702d2669b6SNicolas Pitre * with some operations which require kernel help because of unimplemented 5712d2669b6SNicolas Pitre * native feature and/or instructions in many ARM CPUs. The idea is for 5722d2669b6SNicolas Pitre * this code to be executed directly in user mode for best efficiency but 5732d2669b6SNicolas Pitre * which is too intimate with the kernel counter part to be left to user 5742d2669b6SNicolas Pitre * libraries. In fact this code might even differ from one CPU to another 5752d2669b6SNicolas Pitre * depending on the available instruction set and restrictions like on 5762d2669b6SNicolas Pitre * SMP systems. In other words, the kernel reserves the right to change 5772d2669b6SNicolas Pitre * this code as needed without warning. Only the entry points and their 5782d2669b6SNicolas Pitre * results are guaranteed to be stable. 5792d2669b6SNicolas Pitre * 5802d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high 5812d2669b6SNicolas Pitre * vector page. New segments (if ever needed) must be added in front of 5822d2669b6SNicolas Pitre * existing ones. This mechanism should be used only for things that are 5832d2669b6SNicolas Pitre * really small and justified, and not be abused freely. 5842d2669b6SNicolas Pitre * 5852d2669b6SNicolas Pitre * User space is expected to implement those things inline when optimizing 5862d2669b6SNicolas Pitre * for a processor that has the necessary native support, but only if such 5872d2669b6SNicolas Pitre * resulting binaries are already to be incompatible with earlier ARM 5882d2669b6SNicolas Pitre * processors due to the use of unsupported instructions other than what 5892d2669b6SNicolas Pitre * is provided here. In other words don't make binaries unable to run on 5902d2669b6SNicolas Pitre * earlier processors just for the sake of not using these kernel helpers 5912d2669b6SNicolas Pitre * if your compiled code is not going to use the new instructions for other 5922d2669b6SNicolas Pitre * purpose. 5932d2669b6SNicolas Pitre */ 5942d2669b6SNicolas Pitre 5952d2669b6SNicolas Pitre .align 5 5962d2669b6SNicolas Pitre .globl __kuser_helper_start 5972d2669b6SNicolas Pitre__kuser_helper_start: 5982d2669b6SNicolas Pitre 5992d2669b6SNicolas Pitre/* 6002d2669b6SNicolas Pitre * Reference prototype: 6012d2669b6SNicolas Pitre * 6022d2669b6SNicolas Pitre * int __kernel_cmpxchg(int oldval, int newval, int *ptr) 6032d2669b6SNicolas Pitre * 6042d2669b6SNicolas Pitre * Input: 6052d2669b6SNicolas Pitre * 6062d2669b6SNicolas Pitre * r0 = oldval 6072d2669b6SNicolas Pitre * r1 = newval 6082d2669b6SNicolas Pitre * r2 = ptr 6092d2669b6SNicolas Pitre * lr = return address 6102d2669b6SNicolas Pitre * 6112d2669b6SNicolas Pitre * Output: 6122d2669b6SNicolas Pitre * 6132d2669b6SNicolas Pitre * r0 = returned value (zero or non-zero) 6142d2669b6SNicolas Pitre * C flag = set if r0 == 0, clear if r0 != 0 6152d2669b6SNicolas Pitre * 6162d2669b6SNicolas Pitre * Clobbered: 6172d2669b6SNicolas Pitre * 6182d2669b6SNicolas Pitre * r3, ip, flags 6192d2669b6SNicolas Pitre * 6202d2669b6SNicolas Pitre * Definition and user space usage example: 6212d2669b6SNicolas Pitre * 6222d2669b6SNicolas Pitre * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr); 6232d2669b6SNicolas Pitre * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0) 6242d2669b6SNicolas Pitre * 6252d2669b6SNicolas Pitre * Atomically store newval in *ptr if *ptr is equal to oldval for user space. 6262d2669b6SNicolas Pitre * Return zero if *ptr was changed or non-zero if no exchange happened. 6272d2669b6SNicolas Pitre * The C flag is also set if *ptr was changed to allow for assembly 6282d2669b6SNicolas Pitre * optimization in the calling code. 6292d2669b6SNicolas Pitre * 6302d2669b6SNicolas Pitre * For example, a user space atomic_add implementation could look like this: 6312d2669b6SNicolas Pitre * 6322d2669b6SNicolas Pitre * #define atomic_add(ptr, val) \ 6332d2669b6SNicolas Pitre * ({ register unsigned int *__ptr asm("r2") = (ptr); \ 6342d2669b6SNicolas Pitre * register unsigned int __result asm("r1"); \ 6352d2669b6SNicolas Pitre * asm volatile ( \ 6362d2669b6SNicolas Pitre * "1: @ atomic_add\n\t" \ 6372d2669b6SNicolas Pitre * "ldr r0, [r2]\n\t" \ 6382d2669b6SNicolas Pitre * "mov r3, #0xffff0fff\n\t" \ 6392d2669b6SNicolas Pitre * "add lr, pc, #4\n\t" \ 6402d2669b6SNicolas Pitre * "add r1, r0, %2\n\t" \ 6412d2669b6SNicolas Pitre * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \ 6422d2669b6SNicolas Pitre * "bcc 1b" \ 6432d2669b6SNicolas Pitre * : "=&r" (__result) \ 6442d2669b6SNicolas Pitre * : "r" (__ptr), "rIL" (val) \ 6452d2669b6SNicolas Pitre * : "r0","r3","ip","lr","cc","memory" ); \ 6462d2669b6SNicolas Pitre * __result; }) 6472d2669b6SNicolas Pitre */ 6482d2669b6SNicolas Pitre 6492d2669b6SNicolas Pitre__kuser_cmpxchg: @ 0xffff0fc0 6502d2669b6SNicolas Pitre 6512d2669b6SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6 6522d2669b6SNicolas Pitre 6532d2669b6SNicolas Pitre#ifdef CONFIG_SMP /* sanity check */ 6542d2669b6SNicolas Pitre#error "CONFIG_SMP on a machine supporting pre-ARMv6 processors?" 6552d2669b6SNicolas Pitre#endif 6562d2669b6SNicolas Pitre 6572d2669b6SNicolas Pitre /* 6582d2669b6SNicolas Pitre * Theory of operation: 6592d2669b6SNicolas Pitre * 6602d2669b6SNicolas Pitre * We set the Z flag before loading oldval. If ever an exception 6612d2669b6SNicolas Pitre * occurs we can not be sure the loaded value will still be the same 6622d2669b6SNicolas Pitre * when the exception returns, therefore the user exception handler 6632d2669b6SNicolas Pitre * will clear the Z flag whenever the interrupted user code was 6642d2669b6SNicolas Pitre * actually from the kernel address space (see the usr_entry macro). 6652d2669b6SNicolas Pitre * 6662d2669b6SNicolas Pitre * The post-increment on the str is used to prevent a race with an 6672d2669b6SNicolas Pitre * exception happening just after the str instruction which would 6682d2669b6SNicolas Pitre * clear the Z flag although the exchange was done. 6692d2669b6SNicolas Pitre */ 6702d2669b6SNicolas Pitre teq ip, ip @ set Z flag 6712d2669b6SNicolas Pitre ldr ip, [r2] @ load current val 6722d2669b6SNicolas Pitre add r3, r2, #1 @ prepare store ptr 6732d2669b6SNicolas Pitre teqeq ip, r0 @ compare with oldval if still allowed 6742d2669b6SNicolas Pitre streq r1, [r3, #-1]! @ store newval if still allowed 6752d2669b6SNicolas Pitre subs r0, r2, r3 @ if r2 == r3 the str occured 6762d2669b6SNicolas Pitre mov pc, lr 6772d2669b6SNicolas Pitre 6782d2669b6SNicolas Pitre#else 6792d2669b6SNicolas Pitre 6802d2669b6SNicolas Pitre ldrex r3, [r2] 6812d2669b6SNicolas Pitre subs r3, r3, r0 6822d2669b6SNicolas Pitre strexeq r3, r1, [r2] 6832d2669b6SNicolas Pitre rsbs r0, r3, #0 6842d2669b6SNicolas Pitre mov pc, lr 6852d2669b6SNicolas Pitre 6862d2669b6SNicolas Pitre#endif 6872d2669b6SNicolas Pitre 6882d2669b6SNicolas Pitre .align 5 6892d2669b6SNicolas Pitre 6902d2669b6SNicolas Pitre/* 6912d2669b6SNicolas Pitre * Reference prototype: 6922d2669b6SNicolas Pitre * 6932d2669b6SNicolas Pitre * int __kernel_get_tls(void) 6942d2669b6SNicolas Pitre * 6952d2669b6SNicolas Pitre * Input: 6962d2669b6SNicolas Pitre * 6972d2669b6SNicolas Pitre * lr = return address 6982d2669b6SNicolas Pitre * 6992d2669b6SNicolas Pitre * Output: 7002d2669b6SNicolas Pitre * 7012d2669b6SNicolas Pitre * r0 = TLS value 7022d2669b6SNicolas Pitre * 7032d2669b6SNicolas Pitre * Clobbered: 7042d2669b6SNicolas Pitre * 7052d2669b6SNicolas Pitre * the Z flag might be lost 7062d2669b6SNicolas Pitre * 7072d2669b6SNicolas Pitre * Definition and user space usage example: 7082d2669b6SNicolas Pitre * 7092d2669b6SNicolas Pitre * typedef int (__kernel_get_tls_t)(void); 7102d2669b6SNicolas Pitre * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0) 7112d2669b6SNicolas Pitre * 7122d2669b6SNicolas Pitre * Get the TLS value as previously set via the __ARM_NR_set_tls syscall. 7132d2669b6SNicolas Pitre * 7142d2669b6SNicolas Pitre * This could be used as follows: 7152d2669b6SNicolas Pitre * 7162d2669b6SNicolas Pitre * #define __kernel_get_tls() \ 7172d2669b6SNicolas Pitre * ({ register unsigned int __val asm("r0"); \ 7182d2669b6SNicolas Pitre * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \ 7192d2669b6SNicolas Pitre * : "=r" (__val) : : "lr","cc" ); \ 7202d2669b6SNicolas Pitre * __val; }) 7212d2669b6SNicolas Pitre */ 7222d2669b6SNicolas Pitre 7232d2669b6SNicolas Pitre__kuser_get_tls: @ 0xffff0fe0 7242d2669b6SNicolas Pitre 7254b0e07a5SNicolas Pitre#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL) 7262d2669b6SNicolas Pitre 7272d2669b6SNicolas Pitre ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0 7282d2669b6SNicolas Pitre mov pc, lr 7292d2669b6SNicolas Pitre 7302d2669b6SNicolas Pitre#else 7312d2669b6SNicolas Pitre 7322d2669b6SNicolas Pitre mrc p15, 0, r0, c13, c0, 3 @ read TLS register 7332d2669b6SNicolas Pitre mov pc, lr 7342d2669b6SNicolas Pitre 7352d2669b6SNicolas Pitre#endif 7362d2669b6SNicolas Pitre 7372d2669b6SNicolas Pitre .rep 5 7382d2669b6SNicolas Pitre .word 0 @ pad up to __kuser_helper_version 7392d2669b6SNicolas Pitre .endr 7402d2669b6SNicolas Pitre 7412d2669b6SNicolas Pitre/* 7422d2669b6SNicolas Pitre * Reference declaration: 7432d2669b6SNicolas Pitre * 7442d2669b6SNicolas Pitre * extern unsigned int __kernel_helper_version; 7452d2669b6SNicolas Pitre * 7462d2669b6SNicolas Pitre * Definition and user space usage example: 7472d2669b6SNicolas Pitre * 7482d2669b6SNicolas Pitre * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc) 7492d2669b6SNicolas Pitre * 7502d2669b6SNicolas Pitre * User space may read this to determine the curent number of helpers 7512d2669b6SNicolas Pitre * available. 7522d2669b6SNicolas Pitre */ 7532d2669b6SNicolas Pitre 7542d2669b6SNicolas Pitre__kuser_helper_version: @ 0xffff0ffc 7552d2669b6SNicolas Pitre .word ((__kuser_helper_end - __kuser_helper_start) >> 5) 7562d2669b6SNicolas Pitre 7572d2669b6SNicolas Pitre .globl __kuser_helper_end 7582d2669b6SNicolas Pitre__kuser_helper_end: 7592d2669b6SNicolas Pitre 7602d2669b6SNicolas Pitre 7611da177e4SLinus Torvalds/* 7621da177e4SLinus Torvalds * Vector stubs. 7631da177e4SLinus Torvalds * 7647933523dSRussell King * This code is copied to 0xffff0200 so we can use branches in the 7657933523dSRussell King * vectors, rather than ldr's. Note that this code must not 7667933523dSRussell King * exceed 0x300 bytes. 7671da177e4SLinus Torvalds * 7681da177e4SLinus Torvalds * Common stub entry macro: 7691da177e4SLinus Torvalds * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 770*ccea7a19SRussell King * 771*ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address 772*ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler. 7731da177e4SLinus Torvalds */ 774*ccea7a19SRussell King .macro vector_stub, name, correction=0 7751da177e4SLinus Torvalds .align 5 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvaldsvector_\name: 7781da177e4SLinus Torvalds .if \correction 7791da177e4SLinus Torvalds sub lr, lr, #\correction 7801da177e4SLinus Torvalds .endif 7811da177e4SLinus Torvalds 782*ccea7a19SRussell King @ 783*ccea7a19SRussell King @ Save r0, lr_<exception> (parent PC) and spsr_<exception> 784*ccea7a19SRussell King @ (parent CPSR) 785*ccea7a19SRussell King @ 786*ccea7a19SRussell King stmia sp, {r0, lr} @ save r0, lr 787*ccea7a19SRussell King mrs lr, spsr 788*ccea7a19SRussell King str lr, [sp, #8] @ save spsr 789*ccea7a19SRussell King 790*ccea7a19SRussell King @ 791*ccea7a19SRussell King @ Prepare for SVC32 mode. IRQs remain disabled. 792*ccea7a19SRussell King @ 793*ccea7a19SRussell King mrs r0, cpsr 794*ccea7a19SRussell King bic r0, r0, #MODE_MASK 795*ccea7a19SRussell King orr r0, r0, #SVC_MODE 796*ccea7a19SRussell King msr spsr_cxsf, r0 797*ccea7a19SRussell King 798*ccea7a19SRussell King @ 799*ccea7a19SRussell King @ the branch table must immediately follow this code 800*ccea7a19SRussell King @ 801*ccea7a19SRussell King mov r0, sp 802*ccea7a19SRussell King and lr, lr, #0x0f 8031da177e4SLinus Torvalds ldr lr, [pc, lr, lsl #2] 804*ccea7a19SRussell King movs pc, lr @ branch to handler in SVC mode 8051da177e4SLinus Torvalds .endm 8061da177e4SLinus Torvalds 8077933523dSRussell King .globl __stubs_start 8081da177e4SLinus Torvalds__stubs_start: 8091da177e4SLinus Torvalds/* 8101da177e4SLinus Torvalds * Interrupt dispatcher 8111da177e4SLinus Torvalds */ 812*ccea7a19SRussell King vector_stub irq, 4 8131da177e4SLinus Torvalds 8141da177e4SLinus Torvalds .long __irq_usr @ 0 (USR_26 / USR_32) 8151da177e4SLinus Torvalds .long __irq_invalid @ 1 (FIQ_26 / FIQ_32) 8161da177e4SLinus Torvalds .long __irq_invalid @ 2 (IRQ_26 / IRQ_32) 8171da177e4SLinus Torvalds .long __irq_svc @ 3 (SVC_26 / SVC_32) 8181da177e4SLinus Torvalds .long __irq_invalid @ 4 8191da177e4SLinus Torvalds .long __irq_invalid @ 5 8201da177e4SLinus Torvalds .long __irq_invalid @ 6 8211da177e4SLinus Torvalds .long __irq_invalid @ 7 8221da177e4SLinus Torvalds .long __irq_invalid @ 8 8231da177e4SLinus Torvalds .long __irq_invalid @ 9 8241da177e4SLinus Torvalds .long __irq_invalid @ a 8251da177e4SLinus Torvalds .long __irq_invalid @ b 8261da177e4SLinus Torvalds .long __irq_invalid @ c 8271da177e4SLinus Torvalds .long __irq_invalid @ d 8281da177e4SLinus Torvalds .long __irq_invalid @ e 8291da177e4SLinus Torvalds .long __irq_invalid @ f 8301da177e4SLinus Torvalds 8311da177e4SLinus Torvalds/* 8321da177e4SLinus Torvalds * Data abort dispatcher 8331da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 8341da177e4SLinus Torvalds */ 835*ccea7a19SRussell King vector_stub dabt, 8 8361da177e4SLinus Torvalds 8371da177e4SLinus Torvalds .long __dabt_usr @ 0 (USR_26 / USR_32) 8381da177e4SLinus Torvalds .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32) 8391da177e4SLinus Torvalds .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32) 8401da177e4SLinus Torvalds .long __dabt_svc @ 3 (SVC_26 / SVC_32) 8411da177e4SLinus Torvalds .long __dabt_invalid @ 4 8421da177e4SLinus Torvalds .long __dabt_invalid @ 5 8431da177e4SLinus Torvalds .long __dabt_invalid @ 6 8441da177e4SLinus Torvalds .long __dabt_invalid @ 7 8451da177e4SLinus Torvalds .long __dabt_invalid @ 8 8461da177e4SLinus Torvalds .long __dabt_invalid @ 9 8471da177e4SLinus Torvalds .long __dabt_invalid @ a 8481da177e4SLinus Torvalds .long __dabt_invalid @ b 8491da177e4SLinus Torvalds .long __dabt_invalid @ c 8501da177e4SLinus Torvalds .long __dabt_invalid @ d 8511da177e4SLinus Torvalds .long __dabt_invalid @ e 8521da177e4SLinus Torvalds .long __dabt_invalid @ f 8531da177e4SLinus Torvalds 8541da177e4SLinus Torvalds/* 8551da177e4SLinus Torvalds * Prefetch abort dispatcher 8561da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 8571da177e4SLinus Torvalds */ 858*ccea7a19SRussell King vector_stub pabt, 4 8591da177e4SLinus Torvalds 8601da177e4SLinus Torvalds .long __pabt_usr @ 0 (USR_26 / USR_32) 8611da177e4SLinus Torvalds .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32) 8621da177e4SLinus Torvalds .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32) 8631da177e4SLinus Torvalds .long __pabt_svc @ 3 (SVC_26 / SVC_32) 8641da177e4SLinus Torvalds .long __pabt_invalid @ 4 8651da177e4SLinus Torvalds .long __pabt_invalid @ 5 8661da177e4SLinus Torvalds .long __pabt_invalid @ 6 8671da177e4SLinus Torvalds .long __pabt_invalid @ 7 8681da177e4SLinus Torvalds .long __pabt_invalid @ 8 8691da177e4SLinus Torvalds .long __pabt_invalid @ 9 8701da177e4SLinus Torvalds .long __pabt_invalid @ a 8711da177e4SLinus Torvalds .long __pabt_invalid @ b 8721da177e4SLinus Torvalds .long __pabt_invalid @ c 8731da177e4SLinus Torvalds .long __pabt_invalid @ d 8741da177e4SLinus Torvalds .long __pabt_invalid @ e 8751da177e4SLinus Torvalds .long __pabt_invalid @ f 8761da177e4SLinus Torvalds 8771da177e4SLinus Torvalds/* 8781da177e4SLinus Torvalds * Undef instr entry dispatcher 8791da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 8801da177e4SLinus Torvalds */ 881*ccea7a19SRussell King vector_stub und 8821da177e4SLinus Torvalds 8831da177e4SLinus Torvalds .long __und_usr @ 0 (USR_26 / USR_32) 8841da177e4SLinus Torvalds .long __und_invalid @ 1 (FIQ_26 / FIQ_32) 8851da177e4SLinus Torvalds .long __und_invalid @ 2 (IRQ_26 / IRQ_32) 8861da177e4SLinus Torvalds .long __und_svc @ 3 (SVC_26 / SVC_32) 8871da177e4SLinus Torvalds .long __und_invalid @ 4 8881da177e4SLinus Torvalds .long __und_invalid @ 5 8891da177e4SLinus Torvalds .long __und_invalid @ 6 8901da177e4SLinus Torvalds .long __und_invalid @ 7 8911da177e4SLinus Torvalds .long __und_invalid @ 8 8921da177e4SLinus Torvalds .long __und_invalid @ 9 8931da177e4SLinus Torvalds .long __und_invalid @ a 8941da177e4SLinus Torvalds .long __und_invalid @ b 8951da177e4SLinus Torvalds .long __und_invalid @ c 8961da177e4SLinus Torvalds .long __und_invalid @ d 8971da177e4SLinus Torvalds .long __und_invalid @ e 8981da177e4SLinus Torvalds .long __und_invalid @ f 8991da177e4SLinus Torvalds 9001da177e4SLinus Torvalds .align 5 9011da177e4SLinus Torvalds 9021da177e4SLinus Torvalds/*============================================================================= 9031da177e4SLinus Torvalds * Undefined FIQs 9041da177e4SLinus Torvalds *----------------------------------------------------------------------------- 9051da177e4SLinus Torvalds * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC 9061da177e4SLinus Torvalds * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg. 9071da177e4SLinus Torvalds * Basically to switch modes, we *HAVE* to clobber one register... brain 9081da177e4SLinus Torvalds * damage alert! I don't think that we can execute any code in here in any 9091da177e4SLinus Torvalds * other mode than FIQ... Ok you can switch to another mode, but you can't 9101da177e4SLinus Torvalds * get out of that mode without clobbering one register. 9111da177e4SLinus Torvalds */ 9121da177e4SLinus Torvaldsvector_fiq: 9131da177e4SLinus Torvalds disable_fiq 9141da177e4SLinus Torvalds subs pc, lr, #4 9151da177e4SLinus Torvalds 9161da177e4SLinus Torvalds/*============================================================================= 9171da177e4SLinus Torvalds * Address exception handler 9181da177e4SLinus Torvalds *----------------------------------------------------------------------------- 9191da177e4SLinus Torvalds * These aren't too critical. 9201da177e4SLinus Torvalds * (they're not supposed to happen, and won't happen in 32-bit data mode). 9211da177e4SLinus Torvalds */ 9221da177e4SLinus Torvalds 9231da177e4SLinus Torvaldsvector_addrexcptn: 9241da177e4SLinus Torvalds b vector_addrexcptn 9251da177e4SLinus Torvalds 9261da177e4SLinus Torvalds/* 9271da177e4SLinus Torvalds * We group all the following data together to optimise 9281da177e4SLinus Torvalds * for CPUs with separate I & D caches. 9291da177e4SLinus Torvalds */ 9301da177e4SLinus Torvalds .align 5 9311da177e4SLinus Torvalds 9321da177e4SLinus Torvalds.LCvswi: 9331da177e4SLinus Torvalds .word vector_swi 9341da177e4SLinus Torvalds 9357933523dSRussell King .globl __stubs_end 9361da177e4SLinus Torvalds__stubs_end: 9371da177e4SLinus Torvalds 9387933523dSRussell King .equ stubs_offset, __vectors_start + 0x200 - __stubs_start 9391da177e4SLinus Torvalds 9407933523dSRussell King .globl __vectors_start 9417933523dSRussell King__vectors_start: 9421da177e4SLinus Torvalds swi SYS_ERROR0 9437933523dSRussell King b vector_und + stubs_offset 9447933523dSRussell King ldr pc, .LCvswi + stubs_offset 9457933523dSRussell King b vector_pabt + stubs_offset 9467933523dSRussell King b vector_dabt + stubs_offset 9477933523dSRussell King b vector_addrexcptn + stubs_offset 9487933523dSRussell King b vector_irq + stubs_offset 9497933523dSRussell King b vector_fiq + stubs_offset 9501da177e4SLinus Torvalds 9517933523dSRussell King .globl __vectors_end 9527933523dSRussell King__vectors_end: 9531da177e4SLinus Torvalds 9541da177e4SLinus Torvalds .data 9551da177e4SLinus Torvalds 9561da177e4SLinus Torvalds .globl cr_alignment 9571da177e4SLinus Torvalds .globl cr_no_alignment 9581da177e4SLinus Torvaldscr_alignment: 9591da177e4SLinus Torvalds .space 4 9601da177e4SLinus Torvaldscr_no_alignment: 9611da177e4SLinus Torvalds .space 4 962