11da177e4SLinus Torvalds/* 21da177e4SLinus Torvalds * linux/arch/arm/kernel/entry-armv.S 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1996,1997,1998 Russell King. 51da177e4SLinus Torvalds * ARM700 fix by Matthew Godbolt (linux-user@willothewisp.demon.co.uk) 6afeb90caSHyok S. Choi * nommu support by Hyok S. Choi (hyok.choi@samsung.com) 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 91da177e4SLinus Torvalds * it under the terms of the GNU General Public License version 2 as 101da177e4SLinus Torvalds * published by the Free Software Foundation. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Low-level vector interface routines 131da177e4SLinus Torvalds * 1470b6f2b4SNicolas Pitre * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction 1570b6f2b4SNicolas Pitre * that causes it to save wrong values... Be aware! 161da177e4SLinus Torvalds */ 171da177e4SLinus Torvalds 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> 22a09e64fbSRussell King#include <mach/entry-macro.S> 23d6551e88SRussell King#include <asm/thread_notify.h> 24c4c5716eSCatalin Marinas#include <asm/unwind.h> 25cc20d429SRussell King#include <asm/unistd.h> 26f159f4edSTony Lindgren#include <asm/tls.h> 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds#include "entry-header.S" 29cd544ce7SMagnus Damm#include <asm/entry-macro-multi.S> 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds/* 32187a51adSRussell King * Interrupt handling. Preserves r7, r8, r9 33187a51adSRussell King */ 34187a51adSRussell King .macro irq_handler 3552108641Seric miao#ifdef CONFIG_MULTI_IRQ_HANDLER 3652108641Seric miao ldr r5, =handle_arch_irq 3752108641Seric miao mov r0, sp 3852108641Seric miao ldr r5, [r5] 3952108641Seric miao adr lr, BSYM(9997f) 4052108641Seric miao teq r5, #0 4152108641Seric miao movne pc, r5 4237ee16aeSRussell King#endif 43cd544ce7SMagnus Damm arch_irq_handler_default 44f00ec48fSRussell King9997: 45187a51adSRussell King .endm 46187a51adSRussell King 47785d3cd2SNicolas Pitre#ifdef CONFIG_KPROBES 48785d3cd2SNicolas Pitre .section .kprobes.text,"ax",%progbits 49785d3cd2SNicolas Pitre#else 50785d3cd2SNicolas Pitre .text 51785d3cd2SNicolas Pitre#endif 52785d3cd2SNicolas Pitre 53187a51adSRussell King/* 541da177e4SLinus Torvalds * Invalid mode handlers 551da177e4SLinus Torvalds */ 56ccea7a19SRussell King .macro inv_entry, reason 57ccea7a19SRussell King sub sp, sp, #S_FRAME_SIZE 58b86040a5SCatalin Marinas ARM( stmib sp, {r1 - lr} ) 59b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 60b86040a5SCatalin Marinas THUMB( str sp, [sp, #S_SP] ) 61b86040a5SCatalin Marinas THUMB( str lr, [sp, #S_LR] ) 621da177e4SLinus Torvalds mov r1, #\reason 631da177e4SLinus Torvalds .endm 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds__pabt_invalid: 66ccea7a19SRussell King inv_entry BAD_PREFETCH 67ccea7a19SRussell King b common_invalid 6893ed3970SCatalin MarinasENDPROC(__pabt_invalid) 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds__dabt_invalid: 71ccea7a19SRussell King inv_entry BAD_DATA 72ccea7a19SRussell King b common_invalid 7393ed3970SCatalin MarinasENDPROC(__dabt_invalid) 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds__irq_invalid: 76ccea7a19SRussell King inv_entry BAD_IRQ 77ccea7a19SRussell King b common_invalid 7893ed3970SCatalin MarinasENDPROC(__irq_invalid) 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds__und_invalid: 81ccea7a19SRussell King inv_entry BAD_UNDEFINSTR 821da177e4SLinus Torvalds 83ccea7a19SRussell King @ 84ccea7a19SRussell King @ XXX fall through to common_invalid 85ccea7a19SRussell King @ 86ccea7a19SRussell King 87ccea7a19SRussell King@ 88ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers) 89ccea7a19SRussell King@ 90ccea7a19SRussell Kingcommon_invalid: 91ccea7a19SRussell King zero_fp 92ccea7a19SRussell King 93ccea7a19SRussell King ldmia r0, {r4 - r6} 94ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 95ccea7a19SRussell King mov r7, #-1 @ "" "" "" "" 96ccea7a19SRussell King str r4, [sp] @ save preserved r0 97ccea7a19SRussell King stmia r0, {r5 - r7} @ lr_<exception>, 98ccea7a19SRussell King @ cpsr_<exception>, "old_r0" 99ccea7a19SRussell King 1001da177e4SLinus Torvalds mov r0, sp 1011da177e4SLinus Torvalds b bad_mode 10293ed3970SCatalin MarinasENDPROC(__und_invalid) 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds/* 1051da177e4SLinus Torvalds * SVC mode handlers 1061da177e4SLinus Torvalds */ 1072dede2d8SNicolas Pitre 1082dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) 1092dede2d8SNicolas Pitre#define SPFIX(code...) code 1102dede2d8SNicolas Pitre#else 1112dede2d8SNicolas Pitre#define SPFIX(code...) 1122dede2d8SNicolas Pitre#endif 1132dede2d8SNicolas Pitre 114d30a0c8bSNicolas Pitre .macro svc_entry, stack_hole=0 115c4c5716eSCatalin Marinas UNWIND(.fnstart ) 116c4c5716eSCatalin Marinas UNWIND(.save {r0 - pc} ) 117b86040a5SCatalin Marinas sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4) 118b86040a5SCatalin Marinas#ifdef CONFIG_THUMB2_KERNEL 119b86040a5SCatalin Marinas SPFIX( str r0, [sp] ) @ temporarily saved 120b86040a5SCatalin Marinas SPFIX( mov r0, sp ) 121b86040a5SCatalin Marinas SPFIX( tst r0, #4 ) @ test original stack alignment 122b86040a5SCatalin Marinas SPFIX( ldr r0, [sp] ) @ restored 123b86040a5SCatalin Marinas#else 1242dede2d8SNicolas Pitre SPFIX( tst sp, #4 ) 125b86040a5SCatalin Marinas#endif 126b86040a5SCatalin Marinas SPFIX( subeq sp, sp, #4 ) 127b86040a5SCatalin Marinas stmia sp, {r1 - r12} 128ccea7a19SRussell King 129ccea7a19SRussell King ldmia r0, {r1 - r3} 130b86040a5SCatalin Marinas add r5, sp, #S_SP - 4 @ here for interlock avoidance 131ccea7a19SRussell King mov r4, #-1 @ "" "" "" "" 132b86040a5SCatalin Marinas add r0, sp, #(S_FRAME_SIZE + \stack_hole - 4) 133b86040a5SCatalin Marinas SPFIX( addeq r0, r0, #4 ) 134b86040a5SCatalin Marinas str r1, [sp, #-4]! @ save the "real" r0 copied 135ccea7a19SRussell King @ from the exception stack 136ccea7a19SRussell King 1371da177e4SLinus Torvalds mov r1, lr 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds @ 1401da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 1411da177e4SLinus Torvalds @ 1421da177e4SLinus Torvalds @ r0 - sp_svc 1431da177e4SLinus Torvalds @ r1 - lr_svc 1441da177e4SLinus Torvalds @ r2 - lr_<exception>, already fixed up for correct return/restart 1451da177e4SLinus Torvalds @ r3 - spsr_<exception> 1461da177e4SLinus Torvalds @ r4 - orig_r0 (see pt_regs definition in ptrace.h) 1471da177e4SLinus Torvalds @ 1481da177e4SLinus Torvalds stmia r5, {r0 - r4} 1491da177e4SLinus Torvalds .endm 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds .align 5 1521da177e4SLinus Torvalds__dabt_svc: 153ccea7a19SRussell King svc_entry 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds @ 1561da177e4SLinus Torvalds @ get ready to re-enable interrupts if appropriate 1571da177e4SLinus Torvalds @ 1581da177e4SLinus Torvalds mrs r9, cpsr 1591da177e4SLinus Torvalds tst r3, #PSR_I_BIT 1601da177e4SLinus Torvalds biceq r9, r9, #PSR_I_BIT 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds @ 1631da177e4SLinus Torvalds @ Call the processor-specific abort handler: 1641da177e4SLinus Torvalds @ 1651da177e4SLinus Torvalds @ r2 - aborted context pc 1661da177e4SLinus Torvalds @ r3 - aborted context cpsr 1671da177e4SLinus Torvalds @ 1681da177e4SLinus Torvalds @ The abort handler must return the aborted address in r0, and 1691da177e4SLinus Torvalds @ the fault status register in r1. r9 must be preserved. 1701da177e4SLinus Torvalds @ 17148d7927bSPaul Brook#ifdef MULTI_DABORT 1721da177e4SLinus Torvalds ldr r4, .LCprocfns 1731da177e4SLinus Torvalds mov lr, pc 17448d7927bSPaul Brook ldr pc, [r4, #PROCESSOR_DABT_FUNC] 1751da177e4SLinus Torvalds#else 17648d7927bSPaul Brook bl CPU_DABORT_HANDLER 1771da177e4SLinus Torvalds#endif 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds @ 1801da177e4SLinus Torvalds @ set desired IRQ state, then call main handler 1811da177e4SLinus Torvalds @ 1827e202696SWill Deacon debug_entry r1 1831da177e4SLinus Torvalds msr cpsr_c, r9 1841da177e4SLinus Torvalds mov r2, sp 1851da177e4SLinus Torvalds bl do_DataAbort 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds @ 1881da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 1891da177e4SLinus Torvalds @ 190ac78884eSRussell King disable_irq_notrace 1911da177e4SLinus Torvalds 1921da177e4SLinus Torvalds @ 1931da177e4SLinus Torvalds @ restore SPSR and restart the instruction 1941da177e4SLinus Torvalds @ 195b86040a5SCatalin Marinas ldr r2, [sp, #S_PSR] 196b86040a5SCatalin Marinas svc_exit r2 @ return from exception 197c4c5716eSCatalin Marinas UNWIND(.fnend ) 19893ed3970SCatalin MarinasENDPROC(__dabt_svc) 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds .align 5 2011da177e4SLinus Torvalds__irq_svc: 202ccea7a19SRussell King svc_entry 203ccea7a19SRussell King 204ac78884eSRussell King#ifdef CONFIG_TRACE_IRQFLAGS 205ac78884eSRussell King bl trace_hardirqs_off 206ac78884eSRussell King#endif 2071da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 208706fdd9fSRussell King get_thread_info tsk 209706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 210706fdd9fSRussell King add r7, r8, #1 @ increment it 211706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] 2121da177e4SLinus Torvalds#endif 213ccea7a19SRussell King 214187a51adSRussell King irq_handler 2151da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 21628fab1a2SRussell King str r8, [tsk, #TI_PREEMPT] @ restore preempt count 217706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get flags 21828fab1a2SRussell King teq r8, #0 @ if preempt count != 0 21928fab1a2SRussell King movne r0, #0 @ force flags to 0 2201da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2211da177e4SLinus Torvalds blne svc_preempt 2221da177e4SLinus Torvalds#endif 223b86040a5SCatalin Marinas ldr r4, [sp, #S_PSR] @ irqs are already disabled 2247ad1bcb2SRussell King#ifdef CONFIG_TRACE_IRQFLAGS 225b86040a5SCatalin Marinas tst r4, #PSR_I_BIT 2267ad1bcb2SRussell King bleq trace_hardirqs_on 2277ad1bcb2SRussell King#endif 228b86040a5SCatalin Marinas svc_exit r4 @ return from exception 229c4c5716eSCatalin Marinas UNWIND(.fnend ) 23093ed3970SCatalin MarinasENDPROC(__irq_svc) 2311da177e4SLinus Torvalds 2321da177e4SLinus Torvalds .ltorg 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 2351da177e4SLinus Torvaldssvc_preempt: 23628fab1a2SRussell King mov r8, lr 2371da177e4SLinus Torvalds1: bl preempt_schedule_irq @ irq en/disable is done inside 238706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS 2391da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 24028fab1a2SRussell King moveq pc, r8 @ go again 2411da177e4SLinus Torvalds b 1b 2421da177e4SLinus Torvalds#endif 2431da177e4SLinus Torvalds 2441da177e4SLinus Torvalds .align 5 2451da177e4SLinus Torvalds__und_svc: 246d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES 247d30a0c8bSNicolas Pitre @ If a kprobe is about to simulate a "stmdb sp..." instruction, 248d30a0c8bSNicolas Pitre @ it obviously needs free stack space which then will belong to 249d30a0c8bSNicolas Pitre @ the saved context. 250d30a0c8bSNicolas Pitre svc_entry 64 251d30a0c8bSNicolas Pitre#else 252ccea7a19SRussell King svc_entry 253d30a0c8bSNicolas Pitre#endif 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds @ 2561da177e4SLinus Torvalds @ call emulation code, which returns using r9 if it has emulated 2571da177e4SLinus Torvalds @ the instruction, or the more conventional lr if we are to treat 2581da177e4SLinus Torvalds @ this as a real undefined instruction 2591da177e4SLinus Torvalds @ 2601da177e4SLinus Torvalds @ r0 - instruction 2611da177e4SLinus Torvalds @ 26283e686eaSCatalin Marinas#ifndef CONFIG_THUMB2_KERNEL 2631da177e4SLinus Torvalds ldr r0, [r2, #-4] 26483e686eaSCatalin Marinas#else 26583e686eaSCatalin Marinas ldrh r0, [r2, #-2] @ Thumb instruction at LR - 2 26683e686eaSCatalin Marinas and r9, r0, #0xf800 26783e686eaSCatalin Marinas cmp r9, #0xe800 @ 32-bit instruction if xx >= 0 26883e686eaSCatalin Marinas ldrhhs r9, [r2] @ bottom 16 bits 26983e686eaSCatalin Marinas orrhs r0, r9, r0, lsl #16 27083e686eaSCatalin Marinas#endif 271b86040a5SCatalin Marinas adr r9, BSYM(1f) 2721da177e4SLinus Torvalds bl call_fpe 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds mov r0, sp @ struct pt_regs *regs 2751da177e4SLinus Torvalds bl do_undefinstr 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds @ 2781da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 2791da177e4SLinus Torvalds @ 280ac78884eSRussell King1: disable_irq_notrace 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds @ 2831da177e4SLinus Torvalds @ restore SPSR and restart the instruction 2841da177e4SLinus Torvalds @ 285b86040a5SCatalin Marinas ldr r2, [sp, #S_PSR] @ Get SVC cpsr 286b86040a5SCatalin Marinas svc_exit r2 @ return from exception 287c4c5716eSCatalin Marinas UNWIND(.fnend ) 28893ed3970SCatalin MarinasENDPROC(__und_svc) 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds .align 5 2911da177e4SLinus Torvalds__pabt_svc: 292ccea7a19SRussell King svc_entry 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds @ 2951da177e4SLinus Torvalds @ re-enable interrupts if appropriate 2961da177e4SLinus Torvalds @ 2971da177e4SLinus Torvalds mrs r9, cpsr 2981da177e4SLinus Torvalds tst r3, #PSR_I_BIT 2991da177e4SLinus Torvalds biceq r9, r9, #PSR_I_BIT 3001da177e4SLinus Torvalds 30148d7927bSPaul Brook mov r0, r2 @ pass address of aborted instruction. 3024fb28474SKirill A. Shutemov#ifdef MULTI_PABORT 30348d7927bSPaul Brook ldr r4, .LCprocfns 30448d7927bSPaul Brook mov lr, pc 30548d7927bSPaul Brook ldr pc, [r4, #PROCESSOR_PABT_FUNC] 30648d7927bSPaul Brook#else 3074fb28474SKirill A. Shutemov bl CPU_PABORT_HANDLER 30848d7927bSPaul Brook#endif 3097e202696SWill Deacon debug_entry r1 31048d7927bSPaul Brook msr cpsr_c, r9 @ Maybe enable interrupts 3114fb28474SKirill A. Shutemov mov r2, sp @ regs 3121da177e4SLinus Torvalds bl do_PrefetchAbort @ call abort handler 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds @ 3151da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 3161da177e4SLinus Torvalds @ 317ac78884eSRussell King disable_irq_notrace 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds @ 3201da177e4SLinus Torvalds @ restore SPSR and restart the instruction 3211da177e4SLinus Torvalds @ 322b86040a5SCatalin Marinas ldr r2, [sp, #S_PSR] 323b86040a5SCatalin Marinas svc_exit r2 @ return from exception 324c4c5716eSCatalin Marinas UNWIND(.fnend ) 32593ed3970SCatalin MarinasENDPROC(__pabt_svc) 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds .align 5 32849f680eaSRussell King.LCcralign: 32949f680eaSRussell King .word cr_alignment 33048d7927bSPaul Brook#ifdef MULTI_DABORT 3311da177e4SLinus Torvalds.LCprocfns: 3321da177e4SLinus Torvalds .word processor 3331da177e4SLinus Torvalds#endif 3341da177e4SLinus Torvalds.LCfp: 3351da177e4SLinus Torvalds .word fp_enter 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds/* 3381da177e4SLinus Torvalds * User mode handlers 3392dede2d8SNicolas Pitre * 3402dede2d8SNicolas Pitre * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE 3411da177e4SLinus Torvalds */ 3422dede2d8SNicolas Pitre 3432dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7) 3442dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8" 3452dede2d8SNicolas Pitre#endif 3462dede2d8SNicolas Pitre 347ccea7a19SRussell King .macro usr_entry 348c4c5716eSCatalin Marinas UNWIND(.fnstart ) 349c4c5716eSCatalin Marinas UNWIND(.cantunwind ) @ don't unwind the user space 350ccea7a19SRussell King sub sp, sp, #S_FRAME_SIZE 351b86040a5SCatalin Marinas ARM( stmib sp, {r1 - r12} ) 352b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 353ccea7a19SRussell King 354ccea7a19SRussell King ldmia r0, {r1 - r3} 355ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 356ccea7a19SRussell King mov r4, #-1 @ "" "" "" "" 357ccea7a19SRussell King 358ccea7a19SRussell King str r1, [sp] @ save the "real" r0 copied 359ccea7a19SRussell King @ from the exception stack 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds @ 3621da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 3631da177e4SLinus Torvalds @ 3641da177e4SLinus Torvalds @ r2 - lr_<exception>, already fixed up for correct return/restart 3651da177e4SLinus Torvalds @ r3 - spsr_<exception> 3661da177e4SLinus Torvalds @ r4 - orig_r0 (see pt_regs definition in ptrace.h) 3671da177e4SLinus Torvalds @ 3681da177e4SLinus Torvalds @ Also, separately save sp_usr and lr_usr 3691da177e4SLinus Torvalds @ 370ccea7a19SRussell King stmia r0, {r2 - r4} 371b86040a5SCatalin Marinas ARM( stmdb r0, {sp, lr}^ ) 372b86040a5SCatalin Marinas THUMB( store_user_sp_lr r0, r1, S_SP - S_PC ) 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds @ 3751da177e4SLinus Torvalds @ Enable the alignment trap while in kernel mode 3761da177e4SLinus Torvalds @ 37749f680eaSRussell King alignment_trap r0 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds @ 3801da177e4SLinus Torvalds @ Clear FP to mark the first stack frame 3811da177e4SLinus Torvalds @ 3821da177e4SLinus Torvalds zero_fp 3831da177e4SLinus Torvalds .endm 3841da177e4SLinus Torvalds 385b49c0f24SNicolas Pitre .macro kuser_cmpxchg_check 386b49c0f24SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG) 387b49c0f24SNicolas Pitre#ifndef CONFIG_MMU 388b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing" 389b49c0f24SNicolas Pitre#else 390b49c0f24SNicolas Pitre @ Make sure our user space atomic helper is restarted 391b49c0f24SNicolas Pitre @ if it was interrupted in a critical region. Here we 392b49c0f24SNicolas Pitre @ perform a quick test inline since it should be false 393b49c0f24SNicolas Pitre @ 99.9999% of the time. The rest is done out of line. 394b49c0f24SNicolas Pitre cmp r2, #TASK_SIZE 395b49c0f24SNicolas Pitre blhs kuser_cmpxchg_fixup 396b49c0f24SNicolas Pitre#endif 397b49c0f24SNicolas Pitre#endif 398b49c0f24SNicolas Pitre .endm 399b49c0f24SNicolas Pitre 4001da177e4SLinus Torvalds .align 5 4011da177e4SLinus Torvalds__dabt_usr: 402ccea7a19SRussell King usr_entry 403b49c0f24SNicolas Pitre kuser_cmpxchg_check 4041da177e4SLinus Torvalds 4051da177e4SLinus Torvalds @ 4061da177e4SLinus Torvalds @ Call the processor-specific abort handler: 4071da177e4SLinus Torvalds @ 4081da177e4SLinus Torvalds @ r2 - aborted context pc 4091da177e4SLinus Torvalds @ r3 - aborted context cpsr 4101da177e4SLinus Torvalds @ 4111da177e4SLinus Torvalds @ The abort handler must return the aborted address in r0, and 4121da177e4SLinus Torvalds @ the fault status register in r1. 4131da177e4SLinus Torvalds @ 41448d7927bSPaul Brook#ifdef MULTI_DABORT 4151da177e4SLinus Torvalds ldr r4, .LCprocfns 4161da177e4SLinus Torvalds mov lr, pc 41748d7927bSPaul Brook ldr pc, [r4, #PROCESSOR_DABT_FUNC] 4181da177e4SLinus Torvalds#else 41948d7927bSPaul Brook bl CPU_DABORT_HANDLER 4201da177e4SLinus Torvalds#endif 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds @ 4231da177e4SLinus Torvalds @ IRQs on, then call the main handler 4241da177e4SLinus Torvalds @ 4257e202696SWill Deacon debug_entry r1 4261ec42c0cSRussell King enable_irq 4271da177e4SLinus Torvalds mov r2, sp 428b86040a5SCatalin Marinas adr lr, BSYM(ret_from_exception) 4291da177e4SLinus Torvalds b do_DataAbort 430c4c5716eSCatalin Marinas UNWIND(.fnend ) 43193ed3970SCatalin MarinasENDPROC(__dabt_usr) 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds .align 5 4341da177e4SLinus Torvalds__irq_usr: 435ccea7a19SRussell King usr_entry 436b49c0f24SNicolas Pitre kuser_cmpxchg_check 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds get_thread_info tsk 4391da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 440706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 441706fdd9fSRussell King add r7, r8, #1 @ increment it 442706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] 4431da177e4SLinus Torvalds#endif 444ccea7a19SRussell King 445187a51adSRussell King irq_handler 4461da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 447706fdd9fSRussell King ldr r0, [tsk, #TI_PREEMPT] 448706fdd9fSRussell King str r8, [tsk, #TI_PREEMPT] 4491da177e4SLinus Torvalds teq r0, r7 450b86040a5SCatalin Marinas ARM( strne r0, [r0, -r0] ) 451b86040a5SCatalin Marinas THUMB( movne r0, #0 ) 452b86040a5SCatalin Marinas THUMB( strne r0, [r0] ) 4531da177e4SLinus Torvalds#endif 454ccea7a19SRussell King 4551da177e4SLinus Torvalds mov why, #0 4561da177e4SLinus Torvalds b ret_to_user 457c4c5716eSCatalin Marinas UNWIND(.fnend ) 45893ed3970SCatalin MarinasENDPROC(__irq_usr) 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds .ltorg 4611da177e4SLinus Torvalds 4621da177e4SLinus Torvalds .align 5 4631da177e4SLinus Torvalds__und_usr: 464ccea7a19SRussell King usr_entry 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds @ 4671da177e4SLinus Torvalds @ fall through to the emulation code, which returns using r9 if 4681da177e4SLinus Torvalds @ it has emulated the instruction, or the more conventional lr 4691da177e4SLinus Torvalds @ if we are to treat this as a real undefined instruction 4701da177e4SLinus Torvalds @ 4711da177e4SLinus Torvalds @ r0 - instruction 4721da177e4SLinus Torvalds @ 473b86040a5SCatalin Marinas adr r9, BSYM(ret_from_exception) 474b86040a5SCatalin Marinas adr lr, BSYM(__und_usr_unknown) 475cb170a45SPaul Brook tst r3, #PSR_T_BIT @ Thumb mode? 476b86040a5SCatalin Marinas itet eq @ explicit IT needed for the 1f label 477cb170a45SPaul Brook subeq r4, r2, #4 @ ARM instr at LR - 4 478cb170a45SPaul Brook subne r4, r2, #2 @ Thumb instr at LR - 2 479cb170a45SPaul Brook1: ldreqt r0, [r4] 48026584853SCatalin Marinas#ifdef CONFIG_CPU_ENDIAN_BE8 48126584853SCatalin Marinas reveq r0, r0 @ little endian instruction 48226584853SCatalin Marinas#endif 483cb170a45SPaul Brook beq call_fpe 484cb170a45SPaul Brook @ Thumb instruction 485cb170a45SPaul Brook#if __LINUX_ARM_ARCH__ >= 7 486b86040a5SCatalin Marinas2: 487b86040a5SCatalin Marinas ARM( ldrht r5, [r4], #2 ) 488b86040a5SCatalin Marinas THUMB( ldrht r5, [r4] ) 489b86040a5SCatalin Marinas THUMB( add r4, r4, #2 ) 490cb170a45SPaul Brook and r0, r5, #0xf800 @ mask bits 111x x... .... .... 491cb170a45SPaul Brook cmp r0, #0xe800 @ 32bit instruction if xx != 0 492cb170a45SPaul Brook blo __und_usr_unknown 493cb170a45SPaul Brook3: ldrht r0, [r4] 494cb170a45SPaul Brook add r2, r2, #2 @ r2 is PC + 2, make it PC + 4 495cb170a45SPaul Brook orr r0, r0, r5, lsl #16 496cb170a45SPaul Brook#else 497cb170a45SPaul Brook b __und_usr_unknown 498cb170a45SPaul Brook#endif 499c4c5716eSCatalin Marinas UNWIND(.fnend ) 50093ed3970SCatalin MarinasENDPROC(__und_usr) 501cb170a45SPaul Brook 5021da177e4SLinus Torvalds @ 5031da177e4SLinus Torvalds @ fallthrough to call_fpe 5041da177e4SLinus Torvalds @ 5051da177e4SLinus Torvalds 5061da177e4SLinus Torvalds/* 5071da177e4SLinus Torvalds * The out of line fixup for the ldrt above. 5081da177e4SLinus Torvalds */ 5094260415fSRussell King .pushsection .fixup, "ax" 510cb170a45SPaul Brook4: mov pc, r9 5114260415fSRussell King .popsection 5124260415fSRussell King .pushsection __ex_table,"a" 513cb170a45SPaul Brook .long 1b, 4b 514cb170a45SPaul Brook#if __LINUX_ARM_ARCH__ >= 7 515cb170a45SPaul Brook .long 2b, 4b 516cb170a45SPaul Brook .long 3b, 4b 517cb170a45SPaul Brook#endif 5184260415fSRussell King .popsection 5191da177e4SLinus Torvalds 5201da177e4SLinus Torvalds/* 5211da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction. 5221da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler. 5231da177e4SLinus Torvalds * 5241da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor 5251da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well 5261da177e4SLinus Torvalds * defined. The only instructions that should fault are the 5271da177e4SLinus Torvalds * co-processor instructions. However, we have to watch out 5281da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug. 5291da177e4SLinus Torvalds * 530b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all 531b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have 532b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's 533b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs 534b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the 535b5872db4SCatalin Marinas * NEON handler code. 536b5872db4SCatalin Marinas * 5371da177e4SLinus Torvalds * Emulators may wish to make use of the following registers: 5381da177e4SLinus Torvalds * r0 = instruction opcode. 5391da177e4SLinus Torvalds * r2 = PC+4 540db6ccbb6SRussell King * r9 = normal "successful" return address 5411da177e4SLinus Torvalds * r10 = this threads thread_info structure. 542db6ccbb6SRussell King * lr = unrecognised instruction return address 5431da177e4SLinus Torvalds */ 544cb170a45SPaul Brook @ 545cb170a45SPaul Brook @ Fall-through from Thumb-2 __und_usr 546cb170a45SPaul Brook @ 547cb170a45SPaul Brook#ifdef CONFIG_NEON 548cb170a45SPaul Brook adr r6, .LCneon_thumb_opcodes 549cb170a45SPaul Brook b 2f 550cb170a45SPaul Brook#endif 5511da177e4SLinus Torvaldscall_fpe: 552b5872db4SCatalin Marinas#ifdef CONFIG_NEON 553cb170a45SPaul Brook adr r6, .LCneon_arm_opcodes 554b5872db4SCatalin Marinas2: 555b5872db4SCatalin Marinas ldr r7, [r6], #4 @ mask value 556b5872db4SCatalin Marinas cmp r7, #0 @ end mask? 557b5872db4SCatalin Marinas beq 1f 558b5872db4SCatalin Marinas and r8, r0, r7 559b5872db4SCatalin Marinas ldr r7, [r6], #4 @ opcode bits matching in mask 560b5872db4SCatalin Marinas cmp r8, r7 @ NEON instruction? 561b5872db4SCatalin Marinas bne 2b 562b5872db4SCatalin Marinas get_thread_info r10 563b5872db4SCatalin Marinas mov r7, #1 564b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used 565b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used 566b5872db4SCatalin Marinas b do_vfp @ let VFP handler handle this 567b5872db4SCatalin Marinas1: 568b5872db4SCatalin Marinas#endif 5691da177e4SLinus Torvalds tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27 570cb170a45SPaul Brook tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2 5711da177e4SLinus Torvalds#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710) 5721da177e4SLinus Torvalds and r8, r0, #0x0f000000 @ mask out op-code bits 5731da177e4SLinus Torvalds teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)? 5741da177e4SLinus Torvalds#endif 5751da177e4SLinus Torvalds moveq pc, lr 5761da177e4SLinus Torvalds get_thread_info r10 @ get current thread 5771da177e4SLinus Torvalds and r8, r0, #0x00000f00 @ mask out CP number 578b86040a5SCatalin Marinas THUMB( lsr r8, r8, #8 ) 5791da177e4SLinus Torvalds mov r7, #1 5801da177e4SLinus Torvalds add r6, r10, #TI_USED_CP 581b86040a5SCatalin Marinas ARM( strb r7, [r6, r8, lsr #8] ) @ set appropriate used_cp[] 582b86040a5SCatalin Marinas THUMB( strb r7, [r6, r8] ) @ set appropriate used_cp[] 5831da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT 5841da177e4SLinus Torvalds @ Test if we need to give access to iWMMXt coprocessors 5851da177e4SLinus Torvalds ldr r5, [r10, #TI_FLAGS] 5861da177e4SLinus Torvalds rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only 5871da177e4SLinus Torvalds movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1) 5881da177e4SLinus Torvalds bcs iwmmxt_task_enable 5891da177e4SLinus Torvalds#endif 590b86040a5SCatalin Marinas ARM( add pc, pc, r8, lsr #6 ) 591b86040a5SCatalin Marinas THUMB( lsl r8, r8, #2 ) 592b86040a5SCatalin Marinas THUMB( add pc, r8 ) 593b86040a5SCatalin Marinas nop 5941da177e4SLinus Torvalds 595a771fe6eSCatalin Marinas movw_pc lr @ CP#0 596b86040a5SCatalin Marinas W(b) do_fpe @ CP#1 (FPE) 597b86040a5SCatalin Marinas W(b) do_fpe @ CP#2 (FPE) 598a771fe6eSCatalin Marinas movw_pc lr @ CP#3 599c17fad11SLennert Buytenhek#ifdef CONFIG_CRUNCH 600c17fad11SLennert Buytenhek b crunch_task_enable @ CP#4 (MaverickCrunch) 601c17fad11SLennert Buytenhek b crunch_task_enable @ CP#5 (MaverickCrunch) 602c17fad11SLennert Buytenhek b crunch_task_enable @ CP#6 (MaverickCrunch) 603c17fad11SLennert Buytenhek#else 604a771fe6eSCatalin Marinas movw_pc lr @ CP#4 605a771fe6eSCatalin Marinas movw_pc lr @ CP#5 606a771fe6eSCatalin Marinas movw_pc lr @ CP#6 607c17fad11SLennert Buytenhek#endif 608a771fe6eSCatalin Marinas movw_pc lr @ CP#7 609a771fe6eSCatalin Marinas movw_pc lr @ CP#8 610a771fe6eSCatalin Marinas movw_pc lr @ CP#9 6111da177e4SLinus Torvalds#ifdef CONFIG_VFP 612b86040a5SCatalin Marinas W(b) do_vfp @ CP#10 (VFP) 613b86040a5SCatalin Marinas W(b) do_vfp @ CP#11 (VFP) 6141da177e4SLinus Torvalds#else 615a771fe6eSCatalin Marinas movw_pc lr @ CP#10 (VFP) 616a771fe6eSCatalin Marinas movw_pc lr @ CP#11 (VFP) 6171da177e4SLinus Torvalds#endif 618a771fe6eSCatalin Marinas movw_pc lr @ CP#12 619a771fe6eSCatalin Marinas movw_pc lr @ CP#13 620a771fe6eSCatalin Marinas movw_pc lr @ CP#14 (Debug) 621a771fe6eSCatalin Marinas movw_pc lr @ CP#15 (Control) 6221da177e4SLinus Torvalds 623b5872db4SCatalin Marinas#ifdef CONFIG_NEON 624b5872db4SCatalin Marinas .align 6 625b5872db4SCatalin Marinas 626cb170a45SPaul Brook.LCneon_arm_opcodes: 627b5872db4SCatalin Marinas .word 0xfe000000 @ mask 628b5872db4SCatalin Marinas .word 0xf2000000 @ opcode 629b5872db4SCatalin Marinas 630b5872db4SCatalin Marinas .word 0xff100000 @ mask 631b5872db4SCatalin Marinas .word 0xf4000000 @ opcode 632b5872db4SCatalin Marinas 633b5872db4SCatalin Marinas .word 0x00000000 @ mask 634b5872db4SCatalin Marinas .word 0x00000000 @ opcode 635cb170a45SPaul Brook 636cb170a45SPaul Brook.LCneon_thumb_opcodes: 637cb170a45SPaul Brook .word 0xef000000 @ mask 638cb170a45SPaul Brook .word 0xef000000 @ opcode 639cb170a45SPaul Brook 640cb170a45SPaul Brook .word 0xff100000 @ mask 641cb170a45SPaul Brook .word 0xf9000000 @ opcode 642cb170a45SPaul Brook 643cb170a45SPaul Brook .word 0x00000000 @ mask 644cb170a45SPaul Brook .word 0x00000000 @ opcode 645b5872db4SCatalin Marinas#endif 646b5872db4SCatalin Marinas 6471da177e4SLinus Torvaldsdo_fpe: 6485d25ac03SRussell King enable_irq 6491da177e4SLinus Torvalds ldr r4, .LCfp 6501da177e4SLinus Torvalds add r10, r10, #TI_FPSTATE @ r10 = workspace 6511da177e4SLinus Torvalds ldr pc, [r4] @ Call FP module USR entry point 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds/* 6541da177e4SLinus Torvalds * The FP module is called with these registers set: 6551da177e4SLinus Torvalds * r0 = instruction 6561da177e4SLinus Torvalds * r2 = PC+4 6571da177e4SLinus Torvalds * r9 = normal "successful" return address 6581da177e4SLinus Torvalds * r10 = FP workspace 6591da177e4SLinus Torvalds * lr = unrecognised FP instruction return address 6601da177e4SLinus Torvalds */ 6611da177e4SLinus Torvalds 662124efc27SSantosh Shilimkar .pushsection .data 6631da177e4SLinus TorvaldsENTRY(fp_enter) 664db6ccbb6SRussell King .word no_fp 665124efc27SSantosh Shilimkar .popsection 6661da177e4SLinus Torvalds 66783e686eaSCatalin MarinasENTRY(no_fp) 66883e686eaSCatalin Marinas mov pc, lr 66983e686eaSCatalin MarinasENDPROC(no_fp) 670db6ccbb6SRussell King 671db6ccbb6SRussell King__und_usr_unknown: 672ecbab71cSRussell King enable_irq 6731da177e4SLinus Torvalds mov r0, sp 674b86040a5SCatalin Marinas adr lr, BSYM(ret_from_exception) 6751da177e4SLinus Torvalds b do_undefinstr 67693ed3970SCatalin MarinasENDPROC(__und_usr_unknown) 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds .align 5 6791da177e4SLinus Torvalds__pabt_usr: 680ccea7a19SRussell King usr_entry 6811da177e4SLinus Torvalds 68248d7927bSPaul Brook mov r0, r2 @ pass address of aborted instruction. 6834fb28474SKirill A. Shutemov#ifdef MULTI_PABORT 68448d7927bSPaul Brook ldr r4, .LCprocfns 68548d7927bSPaul Brook mov lr, pc 68648d7927bSPaul Brook ldr pc, [r4, #PROCESSOR_PABT_FUNC] 68748d7927bSPaul Brook#else 6884fb28474SKirill A. Shutemov bl CPU_PABORT_HANDLER 68948d7927bSPaul Brook#endif 6907e202696SWill Deacon debug_entry r1 6911ec42c0cSRussell King enable_irq @ Enable interrupts 6924fb28474SKirill A. Shutemov mov r2, sp @ regs 6931da177e4SLinus Torvalds bl do_PrefetchAbort @ call abort handler 694c4c5716eSCatalin Marinas UNWIND(.fnend ) 6951da177e4SLinus Torvalds /* fall through */ 6961da177e4SLinus Torvalds/* 6971da177e4SLinus Torvalds * This is the return code to user mode for abort handlers 6981da177e4SLinus Torvalds */ 6991da177e4SLinus TorvaldsENTRY(ret_from_exception) 700c4c5716eSCatalin Marinas UNWIND(.fnstart ) 701c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 7021da177e4SLinus Torvalds get_thread_info tsk 7031da177e4SLinus Torvalds mov why, #0 7041da177e4SLinus Torvalds b ret_to_user 705c4c5716eSCatalin Marinas UNWIND(.fnend ) 70693ed3970SCatalin MarinasENDPROC(__pabt_usr) 70793ed3970SCatalin MarinasENDPROC(ret_from_exception) 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds/* 7101da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors 7111da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info 7121da177e4SLinus Torvalds * previous and next are guaranteed not to be the same. 7131da177e4SLinus Torvalds */ 7141da177e4SLinus TorvaldsENTRY(__switch_to) 715c4c5716eSCatalin Marinas UNWIND(.fnstart ) 716c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 7171da177e4SLinus Torvalds add ip, r1, #TI_CPU_SAVE 7181da177e4SLinus Torvalds ldr r3, [r2, #TI_TP_VALUE] 719b86040a5SCatalin Marinas ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack 720b86040a5SCatalin Marinas THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack 721b86040a5SCatalin Marinas THUMB( str sp, [ip], #4 ) 722b86040a5SCatalin Marinas THUMB( str lr, [ip], #4 ) 723247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 724d6551e88SRussell King ldr r6, [r2, #TI_CPU_DOMAIN] 725afeb90caSHyok S. Choi#endif 726f159f4edSTony Lindgren set_tls r3, r4, r5 727df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP) 728df0698beSNicolas Pitre ldr r7, [r2, #TI_TASK] 729df0698beSNicolas Pitre ldr r8, =__stack_chk_guard 730df0698beSNicolas Pitre ldr r7, [r7, #TSK_STACK_CANARY] 731df0698beSNicolas Pitre#endif 732247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 7331da177e4SLinus Torvalds mcr p15, 0, r6, c3, c0, 0 @ Set domain register 734afeb90caSHyok S. Choi#endif 735d6551e88SRussell King mov r5, r0 736d6551e88SRussell King add r4, r2, #TI_CPU_SAVE 737d6551e88SRussell King ldr r0, =thread_notify_head 738d6551e88SRussell King mov r1, #THREAD_NOTIFY_SWITCH 739d6551e88SRussell King bl atomic_notifier_call_chain 740df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP) 741df0698beSNicolas Pitre str r7, [r8] 742df0698beSNicolas Pitre#endif 743b86040a5SCatalin Marinas THUMB( mov ip, r4 ) 744d6551e88SRussell King mov r0, r5 745b86040a5SCatalin Marinas ARM( ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previously 746b86040a5SCatalin Marinas THUMB( ldmia ip!, {r4 - sl, fp} ) @ Load all regs saved previously 747b86040a5SCatalin Marinas THUMB( ldr sp, [ip], #4 ) 748b86040a5SCatalin Marinas THUMB( ldr pc, [ip] ) 749c4c5716eSCatalin Marinas UNWIND(.fnend ) 75093ed3970SCatalin MarinasENDPROC(__switch_to) 7511da177e4SLinus Torvalds 7521da177e4SLinus Torvalds __INIT 7532d2669b6SNicolas Pitre 7542d2669b6SNicolas Pitre/* 7552d2669b6SNicolas Pitre * User helpers. 7562d2669b6SNicolas Pitre * 7572d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high 7582d2669b6SNicolas Pitre * vector page. New segments (if ever needed) must be added in front of 7592d2669b6SNicolas Pitre * existing ones. This mechanism should be used only for things that are 7602d2669b6SNicolas Pitre * really small and justified, and not be abused freely. 7612d2669b6SNicolas Pitre * 762*37b83046SNicolas Pitre * See Documentation/arm/kernel_user_helpers.txt for formal definitions. 7632d2669b6SNicolas Pitre */ 764b86040a5SCatalin Marinas THUMB( .arm ) 7652d2669b6SNicolas Pitre 766ba9b5d76SNicolas Pitre .macro usr_ret, reg 767ba9b5d76SNicolas Pitre#ifdef CONFIG_ARM_THUMB 768ba9b5d76SNicolas Pitre bx \reg 769ba9b5d76SNicolas Pitre#else 770ba9b5d76SNicolas Pitre mov pc, \reg 771ba9b5d76SNicolas Pitre#endif 772ba9b5d76SNicolas Pitre .endm 773ba9b5d76SNicolas Pitre 7742d2669b6SNicolas Pitre .align 5 7752d2669b6SNicolas Pitre .globl __kuser_helper_start 7762d2669b6SNicolas Pitre__kuser_helper_start: 7772d2669b6SNicolas Pitre 7787c612bfdSNicolas Pitre__kuser_memory_barrier: @ 0xffff0fa0 779ed3768a8SDave Martin smp_dmb arm 780ba9b5d76SNicolas Pitre usr_ret lr 7817c612bfdSNicolas Pitre 7827c612bfdSNicolas Pitre .align 5 7837c612bfdSNicolas Pitre 7842d2669b6SNicolas Pitre__kuser_cmpxchg: @ 0xffff0fc0 7852d2669b6SNicolas Pitre 786dcef1f63SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG) 7872d2669b6SNicolas Pitre 788dcef1f63SNicolas Pitre /* 789dcef1f63SNicolas Pitre * Poor you. No fast solution possible... 790dcef1f63SNicolas Pitre * The kernel itself must perform the operation. 791dcef1f63SNicolas Pitre * A special ghost syscall is used for that (see traps.c). 792dcef1f63SNicolas Pitre */ 7935e097445SNicolas Pitre stmfd sp!, {r7, lr} 79455afd264SDave Martin ldr r7, 1f @ it's 20 bits 795cc20d429SRussell King swi __ARM_NR_cmpxchg 7965e097445SNicolas Pitre ldmfd sp!, {r7, pc} 797cc20d429SRussell King1: .word __ARM_NR_cmpxchg 798dcef1f63SNicolas Pitre 799dcef1f63SNicolas Pitre#elif __LINUX_ARM_ARCH__ < 6 8002d2669b6SNicolas Pitre 80149bca4c2SNicolas Pitre#ifdef CONFIG_MMU 802b49c0f24SNicolas Pitre 803b49c0f24SNicolas Pitre /* 804b49c0f24SNicolas Pitre * The only thing that can break atomicity in this cmpxchg 805b49c0f24SNicolas Pitre * implementation is either an IRQ or a data abort exception 806b49c0f24SNicolas Pitre * causing another process/thread to be scheduled in the middle 807b49c0f24SNicolas Pitre * of the critical sequence. To prevent this, code is added to 808b49c0f24SNicolas Pitre * the IRQ and data abort exception handlers to set the pc back 809b49c0f24SNicolas Pitre * to the beginning of the critical section if it is found to be 810b49c0f24SNicolas Pitre * within that critical section (see kuser_cmpxchg_fixup). 811b49c0f24SNicolas Pitre */ 812b49c0f24SNicolas Pitre1: ldr r3, [r2] @ load current val 813b49c0f24SNicolas Pitre subs r3, r3, r0 @ compare with oldval 814b49c0f24SNicolas Pitre2: streq r1, [r2] @ store newval if eq 815b49c0f24SNicolas Pitre rsbs r0, r3, #0 @ set return val and C flag 816b49c0f24SNicolas Pitre usr_ret lr 817b49c0f24SNicolas Pitre 818b49c0f24SNicolas Pitre .text 819b49c0f24SNicolas Pitrekuser_cmpxchg_fixup: 820b49c0f24SNicolas Pitre @ Called from kuser_cmpxchg_check macro. 821b49c0f24SNicolas Pitre @ r2 = address of interrupted insn (must be preserved). 822b49c0f24SNicolas Pitre @ sp = saved regs. r7 and r8 are clobbered. 823b49c0f24SNicolas Pitre @ 1b = first critical insn, 2b = last critical insn. 824b49c0f24SNicolas Pitre @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b. 825b49c0f24SNicolas Pitre mov r7, #0xffff0fff 826b49c0f24SNicolas Pitre sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg))) 827b49c0f24SNicolas Pitre subs r8, r2, r7 828b49c0f24SNicolas Pitre rsbcss r8, r8, #(2b - 1b) 829b49c0f24SNicolas Pitre strcs r7, [sp, #S_PC] 830b49c0f24SNicolas Pitre mov pc, lr 831b49c0f24SNicolas Pitre .previous 832b49c0f24SNicolas Pitre 83349bca4c2SNicolas Pitre#else 83449bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing" 83549bca4c2SNicolas Pitre mov r0, #-1 83649bca4c2SNicolas Pitre adds r0, r0, #0 837ba9b5d76SNicolas Pitre usr_ret lr 838b49c0f24SNicolas Pitre#endif 8392d2669b6SNicolas Pitre 8402d2669b6SNicolas Pitre#else 8412d2669b6SNicolas Pitre 842ed3768a8SDave Martin smp_dmb arm 843b49c0f24SNicolas Pitre1: ldrex r3, [r2] 8442d2669b6SNicolas Pitre subs r3, r3, r0 8452d2669b6SNicolas Pitre strexeq r3, r1, [r2] 846b49c0f24SNicolas Pitre teqeq r3, #1 847b49c0f24SNicolas Pitre beq 1b 8482d2669b6SNicolas Pitre rsbs r0, r3, #0 849b49c0f24SNicolas Pitre /* beware -- each __kuser slot must be 8 instructions max */ 850f00ec48fSRussell King ALT_SMP(b __kuser_memory_barrier) 851f00ec48fSRussell King ALT_UP(usr_ret lr) 8522d2669b6SNicolas Pitre 8532d2669b6SNicolas Pitre#endif 8542d2669b6SNicolas Pitre 8552d2669b6SNicolas Pitre .align 5 8562d2669b6SNicolas Pitre 8572d2669b6SNicolas Pitre__kuser_get_tls: @ 0xffff0fe0 858f159f4edSTony Lindgren ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init 859ba9b5d76SNicolas Pitre usr_ret lr 860f159f4edSTony Lindgren mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code 861f159f4edSTony Lindgren .rep 4 862f159f4edSTony Lindgren .word 0 @ 0xffff0ff0 software TLS value, then 863f159f4edSTony Lindgren .endr @ pad up to __kuser_helper_version 8642d2669b6SNicolas Pitre 8652d2669b6SNicolas Pitre__kuser_helper_version: @ 0xffff0ffc 8662d2669b6SNicolas Pitre .word ((__kuser_helper_end - __kuser_helper_start) >> 5) 8672d2669b6SNicolas Pitre 8682d2669b6SNicolas Pitre .globl __kuser_helper_end 8692d2669b6SNicolas Pitre__kuser_helper_end: 8702d2669b6SNicolas Pitre 871b86040a5SCatalin Marinas THUMB( .thumb ) 8722d2669b6SNicolas Pitre 8731da177e4SLinus Torvalds/* 8741da177e4SLinus Torvalds * Vector stubs. 8751da177e4SLinus Torvalds * 8767933523dSRussell King * This code is copied to 0xffff0200 so we can use branches in the 8777933523dSRussell King * vectors, rather than ldr's. Note that this code must not 8787933523dSRussell King * exceed 0x300 bytes. 8791da177e4SLinus Torvalds * 8801da177e4SLinus Torvalds * Common stub entry macro: 8811da177e4SLinus Torvalds * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 882ccea7a19SRussell King * 883ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address 884ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler. 8851da177e4SLinus Torvalds */ 886b7ec4795SNicolas Pitre .macro vector_stub, name, mode, correction=0 8871da177e4SLinus Torvalds .align 5 8881da177e4SLinus Torvalds 8891da177e4SLinus Torvaldsvector_\name: 8901da177e4SLinus Torvalds .if \correction 8911da177e4SLinus Torvalds sub lr, lr, #\correction 8921da177e4SLinus Torvalds .endif 8931da177e4SLinus Torvalds 894ccea7a19SRussell King @ 895ccea7a19SRussell King @ Save r0, lr_<exception> (parent PC) and spsr_<exception> 896ccea7a19SRussell King @ (parent CPSR) 897ccea7a19SRussell King @ 898ccea7a19SRussell King stmia sp, {r0, lr} @ save r0, lr 899ccea7a19SRussell King mrs lr, spsr 900ccea7a19SRussell King str lr, [sp, #8] @ save spsr 901ccea7a19SRussell King 902ccea7a19SRussell King @ 903ccea7a19SRussell King @ Prepare for SVC32 mode. IRQs remain disabled. 904ccea7a19SRussell King @ 905ccea7a19SRussell King mrs r0, cpsr 906b86040a5SCatalin Marinas eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE) 907ccea7a19SRussell King msr spsr_cxsf, r0 908ccea7a19SRussell King 909ccea7a19SRussell King @ 910ccea7a19SRussell King @ the branch table must immediately follow this code 911ccea7a19SRussell King @ 912ccea7a19SRussell King and lr, lr, #0x0f 913b86040a5SCatalin Marinas THUMB( adr r0, 1f ) 914b86040a5SCatalin Marinas THUMB( ldr lr, [r0, lr, lsl #2] ) 915b7ec4795SNicolas Pitre mov r0, sp 916b86040a5SCatalin Marinas ARM( ldr lr, [pc, lr, lsl #2] ) 917ccea7a19SRussell King movs pc, lr @ branch to handler in SVC mode 91893ed3970SCatalin MarinasENDPROC(vector_\name) 91988987ef9SCatalin Marinas 92088987ef9SCatalin Marinas .align 2 92188987ef9SCatalin Marinas @ handler addresses follow this label 92288987ef9SCatalin Marinas1: 9231da177e4SLinus Torvalds .endm 9241da177e4SLinus Torvalds 9257933523dSRussell King .globl __stubs_start 9261da177e4SLinus Torvalds__stubs_start: 9271da177e4SLinus Torvalds/* 9281da177e4SLinus Torvalds * Interrupt dispatcher 9291da177e4SLinus Torvalds */ 930b7ec4795SNicolas Pitre vector_stub irq, IRQ_MODE, 4 9311da177e4SLinus Torvalds 9321da177e4SLinus Torvalds .long __irq_usr @ 0 (USR_26 / USR_32) 9331da177e4SLinus Torvalds .long __irq_invalid @ 1 (FIQ_26 / FIQ_32) 9341da177e4SLinus Torvalds .long __irq_invalid @ 2 (IRQ_26 / IRQ_32) 9351da177e4SLinus Torvalds .long __irq_svc @ 3 (SVC_26 / SVC_32) 9361da177e4SLinus Torvalds .long __irq_invalid @ 4 9371da177e4SLinus Torvalds .long __irq_invalid @ 5 9381da177e4SLinus Torvalds .long __irq_invalid @ 6 9391da177e4SLinus Torvalds .long __irq_invalid @ 7 9401da177e4SLinus Torvalds .long __irq_invalid @ 8 9411da177e4SLinus Torvalds .long __irq_invalid @ 9 9421da177e4SLinus Torvalds .long __irq_invalid @ a 9431da177e4SLinus Torvalds .long __irq_invalid @ b 9441da177e4SLinus Torvalds .long __irq_invalid @ c 9451da177e4SLinus Torvalds .long __irq_invalid @ d 9461da177e4SLinus Torvalds .long __irq_invalid @ e 9471da177e4SLinus Torvalds .long __irq_invalid @ f 9481da177e4SLinus Torvalds 9491da177e4SLinus Torvalds/* 9501da177e4SLinus Torvalds * Data abort dispatcher 9511da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 9521da177e4SLinus Torvalds */ 953b7ec4795SNicolas Pitre vector_stub dabt, ABT_MODE, 8 9541da177e4SLinus Torvalds 9551da177e4SLinus Torvalds .long __dabt_usr @ 0 (USR_26 / USR_32) 9561da177e4SLinus Torvalds .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32) 9571da177e4SLinus Torvalds .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32) 9581da177e4SLinus Torvalds .long __dabt_svc @ 3 (SVC_26 / SVC_32) 9591da177e4SLinus Torvalds .long __dabt_invalid @ 4 9601da177e4SLinus Torvalds .long __dabt_invalid @ 5 9611da177e4SLinus Torvalds .long __dabt_invalid @ 6 9621da177e4SLinus Torvalds .long __dabt_invalid @ 7 9631da177e4SLinus Torvalds .long __dabt_invalid @ 8 9641da177e4SLinus Torvalds .long __dabt_invalid @ 9 9651da177e4SLinus Torvalds .long __dabt_invalid @ a 9661da177e4SLinus Torvalds .long __dabt_invalid @ b 9671da177e4SLinus Torvalds .long __dabt_invalid @ c 9681da177e4SLinus Torvalds .long __dabt_invalid @ d 9691da177e4SLinus Torvalds .long __dabt_invalid @ e 9701da177e4SLinus Torvalds .long __dabt_invalid @ f 9711da177e4SLinus Torvalds 9721da177e4SLinus Torvalds/* 9731da177e4SLinus Torvalds * Prefetch abort dispatcher 9741da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 9751da177e4SLinus Torvalds */ 976b7ec4795SNicolas Pitre vector_stub pabt, ABT_MODE, 4 9771da177e4SLinus Torvalds 9781da177e4SLinus Torvalds .long __pabt_usr @ 0 (USR_26 / USR_32) 9791da177e4SLinus Torvalds .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32) 9801da177e4SLinus Torvalds .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32) 9811da177e4SLinus Torvalds .long __pabt_svc @ 3 (SVC_26 / SVC_32) 9821da177e4SLinus Torvalds .long __pabt_invalid @ 4 9831da177e4SLinus Torvalds .long __pabt_invalid @ 5 9841da177e4SLinus Torvalds .long __pabt_invalid @ 6 9851da177e4SLinus Torvalds .long __pabt_invalid @ 7 9861da177e4SLinus Torvalds .long __pabt_invalid @ 8 9871da177e4SLinus Torvalds .long __pabt_invalid @ 9 9881da177e4SLinus Torvalds .long __pabt_invalid @ a 9891da177e4SLinus Torvalds .long __pabt_invalid @ b 9901da177e4SLinus Torvalds .long __pabt_invalid @ c 9911da177e4SLinus Torvalds .long __pabt_invalid @ d 9921da177e4SLinus Torvalds .long __pabt_invalid @ e 9931da177e4SLinus Torvalds .long __pabt_invalid @ f 9941da177e4SLinus Torvalds 9951da177e4SLinus Torvalds/* 9961da177e4SLinus Torvalds * Undef instr entry dispatcher 9971da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 9981da177e4SLinus Torvalds */ 999b7ec4795SNicolas Pitre vector_stub und, UND_MODE 10001da177e4SLinus Torvalds 10011da177e4SLinus Torvalds .long __und_usr @ 0 (USR_26 / USR_32) 10021da177e4SLinus Torvalds .long __und_invalid @ 1 (FIQ_26 / FIQ_32) 10031da177e4SLinus Torvalds .long __und_invalid @ 2 (IRQ_26 / IRQ_32) 10041da177e4SLinus Torvalds .long __und_svc @ 3 (SVC_26 / SVC_32) 10051da177e4SLinus Torvalds .long __und_invalid @ 4 10061da177e4SLinus Torvalds .long __und_invalid @ 5 10071da177e4SLinus Torvalds .long __und_invalid @ 6 10081da177e4SLinus Torvalds .long __und_invalid @ 7 10091da177e4SLinus Torvalds .long __und_invalid @ 8 10101da177e4SLinus Torvalds .long __und_invalid @ 9 10111da177e4SLinus Torvalds .long __und_invalid @ a 10121da177e4SLinus Torvalds .long __und_invalid @ b 10131da177e4SLinus Torvalds .long __und_invalid @ c 10141da177e4SLinus Torvalds .long __und_invalid @ d 10151da177e4SLinus Torvalds .long __und_invalid @ e 10161da177e4SLinus Torvalds .long __und_invalid @ f 10171da177e4SLinus Torvalds 10181da177e4SLinus Torvalds .align 5 10191da177e4SLinus Torvalds 10201da177e4SLinus Torvalds/*============================================================================= 10211da177e4SLinus Torvalds * Undefined FIQs 10221da177e4SLinus Torvalds *----------------------------------------------------------------------------- 10231da177e4SLinus Torvalds * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC 10241da177e4SLinus Torvalds * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg. 10251da177e4SLinus Torvalds * Basically to switch modes, we *HAVE* to clobber one register... brain 10261da177e4SLinus Torvalds * damage alert! I don't think that we can execute any code in here in any 10271da177e4SLinus Torvalds * other mode than FIQ... Ok you can switch to another mode, but you can't 10281da177e4SLinus Torvalds * get out of that mode without clobbering one register. 10291da177e4SLinus Torvalds */ 10301da177e4SLinus Torvaldsvector_fiq: 10311da177e4SLinus Torvalds disable_fiq 10321da177e4SLinus Torvalds subs pc, lr, #4 10331da177e4SLinus Torvalds 10341da177e4SLinus Torvalds/*============================================================================= 10351da177e4SLinus Torvalds * Address exception handler 10361da177e4SLinus Torvalds *----------------------------------------------------------------------------- 10371da177e4SLinus Torvalds * These aren't too critical. 10381da177e4SLinus Torvalds * (they're not supposed to happen, and won't happen in 32-bit data mode). 10391da177e4SLinus Torvalds */ 10401da177e4SLinus Torvalds 10411da177e4SLinus Torvaldsvector_addrexcptn: 10421da177e4SLinus Torvalds b vector_addrexcptn 10431da177e4SLinus Torvalds 10441da177e4SLinus Torvalds/* 10451da177e4SLinus Torvalds * We group all the following data together to optimise 10461da177e4SLinus Torvalds * for CPUs with separate I & D caches. 10471da177e4SLinus Torvalds */ 10481da177e4SLinus Torvalds .align 5 10491da177e4SLinus Torvalds 10501da177e4SLinus Torvalds.LCvswi: 10511da177e4SLinus Torvalds .word vector_swi 10521da177e4SLinus Torvalds 10537933523dSRussell King .globl __stubs_end 10541da177e4SLinus Torvalds__stubs_end: 10551da177e4SLinus Torvalds 10567933523dSRussell King .equ stubs_offset, __vectors_start + 0x200 - __stubs_start 10571da177e4SLinus Torvalds 10587933523dSRussell King .globl __vectors_start 10597933523dSRussell King__vectors_start: 1060b86040a5SCatalin Marinas ARM( swi SYS_ERROR0 ) 1061b86040a5SCatalin Marinas THUMB( svc #0 ) 1062b86040a5SCatalin Marinas THUMB( nop ) 1063b86040a5SCatalin Marinas W(b) vector_und + stubs_offset 1064b86040a5SCatalin Marinas W(ldr) pc, .LCvswi + stubs_offset 1065b86040a5SCatalin Marinas W(b) vector_pabt + stubs_offset 1066b86040a5SCatalin Marinas W(b) vector_dabt + stubs_offset 1067b86040a5SCatalin Marinas W(b) vector_addrexcptn + stubs_offset 1068b86040a5SCatalin Marinas W(b) vector_irq + stubs_offset 1069b86040a5SCatalin Marinas W(b) vector_fiq + stubs_offset 10701da177e4SLinus Torvalds 10717933523dSRussell King .globl __vectors_end 10727933523dSRussell King__vectors_end: 10731da177e4SLinus Torvalds 10741da177e4SLinus Torvalds .data 10751da177e4SLinus Torvalds 10761da177e4SLinus Torvalds .globl cr_alignment 10771da177e4SLinus Torvalds .globl cr_no_alignment 10781da177e4SLinus Torvaldscr_alignment: 10791da177e4SLinus Torvalds .space 4 10801da177e4SLinus Torvaldscr_no_alignment: 10811da177e4SLinus Torvalds .space 4 108252108641Seric miao 108352108641Seric miao#ifdef CONFIG_MULTI_IRQ_HANDLER 108452108641Seric miao .globl handle_arch_irq 108552108641Seric miaohandle_arch_irq: 108652108641Seric miao .space 4 108752108641Seric miao#endif 1088