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 367a8ca84aSArd Biesheuvel mov r1, sp 377a8ca84aSArd Biesheuvel ldr_this_cpu r2, irq_stack_ptr, r2, r3 38d4664b6cSArd Biesheuvel .if \from_user == 0 39d4664b6cSArd Biesheuvel @ 40d4664b6cSArd Biesheuvel @ If we took the interrupt while running in the kernel, we may already 41d4664b6cSArd Biesheuvel @ be using the IRQ stack, so revert to the original value in that case. 42d4664b6cSArd Biesheuvel @ 437a8ca84aSArd Biesheuvel subs r3, r2, r1 @ SP above bottom of IRQ stack? 447a8ca84aSArd Biesheuvel rsbscs r3, r3, #THREAD_SIZE @ ... and below the top? 45a1c510d0SArd Biesheuvel#ifdef CONFIG_VMAP_STACK 467a8ca84aSArd Biesheuvel ldr_va r3, high_memory, cc @ End of the linear region 477a8ca84aSArd Biesheuvel cmpcc r3, r1 @ Stack pointer was below it? 48abeb24aeSMarc Zyngier#endif 497a8ca84aSArd Biesheuvel bcc 0f @ If not, switch to the IRQ stack 507a8ca84aSArd Biesheuvel mov r0, r1 5152108641Seric miao bl generic_handle_arch_irq 527a8ca84aSArd Biesheuvel b 1f 537a8ca84aSArd Biesheuvel0: 547a8ca84aSArd Biesheuvel .endif 55d4664b6cSArd Biesheuvel 567a8ca84aSArd Biesheuvel mov_l r0, generic_handle_arch_irq 577a8ca84aSArd Biesheuvel bl call_with_stack 587a8ca84aSArd Biesheuvel1: 59187a51adSRussell King .endm 60187a51adSRussell King 61ac8b9c1cSRussell King .macro pabt_helper 628dfe7ac9SRussell King @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5 63ac8b9c1cSRussell King#ifdef MULTI_PABORT 6450807460SArd Biesheuvel ldr_va ip, processor, offset=PROCESSOR_PABT_FUNC 6550807460SArd Biesheuvel bl_r ip 66ac8b9c1cSRussell King#else 67ac8b9c1cSRussell King bl CPU_PABORT_HANDLER 68ac8b9c1cSRussell King#endif 69ac8b9c1cSRussell King .endm 70ac8b9c1cSRussell King 71ac8b9c1cSRussell King .macro dabt_helper 72ac8b9c1cSRussell King 73ac8b9c1cSRussell King @ 74ac8b9c1cSRussell King @ Call the processor-specific abort handler: 75ac8b9c1cSRussell King @ 76da740472SRussell King @ r2 - pt_regs 773e287becSRussell King @ r4 - aborted context pc 783e287becSRussell King @ r5 - aborted context psr 79ac8b9c1cSRussell King @ 80ac8b9c1cSRussell King @ The abort handler must return the aborted address in r0, and 81ac8b9c1cSRussell King @ the fault status register in r1. r9 must be preserved. 82ac8b9c1cSRussell King @ 83ac8b9c1cSRussell King#ifdef MULTI_DABORT 8450807460SArd Biesheuvel ldr_va ip, processor, offset=PROCESSOR_DABT_FUNC 8550807460SArd Biesheuvel bl_r ip 86ac8b9c1cSRussell King#else 87ac8b9c1cSRussell King bl CPU_DABORT_HANDLER 88ac8b9c1cSRussell King#endif 89ac8b9c1cSRussell King .endm 90ac8b9c1cSRussell King 91c6089061SRussell King .section .entry.text,"ax",%progbits 92785d3cd2SNicolas Pitre 93187a51adSRussell King/* 941da177e4SLinus Torvalds * Invalid mode handlers 951da177e4SLinus Torvalds */ 96ccea7a19SRussell King .macro inv_entry, reason 975745eef6SRussell King sub sp, sp, #PT_REGS_SIZE 98b86040a5SCatalin Marinas ARM( stmib sp, {r1 - lr} ) 99b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 100b86040a5SCatalin Marinas THUMB( str sp, [sp, #S_SP] ) 101b86040a5SCatalin Marinas THUMB( str lr, [sp, #S_LR] ) 1021da177e4SLinus Torvalds mov r1, #\reason 1031da177e4SLinus Torvalds .endm 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds__pabt_invalid: 106ccea7a19SRussell King inv_entry BAD_PREFETCH 107ccea7a19SRussell King b common_invalid 10893ed3970SCatalin MarinasENDPROC(__pabt_invalid) 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds__dabt_invalid: 111ccea7a19SRussell King inv_entry BAD_DATA 112ccea7a19SRussell King b common_invalid 11393ed3970SCatalin MarinasENDPROC(__dabt_invalid) 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds__irq_invalid: 116ccea7a19SRussell King inv_entry BAD_IRQ 117ccea7a19SRussell King b common_invalid 11893ed3970SCatalin MarinasENDPROC(__irq_invalid) 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds__und_invalid: 121ccea7a19SRussell King inv_entry BAD_UNDEFINSTR 1221da177e4SLinus Torvalds 123ccea7a19SRussell King @ 124ccea7a19SRussell King @ XXX fall through to common_invalid 125ccea7a19SRussell King @ 126ccea7a19SRussell King 127ccea7a19SRussell King@ 128ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers) 129ccea7a19SRussell King@ 130ccea7a19SRussell Kingcommon_invalid: 131ccea7a19SRussell King zero_fp 132ccea7a19SRussell King 133ccea7a19SRussell King ldmia r0, {r4 - r6} 134ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 135ccea7a19SRussell King mov r7, #-1 @ "" "" "" "" 136ccea7a19SRussell King str r4, [sp] @ save preserved r0 137ccea7a19SRussell King stmia r0, {r5 - r7} @ lr_<exception>, 138ccea7a19SRussell King @ cpsr_<exception>, "old_r0" 139ccea7a19SRussell King 1401da177e4SLinus Torvalds mov r0, sp 1411da177e4SLinus Torvalds b bad_mode 14293ed3970SCatalin MarinasENDPROC(__und_invalid) 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds/* 1451da177e4SLinus Torvalds * SVC mode handlers 1461da177e4SLinus Torvalds */ 1472dede2d8SNicolas Pitre 1482dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) 1492dede2d8SNicolas Pitre#define SPFIX(code...) code 1502dede2d8SNicolas Pitre#else 1512dede2d8SNicolas Pitre#define SPFIX(code...) 1522dede2d8SNicolas Pitre#endif 1532dede2d8SNicolas Pitre 154a1c510d0SArd Biesheuvel .macro svc_entry, stack_hole=0, trace=1, uaccess=1, overflow_check=1 155c4c5716eSCatalin Marinas UNWIND(.fnstart ) 156ae5cc07dSArd Biesheuvel sub sp, sp, #(SVC_REGS_SIZE + \stack_hole) 157a1c510d0SArd Biesheuvel THUMB( add sp, r1 ) @ get SP in a GPR without 158a1c510d0SArd Biesheuvel THUMB( sub r1, sp, r1 ) @ using a temp register 159a1c510d0SArd Biesheuvel 160a1c510d0SArd Biesheuvel .if \overflow_check 161c4c5716eSCatalin Marinas UNWIND(.save {r0 - pc} ) 162a1c510d0SArd Biesheuvel do_overflow_check (SVC_REGS_SIZE + \stack_hole) 163a1c510d0SArd Biesheuvel .endif 164a1c510d0SArd Biesheuvel 165b86040a5SCatalin Marinas#ifdef CONFIG_THUMB2_KERNEL 166ae5cc07dSArd Biesheuvel tst r1, #4 @ test stack pointer alignment 167ae5cc07dSArd Biesheuvel sub r1, sp, r1 @ restore original R1 168ae5cc07dSArd Biesheuvel sub sp, r1 @ restore original SP 169b86040a5SCatalin Marinas#else 1702dede2d8SNicolas Pitre SPFIX( tst sp, #4 ) 171b86040a5SCatalin Marinas#endif 172ae5cc07dSArd Biesheuvel SPFIX( subne sp, sp, #4 ) 173ae5cc07dSArd Biesheuvel 174ae5cc07dSArd Biesheuvel ARM( stmib sp, {r1 - r12} ) 175ae5cc07dSArd Biesheuvel THUMB( stmia sp, {r0 - r12} ) @ No STMIB in Thumb-2 176ccea7a19SRussell King 177b059bdc3SRussell King ldmia r0, {r3 - r5} 178ae5cc07dSArd Biesheuvel add r7, sp, #S_SP @ here for interlock avoidance 179b059bdc3SRussell King mov r6, #-1 @ "" "" "" "" 180ae5cc07dSArd Biesheuvel add r2, sp, #(SVC_REGS_SIZE + \stack_hole) 181ae5cc07dSArd Biesheuvel SPFIX( addne r2, r2, #4 ) 182ae5cc07dSArd Biesheuvel str r3, [sp] @ save the "real" r0 copied 183ccea7a19SRussell King @ from the exception stack 184ccea7a19SRussell King 185b059bdc3SRussell King mov r3, lr 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds @ 1881da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 1891da177e4SLinus Torvalds @ 190b059bdc3SRussell King @ r2 - sp_svc 191b059bdc3SRussell King @ r3 - lr_svc 192b059bdc3SRussell King @ r4 - lr_<exception>, already fixed up for correct return/restart 193b059bdc3SRussell King @ r5 - spsr_<exception> 194b059bdc3SRussell King @ r6 - orig_r0 (see pt_regs definition in ptrace.h) 1951da177e4SLinus Torvalds @ 196b059bdc3SRussell King stmia r7, {r2 - r6} 197f2741b78SRussell King 198e6978e4bSRussell King get_thread_info tsk 199747ffc2fSRussell King uaccess_entry tsk, r0, r1, r2, \uaccess 2002190fed6SRussell King 201c0e7f7eeSDaniel Thompson .if \trace 202f2741b78SRussell King#ifdef CONFIG_TRACE_IRQFLAGS 203f2741b78SRussell King bl trace_hardirqs_off 204f2741b78SRussell King#endif 205c0e7f7eeSDaniel Thompson .endif 2061da177e4SLinus Torvalds .endm 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds .align 5 2091da177e4SLinus Torvalds__dabt_svc: 2102190fed6SRussell King svc_entry uaccess=0 2111da177e4SLinus Torvalds mov r2, sp 212da740472SRussell King dabt_helper 213e16b31bfSMarc Zyngier THUMB( ldr r5, [sp, #S_PSR] ) @ potentially updated CPSR 214b059bdc3SRussell King svc_exit r5 @ return from exception 215c4c5716eSCatalin Marinas UNWIND(.fnend ) 21693ed3970SCatalin MarinasENDPROC(__dabt_svc) 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds .align 5 2191da177e4SLinus Torvalds__irq_svc: 220ccea7a19SRussell King svc_entry 221d4664b6cSArd Biesheuvel irq_handler from_user=0 2221613cc11SRussell King 223e7289c6dSThomas Gleixner#ifdef CONFIG_PREEMPTION 224706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 225706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get flags 22628fab1a2SRussell King teq r8, #0 @ if preempt count != 0 22728fab1a2SRussell King movne r0, #0 @ force flags to 0 2281da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2291da177e4SLinus Torvalds blne svc_preempt 2301da177e4SLinus Torvalds#endif 23130891c90SRussell King 2329b56febeSRussell King svc_exit r5, irq = 1 @ return from exception 233c4c5716eSCatalin Marinas UNWIND(.fnend ) 23493ed3970SCatalin MarinasENDPROC(__irq_svc) 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds .ltorg 2371da177e4SLinus Torvalds 238e7289c6dSThomas Gleixner#ifdef CONFIG_PREEMPTION 2391da177e4SLinus Torvaldssvc_preempt: 24028fab1a2SRussell King mov r8, lr 2411da177e4SLinus Torvalds1: bl preempt_schedule_irq @ irq en/disable is done inside 242706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS 2431da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2446ebbf2ceSRussell King reteq r8 @ go again 2451da177e4SLinus Torvalds b 1b 2461da177e4SLinus Torvalds#endif 2471da177e4SLinus Torvalds 24815ac49b6SRussell King__und_fault: 24915ac49b6SRussell King @ Correct the PC such that it is pointing at the instruction 25015ac49b6SRussell King @ which caused the fault. If the faulting instruction was ARM 25115ac49b6SRussell King @ the PC will be pointing at the next instruction, and have to 25215ac49b6SRussell King @ subtract 4. Otherwise, it is Thumb, and the PC will be 25315ac49b6SRussell King @ pointing at the second half of the Thumb instruction. We 25415ac49b6SRussell King @ have to subtract 2. 25515ac49b6SRussell King ldr r2, [r0, #S_PC] 25615ac49b6SRussell King sub r2, r2, r1 25715ac49b6SRussell King str r2, [r0, #S_PC] 25815ac49b6SRussell King b do_undefinstr 25915ac49b6SRussell KingENDPROC(__und_fault) 26015ac49b6SRussell King 2611da177e4SLinus Torvalds .align 5 2621da177e4SLinus Torvalds__und_svc: 263d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES 264d30a0c8bSNicolas Pitre @ If a kprobe is about to simulate a "stmdb sp..." instruction, 265d30a0c8bSNicolas Pitre @ it obviously needs free stack space which then will belong to 266d30a0c8bSNicolas Pitre @ the saved context. 267a0266c21SWang Nan svc_entry MAX_STACK_SIZE 268d30a0c8bSNicolas Pitre#else 269ccea7a19SRussell King svc_entry 270d30a0c8bSNicolas Pitre#endif 2711da177e4SLinus Torvalds 27215ac49b6SRussell King mov r1, #4 @ PC correction to apply 273f77ac2e3SArd Biesheuvel THUMB( tst r5, #PSR_T_BIT ) @ exception taken in Thumb mode? 274f77ac2e3SArd Biesheuvel THUMB( movne r1, #2 ) @ if so, fix up PC correction 2751da177e4SLinus Torvalds mov r0, sp @ struct pt_regs *regs 27615ac49b6SRussell King bl __und_fault 2771da177e4SLinus Torvalds 27815ac49b6SRussell King__und_svc_finish: 27987eed3c7SRussell King get_thread_info tsk 280b059bdc3SRussell King ldr r5, [sp, #S_PSR] @ Get SVC cpsr 281b059bdc3SRussell King svc_exit r5 @ return from exception 282c4c5716eSCatalin Marinas UNWIND(.fnend ) 28393ed3970SCatalin MarinasENDPROC(__und_svc) 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds .align 5 2861da177e4SLinus Torvalds__pabt_svc: 287ccea7a19SRussell King svc_entry 2884fb28474SKirill A. Shutemov mov r2, sp @ regs 2898dfe7ac9SRussell King pabt_helper 290b059bdc3SRussell King svc_exit r5 @ return from exception 291c4c5716eSCatalin Marinas UNWIND(.fnend ) 29293ed3970SCatalin MarinasENDPROC(__pabt_svc) 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds .align 5 295c0e7f7eeSDaniel Thompson__fiq_svc: 296c0e7f7eeSDaniel Thompson svc_entry trace=0 297c0e7f7eeSDaniel Thompson mov r0, sp @ struct pt_regs *regs 298c0e7f7eeSDaniel Thompson bl handle_fiq_as_nmi 299c0e7f7eeSDaniel Thompson svc_exit_via_fiq 300c0e7f7eeSDaniel Thompson UNWIND(.fnend ) 301c0e7f7eeSDaniel ThompsonENDPROC(__fiq_svc) 302c0e7f7eeSDaniel Thompson 3031da177e4SLinus Torvalds/* 304c0e7f7eeSDaniel Thompson * Abort mode handlers 305c0e7f7eeSDaniel Thompson */ 306c0e7f7eeSDaniel Thompson 307c0e7f7eeSDaniel Thompson@ 308c0e7f7eeSDaniel Thompson@ Taking a FIQ in abort mode is similar to taking a FIQ in SVC mode 309c0e7f7eeSDaniel Thompson@ and reuses the same macros. However in abort mode we must also 310c0e7f7eeSDaniel Thompson@ save/restore lr_abt and spsr_abt to make nested aborts safe. 311c0e7f7eeSDaniel Thompson@ 312c0e7f7eeSDaniel Thompson .align 5 313c0e7f7eeSDaniel Thompson__fiq_abt: 314c0e7f7eeSDaniel Thompson svc_entry trace=0 315c0e7f7eeSDaniel Thompson 316c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 317c0e7f7eeSDaniel Thompson THUMB( mov r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 318c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 319c0e7f7eeSDaniel Thompson mov r1, lr @ Save lr_abt 320c0e7f7eeSDaniel Thompson mrs r2, spsr @ Save spsr_abt, abort is now safe 321c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 322c0e7f7eeSDaniel Thompson THUMB( mov r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 323c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 324c0e7f7eeSDaniel Thompson stmfd sp!, {r1 - r2} 325c0e7f7eeSDaniel Thompson 326c0e7f7eeSDaniel Thompson add r0, sp, #8 @ struct pt_regs *regs 327c0e7f7eeSDaniel Thompson bl handle_fiq_as_nmi 328c0e7f7eeSDaniel Thompson 329c0e7f7eeSDaniel Thompson ldmfd sp!, {r1 - r2} 330c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 331c0e7f7eeSDaniel Thompson THUMB( mov r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 332c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 333c0e7f7eeSDaniel Thompson mov lr, r1 @ Restore lr_abt, abort is unsafe 334c0e7f7eeSDaniel Thompson msr spsr_cxsf, r2 @ Restore spsr_abt 335c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 336c0e7f7eeSDaniel Thompson THUMB( mov r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 337c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 338c0e7f7eeSDaniel Thompson 339c0e7f7eeSDaniel Thompson svc_exit_via_fiq 340c0e7f7eeSDaniel Thompson UNWIND(.fnend ) 341c0e7f7eeSDaniel ThompsonENDPROC(__fiq_abt) 342c0e7f7eeSDaniel Thompson 343c0e7f7eeSDaniel Thompson/* 3441da177e4SLinus Torvalds * User mode handlers 3452dede2d8SNicolas Pitre * 3465745eef6SRussell King * EABI note: sp_svc is always 64-bit aligned here, so should PT_REGS_SIZE 3471da177e4SLinus Torvalds */ 3482dede2d8SNicolas Pitre 3495745eef6SRussell King#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (PT_REGS_SIZE & 7) 3502dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8" 3512dede2d8SNicolas Pitre#endif 3522dede2d8SNicolas Pitre 3532190fed6SRussell King .macro usr_entry, trace=1, uaccess=1 354c4c5716eSCatalin Marinas UNWIND(.fnstart ) 355c4c5716eSCatalin Marinas UNWIND(.cantunwind ) @ don't unwind the user space 3565745eef6SRussell King sub sp, sp, #PT_REGS_SIZE 357b86040a5SCatalin Marinas ARM( stmib sp, {r1 - r12} ) 358b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 359ccea7a19SRussell King 360195b58adSRussell King ATRAP( mrc p15, 0, r7, c1, c0, 0) 36150807460SArd Biesheuvel ATRAP( ldr_va r8, cr_alignment) 362195b58adSRussell King 363b059bdc3SRussell King ldmia r0, {r3 - r5} 364ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 365b059bdc3SRussell King mov r6, #-1 @ "" "" "" "" 366ccea7a19SRussell King 367b059bdc3SRussell King str r3, [sp] @ save the "real" r0 copied 368ccea7a19SRussell King @ from the exception stack 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds @ 3711da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 3721da177e4SLinus Torvalds @ 373b059bdc3SRussell King @ r4 - lr_<exception>, already fixed up for correct return/restart 374b059bdc3SRussell King @ r5 - spsr_<exception> 375b059bdc3SRussell King @ r6 - orig_r0 (see pt_regs definition in ptrace.h) 3761da177e4SLinus Torvalds @ 3771da177e4SLinus Torvalds @ Also, separately save sp_usr and lr_usr 3781da177e4SLinus Torvalds @ 379b059bdc3SRussell King stmia r0, {r4 - r6} 380b86040a5SCatalin Marinas ARM( stmdb r0, {sp, lr}^ ) 381b86040a5SCatalin Marinas THUMB( store_user_sp_lr r0, r1, S_SP - S_PC ) 3821da177e4SLinus Torvalds 3832190fed6SRussell King .if \uaccess 3842190fed6SRussell King uaccess_disable ip 3852190fed6SRussell King .endif 3862190fed6SRussell King 3871da177e4SLinus Torvalds @ Enable the alignment trap while in kernel mode 388195b58adSRussell King ATRAP( teq r8, r7) 389195b58adSRussell King ATRAP( mcrne p15, 0, r8, c1, c0, 0) 3901da177e4SLinus Torvalds 39150596b75SArd Biesheuvel reload_current r7, r8 39250596b75SArd Biesheuvel 3931da177e4SLinus Torvalds @ 3941da177e4SLinus Torvalds @ Clear FP to mark the first stack frame 3951da177e4SLinus Torvalds @ 3961da177e4SLinus Torvalds zero_fp 397f2741b78SRussell King 398c0e7f7eeSDaniel Thompson .if \trace 39911b8b25cSRussell King#ifdef CONFIG_TRACE_IRQFLAGS 400f2741b78SRussell King bl trace_hardirqs_off 401f2741b78SRussell King#endif 402b0088480SKevin Hilman ct_user_exit save = 0 403c0e7f7eeSDaniel Thompson .endif 4041da177e4SLinus Torvalds .endm 4051da177e4SLinus Torvalds 406b49c0f24SNicolas Pitre .macro kuser_cmpxchg_check 407db695c05SRussell King#if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS) 408b49c0f24SNicolas Pitre#ifndef CONFIG_MMU 409b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing" 410b49c0f24SNicolas Pitre#else 411b49c0f24SNicolas Pitre @ Make sure our user space atomic helper is restarted 412b49c0f24SNicolas Pitre @ if it was interrupted in a critical region. Here we 413b49c0f24SNicolas Pitre @ perform a quick test inline since it should be false 414b49c0f24SNicolas Pitre @ 99.9999% of the time. The rest is done out of line. 415c12366baSLinus Walleij ldr r0, =TASK_SIZE 416c12366baSLinus Walleij cmp r4, r0 41740fb79c8SNicolas Pitre blhs kuser_cmpxchg64_fixup 418b49c0f24SNicolas Pitre#endif 419b49c0f24SNicolas Pitre#endif 420b49c0f24SNicolas Pitre .endm 421b49c0f24SNicolas Pitre 4221da177e4SLinus Torvalds .align 5 4231da177e4SLinus Torvalds__dabt_usr: 4242190fed6SRussell King usr_entry uaccess=0 425b49c0f24SNicolas Pitre kuser_cmpxchg_check 4261da177e4SLinus Torvalds mov r2, sp 427da740472SRussell King dabt_helper 428da740472SRussell King b ret_from_exception 429c4c5716eSCatalin Marinas UNWIND(.fnend ) 43093ed3970SCatalin MarinasENDPROC(__dabt_usr) 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds .align 5 4331da177e4SLinus Torvalds__irq_usr: 434ccea7a19SRussell King usr_entry 435bc089602SRussell King kuser_cmpxchg_check 436d4664b6cSArd Biesheuvel irq_handler from_user=1 4371613cc11SRussell King get_thread_info tsk 4381da177e4SLinus Torvalds mov why, #0 4399fc2552aSMing Lei b ret_to_user_from_irq 440c4c5716eSCatalin Marinas UNWIND(.fnend ) 44193ed3970SCatalin MarinasENDPROC(__irq_usr) 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds .ltorg 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds .align 5 4461da177e4SLinus Torvalds__und_usr: 4472190fed6SRussell King usr_entry uaccess=0 448bc089602SRussell King 449b059bdc3SRussell King mov r2, r4 450b059bdc3SRussell King mov r3, r5 4511da177e4SLinus Torvalds 45215ac49b6SRussell King @ r2 = regs->ARM_pc, which is either 2 or 4 bytes ahead of the 45315ac49b6SRussell King @ faulting instruction depending on Thumb mode. 45415ac49b6SRussell King @ r3 = regs->ARM_cpsr 4551da177e4SLinus Torvalds @ 45615ac49b6SRussell King @ The emulation code returns using r9 if it has emulated the 45715ac49b6SRussell King @ instruction, or the more conventional lr if we are to treat 45815ac49b6SRussell King @ this as a real undefined instruction 4591da177e4SLinus Torvalds @ 46014327c66SRussell King badr r9, ret_from_exception 46115ac49b6SRussell King 4621417a6b8SCatalin Marinas @ IRQs must be enabled before attempting to read the instruction from 4631417a6b8SCatalin Marinas @ user space since that could cause a page/translation fault if the 4641417a6b8SCatalin Marinas @ page table was modified by another CPU. 4651417a6b8SCatalin Marinas enable_irq 4661417a6b8SCatalin Marinas 467cb170a45SPaul Brook tst r3, #PSR_T_BIT @ Thumb mode? 46815ac49b6SRussell King bne __und_usr_thumb 46915ac49b6SRussell King sub r4, r2, #4 @ ARM instr at LR - 4 47015ac49b6SRussell King1: ldrt r0, [r4] 471457c2403SBen Dooks ARM_BE8(rev r0, r0) @ little endian instruction 472457c2403SBen Dooks 4732190fed6SRussell King uaccess_disable ip 4742190fed6SRussell King 47515ac49b6SRussell King @ r0 = 32-bit ARM instruction which caused the exception 47615ac49b6SRussell King @ r2 = PC value for the following instruction (:= regs->ARM_pc) 47715ac49b6SRussell King @ r4 = PC value for the faulting instruction 47815ac49b6SRussell King @ lr = 32-bit undefined instruction function 47914327c66SRussell King badr lr, __und_usr_fault_32 48015ac49b6SRussell King b call_fpe 48115ac49b6SRussell King 48215ac49b6SRussell King__und_usr_thumb: 483cb170a45SPaul Brook @ Thumb instruction 48415ac49b6SRussell King sub r4, r2, #2 @ First half of thumb instr at LR - 2 485ef4c5368SDave Martin#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7 486ef4c5368SDave Martin/* 487ef4c5368SDave Martin * Thumb-2 instruction handling. Note that because pre-v6 and >= v6 platforms 488ef4c5368SDave Martin * can never be supported in a single kernel, this code is not applicable at 489ef4c5368SDave Martin * all when __LINUX_ARM_ARCH__ < 6. This allows simplifying assumptions to be 490ef4c5368SDave Martin * made about .arch directives. 491ef4c5368SDave Martin */ 492ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7 493ef4c5368SDave Martin/* If the target CPU may not be Thumb-2-capable, a run-time check is needed: */ 49450807460SArd Biesheuvel ldr_va r5, cpu_architecture 495ef4c5368SDave Martin cmp r5, #CPU_ARCH_ARMv7 49615ac49b6SRussell King blo __und_usr_fault_16 @ 16bit undefined instruction 497ef4c5368SDave Martin/* 498ef4c5368SDave Martin * The following code won't get run unless the running CPU really is v7, so 499ef4c5368SDave Martin * coding round the lack of ldrht on older arches is pointless. Temporarily 500ef4c5368SDave Martin * override the assembler target arch with the minimum required instead: 501ef4c5368SDave Martin */ 502ef4c5368SDave Martin .arch armv6t2 503ef4c5368SDave Martin#endif 50415ac49b6SRussell King2: ldrht r5, [r4] 505f8fe23ecSVictor KamenskyARM_BE8(rev16 r5, r5) @ little endian instruction 50685519189SDave Martin cmp r5, #0xe800 @ 32bit instruction if xx != 0 5072190fed6SRussell King blo __und_usr_fault_16_pan @ 16bit undefined instruction 50815ac49b6SRussell King3: ldrht r0, [r2] 509f8fe23ecSVictor KamenskyARM_BE8(rev16 r0, r0) @ little endian instruction 5102190fed6SRussell King uaccess_disable ip 511cb170a45SPaul Brook add r2, r2, #2 @ r2 is PC + 2, make it PC + 4 51215ac49b6SRussell King str r2, [sp, #S_PC] @ it's a 2x16bit instr, update 513cb170a45SPaul Brook orr r0, r0, r5, lsl #16 51414327c66SRussell King badr lr, __und_usr_fault_32 51515ac49b6SRussell King @ r0 = the two 16-bit Thumb instructions which caused the exception 51615ac49b6SRussell King @ r2 = PC value for the following Thumb instruction (:= regs->ARM_pc) 51715ac49b6SRussell King @ r4 = PC value for the first 16-bit Thumb instruction 51815ac49b6SRussell King @ lr = 32bit undefined instruction function 519ef4c5368SDave Martin 520ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7 521ef4c5368SDave Martin/* If the target arch was overridden, change it back: */ 522ef4c5368SDave Martin#ifdef CONFIG_CPU_32v6K 523ef4c5368SDave Martin .arch armv6k 524cb170a45SPaul Brook#else 525ef4c5368SDave Martin .arch armv6 526ef4c5368SDave Martin#endif 527ef4c5368SDave Martin#endif /* __LINUX_ARM_ARCH__ < 7 */ 528ef4c5368SDave Martin#else /* !(CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7) */ 52915ac49b6SRussell King b __und_usr_fault_16 530cb170a45SPaul Brook#endif 531c4c5716eSCatalin Marinas UNWIND(.fnend) 53293ed3970SCatalin MarinasENDPROC(__und_usr) 533cb170a45SPaul Brook 5341da177e4SLinus Torvalds/* 53515ac49b6SRussell King * The out of line fixup for the ldrt instructions above. 5361da177e4SLinus Torvalds */ 537c4a84ae3SArd Biesheuvel .pushsection .text.fixup, "ax" 538667d1b48SWill Deacon .align 2 5393780f7abSArun K S4: str r4, [sp, #S_PC] @ retry current instruction 5406ebbf2ceSRussell King ret r9 5414260415fSRussell King .popsection 5424260415fSRussell King .pushsection __ex_table,"a" 543cb170a45SPaul Brook .long 1b, 4b 544c89cefedSGuennadi Liakhovetski#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7 545cb170a45SPaul Brook .long 2b, 4b 546cb170a45SPaul Brook .long 3b, 4b 547cb170a45SPaul Brook#endif 5484260415fSRussell King .popsection 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvalds/* 5511da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction. 5521da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler. 5531da177e4SLinus Torvalds * 5541da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor 5551da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well 5561da177e4SLinus Torvalds * defined. The only instructions that should fault are the 5571da177e4SLinus Torvalds * co-processor instructions. However, we have to watch out 5581da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug. 5591da177e4SLinus Torvalds * 560b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all 561b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have 562b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's 563b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs 564b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the 565b5872db4SCatalin Marinas * NEON handler code. 566b5872db4SCatalin Marinas * 5671da177e4SLinus Torvalds * Emulators may wish to make use of the following registers: 56815ac49b6SRussell King * r0 = instruction opcode (32-bit ARM or two 16-bit Thumb) 56915ac49b6SRussell King * r2 = PC value to resume execution after successful emulation 570db6ccbb6SRussell King * r9 = normal "successful" return address 57115ac49b6SRussell King * r10 = this threads thread_info structure 572db6ccbb6SRussell King * lr = unrecognised instruction return address 5731417a6b8SCatalin Marinas * IRQs enabled, FIQs enabled. 5741da177e4SLinus Torvalds */ 575cb170a45SPaul Brook @ 576cb170a45SPaul Brook @ Fall-through from Thumb-2 __und_usr 577cb170a45SPaul Brook @ 578cb170a45SPaul Brook#ifdef CONFIG_NEON 579d3f79584SRussell King get_thread_info r10 @ get current thread 580cb170a45SPaul Brook adr r6, .LCneon_thumb_opcodes 581cb170a45SPaul Brook b 2f 582cb170a45SPaul Brook#endif 5831da177e4SLinus Torvaldscall_fpe: 584d3f79584SRussell King get_thread_info r10 @ get current thread 585b5872db4SCatalin Marinas#ifdef CONFIG_NEON 586cb170a45SPaul Brook adr r6, .LCneon_arm_opcodes 587d3f79584SRussell King2: ldr r5, [r6], #4 @ mask value 588b5872db4SCatalin Marinas ldr r7, [r6], #4 @ opcode bits matching in mask 589d3f79584SRussell King cmp r5, #0 @ end mask? 590d3f79584SRussell King beq 1f 591d3f79584SRussell King and r8, r0, r5 592b5872db4SCatalin Marinas cmp r8, r7 @ NEON instruction? 593b5872db4SCatalin Marinas bne 2b 594b5872db4SCatalin Marinas mov r7, #1 595b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used 596b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used 597b5872db4SCatalin Marinas b do_vfp @ let VFP handler handle this 598b5872db4SCatalin Marinas1: 599b5872db4SCatalin Marinas#endif 6001da177e4SLinus Torvalds tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27 601cb170a45SPaul Brook tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2 6026ebbf2ceSRussell King reteq lr 6031da177e4SLinus Torvalds and r8, r0, #0x00000f00 @ mask out CP number 6041da177e4SLinus Torvalds mov r7, #1 6058536a5efSArd Biesheuvel add r6, r10, r8, lsr #8 @ add used_cp[] array offset first 6068536a5efSArd Biesheuvel strb r7, [r6, #TI_USED_CP] @ set appropriate used_cp[] 6071da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT 6081da177e4SLinus Torvalds @ Test if we need to give access to iWMMXt coprocessors 6091da177e4SLinus Torvalds ldr r5, [r10, #TI_FLAGS] 6101da177e4SLinus Torvalds rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only 611e44fc388SStefan Agner movscs r7, r5, lsr #(TIF_USING_IWMMXT + 1) 6121da177e4SLinus Torvalds bcs iwmmxt_task_enable 6131da177e4SLinus Torvalds#endif 614b86040a5SCatalin Marinas ARM( add pc, pc, r8, lsr #6 ) 6158536a5efSArd Biesheuvel THUMB( lsr r8, r8, #6 ) 616b86040a5SCatalin Marinas THUMB( add pc, r8 ) 617b86040a5SCatalin Marinas nop 6181da177e4SLinus Torvalds 6196ebbf2ceSRussell King ret.w lr @ CP#0 620b86040a5SCatalin Marinas W(b) do_fpe @ CP#1 (FPE) 621b86040a5SCatalin Marinas W(b) do_fpe @ CP#2 (FPE) 6226ebbf2ceSRussell King ret.w lr @ CP#3 6236ebbf2ceSRussell King ret.w lr @ CP#4 6246ebbf2ceSRussell King ret.w lr @ CP#5 6256ebbf2ceSRussell King ret.w lr @ CP#6 6266ebbf2ceSRussell King ret.w lr @ CP#7 6276ebbf2ceSRussell King ret.w lr @ CP#8 6286ebbf2ceSRussell King ret.w lr @ CP#9 6291da177e4SLinus Torvalds#ifdef CONFIG_VFP 630b86040a5SCatalin Marinas W(b) do_vfp @ CP#10 (VFP) 631b86040a5SCatalin Marinas W(b) do_vfp @ CP#11 (VFP) 6321da177e4SLinus Torvalds#else 6336ebbf2ceSRussell King ret.w lr @ CP#10 (VFP) 6346ebbf2ceSRussell King ret.w lr @ CP#11 (VFP) 6351da177e4SLinus Torvalds#endif 6366ebbf2ceSRussell King ret.w lr @ CP#12 6376ebbf2ceSRussell King ret.w lr @ CP#13 6386ebbf2ceSRussell King ret.w lr @ CP#14 (Debug) 6396ebbf2ceSRussell King ret.w lr @ CP#15 (Control) 6401da177e4SLinus Torvalds 641b5872db4SCatalin Marinas#ifdef CONFIG_NEON 642b5872db4SCatalin Marinas .align 6 643b5872db4SCatalin Marinas 644cb170a45SPaul Brook.LCneon_arm_opcodes: 645b5872db4SCatalin Marinas .word 0xfe000000 @ mask 646b5872db4SCatalin Marinas .word 0xf2000000 @ opcode 647b5872db4SCatalin Marinas 648b5872db4SCatalin Marinas .word 0xff100000 @ mask 649b5872db4SCatalin Marinas .word 0xf4000000 @ opcode 650b5872db4SCatalin Marinas 651b5872db4SCatalin Marinas .word 0x00000000 @ mask 652b5872db4SCatalin Marinas .word 0x00000000 @ opcode 653cb170a45SPaul Brook 654cb170a45SPaul Brook.LCneon_thumb_opcodes: 655cb170a45SPaul Brook .word 0xef000000 @ mask 656cb170a45SPaul Brook .word 0xef000000 @ opcode 657cb170a45SPaul Brook 658cb170a45SPaul Brook .word 0xff100000 @ mask 659cb170a45SPaul Brook .word 0xf9000000 @ opcode 660cb170a45SPaul Brook 661cb170a45SPaul Brook .word 0x00000000 @ mask 662cb170a45SPaul Brook .word 0x00000000 @ opcode 663b5872db4SCatalin Marinas#endif 664b5872db4SCatalin Marinas 6651da177e4SLinus Torvaldsdo_fpe: 6661da177e4SLinus Torvalds add r10, r10, #TI_FPSTATE @ r10 = workspace 66750807460SArd Biesheuvel ldr_va pc, fp_enter, tmp=r4 @ Call FP module USR entry point 6681da177e4SLinus Torvalds 6691da177e4SLinus Torvalds/* 6701da177e4SLinus Torvalds * The FP module is called with these registers set: 6711da177e4SLinus Torvalds * r0 = instruction 6721da177e4SLinus Torvalds * r2 = PC+4 6731da177e4SLinus Torvalds * r9 = normal "successful" return address 6741da177e4SLinus Torvalds * r10 = FP workspace 6751da177e4SLinus Torvalds * lr = unrecognised FP instruction return address 6761da177e4SLinus Torvalds */ 6771da177e4SLinus Torvalds 678124efc27SSantosh Shilimkar .pushsection .data 6791abd3502SRussell King .align 2 6801da177e4SLinus TorvaldsENTRY(fp_enter) 681db6ccbb6SRussell King .word no_fp 682124efc27SSantosh Shilimkar .popsection 6831da177e4SLinus Torvalds 68483e686eaSCatalin MarinasENTRY(no_fp) 6856ebbf2ceSRussell King ret lr 68683e686eaSCatalin MarinasENDPROC(no_fp) 687db6ccbb6SRussell King 68815ac49b6SRussell King__und_usr_fault_32: 68915ac49b6SRussell King mov r1, #4 69015ac49b6SRussell King b 1f 6912190fed6SRussell King__und_usr_fault_16_pan: 6922190fed6SRussell King uaccess_disable ip 69315ac49b6SRussell King__und_usr_fault_16: 69415ac49b6SRussell King mov r1, #2 6951417a6b8SCatalin Marinas1: mov r0, sp 69614327c66SRussell King badr lr, ret_from_exception 69715ac49b6SRussell King b __und_fault 69815ac49b6SRussell KingENDPROC(__und_usr_fault_32) 69915ac49b6SRussell KingENDPROC(__und_usr_fault_16) 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds .align 5 7021da177e4SLinus Torvalds__pabt_usr: 703ccea7a19SRussell King usr_entry 7044fb28474SKirill A. Shutemov mov r2, sp @ regs 7058dfe7ac9SRussell King pabt_helper 706c4c5716eSCatalin Marinas UNWIND(.fnend ) 7071da177e4SLinus Torvalds /* fall through */ 7081da177e4SLinus Torvalds/* 7091da177e4SLinus Torvalds * This is the return code to user mode for abort handlers 7101da177e4SLinus Torvalds */ 7111da177e4SLinus TorvaldsENTRY(ret_from_exception) 712c4c5716eSCatalin Marinas UNWIND(.fnstart ) 713c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 7141da177e4SLinus Torvalds get_thread_info tsk 7151da177e4SLinus Torvalds mov why, #0 7161da177e4SLinus Torvalds b ret_to_user 717c4c5716eSCatalin Marinas UNWIND(.fnend ) 71893ed3970SCatalin MarinasENDPROC(__pabt_usr) 71993ed3970SCatalin MarinasENDPROC(ret_from_exception) 7201da177e4SLinus Torvalds 721c0e7f7eeSDaniel Thompson .align 5 722c0e7f7eeSDaniel Thompson__fiq_usr: 723c0e7f7eeSDaniel Thompson usr_entry trace=0 724c0e7f7eeSDaniel Thompson kuser_cmpxchg_check 725c0e7f7eeSDaniel Thompson mov r0, sp @ struct pt_regs *regs 726c0e7f7eeSDaniel Thompson bl handle_fiq_as_nmi 727c0e7f7eeSDaniel Thompson get_thread_info tsk 728c0e7f7eeSDaniel Thompson restore_user_regs fast = 0, offset = 0 729c0e7f7eeSDaniel Thompson UNWIND(.fnend ) 730c0e7f7eeSDaniel ThompsonENDPROC(__fiq_usr) 731c0e7f7eeSDaniel Thompson 7321da177e4SLinus Torvalds/* 7331da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors 7341da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info 7351da177e4SLinus Torvalds * previous and next are guaranteed not to be the same. 7361da177e4SLinus Torvalds */ 7371da177e4SLinus TorvaldsENTRY(__switch_to) 738c4c5716eSCatalin Marinas UNWIND(.fnstart ) 739c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 7401da177e4SLinus Torvalds add ip, r1, #TI_CPU_SAVE 741b86040a5SCatalin Marinas ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack 742b86040a5SCatalin Marinas THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack 743b86040a5SCatalin Marinas THUMB( str sp, [ip], #4 ) 744b86040a5SCatalin Marinas THUMB( str lr, [ip], #4 ) 745a4780adeSAndré Hentschel ldr r4, [r2, #TI_TP_VALUE] 746a4780adeSAndré Hentschel ldr r5, [r2, #TI_TP_VALUE + 4] 747247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 7481eef5d2fSRussell King mrc p15, 0, r6, c3, c0, 0 @ Get domain register 7491eef5d2fSRussell King str r6, [r1, #TI_CPU_DOMAIN] @ Save old domain register 750d6551e88SRussell King ldr r6, [r2, #TI_CPU_DOMAIN] 751afeb90caSHyok S. Choi#endif 752a4780adeSAndré Hentschel switch_tls r1, r4, r5, r3, r7 753831a469bSArd Biesheuvel#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) && \ 754831a469bSArd Biesheuvel !defined(CONFIG_STACKPROTECTOR_PER_TASK) 755df0698beSNicolas Pitre ldr r8, =__stack_chk_guard 756ffa47aa6SArnd Bergmann .if (TSK_STACK_CANARY > IMM12_MASK) 7579c46929eSArd Biesheuvel add r9, r2, #TSK_STACK_CANARY & ~IMM12_MASK 758831a469bSArd Biesheuvel ldr r9, [r9, #TSK_STACK_CANARY & IMM12_MASK] 7599c46929eSArd Biesheuvel .else 7609c46929eSArd Biesheuvel ldr r9, [r2, #TSK_STACK_CANARY & IMM12_MASK] 761ffa47aa6SArnd Bergmann .endif 762df0698beSNicolas Pitre#endif 763831a469bSArd Biesheuvel mov r7, r2 @ Preserve 'next' 764247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 7651da177e4SLinus Torvalds mcr p15, 0, r6, c3, c0, 0 @ Set domain register 766afeb90caSHyok S. Choi#endif 767d6551e88SRussell King mov r5, r0 768d6551e88SRussell King add r4, r2, #TI_CPU_SAVE 769d6551e88SRussell King ldr r0, =thread_notify_head 770d6551e88SRussell King mov r1, #THREAD_NOTIFY_SWITCH 771d6551e88SRussell King bl atomic_notifier_call_chain 772831a469bSArd Biesheuvel#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) && \ 773831a469bSArd Biesheuvel !defined(CONFIG_STACKPROTECTOR_PER_TASK) 774831a469bSArd Biesheuvel str r9, [r8] 775df0698beSNicolas Pitre#endif 776d6551e88SRussell King mov r0, r5 777a1c510d0SArd Biesheuvel#if !defined(CONFIG_THUMB2_KERNEL) && !defined(CONFIG_VMAP_STACK) 7789c46929eSArd Biesheuvel set_current r7, r8 779b832faecSArd Biesheuvel ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously 780b832faecSArd Biesheuvel#else 781b832faecSArd Biesheuvel mov r1, r7 782b832faecSArd Biesheuvel ldmia r4, {r4 - sl, fp, ip, lr} @ Load all regs saved previously 783a1c510d0SArd Biesheuvel#ifdef CONFIG_VMAP_STACK 784a1c510d0SArd Biesheuvel @ 785a1c510d0SArd Biesheuvel @ Do a dummy read from the new stack while running from the old one so 786a1c510d0SArd Biesheuvel @ that we can rely on do_translation_fault() to fix up any stale PMD 787a1c510d0SArd Biesheuvel @ entries covering the vmalloc region. 788a1c510d0SArd Biesheuvel @ 789a1c510d0SArd Biesheuvel ldr r2, [ip] 790a1c510d0SArd Biesheuvel#endif 791b832faecSArd Biesheuvel 792b832faecSArd Biesheuvel @ When CONFIG_THREAD_INFO_IN_TASK=n, the update of SP itself is what 793b832faecSArd Biesheuvel @ effectuates the task switch, as that is what causes the observable 794b832faecSArd Biesheuvel @ values of current and current_thread_info to change. When 795b832faecSArd Biesheuvel @ CONFIG_THREAD_INFO_IN_TASK=y, setting current (and therefore 796b832faecSArd Biesheuvel @ current_thread_info) is done explicitly, and the update of SP just 797b832faecSArd Biesheuvel @ switches us to another stack, with few other side effects. In order 798b832faecSArd Biesheuvel @ to prevent this distinction from causing any inconsistencies, let's 799b832faecSArd Biesheuvel @ keep the 'set_current' call as close as we can to the update of SP. 8009c46929eSArd Biesheuvel set_current r1, r2 801b832faecSArd Biesheuvel mov sp, ip 802b832faecSArd Biesheuvel ret lr 803b832faecSArd Biesheuvel#endif 804c4c5716eSCatalin Marinas UNWIND(.fnend ) 80593ed3970SCatalin MarinasENDPROC(__switch_to) 8061da177e4SLinus Torvalds 807a1c510d0SArd Biesheuvel#ifdef CONFIG_VMAP_STACK 808a1c510d0SArd Biesheuvel .text 809a1c510d0SArd Biesheuvel .align 2 810a1c510d0SArd Biesheuvel__bad_stack: 811a1c510d0SArd Biesheuvel @ 812a1c510d0SArd Biesheuvel @ We've just detected an overflow. We need to load the address of this 813a1c510d0SArd Biesheuvel @ CPU's overflow stack into the stack pointer register. We have only one 814a1c510d0SArd Biesheuvel @ scratch register so let's use a sequence of ADDs including one 815a1c510d0SArd Biesheuvel @ involving the PC, and decorate them with PC-relative group 816a1c510d0SArd Biesheuvel @ relocations. As these are ARM only, switch to ARM mode first. 817a1c510d0SArd Biesheuvel @ 818a1c510d0SArd Biesheuvel @ We enter here with IP clobbered and its value stashed on the mode 819a1c510d0SArd Biesheuvel @ stack. 820a1c510d0SArd Biesheuvel @ 821a1c510d0SArd BiesheuvelTHUMB( bx pc ) 822a1c510d0SArd BiesheuvelTHUMB( nop ) 823a1c510d0SArd BiesheuvelTHUMB( .arm ) 8247b9896c3SArd Biesheuvel ldr_this_cpu_armv6 ip, overflow_stack_ptr 825a1c510d0SArd Biesheuvel 826a1c510d0SArd Biesheuvel str sp, [ip, #-4]! @ Preserve original SP value 827a1c510d0SArd Biesheuvel mov sp, ip @ Switch to overflow stack 828a1c510d0SArd Biesheuvel pop {ip} @ Original SP in IP 829a1c510d0SArd Biesheuvel 830a1c510d0SArd Biesheuvel#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) 831a1c510d0SArd Biesheuvel mov ip, ip @ mov expected by unwinder 832a1c510d0SArd Biesheuvel push {fp, ip, lr, pc} @ GCC flavor frame record 833a1c510d0SArd Biesheuvel#else 834a1c510d0SArd Biesheuvel str ip, [sp, #-8]! @ store original SP 835a1c510d0SArd Biesheuvel push {fpreg, lr} @ Clang flavor frame record 836a1c510d0SArd Biesheuvel#endif 837a1c510d0SArd BiesheuvelUNWIND( ldr ip, [r0, #4] ) @ load exception LR 838a1c510d0SArd BiesheuvelUNWIND( str ip, [sp, #12] ) @ store in the frame record 839a1c510d0SArd Biesheuvel ldr ip, [r0, #12] @ reload IP 840a1c510d0SArd Biesheuvel 841a1c510d0SArd Biesheuvel @ Store the original GPRs to the new stack. 842a1c510d0SArd Biesheuvel svc_entry uaccess=0, overflow_check=0 843a1c510d0SArd Biesheuvel 844a1c510d0SArd BiesheuvelUNWIND( .save {sp, pc} ) 845a1c510d0SArd BiesheuvelUNWIND( .save {fpreg, lr} ) 846a1c510d0SArd BiesheuvelUNWIND( .setfp fpreg, sp ) 847a1c510d0SArd Biesheuvel 848a1c510d0SArd Biesheuvel ldr fpreg, [sp, #S_SP] @ Add our frame record 849a1c510d0SArd Biesheuvel @ to the linked list 850a1c510d0SArd Biesheuvel#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) 851a1c510d0SArd Biesheuvel ldr r1, [fp, #4] @ reload SP at entry 852a1c510d0SArd Biesheuvel add fp, fp, #12 853a1c510d0SArd Biesheuvel#else 854a1c510d0SArd Biesheuvel ldr r1, [fpreg, #8] 855a1c510d0SArd Biesheuvel#endif 856a1c510d0SArd Biesheuvel str r1, [sp, #S_SP] @ store in pt_regs 857a1c510d0SArd Biesheuvel 858a1c510d0SArd Biesheuvel @ Stash the regs for handle_bad_stack 859a1c510d0SArd Biesheuvel mov r0, sp 860a1c510d0SArd Biesheuvel 861a1c510d0SArd Biesheuvel @ Time to die 862a1c510d0SArd Biesheuvel bl handle_bad_stack 863a1c510d0SArd Biesheuvel nop 864a1c510d0SArd BiesheuvelUNWIND( .fnend ) 865a1c510d0SArd BiesheuvelENDPROC(__bad_stack) 866a1c510d0SArd Biesheuvel#endif 867a1c510d0SArd Biesheuvel 8681da177e4SLinus Torvalds __INIT 8692d2669b6SNicolas Pitre 8702d2669b6SNicolas Pitre/* 8712d2669b6SNicolas Pitre * User helpers. 8722d2669b6SNicolas Pitre * 8732d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high 8742d2669b6SNicolas Pitre * vector page. New segments (if ever needed) must be added in front of 8752d2669b6SNicolas Pitre * existing ones. This mechanism should be used only for things that are 8762d2669b6SNicolas Pitre * really small and justified, and not be abused freely. 8772d2669b6SNicolas Pitre * 878*e318b36eSJonathan Corbet * See Documentation/arch/arm/kernel_user_helpers.rst for formal definitions. 8792d2669b6SNicolas Pitre */ 880b86040a5SCatalin Marinas THUMB( .arm ) 8812d2669b6SNicolas Pitre 882ba9b5d76SNicolas Pitre .macro usr_ret, reg 883ba9b5d76SNicolas Pitre#ifdef CONFIG_ARM_THUMB 884ba9b5d76SNicolas Pitre bx \reg 885ba9b5d76SNicolas Pitre#else 8866ebbf2ceSRussell King ret \reg 887ba9b5d76SNicolas Pitre#endif 888ba9b5d76SNicolas Pitre .endm 889ba9b5d76SNicolas Pitre 8905b43e7a3SRussell King .macro kuser_pad, sym, size 8915b43e7a3SRussell King .if (. - \sym) & 3 8925b43e7a3SRussell King .rept 4 - (. - \sym) & 3 8935b43e7a3SRussell King .byte 0 8945b43e7a3SRussell King .endr 8955b43e7a3SRussell King .endif 8965b43e7a3SRussell King .rept (\size - (. - \sym)) / 4 8975b43e7a3SRussell King .word 0xe7fddef1 8985b43e7a3SRussell King .endr 8995b43e7a3SRussell King .endm 9005b43e7a3SRussell King 901f6f91b0dSRussell King#ifdef CONFIG_KUSER_HELPERS 9022d2669b6SNicolas Pitre .align 5 9032d2669b6SNicolas Pitre .globl __kuser_helper_start 9042d2669b6SNicolas Pitre__kuser_helper_start: 9052d2669b6SNicolas Pitre 9062d2669b6SNicolas Pitre/* 90740fb79c8SNicolas Pitre * Due to the length of some sequences, __kuser_cmpxchg64 spans 2 regular 90840fb79c8SNicolas Pitre * kuser "slots", therefore 0xffff0f80 is not used as a valid entry point. 9097c612bfdSNicolas Pitre */ 9107c612bfdSNicolas Pitre 91140fb79c8SNicolas Pitre__kuser_cmpxchg64: @ 0xffff0f60 91240fb79c8SNicolas Pitre 913db695c05SRussell King#if defined(CONFIG_CPU_32v6K) 91440fb79c8SNicolas Pitre 91540fb79c8SNicolas Pitre stmfd sp!, {r4, r5, r6, r7} 91640fb79c8SNicolas Pitre ldrd r4, r5, [r0] @ load old val 91740fb79c8SNicolas Pitre ldrd r6, r7, [r1] @ load new val 91840fb79c8SNicolas Pitre smp_dmb arm 91940fb79c8SNicolas Pitre1: ldrexd r0, r1, [r2] @ load current val 92040fb79c8SNicolas Pitre eors r3, r0, r4 @ compare with oldval (1) 921e44fc388SStefan Agner eorseq r3, r1, r5 @ compare with oldval (2) 92240fb79c8SNicolas Pitre strexdeq r3, r6, r7, [r2] @ store newval if eq 92340fb79c8SNicolas Pitre teqeq r3, #1 @ success? 92440fb79c8SNicolas Pitre beq 1b @ if no then retry 92540fb79c8SNicolas Pitre smp_dmb arm 92640fb79c8SNicolas Pitre rsbs r0, r3, #0 @ set returned val and C flag 92740fb79c8SNicolas Pitre ldmfd sp!, {r4, r5, r6, r7} 9285a97d0aeSWill Deacon usr_ret lr 92940fb79c8SNicolas Pitre 93040fb79c8SNicolas Pitre#elif !defined(CONFIG_SMP) 93140fb79c8SNicolas Pitre 93240fb79c8SNicolas Pitre#ifdef CONFIG_MMU 93340fb79c8SNicolas Pitre 93440fb79c8SNicolas Pitre /* 93540fb79c8SNicolas Pitre * The only thing that can break atomicity in this cmpxchg64 93640fb79c8SNicolas Pitre * implementation is either an IRQ or a data abort exception 93740fb79c8SNicolas Pitre * causing another process/thread to be scheduled in the middle of 93840fb79c8SNicolas Pitre * the critical sequence. The same strategy as for cmpxchg is used. 93940fb79c8SNicolas Pitre */ 94040fb79c8SNicolas Pitre stmfd sp!, {r4, r5, r6, lr} 94140fb79c8SNicolas Pitre ldmia r0, {r4, r5} @ load old val 94240fb79c8SNicolas Pitre ldmia r1, {r6, lr} @ load new val 94340fb79c8SNicolas Pitre1: ldmia r2, {r0, r1} @ load current val 94440fb79c8SNicolas Pitre eors r3, r0, r4 @ compare with oldval (1) 945e44fc388SStefan Agner eorseq r3, r1, r5 @ compare with oldval (2) 946e44fc388SStefan Agner2: stmiaeq r2, {r6, lr} @ store newval if eq 94740fb79c8SNicolas Pitre rsbs r0, r3, #0 @ set return val and C flag 94840fb79c8SNicolas Pitre ldmfd sp!, {r4, r5, r6, pc} 94940fb79c8SNicolas Pitre 95040fb79c8SNicolas Pitre .text 95140fb79c8SNicolas Pitrekuser_cmpxchg64_fixup: 95240fb79c8SNicolas Pitre @ Called from kuser_cmpxchg_fixup. 9533ad55155SRussell King @ r4 = address of interrupted insn (must be preserved). 95440fb79c8SNicolas Pitre @ sp = saved regs. r7 and r8 are clobbered. 95540fb79c8SNicolas Pitre @ 1b = first critical insn, 2b = last critical insn. 9563ad55155SRussell King @ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b. 95740fb79c8SNicolas Pitre mov r7, #0xffff0fff 95840fb79c8SNicolas Pitre sub r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64))) 9593ad55155SRussell King subs r8, r4, r7 960e44fc388SStefan Agner rsbscs r8, r8, #(2b - 1b) 96140fb79c8SNicolas Pitre strcs r7, [sp, #S_PC] 96240fb79c8SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6 96340fb79c8SNicolas Pitre bcc kuser_cmpxchg32_fixup 96440fb79c8SNicolas Pitre#endif 9656ebbf2ceSRussell King ret lr 96640fb79c8SNicolas Pitre .previous 96740fb79c8SNicolas Pitre 96840fb79c8SNicolas Pitre#else 96940fb79c8SNicolas Pitre#warning "NPTL on non MMU needs fixing" 97040fb79c8SNicolas Pitre mov r0, #-1 97140fb79c8SNicolas Pitre adds r0, r0, #0 97240fb79c8SNicolas Pitre usr_ret lr 97340fb79c8SNicolas Pitre#endif 97440fb79c8SNicolas Pitre 97540fb79c8SNicolas Pitre#else 97640fb79c8SNicolas Pitre#error "incoherent kernel configuration" 97740fb79c8SNicolas Pitre#endif 97840fb79c8SNicolas Pitre 9795b43e7a3SRussell King kuser_pad __kuser_cmpxchg64, 64 98040fb79c8SNicolas Pitre 9817c612bfdSNicolas Pitre__kuser_memory_barrier: @ 0xffff0fa0 982ed3768a8SDave Martin smp_dmb arm 983ba9b5d76SNicolas Pitre usr_ret lr 9847c612bfdSNicolas Pitre 9855b43e7a3SRussell King kuser_pad __kuser_memory_barrier, 32 9867c612bfdSNicolas Pitre 9872d2669b6SNicolas Pitre__kuser_cmpxchg: @ 0xffff0fc0 9882d2669b6SNicolas Pitre 989db695c05SRussell King#if __LINUX_ARM_ARCH__ < 6 9902d2669b6SNicolas Pitre 99149bca4c2SNicolas Pitre#ifdef CONFIG_MMU 992b49c0f24SNicolas Pitre 993b49c0f24SNicolas Pitre /* 994b49c0f24SNicolas Pitre * The only thing that can break atomicity in this cmpxchg 995b49c0f24SNicolas Pitre * implementation is either an IRQ or a data abort exception 996b49c0f24SNicolas Pitre * causing another process/thread to be scheduled in the middle 997b49c0f24SNicolas Pitre * of the critical sequence. To prevent this, code is added to 998b49c0f24SNicolas Pitre * the IRQ and data abort exception handlers to set the pc back 999b49c0f24SNicolas Pitre * to the beginning of the critical section if it is found to be 1000b49c0f24SNicolas Pitre * within that critical section (see kuser_cmpxchg_fixup). 1001b49c0f24SNicolas Pitre */ 1002b49c0f24SNicolas Pitre1: ldr r3, [r2] @ load current val 1003b49c0f24SNicolas Pitre subs r3, r3, r0 @ compare with oldval 1004b49c0f24SNicolas Pitre2: streq r1, [r2] @ store newval if eq 1005b49c0f24SNicolas Pitre rsbs r0, r3, #0 @ set return val and C flag 1006b49c0f24SNicolas Pitre usr_ret lr 1007b49c0f24SNicolas Pitre 1008b49c0f24SNicolas Pitre .text 100940fb79c8SNicolas Pitrekuser_cmpxchg32_fixup: 1010b49c0f24SNicolas Pitre @ Called from kuser_cmpxchg_check macro. 1011b059bdc3SRussell King @ r4 = address of interrupted insn (must be preserved). 1012b49c0f24SNicolas Pitre @ sp = saved regs. r7 and r8 are clobbered. 1013b49c0f24SNicolas Pitre @ 1b = first critical insn, 2b = last critical insn. 1014b059bdc3SRussell King @ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b. 1015b49c0f24SNicolas Pitre mov r7, #0xffff0fff 1016b49c0f24SNicolas Pitre sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg))) 1017b059bdc3SRussell King subs r8, r4, r7 1018e44fc388SStefan Agner rsbscs r8, r8, #(2b - 1b) 1019b49c0f24SNicolas Pitre strcs r7, [sp, #S_PC] 10206ebbf2ceSRussell King ret lr 1021b49c0f24SNicolas Pitre .previous 1022b49c0f24SNicolas Pitre 102349bca4c2SNicolas Pitre#else 102449bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing" 102549bca4c2SNicolas Pitre mov r0, #-1 102649bca4c2SNicolas Pitre adds r0, r0, #0 1027ba9b5d76SNicolas Pitre usr_ret lr 1028b49c0f24SNicolas Pitre#endif 10292d2669b6SNicolas Pitre 10302d2669b6SNicolas Pitre#else 10312d2669b6SNicolas Pitre 1032ed3768a8SDave Martin smp_dmb arm 1033b49c0f24SNicolas Pitre1: ldrex r3, [r2] 10342d2669b6SNicolas Pitre subs r3, r3, r0 10352d2669b6SNicolas Pitre strexeq r3, r1, [r2] 1036b49c0f24SNicolas Pitre teqeq r3, #1 1037b49c0f24SNicolas Pitre beq 1b 10382d2669b6SNicolas Pitre rsbs r0, r3, #0 1039b49c0f24SNicolas Pitre /* beware -- each __kuser slot must be 8 instructions max */ 1040f00ec48fSRussell King ALT_SMP(b __kuser_memory_barrier) 1041f00ec48fSRussell King ALT_UP(usr_ret lr) 10422d2669b6SNicolas Pitre 10432d2669b6SNicolas Pitre#endif 10442d2669b6SNicolas Pitre 10455b43e7a3SRussell King kuser_pad __kuser_cmpxchg, 32 10462d2669b6SNicolas Pitre 10472d2669b6SNicolas Pitre__kuser_get_tls: @ 0xffff0fe0 1048f159f4edSTony Lindgren ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init 1049ba9b5d76SNicolas Pitre usr_ret lr 1050f159f4edSTony Lindgren mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code 10515b43e7a3SRussell King kuser_pad __kuser_get_tls, 16 10525b43e7a3SRussell King .rep 3 1053f159f4edSTony Lindgren .word 0 @ 0xffff0ff0 software TLS value, then 1054f159f4edSTony Lindgren .endr @ pad up to __kuser_helper_version 10552d2669b6SNicolas Pitre 10562d2669b6SNicolas Pitre__kuser_helper_version: @ 0xffff0ffc 10572d2669b6SNicolas Pitre .word ((__kuser_helper_end - __kuser_helper_start) >> 5) 10582d2669b6SNicolas Pitre 10592d2669b6SNicolas Pitre .globl __kuser_helper_end 10602d2669b6SNicolas Pitre__kuser_helper_end: 10612d2669b6SNicolas Pitre 1062f6f91b0dSRussell King#endif 1063f6f91b0dSRussell King 1064b86040a5SCatalin Marinas THUMB( .thumb ) 10652d2669b6SNicolas Pitre 10661da177e4SLinus Torvalds/* 10671da177e4SLinus Torvalds * Vector stubs. 10681da177e4SLinus Torvalds * 106919accfd3SRussell King * This code is copied to 0xffff1000 so we can use branches in the 107019accfd3SRussell King * vectors, rather than ldr's. Note that this code must not exceed 107119accfd3SRussell King * a page size. 10721da177e4SLinus Torvalds * 10731da177e4SLinus Torvalds * Common stub entry macro: 10741da177e4SLinus Torvalds * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 1075ccea7a19SRussell King * 1076ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address 1077ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler. 10781da177e4SLinus Torvalds */ 1079b7ec4795SNicolas Pitre .macro vector_stub, name, mode, correction=0 10801da177e4SLinus Torvalds .align 5 1081c4f486f1SArd Biesheuvel#ifdef CONFIG_HARDEN_BRANCH_HISTORY 1082c4f486f1SArd Biesheuvelvector_bhb_bpiall_\name: 1083c4f486f1SArd Biesheuvel mcr p15, 0, r0, c7, c5, 6 @ BPIALL 1084c4f486f1SArd Biesheuvel @ isb not needed due to "movs pc, lr" in the vector stub 1085c4f486f1SArd Biesheuvel @ which gives a "context synchronisation". 1086c4f486f1SArd Biesheuvel#endif 10871da177e4SLinus Torvalds 10881da177e4SLinus Torvaldsvector_\name: 10891da177e4SLinus Torvalds .if \correction 10901da177e4SLinus Torvalds sub lr, lr, #\correction 10911da177e4SLinus Torvalds .endif 10921da177e4SLinus Torvalds 1093b9baf5c8SRussell King (Oracle) @ Save r0, lr_<exception> (parent PC) 1094ccea7a19SRussell King stmia sp, {r0, lr} @ save r0, lr 1095b9baf5c8SRussell King (Oracle) 1096b9baf5c8SRussell King (Oracle) @ Save spsr_<exception> (parent CPSR) 10971290c70dSArd Biesheuvel.Lvec_\name: 10981290c70dSArd Biesheuvel mrs lr, spsr 1099ccea7a19SRussell King str lr, [sp, #8] @ save spsr 1100ccea7a19SRussell King 1101ccea7a19SRussell King @ 1102ccea7a19SRussell King @ Prepare for SVC32 mode. IRQs remain disabled. 1103ccea7a19SRussell King @ 1104ccea7a19SRussell King mrs r0, cpsr 1105b86040a5SCatalin Marinas eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE) 1106ccea7a19SRussell King msr spsr_cxsf, r0 1107ccea7a19SRussell King 1108ccea7a19SRussell King @ 1109ccea7a19SRussell King @ the branch table must immediately follow this code 1110ccea7a19SRussell King @ 1111ccea7a19SRussell King and lr, lr, #0x0f 1112b86040a5SCatalin Marinas THUMB( adr r0, 1f ) 1113b86040a5SCatalin Marinas THUMB( ldr lr, [r0, lr, lsl #2] ) 1114b7ec4795SNicolas Pitre mov r0, sp 1115b86040a5SCatalin Marinas ARM( ldr lr, [pc, lr, lsl #2] ) 1116ccea7a19SRussell King movs pc, lr @ branch to handler in SVC mode 111793ed3970SCatalin MarinasENDPROC(vector_\name) 111888987ef9SCatalin Marinas 1119b9baf5c8SRussell King (Oracle)#ifdef CONFIG_HARDEN_BRANCH_HISTORY 1120b9baf5c8SRussell King (Oracle) .subsection 1 1121b9baf5c8SRussell King (Oracle) .align 5 1122b9baf5c8SRussell King (Oracle)vector_bhb_loop8_\name: 1123b9baf5c8SRussell King (Oracle) .if \correction 1124b9baf5c8SRussell King (Oracle) sub lr, lr, #\correction 1125b9baf5c8SRussell King (Oracle) .endif 1126b9baf5c8SRussell King (Oracle) 1127b9baf5c8SRussell King (Oracle) @ Save r0, lr_<exception> (parent PC) 1128b9baf5c8SRussell King (Oracle) stmia sp, {r0, lr} 1129b9baf5c8SRussell King (Oracle) 1130b9baf5c8SRussell King (Oracle) @ bhb workaround 1131b9baf5c8SRussell King (Oracle) mov r0, #8 11323cfb3019SArd Biesheuvel3: W(b) . + 4 1133b9baf5c8SRussell King (Oracle) subs r0, r0, #1 11346c7cb60bSRussell King (Oracle) bne 3b 1135892c608aSArd Biesheuvel dsb nsh 1136892c608aSArd Biesheuvel @ isb not needed due to "movs pc, lr" in the vector stub 1137892c608aSArd Biesheuvel @ which gives a "context synchronisation". 11381290c70dSArd Biesheuvel b .Lvec_\name 1139b9baf5c8SRussell King (Oracle)ENDPROC(vector_bhb_loop8_\name) 1140b9baf5c8SRussell King (Oracle) .previous 1141b9baf5c8SRussell King (Oracle)#endif 1142b9baf5c8SRussell King (Oracle) 114388987ef9SCatalin Marinas .align 2 114488987ef9SCatalin Marinas @ handler addresses follow this label 114588987ef9SCatalin Marinas1: 11461da177e4SLinus Torvalds .endm 11471da177e4SLinus Torvalds 1148b9b32bf7SRussell King .section .stubs, "ax", %progbits 1149ad12c2f1SArd Biesheuvel @ These need to remain at the start of the section so that 1150ad12c2f1SArd Biesheuvel @ they are in range of the 'SWI' entries in the vector tables 1151ad12c2f1SArd Biesheuvel @ located 4k down. 1152ad12c2f1SArd Biesheuvel.L__vector_swi: 115319accfd3SRussell King .word vector_swi 1154b9baf5c8SRussell King (Oracle)#ifdef CONFIG_HARDEN_BRANCH_HISTORY 1155ad12c2f1SArd Biesheuvel.L__vector_bhb_loop8_swi: 1156b9baf5c8SRussell King (Oracle) .word vector_bhb_loop8_swi 1157ad12c2f1SArd Biesheuvel.L__vector_bhb_bpiall_swi: 1158b9baf5c8SRussell King (Oracle) .word vector_bhb_bpiall_swi 1159b9baf5c8SRussell King (Oracle)#endif 116019accfd3SRussell King 116119accfd3SRussell Kingvector_rst: 116219accfd3SRussell King ARM( swi SYS_ERROR0 ) 116319accfd3SRussell King THUMB( svc #0 ) 116419accfd3SRussell King THUMB( nop ) 116519accfd3SRussell King b vector_und 116619accfd3SRussell King 11671da177e4SLinus Torvalds/* 11681da177e4SLinus Torvalds * Interrupt dispatcher 11691da177e4SLinus Torvalds */ 1170b7ec4795SNicolas Pitre vector_stub irq, IRQ_MODE, 4 11711da177e4SLinus Torvalds 11721da177e4SLinus Torvalds .long __irq_usr @ 0 (USR_26 / USR_32) 11731da177e4SLinus Torvalds .long __irq_invalid @ 1 (FIQ_26 / FIQ_32) 11741da177e4SLinus Torvalds .long __irq_invalid @ 2 (IRQ_26 / IRQ_32) 11751da177e4SLinus Torvalds .long __irq_svc @ 3 (SVC_26 / SVC_32) 11761da177e4SLinus Torvalds .long __irq_invalid @ 4 11771da177e4SLinus Torvalds .long __irq_invalid @ 5 11781da177e4SLinus Torvalds .long __irq_invalid @ 6 11791da177e4SLinus Torvalds .long __irq_invalid @ 7 11801da177e4SLinus Torvalds .long __irq_invalid @ 8 11811da177e4SLinus Torvalds .long __irq_invalid @ 9 11821da177e4SLinus Torvalds .long __irq_invalid @ a 11831da177e4SLinus Torvalds .long __irq_invalid @ b 11841da177e4SLinus Torvalds .long __irq_invalid @ c 11851da177e4SLinus Torvalds .long __irq_invalid @ d 11861da177e4SLinus Torvalds .long __irq_invalid @ e 11871da177e4SLinus Torvalds .long __irq_invalid @ f 11881da177e4SLinus Torvalds 11891da177e4SLinus Torvalds/* 11901da177e4SLinus Torvalds * Data abort dispatcher 11911da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 11921da177e4SLinus Torvalds */ 1193b7ec4795SNicolas Pitre vector_stub dabt, ABT_MODE, 8 11941da177e4SLinus Torvalds 11951da177e4SLinus Torvalds .long __dabt_usr @ 0 (USR_26 / USR_32) 11961da177e4SLinus Torvalds .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32) 11971da177e4SLinus Torvalds .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32) 11981da177e4SLinus Torvalds .long __dabt_svc @ 3 (SVC_26 / SVC_32) 11991da177e4SLinus Torvalds .long __dabt_invalid @ 4 12001da177e4SLinus Torvalds .long __dabt_invalid @ 5 12011da177e4SLinus Torvalds .long __dabt_invalid @ 6 12021da177e4SLinus Torvalds .long __dabt_invalid @ 7 12031da177e4SLinus Torvalds .long __dabt_invalid @ 8 12041da177e4SLinus Torvalds .long __dabt_invalid @ 9 12051da177e4SLinus Torvalds .long __dabt_invalid @ a 12061da177e4SLinus Torvalds .long __dabt_invalid @ b 12071da177e4SLinus Torvalds .long __dabt_invalid @ c 12081da177e4SLinus Torvalds .long __dabt_invalid @ d 12091da177e4SLinus Torvalds .long __dabt_invalid @ e 12101da177e4SLinus Torvalds .long __dabt_invalid @ f 12111da177e4SLinus Torvalds 12121da177e4SLinus Torvalds/* 12131da177e4SLinus Torvalds * Prefetch abort dispatcher 12141da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 12151da177e4SLinus Torvalds */ 1216b7ec4795SNicolas Pitre vector_stub pabt, ABT_MODE, 4 12171da177e4SLinus Torvalds 12181da177e4SLinus Torvalds .long __pabt_usr @ 0 (USR_26 / USR_32) 12191da177e4SLinus Torvalds .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32) 12201da177e4SLinus Torvalds .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32) 12211da177e4SLinus Torvalds .long __pabt_svc @ 3 (SVC_26 / SVC_32) 12221da177e4SLinus Torvalds .long __pabt_invalid @ 4 12231da177e4SLinus Torvalds .long __pabt_invalid @ 5 12241da177e4SLinus Torvalds .long __pabt_invalid @ 6 12251da177e4SLinus Torvalds .long __pabt_invalid @ 7 12261da177e4SLinus Torvalds .long __pabt_invalid @ 8 12271da177e4SLinus Torvalds .long __pabt_invalid @ 9 12281da177e4SLinus Torvalds .long __pabt_invalid @ a 12291da177e4SLinus Torvalds .long __pabt_invalid @ b 12301da177e4SLinus Torvalds .long __pabt_invalid @ c 12311da177e4SLinus Torvalds .long __pabt_invalid @ d 12321da177e4SLinus Torvalds .long __pabt_invalid @ e 12331da177e4SLinus Torvalds .long __pabt_invalid @ f 12341da177e4SLinus Torvalds 12351da177e4SLinus Torvalds/* 12361da177e4SLinus Torvalds * Undef instr entry dispatcher 12371da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 12381da177e4SLinus Torvalds */ 1239b7ec4795SNicolas Pitre vector_stub und, UND_MODE 12401da177e4SLinus Torvalds 12411da177e4SLinus Torvalds .long __und_usr @ 0 (USR_26 / USR_32) 12421da177e4SLinus Torvalds .long __und_invalid @ 1 (FIQ_26 / FIQ_32) 12431da177e4SLinus Torvalds .long __und_invalid @ 2 (IRQ_26 / IRQ_32) 12441da177e4SLinus Torvalds .long __und_svc @ 3 (SVC_26 / SVC_32) 12451da177e4SLinus Torvalds .long __und_invalid @ 4 12461da177e4SLinus Torvalds .long __und_invalid @ 5 12471da177e4SLinus Torvalds .long __und_invalid @ 6 12481da177e4SLinus Torvalds .long __und_invalid @ 7 12491da177e4SLinus Torvalds .long __und_invalid @ 8 12501da177e4SLinus Torvalds .long __und_invalid @ 9 12511da177e4SLinus Torvalds .long __und_invalid @ a 12521da177e4SLinus Torvalds .long __und_invalid @ b 12531da177e4SLinus Torvalds .long __und_invalid @ c 12541da177e4SLinus Torvalds .long __und_invalid @ d 12551da177e4SLinus Torvalds .long __und_invalid @ e 12561da177e4SLinus Torvalds .long __und_invalid @ f 12571da177e4SLinus Torvalds 12581da177e4SLinus Torvalds .align 5 12591da177e4SLinus Torvalds 12601da177e4SLinus Torvalds/*============================================================================= 126119accfd3SRussell King * Address exception handler 126219accfd3SRussell King *----------------------------------------------------------------------------- 126319accfd3SRussell King * These aren't too critical. 126419accfd3SRussell King * (they're not supposed to happen, and won't happen in 32-bit data mode). 126519accfd3SRussell King */ 126619accfd3SRussell King 126719accfd3SRussell Kingvector_addrexcptn: 126819accfd3SRussell King b vector_addrexcptn 126919accfd3SRussell King 127019accfd3SRussell King/*============================================================================= 1271c0e7f7eeSDaniel Thompson * FIQ "NMI" handler 12721da177e4SLinus Torvalds *----------------------------------------------------------------------------- 1273c0e7f7eeSDaniel Thompson * Handle a FIQ using the SVC stack allowing FIQ act like NMI on x86 1274b9baf5c8SRussell King (Oracle) * systems. This must be the last vector stub, so lets place it in its own 1275b9baf5c8SRussell King (Oracle) * subsection. 12761da177e4SLinus Torvalds */ 1277b9baf5c8SRussell King (Oracle) .subsection 2 1278c0e7f7eeSDaniel Thompson vector_stub fiq, FIQ_MODE, 4 1279c0e7f7eeSDaniel Thompson 1280c0e7f7eeSDaniel Thompson .long __fiq_usr @ 0 (USR_26 / USR_32) 1281c0e7f7eeSDaniel Thompson .long __fiq_svc @ 1 (FIQ_26 / FIQ_32) 1282c0e7f7eeSDaniel Thompson .long __fiq_svc @ 2 (IRQ_26 / IRQ_32) 1283c0e7f7eeSDaniel Thompson .long __fiq_svc @ 3 (SVC_26 / SVC_32) 1284c0e7f7eeSDaniel Thompson .long __fiq_svc @ 4 1285c0e7f7eeSDaniel Thompson .long __fiq_svc @ 5 1286c0e7f7eeSDaniel Thompson .long __fiq_svc @ 6 1287c0e7f7eeSDaniel Thompson .long __fiq_abt @ 7 1288c0e7f7eeSDaniel Thompson .long __fiq_svc @ 8 1289c0e7f7eeSDaniel Thompson .long __fiq_svc @ 9 1290c0e7f7eeSDaniel Thompson .long __fiq_svc @ a 1291c0e7f7eeSDaniel Thompson .long __fiq_svc @ b 1292c0e7f7eeSDaniel Thompson .long __fiq_svc @ c 1293c0e7f7eeSDaniel Thompson .long __fiq_svc @ d 1294c0e7f7eeSDaniel Thompson .long __fiq_svc @ e 1295c0e7f7eeSDaniel Thompson .long __fiq_svc @ f 12961da177e4SLinus Torvalds 129731b96caeSArd Biesheuvel .globl vector_fiq 1298e39e3f3eSRussell King 1299b9b32bf7SRussell King .section .vectors, "ax", %progbits 1300b9b32bf7SRussell King W(b) vector_rst 1301b9b32bf7SRussell King W(b) vector_und 1302ad12c2f1SArd BiesheuvelARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_swi ) 1303ad12c2f1SArd BiesheuvelTHUMB( .reloc ., R_ARM_THM_PC12, .L__vector_swi ) 1304ad12c2f1SArd Biesheuvel W(ldr) pc, . 1305b9b32bf7SRussell King W(b) vector_pabt 1306b9b32bf7SRussell King W(b) vector_dabt 1307b9b32bf7SRussell King W(b) vector_addrexcptn 1308b9b32bf7SRussell King W(b) vector_irq 1309b9b32bf7SRussell King W(b) vector_fiq 13101da177e4SLinus Torvalds 1311b9baf5c8SRussell King (Oracle)#ifdef CONFIG_HARDEN_BRANCH_HISTORY 1312b9baf5c8SRussell King (Oracle) .section .vectors.bhb.loop8, "ax", %progbits 1313b9baf5c8SRussell King (Oracle) W(b) vector_rst 1314b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_und 1315ad12c2f1SArd BiesheuvelARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_bhb_loop8_swi ) 1316ad12c2f1SArd BiesheuvelTHUMB( .reloc ., R_ARM_THM_PC12, .L__vector_bhb_loop8_swi ) 1317ad12c2f1SArd Biesheuvel W(ldr) pc, . 1318b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_pabt 1319b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_dabt 1320b9baf5c8SRussell King (Oracle) W(b) vector_addrexcptn 1321b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_irq 1322b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_fiq 1323b9baf5c8SRussell King (Oracle) 1324b9baf5c8SRussell King (Oracle) .section .vectors.bhb.bpiall, "ax", %progbits 1325b9baf5c8SRussell King (Oracle) W(b) vector_rst 1326b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_und 1327ad12c2f1SArd BiesheuvelARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_bhb_bpiall_swi ) 1328ad12c2f1SArd BiesheuvelTHUMB( .reloc ., R_ARM_THM_PC12, .L__vector_bhb_bpiall_swi ) 1329ad12c2f1SArd Biesheuvel W(ldr) pc, . 1330b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_pabt 1331b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_dabt 1332b9baf5c8SRussell King (Oracle) W(b) vector_addrexcptn 1333b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_irq 1334b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_fiq 1335b9baf5c8SRussell King (Oracle)#endif 1336b9baf5c8SRussell King (Oracle) 13371da177e4SLinus Torvalds .data 13381abd3502SRussell King .align 2 13391da177e4SLinus Torvalds 13401da177e4SLinus Torvalds .globl cr_alignment 13411da177e4SLinus Torvaldscr_alignment: 13421da177e4SLinus Torvalds .space 4 1343