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) 6afeb90caSHyok S. Choi * nommu support by Hyok S. Choi (hyok.choi@samsung.com) 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 91da177e4SLinus Torvalds * it under the terms of the GNU General Public License version 2 as 101da177e4SLinus Torvalds * published by the Free Software Foundation. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Low-level vector interface routines 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction that causes 151da177e4SLinus Torvalds * it to save wrong values... Be aware! 161da177e4SLinus Torvalds */ 171da177e4SLinus Torvalds#include <linux/config.h> 181da177e4SLinus Torvalds 19f09b9979SNicolas Pitre#include <asm/memory.h> 201da177e4SLinus Torvalds#include <asm/glue.h> 211da177e4SLinus Torvalds#include <asm/vfpmacros.h> 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 4937ee16aeSRussell King 5037ee16aeSRussell King#ifdef CONFIG_LOCAL_TIMERS 5137ee16aeSRussell King test_for_ltirq r0, r6, r5, lr 5237ee16aeSRussell King movne r0, sp 5337ee16aeSRussell King adrne lr, 1b 5437ee16aeSRussell King bne do_local_timer 5537ee16aeSRussell King#endif 56791be9b9SRussell King#endif 57791be9b9SRussell King 58187a51adSRussell King .endm 59187a51adSRussell King 60187a51adSRussell King/* 611da177e4SLinus Torvalds * Invalid mode handlers 621da177e4SLinus Torvalds */ 63ccea7a19SRussell King .macro inv_entry, reason 64ccea7a19SRussell King sub sp, sp, #S_FRAME_SIZE 65ccea7a19SRussell King stmib sp, {r1 - lr} 661da177e4SLinus Torvalds mov r1, #\reason 671da177e4SLinus Torvalds .endm 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds__pabt_invalid: 70ccea7a19SRussell King inv_entry BAD_PREFETCH 71ccea7a19SRussell King b common_invalid 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds__dabt_invalid: 74ccea7a19SRussell King inv_entry BAD_DATA 75ccea7a19SRussell King b common_invalid 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds__irq_invalid: 78ccea7a19SRussell King inv_entry BAD_IRQ 79ccea7a19SRussell King b common_invalid 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds__und_invalid: 82ccea7a19SRussell King inv_entry BAD_UNDEFINSTR 831da177e4SLinus Torvalds 84ccea7a19SRussell King @ 85ccea7a19SRussell King @ XXX fall through to common_invalid 86ccea7a19SRussell King @ 87ccea7a19SRussell King 88ccea7a19SRussell King@ 89ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers) 90ccea7a19SRussell King@ 91ccea7a19SRussell Kingcommon_invalid: 92ccea7a19SRussell King zero_fp 93ccea7a19SRussell King 94ccea7a19SRussell King ldmia r0, {r4 - r6} 95ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 96ccea7a19SRussell King mov r7, #-1 @ "" "" "" "" 97ccea7a19SRussell King str r4, [sp] @ save preserved r0 98ccea7a19SRussell King stmia r0, {r5 - r7} @ lr_<exception>, 99ccea7a19SRussell King @ cpsr_<exception>, "old_r0" 100ccea7a19SRussell King 1011da177e4SLinus Torvalds mov r0, sp 102ccea7a19SRussell King and r2, r6, #0x1f 1031da177e4SLinus Torvalds b bad_mode 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds/* 1061da177e4SLinus Torvalds * SVC mode handlers 1071da177e4SLinus Torvalds */ 108*2dede2d8SNicolas Pitre 109*2dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) 110*2dede2d8SNicolas Pitre#define SPFIX(code...) code 111*2dede2d8SNicolas Pitre#else 112*2dede2d8SNicolas Pitre#define SPFIX(code...) 113*2dede2d8SNicolas Pitre#endif 114*2dede2d8SNicolas Pitre 115ccea7a19SRussell King .macro svc_entry 1161da177e4SLinus Torvalds sub sp, sp, #S_FRAME_SIZE 117*2dede2d8SNicolas Pitre SPFIX( tst sp, #4 ) 118*2dede2d8SNicolas Pitre SPFIX( bicne sp, sp, #4 ) 119ccea7a19SRussell King stmib sp, {r1 - r12} 120ccea7a19SRussell King 121ccea7a19SRussell King ldmia r0, {r1 - r3} 122ccea7a19SRussell King add r5, sp, #S_SP @ here for interlock avoidance 123ccea7a19SRussell King mov r4, #-1 @ "" "" "" "" 124ccea7a19SRussell King add r0, sp, #S_FRAME_SIZE @ "" "" "" "" 125*2dede2d8SNicolas Pitre SPFIX( addne r0, r0, #4 ) 126ccea7a19SRussell King str r1, [sp] @ save the "real" r0 copied 127ccea7a19SRussell King @ from the exception stack 128ccea7a19SRussell King 1291da177e4SLinus Torvalds mov r1, lr 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds @ 1321da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 1331da177e4SLinus Torvalds @ 1341da177e4SLinus Torvalds @ r0 - sp_svc 1351da177e4SLinus Torvalds @ r1 - lr_svc 1361da177e4SLinus Torvalds @ r2 - lr_<exception>, already fixed up for correct return/restart 1371da177e4SLinus Torvalds @ r3 - spsr_<exception> 1381da177e4SLinus Torvalds @ r4 - orig_r0 (see pt_regs definition in ptrace.h) 1391da177e4SLinus Torvalds @ 1401da177e4SLinus Torvalds stmia r5, {r0 - r4} 1411da177e4SLinus Torvalds .endm 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds .align 5 1441da177e4SLinus Torvalds__dabt_svc: 145ccea7a19SRussell King svc_entry 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds @ 1481da177e4SLinus Torvalds @ get ready to re-enable interrupts if appropriate 1491da177e4SLinus Torvalds @ 1501da177e4SLinus Torvalds mrs r9, cpsr 1511da177e4SLinus Torvalds tst r3, #PSR_I_BIT 1521da177e4SLinus Torvalds biceq r9, r9, #PSR_I_BIT 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds @ 1551da177e4SLinus Torvalds @ Call the processor-specific abort handler: 1561da177e4SLinus Torvalds @ 1571da177e4SLinus Torvalds @ r2 - aborted context pc 1581da177e4SLinus Torvalds @ r3 - aborted context cpsr 1591da177e4SLinus Torvalds @ 1601da177e4SLinus Torvalds @ The abort handler must return the aborted address in r0, and 1611da177e4SLinus Torvalds @ the fault status register in r1. r9 must be preserved. 1621da177e4SLinus Torvalds @ 1631da177e4SLinus Torvalds#ifdef MULTI_ABORT 1641da177e4SLinus Torvalds ldr r4, .LCprocfns 1651da177e4SLinus Torvalds mov lr, pc 1661da177e4SLinus Torvalds ldr pc, [r4] 1671da177e4SLinus Torvalds#else 1681da177e4SLinus Torvalds bl CPU_ABORT_HANDLER 1691da177e4SLinus Torvalds#endif 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds @ 1721da177e4SLinus Torvalds @ set desired IRQ state, then call main handler 1731da177e4SLinus Torvalds @ 1741da177e4SLinus Torvalds msr cpsr_c, r9 1751da177e4SLinus Torvalds mov r2, sp 1761da177e4SLinus Torvalds bl do_DataAbort 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds @ 1791da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 1801da177e4SLinus Torvalds @ 1811ec42c0cSRussell King disable_irq 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds @ 1841da177e4SLinus Torvalds @ restore SPSR and restart the instruction 1851da177e4SLinus Torvalds @ 1861da177e4SLinus Torvalds ldr r0, [sp, #S_PSR] 1871da177e4SLinus Torvalds msr spsr_cxsf, r0 1881da177e4SLinus Torvalds ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds .align 5 1911da177e4SLinus Torvalds__irq_svc: 192ccea7a19SRussell King svc_entry 193ccea7a19SRussell King 1941da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 195706fdd9fSRussell King get_thread_info tsk 196706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 197706fdd9fSRussell King add r7, r8, #1 @ increment it 198706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] 1991da177e4SLinus Torvalds#endif 200ccea7a19SRussell King 201187a51adSRussell King irq_handler 2021da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 203706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get flags 2041da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2051da177e4SLinus Torvalds blne svc_preempt 2061da177e4SLinus Torvaldspreempt_return: 207706fdd9fSRussell King ldr r0, [tsk, #TI_PREEMPT] @ read preempt value 208706fdd9fSRussell King str r8, [tsk, #TI_PREEMPT] @ restore preempt count 2091da177e4SLinus Torvalds teq r0, r7 2101da177e4SLinus Torvalds strne r0, [r0, -r0] @ bug() 2111da177e4SLinus Torvalds#endif 2121da177e4SLinus Torvalds ldr r0, [sp, #S_PSR] @ irqs are already disabled 2131da177e4SLinus Torvalds msr spsr_cxsf, r0 2141da177e4SLinus Torvalds ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds .ltorg 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 2191da177e4SLinus Torvaldssvc_preempt: 220706fdd9fSRussell King teq r8, #0 @ was preempt count = 0 2211da177e4SLinus Torvalds ldreq r6, .LCirq_stat 2221da177e4SLinus Torvalds movne pc, lr @ no 2231da177e4SLinus Torvalds ldr r0, [r6, #4] @ local_irq_count 2241da177e4SLinus Torvalds ldr r1, [r6, #8] @ local_bh_count 2251da177e4SLinus Torvalds adds r0, r0, r1 2261da177e4SLinus Torvalds movne pc, lr 2271da177e4SLinus Torvalds mov r7, #0 @ preempt_schedule_irq 228706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] @ expects preempt_count == 0 2291da177e4SLinus Torvalds1: bl preempt_schedule_irq @ irq en/disable is done inside 230706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS 2311da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2321da177e4SLinus Torvalds beq preempt_return @ go again 2331da177e4SLinus Torvalds b 1b 2341da177e4SLinus Torvalds#endif 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds .align 5 2371da177e4SLinus Torvalds__und_svc: 238ccea7a19SRussell King svc_entry 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds @ 2411da177e4SLinus Torvalds @ call emulation code, which returns using r9 if it has emulated 2421da177e4SLinus Torvalds @ the instruction, or the more conventional lr if we are to treat 2431da177e4SLinus Torvalds @ this as a real undefined instruction 2441da177e4SLinus Torvalds @ 2451da177e4SLinus Torvalds @ r0 - instruction 2461da177e4SLinus Torvalds @ 2471da177e4SLinus Torvalds ldr r0, [r2, #-4] 2481da177e4SLinus Torvalds adr r9, 1f 2491da177e4SLinus Torvalds bl call_fpe 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds mov r0, sp @ struct pt_regs *regs 2521da177e4SLinus Torvalds bl do_undefinstr 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds @ 2551da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 2561da177e4SLinus Torvalds @ 2571ec42c0cSRussell King1: disable_irq 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds @ 2601da177e4SLinus Torvalds @ restore SPSR and restart the instruction 2611da177e4SLinus Torvalds @ 2621da177e4SLinus Torvalds ldr lr, [sp, #S_PSR] @ Get SVC cpsr 2631da177e4SLinus Torvalds msr spsr_cxsf, lr 2641da177e4SLinus Torvalds ldmia sp, {r0 - pc}^ @ Restore SVC registers 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds .align 5 2671da177e4SLinus Torvalds__pabt_svc: 268ccea7a19SRussell King svc_entry 2691da177e4SLinus Torvalds 2701da177e4SLinus Torvalds @ 2711da177e4SLinus Torvalds @ re-enable interrupts if appropriate 2721da177e4SLinus Torvalds @ 2731da177e4SLinus Torvalds mrs r9, cpsr 2741da177e4SLinus Torvalds tst r3, #PSR_I_BIT 2751da177e4SLinus Torvalds biceq r9, r9, #PSR_I_BIT 2761da177e4SLinus Torvalds msr cpsr_c, r9 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds @ 2791da177e4SLinus Torvalds @ set args, then call main handler 2801da177e4SLinus Torvalds @ 2811da177e4SLinus Torvalds @ r0 - address of faulting instruction 2821da177e4SLinus Torvalds @ r1 - pointer to registers on stack 2831da177e4SLinus Torvalds @ 2841da177e4SLinus Torvalds mov r0, r2 @ address (pc) 2851da177e4SLinus Torvalds mov r1, sp @ regs 2861da177e4SLinus Torvalds bl do_PrefetchAbort @ call abort handler 2871da177e4SLinus Torvalds 2881da177e4SLinus Torvalds @ 2891da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 2901da177e4SLinus Torvalds @ 2911ec42c0cSRussell King disable_irq 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds @ 2941da177e4SLinus Torvalds @ restore SPSR and restart the instruction 2951da177e4SLinus Torvalds @ 2961da177e4SLinus Torvalds ldr r0, [sp, #S_PSR] 2971da177e4SLinus Torvalds msr spsr_cxsf, r0 2981da177e4SLinus Torvalds ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds .align 5 30149f680eaSRussell King.LCcralign: 30249f680eaSRussell King .word cr_alignment 3031da177e4SLinus Torvalds#ifdef MULTI_ABORT 3041da177e4SLinus Torvalds.LCprocfns: 3051da177e4SLinus Torvalds .word processor 3061da177e4SLinus Torvalds#endif 3071da177e4SLinus Torvalds.LCfp: 3081da177e4SLinus Torvalds .word fp_enter 3091da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 3101da177e4SLinus Torvalds.LCirq_stat: 3111da177e4SLinus Torvalds .word irq_stat 3121da177e4SLinus Torvalds#endif 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds/* 3151da177e4SLinus Torvalds * User mode handlers 316*2dede2d8SNicolas Pitre * 317*2dede2d8SNicolas Pitre * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE 3181da177e4SLinus Torvalds */ 319*2dede2d8SNicolas Pitre 320*2dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7) 321*2dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8" 322*2dede2d8SNicolas Pitre#endif 323*2dede2d8SNicolas Pitre 324ccea7a19SRussell King .macro usr_entry 325ccea7a19SRussell King sub sp, sp, #S_FRAME_SIZE 326ccea7a19SRussell King stmib sp, {r1 - r12} 327ccea7a19SRussell King 328ccea7a19SRussell King ldmia r0, {r1 - r3} 329ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 330ccea7a19SRussell King mov r4, #-1 @ "" "" "" "" 331ccea7a19SRussell King 332ccea7a19SRussell King str r1, [sp] @ save the "real" r0 copied 333ccea7a19SRussell King @ from the exception stack 3341da177e4SLinus Torvalds 335dcef1f63SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG) 3362d2669b6SNicolas Pitre @ make sure our user space atomic helper is aborted 337f09b9979SNicolas Pitre cmp r2, #TASK_SIZE 3382d2669b6SNicolas Pitre bichs r3, r3, #PSR_Z_BIT 3392d2669b6SNicolas Pitre#endif 3402d2669b6SNicolas Pitre 3411da177e4SLinus Torvalds @ 3421da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 3431da177e4SLinus Torvalds @ 3441da177e4SLinus Torvalds @ r2 - lr_<exception>, already fixed up for correct return/restart 3451da177e4SLinus Torvalds @ r3 - spsr_<exception> 3461da177e4SLinus Torvalds @ r4 - orig_r0 (see pt_regs definition in ptrace.h) 3471da177e4SLinus Torvalds @ 3481da177e4SLinus Torvalds @ Also, separately save sp_usr and lr_usr 3491da177e4SLinus Torvalds @ 350ccea7a19SRussell King stmia r0, {r2 - r4} 351ccea7a19SRussell King stmdb r0, {sp, lr}^ 3521da177e4SLinus Torvalds 3531da177e4SLinus Torvalds @ 3541da177e4SLinus Torvalds @ Enable the alignment trap while in kernel mode 3551da177e4SLinus Torvalds @ 35649f680eaSRussell King alignment_trap r0 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds @ 3591da177e4SLinus Torvalds @ Clear FP to mark the first stack frame 3601da177e4SLinus Torvalds @ 3611da177e4SLinus Torvalds zero_fp 3621da177e4SLinus Torvalds .endm 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds .align 5 3651da177e4SLinus Torvalds__dabt_usr: 366ccea7a19SRussell King usr_entry 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds @ 3691da177e4SLinus Torvalds @ Call the processor-specific abort handler: 3701da177e4SLinus Torvalds @ 3711da177e4SLinus Torvalds @ r2 - aborted context pc 3721da177e4SLinus Torvalds @ r3 - aborted context cpsr 3731da177e4SLinus Torvalds @ 3741da177e4SLinus Torvalds @ The abort handler must return the aborted address in r0, and 3751da177e4SLinus Torvalds @ the fault status register in r1. 3761da177e4SLinus Torvalds @ 3771da177e4SLinus Torvalds#ifdef MULTI_ABORT 3781da177e4SLinus Torvalds ldr r4, .LCprocfns 3791da177e4SLinus Torvalds mov lr, pc 3801da177e4SLinus Torvalds ldr pc, [r4] 3811da177e4SLinus Torvalds#else 3821da177e4SLinus Torvalds bl CPU_ABORT_HANDLER 3831da177e4SLinus Torvalds#endif 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds @ 3861da177e4SLinus Torvalds @ IRQs on, then call the main handler 3871da177e4SLinus Torvalds @ 3881ec42c0cSRussell King enable_irq 3891da177e4SLinus Torvalds mov r2, sp 3901da177e4SLinus Torvalds adr lr, ret_from_exception 3911da177e4SLinus Torvalds b do_DataAbort 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds .align 5 3941da177e4SLinus Torvalds__irq_usr: 395ccea7a19SRussell King usr_entry 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds get_thread_info tsk 3981da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 399706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 400706fdd9fSRussell King add r7, r8, #1 @ increment it 401706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] 4021da177e4SLinus Torvalds#endif 403ccea7a19SRussell King 404187a51adSRussell King irq_handler 4051da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 406706fdd9fSRussell King ldr r0, [tsk, #TI_PREEMPT] 407706fdd9fSRussell King str r8, [tsk, #TI_PREEMPT] 4081da177e4SLinus Torvalds teq r0, r7 4091da177e4SLinus Torvalds strne r0, [r0, -r0] 4101da177e4SLinus Torvalds#endif 411ccea7a19SRussell King 4121da177e4SLinus Torvalds mov why, #0 4131da177e4SLinus Torvalds b ret_to_user 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds .ltorg 4161da177e4SLinus Torvalds 4171da177e4SLinus Torvalds .align 5 4181da177e4SLinus Torvalds__und_usr: 419ccea7a19SRussell King usr_entry 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds tst r3, #PSR_T_BIT @ Thumb mode? 4221da177e4SLinus Torvalds bne fpundefinstr @ ignore FP 4231da177e4SLinus Torvalds sub r4, r2, #4 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds @ 4261da177e4SLinus Torvalds @ fall through to the emulation code, which returns using r9 if 4271da177e4SLinus Torvalds @ it has emulated the instruction, or the more conventional lr 4281da177e4SLinus Torvalds @ if we are to treat this as a real undefined instruction 4291da177e4SLinus Torvalds @ 4301da177e4SLinus Torvalds @ r0 - instruction 4311da177e4SLinus Torvalds @ 4321da177e4SLinus Torvalds1: ldrt r0, [r4] 4331da177e4SLinus Torvalds adr r9, ret_from_exception 4341da177e4SLinus Torvalds adr lr, fpundefinstr 4351da177e4SLinus Torvalds @ 4361da177e4SLinus Torvalds @ fallthrough to call_fpe 4371da177e4SLinus Torvalds @ 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds/* 4401da177e4SLinus Torvalds * The out of line fixup for the ldrt above. 4411da177e4SLinus Torvalds */ 4421da177e4SLinus Torvalds .section .fixup, "ax" 4431da177e4SLinus Torvalds2: mov pc, r9 4441da177e4SLinus Torvalds .previous 4451da177e4SLinus Torvalds .section __ex_table,"a" 4461da177e4SLinus Torvalds .long 1b, 2b 4471da177e4SLinus Torvalds .previous 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds/* 4501da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction. 4511da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler. 4521da177e4SLinus Torvalds * 4531da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor 4541da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well 4551da177e4SLinus Torvalds * defined. The only instructions that should fault are the 4561da177e4SLinus Torvalds * co-processor instructions. However, we have to watch out 4571da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug. 4581da177e4SLinus Torvalds * 4591da177e4SLinus Torvalds * Emulators may wish to make use of the following registers: 4601da177e4SLinus Torvalds * r0 = instruction opcode. 4611da177e4SLinus Torvalds * r2 = PC+4 4621da177e4SLinus Torvalds * r10 = this threads thread_info structure. 4631da177e4SLinus Torvalds */ 4641da177e4SLinus Torvaldscall_fpe: 4651da177e4SLinus Torvalds tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27 4661da177e4SLinus Torvalds#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710) 4671da177e4SLinus Torvalds and r8, r0, #0x0f000000 @ mask out op-code bits 4681da177e4SLinus Torvalds teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)? 4691da177e4SLinus Torvalds#endif 4701da177e4SLinus Torvalds moveq pc, lr 4711da177e4SLinus Torvalds get_thread_info r10 @ get current thread 4721da177e4SLinus Torvalds and r8, r0, #0x00000f00 @ mask out CP number 4731da177e4SLinus Torvalds mov r7, #1 4741da177e4SLinus Torvalds add r6, r10, #TI_USED_CP 4751da177e4SLinus Torvalds strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[] 4761da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT 4771da177e4SLinus Torvalds @ Test if we need to give access to iWMMXt coprocessors 4781da177e4SLinus Torvalds ldr r5, [r10, #TI_FLAGS] 4791da177e4SLinus Torvalds rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only 4801da177e4SLinus Torvalds movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1) 4811da177e4SLinus Torvalds bcs iwmmxt_task_enable 4821da177e4SLinus Torvalds#endif 4831ec42c0cSRussell King enable_irq 4841da177e4SLinus Torvalds add pc, pc, r8, lsr #6 4851da177e4SLinus Torvalds mov r0, r0 4861da177e4SLinus Torvalds 4871da177e4SLinus Torvalds mov pc, lr @ CP#0 4881da177e4SLinus Torvalds b do_fpe @ CP#1 (FPE) 4891da177e4SLinus Torvalds b do_fpe @ CP#2 (FPE) 4901da177e4SLinus Torvalds mov pc, lr @ CP#3 4911da177e4SLinus Torvalds mov pc, lr @ CP#4 4921da177e4SLinus Torvalds mov pc, lr @ CP#5 4931da177e4SLinus Torvalds mov pc, lr @ CP#6 4941da177e4SLinus Torvalds mov pc, lr @ CP#7 4951da177e4SLinus Torvalds mov pc, lr @ CP#8 4961da177e4SLinus Torvalds mov pc, lr @ CP#9 4971da177e4SLinus Torvalds#ifdef CONFIG_VFP 4981da177e4SLinus Torvalds b do_vfp @ CP#10 (VFP) 4991da177e4SLinus Torvalds b do_vfp @ CP#11 (VFP) 5001da177e4SLinus Torvalds#else 5011da177e4SLinus Torvalds mov pc, lr @ CP#10 (VFP) 5021da177e4SLinus Torvalds mov pc, lr @ CP#11 (VFP) 5031da177e4SLinus Torvalds#endif 5041da177e4SLinus Torvalds mov pc, lr @ CP#12 5051da177e4SLinus Torvalds mov pc, lr @ CP#13 5061da177e4SLinus Torvalds mov pc, lr @ CP#14 (Debug) 5071da177e4SLinus Torvalds mov pc, lr @ CP#15 (Control) 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvaldsdo_fpe: 5101da177e4SLinus Torvalds ldr r4, .LCfp 5111da177e4SLinus Torvalds add r10, r10, #TI_FPSTATE @ r10 = workspace 5121da177e4SLinus Torvalds ldr pc, [r4] @ Call FP module USR entry point 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds/* 5151da177e4SLinus Torvalds * The FP module is called with these registers set: 5161da177e4SLinus Torvalds * r0 = instruction 5171da177e4SLinus Torvalds * r2 = PC+4 5181da177e4SLinus Torvalds * r9 = normal "successful" return address 5191da177e4SLinus Torvalds * r10 = FP workspace 5201da177e4SLinus Torvalds * lr = unrecognised FP instruction return address 5211da177e4SLinus Torvalds */ 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds .data 5241da177e4SLinus TorvaldsENTRY(fp_enter) 5251da177e4SLinus Torvalds .word fpundefinstr 5261da177e4SLinus Torvalds .text 5271da177e4SLinus Torvalds 5281da177e4SLinus Torvaldsfpundefinstr: 5291da177e4SLinus Torvalds mov r0, sp 5301da177e4SLinus Torvalds adr lr, ret_from_exception 5311da177e4SLinus Torvalds b do_undefinstr 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds .align 5 5341da177e4SLinus Torvalds__pabt_usr: 535ccea7a19SRussell King usr_entry 5361da177e4SLinus Torvalds 5371ec42c0cSRussell King enable_irq @ Enable interrupts 5381da177e4SLinus Torvalds mov r0, r2 @ address (pc) 5391da177e4SLinus Torvalds mov r1, sp @ regs 5401da177e4SLinus Torvalds bl do_PrefetchAbort @ call abort handler 5411da177e4SLinus Torvalds /* fall through */ 5421da177e4SLinus Torvalds/* 5431da177e4SLinus Torvalds * This is the return code to user mode for abort handlers 5441da177e4SLinus Torvalds */ 5451da177e4SLinus TorvaldsENTRY(ret_from_exception) 5461da177e4SLinus Torvalds get_thread_info tsk 5471da177e4SLinus Torvalds mov why, #0 5481da177e4SLinus Torvalds b ret_to_user 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvalds/* 5511da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors 5521da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info 5531da177e4SLinus Torvalds * previous and next are guaranteed not to be the same. 5541da177e4SLinus Torvalds */ 5551da177e4SLinus TorvaldsENTRY(__switch_to) 5561da177e4SLinus Torvalds add ip, r1, #TI_CPU_SAVE 5571da177e4SLinus Torvalds ldr r3, [r2, #TI_TP_VALUE] 5581da177e4SLinus Torvalds stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack 559afeb90caSHyok S. Choi#ifndef CONFIG_MMU 560afeb90caSHyok S. Choi add r2, r2, #TI_CPU_DOMAIN 561afeb90caSHyok S. Choi#else 5621da177e4SLinus Torvalds ldr r6, [r2, #TI_CPU_DOMAIN]! 563afeb90caSHyok S. Choi#endif 564b876386eSRussell King#if __LINUX_ARM_ARCH__ >= 6 565b876386eSRussell King#ifdef CONFIG_CPU_MPCORE 566b876386eSRussell King clrex 567b876386eSRussell King#else 56873394322SRussell King strex r5, r4, [ip] @ Clear exclusive monitor 569b876386eSRussell King#endif 570b876386eSRussell King#endif 5711da177e4SLinus Torvalds#if defined(CONFIG_CPU_XSCALE) && !defined(CONFIG_IWMMXT) 5721da177e4SLinus Torvalds mra r4, r5, acc0 5731da177e4SLinus Torvalds stmia ip, {r4, r5} 5741da177e4SLinus Torvalds#endif 5754b0e07a5SNicolas Pitre#if defined(CONFIG_HAS_TLS_REG) 5762d2669b6SNicolas Pitre mcr p15, 0, r3, c13, c0, 3 @ set TLS register 5774b0e07a5SNicolas Pitre#elif !defined(CONFIG_TLS_REG_EMUL) 5781da177e4SLinus Torvalds mov r4, #0xffff0fff 5792d2669b6SNicolas Pitre str r3, [r4, #-15] @ TLS val at 0xffff0ff0 5802d2669b6SNicolas Pitre#endif 581afeb90caSHyok S. Choi#ifdef CONFIG_MMU 5821da177e4SLinus Torvalds mcr p15, 0, r6, c3, c0, 0 @ Set domain register 583afeb90caSHyok S. Choi#endif 5841da177e4SLinus Torvalds#ifdef CONFIG_VFP 5851da177e4SLinus Torvalds @ Always disable VFP so we can lazily save/restore the old 5861da177e4SLinus Torvalds @ state. This occurs in the context of the previous thread. 5871da177e4SLinus Torvalds VFPFMRX r4, FPEXC 5881da177e4SLinus Torvalds bic r4, r4, #FPEXC_ENABLE 5891da177e4SLinus Torvalds VFPFMXR FPEXC, r4 5901da177e4SLinus Torvalds#endif 5911da177e4SLinus Torvalds#if defined(CONFIG_IWMMXT) 5921da177e4SLinus Torvalds bl iwmmxt_task_switch 5931da177e4SLinus Torvalds#elif defined(CONFIG_CPU_XSCALE) 5941da177e4SLinus Torvalds add r4, r2, #40 @ cpu_context_save->extra 5951da177e4SLinus Torvalds ldmib r4, {r4, r5} 5961da177e4SLinus Torvalds mar acc0, r4, r5 5971da177e4SLinus Torvalds#endif 5981da177e4SLinus Torvalds ldmib r2, {r4 - sl, fp, sp, pc} @ Load all regs saved previously 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds __INIT 6012d2669b6SNicolas Pitre 6022d2669b6SNicolas Pitre/* 6032d2669b6SNicolas Pitre * User helpers. 6042d2669b6SNicolas Pitre * 6052d2669b6SNicolas Pitre * These are segment of kernel provided user code reachable from user space 6062d2669b6SNicolas Pitre * at a fixed address in kernel memory. This is used to provide user space 6072d2669b6SNicolas Pitre * with some operations which require kernel help because of unimplemented 6082d2669b6SNicolas Pitre * native feature and/or instructions in many ARM CPUs. The idea is for 6092d2669b6SNicolas Pitre * this code to be executed directly in user mode for best efficiency but 6102d2669b6SNicolas Pitre * which is too intimate with the kernel counter part to be left to user 6112d2669b6SNicolas Pitre * libraries. In fact this code might even differ from one CPU to another 6122d2669b6SNicolas Pitre * depending on the available instruction set and restrictions like on 6132d2669b6SNicolas Pitre * SMP systems. In other words, the kernel reserves the right to change 6142d2669b6SNicolas Pitre * this code as needed without warning. Only the entry points and their 6152d2669b6SNicolas Pitre * results are guaranteed to be stable. 6162d2669b6SNicolas Pitre * 6172d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high 6182d2669b6SNicolas Pitre * vector page. New segments (if ever needed) must be added in front of 6192d2669b6SNicolas Pitre * existing ones. This mechanism should be used only for things that are 6202d2669b6SNicolas Pitre * really small and justified, and not be abused freely. 6212d2669b6SNicolas Pitre * 6222d2669b6SNicolas Pitre * User space is expected to implement those things inline when optimizing 6232d2669b6SNicolas Pitre * for a processor that has the necessary native support, but only if such 6242d2669b6SNicolas Pitre * resulting binaries are already to be incompatible with earlier ARM 6252d2669b6SNicolas Pitre * processors due to the use of unsupported instructions other than what 6262d2669b6SNicolas Pitre * is provided here. In other words don't make binaries unable to run on 6272d2669b6SNicolas Pitre * earlier processors just for the sake of not using these kernel helpers 6282d2669b6SNicolas Pitre * if your compiled code is not going to use the new instructions for other 6292d2669b6SNicolas Pitre * purpose. 6302d2669b6SNicolas Pitre */ 6312d2669b6SNicolas Pitre 6322d2669b6SNicolas Pitre .align 5 6332d2669b6SNicolas Pitre .globl __kuser_helper_start 6342d2669b6SNicolas Pitre__kuser_helper_start: 6352d2669b6SNicolas Pitre 6362d2669b6SNicolas Pitre/* 6372d2669b6SNicolas Pitre * Reference prototype: 6382d2669b6SNicolas Pitre * 6397c612bfdSNicolas Pitre * void __kernel_memory_barrier(void) 6407c612bfdSNicolas Pitre * 6417c612bfdSNicolas Pitre * Input: 6427c612bfdSNicolas Pitre * 6437c612bfdSNicolas Pitre * lr = return address 6447c612bfdSNicolas Pitre * 6457c612bfdSNicolas Pitre * Output: 6467c612bfdSNicolas Pitre * 6477c612bfdSNicolas Pitre * none 6487c612bfdSNicolas Pitre * 6497c612bfdSNicolas Pitre * Clobbered: 6507c612bfdSNicolas Pitre * 6517c612bfdSNicolas Pitre * the Z flag might be lost 6527c612bfdSNicolas Pitre * 6537c612bfdSNicolas Pitre * Definition and user space usage example: 6547c612bfdSNicolas Pitre * 6557c612bfdSNicolas Pitre * typedef void (__kernel_dmb_t)(void); 6567c612bfdSNicolas Pitre * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0) 6577c612bfdSNicolas Pitre * 6587c612bfdSNicolas Pitre * Apply any needed memory barrier to preserve consistency with data modified 6597c612bfdSNicolas Pitre * manually and __kuser_cmpxchg usage. 6607c612bfdSNicolas Pitre * 6617c612bfdSNicolas Pitre * This could be used as follows: 6627c612bfdSNicolas Pitre * 6637c612bfdSNicolas Pitre * #define __kernel_dmb() \ 6647c612bfdSNicolas Pitre * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \ 6657c612bfdSNicolas Pitre * : : : "lr","cc" ) 6667c612bfdSNicolas Pitre */ 6677c612bfdSNicolas Pitre 6687c612bfdSNicolas Pitre__kuser_memory_barrier: @ 0xffff0fa0 6697c612bfdSNicolas Pitre 6707c612bfdSNicolas Pitre#if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_SMP) 6717c612bfdSNicolas Pitre mcr p15, 0, r0, c7, c10, 5 @ dmb 6727c612bfdSNicolas Pitre#endif 6737c612bfdSNicolas Pitre mov pc, lr 6747c612bfdSNicolas Pitre 6757c612bfdSNicolas Pitre .align 5 6767c612bfdSNicolas Pitre 6777c612bfdSNicolas Pitre/* 6787c612bfdSNicolas Pitre * Reference prototype: 6797c612bfdSNicolas Pitre * 6802d2669b6SNicolas Pitre * int __kernel_cmpxchg(int oldval, int newval, int *ptr) 6812d2669b6SNicolas Pitre * 6822d2669b6SNicolas Pitre * Input: 6832d2669b6SNicolas Pitre * 6842d2669b6SNicolas Pitre * r0 = oldval 6852d2669b6SNicolas Pitre * r1 = newval 6862d2669b6SNicolas Pitre * r2 = ptr 6872d2669b6SNicolas Pitre * lr = return address 6882d2669b6SNicolas Pitre * 6892d2669b6SNicolas Pitre * Output: 6902d2669b6SNicolas Pitre * 6912d2669b6SNicolas Pitre * r0 = returned value (zero or non-zero) 6922d2669b6SNicolas Pitre * C flag = set if r0 == 0, clear if r0 != 0 6932d2669b6SNicolas Pitre * 6942d2669b6SNicolas Pitre * Clobbered: 6952d2669b6SNicolas Pitre * 6962d2669b6SNicolas Pitre * r3, ip, flags 6972d2669b6SNicolas Pitre * 6982d2669b6SNicolas Pitre * Definition and user space usage example: 6992d2669b6SNicolas Pitre * 7002d2669b6SNicolas Pitre * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr); 7012d2669b6SNicolas Pitre * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0) 7022d2669b6SNicolas Pitre * 7032d2669b6SNicolas Pitre * Atomically store newval in *ptr if *ptr is equal to oldval for user space. 7042d2669b6SNicolas Pitre * Return zero if *ptr was changed or non-zero if no exchange happened. 7052d2669b6SNicolas Pitre * The C flag is also set if *ptr was changed to allow for assembly 7062d2669b6SNicolas Pitre * optimization in the calling code. 7072d2669b6SNicolas Pitre * 7087c612bfdSNicolas Pitre * Note: this routine already includes memory barriers as needed. 7097c612bfdSNicolas Pitre * 7102d2669b6SNicolas Pitre * For example, a user space atomic_add implementation could look like this: 7112d2669b6SNicolas Pitre * 7122d2669b6SNicolas Pitre * #define atomic_add(ptr, val) \ 7132d2669b6SNicolas Pitre * ({ register unsigned int *__ptr asm("r2") = (ptr); \ 7142d2669b6SNicolas Pitre * register unsigned int __result asm("r1"); \ 7152d2669b6SNicolas Pitre * asm volatile ( \ 7162d2669b6SNicolas Pitre * "1: @ atomic_add\n\t" \ 7172d2669b6SNicolas Pitre * "ldr r0, [r2]\n\t" \ 7182d2669b6SNicolas Pitre * "mov r3, #0xffff0fff\n\t" \ 7192d2669b6SNicolas Pitre * "add lr, pc, #4\n\t" \ 7202d2669b6SNicolas Pitre * "add r1, r0, %2\n\t" \ 7212d2669b6SNicolas Pitre * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \ 7222d2669b6SNicolas Pitre * "bcc 1b" \ 7232d2669b6SNicolas Pitre * : "=&r" (__result) \ 7242d2669b6SNicolas Pitre * : "r" (__ptr), "rIL" (val) \ 7252d2669b6SNicolas Pitre * : "r0","r3","ip","lr","cc","memory" ); \ 7262d2669b6SNicolas Pitre * __result; }) 7272d2669b6SNicolas Pitre */ 7282d2669b6SNicolas Pitre 7292d2669b6SNicolas Pitre__kuser_cmpxchg: @ 0xffff0fc0 7302d2669b6SNicolas Pitre 731dcef1f63SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG) 7322d2669b6SNicolas Pitre 733dcef1f63SNicolas Pitre /* 734dcef1f63SNicolas Pitre * Poor you. No fast solution possible... 735dcef1f63SNicolas Pitre * The kernel itself must perform the operation. 736dcef1f63SNicolas Pitre * A special ghost syscall is used for that (see traps.c). 737dcef1f63SNicolas Pitre */ 738dcef1f63SNicolas Pitre swi #0x9ffff0 739dcef1f63SNicolas Pitre mov pc, lr 740dcef1f63SNicolas Pitre 741dcef1f63SNicolas Pitre#elif __LINUX_ARM_ARCH__ < 6 7422d2669b6SNicolas Pitre 7432d2669b6SNicolas Pitre /* 7442d2669b6SNicolas Pitre * Theory of operation: 7452d2669b6SNicolas Pitre * 7462d2669b6SNicolas Pitre * We set the Z flag before loading oldval. If ever an exception 7472d2669b6SNicolas Pitre * occurs we can not be sure the loaded value will still be the same 7482d2669b6SNicolas Pitre * when the exception returns, therefore the user exception handler 7492d2669b6SNicolas Pitre * will clear the Z flag whenever the interrupted user code was 7502d2669b6SNicolas Pitre * actually from the kernel address space (see the usr_entry macro). 7512d2669b6SNicolas Pitre * 7522d2669b6SNicolas Pitre * The post-increment on the str is used to prevent a race with an 7532d2669b6SNicolas Pitre * exception happening just after the str instruction which would 7542d2669b6SNicolas Pitre * clear the Z flag although the exchange was done. 7552d2669b6SNicolas Pitre */ 7562d2669b6SNicolas Pitre teq ip, ip @ set Z flag 7572d2669b6SNicolas Pitre ldr ip, [r2] @ load current val 7582d2669b6SNicolas Pitre add r3, r2, #1 @ prepare store ptr 7592d2669b6SNicolas Pitre teqeq ip, r0 @ compare with oldval if still allowed 7602d2669b6SNicolas Pitre streq r1, [r3, #-1]! @ store newval if still allowed 7612d2669b6SNicolas Pitre subs r0, r2, r3 @ if r2 == r3 the str occured 7622d2669b6SNicolas Pitre mov pc, lr 7632d2669b6SNicolas Pitre 7642d2669b6SNicolas Pitre#else 7652d2669b6SNicolas Pitre 7667c612bfdSNicolas Pitre#ifdef CONFIG_SMP 7677c612bfdSNicolas Pitre mcr p15, 0, r0, c7, c10, 5 @ dmb 7687c612bfdSNicolas Pitre#endif 7692d2669b6SNicolas Pitre ldrex r3, [r2] 7702d2669b6SNicolas Pitre subs r3, r3, r0 7712d2669b6SNicolas Pitre strexeq r3, r1, [r2] 7722d2669b6SNicolas Pitre rsbs r0, r3, #0 7737c612bfdSNicolas Pitre#ifdef CONFIG_SMP 7747c612bfdSNicolas Pitre mcr p15, 0, r0, c7, c10, 5 @ dmb 7757c612bfdSNicolas Pitre#endif 7762d2669b6SNicolas Pitre mov pc, lr 7772d2669b6SNicolas Pitre 7782d2669b6SNicolas Pitre#endif 7792d2669b6SNicolas Pitre 7802d2669b6SNicolas Pitre .align 5 7812d2669b6SNicolas Pitre 7822d2669b6SNicolas Pitre/* 7832d2669b6SNicolas Pitre * Reference prototype: 7842d2669b6SNicolas Pitre * 7852d2669b6SNicolas Pitre * int __kernel_get_tls(void) 7862d2669b6SNicolas Pitre * 7872d2669b6SNicolas Pitre * Input: 7882d2669b6SNicolas Pitre * 7892d2669b6SNicolas Pitre * lr = return address 7902d2669b6SNicolas Pitre * 7912d2669b6SNicolas Pitre * Output: 7922d2669b6SNicolas Pitre * 7932d2669b6SNicolas Pitre * r0 = TLS value 7942d2669b6SNicolas Pitre * 7952d2669b6SNicolas Pitre * Clobbered: 7962d2669b6SNicolas Pitre * 7972d2669b6SNicolas Pitre * the Z flag might be lost 7982d2669b6SNicolas Pitre * 7992d2669b6SNicolas Pitre * Definition and user space usage example: 8002d2669b6SNicolas Pitre * 8012d2669b6SNicolas Pitre * typedef int (__kernel_get_tls_t)(void); 8022d2669b6SNicolas Pitre * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0) 8032d2669b6SNicolas Pitre * 8042d2669b6SNicolas Pitre * Get the TLS value as previously set via the __ARM_NR_set_tls syscall. 8052d2669b6SNicolas Pitre * 8062d2669b6SNicolas Pitre * This could be used as follows: 8072d2669b6SNicolas Pitre * 8082d2669b6SNicolas Pitre * #define __kernel_get_tls() \ 8092d2669b6SNicolas Pitre * ({ register unsigned int __val asm("r0"); \ 8102d2669b6SNicolas Pitre * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \ 8112d2669b6SNicolas Pitre * : "=r" (__val) : : "lr","cc" ); \ 8122d2669b6SNicolas Pitre * __val; }) 8132d2669b6SNicolas Pitre */ 8142d2669b6SNicolas Pitre 8152d2669b6SNicolas Pitre__kuser_get_tls: @ 0xffff0fe0 8162d2669b6SNicolas Pitre 8174b0e07a5SNicolas Pitre#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL) 8182d2669b6SNicolas Pitre 8192d2669b6SNicolas Pitre ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0 8202d2669b6SNicolas Pitre mov pc, lr 8212d2669b6SNicolas Pitre 8222d2669b6SNicolas Pitre#else 8232d2669b6SNicolas Pitre 8242d2669b6SNicolas Pitre mrc p15, 0, r0, c13, c0, 3 @ read TLS register 8252d2669b6SNicolas Pitre mov pc, lr 8262d2669b6SNicolas Pitre 8272d2669b6SNicolas Pitre#endif 8282d2669b6SNicolas Pitre 8292d2669b6SNicolas Pitre .rep 5 8302d2669b6SNicolas Pitre .word 0 @ pad up to __kuser_helper_version 8312d2669b6SNicolas Pitre .endr 8322d2669b6SNicolas Pitre 8332d2669b6SNicolas Pitre/* 8342d2669b6SNicolas Pitre * Reference declaration: 8352d2669b6SNicolas Pitre * 8362d2669b6SNicolas Pitre * extern unsigned int __kernel_helper_version; 8372d2669b6SNicolas Pitre * 8382d2669b6SNicolas Pitre * Definition and user space usage example: 8392d2669b6SNicolas Pitre * 8402d2669b6SNicolas Pitre * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc) 8412d2669b6SNicolas Pitre * 8422d2669b6SNicolas Pitre * User space may read this to determine the curent number of helpers 8432d2669b6SNicolas Pitre * available. 8442d2669b6SNicolas Pitre */ 8452d2669b6SNicolas Pitre 8462d2669b6SNicolas Pitre__kuser_helper_version: @ 0xffff0ffc 8472d2669b6SNicolas Pitre .word ((__kuser_helper_end - __kuser_helper_start) >> 5) 8482d2669b6SNicolas Pitre 8492d2669b6SNicolas Pitre .globl __kuser_helper_end 8502d2669b6SNicolas Pitre__kuser_helper_end: 8512d2669b6SNicolas Pitre 8522d2669b6SNicolas Pitre 8531da177e4SLinus Torvalds/* 8541da177e4SLinus Torvalds * Vector stubs. 8551da177e4SLinus Torvalds * 8567933523dSRussell King * This code is copied to 0xffff0200 so we can use branches in the 8577933523dSRussell King * vectors, rather than ldr's. Note that this code must not 8587933523dSRussell King * exceed 0x300 bytes. 8591da177e4SLinus Torvalds * 8601da177e4SLinus Torvalds * Common stub entry macro: 8611da177e4SLinus Torvalds * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 862ccea7a19SRussell King * 863ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address 864ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler. 8651da177e4SLinus Torvalds */ 866b7ec4795SNicolas Pitre .macro vector_stub, name, mode, correction=0 8671da177e4SLinus Torvalds .align 5 8681da177e4SLinus Torvalds 8691da177e4SLinus Torvaldsvector_\name: 8701da177e4SLinus Torvalds .if \correction 8711da177e4SLinus Torvalds sub lr, lr, #\correction 8721da177e4SLinus Torvalds .endif 8731da177e4SLinus Torvalds 874ccea7a19SRussell King @ 875ccea7a19SRussell King @ Save r0, lr_<exception> (parent PC) and spsr_<exception> 876ccea7a19SRussell King @ (parent CPSR) 877ccea7a19SRussell King @ 878ccea7a19SRussell King stmia sp, {r0, lr} @ save r0, lr 879ccea7a19SRussell King mrs lr, spsr 880ccea7a19SRussell King str lr, [sp, #8] @ save spsr 881ccea7a19SRussell King 882ccea7a19SRussell King @ 883ccea7a19SRussell King @ Prepare for SVC32 mode. IRQs remain disabled. 884ccea7a19SRussell King @ 885ccea7a19SRussell King mrs r0, cpsr 886b7ec4795SNicolas Pitre eor r0, r0, #(\mode ^ SVC_MODE) 887ccea7a19SRussell King msr spsr_cxsf, r0 888ccea7a19SRussell King 889ccea7a19SRussell King @ 890ccea7a19SRussell King @ the branch table must immediately follow this code 891ccea7a19SRussell King @ 892ccea7a19SRussell King and lr, lr, #0x0f 893b7ec4795SNicolas Pitre mov r0, sp 8941da177e4SLinus Torvalds ldr lr, [pc, lr, lsl #2] 895ccea7a19SRussell King movs pc, lr @ branch to handler in SVC mode 8961da177e4SLinus Torvalds .endm 8971da177e4SLinus Torvalds 8987933523dSRussell King .globl __stubs_start 8991da177e4SLinus Torvalds__stubs_start: 9001da177e4SLinus Torvalds/* 9011da177e4SLinus Torvalds * Interrupt dispatcher 9021da177e4SLinus Torvalds */ 903b7ec4795SNicolas Pitre vector_stub irq, IRQ_MODE, 4 9041da177e4SLinus Torvalds 9051da177e4SLinus Torvalds .long __irq_usr @ 0 (USR_26 / USR_32) 9061da177e4SLinus Torvalds .long __irq_invalid @ 1 (FIQ_26 / FIQ_32) 9071da177e4SLinus Torvalds .long __irq_invalid @ 2 (IRQ_26 / IRQ_32) 9081da177e4SLinus Torvalds .long __irq_svc @ 3 (SVC_26 / SVC_32) 9091da177e4SLinus Torvalds .long __irq_invalid @ 4 9101da177e4SLinus Torvalds .long __irq_invalid @ 5 9111da177e4SLinus Torvalds .long __irq_invalid @ 6 9121da177e4SLinus Torvalds .long __irq_invalid @ 7 9131da177e4SLinus Torvalds .long __irq_invalid @ 8 9141da177e4SLinus Torvalds .long __irq_invalid @ 9 9151da177e4SLinus Torvalds .long __irq_invalid @ a 9161da177e4SLinus Torvalds .long __irq_invalid @ b 9171da177e4SLinus Torvalds .long __irq_invalid @ c 9181da177e4SLinus Torvalds .long __irq_invalid @ d 9191da177e4SLinus Torvalds .long __irq_invalid @ e 9201da177e4SLinus Torvalds .long __irq_invalid @ f 9211da177e4SLinus Torvalds 9221da177e4SLinus Torvalds/* 9231da177e4SLinus Torvalds * Data abort dispatcher 9241da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 9251da177e4SLinus Torvalds */ 926b7ec4795SNicolas Pitre vector_stub dabt, ABT_MODE, 8 9271da177e4SLinus Torvalds 9281da177e4SLinus Torvalds .long __dabt_usr @ 0 (USR_26 / USR_32) 9291da177e4SLinus Torvalds .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32) 9301da177e4SLinus Torvalds .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32) 9311da177e4SLinus Torvalds .long __dabt_svc @ 3 (SVC_26 / SVC_32) 9321da177e4SLinus Torvalds .long __dabt_invalid @ 4 9331da177e4SLinus Torvalds .long __dabt_invalid @ 5 9341da177e4SLinus Torvalds .long __dabt_invalid @ 6 9351da177e4SLinus Torvalds .long __dabt_invalid @ 7 9361da177e4SLinus Torvalds .long __dabt_invalid @ 8 9371da177e4SLinus Torvalds .long __dabt_invalid @ 9 9381da177e4SLinus Torvalds .long __dabt_invalid @ a 9391da177e4SLinus Torvalds .long __dabt_invalid @ b 9401da177e4SLinus Torvalds .long __dabt_invalid @ c 9411da177e4SLinus Torvalds .long __dabt_invalid @ d 9421da177e4SLinus Torvalds .long __dabt_invalid @ e 9431da177e4SLinus Torvalds .long __dabt_invalid @ f 9441da177e4SLinus Torvalds 9451da177e4SLinus Torvalds/* 9461da177e4SLinus Torvalds * Prefetch abort dispatcher 9471da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 9481da177e4SLinus Torvalds */ 949b7ec4795SNicolas Pitre vector_stub pabt, ABT_MODE, 4 9501da177e4SLinus Torvalds 9511da177e4SLinus Torvalds .long __pabt_usr @ 0 (USR_26 / USR_32) 9521da177e4SLinus Torvalds .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32) 9531da177e4SLinus Torvalds .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32) 9541da177e4SLinus Torvalds .long __pabt_svc @ 3 (SVC_26 / SVC_32) 9551da177e4SLinus Torvalds .long __pabt_invalid @ 4 9561da177e4SLinus Torvalds .long __pabt_invalid @ 5 9571da177e4SLinus Torvalds .long __pabt_invalid @ 6 9581da177e4SLinus Torvalds .long __pabt_invalid @ 7 9591da177e4SLinus Torvalds .long __pabt_invalid @ 8 9601da177e4SLinus Torvalds .long __pabt_invalid @ 9 9611da177e4SLinus Torvalds .long __pabt_invalid @ a 9621da177e4SLinus Torvalds .long __pabt_invalid @ b 9631da177e4SLinus Torvalds .long __pabt_invalid @ c 9641da177e4SLinus Torvalds .long __pabt_invalid @ d 9651da177e4SLinus Torvalds .long __pabt_invalid @ e 9661da177e4SLinus Torvalds .long __pabt_invalid @ f 9671da177e4SLinus Torvalds 9681da177e4SLinus Torvalds/* 9691da177e4SLinus Torvalds * Undef instr entry dispatcher 9701da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 9711da177e4SLinus Torvalds */ 972b7ec4795SNicolas Pitre vector_stub und, UND_MODE 9731da177e4SLinus Torvalds 9741da177e4SLinus Torvalds .long __und_usr @ 0 (USR_26 / USR_32) 9751da177e4SLinus Torvalds .long __und_invalid @ 1 (FIQ_26 / FIQ_32) 9761da177e4SLinus Torvalds .long __und_invalid @ 2 (IRQ_26 / IRQ_32) 9771da177e4SLinus Torvalds .long __und_svc @ 3 (SVC_26 / SVC_32) 9781da177e4SLinus Torvalds .long __und_invalid @ 4 9791da177e4SLinus Torvalds .long __und_invalid @ 5 9801da177e4SLinus Torvalds .long __und_invalid @ 6 9811da177e4SLinus Torvalds .long __und_invalid @ 7 9821da177e4SLinus Torvalds .long __und_invalid @ 8 9831da177e4SLinus Torvalds .long __und_invalid @ 9 9841da177e4SLinus Torvalds .long __und_invalid @ a 9851da177e4SLinus Torvalds .long __und_invalid @ b 9861da177e4SLinus Torvalds .long __und_invalid @ c 9871da177e4SLinus Torvalds .long __und_invalid @ d 9881da177e4SLinus Torvalds .long __und_invalid @ e 9891da177e4SLinus Torvalds .long __und_invalid @ f 9901da177e4SLinus Torvalds 9911da177e4SLinus Torvalds .align 5 9921da177e4SLinus Torvalds 9931da177e4SLinus Torvalds/*============================================================================= 9941da177e4SLinus Torvalds * Undefined FIQs 9951da177e4SLinus Torvalds *----------------------------------------------------------------------------- 9961da177e4SLinus Torvalds * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC 9971da177e4SLinus Torvalds * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg. 9981da177e4SLinus Torvalds * Basically to switch modes, we *HAVE* to clobber one register... brain 9991da177e4SLinus Torvalds * damage alert! I don't think that we can execute any code in here in any 10001da177e4SLinus Torvalds * other mode than FIQ... Ok you can switch to another mode, but you can't 10011da177e4SLinus Torvalds * get out of that mode without clobbering one register. 10021da177e4SLinus Torvalds */ 10031da177e4SLinus Torvaldsvector_fiq: 10041da177e4SLinus Torvalds disable_fiq 10051da177e4SLinus Torvalds subs pc, lr, #4 10061da177e4SLinus Torvalds 10071da177e4SLinus Torvalds/*============================================================================= 10081da177e4SLinus Torvalds * Address exception handler 10091da177e4SLinus Torvalds *----------------------------------------------------------------------------- 10101da177e4SLinus Torvalds * These aren't too critical. 10111da177e4SLinus Torvalds * (they're not supposed to happen, and won't happen in 32-bit data mode). 10121da177e4SLinus Torvalds */ 10131da177e4SLinus Torvalds 10141da177e4SLinus Torvaldsvector_addrexcptn: 10151da177e4SLinus Torvalds b vector_addrexcptn 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds/* 10181da177e4SLinus Torvalds * We group all the following data together to optimise 10191da177e4SLinus Torvalds * for CPUs with separate I & D caches. 10201da177e4SLinus Torvalds */ 10211da177e4SLinus Torvalds .align 5 10221da177e4SLinus Torvalds 10231da177e4SLinus Torvalds.LCvswi: 10241da177e4SLinus Torvalds .word vector_swi 10251da177e4SLinus Torvalds 10267933523dSRussell King .globl __stubs_end 10271da177e4SLinus Torvalds__stubs_end: 10281da177e4SLinus Torvalds 10297933523dSRussell King .equ stubs_offset, __vectors_start + 0x200 - __stubs_start 10301da177e4SLinus Torvalds 10317933523dSRussell King .globl __vectors_start 10327933523dSRussell King__vectors_start: 10331da177e4SLinus Torvalds swi SYS_ERROR0 10347933523dSRussell King b vector_und + stubs_offset 10357933523dSRussell King ldr pc, .LCvswi + stubs_offset 10367933523dSRussell King b vector_pabt + stubs_offset 10377933523dSRussell King b vector_dabt + stubs_offset 10387933523dSRussell King b vector_addrexcptn + stubs_offset 10397933523dSRussell King b vector_irq + stubs_offset 10407933523dSRussell King b vector_fiq + stubs_offset 10411da177e4SLinus Torvalds 10427933523dSRussell King .globl __vectors_end 10437933523dSRussell King__vectors_end: 10441da177e4SLinus Torvalds 10451da177e4SLinus Torvalds .data 10461da177e4SLinus Torvalds 10471da177e4SLinus Torvalds .globl cr_alignment 10481da177e4SLinus Torvalds .globl cr_no_alignment 10491da177e4SLinus Torvaldscr_alignment: 10501da177e4SLinus Torvalds .space 4 10511da177e4SLinus Torvaldscr_no_alignment: 10521da177e4SLinus Torvalds .space 4 1053