1d2912cb1SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-only */ 21da177e4SLinus Torvalds/* 31da177e4SLinus Torvalds * linux/arch/arm/kernel/entry-armv.S 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 1996,1997,1998 Russell King. 61da177e4SLinus Torvalds * ARM700 fix by Matthew Godbolt (linux-user@willothewisp.demon.co.uk) 7afeb90caSHyok S. Choi * nommu support by Hyok S. Choi (hyok.choi@samsung.com) 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Low-level vector interface routines 101da177e4SLinus Torvalds * 1170b6f2b4SNicolas Pitre * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction 1270b6f2b4SNicolas Pitre * that causes it to save wrong values... Be aware! 131da177e4SLinus Torvalds */ 141da177e4SLinus Torvalds 159b9cf81aSPaul Gortmaker#include <linux/init.h> 169b9cf81aSPaul Gortmaker 176f6f6a70SRob Herring#include <asm/assembler.h> 18f09b9979SNicolas Pitre#include <asm/memory.h> 19753790e7SRussell King#include <asm/glue-df.h> 20753790e7SRussell King#include <asm/glue-pf.h> 211da177e4SLinus Torvalds#include <asm/vfpmacros.h> 22d6551e88SRussell King#include <asm/thread_notify.h> 23c4c5716eSCatalin Marinas#include <asm/unwind.h> 24cc20d429SRussell King#include <asm/unistd.h> 25f159f4edSTony Lindgren#include <asm/tls.h> 269f97da78SDavid Howells#include <asm/system_info.h> 27747ffc2fSRussell King#include <asm/uaccess-asm.h> 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds#include "entry-header.S" 30a0266c21SWang Nan#include <asm/probes.h> 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds/* 33d9600c99SRussell King * Interrupt handling. 34187a51adSRussell King */ 35d4664b6cSArd Biesheuvel .macro irq_handler, from_user:req 3652108641Seric miao mov r0, sp 37d4664b6cSArd Biesheuvel#ifdef CONFIG_IRQSTACKS 38d4664b6cSArd Biesheuvel#ifdef CONFIG_UNWINDER_ARM 39d4664b6cSArd Biesheuvel mov fpreg, sp @ Preserve original SP 40d4664b6cSArd Biesheuvel#else 41d4664b6cSArd Biesheuvel mov r8, fp @ Preserve original FP 42d4664b6cSArd Biesheuvel mov r9, sp @ Preserve original SP 43d4664b6cSArd Biesheuvel#endif 44*7b9896c3SArd Biesheuvel ldr_this_cpu sp, irq_stack_ptr, r2, r3 45*7b9896c3SArd Biesheuvel 46d4664b6cSArd Biesheuvel .if \from_user == 0 47d4664b6cSArd BiesheuvelUNWIND( .setfp fpreg, sp ) 48d4664b6cSArd Biesheuvel @ 49d4664b6cSArd Biesheuvel @ If we took the interrupt while running in the kernel, we may already 50d4664b6cSArd Biesheuvel @ be using the IRQ stack, so revert to the original value in that case. 51d4664b6cSArd Biesheuvel @ 52d4664b6cSArd Biesheuvel subs r2, sp, r0 @ SP above bottom of IRQ stack? 53d4664b6cSArd Biesheuvel rsbscs r2, r2, #THREAD_SIZE @ ... and below the top? 54a1c510d0SArd Biesheuvel#ifdef CONFIG_VMAP_STACK 554e918ab1SArd Biesheuvel ldr_va r2, high_memory, cc @ End of the linear region 56a1c510d0SArd Biesheuvel cmpcc r2, r0 @ Stack pointer was below it? 57a1c510d0SArd Biesheuvel#endif 58d4664b6cSArd Biesheuvel movcs sp, r0 @ If so, revert to incoming SP 59d4664b6cSArd Biesheuvel 60d4664b6cSArd Biesheuvel#ifndef CONFIG_UNWINDER_ARM 61d4664b6cSArd Biesheuvel @ 62d4664b6cSArd Biesheuvel @ Inform the frame pointer unwinder where the next frame lives 63d4664b6cSArd Biesheuvel @ 64d4664b6cSArd Biesheuvel movcc lr, pc @ Make LR point into .entry.text so 65d4664b6cSArd Biesheuvel @ that we will get a dump of the 66d4664b6cSArd Biesheuvel @ exception stack for this frame. 67d4664b6cSArd Biesheuvel#ifdef CONFIG_CC_IS_GCC 68d4664b6cSArd Biesheuvel movcc ip, r0 @ Store the old SP in the frame record. 69d4664b6cSArd Biesheuvel stmdbcc sp!, {fp, ip, lr, pc} @ Push frame record 70d4664b6cSArd Biesheuvel addcc fp, sp, #12 71d4664b6cSArd Biesheuvel#else 72d4664b6cSArd Biesheuvel stmdbcc sp!, {fp, lr} @ Push frame record 73d4664b6cSArd Biesheuvel movcc fp, sp 74d4664b6cSArd Biesheuvel#endif // CONFIG_CC_IS_GCC 75d4664b6cSArd Biesheuvel#endif // CONFIG_UNWINDER_ARM 76d4664b6cSArd Biesheuvel .endif 77d4664b6cSArd Biesheuvel#endif // CONFIG_IRQSTACKS 78d4664b6cSArd Biesheuvel 79a7b0872eSMark Rutland bl generic_handle_arch_irq 80d4664b6cSArd Biesheuvel 81d4664b6cSArd Biesheuvel#ifdef CONFIG_IRQSTACKS 82d4664b6cSArd Biesheuvel#ifdef CONFIG_UNWINDER_ARM 83d4664b6cSArd Biesheuvel mov sp, fpreg @ Restore original SP 84d4664b6cSArd Biesheuvel#else 85d4664b6cSArd Biesheuvel mov fp, r8 @ Restore original FP 86d4664b6cSArd Biesheuvel mov sp, r9 @ Restore original SP 87d4664b6cSArd Biesheuvel#endif // CONFIG_UNWINDER_ARM 88d4664b6cSArd Biesheuvel#endif // CONFIG_IRQSTACKS 89187a51adSRussell King .endm 90187a51adSRussell King 91ac8b9c1cSRussell King .macro pabt_helper 928dfe7ac9SRussell King @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5 93ac8b9c1cSRussell King#ifdef MULTI_PABORT 940402beceSRussell King ldr ip, .LCprocfns 95ac8b9c1cSRussell King mov lr, pc 960402beceSRussell King ldr pc, [ip, #PROCESSOR_PABT_FUNC] 97ac8b9c1cSRussell King#else 98ac8b9c1cSRussell King bl CPU_PABORT_HANDLER 99ac8b9c1cSRussell King#endif 100ac8b9c1cSRussell King .endm 101ac8b9c1cSRussell King 102ac8b9c1cSRussell King .macro dabt_helper 103ac8b9c1cSRussell King 104ac8b9c1cSRussell King @ 105ac8b9c1cSRussell King @ Call the processor-specific abort handler: 106ac8b9c1cSRussell King @ 107da740472SRussell King @ r2 - pt_regs 1083e287becSRussell King @ r4 - aborted context pc 1093e287becSRussell King @ r5 - aborted context psr 110ac8b9c1cSRussell King @ 111ac8b9c1cSRussell King @ The abort handler must return the aborted address in r0, and 112ac8b9c1cSRussell King @ the fault status register in r1. r9 must be preserved. 113ac8b9c1cSRussell King @ 114ac8b9c1cSRussell King#ifdef MULTI_DABORT 1150402beceSRussell King ldr ip, .LCprocfns 116ac8b9c1cSRussell King mov lr, pc 1170402beceSRussell King ldr pc, [ip, #PROCESSOR_DABT_FUNC] 118ac8b9c1cSRussell King#else 119ac8b9c1cSRussell King bl CPU_DABORT_HANDLER 120ac8b9c1cSRussell King#endif 121ac8b9c1cSRussell King .endm 122ac8b9c1cSRussell King 123c6089061SRussell King .section .entry.text,"ax",%progbits 124785d3cd2SNicolas Pitre 125187a51adSRussell King/* 1261da177e4SLinus Torvalds * Invalid mode handlers 1271da177e4SLinus Torvalds */ 128ccea7a19SRussell King .macro inv_entry, reason 1295745eef6SRussell King sub sp, sp, #PT_REGS_SIZE 130b86040a5SCatalin Marinas ARM( stmib sp, {r1 - lr} ) 131b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 132b86040a5SCatalin Marinas THUMB( str sp, [sp, #S_SP] ) 133b86040a5SCatalin Marinas THUMB( str lr, [sp, #S_LR] ) 1341da177e4SLinus Torvalds mov r1, #\reason 1351da177e4SLinus Torvalds .endm 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds__pabt_invalid: 138ccea7a19SRussell King inv_entry BAD_PREFETCH 139ccea7a19SRussell King b common_invalid 14093ed3970SCatalin MarinasENDPROC(__pabt_invalid) 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds__dabt_invalid: 143ccea7a19SRussell King inv_entry BAD_DATA 144ccea7a19SRussell King b common_invalid 14593ed3970SCatalin MarinasENDPROC(__dabt_invalid) 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds__irq_invalid: 148ccea7a19SRussell King inv_entry BAD_IRQ 149ccea7a19SRussell King b common_invalid 15093ed3970SCatalin MarinasENDPROC(__irq_invalid) 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds__und_invalid: 153ccea7a19SRussell King inv_entry BAD_UNDEFINSTR 1541da177e4SLinus Torvalds 155ccea7a19SRussell King @ 156ccea7a19SRussell King @ XXX fall through to common_invalid 157ccea7a19SRussell King @ 158ccea7a19SRussell King 159ccea7a19SRussell King@ 160ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers) 161ccea7a19SRussell King@ 162ccea7a19SRussell Kingcommon_invalid: 163ccea7a19SRussell King zero_fp 164ccea7a19SRussell King 165ccea7a19SRussell King ldmia r0, {r4 - r6} 166ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 167ccea7a19SRussell King mov r7, #-1 @ "" "" "" "" 168ccea7a19SRussell King str r4, [sp] @ save preserved r0 169ccea7a19SRussell King stmia r0, {r5 - r7} @ lr_<exception>, 170ccea7a19SRussell King @ cpsr_<exception>, "old_r0" 171ccea7a19SRussell King 1721da177e4SLinus Torvalds mov r0, sp 1731da177e4SLinus Torvalds b bad_mode 17493ed3970SCatalin MarinasENDPROC(__und_invalid) 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds/* 1771da177e4SLinus Torvalds * SVC mode handlers 1781da177e4SLinus Torvalds */ 1792dede2d8SNicolas Pitre 1802dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) 1812dede2d8SNicolas Pitre#define SPFIX(code...) code 1822dede2d8SNicolas Pitre#else 1832dede2d8SNicolas Pitre#define SPFIX(code...) 1842dede2d8SNicolas Pitre#endif 1852dede2d8SNicolas Pitre 186a1c510d0SArd Biesheuvel .macro svc_entry, stack_hole=0, trace=1, uaccess=1, overflow_check=1 187c4c5716eSCatalin Marinas UNWIND(.fnstart ) 188ae5cc07dSArd Biesheuvel sub sp, sp, #(SVC_REGS_SIZE + \stack_hole) 189a1c510d0SArd Biesheuvel THUMB( add sp, r1 ) @ get SP in a GPR without 190a1c510d0SArd Biesheuvel THUMB( sub r1, sp, r1 ) @ using a temp register 191a1c510d0SArd Biesheuvel 192a1c510d0SArd Biesheuvel .if \overflow_check 193a1c510d0SArd Biesheuvel UNWIND(.save {r0 - pc} ) 194a1c510d0SArd Biesheuvel do_overflow_check (SVC_REGS_SIZE + \stack_hole) 195a1c510d0SArd Biesheuvel .endif 196a1c510d0SArd Biesheuvel 197b86040a5SCatalin Marinas#ifdef CONFIG_THUMB2_KERNEL 198ae5cc07dSArd Biesheuvel tst r1, #4 @ test stack pointer alignment 199ae5cc07dSArd Biesheuvel sub r1, sp, r1 @ restore original R1 200ae5cc07dSArd Biesheuvel sub sp, r1 @ restore original SP 201b86040a5SCatalin Marinas#else 2022dede2d8SNicolas Pitre SPFIX( tst sp, #4 ) 203b86040a5SCatalin Marinas#endif 204ae5cc07dSArd Biesheuvel SPFIX( subne sp, sp, #4 ) 205ae5cc07dSArd Biesheuvel 206ae5cc07dSArd Biesheuvel ARM( stmib sp, {r1 - r12} ) 207ae5cc07dSArd Biesheuvel THUMB( stmia sp, {r0 - r12} ) @ No STMIB in Thumb-2 208ccea7a19SRussell King 209b059bdc3SRussell King ldmia r0, {r3 - r5} 210ae5cc07dSArd Biesheuvel add r7, sp, #S_SP @ here for interlock avoidance 211b059bdc3SRussell King mov r6, #-1 @ "" "" "" "" 212ae5cc07dSArd Biesheuvel add r2, sp, #(SVC_REGS_SIZE + \stack_hole) 213ae5cc07dSArd Biesheuvel SPFIX( addne r2, r2, #4 ) 214ae5cc07dSArd Biesheuvel str r3, [sp] @ save the "real" r0 copied 215ccea7a19SRussell King @ from the exception stack 216ccea7a19SRussell King 217b059bdc3SRussell King mov r3, lr 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds @ 2201da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 2211da177e4SLinus Torvalds @ 222b059bdc3SRussell King @ r2 - sp_svc 223b059bdc3SRussell King @ r3 - lr_svc 224b059bdc3SRussell King @ r4 - lr_<exception>, already fixed up for correct return/restart 225b059bdc3SRussell King @ r5 - spsr_<exception> 226b059bdc3SRussell King @ r6 - orig_r0 (see pt_regs definition in ptrace.h) 2271da177e4SLinus Torvalds @ 228b059bdc3SRussell King stmia r7, {r2 - r6} 229f2741b78SRussell King 230e6978e4bSRussell King get_thread_info tsk 231747ffc2fSRussell King uaccess_entry tsk, r0, r1, r2, \uaccess 2322190fed6SRussell King 233c0e7f7eeSDaniel Thompson .if \trace 234f2741b78SRussell King#ifdef CONFIG_TRACE_IRQFLAGS 235f2741b78SRussell King bl trace_hardirqs_off 236f2741b78SRussell King#endif 237c0e7f7eeSDaniel Thompson .endif 2381da177e4SLinus Torvalds .endm 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds .align 5 2411da177e4SLinus Torvalds__dabt_svc: 2422190fed6SRussell King svc_entry uaccess=0 2431da177e4SLinus Torvalds mov r2, sp 244da740472SRussell King dabt_helper 245e16b31bfSMarc Zyngier THUMB( ldr r5, [sp, #S_PSR] ) @ potentially updated CPSR 246b059bdc3SRussell King svc_exit r5 @ return from exception 247c4c5716eSCatalin Marinas UNWIND(.fnend ) 24893ed3970SCatalin MarinasENDPROC(__dabt_svc) 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds .align 5 2511da177e4SLinus Torvalds__irq_svc: 252ccea7a19SRussell King svc_entry 253d4664b6cSArd Biesheuvel irq_handler from_user=0 2541613cc11SRussell King 255e7289c6dSThomas Gleixner#ifdef CONFIG_PREEMPTION 256706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 257706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get flags 25828fab1a2SRussell King teq r8, #0 @ if preempt count != 0 25928fab1a2SRussell King movne r0, #0 @ force flags to 0 2601da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2611da177e4SLinus Torvalds blne svc_preempt 2621da177e4SLinus Torvalds#endif 26330891c90SRussell King 2649b56febeSRussell King svc_exit r5, irq = 1 @ return from exception 265c4c5716eSCatalin Marinas UNWIND(.fnend ) 26693ed3970SCatalin MarinasENDPROC(__irq_svc) 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds .ltorg 2691da177e4SLinus Torvalds 270e7289c6dSThomas Gleixner#ifdef CONFIG_PREEMPTION 2711da177e4SLinus Torvaldssvc_preempt: 27228fab1a2SRussell King mov r8, lr 2731da177e4SLinus Torvalds1: bl preempt_schedule_irq @ irq en/disable is done inside 274706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS 2751da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2766ebbf2ceSRussell King reteq r8 @ go again 2771da177e4SLinus Torvalds b 1b 2781da177e4SLinus Torvalds#endif 2791da177e4SLinus Torvalds 28015ac49b6SRussell King__und_fault: 28115ac49b6SRussell King @ Correct the PC such that it is pointing at the instruction 28215ac49b6SRussell King @ which caused the fault. If the faulting instruction was ARM 28315ac49b6SRussell King @ the PC will be pointing at the next instruction, and have to 28415ac49b6SRussell King @ subtract 4. Otherwise, it is Thumb, and the PC will be 28515ac49b6SRussell King @ pointing at the second half of the Thumb instruction. We 28615ac49b6SRussell King @ have to subtract 2. 28715ac49b6SRussell King ldr r2, [r0, #S_PC] 28815ac49b6SRussell King sub r2, r2, r1 28915ac49b6SRussell King str r2, [r0, #S_PC] 29015ac49b6SRussell King b do_undefinstr 29115ac49b6SRussell KingENDPROC(__und_fault) 29215ac49b6SRussell King 2931da177e4SLinus Torvalds .align 5 2941da177e4SLinus Torvalds__und_svc: 295d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES 296d30a0c8bSNicolas Pitre @ If a kprobe is about to simulate a "stmdb sp..." instruction, 297d30a0c8bSNicolas Pitre @ it obviously needs free stack space which then will belong to 298d30a0c8bSNicolas Pitre @ the saved context. 299a0266c21SWang Nan svc_entry MAX_STACK_SIZE 300d30a0c8bSNicolas Pitre#else 301ccea7a19SRussell King svc_entry 302d30a0c8bSNicolas Pitre#endif 3031da177e4SLinus Torvalds 30415ac49b6SRussell King mov r1, #4 @ PC correction to apply 305f77ac2e3SArd Biesheuvel THUMB( tst r5, #PSR_T_BIT ) @ exception taken in Thumb mode? 306f77ac2e3SArd Biesheuvel THUMB( movne r1, #2 ) @ if so, fix up PC correction 3071da177e4SLinus Torvalds mov r0, sp @ struct pt_regs *regs 30815ac49b6SRussell King bl __und_fault 3091da177e4SLinus Torvalds 31015ac49b6SRussell King__und_svc_finish: 31187eed3c7SRussell King get_thread_info tsk 312b059bdc3SRussell King ldr r5, [sp, #S_PSR] @ Get SVC cpsr 313b059bdc3SRussell King svc_exit r5 @ return from exception 314c4c5716eSCatalin Marinas UNWIND(.fnend ) 31593ed3970SCatalin MarinasENDPROC(__und_svc) 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds .align 5 3181da177e4SLinus Torvalds__pabt_svc: 319ccea7a19SRussell King svc_entry 3204fb28474SKirill A. Shutemov mov r2, sp @ regs 3218dfe7ac9SRussell King pabt_helper 322b059bdc3SRussell King svc_exit r5 @ return from exception 323c4c5716eSCatalin Marinas UNWIND(.fnend ) 32493ed3970SCatalin MarinasENDPROC(__pabt_svc) 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds .align 5 327c0e7f7eeSDaniel Thompson__fiq_svc: 328c0e7f7eeSDaniel Thompson svc_entry trace=0 329c0e7f7eeSDaniel Thompson mov r0, sp @ struct pt_regs *regs 330c0e7f7eeSDaniel Thompson bl handle_fiq_as_nmi 331c0e7f7eeSDaniel Thompson svc_exit_via_fiq 332c0e7f7eeSDaniel Thompson UNWIND(.fnend ) 333c0e7f7eeSDaniel ThompsonENDPROC(__fiq_svc) 334c0e7f7eeSDaniel Thompson 335c0e7f7eeSDaniel Thompson .align 5 33649f680eaSRussell King.LCcralign: 33749f680eaSRussell King .word cr_alignment 33848d7927bSPaul Brook#ifdef MULTI_DABORT 3391da177e4SLinus Torvalds.LCprocfns: 3401da177e4SLinus Torvalds .word processor 3411da177e4SLinus Torvalds#endif 3421da177e4SLinus Torvalds.LCfp: 3431da177e4SLinus Torvalds .word fp_enter 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds/* 346c0e7f7eeSDaniel Thompson * Abort mode handlers 347c0e7f7eeSDaniel Thompson */ 348c0e7f7eeSDaniel Thompson 349c0e7f7eeSDaniel Thompson@ 350c0e7f7eeSDaniel Thompson@ Taking a FIQ in abort mode is similar to taking a FIQ in SVC mode 351c0e7f7eeSDaniel Thompson@ and reuses the same macros. However in abort mode we must also 352c0e7f7eeSDaniel Thompson@ save/restore lr_abt and spsr_abt to make nested aborts safe. 353c0e7f7eeSDaniel Thompson@ 354c0e7f7eeSDaniel Thompson .align 5 355c0e7f7eeSDaniel Thompson__fiq_abt: 356c0e7f7eeSDaniel Thompson svc_entry trace=0 357c0e7f7eeSDaniel Thompson 358c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 359c0e7f7eeSDaniel Thompson THUMB( mov r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 360c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 361c0e7f7eeSDaniel Thompson mov r1, lr @ Save lr_abt 362c0e7f7eeSDaniel Thompson mrs r2, spsr @ Save spsr_abt, abort is now safe 363c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 364c0e7f7eeSDaniel Thompson THUMB( mov r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 365c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 366c0e7f7eeSDaniel Thompson stmfd sp!, {r1 - r2} 367c0e7f7eeSDaniel Thompson 368c0e7f7eeSDaniel Thompson add r0, sp, #8 @ struct pt_regs *regs 369c0e7f7eeSDaniel Thompson bl handle_fiq_as_nmi 370c0e7f7eeSDaniel Thompson 371c0e7f7eeSDaniel Thompson ldmfd sp!, {r1 - r2} 372c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 373c0e7f7eeSDaniel Thompson THUMB( mov r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 374c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 375c0e7f7eeSDaniel Thompson mov lr, r1 @ Restore lr_abt, abort is unsafe 376c0e7f7eeSDaniel Thompson msr spsr_cxsf, r2 @ Restore spsr_abt 377c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 378c0e7f7eeSDaniel Thompson THUMB( mov r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 379c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 380c0e7f7eeSDaniel Thompson 381c0e7f7eeSDaniel Thompson svc_exit_via_fiq 382c0e7f7eeSDaniel Thompson UNWIND(.fnend ) 383c0e7f7eeSDaniel ThompsonENDPROC(__fiq_abt) 384c0e7f7eeSDaniel Thompson 385c0e7f7eeSDaniel Thompson/* 3861da177e4SLinus Torvalds * User mode handlers 3872dede2d8SNicolas Pitre * 3885745eef6SRussell King * EABI note: sp_svc is always 64-bit aligned here, so should PT_REGS_SIZE 3891da177e4SLinus Torvalds */ 3902dede2d8SNicolas Pitre 3915745eef6SRussell King#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (PT_REGS_SIZE & 7) 3922dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8" 3932dede2d8SNicolas Pitre#endif 3942dede2d8SNicolas Pitre 3952190fed6SRussell King .macro usr_entry, trace=1, uaccess=1 396c4c5716eSCatalin Marinas UNWIND(.fnstart ) 397c4c5716eSCatalin Marinas UNWIND(.cantunwind ) @ don't unwind the user space 3985745eef6SRussell King sub sp, sp, #PT_REGS_SIZE 399b86040a5SCatalin Marinas ARM( stmib sp, {r1 - r12} ) 400b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 401ccea7a19SRussell King 402195b58adSRussell King ATRAP( mrc p15, 0, r7, c1, c0, 0) 403195b58adSRussell King ATRAP( ldr r8, .LCcralign) 404195b58adSRussell King 405b059bdc3SRussell King ldmia r0, {r3 - r5} 406ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 407b059bdc3SRussell King mov r6, #-1 @ "" "" "" "" 408ccea7a19SRussell King 409b059bdc3SRussell King str r3, [sp] @ save the "real" r0 copied 410ccea7a19SRussell King @ from the exception stack 4111da177e4SLinus Torvalds 412195b58adSRussell King ATRAP( ldr r8, [r8, #0]) 413195b58adSRussell King 4141da177e4SLinus Torvalds @ 4151da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 4161da177e4SLinus Torvalds @ 417b059bdc3SRussell King @ r4 - lr_<exception>, already fixed up for correct return/restart 418b059bdc3SRussell King @ r5 - spsr_<exception> 419b059bdc3SRussell King @ r6 - orig_r0 (see pt_regs definition in ptrace.h) 4201da177e4SLinus Torvalds @ 4211da177e4SLinus Torvalds @ Also, separately save sp_usr and lr_usr 4221da177e4SLinus Torvalds @ 423b059bdc3SRussell King stmia r0, {r4 - r6} 424b86040a5SCatalin Marinas ARM( stmdb r0, {sp, lr}^ ) 425b86040a5SCatalin Marinas THUMB( store_user_sp_lr r0, r1, S_SP - S_PC ) 4261da177e4SLinus Torvalds 4272190fed6SRussell King .if \uaccess 4282190fed6SRussell King uaccess_disable ip 4292190fed6SRussell King .endif 4302190fed6SRussell King 4311da177e4SLinus Torvalds @ Enable the alignment trap while in kernel mode 432195b58adSRussell King ATRAP( teq r8, r7) 433195b58adSRussell King ATRAP( mcrne p15, 0, r8, c1, c0, 0) 4341da177e4SLinus Torvalds 43550596b75SArd Biesheuvel reload_current r7, r8 43650596b75SArd Biesheuvel 4371da177e4SLinus Torvalds @ 4381da177e4SLinus Torvalds @ Clear FP to mark the first stack frame 4391da177e4SLinus Torvalds @ 4401da177e4SLinus Torvalds zero_fp 441f2741b78SRussell King 442c0e7f7eeSDaniel Thompson .if \trace 44311b8b25cSRussell King#ifdef CONFIG_TRACE_IRQFLAGS 444f2741b78SRussell King bl trace_hardirqs_off 445f2741b78SRussell King#endif 446b0088480SKevin Hilman ct_user_exit save = 0 447c0e7f7eeSDaniel Thompson .endif 4481da177e4SLinus Torvalds .endm 4491da177e4SLinus Torvalds 450b49c0f24SNicolas Pitre .macro kuser_cmpxchg_check 451db695c05SRussell King#if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS) 452b49c0f24SNicolas Pitre#ifndef CONFIG_MMU 453b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing" 454b49c0f24SNicolas Pitre#else 455b49c0f24SNicolas Pitre @ Make sure our user space atomic helper is restarted 456b49c0f24SNicolas Pitre @ if it was interrupted in a critical region. Here we 457b49c0f24SNicolas Pitre @ perform a quick test inline since it should be false 458b49c0f24SNicolas Pitre @ 99.9999% of the time. The rest is done out of line. 459c12366baSLinus Walleij ldr r0, =TASK_SIZE 460c12366baSLinus Walleij cmp r4, r0 46140fb79c8SNicolas Pitre blhs kuser_cmpxchg64_fixup 462b49c0f24SNicolas Pitre#endif 463b49c0f24SNicolas Pitre#endif 464b49c0f24SNicolas Pitre .endm 465b49c0f24SNicolas Pitre 4661da177e4SLinus Torvalds .align 5 4671da177e4SLinus Torvalds__dabt_usr: 4682190fed6SRussell King usr_entry uaccess=0 469b49c0f24SNicolas Pitre kuser_cmpxchg_check 4701da177e4SLinus Torvalds mov r2, sp 471da740472SRussell King dabt_helper 472da740472SRussell King b ret_from_exception 473c4c5716eSCatalin Marinas UNWIND(.fnend ) 47493ed3970SCatalin MarinasENDPROC(__dabt_usr) 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds .align 5 4771da177e4SLinus Torvalds__irq_usr: 478ccea7a19SRussell King usr_entry 479bc089602SRussell King kuser_cmpxchg_check 480d4664b6cSArd Biesheuvel irq_handler from_user=1 4811613cc11SRussell King get_thread_info tsk 4821da177e4SLinus Torvalds mov why, #0 4839fc2552aSMing Lei b ret_to_user_from_irq 484c4c5716eSCatalin Marinas UNWIND(.fnend ) 48593ed3970SCatalin MarinasENDPROC(__irq_usr) 4861da177e4SLinus Torvalds 4871da177e4SLinus Torvalds .ltorg 4881da177e4SLinus Torvalds 4891da177e4SLinus Torvalds .align 5 4901da177e4SLinus Torvalds__und_usr: 4912190fed6SRussell King usr_entry uaccess=0 492bc089602SRussell King 493b059bdc3SRussell King mov r2, r4 494b059bdc3SRussell King mov r3, r5 4951da177e4SLinus Torvalds 49615ac49b6SRussell King @ r2 = regs->ARM_pc, which is either 2 or 4 bytes ahead of the 49715ac49b6SRussell King @ faulting instruction depending on Thumb mode. 49815ac49b6SRussell King @ r3 = regs->ARM_cpsr 4991da177e4SLinus Torvalds @ 50015ac49b6SRussell King @ The emulation code returns using r9 if it has emulated the 50115ac49b6SRussell King @ instruction, or the more conventional lr if we are to treat 50215ac49b6SRussell King @ this as a real undefined instruction 5031da177e4SLinus Torvalds @ 50414327c66SRussell King badr r9, ret_from_exception 50515ac49b6SRussell King 5061417a6b8SCatalin Marinas @ IRQs must be enabled before attempting to read the instruction from 5071417a6b8SCatalin Marinas @ user space since that could cause a page/translation fault if the 5081417a6b8SCatalin Marinas @ page table was modified by another CPU. 5091417a6b8SCatalin Marinas enable_irq 5101417a6b8SCatalin Marinas 511cb170a45SPaul Brook tst r3, #PSR_T_BIT @ Thumb mode? 51215ac49b6SRussell King bne __und_usr_thumb 51315ac49b6SRussell King sub r4, r2, #4 @ ARM instr at LR - 4 51415ac49b6SRussell King1: ldrt r0, [r4] 515457c2403SBen Dooks ARM_BE8(rev r0, r0) @ little endian instruction 516457c2403SBen Dooks 5172190fed6SRussell King uaccess_disable ip 5182190fed6SRussell King 51915ac49b6SRussell King @ r0 = 32-bit ARM instruction which caused the exception 52015ac49b6SRussell King @ r2 = PC value for the following instruction (:= regs->ARM_pc) 52115ac49b6SRussell King @ r4 = PC value for the faulting instruction 52215ac49b6SRussell King @ lr = 32-bit undefined instruction function 52314327c66SRussell King badr lr, __und_usr_fault_32 52415ac49b6SRussell King b call_fpe 52515ac49b6SRussell King 52615ac49b6SRussell King__und_usr_thumb: 527cb170a45SPaul Brook @ Thumb instruction 52815ac49b6SRussell King sub r4, r2, #2 @ First half of thumb instr at LR - 2 529ef4c5368SDave Martin#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7 530ef4c5368SDave Martin/* 531ef4c5368SDave Martin * Thumb-2 instruction handling. Note that because pre-v6 and >= v6 platforms 532ef4c5368SDave Martin * can never be supported in a single kernel, this code is not applicable at 533ef4c5368SDave Martin * all when __LINUX_ARM_ARCH__ < 6. This allows simplifying assumptions to be 534ef4c5368SDave Martin * made about .arch directives. 535ef4c5368SDave Martin */ 536ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7 537ef4c5368SDave Martin/* If the target CPU may not be Thumb-2-capable, a run-time check is needed: */ 538ef4c5368SDave Martin#define NEED_CPU_ARCHITECTURE 539ef4c5368SDave Martin ldr r5, .LCcpu_architecture 540ef4c5368SDave Martin ldr r5, [r5] 541ef4c5368SDave Martin cmp r5, #CPU_ARCH_ARMv7 54215ac49b6SRussell King blo __und_usr_fault_16 @ 16bit undefined instruction 543ef4c5368SDave Martin/* 544ef4c5368SDave Martin * The following code won't get run unless the running CPU really is v7, so 545ef4c5368SDave Martin * coding round the lack of ldrht on older arches is pointless. Temporarily 546ef4c5368SDave Martin * override the assembler target arch with the minimum required instead: 547ef4c5368SDave Martin */ 548ef4c5368SDave Martin .arch armv6t2 549ef4c5368SDave Martin#endif 55015ac49b6SRussell King2: ldrht r5, [r4] 551f8fe23ecSVictor KamenskyARM_BE8(rev16 r5, r5) @ little endian instruction 55285519189SDave Martin cmp r5, #0xe800 @ 32bit instruction if xx != 0 5532190fed6SRussell King blo __und_usr_fault_16_pan @ 16bit undefined instruction 55415ac49b6SRussell King3: ldrht r0, [r2] 555f8fe23ecSVictor KamenskyARM_BE8(rev16 r0, r0) @ little endian instruction 5562190fed6SRussell King uaccess_disable ip 557cb170a45SPaul Brook add r2, r2, #2 @ r2 is PC + 2, make it PC + 4 55815ac49b6SRussell King str r2, [sp, #S_PC] @ it's a 2x16bit instr, update 559cb170a45SPaul Brook orr r0, r0, r5, lsl #16 56014327c66SRussell King badr lr, __und_usr_fault_32 56115ac49b6SRussell King @ r0 = the two 16-bit Thumb instructions which caused the exception 56215ac49b6SRussell King @ r2 = PC value for the following Thumb instruction (:= regs->ARM_pc) 56315ac49b6SRussell King @ r4 = PC value for the first 16-bit Thumb instruction 56415ac49b6SRussell King @ lr = 32bit undefined instruction function 565ef4c5368SDave Martin 566ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7 567ef4c5368SDave Martin/* If the target arch was overridden, change it back: */ 568ef4c5368SDave Martin#ifdef CONFIG_CPU_32v6K 569ef4c5368SDave Martin .arch armv6k 570cb170a45SPaul Brook#else 571ef4c5368SDave Martin .arch armv6 572ef4c5368SDave Martin#endif 573ef4c5368SDave Martin#endif /* __LINUX_ARM_ARCH__ < 7 */ 574ef4c5368SDave Martin#else /* !(CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7) */ 57515ac49b6SRussell King b __und_usr_fault_16 576cb170a45SPaul Brook#endif 577c4c5716eSCatalin Marinas UNWIND(.fnend) 57893ed3970SCatalin MarinasENDPROC(__und_usr) 579cb170a45SPaul Brook 5801da177e4SLinus Torvalds/* 58115ac49b6SRussell King * The out of line fixup for the ldrt instructions above. 5821da177e4SLinus Torvalds */ 583c4a84ae3SArd Biesheuvel .pushsection .text.fixup, "ax" 584667d1b48SWill Deacon .align 2 5853780f7abSArun K S4: str r4, [sp, #S_PC] @ retry current instruction 5866ebbf2ceSRussell King ret r9 5874260415fSRussell King .popsection 5884260415fSRussell King .pushsection __ex_table,"a" 589cb170a45SPaul Brook .long 1b, 4b 590c89cefedSGuennadi Liakhovetski#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7 591cb170a45SPaul Brook .long 2b, 4b 592cb170a45SPaul Brook .long 3b, 4b 593cb170a45SPaul Brook#endif 5944260415fSRussell King .popsection 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds/* 5971da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction. 5981da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler. 5991da177e4SLinus Torvalds * 6001da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor 6011da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well 6021da177e4SLinus Torvalds * defined. The only instructions that should fault are the 6031da177e4SLinus Torvalds * co-processor instructions. However, we have to watch out 6041da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug. 6051da177e4SLinus Torvalds * 606b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all 607b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have 608b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's 609b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs 610b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the 611b5872db4SCatalin Marinas * NEON handler code. 612b5872db4SCatalin Marinas * 6131da177e4SLinus Torvalds * Emulators may wish to make use of the following registers: 61415ac49b6SRussell King * r0 = instruction opcode (32-bit ARM or two 16-bit Thumb) 61515ac49b6SRussell King * r2 = PC value to resume execution after successful emulation 616db6ccbb6SRussell King * r9 = normal "successful" return address 61715ac49b6SRussell King * r10 = this threads thread_info structure 618db6ccbb6SRussell King * lr = unrecognised instruction return address 6191417a6b8SCatalin Marinas * IRQs enabled, FIQs enabled. 6201da177e4SLinus Torvalds */ 621cb170a45SPaul Brook @ 622cb170a45SPaul Brook @ Fall-through from Thumb-2 __und_usr 623cb170a45SPaul Brook @ 624cb170a45SPaul Brook#ifdef CONFIG_NEON 625d3f79584SRussell King get_thread_info r10 @ get current thread 626cb170a45SPaul Brook adr r6, .LCneon_thumb_opcodes 627cb170a45SPaul Brook b 2f 628cb170a45SPaul Brook#endif 6291da177e4SLinus Torvaldscall_fpe: 630d3f79584SRussell King get_thread_info r10 @ get current thread 631b5872db4SCatalin Marinas#ifdef CONFIG_NEON 632cb170a45SPaul Brook adr r6, .LCneon_arm_opcodes 633d3f79584SRussell King2: ldr r5, [r6], #4 @ mask value 634b5872db4SCatalin Marinas ldr r7, [r6], #4 @ opcode bits matching in mask 635d3f79584SRussell King cmp r5, #0 @ end mask? 636d3f79584SRussell King beq 1f 637d3f79584SRussell King and r8, r0, r5 638b5872db4SCatalin Marinas cmp r8, r7 @ NEON instruction? 639b5872db4SCatalin Marinas bne 2b 640b5872db4SCatalin Marinas mov r7, #1 641b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used 642b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used 643b5872db4SCatalin Marinas b do_vfp @ let VFP handler handle this 644b5872db4SCatalin Marinas1: 645b5872db4SCatalin Marinas#endif 6461da177e4SLinus Torvalds tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27 647cb170a45SPaul Brook tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2 6486ebbf2ceSRussell King reteq lr 6491da177e4SLinus Torvalds and r8, r0, #0x00000f00 @ mask out CP number 650b86040a5SCatalin Marinas THUMB( lsr r8, r8, #8 ) 6511da177e4SLinus Torvalds mov r7, #1 6521da177e4SLinus Torvalds add r6, r10, #TI_USED_CP 653b86040a5SCatalin Marinas ARM( strb r7, [r6, r8, lsr #8] ) @ set appropriate used_cp[] 654b86040a5SCatalin Marinas THUMB( strb r7, [r6, r8] ) @ set appropriate used_cp[] 6551da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT 6561da177e4SLinus Torvalds @ Test if we need to give access to iWMMXt coprocessors 6571da177e4SLinus Torvalds ldr r5, [r10, #TI_FLAGS] 6581da177e4SLinus Torvalds rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only 659e44fc388SStefan Agner movscs r7, r5, lsr #(TIF_USING_IWMMXT + 1) 6601da177e4SLinus Torvalds bcs iwmmxt_task_enable 6611da177e4SLinus Torvalds#endif 662b86040a5SCatalin Marinas ARM( add pc, pc, r8, lsr #6 ) 663b86040a5SCatalin Marinas THUMB( lsl r8, r8, #2 ) 664b86040a5SCatalin Marinas THUMB( add pc, r8 ) 665b86040a5SCatalin Marinas nop 6661da177e4SLinus Torvalds 6676ebbf2ceSRussell King ret.w lr @ CP#0 668b86040a5SCatalin Marinas W(b) do_fpe @ CP#1 (FPE) 669b86040a5SCatalin Marinas W(b) do_fpe @ CP#2 (FPE) 6706ebbf2ceSRussell King ret.w lr @ CP#3 6716ebbf2ceSRussell King ret.w lr @ CP#4 6726ebbf2ceSRussell King ret.w lr @ CP#5 6736ebbf2ceSRussell King ret.w lr @ CP#6 6746ebbf2ceSRussell King ret.w lr @ CP#7 6756ebbf2ceSRussell King ret.w lr @ CP#8 6766ebbf2ceSRussell King ret.w lr @ CP#9 6771da177e4SLinus Torvalds#ifdef CONFIG_VFP 678b86040a5SCatalin Marinas W(b) do_vfp @ CP#10 (VFP) 679b86040a5SCatalin Marinas W(b) do_vfp @ CP#11 (VFP) 6801da177e4SLinus Torvalds#else 6816ebbf2ceSRussell King ret.w lr @ CP#10 (VFP) 6826ebbf2ceSRussell King ret.w lr @ CP#11 (VFP) 6831da177e4SLinus Torvalds#endif 6846ebbf2ceSRussell King ret.w lr @ CP#12 6856ebbf2ceSRussell King ret.w lr @ CP#13 6866ebbf2ceSRussell King ret.w lr @ CP#14 (Debug) 6876ebbf2ceSRussell King ret.w lr @ CP#15 (Control) 6881da177e4SLinus Torvalds 689ef4c5368SDave Martin#ifdef NEED_CPU_ARCHITECTURE 690ef4c5368SDave Martin .align 2 691ef4c5368SDave Martin.LCcpu_architecture: 692ef4c5368SDave Martin .word __cpu_architecture 693ef4c5368SDave Martin#endif 694ef4c5368SDave Martin 695b5872db4SCatalin Marinas#ifdef CONFIG_NEON 696b5872db4SCatalin Marinas .align 6 697b5872db4SCatalin Marinas 698cb170a45SPaul Brook.LCneon_arm_opcodes: 699b5872db4SCatalin Marinas .word 0xfe000000 @ mask 700b5872db4SCatalin Marinas .word 0xf2000000 @ opcode 701b5872db4SCatalin Marinas 702b5872db4SCatalin Marinas .word 0xff100000 @ mask 703b5872db4SCatalin Marinas .word 0xf4000000 @ opcode 704b5872db4SCatalin Marinas 705b5872db4SCatalin Marinas .word 0x00000000 @ mask 706b5872db4SCatalin Marinas .word 0x00000000 @ opcode 707cb170a45SPaul Brook 708cb170a45SPaul Brook.LCneon_thumb_opcodes: 709cb170a45SPaul Brook .word 0xef000000 @ mask 710cb170a45SPaul Brook .word 0xef000000 @ opcode 711cb170a45SPaul Brook 712cb170a45SPaul Brook .word 0xff100000 @ mask 713cb170a45SPaul Brook .word 0xf9000000 @ opcode 714cb170a45SPaul Brook 715cb170a45SPaul Brook .word 0x00000000 @ mask 716cb170a45SPaul Brook .word 0x00000000 @ opcode 717b5872db4SCatalin Marinas#endif 718b5872db4SCatalin Marinas 7191da177e4SLinus Torvaldsdo_fpe: 7201da177e4SLinus Torvalds ldr r4, .LCfp 7211da177e4SLinus Torvalds add r10, r10, #TI_FPSTATE @ r10 = workspace 7221da177e4SLinus Torvalds ldr pc, [r4] @ Call FP module USR entry point 7231da177e4SLinus Torvalds 7241da177e4SLinus Torvalds/* 7251da177e4SLinus Torvalds * The FP module is called with these registers set: 7261da177e4SLinus Torvalds * r0 = instruction 7271da177e4SLinus Torvalds * r2 = PC+4 7281da177e4SLinus Torvalds * r9 = normal "successful" return address 7291da177e4SLinus Torvalds * r10 = FP workspace 7301da177e4SLinus Torvalds * lr = unrecognised FP instruction return address 7311da177e4SLinus Torvalds */ 7321da177e4SLinus Torvalds 733124efc27SSantosh Shilimkar .pushsection .data 7341abd3502SRussell King .align 2 7351da177e4SLinus TorvaldsENTRY(fp_enter) 736db6ccbb6SRussell King .word no_fp 737124efc27SSantosh Shilimkar .popsection 7381da177e4SLinus Torvalds 73983e686eaSCatalin MarinasENTRY(no_fp) 7406ebbf2ceSRussell King ret lr 74183e686eaSCatalin MarinasENDPROC(no_fp) 742db6ccbb6SRussell King 74315ac49b6SRussell King__und_usr_fault_32: 74415ac49b6SRussell King mov r1, #4 74515ac49b6SRussell King b 1f 7462190fed6SRussell King__und_usr_fault_16_pan: 7472190fed6SRussell King uaccess_disable ip 74815ac49b6SRussell King__und_usr_fault_16: 74915ac49b6SRussell King mov r1, #2 7501417a6b8SCatalin Marinas1: mov r0, sp 75114327c66SRussell King badr lr, ret_from_exception 75215ac49b6SRussell King b __und_fault 75315ac49b6SRussell KingENDPROC(__und_usr_fault_32) 75415ac49b6SRussell KingENDPROC(__und_usr_fault_16) 7551da177e4SLinus Torvalds 7561da177e4SLinus Torvalds .align 5 7571da177e4SLinus Torvalds__pabt_usr: 758ccea7a19SRussell King usr_entry 7594fb28474SKirill A. Shutemov mov r2, sp @ regs 7608dfe7ac9SRussell King pabt_helper 761c4c5716eSCatalin Marinas UNWIND(.fnend ) 7621da177e4SLinus Torvalds /* fall through */ 7631da177e4SLinus Torvalds/* 7641da177e4SLinus Torvalds * This is the return code to user mode for abort handlers 7651da177e4SLinus Torvalds */ 7661da177e4SLinus TorvaldsENTRY(ret_from_exception) 767c4c5716eSCatalin Marinas UNWIND(.fnstart ) 768c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 7691da177e4SLinus Torvalds get_thread_info tsk 7701da177e4SLinus Torvalds mov why, #0 7711da177e4SLinus Torvalds b ret_to_user 772c4c5716eSCatalin Marinas UNWIND(.fnend ) 77393ed3970SCatalin MarinasENDPROC(__pabt_usr) 77493ed3970SCatalin MarinasENDPROC(ret_from_exception) 7751da177e4SLinus Torvalds 776c0e7f7eeSDaniel Thompson .align 5 777c0e7f7eeSDaniel Thompson__fiq_usr: 778c0e7f7eeSDaniel Thompson usr_entry trace=0 779c0e7f7eeSDaniel Thompson kuser_cmpxchg_check 780c0e7f7eeSDaniel Thompson mov r0, sp @ struct pt_regs *regs 781c0e7f7eeSDaniel Thompson bl handle_fiq_as_nmi 782c0e7f7eeSDaniel Thompson get_thread_info tsk 783c0e7f7eeSDaniel Thompson restore_user_regs fast = 0, offset = 0 784c0e7f7eeSDaniel Thompson UNWIND(.fnend ) 785c0e7f7eeSDaniel ThompsonENDPROC(__fiq_usr) 786c0e7f7eeSDaniel Thompson 7871da177e4SLinus Torvalds/* 7881da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors 7891da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info 7901da177e4SLinus Torvalds * previous and next are guaranteed not to be the same. 7911da177e4SLinus Torvalds */ 7921da177e4SLinus TorvaldsENTRY(__switch_to) 793c4c5716eSCatalin Marinas UNWIND(.fnstart ) 794c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 7951da177e4SLinus Torvalds add ip, r1, #TI_CPU_SAVE 796b86040a5SCatalin Marinas ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack 797b86040a5SCatalin Marinas THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack 798b86040a5SCatalin Marinas THUMB( str sp, [ip], #4 ) 799b86040a5SCatalin Marinas THUMB( str lr, [ip], #4 ) 800a4780adeSAndré Hentschel ldr r4, [r2, #TI_TP_VALUE] 801a4780adeSAndré Hentschel ldr r5, [r2, #TI_TP_VALUE + 4] 802247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 8031eef5d2fSRussell King mrc p15, 0, r6, c3, c0, 0 @ Get domain register 8041eef5d2fSRussell King str r6, [r1, #TI_CPU_DOMAIN] @ Save old domain register 805d6551e88SRussell King ldr r6, [r2, #TI_CPU_DOMAIN] 806afeb90caSHyok S. Choi#endif 807a4780adeSAndré Hentschel switch_tls r1, r4, r5, r3, r7 808831a469bSArd Biesheuvel#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) && \ 809831a469bSArd Biesheuvel !defined(CONFIG_STACKPROTECTOR_PER_TASK) 810831a469bSArd Biesheuvel ldr r9, [r2, #TI_TASK] 811df0698beSNicolas Pitre ldr r8, =__stack_chk_guard 812ffa47aa6SArnd Bergmann .if (TSK_STACK_CANARY > IMM12_MASK) 813831a469bSArd Biesheuvel add r9, r9, #TSK_STACK_CANARY & ~IMM12_MASK 814ffa47aa6SArnd Bergmann .endif 815831a469bSArd Biesheuvel ldr r9, [r9, #TSK_STACK_CANARY & IMM12_MASK] 816df0698beSNicolas Pitre#endif 817831a469bSArd Biesheuvel mov r7, r2 @ Preserve 'next' 818247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 8191da177e4SLinus Torvalds mcr p15, 0, r6, c3, c0, 0 @ Set domain register 820afeb90caSHyok S. Choi#endif 821d6551e88SRussell King mov r5, r0 822d6551e88SRussell King add r4, r2, #TI_CPU_SAVE 823d6551e88SRussell King ldr r0, =thread_notify_head 824d6551e88SRussell King mov r1, #THREAD_NOTIFY_SWITCH 825d6551e88SRussell King bl atomic_notifier_call_chain 826831a469bSArd Biesheuvel#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) && \ 827831a469bSArd Biesheuvel !defined(CONFIG_STACKPROTECTOR_PER_TASK) 828831a469bSArd Biesheuvel str r9, [r8] 829df0698beSNicolas Pitre#endif 830d6551e88SRussell King mov r0, r5 831a1c510d0SArd Biesheuvel#if !defined(CONFIG_THUMB2_KERNEL) && !defined(CONFIG_VMAP_STACK) 83250596b75SArd Biesheuvel set_current r7 833b832faecSArd Biesheuvel ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously 834b832faecSArd Biesheuvel#else 835b832faecSArd Biesheuvel mov r1, r7 836b832faecSArd Biesheuvel ldmia r4, {r4 - sl, fp, ip, lr} @ Load all regs saved previously 837a1c510d0SArd Biesheuvel#ifdef CONFIG_VMAP_STACK 838a1c510d0SArd Biesheuvel @ 839a1c510d0SArd Biesheuvel @ Do a dummy read from the new stack while running from the old one so 840a1c510d0SArd Biesheuvel @ that we can rely on do_translation_fault() to fix up any stale PMD 841a1c510d0SArd Biesheuvel @ entries covering the vmalloc region. 842a1c510d0SArd Biesheuvel @ 843a1c510d0SArd Biesheuvel ldr r2, [ip] 844a1c510d0SArd Biesheuvel#endif 845b832faecSArd Biesheuvel 846b832faecSArd Biesheuvel @ When CONFIG_THREAD_INFO_IN_TASK=n, the update of SP itself is what 847b832faecSArd Biesheuvel @ effectuates the task switch, as that is what causes the observable 848b832faecSArd Biesheuvel @ values of current and current_thread_info to change. When 849b832faecSArd Biesheuvel @ CONFIG_THREAD_INFO_IN_TASK=y, setting current (and therefore 850b832faecSArd Biesheuvel @ current_thread_info) is done explicitly, and the update of SP just 851b832faecSArd Biesheuvel @ switches us to another stack, with few other side effects. In order 852b832faecSArd Biesheuvel @ to prevent this distinction from causing any inconsistencies, let's 853b832faecSArd Biesheuvel @ keep the 'set_current' call as close as we can to the update of SP. 854b832faecSArd Biesheuvel set_current r1 855b832faecSArd Biesheuvel mov sp, ip 856b832faecSArd Biesheuvel ret lr 857b832faecSArd Biesheuvel#endif 858c4c5716eSCatalin Marinas UNWIND(.fnend ) 85993ed3970SCatalin MarinasENDPROC(__switch_to) 8601da177e4SLinus Torvalds 861a1c510d0SArd Biesheuvel#ifdef CONFIG_VMAP_STACK 862a1c510d0SArd Biesheuvel .text 863a1c510d0SArd Biesheuvel .align 2 864a1c510d0SArd Biesheuvel__bad_stack: 865a1c510d0SArd Biesheuvel @ 866a1c510d0SArd Biesheuvel @ We've just detected an overflow. We need to load the address of this 867a1c510d0SArd Biesheuvel @ CPU's overflow stack into the stack pointer register. We have only one 868a1c510d0SArd Biesheuvel @ scratch register so let's use a sequence of ADDs including one 869a1c510d0SArd Biesheuvel @ involving the PC, and decorate them with PC-relative group 870a1c510d0SArd Biesheuvel @ relocations. As these are ARM only, switch to ARM mode first. 871a1c510d0SArd Biesheuvel @ 872a1c510d0SArd Biesheuvel @ We enter here with IP clobbered and its value stashed on the mode 873a1c510d0SArd Biesheuvel @ stack. 874a1c510d0SArd Biesheuvel @ 875a1c510d0SArd BiesheuvelTHUMB( bx pc ) 876a1c510d0SArd BiesheuvelTHUMB( nop ) 877a1c510d0SArd BiesheuvelTHUMB( .arm ) 878*7b9896c3SArd Biesheuvel ldr_this_cpu_armv6 ip, overflow_stack_ptr 879a1c510d0SArd Biesheuvel 880a1c510d0SArd Biesheuvel str sp, [ip, #-4]! @ Preserve original SP value 881a1c510d0SArd Biesheuvel mov sp, ip @ Switch to overflow stack 882a1c510d0SArd Biesheuvel pop {ip} @ Original SP in IP 883a1c510d0SArd Biesheuvel 884a1c510d0SArd Biesheuvel#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) 885a1c510d0SArd Biesheuvel mov ip, ip @ mov expected by unwinder 886a1c510d0SArd Biesheuvel push {fp, ip, lr, pc} @ GCC flavor frame record 887a1c510d0SArd Biesheuvel#else 888a1c510d0SArd Biesheuvel str ip, [sp, #-8]! @ store original SP 889a1c510d0SArd Biesheuvel push {fpreg, lr} @ Clang flavor frame record 890a1c510d0SArd Biesheuvel#endif 891a1c510d0SArd BiesheuvelUNWIND( ldr ip, [r0, #4] ) @ load exception LR 892a1c510d0SArd BiesheuvelUNWIND( str ip, [sp, #12] ) @ store in the frame record 893a1c510d0SArd Biesheuvel ldr ip, [r0, #12] @ reload IP 894a1c510d0SArd Biesheuvel 895a1c510d0SArd Biesheuvel @ Store the original GPRs to the new stack. 896a1c510d0SArd Biesheuvel svc_entry uaccess=0, overflow_check=0 897a1c510d0SArd Biesheuvel 898a1c510d0SArd BiesheuvelUNWIND( .save {sp, pc} ) 899a1c510d0SArd BiesheuvelUNWIND( .save {fpreg, lr} ) 900a1c510d0SArd BiesheuvelUNWIND( .setfp fpreg, sp ) 901a1c510d0SArd Biesheuvel 902a1c510d0SArd Biesheuvel ldr fpreg, [sp, #S_SP] @ Add our frame record 903a1c510d0SArd Biesheuvel @ to the linked list 904a1c510d0SArd Biesheuvel#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) 905a1c510d0SArd Biesheuvel ldr r1, [fp, #4] @ reload SP at entry 906a1c510d0SArd Biesheuvel add fp, fp, #12 907a1c510d0SArd Biesheuvel#else 908a1c510d0SArd Biesheuvel ldr r1, [fpreg, #8] 909a1c510d0SArd Biesheuvel#endif 910a1c510d0SArd Biesheuvel str r1, [sp, #S_SP] @ store in pt_regs 911a1c510d0SArd Biesheuvel 912a1c510d0SArd Biesheuvel @ Stash the regs for handle_bad_stack 913a1c510d0SArd Biesheuvel mov r0, sp 914a1c510d0SArd Biesheuvel 915a1c510d0SArd Biesheuvel @ Time to die 916a1c510d0SArd Biesheuvel bl handle_bad_stack 917a1c510d0SArd Biesheuvel nop 918a1c510d0SArd BiesheuvelUNWIND( .fnend ) 919a1c510d0SArd BiesheuvelENDPROC(__bad_stack) 920a1c510d0SArd Biesheuvel#endif 921a1c510d0SArd Biesheuvel 9221da177e4SLinus Torvalds __INIT 9232d2669b6SNicolas Pitre 9242d2669b6SNicolas Pitre/* 9252d2669b6SNicolas Pitre * User helpers. 9262d2669b6SNicolas Pitre * 9272d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high 9282d2669b6SNicolas Pitre * vector page. New segments (if ever needed) must be added in front of 9292d2669b6SNicolas Pitre * existing ones. This mechanism should be used only for things that are 9302d2669b6SNicolas Pitre * really small and justified, and not be abused freely. 9312d2669b6SNicolas Pitre * 932dc7a12bdSMauro Carvalho Chehab * See Documentation/arm/kernel_user_helpers.rst for formal definitions. 9332d2669b6SNicolas Pitre */ 934b86040a5SCatalin Marinas THUMB( .arm ) 9352d2669b6SNicolas Pitre 936ba9b5d76SNicolas Pitre .macro usr_ret, reg 937ba9b5d76SNicolas Pitre#ifdef CONFIG_ARM_THUMB 938ba9b5d76SNicolas Pitre bx \reg 939ba9b5d76SNicolas Pitre#else 9406ebbf2ceSRussell King ret \reg 941ba9b5d76SNicolas Pitre#endif 942ba9b5d76SNicolas Pitre .endm 943ba9b5d76SNicolas Pitre 9445b43e7a3SRussell King .macro kuser_pad, sym, size 9455b43e7a3SRussell King .if (. - \sym) & 3 9465b43e7a3SRussell King .rept 4 - (. - \sym) & 3 9475b43e7a3SRussell King .byte 0 9485b43e7a3SRussell King .endr 9495b43e7a3SRussell King .endif 9505b43e7a3SRussell King .rept (\size - (. - \sym)) / 4 9515b43e7a3SRussell King .word 0xe7fddef1 9525b43e7a3SRussell King .endr 9535b43e7a3SRussell King .endm 9545b43e7a3SRussell King 955f6f91b0dSRussell King#ifdef CONFIG_KUSER_HELPERS 9562d2669b6SNicolas Pitre .align 5 9572d2669b6SNicolas Pitre .globl __kuser_helper_start 9582d2669b6SNicolas Pitre__kuser_helper_start: 9592d2669b6SNicolas Pitre 9602d2669b6SNicolas Pitre/* 96140fb79c8SNicolas Pitre * Due to the length of some sequences, __kuser_cmpxchg64 spans 2 regular 96240fb79c8SNicolas Pitre * kuser "slots", therefore 0xffff0f80 is not used as a valid entry point. 9637c612bfdSNicolas Pitre */ 9647c612bfdSNicolas Pitre 96540fb79c8SNicolas Pitre__kuser_cmpxchg64: @ 0xffff0f60 96640fb79c8SNicolas Pitre 967db695c05SRussell King#if defined(CONFIG_CPU_32v6K) 96840fb79c8SNicolas Pitre 96940fb79c8SNicolas Pitre stmfd sp!, {r4, r5, r6, r7} 97040fb79c8SNicolas Pitre ldrd r4, r5, [r0] @ load old val 97140fb79c8SNicolas Pitre ldrd r6, r7, [r1] @ load new val 97240fb79c8SNicolas Pitre smp_dmb arm 97340fb79c8SNicolas Pitre1: ldrexd r0, r1, [r2] @ load current val 97440fb79c8SNicolas Pitre eors r3, r0, r4 @ compare with oldval (1) 975e44fc388SStefan Agner eorseq r3, r1, r5 @ compare with oldval (2) 97640fb79c8SNicolas Pitre strexdeq r3, r6, r7, [r2] @ store newval if eq 97740fb79c8SNicolas Pitre teqeq r3, #1 @ success? 97840fb79c8SNicolas Pitre beq 1b @ if no then retry 97940fb79c8SNicolas Pitre smp_dmb arm 98040fb79c8SNicolas Pitre rsbs r0, r3, #0 @ set returned val and C flag 98140fb79c8SNicolas Pitre ldmfd sp!, {r4, r5, r6, r7} 9825a97d0aeSWill Deacon usr_ret lr 98340fb79c8SNicolas Pitre 98440fb79c8SNicolas Pitre#elif !defined(CONFIG_SMP) 98540fb79c8SNicolas Pitre 98640fb79c8SNicolas Pitre#ifdef CONFIG_MMU 98740fb79c8SNicolas Pitre 98840fb79c8SNicolas Pitre /* 98940fb79c8SNicolas Pitre * The only thing that can break atomicity in this cmpxchg64 99040fb79c8SNicolas Pitre * implementation is either an IRQ or a data abort exception 99140fb79c8SNicolas Pitre * causing another process/thread to be scheduled in the middle of 99240fb79c8SNicolas Pitre * the critical sequence. The same strategy as for cmpxchg is used. 99340fb79c8SNicolas Pitre */ 99440fb79c8SNicolas Pitre stmfd sp!, {r4, r5, r6, lr} 99540fb79c8SNicolas Pitre ldmia r0, {r4, r5} @ load old val 99640fb79c8SNicolas Pitre ldmia r1, {r6, lr} @ load new val 99740fb79c8SNicolas Pitre1: ldmia r2, {r0, r1} @ load current val 99840fb79c8SNicolas Pitre eors r3, r0, r4 @ compare with oldval (1) 999e44fc388SStefan Agner eorseq r3, r1, r5 @ compare with oldval (2) 1000e44fc388SStefan Agner2: stmiaeq r2, {r6, lr} @ store newval if eq 100140fb79c8SNicolas Pitre rsbs r0, r3, #0 @ set return val and C flag 100240fb79c8SNicolas Pitre ldmfd sp!, {r4, r5, r6, pc} 100340fb79c8SNicolas Pitre 100440fb79c8SNicolas Pitre .text 100540fb79c8SNicolas Pitrekuser_cmpxchg64_fixup: 100640fb79c8SNicolas Pitre @ Called from kuser_cmpxchg_fixup. 10073ad55155SRussell King @ r4 = address of interrupted insn (must be preserved). 100840fb79c8SNicolas Pitre @ sp = saved regs. r7 and r8 are clobbered. 100940fb79c8SNicolas Pitre @ 1b = first critical insn, 2b = last critical insn. 10103ad55155SRussell King @ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b. 101140fb79c8SNicolas Pitre mov r7, #0xffff0fff 101240fb79c8SNicolas Pitre sub r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64))) 10133ad55155SRussell King subs r8, r4, r7 1014e44fc388SStefan Agner rsbscs r8, r8, #(2b - 1b) 101540fb79c8SNicolas Pitre strcs r7, [sp, #S_PC] 101640fb79c8SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6 101740fb79c8SNicolas Pitre bcc kuser_cmpxchg32_fixup 101840fb79c8SNicolas Pitre#endif 10196ebbf2ceSRussell King ret lr 102040fb79c8SNicolas Pitre .previous 102140fb79c8SNicolas Pitre 102240fb79c8SNicolas Pitre#else 102340fb79c8SNicolas Pitre#warning "NPTL on non MMU needs fixing" 102440fb79c8SNicolas Pitre mov r0, #-1 102540fb79c8SNicolas Pitre adds r0, r0, #0 102640fb79c8SNicolas Pitre usr_ret lr 102740fb79c8SNicolas Pitre#endif 102840fb79c8SNicolas Pitre 102940fb79c8SNicolas Pitre#else 103040fb79c8SNicolas Pitre#error "incoherent kernel configuration" 103140fb79c8SNicolas Pitre#endif 103240fb79c8SNicolas Pitre 10335b43e7a3SRussell King kuser_pad __kuser_cmpxchg64, 64 103440fb79c8SNicolas Pitre 10357c612bfdSNicolas Pitre__kuser_memory_barrier: @ 0xffff0fa0 1036ed3768a8SDave Martin smp_dmb arm 1037ba9b5d76SNicolas Pitre usr_ret lr 10387c612bfdSNicolas Pitre 10395b43e7a3SRussell King kuser_pad __kuser_memory_barrier, 32 10407c612bfdSNicolas Pitre 10412d2669b6SNicolas Pitre__kuser_cmpxchg: @ 0xffff0fc0 10422d2669b6SNicolas Pitre 1043db695c05SRussell King#if __LINUX_ARM_ARCH__ < 6 10442d2669b6SNicolas Pitre 104549bca4c2SNicolas Pitre#ifdef CONFIG_MMU 1046b49c0f24SNicolas Pitre 1047b49c0f24SNicolas Pitre /* 1048b49c0f24SNicolas Pitre * The only thing that can break atomicity in this cmpxchg 1049b49c0f24SNicolas Pitre * implementation is either an IRQ or a data abort exception 1050b49c0f24SNicolas Pitre * causing another process/thread to be scheduled in the middle 1051b49c0f24SNicolas Pitre * of the critical sequence. To prevent this, code is added to 1052b49c0f24SNicolas Pitre * the IRQ and data abort exception handlers to set the pc back 1053b49c0f24SNicolas Pitre * to the beginning of the critical section if it is found to be 1054b49c0f24SNicolas Pitre * within that critical section (see kuser_cmpxchg_fixup). 1055b49c0f24SNicolas Pitre */ 1056b49c0f24SNicolas Pitre1: ldr r3, [r2] @ load current val 1057b49c0f24SNicolas Pitre subs r3, r3, r0 @ compare with oldval 1058b49c0f24SNicolas Pitre2: streq r1, [r2] @ store newval if eq 1059b49c0f24SNicolas Pitre rsbs r0, r3, #0 @ set return val and C flag 1060b49c0f24SNicolas Pitre usr_ret lr 1061b49c0f24SNicolas Pitre 1062b49c0f24SNicolas Pitre .text 106340fb79c8SNicolas Pitrekuser_cmpxchg32_fixup: 1064b49c0f24SNicolas Pitre @ Called from kuser_cmpxchg_check macro. 1065b059bdc3SRussell King @ r4 = address of interrupted insn (must be preserved). 1066b49c0f24SNicolas Pitre @ sp = saved regs. r7 and r8 are clobbered. 1067b49c0f24SNicolas Pitre @ 1b = first critical insn, 2b = last critical insn. 1068b059bdc3SRussell King @ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b. 1069b49c0f24SNicolas Pitre mov r7, #0xffff0fff 1070b49c0f24SNicolas Pitre sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg))) 1071b059bdc3SRussell King subs r8, r4, r7 1072e44fc388SStefan Agner rsbscs r8, r8, #(2b - 1b) 1073b49c0f24SNicolas Pitre strcs r7, [sp, #S_PC] 10746ebbf2ceSRussell King ret lr 1075b49c0f24SNicolas Pitre .previous 1076b49c0f24SNicolas Pitre 107749bca4c2SNicolas Pitre#else 107849bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing" 107949bca4c2SNicolas Pitre mov r0, #-1 108049bca4c2SNicolas Pitre adds r0, r0, #0 1081ba9b5d76SNicolas Pitre usr_ret lr 1082b49c0f24SNicolas Pitre#endif 10832d2669b6SNicolas Pitre 10842d2669b6SNicolas Pitre#else 10852d2669b6SNicolas Pitre 1086ed3768a8SDave Martin smp_dmb arm 1087b49c0f24SNicolas Pitre1: ldrex r3, [r2] 10882d2669b6SNicolas Pitre subs r3, r3, r0 10892d2669b6SNicolas Pitre strexeq r3, r1, [r2] 1090b49c0f24SNicolas Pitre teqeq r3, #1 1091b49c0f24SNicolas Pitre beq 1b 10922d2669b6SNicolas Pitre rsbs r0, r3, #0 1093b49c0f24SNicolas Pitre /* beware -- each __kuser slot must be 8 instructions max */ 1094f00ec48fSRussell King ALT_SMP(b __kuser_memory_barrier) 1095f00ec48fSRussell King ALT_UP(usr_ret lr) 10962d2669b6SNicolas Pitre 10972d2669b6SNicolas Pitre#endif 10982d2669b6SNicolas Pitre 10995b43e7a3SRussell King kuser_pad __kuser_cmpxchg, 32 11002d2669b6SNicolas Pitre 11012d2669b6SNicolas Pitre__kuser_get_tls: @ 0xffff0fe0 1102f159f4edSTony Lindgren ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init 1103ba9b5d76SNicolas Pitre usr_ret lr 1104f159f4edSTony Lindgren mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code 11055b43e7a3SRussell King kuser_pad __kuser_get_tls, 16 11065b43e7a3SRussell King .rep 3 1107f159f4edSTony Lindgren .word 0 @ 0xffff0ff0 software TLS value, then 1108f159f4edSTony Lindgren .endr @ pad up to __kuser_helper_version 11092d2669b6SNicolas Pitre 11102d2669b6SNicolas Pitre__kuser_helper_version: @ 0xffff0ffc 11112d2669b6SNicolas Pitre .word ((__kuser_helper_end - __kuser_helper_start) >> 5) 11122d2669b6SNicolas Pitre 11132d2669b6SNicolas Pitre .globl __kuser_helper_end 11142d2669b6SNicolas Pitre__kuser_helper_end: 11152d2669b6SNicolas Pitre 1116f6f91b0dSRussell King#endif 1117f6f91b0dSRussell King 1118b86040a5SCatalin Marinas THUMB( .thumb ) 11192d2669b6SNicolas Pitre 11201da177e4SLinus Torvalds/* 11211da177e4SLinus Torvalds * Vector stubs. 11221da177e4SLinus Torvalds * 112319accfd3SRussell King * This code is copied to 0xffff1000 so we can use branches in the 112419accfd3SRussell King * vectors, rather than ldr's. Note that this code must not exceed 112519accfd3SRussell King * a page size. 11261da177e4SLinus Torvalds * 11271da177e4SLinus Torvalds * Common stub entry macro: 11281da177e4SLinus Torvalds * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 1129ccea7a19SRussell King * 1130ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address 1131ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler. 11321da177e4SLinus Torvalds */ 1133b7ec4795SNicolas Pitre .macro vector_stub, name, mode, correction=0 11341da177e4SLinus Torvalds .align 5 11351da177e4SLinus Torvalds 11361da177e4SLinus Torvaldsvector_\name: 11371da177e4SLinus Torvalds .if \correction 11381da177e4SLinus Torvalds sub lr, lr, #\correction 11391da177e4SLinus Torvalds .endif 11401da177e4SLinus Torvalds 1141ccea7a19SRussell King @ 1142ccea7a19SRussell King @ Save r0, lr_<exception> (parent PC) and spsr_<exception> 1143ccea7a19SRussell King @ (parent CPSR) 1144ccea7a19SRussell King @ 1145ccea7a19SRussell King stmia sp, {r0, lr} @ save r0, lr 1146ccea7a19SRussell King mrs lr, spsr 1147ccea7a19SRussell King str lr, [sp, #8] @ save spsr 1148ccea7a19SRussell King 1149ccea7a19SRussell King @ 1150ccea7a19SRussell King @ Prepare for SVC32 mode. IRQs remain disabled. 1151ccea7a19SRussell King @ 1152ccea7a19SRussell King mrs r0, cpsr 1153b86040a5SCatalin Marinas eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE) 1154ccea7a19SRussell King msr spsr_cxsf, r0 1155ccea7a19SRussell King 1156ccea7a19SRussell King @ 1157ccea7a19SRussell King @ the branch table must immediately follow this code 1158ccea7a19SRussell King @ 1159ccea7a19SRussell King and lr, lr, #0x0f 1160b86040a5SCatalin Marinas THUMB( adr r0, 1f ) 1161b86040a5SCatalin Marinas THUMB( ldr lr, [r0, lr, lsl #2] ) 1162b7ec4795SNicolas Pitre mov r0, sp 1163b86040a5SCatalin Marinas ARM( ldr lr, [pc, lr, lsl #2] ) 1164ccea7a19SRussell King movs pc, lr @ branch to handler in SVC mode 116593ed3970SCatalin MarinasENDPROC(vector_\name) 116688987ef9SCatalin Marinas 116788987ef9SCatalin Marinas .align 2 116888987ef9SCatalin Marinas @ handler addresses follow this label 116988987ef9SCatalin Marinas1: 11701da177e4SLinus Torvalds .endm 11711da177e4SLinus Torvalds 1172b9b32bf7SRussell King .section .stubs, "ax", %progbits 117319accfd3SRussell King @ This must be the first word 117419accfd3SRussell King .word vector_swi 117519accfd3SRussell King 117619accfd3SRussell Kingvector_rst: 117719accfd3SRussell King ARM( swi SYS_ERROR0 ) 117819accfd3SRussell King THUMB( svc #0 ) 117919accfd3SRussell King THUMB( nop ) 118019accfd3SRussell King b vector_und 118119accfd3SRussell King 11821da177e4SLinus Torvalds/* 11831da177e4SLinus Torvalds * Interrupt dispatcher 11841da177e4SLinus Torvalds */ 1185b7ec4795SNicolas Pitre vector_stub irq, IRQ_MODE, 4 11861da177e4SLinus Torvalds 11871da177e4SLinus Torvalds .long __irq_usr @ 0 (USR_26 / USR_32) 11881da177e4SLinus Torvalds .long __irq_invalid @ 1 (FIQ_26 / FIQ_32) 11891da177e4SLinus Torvalds .long __irq_invalid @ 2 (IRQ_26 / IRQ_32) 11901da177e4SLinus Torvalds .long __irq_svc @ 3 (SVC_26 / SVC_32) 11911da177e4SLinus Torvalds .long __irq_invalid @ 4 11921da177e4SLinus Torvalds .long __irq_invalid @ 5 11931da177e4SLinus Torvalds .long __irq_invalid @ 6 11941da177e4SLinus Torvalds .long __irq_invalid @ 7 11951da177e4SLinus Torvalds .long __irq_invalid @ 8 11961da177e4SLinus Torvalds .long __irq_invalid @ 9 11971da177e4SLinus Torvalds .long __irq_invalid @ a 11981da177e4SLinus Torvalds .long __irq_invalid @ b 11991da177e4SLinus Torvalds .long __irq_invalid @ c 12001da177e4SLinus Torvalds .long __irq_invalid @ d 12011da177e4SLinus Torvalds .long __irq_invalid @ e 12021da177e4SLinus Torvalds .long __irq_invalid @ f 12031da177e4SLinus Torvalds 12041da177e4SLinus Torvalds/* 12051da177e4SLinus Torvalds * Data abort dispatcher 12061da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 12071da177e4SLinus Torvalds */ 1208b7ec4795SNicolas Pitre vector_stub dabt, ABT_MODE, 8 12091da177e4SLinus Torvalds 12101da177e4SLinus Torvalds .long __dabt_usr @ 0 (USR_26 / USR_32) 12111da177e4SLinus Torvalds .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32) 12121da177e4SLinus Torvalds .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32) 12131da177e4SLinus Torvalds .long __dabt_svc @ 3 (SVC_26 / SVC_32) 12141da177e4SLinus Torvalds .long __dabt_invalid @ 4 12151da177e4SLinus Torvalds .long __dabt_invalid @ 5 12161da177e4SLinus Torvalds .long __dabt_invalid @ 6 12171da177e4SLinus Torvalds .long __dabt_invalid @ 7 12181da177e4SLinus Torvalds .long __dabt_invalid @ 8 12191da177e4SLinus Torvalds .long __dabt_invalid @ 9 12201da177e4SLinus Torvalds .long __dabt_invalid @ a 12211da177e4SLinus Torvalds .long __dabt_invalid @ b 12221da177e4SLinus Torvalds .long __dabt_invalid @ c 12231da177e4SLinus Torvalds .long __dabt_invalid @ d 12241da177e4SLinus Torvalds .long __dabt_invalid @ e 12251da177e4SLinus Torvalds .long __dabt_invalid @ f 12261da177e4SLinus Torvalds 12271da177e4SLinus Torvalds/* 12281da177e4SLinus Torvalds * Prefetch abort dispatcher 12291da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 12301da177e4SLinus Torvalds */ 1231b7ec4795SNicolas Pitre vector_stub pabt, ABT_MODE, 4 12321da177e4SLinus Torvalds 12331da177e4SLinus Torvalds .long __pabt_usr @ 0 (USR_26 / USR_32) 12341da177e4SLinus Torvalds .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32) 12351da177e4SLinus Torvalds .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32) 12361da177e4SLinus Torvalds .long __pabt_svc @ 3 (SVC_26 / SVC_32) 12371da177e4SLinus Torvalds .long __pabt_invalid @ 4 12381da177e4SLinus Torvalds .long __pabt_invalid @ 5 12391da177e4SLinus Torvalds .long __pabt_invalid @ 6 12401da177e4SLinus Torvalds .long __pabt_invalid @ 7 12411da177e4SLinus Torvalds .long __pabt_invalid @ 8 12421da177e4SLinus Torvalds .long __pabt_invalid @ 9 12431da177e4SLinus Torvalds .long __pabt_invalid @ a 12441da177e4SLinus Torvalds .long __pabt_invalid @ b 12451da177e4SLinus Torvalds .long __pabt_invalid @ c 12461da177e4SLinus Torvalds .long __pabt_invalid @ d 12471da177e4SLinus Torvalds .long __pabt_invalid @ e 12481da177e4SLinus Torvalds .long __pabt_invalid @ f 12491da177e4SLinus Torvalds 12501da177e4SLinus Torvalds/* 12511da177e4SLinus Torvalds * Undef instr entry dispatcher 12521da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 12531da177e4SLinus Torvalds */ 1254b7ec4795SNicolas Pitre vector_stub und, UND_MODE 12551da177e4SLinus Torvalds 12561da177e4SLinus Torvalds .long __und_usr @ 0 (USR_26 / USR_32) 12571da177e4SLinus Torvalds .long __und_invalid @ 1 (FIQ_26 / FIQ_32) 12581da177e4SLinus Torvalds .long __und_invalid @ 2 (IRQ_26 / IRQ_32) 12591da177e4SLinus Torvalds .long __und_svc @ 3 (SVC_26 / SVC_32) 12601da177e4SLinus Torvalds .long __und_invalid @ 4 12611da177e4SLinus Torvalds .long __und_invalid @ 5 12621da177e4SLinus Torvalds .long __und_invalid @ 6 12631da177e4SLinus Torvalds .long __und_invalid @ 7 12641da177e4SLinus Torvalds .long __und_invalid @ 8 12651da177e4SLinus Torvalds .long __und_invalid @ 9 12661da177e4SLinus Torvalds .long __und_invalid @ a 12671da177e4SLinus Torvalds .long __und_invalid @ b 12681da177e4SLinus Torvalds .long __und_invalid @ c 12691da177e4SLinus Torvalds .long __und_invalid @ d 12701da177e4SLinus Torvalds .long __und_invalid @ e 12711da177e4SLinus Torvalds .long __und_invalid @ f 12721da177e4SLinus Torvalds 12731da177e4SLinus Torvalds .align 5 12741da177e4SLinus Torvalds 12751da177e4SLinus Torvalds/*============================================================================= 127619accfd3SRussell King * Address exception handler 127719accfd3SRussell King *----------------------------------------------------------------------------- 127819accfd3SRussell King * These aren't too critical. 127919accfd3SRussell King * (they're not supposed to happen, and won't happen in 32-bit data mode). 128019accfd3SRussell King */ 128119accfd3SRussell King 128219accfd3SRussell Kingvector_addrexcptn: 128319accfd3SRussell King b vector_addrexcptn 128419accfd3SRussell King 128519accfd3SRussell King/*============================================================================= 1286c0e7f7eeSDaniel Thompson * FIQ "NMI" handler 12871da177e4SLinus Torvalds *----------------------------------------------------------------------------- 1288c0e7f7eeSDaniel Thompson * Handle a FIQ using the SVC stack allowing FIQ act like NMI on x86 1289c0e7f7eeSDaniel Thompson * systems. 12901da177e4SLinus Torvalds */ 1291c0e7f7eeSDaniel Thompson vector_stub fiq, FIQ_MODE, 4 1292c0e7f7eeSDaniel Thompson 1293c0e7f7eeSDaniel Thompson .long __fiq_usr @ 0 (USR_26 / USR_32) 1294c0e7f7eeSDaniel Thompson .long __fiq_svc @ 1 (FIQ_26 / FIQ_32) 1295c0e7f7eeSDaniel Thompson .long __fiq_svc @ 2 (IRQ_26 / IRQ_32) 1296c0e7f7eeSDaniel Thompson .long __fiq_svc @ 3 (SVC_26 / SVC_32) 1297c0e7f7eeSDaniel Thompson .long __fiq_svc @ 4 1298c0e7f7eeSDaniel Thompson .long __fiq_svc @ 5 1299c0e7f7eeSDaniel Thompson .long __fiq_svc @ 6 1300c0e7f7eeSDaniel Thompson .long __fiq_abt @ 7 1301c0e7f7eeSDaniel Thompson .long __fiq_svc @ 8 1302c0e7f7eeSDaniel Thompson .long __fiq_svc @ 9 1303c0e7f7eeSDaniel Thompson .long __fiq_svc @ a 1304c0e7f7eeSDaniel Thompson .long __fiq_svc @ b 1305c0e7f7eeSDaniel Thompson .long __fiq_svc @ c 1306c0e7f7eeSDaniel Thompson .long __fiq_svc @ d 1307c0e7f7eeSDaniel Thompson .long __fiq_svc @ e 1308c0e7f7eeSDaniel Thompson .long __fiq_svc @ f 13091da177e4SLinus Torvalds 131031b96caeSArd Biesheuvel .globl vector_fiq 1311e39e3f3eSRussell King 1312b9b32bf7SRussell King .section .vectors, "ax", %progbits 1313b48da558SArd Biesheuvel.L__vectors_start: 1314b9b32bf7SRussell King W(b) vector_rst 1315b9b32bf7SRussell King W(b) vector_und 1316b48da558SArd Biesheuvel W(ldr) pc, .L__vectors_start + 0x1000 1317b9b32bf7SRussell King W(b) vector_pabt 1318b9b32bf7SRussell King W(b) vector_dabt 1319b9b32bf7SRussell King W(b) vector_addrexcptn 1320b9b32bf7SRussell King W(b) vector_irq 1321b9b32bf7SRussell King W(b) vector_fiq 13221da177e4SLinus Torvalds 13231da177e4SLinus Torvalds .data 13241abd3502SRussell King .align 2 13251da177e4SLinus Torvalds 13261da177e4SLinus Torvalds .globl cr_alignment 13271da177e4SLinus Torvaldscr_alignment: 13281da177e4SLinus Torvalds .space 4 1329