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 640402beceSRussell King ldr ip, .LCprocfns 65ac8b9c1cSRussell King mov lr, pc 660402beceSRussell King ldr pc, [ip, #PROCESSOR_PABT_FUNC] 67ac8b9c1cSRussell King#else 68ac8b9c1cSRussell King bl CPU_PABORT_HANDLER 69ac8b9c1cSRussell King#endif 70ac8b9c1cSRussell King .endm 71ac8b9c1cSRussell King 72ac8b9c1cSRussell King .macro dabt_helper 73ac8b9c1cSRussell King 74ac8b9c1cSRussell King @ 75ac8b9c1cSRussell King @ Call the processor-specific abort handler: 76ac8b9c1cSRussell King @ 77da740472SRussell King @ r2 - pt_regs 783e287becSRussell King @ r4 - aborted context pc 793e287becSRussell King @ r5 - aborted context psr 80ac8b9c1cSRussell King @ 81ac8b9c1cSRussell King @ The abort handler must return the aborted address in r0, and 82ac8b9c1cSRussell King @ the fault status register in r1. r9 must be preserved. 83ac8b9c1cSRussell King @ 84ac8b9c1cSRussell King#ifdef MULTI_DABORT 850402beceSRussell King ldr ip, .LCprocfns 86ac8b9c1cSRussell King mov lr, pc 870402beceSRussell King ldr pc, [ip, #PROCESSOR_DABT_FUNC] 88ac8b9c1cSRussell King#else 89ac8b9c1cSRussell King bl CPU_DABORT_HANDLER 90ac8b9c1cSRussell King#endif 91ac8b9c1cSRussell King .endm 92ac8b9c1cSRussell King 93c6089061SRussell King .section .entry.text,"ax",%progbits 94785d3cd2SNicolas Pitre 95187a51adSRussell King/* 961da177e4SLinus Torvalds * Invalid mode handlers 971da177e4SLinus Torvalds */ 98ccea7a19SRussell King .macro inv_entry, reason 995745eef6SRussell King sub sp, sp, #PT_REGS_SIZE 100b86040a5SCatalin Marinas ARM( stmib sp, {r1 - lr} ) 101b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 102b86040a5SCatalin Marinas THUMB( str sp, [sp, #S_SP] ) 103b86040a5SCatalin Marinas THUMB( str lr, [sp, #S_LR] ) 1041da177e4SLinus Torvalds mov r1, #\reason 1051da177e4SLinus Torvalds .endm 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds__pabt_invalid: 108ccea7a19SRussell King inv_entry BAD_PREFETCH 109ccea7a19SRussell King b common_invalid 11093ed3970SCatalin MarinasENDPROC(__pabt_invalid) 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds__dabt_invalid: 113ccea7a19SRussell King inv_entry BAD_DATA 114ccea7a19SRussell King b common_invalid 11593ed3970SCatalin MarinasENDPROC(__dabt_invalid) 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds__irq_invalid: 118ccea7a19SRussell King inv_entry BAD_IRQ 119ccea7a19SRussell King b common_invalid 12093ed3970SCatalin MarinasENDPROC(__irq_invalid) 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds__und_invalid: 123ccea7a19SRussell King inv_entry BAD_UNDEFINSTR 1241da177e4SLinus Torvalds 125ccea7a19SRussell King @ 126ccea7a19SRussell King @ XXX fall through to common_invalid 127ccea7a19SRussell King @ 128ccea7a19SRussell King 129ccea7a19SRussell King@ 130ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers) 131ccea7a19SRussell King@ 132ccea7a19SRussell Kingcommon_invalid: 133ccea7a19SRussell King zero_fp 134ccea7a19SRussell King 135ccea7a19SRussell King ldmia r0, {r4 - r6} 136ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 137ccea7a19SRussell King mov r7, #-1 @ "" "" "" "" 138ccea7a19SRussell King str r4, [sp] @ save preserved r0 139ccea7a19SRussell King stmia r0, {r5 - r7} @ lr_<exception>, 140ccea7a19SRussell King @ cpsr_<exception>, "old_r0" 141ccea7a19SRussell King 1421da177e4SLinus Torvalds mov r0, sp 1431da177e4SLinus Torvalds b bad_mode 14493ed3970SCatalin MarinasENDPROC(__und_invalid) 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds/* 1471da177e4SLinus Torvalds * SVC mode handlers 1481da177e4SLinus Torvalds */ 1492dede2d8SNicolas Pitre 1502dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) 1512dede2d8SNicolas Pitre#define SPFIX(code...) code 1522dede2d8SNicolas Pitre#else 1532dede2d8SNicolas Pitre#define SPFIX(code...) 1542dede2d8SNicolas Pitre#endif 1552dede2d8SNicolas Pitre 156a1c510d0SArd Biesheuvel .macro svc_entry, stack_hole=0, trace=1, uaccess=1, overflow_check=1 157c4c5716eSCatalin Marinas UNWIND(.fnstart ) 158ae5cc07dSArd Biesheuvel sub sp, sp, #(SVC_REGS_SIZE + \stack_hole) 159a1c510d0SArd Biesheuvel THUMB( add sp, r1 ) @ get SP in a GPR without 160a1c510d0SArd Biesheuvel THUMB( sub r1, sp, r1 ) @ using a temp register 161a1c510d0SArd Biesheuvel 162a1c510d0SArd Biesheuvel .if \overflow_check 163c4c5716eSCatalin Marinas UNWIND(.save {r0 - pc} ) 164a1c510d0SArd Biesheuvel do_overflow_check (SVC_REGS_SIZE + \stack_hole) 165a1c510d0SArd Biesheuvel .endif 166a1c510d0SArd Biesheuvel 167b86040a5SCatalin Marinas#ifdef CONFIG_THUMB2_KERNEL 168ae5cc07dSArd Biesheuvel tst r1, #4 @ test stack pointer alignment 169ae5cc07dSArd Biesheuvel sub r1, sp, r1 @ restore original R1 170ae5cc07dSArd Biesheuvel sub sp, r1 @ restore original SP 171b86040a5SCatalin Marinas#else 1722dede2d8SNicolas Pitre SPFIX( tst sp, #4 ) 173b86040a5SCatalin Marinas#endif 174ae5cc07dSArd Biesheuvel SPFIX( subne sp, sp, #4 ) 175ae5cc07dSArd Biesheuvel 176ae5cc07dSArd Biesheuvel ARM( stmib sp, {r1 - r12} ) 177ae5cc07dSArd Biesheuvel THUMB( stmia sp, {r0 - r12} ) @ No STMIB in Thumb-2 178ccea7a19SRussell King 179b059bdc3SRussell King ldmia r0, {r3 - r5} 180ae5cc07dSArd Biesheuvel add r7, sp, #S_SP @ here for interlock avoidance 181b059bdc3SRussell King mov r6, #-1 @ "" "" "" "" 182ae5cc07dSArd Biesheuvel add r2, sp, #(SVC_REGS_SIZE + \stack_hole) 183ae5cc07dSArd Biesheuvel SPFIX( addne r2, r2, #4 ) 184ae5cc07dSArd Biesheuvel str r3, [sp] @ save the "real" r0 copied 185ccea7a19SRussell King @ from the exception stack 186ccea7a19SRussell King 187b059bdc3SRussell King mov r3, lr 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds @ 1901da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 1911da177e4SLinus Torvalds @ 192b059bdc3SRussell King @ r2 - sp_svc 193b059bdc3SRussell King @ r3 - lr_svc 194b059bdc3SRussell King @ r4 - lr_<exception>, already fixed up for correct return/restart 195b059bdc3SRussell King @ r5 - spsr_<exception> 196b059bdc3SRussell King @ r6 - orig_r0 (see pt_regs definition in ptrace.h) 1971da177e4SLinus Torvalds @ 198b059bdc3SRussell King stmia r7, {r2 - r6} 199f2741b78SRussell King 200e6978e4bSRussell King get_thread_info tsk 201747ffc2fSRussell King uaccess_entry tsk, r0, r1, r2, \uaccess 2022190fed6SRussell King 203c0e7f7eeSDaniel Thompson .if \trace 204f2741b78SRussell King#ifdef CONFIG_TRACE_IRQFLAGS 205f2741b78SRussell King bl trace_hardirqs_off 206f2741b78SRussell King#endif 207c0e7f7eeSDaniel Thompson .endif 2081da177e4SLinus Torvalds .endm 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds .align 5 2111da177e4SLinus Torvalds__dabt_svc: 2122190fed6SRussell King svc_entry uaccess=0 2131da177e4SLinus Torvalds mov r2, sp 214da740472SRussell King dabt_helper 215e16b31bfSMarc Zyngier THUMB( ldr r5, [sp, #S_PSR] ) @ potentially updated CPSR 216b059bdc3SRussell King svc_exit r5 @ return from exception 217c4c5716eSCatalin Marinas UNWIND(.fnend ) 21893ed3970SCatalin MarinasENDPROC(__dabt_svc) 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds .align 5 2211da177e4SLinus Torvalds__irq_svc: 222ccea7a19SRussell King svc_entry 223d4664b6cSArd Biesheuvel irq_handler from_user=0 2241613cc11SRussell King 225e7289c6dSThomas Gleixner#ifdef CONFIG_PREEMPTION 226706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 227706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get flags 22828fab1a2SRussell King teq r8, #0 @ if preempt count != 0 22928fab1a2SRussell King movne r0, #0 @ force flags to 0 2301da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2311da177e4SLinus Torvalds blne svc_preempt 2321da177e4SLinus Torvalds#endif 23330891c90SRussell King 2349b56febeSRussell King svc_exit r5, irq = 1 @ return from exception 235c4c5716eSCatalin Marinas UNWIND(.fnend ) 23693ed3970SCatalin MarinasENDPROC(__irq_svc) 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds .ltorg 2391da177e4SLinus Torvalds 240e7289c6dSThomas Gleixner#ifdef CONFIG_PREEMPTION 2411da177e4SLinus Torvaldssvc_preempt: 24228fab1a2SRussell King mov r8, lr 2431da177e4SLinus Torvalds1: bl preempt_schedule_irq @ irq en/disable is done inside 244706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS 2451da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2466ebbf2ceSRussell King reteq r8 @ go again 2471da177e4SLinus Torvalds b 1b 2481da177e4SLinus Torvalds#endif 2491da177e4SLinus Torvalds 25015ac49b6SRussell King__und_fault: 25115ac49b6SRussell King @ Correct the PC such that it is pointing at the instruction 25215ac49b6SRussell King @ which caused the fault. If the faulting instruction was ARM 25315ac49b6SRussell King @ the PC will be pointing at the next instruction, and have to 25415ac49b6SRussell King @ subtract 4. Otherwise, it is Thumb, and the PC will be 25515ac49b6SRussell King @ pointing at the second half of the Thumb instruction. We 25615ac49b6SRussell King @ have to subtract 2. 25715ac49b6SRussell King ldr r2, [r0, #S_PC] 25815ac49b6SRussell King sub r2, r2, r1 25915ac49b6SRussell King str r2, [r0, #S_PC] 26015ac49b6SRussell King b do_undefinstr 26115ac49b6SRussell KingENDPROC(__und_fault) 26215ac49b6SRussell King 2631da177e4SLinus Torvalds .align 5 2641da177e4SLinus Torvalds__und_svc: 265d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES 266d30a0c8bSNicolas Pitre @ If a kprobe is about to simulate a "stmdb sp..." instruction, 267d30a0c8bSNicolas Pitre @ it obviously needs free stack space which then will belong to 268d30a0c8bSNicolas Pitre @ the saved context. 269a0266c21SWang Nan svc_entry MAX_STACK_SIZE 270d30a0c8bSNicolas Pitre#else 271ccea7a19SRussell King svc_entry 272d30a0c8bSNicolas Pitre#endif 2731da177e4SLinus Torvalds 27415ac49b6SRussell King mov r1, #4 @ PC correction to apply 275f77ac2e3SArd Biesheuvel THUMB( tst r5, #PSR_T_BIT ) @ exception taken in Thumb mode? 276f77ac2e3SArd Biesheuvel THUMB( movne r1, #2 ) @ if so, fix up PC correction 2771da177e4SLinus Torvalds mov r0, sp @ struct pt_regs *regs 27815ac49b6SRussell King bl __und_fault 2791da177e4SLinus Torvalds 28015ac49b6SRussell King__und_svc_finish: 28187eed3c7SRussell King get_thread_info tsk 282b059bdc3SRussell King ldr r5, [sp, #S_PSR] @ Get SVC cpsr 283b059bdc3SRussell King svc_exit r5 @ return from exception 284c4c5716eSCatalin Marinas UNWIND(.fnend ) 28593ed3970SCatalin MarinasENDPROC(__und_svc) 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds .align 5 2881da177e4SLinus Torvalds__pabt_svc: 289ccea7a19SRussell King svc_entry 2904fb28474SKirill A. Shutemov mov r2, sp @ regs 2918dfe7ac9SRussell King pabt_helper 292b059bdc3SRussell King svc_exit r5 @ return from exception 293c4c5716eSCatalin Marinas UNWIND(.fnend ) 29493ed3970SCatalin MarinasENDPROC(__pabt_svc) 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds .align 5 297c0e7f7eeSDaniel Thompson__fiq_svc: 298c0e7f7eeSDaniel Thompson svc_entry trace=0 299c0e7f7eeSDaniel Thompson mov r0, sp @ struct pt_regs *regs 300c0e7f7eeSDaniel Thompson bl handle_fiq_as_nmi 301c0e7f7eeSDaniel Thompson svc_exit_via_fiq 302c0e7f7eeSDaniel Thompson UNWIND(.fnend ) 303c0e7f7eeSDaniel ThompsonENDPROC(__fiq_svc) 304c0e7f7eeSDaniel Thompson 305c0e7f7eeSDaniel Thompson .align 5 30649f680eaSRussell King.LCcralign: 30749f680eaSRussell King .word cr_alignment 30848d7927bSPaul Brook#ifdef MULTI_DABORT 3091da177e4SLinus Torvalds.LCprocfns: 3101da177e4SLinus Torvalds .word processor 3111da177e4SLinus Torvalds#endif 3121da177e4SLinus Torvalds.LCfp: 3131da177e4SLinus Torvalds .word fp_enter 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds/* 316c0e7f7eeSDaniel Thompson * Abort mode handlers 317c0e7f7eeSDaniel Thompson */ 318c0e7f7eeSDaniel Thompson 319c0e7f7eeSDaniel Thompson@ 320c0e7f7eeSDaniel Thompson@ Taking a FIQ in abort mode is similar to taking a FIQ in SVC mode 321c0e7f7eeSDaniel Thompson@ and reuses the same macros. However in abort mode we must also 322c0e7f7eeSDaniel Thompson@ save/restore lr_abt and spsr_abt to make nested aborts safe. 323c0e7f7eeSDaniel Thompson@ 324c0e7f7eeSDaniel Thompson .align 5 325c0e7f7eeSDaniel Thompson__fiq_abt: 326c0e7f7eeSDaniel Thompson svc_entry trace=0 327c0e7f7eeSDaniel Thompson 328c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 329c0e7f7eeSDaniel Thompson THUMB( mov r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 330c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 331c0e7f7eeSDaniel Thompson mov r1, lr @ Save lr_abt 332c0e7f7eeSDaniel Thompson mrs r2, spsr @ Save spsr_abt, abort is now safe 333c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 334c0e7f7eeSDaniel Thompson THUMB( mov r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 335c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 336c0e7f7eeSDaniel Thompson stmfd sp!, {r1 - r2} 337c0e7f7eeSDaniel Thompson 338c0e7f7eeSDaniel Thompson add r0, sp, #8 @ struct pt_regs *regs 339c0e7f7eeSDaniel Thompson bl handle_fiq_as_nmi 340c0e7f7eeSDaniel Thompson 341c0e7f7eeSDaniel Thompson ldmfd sp!, {r1 - r2} 342c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 343c0e7f7eeSDaniel Thompson THUMB( mov r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT ) 344c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 345c0e7f7eeSDaniel Thompson mov lr, r1 @ Restore lr_abt, abort is unsafe 346c0e7f7eeSDaniel Thompson msr spsr_cxsf, r2 @ Restore spsr_abt 347c0e7f7eeSDaniel Thompson ARM( msr cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 348c0e7f7eeSDaniel Thompson THUMB( mov r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT ) 349c0e7f7eeSDaniel Thompson THUMB( msr cpsr_c, r0 ) 350c0e7f7eeSDaniel Thompson 351c0e7f7eeSDaniel Thompson svc_exit_via_fiq 352c0e7f7eeSDaniel Thompson UNWIND(.fnend ) 353c0e7f7eeSDaniel ThompsonENDPROC(__fiq_abt) 354c0e7f7eeSDaniel Thompson 355c0e7f7eeSDaniel Thompson/* 3561da177e4SLinus Torvalds * User mode handlers 3572dede2d8SNicolas Pitre * 3585745eef6SRussell King * EABI note: sp_svc is always 64-bit aligned here, so should PT_REGS_SIZE 3591da177e4SLinus Torvalds */ 3602dede2d8SNicolas Pitre 3615745eef6SRussell King#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (PT_REGS_SIZE & 7) 3622dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8" 3632dede2d8SNicolas Pitre#endif 3642dede2d8SNicolas Pitre 3652190fed6SRussell King .macro usr_entry, trace=1, uaccess=1 366c4c5716eSCatalin Marinas UNWIND(.fnstart ) 367c4c5716eSCatalin Marinas UNWIND(.cantunwind ) @ don't unwind the user space 3685745eef6SRussell King sub sp, sp, #PT_REGS_SIZE 369b86040a5SCatalin Marinas ARM( stmib sp, {r1 - r12} ) 370b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 371ccea7a19SRussell King 372195b58adSRussell King ATRAP( mrc p15, 0, r7, c1, c0, 0) 373195b58adSRussell King ATRAP( ldr r8, .LCcralign) 374195b58adSRussell King 375b059bdc3SRussell King ldmia r0, {r3 - r5} 376ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 377b059bdc3SRussell King mov r6, #-1 @ "" "" "" "" 378ccea7a19SRussell King 379b059bdc3SRussell King str r3, [sp] @ save the "real" r0 copied 380ccea7a19SRussell King @ from the exception stack 3811da177e4SLinus Torvalds 382195b58adSRussell King ATRAP( ldr r8, [r8, #0]) 383195b58adSRussell King 3841da177e4SLinus Torvalds @ 3851da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 3861da177e4SLinus Torvalds @ 387b059bdc3SRussell King @ r4 - lr_<exception>, already fixed up for correct return/restart 388b059bdc3SRussell King @ r5 - spsr_<exception> 389b059bdc3SRussell King @ r6 - orig_r0 (see pt_regs definition in ptrace.h) 3901da177e4SLinus Torvalds @ 3911da177e4SLinus Torvalds @ Also, separately save sp_usr and lr_usr 3921da177e4SLinus Torvalds @ 393b059bdc3SRussell King stmia r0, {r4 - r6} 394b86040a5SCatalin Marinas ARM( stmdb r0, {sp, lr}^ ) 395b86040a5SCatalin Marinas THUMB( store_user_sp_lr r0, r1, S_SP - S_PC ) 3961da177e4SLinus Torvalds 3972190fed6SRussell King .if \uaccess 3982190fed6SRussell King uaccess_disable ip 3992190fed6SRussell King .endif 4002190fed6SRussell King 4011da177e4SLinus Torvalds @ Enable the alignment trap while in kernel mode 402195b58adSRussell King ATRAP( teq r8, r7) 403195b58adSRussell King ATRAP( mcrne p15, 0, r8, c1, c0, 0) 4041da177e4SLinus Torvalds 40550596b75SArd Biesheuvel reload_current r7, r8 40650596b75SArd Biesheuvel 4071da177e4SLinus Torvalds @ 4081da177e4SLinus Torvalds @ Clear FP to mark the first stack frame 4091da177e4SLinus Torvalds @ 4101da177e4SLinus Torvalds zero_fp 411f2741b78SRussell King 412c0e7f7eeSDaniel Thompson .if \trace 41311b8b25cSRussell King#ifdef CONFIG_TRACE_IRQFLAGS 414f2741b78SRussell King bl trace_hardirqs_off 415f2741b78SRussell King#endif 416b0088480SKevin Hilman ct_user_exit save = 0 417c0e7f7eeSDaniel Thompson .endif 4181da177e4SLinus Torvalds .endm 4191da177e4SLinus Torvalds 420b49c0f24SNicolas Pitre .macro kuser_cmpxchg_check 421db695c05SRussell King#if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS) 422b49c0f24SNicolas Pitre#ifndef CONFIG_MMU 423b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing" 424b49c0f24SNicolas Pitre#else 425b49c0f24SNicolas Pitre @ Make sure our user space atomic helper is restarted 426b49c0f24SNicolas Pitre @ if it was interrupted in a critical region. Here we 427b49c0f24SNicolas Pitre @ perform a quick test inline since it should be false 428b49c0f24SNicolas Pitre @ 99.9999% of the time. The rest is done out of line. 429c12366baSLinus Walleij ldr r0, =TASK_SIZE 430c12366baSLinus Walleij cmp r4, r0 43140fb79c8SNicolas Pitre blhs kuser_cmpxchg64_fixup 432b49c0f24SNicolas Pitre#endif 433b49c0f24SNicolas Pitre#endif 434b49c0f24SNicolas Pitre .endm 435b49c0f24SNicolas Pitre 4361da177e4SLinus Torvalds .align 5 4371da177e4SLinus Torvalds__dabt_usr: 4382190fed6SRussell King usr_entry uaccess=0 439b49c0f24SNicolas Pitre kuser_cmpxchg_check 4401da177e4SLinus Torvalds mov r2, sp 441da740472SRussell King dabt_helper 442da740472SRussell King b ret_from_exception 443c4c5716eSCatalin Marinas UNWIND(.fnend ) 44493ed3970SCatalin MarinasENDPROC(__dabt_usr) 4451da177e4SLinus Torvalds 4461da177e4SLinus Torvalds .align 5 4471da177e4SLinus Torvalds__irq_usr: 448ccea7a19SRussell King usr_entry 449bc089602SRussell King kuser_cmpxchg_check 450d4664b6cSArd Biesheuvel irq_handler from_user=1 4511613cc11SRussell King get_thread_info tsk 4521da177e4SLinus Torvalds mov why, #0 4539fc2552aSMing Lei b ret_to_user_from_irq 454c4c5716eSCatalin Marinas UNWIND(.fnend ) 45593ed3970SCatalin MarinasENDPROC(__irq_usr) 4561da177e4SLinus Torvalds 4571da177e4SLinus Torvalds .ltorg 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds .align 5 4601da177e4SLinus Torvalds__und_usr: 4612190fed6SRussell King usr_entry uaccess=0 462bc089602SRussell King 463b059bdc3SRussell King mov r2, r4 464b059bdc3SRussell King mov r3, r5 4651da177e4SLinus Torvalds 46615ac49b6SRussell King @ r2 = regs->ARM_pc, which is either 2 or 4 bytes ahead of the 46715ac49b6SRussell King @ faulting instruction depending on Thumb mode. 46815ac49b6SRussell King @ r3 = regs->ARM_cpsr 4691da177e4SLinus Torvalds @ 47015ac49b6SRussell King @ The emulation code returns using r9 if it has emulated the 47115ac49b6SRussell King @ instruction, or the more conventional lr if we are to treat 47215ac49b6SRussell King @ this as a real undefined instruction 4731da177e4SLinus Torvalds @ 47414327c66SRussell King badr r9, ret_from_exception 47515ac49b6SRussell King 4761417a6b8SCatalin Marinas @ IRQs must be enabled before attempting to read the instruction from 4771417a6b8SCatalin Marinas @ user space since that could cause a page/translation fault if the 4781417a6b8SCatalin Marinas @ page table was modified by another CPU. 4791417a6b8SCatalin Marinas enable_irq 4801417a6b8SCatalin Marinas 481cb170a45SPaul Brook tst r3, #PSR_T_BIT @ Thumb mode? 48215ac49b6SRussell King bne __und_usr_thumb 48315ac49b6SRussell King sub r4, r2, #4 @ ARM instr at LR - 4 48415ac49b6SRussell King1: ldrt r0, [r4] 485457c2403SBen Dooks ARM_BE8(rev r0, r0) @ little endian instruction 486457c2403SBen Dooks 4872190fed6SRussell King uaccess_disable ip 4882190fed6SRussell King 48915ac49b6SRussell King @ r0 = 32-bit ARM instruction which caused the exception 49015ac49b6SRussell King @ r2 = PC value for the following instruction (:= regs->ARM_pc) 49115ac49b6SRussell King @ r4 = PC value for the faulting instruction 49215ac49b6SRussell King @ lr = 32-bit undefined instruction function 49314327c66SRussell King badr lr, __und_usr_fault_32 49415ac49b6SRussell King b call_fpe 49515ac49b6SRussell King 49615ac49b6SRussell King__und_usr_thumb: 497cb170a45SPaul Brook @ Thumb instruction 49815ac49b6SRussell King sub r4, r2, #2 @ First half of thumb instr at LR - 2 499ef4c5368SDave Martin#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7 500ef4c5368SDave Martin/* 501ef4c5368SDave Martin * Thumb-2 instruction handling. Note that because pre-v6 and >= v6 platforms 502ef4c5368SDave Martin * can never be supported in a single kernel, this code is not applicable at 503ef4c5368SDave Martin * all when __LINUX_ARM_ARCH__ < 6. This allows simplifying assumptions to be 504ef4c5368SDave Martin * made about .arch directives. 505ef4c5368SDave Martin */ 506ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7 507ef4c5368SDave Martin/* If the target CPU may not be Thumb-2-capable, a run-time check is needed: */ 508ef4c5368SDave Martin#define NEED_CPU_ARCHITECTURE 509ef4c5368SDave Martin ldr r5, .LCcpu_architecture 510ef4c5368SDave Martin ldr r5, [r5] 511ef4c5368SDave Martin cmp r5, #CPU_ARCH_ARMv7 51215ac49b6SRussell King blo __und_usr_fault_16 @ 16bit undefined instruction 513ef4c5368SDave Martin/* 514ef4c5368SDave Martin * The following code won't get run unless the running CPU really is v7, so 515ef4c5368SDave Martin * coding round the lack of ldrht on older arches is pointless. Temporarily 516ef4c5368SDave Martin * override the assembler target arch with the minimum required instead: 517ef4c5368SDave Martin */ 518ef4c5368SDave Martin .arch armv6t2 519ef4c5368SDave Martin#endif 52015ac49b6SRussell King2: ldrht r5, [r4] 521f8fe23ecSVictor KamenskyARM_BE8(rev16 r5, r5) @ little endian instruction 52285519189SDave Martin cmp r5, #0xe800 @ 32bit instruction if xx != 0 5232190fed6SRussell King blo __und_usr_fault_16_pan @ 16bit undefined instruction 52415ac49b6SRussell King3: ldrht r0, [r2] 525f8fe23ecSVictor KamenskyARM_BE8(rev16 r0, r0) @ little endian instruction 5262190fed6SRussell King uaccess_disable ip 527cb170a45SPaul Brook add r2, r2, #2 @ r2 is PC + 2, make it PC + 4 52815ac49b6SRussell King str r2, [sp, #S_PC] @ it's a 2x16bit instr, update 529cb170a45SPaul Brook orr r0, r0, r5, lsl #16 53014327c66SRussell King badr lr, __und_usr_fault_32 53115ac49b6SRussell King @ r0 = the two 16-bit Thumb instructions which caused the exception 53215ac49b6SRussell King @ r2 = PC value for the following Thumb instruction (:= regs->ARM_pc) 53315ac49b6SRussell King @ r4 = PC value for the first 16-bit Thumb instruction 53415ac49b6SRussell King @ lr = 32bit undefined instruction function 535ef4c5368SDave Martin 536ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7 537ef4c5368SDave Martin/* If the target arch was overridden, change it back: */ 538ef4c5368SDave Martin#ifdef CONFIG_CPU_32v6K 539ef4c5368SDave Martin .arch armv6k 540cb170a45SPaul Brook#else 541ef4c5368SDave Martin .arch armv6 542ef4c5368SDave Martin#endif 543ef4c5368SDave Martin#endif /* __LINUX_ARM_ARCH__ < 7 */ 544ef4c5368SDave Martin#else /* !(CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7) */ 54515ac49b6SRussell King b __und_usr_fault_16 546cb170a45SPaul Brook#endif 547c4c5716eSCatalin Marinas UNWIND(.fnend) 54893ed3970SCatalin MarinasENDPROC(__und_usr) 549cb170a45SPaul Brook 5501da177e4SLinus Torvalds/* 55115ac49b6SRussell King * The out of line fixup for the ldrt instructions above. 5521da177e4SLinus Torvalds */ 553c4a84ae3SArd Biesheuvel .pushsection .text.fixup, "ax" 554667d1b48SWill Deacon .align 2 5553780f7abSArun K S4: str r4, [sp, #S_PC] @ retry current instruction 5566ebbf2ceSRussell King ret r9 5574260415fSRussell King .popsection 5584260415fSRussell King .pushsection __ex_table,"a" 559cb170a45SPaul Brook .long 1b, 4b 560c89cefedSGuennadi Liakhovetski#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7 561cb170a45SPaul Brook .long 2b, 4b 562cb170a45SPaul Brook .long 3b, 4b 563cb170a45SPaul Brook#endif 5644260415fSRussell King .popsection 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds/* 5671da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction. 5681da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler. 5691da177e4SLinus Torvalds * 5701da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor 5711da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well 5721da177e4SLinus Torvalds * defined. The only instructions that should fault are the 5731da177e4SLinus Torvalds * co-processor instructions. However, we have to watch out 5741da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug. 5751da177e4SLinus Torvalds * 576b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all 577b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have 578b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's 579b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs 580b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the 581b5872db4SCatalin Marinas * NEON handler code. 582b5872db4SCatalin Marinas * 5831da177e4SLinus Torvalds * Emulators may wish to make use of the following registers: 58415ac49b6SRussell King * r0 = instruction opcode (32-bit ARM or two 16-bit Thumb) 58515ac49b6SRussell King * r2 = PC value to resume execution after successful emulation 586db6ccbb6SRussell King * r9 = normal "successful" return address 58715ac49b6SRussell King * r10 = this threads thread_info structure 588db6ccbb6SRussell King * lr = unrecognised instruction return address 5891417a6b8SCatalin Marinas * IRQs enabled, FIQs enabled. 5901da177e4SLinus Torvalds */ 591cb170a45SPaul Brook @ 592cb170a45SPaul Brook @ Fall-through from Thumb-2 __und_usr 593cb170a45SPaul Brook @ 594cb170a45SPaul Brook#ifdef CONFIG_NEON 595d3f79584SRussell King get_thread_info r10 @ get current thread 596cb170a45SPaul Brook adr r6, .LCneon_thumb_opcodes 597cb170a45SPaul Brook b 2f 598cb170a45SPaul Brook#endif 5991da177e4SLinus Torvaldscall_fpe: 600d3f79584SRussell King get_thread_info r10 @ get current thread 601b5872db4SCatalin Marinas#ifdef CONFIG_NEON 602cb170a45SPaul Brook adr r6, .LCneon_arm_opcodes 603d3f79584SRussell King2: ldr r5, [r6], #4 @ mask value 604b5872db4SCatalin Marinas ldr r7, [r6], #4 @ opcode bits matching in mask 605d3f79584SRussell King cmp r5, #0 @ end mask? 606d3f79584SRussell King beq 1f 607d3f79584SRussell King and r8, r0, r5 608b5872db4SCatalin Marinas cmp r8, r7 @ NEON instruction? 609b5872db4SCatalin Marinas bne 2b 610b5872db4SCatalin Marinas mov r7, #1 611b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used 612b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used 613b5872db4SCatalin Marinas b do_vfp @ let VFP handler handle this 614b5872db4SCatalin Marinas1: 615b5872db4SCatalin Marinas#endif 6161da177e4SLinus Torvalds tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27 617cb170a45SPaul Brook tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2 6186ebbf2ceSRussell King reteq lr 6191da177e4SLinus Torvalds and r8, r0, #0x00000f00 @ mask out CP number 6201da177e4SLinus Torvalds mov r7, #1 6218536a5efSArd Biesheuvel add r6, r10, r8, lsr #8 @ add used_cp[] array offset first 6228536a5efSArd Biesheuvel strb r7, [r6, #TI_USED_CP] @ set appropriate used_cp[] 6231da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT 6241da177e4SLinus Torvalds @ Test if we need to give access to iWMMXt coprocessors 6251da177e4SLinus Torvalds ldr r5, [r10, #TI_FLAGS] 6261da177e4SLinus Torvalds rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only 627e44fc388SStefan Agner movscs r7, r5, lsr #(TIF_USING_IWMMXT + 1) 6281da177e4SLinus Torvalds bcs iwmmxt_task_enable 6291da177e4SLinus Torvalds#endif 630b86040a5SCatalin Marinas ARM( add pc, pc, r8, lsr #6 ) 6318536a5efSArd Biesheuvel THUMB( lsr r8, r8, #6 ) 632b86040a5SCatalin Marinas THUMB( add pc, r8 ) 633b86040a5SCatalin Marinas nop 6341da177e4SLinus Torvalds 6356ebbf2ceSRussell King ret.w lr @ CP#0 636b86040a5SCatalin Marinas W(b) do_fpe @ CP#1 (FPE) 637b86040a5SCatalin Marinas W(b) do_fpe @ CP#2 (FPE) 6386ebbf2ceSRussell King ret.w lr @ CP#3 6396ebbf2ceSRussell King ret.w lr @ CP#4 6406ebbf2ceSRussell King ret.w lr @ CP#5 6416ebbf2ceSRussell King ret.w lr @ CP#6 6426ebbf2ceSRussell King ret.w lr @ CP#7 6436ebbf2ceSRussell King ret.w lr @ CP#8 6446ebbf2ceSRussell King ret.w lr @ CP#9 6451da177e4SLinus Torvalds#ifdef CONFIG_VFP 646b86040a5SCatalin Marinas W(b) do_vfp @ CP#10 (VFP) 647b86040a5SCatalin Marinas W(b) do_vfp @ CP#11 (VFP) 6481da177e4SLinus Torvalds#else 6496ebbf2ceSRussell King ret.w lr @ CP#10 (VFP) 6506ebbf2ceSRussell King ret.w lr @ CP#11 (VFP) 6511da177e4SLinus Torvalds#endif 6526ebbf2ceSRussell King ret.w lr @ CP#12 6536ebbf2ceSRussell King ret.w lr @ CP#13 6546ebbf2ceSRussell King ret.w lr @ CP#14 (Debug) 6556ebbf2ceSRussell King ret.w lr @ CP#15 (Control) 6561da177e4SLinus Torvalds 657ef4c5368SDave Martin#ifdef NEED_CPU_ARCHITECTURE 658ef4c5368SDave Martin .align 2 659ef4c5368SDave Martin.LCcpu_architecture: 660ef4c5368SDave Martin .word __cpu_architecture 661ef4c5368SDave Martin#endif 662ef4c5368SDave Martin 663b5872db4SCatalin Marinas#ifdef CONFIG_NEON 664b5872db4SCatalin Marinas .align 6 665b5872db4SCatalin Marinas 666cb170a45SPaul Brook.LCneon_arm_opcodes: 667b5872db4SCatalin Marinas .word 0xfe000000 @ mask 668b5872db4SCatalin Marinas .word 0xf2000000 @ opcode 669b5872db4SCatalin Marinas 670b5872db4SCatalin Marinas .word 0xff100000 @ mask 671b5872db4SCatalin Marinas .word 0xf4000000 @ opcode 672b5872db4SCatalin Marinas 673b5872db4SCatalin Marinas .word 0x00000000 @ mask 674b5872db4SCatalin Marinas .word 0x00000000 @ opcode 675cb170a45SPaul Brook 676cb170a45SPaul Brook.LCneon_thumb_opcodes: 677cb170a45SPaul Brook .word 0xef000000 @ mask 678cb170a45SPaul Brook .word 0xef000000 @ opcode 679cb170a45SPaul Brook 680cb170a45SPaul Brook .word 0xff100000 @ mask 681cb170a45SPaul Brook .word 0xf9000000 @ opcode 682cb170a45SPaul Brook 683cb170a45SPaul Brook .word 0x00000000 @ mask 684cb170a45SPaul Brook .word 0x00000000 @ opcode 685b5872db4SCatalin Marinas#endif 686b5872db4SCatalin Marinas 6871da177e4SLinus Torvaldsdo_fpe: 6881da177e4SLinus Torvalds ldr r4, .LCfp 6891da177e4SLinus Torvalds add r10, r10, #TI_FPSTATE @ r10 = workspace 6901da177e4SLinus Torvalds ldr pc, [r4] @ Call FP module USR entry point 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds/* 6931da177e4SLinus Torvalds * The FP module is called with these registers set: 6941da177e4SLinus Torvalds * r0 = instruction 6951da177e4SLinus Torvalds * r2 = PC+4 6961da177e4SLinus Torvalds * r9 = normal "successful" return address 6971da177e4SLinus Torvalds * r10 = FP workspace 6981da177e4SLinus Torvalds * lr = unrecognised FP instruction return address 6991da177e4SLinus Torvalds */ 7001da177e4SLinus Torvalds 701124efc27SSantosh Shilimkar .pushsection .data 7021abd3502SRussell King .align 2 7031da177e4SLinus TorvaldsENTRY(fp_enter) 704db6ccbb6SRussell King .word no_fp 705124efc27SSantosh Shilimkar .popsection 7061da177e4SLinus Torvalds 70783e686eaSCatalin MarinasENTRY(no_fp) 7086ebbf2ceSRussell King ret lr 70983e686eaSCatalin MarinasENDPROC(no_fp) 710db6ccbb6SRussell King 71115ac49b6SRussell King__und_usr_fault_32: 71215ac49b6SRussell King mov r1, #4 71315ac49b6SRussell King b 1f 7142190fed6SRussell King__und_usr_fault_16_pan: 7152190fed6SRussell King uaccess_disable ip 71615ac49b6SRussell King__und_usr_fault_16: 71715ac49b6SRussell King mov r1, #2 7181417a6b8SCatalin Marinas1: mov r0, sp 71914327c66SRussell King badr lr, ret_from_exception 72015ac49b6SRussell King b __und_fault 72115ac49b6SRussell KingENDPROC(__und_usr_fault_32) 72215ac49b6SRussell KingENDPROC(__und_usr_fault_16) 7231da177e4SLinus Torvalds 7241da177e4SLinus Torvalds .align 5 7251da177e4SLinus Torvalds__pabt_usr: 726ccea7a19SRussell King usr_entry 7274fb28474SKirill A. Shutemov mov r2, sp @ regs 7288dfe7ac9SRussell King pabt_helper 729c4c5716eSCatalin Marinas UNWIND(.fnend ) 7301da177e4SLinus Torvalds /* fall through */ 7311da177e4SLinus Torvalds/* 7321da177e4SLinus Torvalds * This is the return code to user mode for abort handlers 7331da177e4SLinus Torvalds */ 7341da177e4SLinus TorvaldsENTRY(ret_from_exception) 735c4c5716eSCatalin Marinas UNWIND(.fnstart ) 736c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 7371da177e4SLinus Torvalds get_thread_info tsk 7381da177e4SLinus Torvalds mov why, #0 7391da177e4SLinus Torvalds b ret_to_user 740c4c5716eSCatalin Marinas UNWIND(.fnend ) 74193ed3970SCatalin MarinasENDPROC(__pabt_usr) 74293ed3970SCatalin MarinasENDPROC(ret_from_exception) 7431da177e4SLinus Torvalds 744c0e7f7eeSDaniel Thompson .align 5 745c0e7f7eeSDaniel Thompson__fiq_usr: 746c0e7f7eeSDaniel Thompson usr_entry trace=0 747c0e7f7eeSDaniel Thompson kuser_cmpxchg_check 748c0e7f7eeSDaniel Thompson mov r0, sp @ struct pt_regs *regs 749c0e7f7eeSDaniel Thompson bl handle_fiq_as_nmi 750c0e7f7eeSDaniel Thompson get_thread_info tsk 751c0e7f7eeSDaniel Thompson restore_user_regs fast = 0, offset = 0 752c0e7f7eeSDaniel Thompson UNWIND(.fnend ) 753c0e7f7eeSDaniel ThompsonENDPROC(__fiq_usr) 754c0e7f7eeSDaniel Thompson 7551da177e4SLinus Torvalds/* 7561da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors 7571da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info 7581da177e4SLinus Torvalds * previous and next are guaranteed not to be the same. 7591da177e4SLinus Torvalds */ 7601da177e4SLinus TorvaldsENTRY(__switch_to) 761c4c5716eSCatalin Marinas UNWIND(.fnstart ) 762c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 7631da177e4SLinus Torvalds add ip, r1, #TI_CPU_SAVE 764b86040a5SCatalin Marinas ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack 765b86040a5SCatalin Marinas THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack 766b86040a5SCatalin Marinas THUMB( str sp, [ip], #4 ) 767b86040a5SCatalin Marinas THUMB( str lr, [ip], #4 ) 768a4780adeSAndré Hentschel ldr r4, [r2, #TI_TP_VALUE] 769a4780adeSAndré Hentschel ldr r5, [r2, #TI_TP_VALUE + 4] 770247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 7711eef5d2fSRussell King mrc p15, 0, r6, c3, c0, 0 @ Get domain register 7721eef5d2fSRussell King str r6, [r1, #TI_CPU_DOMAIN] @ Save old domain register 773d6551e88SRussell King ldr r6, [r2, #TI_CPU_DOMAIN] 774afeb90caSHyok S. Choi#endif 775a4780adeSAndré Hentschel switch_tls r1, r4, r5, r3, r7 776831a469bSArd Biesheuvel#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) && \ 777831a469bSArd Biesheuvel !defined(CONFIG_STACKPROTECTOR_PER_TASK) 778df0698beSNicolas Pitre ldr r8, =__stack_chk_guard 779ffa47aa6SArnd Bergmann .if (TSK_STACK_CANARY > IMM12_MASK) 7809c46929eSArd Biesheuvel add r9, r2, #TSK_STACK_CANARY & ~IMM12_MASK 781831a469bSArd Biesheuvel ldr r9, [r9, #TSK_STACK_CANARY & IMM12_MASK] 7829c46929eSArd Biesheuvel .else 7839c46929eSArd Biesheuvel ldr r9, [r2, #TSK_STACK_CANARY & IMM12_MASK] 784ffa47aa6SArnd Bergmann .endif 785df0698beSNicolas Pitre#endif 786831a469bSArd Biesheuvel mov r7, r2 @ Preserve 'next' 787247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 7881da177e4SLinus Torvalds mcr p15, 0, r6, c3, c0, 0 @ Set domain register 789afeb90caSHyok S. Choi#endif 790d6551e88SRussell King mov r5, r0 791d6551e88SRussell King add r4, r2, #TI_CPU_SAVE 792d6551e88SRussell King ldr r0, =thread_notify_head 793d6551e88SRussell King mov r1, #THREAD_NOTIFY_SWITCH 794d6551e88SRussell King bl atomic_notifier_call_chain 795831a469bSArd Biesheuvel#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) && \ 796831a469bSArd Biesheuvel !defined(CONFIG_STACKPROTECTOR_PER_TASK) 797831a469bSArd Biesheuvel str r9, [r8] 798df0698beSNicolas Pitre#endif 799d6551e88SRussell King mov r0, r5 800a1c510d0SArd Biesheuvel#if !defined(CONFIG_THUMB2_KERNEL) && !defined(CONFIG_VMAP_STACK) 8019c46929eSArd Biesheuvel set_current r7, r8 802b832faecSArd Biesheuvel ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously 803b832faecSArd Biesheuvel#else 804b832faecSArd Biesheuvel mov r1, r7 805b832faecSArd Biesheuvel ldmia r4, {r4 - sl, fp, ip, lr} @ Load all regs saved previously 806a1c510d0SArd Biesheuvel#ifdef CONFIG_VMAP_STACK 807a1c510d0SArd Biesheuvel @ 808a1c510d0SArd Biesheuvel @ Do a dummy read from the new stack while running from the old one so 809a1c510d0SArd Biesheuvel @ that we can rely on do_translation_fault() to fix up any stale PMD 810a1c510d0SArd Biesheuvel @ entries covering the vmalloc region. 811a1c510d0SArd Biesheuvel @ 812a1c510d0SArd Biesheuvel ldr r2, [ip] 813a1c510d0SArd Biesheuvel#endif 814b832faecSArd Biesheuvel 815b832faecSArd Biesheuvel @ When CONFIG_THREAD_INFO_IN_TASK=n, the update of SP itself is what 816b832faecSArd Biesheuvel @ effectuates the task switch, as that is what causes the observable 817b832faecSArd Biesheuvel @ values of current and current_thread_info to change. When 818b832faecSArd Biesheuvel @ CONFIG_THREAD_INFO_IN_TASK=y, setting current (and therefore 819b832faecSArd Biesheuvel @ current_thread_info) is done explicitly, and the update of SP just 820b832faecSArd Biesheuvel @ switches us to another stack, with few other side effects. In order 821b832faecSArd Biesheuvel @ to prevent this distinction from causing any inconsistencies, let's 822b832faecSArd Biesheuvel @ keep the 'set_current' call as close as we can to the update of SP. 8239c46929eSArd Biesheuvel set_current r1, r2 824b832faecSArd Biesheuvel mov sp, ip 825b832faecSArd Biesheuvel ret lr 826b832faecSArd Biesheuvel#endif 827c4c5716eSCatalin Marinas UNWIND(.fnend ) 82893ed3970SCatalin MarinasENDPROC(__switch_to) 8291da177e4SLinus Torvalds 830a1c510d0SArd Biesheuvel#ifdef CONFIG_VMAP_STACK 831a1c510d0SArd Biesheuvel .text 832a1c510d0SArd Biesheuvel .align 2 833a1c510d0SArd Biesheuvel__bad_stack: 834a1c510d0SArd Biesheuvel @ 835a1c510d0SArd Biesheuvel @ We've just detected an overflow. We need to load the address of this 836a1c510d0SArd Biesheuvel @ CPU's overflow stack into the stack pointer register. We have only one 837a1c510d0SArd Biesheuvel @ scratch register so let's use a sequence of ADDs including one 838a1c510d0SArd Biesheuvel @ involving the PC, and decorate them with PC-relative group 839a1c510d0SArd Biesheuvel @ relocations. As these are ARM only, switch to ARM mode first. 840a1c510d0SArd Biesheuvel @ 841a1c510d0SArd Biesheuvel @ We enter here with IP clobbered and its value stashed on the mode 842a1c510d0SArd Biesheuvel @ stack. 843a1c510d0SArd Biesheuvel @ 844a1c510d0SArd BiesheuvelTHUMB( bx pc ) 845a1c510d0SArd BiesheuvelTHUMB( nop ) 846a1c510d0SArd BiesheuvelTHUMB( .arm ) 8477b9896c3SArd Biesheuvel ldr_this_cpu_armv6 ip, overflow_stack_ptr 848a1c510d0SArd Biesheuvel 849a1c510d0SArd Biesheuvel str sp, [ip, #-4]! @ Preserve original SP value 850a1c510d0SArd Biesheuvel mov sp, ip @ Switch to overflow stack 851a1c510d0SArd Biesheuvel pop {ip} @ Original SP in IP 852a1c510d0SArd Biesheuvel 853a1c510d0SArd Biesheuvel#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) 854a1c510d0SArd Biesheuvel mov ip, ip @ mov expected by unwinder 855a1c510d0SArd Biesheuvel push {fp, ip, lr, pc} @ GCC flavor frame record 856a1c510d0SArd Biesheuvel#else 857a1c510d0SArd Biesheuvel str ip, [sp, #-8]! @ store original SP 858a1c510d0SArd Biesheuvel push {fpreg, lr} @ Clang flavor frame record 859a1c510d0SArd Biesheuvel#endif 860a1c510d0SArd BiesheuvelUNWIND( ldr ip, [r0, #4] ) @ load exception LR 861a1c510d0SArd BiesheuvelUNWIND( str ip, [sp, #12] ) @ store in the frame record 862a1c510d0SArd Biesheuvel ldr ip, [r0, #12] @ reload IP 863a1c510d0SArd Biesheuvel 864a1c510d0SArd Biesheuvel @ Store the original GPRs to the new stack. 865a1c510d0SArd Biesheuvel svc_entry uaccess=0, overflow_check=0 866a1c510d0SArd Biesheuvel 867a1c510d0SArd BiesheuvelUNWIND( .save {sp, pc} ) 868a1c510d0SArd BiesheuvelUNWIND( .save {fpreg, lr} ) 869a1c510d0SArd BiesheuvelUNWIND( .setfp fpreg, sp ) 870a1c510d0SArd Biesheuvel 871a1c510d0SArd Biesheuvel ldr fpreg, [sp, #S_SP] @ Add our frame record 872a1c510d0SArd Biesheuvel @ to the linked list 873a1c510d0SArd Biesheuvel#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) 874a1c510d0SArd Biesheuvel ldr r1, [fp, #4] @ reload SP at entry 875a1c510d0SArd Biesheuvel add fp, fp, #12 876a1c510d0SArd Biesheuvel#else 877a1c510d0SArd Biesheuvel ldr r1, [fpreg, #8] 878a1c510d0SArd Biesheuvel#endif 879a1c510d0SArd Biesheuvel str r1, [sp, #S_SP] @ store in pt_regs 880a1c510d0SArd Biesheuvel 881a1c510d0SArd Biesheuvel @ Stash the regs for handle_bad_stack 882a1c510d0SArd Biesheuvel mov r0, sp 883a1c510d0SArd Biesheuvel 884a1c510d0SArd Biesheuvel @ Time to die 885a1c510d0SArd Biesheuvel bl handle_bad_stack 886a1c510d0SArd Biesheuvel nop 887a1c510d0SArd BiesheuvelUNWIND( .fnend ) 888a1c510d0SArd BiesheuvelENDPROC(__bad_stack) 889a1c510d0SArd Biesheuvel#endif 890a1c510d0SArd Biesheuvel 8911da177e4SLinus Torvalds __INIT 8922d2669b6SNicolas Pitre 8932d2669b6SNicolas Pitre/* 8942d2669b6SNicolas Pitre * User helpers. 8952d2669b6SNicolas Pitre * 8962d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high 8972d2669b6SNicolas Pitre * vector page. New segments (if ever needed) must be added in front of 8982d2669b6SNicolas Pitre * existing ones. This mechanism should be used only for things that are 8992d2669b6SNicolas Pitre * really small and justified, and not be abused freely. 9002d2669b6SNicolas Pitre * 901dc7a12bdSMauro Carvalho Chehab * See Documentation/arm/kernel_user_helpers.rst for formal definitions. 9022d2669b6SNicolas Pitre */ 903b86040a5SCatalin Marinas THUMB( .arm ) 9042d2669b6SNicolas Pitre 905ba9b5d76SNicolas Pitre .macro usr_ret, reg 906ba9b5d76SNicolas Pitre#ifdef CONFIG_ARM_THUMB 907ba9b5d76SNicolas Pitre bx \reg 908ba9b5d76SNicolas Pitre#else 9096ebbf2ceSRussell King ret \reg 910ba9b5d76SNicolas Pitre#endif 911ba9b5d76SNicolas Pitre .endm 912ba9b5d76SNicolas Pitre 9135b43e7a3SRussell King .macro kuser_pad, sym, size 9145b43e7a3SRussell King .if (. - \sym) & 3 9155b43e7a3SRussell King .rept 4 - (. - \sym) & 3 9165b43e7a3SRussell King .byte 0 9175b43e7a3SRussell King .endr 9185b43e7a3SRussell King .endif 9195b43e7a3SRussell King .rept (\size - (. - \sym)) / 4 9205b43e7a3SRussell King .word 0xe7fddef1 9215b43e7a3SRussell King .endr 9225b43e7a3SRussell King .endm 9235b43e7a3SRussell King 924f6f91b0dSRussell King#ifdef CONFIG_KUSER_HELPERS 9252d2669b6SNicolas Pitre .align 5 9262d2669b6SNicolas Pitre .globl __kuser_helper_start 9272d2669b6SNicolas Pitre__kuser_helper_start: 9282d2669b6SNicolas Pitre 9292d2669b6SNicolas Pitre/* 93040fb79c8SNicolas Pitre * Due to the length of some sequences, __kuser_cmpxchg64 spans 2 regular 93140fb79c8SNicolas Pitre * kuser "slots", therefore 0xffff0f80 is not used as a valid entry point. 9327c612bfdSNicolas Pitre */ 9337c612bfdSNicolas Pitre 93440fb79c8SNicolas Pitre__kuser_cmpxchg64: @ 0xffff0f60 93540fb79c8SNicolas Pitre 936db695c05SRussell King#if defined(CONFIG_CPU_32v6K) 93740fb79c8SNicolas Pitre 93840fb79c8SNicolas Pitre stmfd sp!, {r4, r5, r6, r7} 93940fb79c8SNicolas Pitre ldrd r4, r5, [r0] @ load old val 94040fb79c8SNicolas Pitre ldrd r6, r7, [r1] @ load new val 94140fb79c8SNicolas Pitre smp_dmb arm 94240fb79c8SNicolas Pitre1: ldrexd r0, r1, [r2] @ load current val 94340fb79c8SNicolas Pitre eors r3, r0, r4 @ compare with oldval (1) 944e44fc388SStefan Agner eorseq r3, r1, r5 @ compare with oldval (2) 94540fb79c8SNicolas Pitre strexdeq r3, r6, r7, [r2] @ store newval if eq 94640fb79c8SNicolas Pitre teqeq r3, #1 @ success? 94740fb79c8SNicolas Pitre beq 1b @ if no then retry 94840fb79c8SNicolas Pitre smp_dmb arm 94940fb79c8SNicolas Pitre rsbs r0, r3, #0 @ set returned val and C flag 95040fb79c8SNicolas Pitre ldmfd sp!, {r4, r5, r6, r7} 9515a97d0aeSWill Deacon usr_ret lr 95240fb79c8SNicolas Pitre 95340fb79c8SNicolas Pitre#elif !defined(CONFIG_SMP) 95440fb79c8SNicolas Pitre 95540fb79c8SNicolas Pitre#ifdef CONFIG_MMU 95640fb79c8SNicolas Pitre 95740fb79c8SNicolas Pitre /* 95840fb79c8SNicolas Pitre * The only thing that can break atomicity in this cmpxchg64 95940fb79c8SNicolas Pitre * implementation is either an IRQ or a data abort exception 96040fb79c8SNicolas Pitre * causing another process/thread to be scheduled in the middle of 96140fb79c8SNicolas Pitre * the critical sequence. The same strategy as for cmpxchg is used. 96240fb79c8SNicolas Pitre */ 96340fb79c8SNicolas Pitre stmfd sp!, {r4, r5, r6, lr} 96440fb79c8SNicolas Pitre ldmia r0, {r4, r5} @ load old val 96540fb79c8SNicolas Pitre ldmia r1, {r6, lr} @ load new val 96640fb79c8SNicolas Pitre1: ldmia r2, {r0, r1} @ load current val 96740fb79c8SNicolas Pitre eors r3, r0, r4 @ compare with oldval (1) 968e44fc388SStefan Agner eorseq r3, r1, r5 @ compare with oldval (2) 969e44fc388SStefan Agner2: stmiaeq r2, {r6, lr} @ store newval if eq 97040fb79c8SNicolas Pitre rsbs r0, r3, #0 @ set return val and C flag 97140fb79c8SNicolas Pitre ldmfd sp!, {r4, r5, r6, pc} 97240fb79c8SNicolas Pitre 97340fb79c8SNicolas Pitre .text 97440fb79c8SNicolas Pitrekuser_cmpxchg64_fixup: 97540fb79c8SNicolas Pitre @ Called from kuser_cmpxchg_fixup. 9763ad55155SRussell King @ r4 = address of interrupted insn (must be preserved). 97740fb79c8SNicolas Pitre @ sp = saved regs. r7 and r8 are clobbered. 97840fb79c8SNicolas Pitre @ 1b = first critical insn, 2b = last critical insn. 9793ad55155SRussell King @ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b. 98040fb79c8SNicolas Pitre mov r7, #0xffff0fff 98140fb79c8SNicolas Pitre sub r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64))) 9823ad55155SRussell King subs r8, r4, r7 983e44fc388SStefan Agner rsbscs r8, r8, #(2b - 1b) 98440fb79c8SNicolas Pitre strcs r7, [sp, #S_PC] 98540fb79c8SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6 98640fb79c8SNicolas Pitre bcc kuser_cmpxchg32_fixup 98740fb79c8SNicolas Pitre#endif 9886ebbf2ceSRussell King ret lr 98940fb79c8SNicolas Pitre .previous 99040fb79c8SNicolas Pitre 99140fb79c8SNicolas Pitre#else 99240fb79c8SNicolas Pitre#warning "NPTL on non MMU needs fixing" 99340fb79c8SNicolas Pitre mov r0, #-1 99440fb79c8SNicolas Pitre adds r0, r0, #0 99540fb79c8SNicolas Pitre usr_ret lr 99640fb79c8SNicolas Pitre#endif 99740fb79c8SNicolas Pitre 99840fb79c8SNicolas Pitre#else 99940fb79c8SNicolas Pitre#error "incoherent kernel configuration" 100040fb79c8SNicolas Pitre#endif 100140fb79c8SNicolas Pitre 10025b43e7a3SRussell King kuser_pad __kuser_cmpxchg64, 64 100340fb79c8SNicolas Pitre 10047c612bfdSNicolas Pitre__kuser_memory_barrier: @ 0xffff0fa0 1005ed3768a8SDave Martin smp_dmb arm 1006ba9b5d76SNicolas Pitre usr_ret lr 10077c612bfdSNicolas Pitre 10085b43e7a3SRussell King kuser_pad __kuser_memory_barrier, 32 10097c612bfdSNicolas Pitre 10102d2669b6SNicolas Pitre__kuser_cmpxchg: @ 0xffff0fc0 10112d2669b6SNicolas Pitre 1012db695c05SRussell King#if __LINUX_ARM_ARCH__ < 6 10132d2669b6SNicolas Pitre 101449bca4c2SNicolas Pitre#ifdef CONFIG_MMU 1015b49c0f24SNicolas Pitre 1016b49c0f24SNicolas Pitre /* 1017b49c0f24SNicolas Pitre * The only thing that can break atomicity in this cmpxchg 1018b49c0f24SNicolas Pitre * implementation is either an IRQ or a data abort exception 1019b49c0f24SNicolas Pitre * causing another process/thread to be scheduled in the middle 1020b49c0f24SNicolas Pitre * of the critical sequence. To prevent this, code is added to 1021b49c0f24SNicolas Pitre * the IRQ and data abort exception handlers to set the pc back 1022b49c0f24SNicolas Pitre * to the beginning of the critical section if it is found to be 1023b49c0f24SNicolas Pitre * within that critical section (see kuser_cmpxchg_fixup). 1024b49c0f24SNicolas Pitre */ 1025b49c0f24SNicolas Pitre1: ldr r3, [r2] @ load current val 1026b49c0f24SNicolas Pitre subs r3, r3, r0 @ compare with oldval 1027b49c0f24SNicolas Pitre2: streq r1, [r2] @ store newval if eq 1028b49c0f24SNicolas Pitre rsbs r0, r3, #0 @ set return val and C flag 1029b49c0f24SNicolas Pitre usr_ret lr 1030b49c0f24SNicolas Pitre 1031b49c0f24SNicolas Pitre .text 103240fb79c8SNicolas Pitrekuser_cmpxchg32_fixup: 1033b49c0f24SNicolas Pitre @ Called from kuser_cmpxchg_check macro. 1034b059bdc3SRussell King @ r4 = address of interrupted insn (must be preserved). 1035b49c0f24SNicolas Pitre @ sp = saved regs. r7 and r8 are clobbered. 1036b49c0f24SNicolas Pitre @ 1b = first critical insn, 2b = last critical insn. 1037b059bdc3SRussell King @ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b. 1038b49c0f24SNicolas Pitre mov r7, #0xffff0fff 1039b49c0f24SNicolas Pitre sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg))) 1040b059bdc3SRussell King subs r8, r4, r7 1041e44fc388SStefan Agner rsbscs r8, r8, #(2b - 1b) 1042b49c0f24SNicolas Pitre strcs r7, [sp, #S_PC] 10436ebbf2ceSRussell King ret lr 1044b49c0f24SNicolas Pitre .previous 1045b49c0f24SNicolas Pitre 104649bca4c2SNicolas Pitre#else 104749bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing" 104849bca4c2SNicolas Pitre mov r0, #-1 104949bca4c2SNicolas Pitre adds r0, r0, #0 1050ba9b5d76SNicolas Pitre usr_ret lr 1051b49c0f24SNicolas Pitre#endif 10522d2669b6SNicolas Pitre 10532d2669b6SNicolas Pitre#else 10542d2669b6SNicolas Pitre 1055ed3768a8SDave Martin smp_dmb arm 1056b49c0f24SNicolas Pitre1: ldrex r3, [r2] 10572d2669b6SNicolas Pitre subs r3, r3, r0 10582d2669b6SNicolas Pitre strexeq r3, r1, [r2] 1059b49c0f24SNicolas Pitre teqeq r3, #1 1060b49c0f24SNicolas Pitre beq 1b 10612d2669b6SNicolas Pitre rsbs r0, r3, #0 1062b49c0f24SNicolas Pitre /* beware -- each __kuser slot must be 8 instructions max */ 1063f00ec48fSRussell King ALT_SMP(b __kuser_memory_barrier) 1064f00ec48fSRussell King ALT_UP(usr_ret lr) 10652d2669b6SNicolas Pitre 10662d2669b6SNicolas Pitre#endif 10672d2669b6SNicolas Pitre 10685b43e7a3SRussell King kuser_pad __kuser_cmpxchg, 32 10692d2669b6SNicolas Pitre 10702d2669b6SNicolas Pitre__kuser_get_tls: @ 0xffff0fe0 1071f159f4edSTony Lindgren ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init 1072ba9b5d76SNicolas Pitre usr_ret lr 1073f159f4edSTony Lindgren mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code 10745b43e7a3SRussell King kuser_pad __kuser_get_tls, 16 10755b43e7a3SRussell King .rep 3 1076f159f4edSTony Lindgren .word 0 @ 0xffff0ff0 software TLS value, then 1077f159f4edSTony Lindgren .endr @ pad up to __kuser_helper_version 10782d2669b6SNicolas Pitre 10792d2669b6SNicolas Pitre__kuser_helper_version: @ 0xffff0ffc 10802d2669b6SNicolas Pitre .word ((__kuser_helper_end - __kuser_helper_start) >> 5) 10812d2669b6SNicolas Pitre 10822d2669b6SNicolas Pitre .globl __kuser_helper_end 10832d2669b6SNicolas Pitre__kuser_helper_end: 10842d2669b6SNicolas Pitre 1085f6f91b0dSRussell King#endif 1086f6f91b0dSRussell King 1087b86040a5SCatalin Marinas THUMB( .thumb ) 10882d2669b6SNicolas Pitre 10891da177e4SLinus Torvalds/* 10901da177e4SLinus Torvalds * Vector stubs. 10911da177e4SLinus Torvalds * 109219accfd3SRussell King * This code is copied to 0xffff1000 so we can use branches in the 109319accfd3SRussell King * vectors, rather than ldr's. Note that this code must not exceed 109419accfd3SRussell King * a page size. 10951da177e4SLinus Torvalds * 10961da177e4SLinus Torvalds * Common stub entry macro: 10971da177e4SLinus Torvalds * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 1098ccea7a19SRussell King * 1099ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address 1100ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler. 11011da177e4SLinus Torvalds */ 1102b7ec4795SNicolas Pitre .macro vector_stub, name, mode, correction=0 11031da177e4SLinus Torvalds .align 5 11041da177e4SLinus Torvalds 11051da177e4SLinus Torvaldsvector_\name: 11061da177e4SLinus Torvalds .if \correction 11071da177e4SLinus Torvalds sub lr, lr, #\correction 11081da177e4SLinus Torvalds .endif 11091da177e4SLinus Torvalds 1110b9baf5c8SRussell King (Oracle) @ Save r0, lr_<exception> (parent PC) 1111ccea7a19SRussell King stmia sp, {r0, lr} @ save r0, lr 1112b9baf5c8SRussell King (Oracle) 1113b9baf5c8SRussell King (Oracle) @ Save spsr_<exception> (parent CPSR) 1114b9baf5c8SRussell King (Oracle)2: mrs lr, spsr 1115ccea7a19SRussell King str lr, [sp, #8] @ save spsr 1116ccea7a19SRussell King 1117ccea7a19SRussell King @ 1118ccea7a19SRussell King @ Prepare for SVC32 mode. IRQs remain disabled. 1119ccea7a19SRussell King @ 1120ccea7a19SRussell King mrs r0, cpsr 1121b86040a5SCatalin Marinas eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE) 1122ccea7a19SRussell King msr spsr_cxsf, r0 1123ccea7a19SRussell King 1124ccea7a19SRussell King @ 1125ccea7a19SRussell King @ the branch table must immediately follow this code 1126ccea7a19SRussell King @ 1127ccea7a19SRussell King and lr, lr, #0x0f 1128b86040a5SCatalin Marinas THUMB( adr r0, 1f ) 1129b86040a5SCatalin Marinas THUMB( ldr lr, [r0, lr, lsl #2] ) 1130b7ec4795SNicolas Pitre mov r0, sp 1131b86040a5SCatalin Marinas ARM( ldr lr, [pc, lr, lsl #2] ) 1132ccea7a19SRussell King movs pc, lr @ branch to handler in SVC mode 113393ed3970SCatalin MarinasENDPROC(vector_\name) 113488987ef9SCatalin Marinas 1135b9baf5c8SRussell King (Oracle)#ifdef CONFIG_HARDEN_BRANCH_HISTORY 1136b9baf5c8SRussell King (Oracle) .subsection 1 1137b9baf5c8SRussell King (Oracle) .align 5 1138b9baf5c8SRussell King (Oracle)vector_bhb_loop8_\name: 1139b9baf5c8SRussell King (Oracle) .if \correction 1140b9baf5c8SRussell King (Oracle) sub lr, lr, #\correction 1141b9baf5c8SRussell King (Oracle) .endif 1142b9baf5c8SRussell King (Oracle) 1143b9baf5c8SRussell King (Oracle) @ Save r0, lr_<exception> (parent PC) 1144b9baf5c8SRussell King (Oracle) stmia sp, {r0, lr} 1145b9baf5c8SRussell King (Oracle) 1146b9baf5c8SRussell King (Oracle) @ bhb workaround 1147b9baf5c8SRussell King (Oracle) mov r0, #8 1148*3cfb3019SArd Biesheuvel3: W(b) . + 4 1149b9baf5c8SRussell King (Oracle) subs r0, r0, #1 11506c7cb60bSRussell King (Oracle) bne 3b 1151b9baf5c8SRussell King (Oracle) dsb 1152b9baf5c8SRussell King (Oracle) isb 1153b9baf5c8SRussell King (Oracle) b 2b 1154b9baf5c8SRussell King (Oracle)ENDPROC(vector_bhb_loop8_\name) 1155b9baf5c8SRussell King (Oracle) 1156b9baf5c8SRussell King (Oracle)vector_bhb_bpiall_\name: 1157b9baf5c8SRussell King (Oracle) .if \correction 1158b9baf5c8SRussell King (Oracle) sub lr, lr, #\correction 1159b9baf5c8SRussell King (Oracle) .endif 1160b9baf5c8SRussell King (Oracle) 1161b9baf5c8SRussell King (Oracle) @ Save r0, lr_<exception> (parent PC) 1162b9baf5c8SRussell King (Oracle) stmia sp, {r0, lr} 1163b9baf5c8SRussell King (Oracle) 1164b9baf5c8SRussell King (Oracle) @ bhb workaround 1165b9baf5c8SRussell King (Oracle) mcr p15, 0, r0, c7, c5, 6 @ BPIALL 1166b9baf5c8SRussell King (Oracle) @ isb not needed due to "movs pc, lr" in the vector stub 1167b9baf5c8SRussell King (Oracle) @ which gives a "context synchronisation". 1168b9baf5c8SRussell King (Oracle) b 2b 1169b9baf5c8SRussell King (Oracle)ENDPROC(vector_bhb_bpiall_\name) 1170b9baf5c8SRussell King (Oracle) .previous 1171b9baf5c8SRussell King (Oracle)#endif 1172b9baf5c8SRussell King (Oracle) 117388987ef9SCatalin Marinas .align 2 117488987ef9SCatalin Marinas @ handler addresses follow this label 117588987ef9SCatalin Marinas1: 11761da177e4SLinus Torvalds .endm 11771da177e4SLinus Torvalds 1178b9b32bf7SRussell King .section .stubs, "ax", %progbits 117919accfd3SRussell King @ This must be the first word 118019accfd3SRussell King .word vector_swi 1181b9baf5c8SRussell King (Oracle)#ifdef CONFIG_HARDEN_BRANCH_HISTORY 1182b9baf5c8SRussell King (Oracle) .word vector_bhb_loop8_swi 1183b9baf5c8SRussell King (Oracle) .word vector_bhb_bpiall_swi 1184b9baf5c8SRussell King (Oracle)#endif 118519accfd3SRussell King 118619accfd3SRussell Kingvector_rst: 118719accfd3SRussell King ARM( swi SYS_ERROR0 ) 118819accfd3SRussell King THUMB( svc #0 ) 118919accfd3SRussell King THUMB( nop ) 119019accfd3SRussell King b vector_und 119119accfd3SRussell King 11921da177e4SLinus Torvalds/* 11931da177e4SLinus Torvalds * Interrupt dispatcher 11941da177e4SLinus Torvalds */ 1195b7ec4795SNicolas Pitre vector_stub irq, IRQ_MODE, 4 11961da177e4SLinus Torvalds 11971da177e4SLinus Torvalds .long __irq_usr @ 0 (USR_26 / USR_32) 11981da177e4SLinus Torvalds .long __irq_invalid @ 1 (FIQ_26 / FIQ_32) 11991da177e4SLinus Torvalds .long __irq_invalid @ 2 (IRQ_26 / IRQ_32) 12001da177e4SLinus Torvalds .long __irq_svc @ 3 (SVC_26 / SVC_32) 12011da177e4SLinus Torvalds .long __irq_invalid @ 4 12021da177e4SLinus Torvalds .long __irq_invalid @ 5 12031da177e4SLinus Torvalds .long __irq_invalid @ 6 12041da177e4SLinus Torvalds .long __irq_invalid @ 7 12051da177e4SLinus Torvalds .long __irq_invalid @ 8 12061da177e4SLinus Torvalds .long __irq_invalid @ 9 12071da177e4SLinus Torvalds .long __irq_invalid @ a 12081da177e4SLinus Torvalds .long __irq_invalid @ b 12091da177e4SLinus Torvalds .long __irq_invalid @ c 12101da177e4SLinus Torvalds .long __irq_invalid @ d 12111da177e4SLinus Torvalds .long __irq_invalid @ e 12121da177e4SLinus Torvalds .long __irq_invalid @ f 12131da177e4SLinus Torvalds 12141da177e4SLinus Torvalds/* 12151da177e4SLinus Torvalds * Data abort dispatcher 12161da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 12171da177e4SLinus Torvalds */ 1218b7ec4795SNicolas Pitre vector_stub dabt, ABT_MODE, 8 12191da177e4SLinus Torvalds 12201da177e4SLinus Torvalds .long __dabt_usr @ 0 (USR_26 / USR_32) 12211da177e4SLinus Torvalds .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32) 12221da177e4SLinus Torvalds .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32) 12231da177e4SLinus Torvalds .long __dabt_svc @ 3 (SVC_26 / SVC_32) 12241da177e4SLinus Torvalds .long __dabt_invalid @ 4 12251da177e4SLinus Torvalds .long __dabt_invalid @ 5 12261da177e4SLinus Torvalds .long __dabt_invalid @ 6 12271da177e4SLinus Torvalds .long __dabt_invalid @ 7 12281da177e4SLinus Torvalds .long __dabt_invalid @ 8 12291da177e4SLinus Torvalds .long __dabt_invalid @ 9 12301da177e4SLinus Torvalds .long __dabt_invalid @ a 12311da177e4SLinus Torvalds .long __dabt_invalid @ b 12321da177e4SLinus Torvalds .long __dabt_invalid @ c 12331da177e4SLinus Torvalds .long __dabt_invalid @ d 12341da177e4SLinus Torvalds .long __dabt_invalid @ e 12351da177e4SLinus Torvalds .long __dabt_invalid @ f 12361da177e4SLinus Torvalds 12371da177e4SLinus Torvalds/* 12381da177e4SLinus Torvalds * Prefetch abort dispatcher 12391da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 12401da177e4SLinus Torvalds */ 1241b7ec4795SNicolas Pitre vector_stub pabt, ABT_MODE, 4 12421da177e4SLinus Torvalds 12431da177e4SLinus Torvalds .long __pabt_usr @ 0 (USR_26 / USR_32) 12441da177e4SLinus Torvalds .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32) 12451da177e4SLinus Torvalds .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32) 12461da177e4SLinus Torvalds .long __pabt_svc @ 3 (SVC_26 / SVC_32) 12471da177e4SLinus Torvalds .long __pabt_invalid @ 4 12481da177e4SLinus Torvalds .long __pabt_invalid @ 5 12491da177e4SLinus Torvalds .long __pabt_invalid @ 6 12501da177e4SLinus Torvalds .long __pabt_invalid @ 7 12511da177e4SLinus Torvalds .long __pabt_invalid @ 8 12521da177e4SLinus Torvalds .long __pabt_invalid @ 9 12531da177e4SLinus Torvalds .long __pabt_invalid @ a 12541da177e4SLinus Torvalds .long __pabt_invalid @ b 12551da177e4SLinus Torvalds .long __pabt_invalid @ c 12561da177e4SLinus Torvalds .long __pabt_invalid @ d 12571da177e4SLinus Torvalds .long __pabt_invalid @ e 12581da177e4SLinus Torvalds .long __pabt_invalid @ f 12591da177e4SLinus Torvalds 12601da177e4SLinus Torvalds/* 12611da177e4SLinus Torvalds * Undef instr entry dispatcher 12621da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 12631da177e4SLinus Torvalds */ 1264b7ec4795SNicolas Pitre vector_stub und, UND_MODE 12651da177e4SLinus Torvalds 12661da177e4SLinus Torvalds .long __und_usr @ 0 (USR_26 / USR_32) 12671da177e4SLinus Torvalds .long __und_invalid @ 1 (FIQ_26 / FIQ_32) 12681da177e4SLinus Torvalds .long __und_invalid @ 2 (IRQ_26 / IRQ_32) 12691da177e4SLinus Torvalds .long __und_svc @ 3 (SVC_26 / SVC_32) 12701da177e4SLinus Torvalds .long __und_invalid @ 4 12711da177e4SLinus Torvalds .long __und_invalid @ 5 12721da177e4SLinus Torvalds .long __und_invalid @ 6 12731da177e4SLinus Torvalds .long __und_invalid @ 7 12741da177e4SLinus Torvalds .long __und_invalid @ 8 12751da177e4SLinus Torvalds .long __und_invalid @ 9 12761da177e4SLinus Torvalds .long __und_invalid @ a 12771da177e4SLinus Torvalds .long __und_invalid @ b 12781da177e4SLinus Torvalds .long __und_invalid @ c 12791da177e4SLinus Torvalds .long __und_invalid @ d 12801da177e4SLinus Torvalds .long __und_invalid @ e 12811da177e4SLinus Torvalds .long __und_invalid @ f 12821da177e4SLinus Torvalds 12831da177e4SLinus Torvalds .align 5 12841da177e4SLinus Torvalds 12851da177e4SLinus Torvalds/*============================================================================= 128619accfd3SRussell King * Address exception handler 128719accfd3SRussell King *----------------------------------------------------------------------------- 128819accfd3SRussell King * These aren't too critical. 128919accfd3SRussell King * (they're not supposed to happen, and won't happen in 32-bit data mode). 129019accfd3SRussell King */ 129119accfd3SRussell King 129219accfd3SRussell Kingvector_addrexcptn: 129319accfd3SRussell King b vector_addrexcptn 129419accfd3SRussell King 129519accfd3SRussell King/*============================================================================= 1296c0e7f7eeSDaniel Thompson * FIQ "NMI" handler 12971da177e4SLinus Torvalds *----------------------------------------------------------------------------- 1298c0e7f7eeSDaniel Thompson * Handle a FIQ using the SVC stack allowing FIQ act like NMI on x86 1299b9baf5c8SRussell King (Oracle) * systems. This must be the last vector stub, so lets place it in its own 1300b9baf5c8SRussell King (Oracle) * subsection. 13011da177e4SLinus Torvalds */ 1302b9baf5c8SRussell King (Oracle) .subsection 2 1303c0e7f7eeSDaniel Thompson vector_stub fiq, FIQ_MODE, 4 1304c0e7f7eeSDaniel Thompson 1305c0e7f7eeSDaniel Thompson .long __fiq_usr @ 0 (USR_26 / USR_32) 1306c0e7f7eeSDaniel Thompson .long __fiq_svc @ 1 (FIQ_26 / FIQ_32) 1307c0e7f7eeSDaniel Thompson .long __fiq_svc @ 2 (IRQ_26 / IRQ_32) 1308c0e7f7eeSDaniel Thompson .long __fiq_svc @ 3 (SVC_26 / SVC_32) 1309c0e7f7eeSDaniel Thompson .long __fiq_svc @ 4 1310c0e7f7eeSDaniel Thompson .long __fiq_svc @ 5 1311c0e7f7eeSDaniel Thompson .long __fiq_svc @ 6 1312c0e7f7eeSDaniel Thompson .long __fiq_abt @ 7 1313c0e7f7eeSDaniel Thompson .long __fiq_svc @ 8 1314c0e7f7eeSDaniel Thompson .long __fiq_svc @ 9 1315c0e7f7eeSDaniel Thompson .long __fiq_svc @ a 1316c0e7f7eeSDaniel Thompson .long __fiq_svc @ b 1317c0e7f7eeSDaniel Thompson .long __fiq_svc @ c 1318c0e7f7eeSDaniel Thompson .long __fiq_svc @ d 1319c0e7f7eeSDaniel Thompson .long __fiq_svc @ e 1320c0e7f7eeSDaniel Thompson .long __fiq_svc @ f 13211da177e4SLinus Torvalds 132231b96caeSArd Biesheuvel .globl vector_fiq 1323e39e3f3eSRussell King 1324b9b32bf7SRussell King .section .vectors, "ax", %progbits 1325b48da558SArd Biesheuvel.L__vectors_start: 1326b9b32bf7SRussell King W(b) vector_rst 1327b9b32bf7SRussell King W(b) vector_und 1328b48da558SArd Biesheuvel W(ldr) pc, .L__vectors_start + 0x1000 1329b9b32bf7SRussell King W(b) vector_pabt 1330b9b32bf7SRussell King W(b) vector_dabt 1331b9b32bf7SRussell King W(b) vector_addrexcptn 1332b9b32bf7SRussell King W(b) vector_irq 1333b9b32bf7SRussell King W(b) vector_fiq 13341da177e4SLinus Torvalds 1335b9baf5c8SRussell King (Oracle)#ifdef CONFIG_HARDEN_BRANCH_HISTORY 1336b9baf5c8SRussell King (Oracle) .section .vectors.bhb.loop8, "ax", %progbits 1337b9baf5c8SRussell King (Oracle).L__vectors_bhb_loop8_start: 1338b9baf5c8SRussell King (Oracle) W(b) vector_rst 1339b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_und 1340b9baf5c8SRussell King (Oracle) W(ldr) pc, .L__vectors_bhb_loop8_start + 0x1004 1341b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_pabt 1342b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_dabt 1343b9baf5c8SRussell King (Oracle) W(b) vector_addrexcptn 1344b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_irq 1345b9baf5c8SRussell King (Oracle) W(b) vector_bhb_loop8_fiq 1346b9baf5c8SRussell King (Oracle) 1347b9baf5c8SRussell King (Oracle) .section .vectors.bhb.bpiall, "ax", %progbits 1348b9baf5c8SRussell King (Oracle).L__vectors_bhb_bpiall_start: 1349b9baf5c8SRussell King (Oracle) W(b) vector_rst 1350b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_und 1351b9baf5c8SRussell King (Oracle) W(ldr) pc, .L__vectors_bhb_bpiall_start + 0x1008 1352b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_pabt 1353b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_dabt 1354b9baf5c8SRussell King (Oracle) W(b) vector_addrexcptn 1355b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_irq 1356b9baf5c8SRussell King (Oracle) W(b) vector_bhb_bpiall_fiq 1357b9baf5c8SRussell King (Oracle)#endif 1358b9baf5c8SRussell King (Oracle) 13591da177e4SLinus Torvalds .data 13601abd3502SRussell King .align 2 13611da177e4SLinus Torvalds 13621da177e4SLinus Torvalds .globl cr_alignment 13631da177e4SLinus Torvaldscr_alignment: 13641da177e4SLinus Torvalds .space 4 1365