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 47ac8b9c1cSRussell King .macro pabt_helper 48ac8b9c1cSRussell King mov r0, r2 @ pass address of aborted instruction. 49ac8b9c1cSRussell King#ifdef MULTI_PABORT 50*0402beceSRussell King ldr ip, .LCprocfns 51ac8b9c1cSRussell King mov lr, pc 52*0402beceSRussell King ldr pc, [ip, #PROCESSOR_PABT_FUNC] 53ac8b9c1cSRussell King#else 54ac8b9c1cSRussell King bl CPU_PABORT_HANDLER 55ac8b9c1cSRussell King#endif 56ac8b9c1cSRussell King .endm 57ac8b9c1cSRussell King 58ac8b9c1cSRussell King .macro dabt_helper 59ac8b9c1cSRussell King 60ac8b9c1cSRussell King @ 61ac8b9c1cSRussell King @ Call the processor-specific abort handler: 62ac8b9c1cSRussell King @ 63ac8b9c1cSRussell King @ r2 - aborted context pc 64ac8b9c1cSRussell King @ r3 - aborted context cpsr 65ac8b9c1cSRussell King @ 66ac8b9c1cSRussell King @ The abort handler must return the aborted address in r0, and 67ac8b9c1cSRussell King @ the fault status register in r1. r9 must be preserved. 68ac8b9c1cSRussell King @ 69ac8b9c1cSRussell King#ifdef MULTI_DABORT 70*0402beceSRussell King ldr ip, .LCprocfns 71ac8b9c1cSRussell King mov lr, pc 72*0402beceSRussell King ldr pc, [ip, #PROCESSOR_DABT_FUNC] 73ac8b9c1cSRussell King#else 74ac8b9c1cSRussell King bl CPU_DABORT_HANDLER 75ac8b9c1cSRussell King#endif 76ac8b9c1cSRussell King .endm 77ac8b9c1cSRussell King 78785d3cd2SNicolas Pitre#ifdef CONFIG_KPROBES 79785d3cd2SNicolas Pitre .section .kprobes.text,"ax",%progbits 80785d3cd2SNicolas Pitre#else 81785d3cd2SNicolas Pitre .text 82785d3cd2SNicolas Pitre#endif 83785d3cd2SNicolas Pitre 84187a51adSRussell King/* 851da177e4SLinus Torvalds * Invalid mode handlers 861da177e4SLinus Torvalds */ 87ccea7a19SRussell King .macro inv_entry, reason 88ccea7a19SRussell King sub sp, sp, #S_FRAME_SIZE 89b86040a5SCatalin Marinas ARM( stmib sp, {r1 - lr} ) 90b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 91b86040a5SCatalin Marinas THUMB( str sp, [sp, #S_SP] ) 92b86040a5SCatalin Marinas THUMB( str lr, [sp, #S_LR] ) 931da177e4SLinus Torvalds mov r1, #\reason 941da177e4SLinus Torvalds .endm 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds__pabt_invalid: 97ccea7a19SRussell King inv_entry BAD_PREFETCH 98ccea7a19SRussell King b common_invalid 9993ed3970SCatalin MarinasENDPROC(__pabt_invalid) 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds__dabt_invalid: 102ccea7a19SRussell King inv_entry BAD_DATA 103ccea7a19SRussell King b common_invalid 10493ed3970SCatalin MarinasENDPROC(__dabt_invalid) 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds__irq_invalid: 107ccea7a19SRussell King inv_entry BAD_IRQ 108ccea7a19SRussell King b common_invalid 10993ed3970SCatalin MarinasENDPROC(__irq_invalid) 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds__und_invalid: 112ccea7a19SRussell King inv_entry BAD_UNDEFINSTR 1131da177e4SLinus Torvalds 114ccea7a19SRussell King @ 115ccea7a19SRussell King @ XXX fall through to common_invalid 116ccea7a19SRussell King @ 117ccea7a19SRussell King 118ccea7a19SRussell King@ 119ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers) 120ccea7a19SRussell King@ 121ccea7a19SRussell Kingcommon_invalid: 122ccea7a19SRussell King zero_fp 123ccea7a19SRussell King 124ccea7a19SRussell King ldmia r0, {r4 - r6} 125ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 126ccea7a19SRussell King mov r7, #-1 @ "" "" "" "" 127ccea7a19SRussell King str r4, [sp] @ save preserved r0 128ccea7a19SRussell King stmia r0, {r5 - r7} @ lr_<exception>, 129ccea7a19SRussell King @ cpsr_<exception>, "old_r0" 130ccea7a19SRussell King 1311da177e4SLinus Torvalds mov r0, sp 1321da177e4SLinus Torvalds b bad_mode 13393ed3970SCatalin MarinasENDPROC(__und_invalid) 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds/* 1361da177e4SLinus Torvalds * SVC mode handlers 1371da177e4SLinus Torvalds */ 1382dede2d8SNicolas Pitre 1392dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) 1402dede2d8SNicolas Pitre#define SPFIX(code...) code 1412dede2d8SNicolas Pitre#else 1422dede2d8SNicolas Pitre#define SPFIX(code...) 1432dede2d8SNicolas Pitre#endif 1442dede2d8SNicolas Pitre 145d30a0c8bSNicolas Pitre .macro svc_entry, stack_hole=0 146c4c5716eSCatalin Marinas UNWIND(.fnstart ) 147c4c5716eSCatalin Marinas UNWIND(.save {r0 - pc} ) 148b86040a5SCatalin Marinas sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4) 149b86040a5SCatalin Marinas#ifdef CONFIG_THUMB2_KERNEL 150b86040a5SCatalin Marinas SPFIX( str r0, [sp] ) @ temporarily saved 151b86040a5SCatalin Marinas SPFIX( mov r0, sp ) 152b86040a5SCatalin Marinas SPFIX( tst r0, #4 ) @ test original stack alignment 153b86040a5SCatalin Marinas SPFIX( ldr r0, [sp] ) @ restored 154b86040a5SCatalin Marinas#else 1552dede2d8SNicolas Pitre SPFIX( tst sp, #4 ) 156b86040a5SCatalin Marinas#endif 157b86040a5SCatalin Marinas SPFIX( subeq sp, sp, #4 ) 158b86040a5SCatalin Marinas stmia sp, {r1 - r12} 159ccea7a19SRussell King 160ccea7a19SRussell King ldmia r0, {r1 - r3} 161b86040a5SCatalin Marinas add r5, sp, #S_SP - 4 @ here for interlock avoidance 162ccea7a19SRussell King mov r4, #-1 @ "" "" "" "" 163b86040a5SCatalin Marinas add r0, sp, #(S_FRAME_SIZE + \stack_hole - 4) 164b86040a5SCatalin Marinas SPFIX( addeq r0, r0, #4 ) 165b86040a5SCatalin Marinas str r1, [sp, #-4]! @ save the "real" r0 copied 166ccea7a19SRussell King @ from the exception stack 167ccea7a19SRussell King 1681da177e4SLinus Torvalds mov r1, lr 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds @ 1711da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 1721da177e4SLinus Torvalds @ 1731da177e4SLinus Torvalds @ r0 - sp_svc 1741da177e4SLinus Torvalds @ r1 - lr_svc 1751da177e4SLinus Torvalds @ r2 - lr_<exception>, already fixed up for correct return/restart 1761da177e4SLinus Torvalds @ r3 - spsr_<exception> 1771da177e4SLinus Torvalds @ r4 - orig_r0 (see pt_regs definition in ptrace.h) 1781da177e4SLinus Torvalds @ 1791da177e4SLinus Torvalds stmia r5, {r0 - r4} 1801da177e4SLinus Torvalds .endm 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds .align 5 1831da177e4SLinus Torvalds__dabt_svc: 184ccea7a19SRussell King svc_entry 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds @ 1871da177e4SLinus Torvalds @ get ready to re-enable interrupts if appropriate 1881da177e4SLinus Torvalds @ 1891da177e4SLinus Torvalds mrs r9, cpsr 1901da177e4SLinus Torvalds tst r3, #PSR_I_BIT 1911da177e4SLinus Torvalds biceq r9, r9, #PSR_I_BIT 1921da177e4SLinus Torvalds 193ac8b9c1cSRussell King dabt_helper 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds @ 1961da177e4SLinus Torvalds @ set desired IRQ state, then call main handler 1971da177e4SLinus Torvalds @ 1987e202696SWill Deacon debug_entry r1 1991da177e4SLinus Torvalds msr cpsr_c, r9 2001da177e4SLinus Torvalds mov r2, sp 2011da177e4SLinus Torvalds bl do_DataAbort 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds @ 2041da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 2051da177e4SLinus Torvalds @ 206ac78884eSRussell King disable_irq_notrace 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds @ 2091da177e4SLinus Torvalds @ restore SPSR and restart the instruction 2101da177e4SLinus Torvalds @ 211b86040a5SCatalin Marinas ldr r2, [sp, #S_PSR] 212b86040a5SCatalin Marinas svc_exit r2 @ return from exception 213c4c5716eSCatalin Marinas UNWIND(.fnend ) 21493ed3970SCatalin MarinasENDPROC(__dabt_svc) 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds .align 5 2171da177e4SLinus Torvalds__irq_svc: 218ccea7a19SRussell King svc_entry 219ccea7a19SRussell King 220ac78884eSRussell King#ifdef CONFIG_TRACE_IRQFLAGS 221ac78884eSRussell King bl trace_hardirqs_off 222ac78884eSRussell King#endif 2231da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 224706fdd9fSRussell King get_thread_info tsk 225706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 226706fdd9fSRussell King add r7, r8, #1 @ increment it 227706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] 2281da177e4SLinus Torvalds#endif 229ccea7a19SRussell King 230187a51adSRussell King irq_handler 2311da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 23228fab1a2SRussell King str r8, [tsk, #TI_PREEMPT] @ restore preempt count 233706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get flags 23428fab1a2SRussell King teq r8, #0 @ if preempt count != 0 23528fab1a2SRussell King movne r0, #0 @ force flags to 0 2361da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 2371da177e4SLinus Torvalds blne svc_preempt 2381da177e4SLinus Torvalds#endif 239b86040a5SCatalin Marinas ldr r4, [sp, #S_PSR] @ irqs are already disabled 2407ad1bcb2SRussell King#ifdef CONFIG_TRACE_IRQFLAGS 241b86040a5SCatalin Marinas tst r4, #PSR_I_BIT 2427ad1bcb2SRussell King bleq trace_hardirqs_on 2437ad1bcb2SRussell King#endif 244b86040a5SCatalin Marinas svc_exit r4 @ return from exception 245c4c5716eSCatalin Marinas UNWIND(.fnend ) 24693ed3970SCatalin MarinasENDPROC(__irq_svc) 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds .ltorg 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 2511da177e4SLinus Torvaldssvc_preempt: 25228fab1a2SRussell King mov r8, lr 2531da177e4SLinus Torvalds1: bl preempt_schedule_irq @ irq en/disable is done inside 254706fdd9fSRussell King ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS 2551da177e4SLinus Torvalds tst r0, #_TIF_NEED_RESCHED 25628fab1a2SRussell King moveq pc, r8 @ go again 2571da177e4SLinus Torvalds b 1b 2581da177e4SLinus Torvalds#endif 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds .align 5 2611da177e4SLinus Torvalds__und_svc: 262d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES 263d30a0c8bSNicolas Pitre @ If a kprobe is about to simulate a "stmdb sp..." instruction, 264d30a0c8bSNicolas Pitre @ it obviously needs free stack space which then will belong to 265d30a0c8bSNicolas Pitre @ the saved context. 266d30a0c8bSNicolas Pitre svc_entry 64 267d30a0c8bSNicolas Pitre#else 268ccea7a19SRussell King svc_entry 269d30a0c8bSNicolas Pitre#endif 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds @ 2721da177e4SLinus Torvalds @ call emulation code, which returns using r9 if it has emulated 2731da177e4SLinus Torvalds @ the instruction, or the more conventional lr if we are to treat 2741da177e4SLinus Torvalds @ this as a real undefined instruction 2751da177e4SLinus Torvalds @ 2761da177e4SLinus Torvalds @ r0 - instruction 2771da177e4SLinus Torvalds @ 27883e686eaSCatalin Marinas#ifndef CONFIG_THUMB2_KERNEL 2791da177e4SLinus Torvalds ldr r0, [r2, #-4] 28083e686eaSCatalin Marinas#else 28183e686eaSCatalin Marinas ldrh r0, [r2, #-2] @ Thumb instruction at LR - 2 28283e686eaSCatalin Marinas and r9, r0, #0xf800 28383e686eaSCatalin Marinas cmp r9, #0xe800 @ 32-bit instruction if xx >= 0 28483e686eaSCatalin Marinas ldrhhs r9, [r2] @ bottom 16 bits 28583e686eaSCatalin Marinas orrhs r0, r9, r0, lsl #16 28683e686eaSCatalin Marinas#endif 287b86040a5SCatalin Marinas adr r9, BSYM(1f) 2881da177e4SLinus Torvalds bl call_fpe 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds mov r0, sp @ struct pt_regs *regs 2911da177e4SLinus Torvalds bl do_undefinstr 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds @ 2941da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 2951da177e4SLinus Torvalds @ 296ac78884eSRussell King1: disable_irq_notrace 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds @ 2991da177e4SLinus Torvalds @ restore SPSR and restart the instruction 3001da177e4SLinus Torvalds @ 301b86040a5SCatalin Marinas ldr r2, [sp, #S_PSR] @ Get SVC cpsr 302b86040a5SCatalin Marinas svc_exit r2 @ return from exception 303c4c5716eSCatalin Marinas UNWIND(.fnend ) 30493ed3970SCatalin MarinasENDPROC(__und_svc) 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds .align 5 3071da177e4SLinus Torvalds__pabt_svc: 308ccea7a19SRussell King svc_entry 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds @ 3111da177e4SLinus Torvalds @ re-enable interrupts if appropriate 3121da177e4SLinus Torvalds @ 3131da177e4SLinus Torvalds mrs r9, cpsr 3141da177e4SLinus Torvalds tst r3, #PSR_I_BIT 3151da177e4SLinus Torvalds biceq r9, r9, #PSR_I_BIT 3161da177e4SLinus Torvalds 317ac8b9c1cSRussell King pabt_helper 3187e202696SWill Deacon debug_entry r1 31948d7927bSPaul Brook msr cpsr_c, r9 @ Maybe enable interrupts 3204fb28474SKirill A. Shutemov mov r2, sp @ regs 3211da177e4SLinus Torvalds bl do_PrefetchAbort @ call abort handler 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds @ 3241da177e4SLinus Torvalds @ IRQs off again before pulling preserved data off the stack 3251da177e4SLinus Torvalds @ 326ac78884eSRussell King disable_irq_notrace 3271da177e4SLinus Torvalds 3281da177e4SLinus Torvalds @ 3291da177e4SLinus Torvalds @ restore SPSR and restart the instruction 3301da177e4SLinus Torvalds @ 331b86040a5SCatalin Marinas ldr r2, [sp, #S_PSR] 332b86040a5SCatalin Marinas svc_exit r2 @ return from exception 333c4c5716eSCatalin Marinas UNWIND(.fnend ) 33493ed3970SCatalin MarinasENDPROC(__pabt_svc) 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds .align 5 33749f680eaSRussell King.LCcralign: 33849f680eaSRussell King .word cr_alignment 33948d7927bSPaul Brook#ifdef MULTI_DABORT 3401da177e4SLinus Torvalds.LCprocfns: 3411da177e4SLinus Torvalds .word processor 3421da177e4SLinus Torvalds#endif 3431da177e4SLinus Torvalds.LCfp: 3441da177e4SLinus Torvalds .word fp_enter 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds/* 3471da177e4SLinus Torvalds * User mode handlers 3482dede2d8SNicolas Pitre * 3492dede2d8SNicolas Pitre * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE 3501da177e4SLinus Torvalds */ 3512dede2d8SNicolas Pitre 3522dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7) 3532dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8" 3542dede2d8SNicolas Pitre#endif 3552dede2d8SNicolas Pitre 356ccea7a19SRussell King .macro usr_entry 357c4c5716eSCatalin Marinas UNWIND(.fnstart ) 358c4c5716eSCatalin Marinas UNWIND(.cantunwind ) @ don't unwind the user space 359ccea7a19SRussell King sub sp, sp, #S_FRAME_SIZE 360b86040a5SCatalin Marinas ARM( stmib sp, {r1 - r12} ) 361b86040a5SCatalin Marinas THUMB( stmia sp, {r0 - r12} ) 362ccea7a19SRussell King 363ccea7a19SRussell King ldmia r0, {r1 - r3} 364ccea7a19SRussell King add r0, sp, #S_PC @ here for interlock avoidance 365ccea7a19SRussell King mov r4, #-1 @ "" "" "" "" 366ccea7a19SRussell King 367ccea7a19SRussell King str r1, [sp] @ save the "real" r0 copied 368ccea7a19SRussell King @ from the exception stack 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds @ 3711da177e4SLinus Torvalds @ We are now ready to fill in the remaining blanks on the stack: 3721da177e4SLinus Torvalds @ 3731da177e4SLinus Torvalds @ r2 - lr_<exception>, already fixed up for correct return/restart 3741da177e4SLinus Torvalds @ r3 - spsr_<exception> 3751da177e4SLinus Torvalds @ r4 - orig_r0 (see pt_regs definition in ptrace.h) 3761da177e4SLinus Torvalds @ 3771da177e4SLinus Torvalds @ Also, separately save sp_usr and lr_usr 3781da177e4SLinus Torvalds @ 379ccea7a19SRussell King stmia r0, {r2 - r4} 380b86040a5SCatalin Marinas ARM( stmdb r0, {sp, lr}^ ) 381b86040a5SCatalin Marinas THUMB( store_user_sp_lr r0, r1, S_SP - S_PC ) 3821da177e4SLinus Torvalds 3831da177e4SLinus Torvalds @ 3841da177e4SLinus Torvalds @ Enable the alignment trap while in kernel mode 3851da177e4SLinus Torvalds @ 38649f680eaSRussell King alignment_trap r0 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds @ 3891da177e4SLinus Torvalds @ Clear FP to mark the first stack frame 3901da177e4SLinus Torvalds @ 3911da177e4SLinus Torvalds zero_fp 3921da177e4SLinus Torvalds .endm 3931da177e4SLinus Torvalds 394b49c0f24SNicolas Pitre .macro kuser_cmpxchg_check 395b49c0f24SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG) 396b49c0f24SNicolas Pitre#ifndef CONFIG_MMU 397b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing" 398b49c0f24SNicolas Pitre#else 399b49c0f24SNicolas Pitre @ Make sure our user space atomic helper is restarted 400b49c0f24SNicolas Pitre @ if it was interrupted in a critical region. Here we 401b49c0f24SNicolas Pitre @ perform a quick test inline since it should be false 402b49c0f24SNicolas Pitre @ 99.9999% of the time. The rest is done out of line. 403b49c0f24SNicolas Pitre cmp r2, #TASK_SIZE 404b49c0f24SNicolas Pitre blhs kuser_cmpxchg_fixup 405b49c0f24SNicolas Pitre#endif 406b49c0f24SNicolas Pitre#endif 407b49c0f24SNicolas Pitre .endm 408b49c0f24SNicolas Pitre 4091da177e4SLinus Torvalds .align 5 4101da177e4SLinus Torvalds__dabt_usr: 411ccea7a19SRussell King usr_entry 412b49c0f24SNicolas Pitre kuser_cmpxchg_check 413ac8b9c1cSRussell King dabt_helper 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds @ 4161da177e4SLinus Torvalds @ IRQs on, then call the main handler 4171da177e4SLinus Torvalds @ 4187e202696SWill Deacon debug_entry r1 4191ec42c0cSRussell King enable_irq 4201da177e4SLinus Torvalds mov r2, sp 421b86040a5SCatalin Marinas adr lr, BSYM(ret_from_exception) 4221da177e4SLinus Torvalds b do_DataAbort 423c4c5716eSCatalin Marinas UNWIND(.fnend ) 42493ed3970SCatalin MarinasENDPROC(__dabt_usr) 4251da177e4SLinus Torvalds 4261da177e4SLinus Torvalds .align 5 4271da177e4SLinus Torvalds__irq_usr: 428ccea7a19SRussell King usr_entry 429b49c0f24SNicolas Pitre kuser_cmpxchg_check 4301da177e4SLinus Torvalds 4319fc2552aSMing Lei#ifdef CONFIG_IRQSOFF_TRACER 4329fc2552aSMing Lei bl trace_hardirqs_off 4339fc2552aSMing Lei#endif 4349fc2552aSMing Lei 4351da177e4SLinus Torvalds get_thread_info tsk 4361da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 437706fdd9fSRussell King ldr r8, [tsk, #TI_PREEMPT] @ get preempt count 438706fdd9fSRussell King add r7, r8, #1 @ increment it 439706fdd9fSRussell King str r7, [tsk, #TI_PREEMPT] 4401da177e4SLinus Torvalds#endif 441ccea7a19SRussell King 442187a51adSRussell King irq_handler 4431da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT 444706fdd9fSRussell King ldr r0, [tsk, #TI_PREEMPT] 445706fdd9fSRussell King str r8, [tsk, #TI_PREEMPT] 4461da177e4SLinus Torvalds teq r0, r7 447b86040a5SCatalin Marinas ARM( strne r0, [r0, -r0] ) 448b86040a5SCatalin Marinas THUMB( movne r0, #0 ) 449b86040a5SCatalin Marinas THUMB( strne r0, [r0] ) 4501da177e4SLinus Torvalds#endif 451ccea7a19SRussell King 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: 461ccea7a19SRussell King usr_entry 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds @ 4641da177e4SLinus Torvalds @ fall through to the emulation code, which returns using r9 if 4651da177e4SLinus Torvalds @ it has emulated the instruction, or the more conventional lr 4661da177e4SLinus Torvalds @ if we are to treat this as a real undefined instruction 4671da177e4SLinus Torvalds @ 4681da177e4SLinus Torvalds @ r0 - instruction 4691da177e4SLinus Torvalds @ 470b86040a5SCatalin Marinas adr r9, BSYM(ret_from_exception) 471b86040a5SCatalin Marinas adr lr, BSYM(__und_usr_unknown) 472cb170a45SPaul Brook tst r3, #PSR_T_BIT @ Thumb mode? 473b86040a5SCatalin Marinas itet eq @ explicit IT needed for the 1f label 474cb170a45SPaul Brook subeq r4, r2, #4 @ ARM instr at LR - 4 475cb170a45SPaul Brook subne r4, r2, #2 @ Thumb instr at LR - 2 476cb170a45SPaul Brook1: ldreqt r0, [r4] 47726584853SCatalin Marinas#ifdef CONFIG_CPU_ENDIAN_BE8 47826584853SCatalin Marinas reveq r0, r0 @ little endian instruction 47926584853SCatalin Marinas#endif 480cb170a45SPaul Brook beq call_fpe 481cb170a45SPaul Brook @ Thumb instruction 482cb170a45SPaul Brook#if __LINUX_ARM_ARCH__ >= 7 483b86040a5SCatalin Marinas2: 484b86040a5SCatalin Marinas ARM( ldrht r5, [r4], #2 ) 485b86040a5SCatalin Marinas THUMB( ldrht r5, [r4] ) 486b86040a5SCatalin Marinas THUMB( add r4, r4, #2 ) 487cb170a45SPaul Brook and r0, r5, #0xf800 @ mask bits 111x x... .... .... 488cb170a45SPaul Brook cmp r0, #0xe800 @ 32bit instruction if xx != 0 489cb170a45SPaul Brook blo __und_usr_unknown 490cb170a45SPaul Brook3: ldrht r0, [r4] 491cb170a45SPaul Brook add r2, r2, #2 @ r2 is PC + 2, make it PC + 4 492cb170a45SPaul Brook orr r0, r0, r5, lsl #16 493cb170a45SPaul Brook#else 494cb170a45SPaul Brook b __und_usr_unknown 495cb170a45SPaul Brook#endif 496c4c5716eSCatalin Marinas UNWIND(.fnend ) 49793ed3970SCatalin MarinasENDPROC(__und_usr) 498cb170a45SPaul Brook 4991da177e4SLinus Torvalds @ 5001da177e4SLinus Torvalds @ fallthrough to call_fpe 5011da177e4SLinus Torvalds @ 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds/* 5041da177e4SLinus Torvalds * The out of line fixup for the ldrt above. 5051da177e4SLinus Torvalds */ 5064260415fSRussell King .pushsection .fixup, "ax" 507cb170a45SPaul Brook4: mov pc, r9 5084260415fSRussell King .popsection 5094260415fSRussell King .pushsection __ex_table,"a" 510cb170a45SPaul Brook .long 1b, 4b 511cb170a45SPaul Brook#if __LINUX_ARM_ARCH__ >= 7 512cb170a45SPaul Brook .long 2b, 4b 513cb170a45SPaul Brook .long 3b, 4b 514cb170a45SPaul Brook#endif 5154260415fSRussell King .popsection 5161da177e4SLinus Torvalds 5171da177e4SLinus Torvalds/* 5181da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction. 5191da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler. 5201da177e4SLinus Torvalds * 5211da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor 5221da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well 5231da177e4SLinus Torvalds * defined. The only instructions that should fault are the 5241da177e4SLinus Torvalds * co-processor instructions. However, we have to watch out 5251da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug. 5261da177e4SLinus Torvalds * 527b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all 528b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have 529b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's 530b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs 531b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the 532b5872db4SCatalin Marinas * NEON handler code. 533b5872db4SCatalin Marinas * 5341da177e4SLinus Torvalds * Emulators may wish to make use of the following registers: 5351da177e4SLinus Torvalds * r0 = instruction opcode. 5361da177e4SLinus Torvalds * r2 = PC+4 537db6ccbb6SRussell King * r9 = normal "successful" return address 5381da177e4SLinus Torvalds * r10 = this threads thread_info structure. 539db6ccbb6SRussell King * lr = unrecognised instruction return address 5401da177e4SLinus Torvalds */ 541cb170a45SPaul Brook @ 542cb170a45SPaul Brook @ Fall-through from Thumb-2 __und_usr 543cb170a45SPaul Brook @ 544cb170a45SPaul Brook#ifdef CONFIG_NEON 545cb170a45SPaul Brook adr r6, .LCneon_thumb_opcodes 546cb170a45SPaul Brook b 2f 547cb170a45SPaul Brook#endif 5481da177e4SLinus Torvaldscall_fpe: 549b5872db4SCatalin Marinas#ifdef CONFIG_NEON 550cb170a45SPaul Brook adr r6, .LCneon_arm_opcodes 551b5872db4SCatalin Marinas2: 552b5872db4SCatalin Marinas ldr r7, [r6], #4 @ mask value 553b5872db4SCatalin Marinas cmp r7, #0 @ end mask? 554b5872db4SCatalin Marinas beq 1f 555b5872db4SCatalin Marinas and r8, r0, r7 556b5872db4SCatalin Marinas ldr r7, [r6], #4 @ opcode bits matching in mask 557b5872db4SCatalin Marinas cmp r8, r7 @ NEON instruction? 558b5872db4SCatalin Marinas bne 2b 559b5872db4SCatalin Marinas get_thread_info r10 560b5872db4SCatalin Marinas mov r7, #1 561b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used 562b5872db4SCatalin Marinas strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used 563b5872db4SCatalin Marinas b do_vfp @ let VFP handler handle this 564b5872db4SCatalin Marinas1: 565b5872db4SCatalin Marinas#endif 5661da177e4SLinus Torvalds tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27 567cb170a45SPaul Brook tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2 5681da177e4SLinus Torvalds#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710) 5691da177e4SLinus Torvalds and r8, r0, #0x0f000000 @ mask out op-code bits 5701da177e4SLinus Torvalds teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)? 5711da177e4SLinus Torvalds#endif 5721da177e4SLinus Torvalds moveq pc, lr 5731da177e4SLinus Torvalds get_thread_info r10 @ get current thread 5741da177e4SLinus Torvalds and r8, r0, #0x00000f00 @ mask out CP number 575b86040a5SCatalin Marinas THUMB( lsr r8, r8, #8 ) 5761da177e4SLinus Torvalds mov r7, #1 5771da177e4SLinus Torvalds add r6, r10, #TI_USED_CP 578b86040a5SCatalin Marinas ARM( strb r7, [r6, r8, lsr #8] ) @ set appropriate used_cp[] 579b86040a5SCatalin Marinas THUMB( strb r7, [r6, r8] ) @ set appropriate used_cp[] 5801da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT 5811da177e4SLinus Torvalds @ Test if we need to give access to iWMMXt coprocessors 5821da177e4SLinus Torvalds ldr r5, [r10, #TI_FLAGS] 5831da177e4SLinus Torvalds rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only 5841da177e4SLinus Torvalds movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1) 5851da177e4SLinus Torvalds bcs iwmmxt_task_enable 5861da177e4SLinus Torvalds#endif 587b86040a5SCatalin Marinas ARM( add pc, pc, r8, lsr #6 ) 588b86040a5SCatalin Marinas THUMB( lsl r8, r8, #2 ) 589b86040a5SCatalin Marinas THUMB( add pc, r8 ) 590b86040a5SCatalin Marinas nop 5911da177e4SLinus Torvalds 592a771fe6eSCatalin Marinas movw_pc lr @ CP#0 593b86040a5SCatalin Marinas W(b) do_fpe @ CP#1 (FPE) 594b86040a5SCatalin Marinas W(b) do_fpe @ CP#2 (FPE) 595a771fe6eSCatalin Marinas movw_pc lr @ CP#3 596c17fad11SLennert Buytenhek#ifdef CONFIG_CRUNCH 597c17fad11SLennert Buytenhek b crunch_task_enable @ CP#4 (MaverickCrunch) 598c17fad11SLennert Buytenhek b crunch_task_enable @ CP#5 (MaverickCrunch) 599c17fad11SLennert Buytenhek b crunch_task_enable @ CP#6 (MaverickCrunch) 600c17fad11SLennert Buytenhek#else 601a771fe6eSCatalin Marinas movw_pc lr @ CP#4 602a771fe6eSCatalin Marinas movw_pc lr @ CP#5 603a771fe6eSCatalin Marinas movw_pc lr @ CP#6 604c17fad11SLennert Buytenhek#endif 605a771fe6eSCatalin Marinas movw_pc lr @ CP#7 606a771fe6eSCatalin Marinas movw_pc lr @ CP#8 607a771fe6eSCatalin Marinas movw_pc lr @ CP#9 6081da177e4SLinus Torvalds#ifdef CONFIG_VFP 609b86040a5SCatalin Marinas W(b) do_vfp @ CP#10 (VFP) 610b86040a5SCatalin Marinas W(b) do_vfp @ CP#11 (VFP) 6111da177e4SLinus Torvalds#else 612a771fe6eSCatalin Marinas movw_pc lr @ CP#10 (VFP) 613a771fe6eSCatalin Marinas movw_pc lr @ CP#11 (VFP) 6141da177e4SLinus Torvalds#endif 615a771fe6eSCatalin Marinas movw_pc lr @ CP#12 616a771fe6eSCatalin Marinas movw_pc lr @ CP#13 617a771fe6eSCatalin Marinas movw_pc lr @ CP#14 (Debug) 618a771fe6eSCatalin Marinas movw_pc lr @ CP#15 (Control) 6191da177e4SLinus Torvalds 620b5872db4SCatalin Marinas#ifdef CONFIG_NEON 621b5872db4SCatalin Marinas .align 6 622b5872db4SCatalin Marinas 623cb170a45SPaul Brook.LCneon_arm_opcodes: 624b5872db4SCatalin Marinas .word 0xfe000000 @ mask 625b5872db4SCatalin Marinas .word 0xf2000000 @ opcode 626b5872db4SCatalin Marinas 627b5872db4SCatalin Marinas .word 0xff100000 @ mask 628b5872db4SCatalin Marinas .word 0xf4000000 @ opcode 629b5872db4SCatalin Marinas 630b5872db4SCatalin Marinas .word 0x00000000 @ mask 631b5872db4SCatalin Marinas .word 0x00000000 @ opcode 632cb170a45SPaul Brook 633cb170a45SPaul Brook.LCneon_thumb_opcodes: 634cb170a45SPaul Brook .word 0xef000000 @ mask 635cb170a45SPaul Brook .word 0xef000000 @ opcode 636cb170a45SPaul Brook 637cb170a45SPaul Brook .word 0xff100000 @ mask 638cb170a45SPaul Brook .word 0xf9000000 @ opcode 639cb170a45SPaul Brook 640cb170a45SPaul Brook .word 0x00000000 @ mask 641cb170a45SPaul Brook .word 0x00000000 @ opcode 642b5872db4SCatalin Marinas#endif 643b5872db4SCatalin Marinas 6441da177e4SLinus Torvaldsdo_fpe: 6455d25ac03SRussell King enable_irq 6461da177e4SLinus Torvalds ldr r4, .LCfp 6471da177e4SLinus Torvalds add r10, r10, #TI_FPSTATE @ r10 = workspace 6481da177e4SLinus Torvalds ldr pc, [r4] @ Call FP module USR entry point 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds/* 6511da177e4SLinus Torvalds * The FP module is called with these registers set: 6521da177e4SLinus Torvalds * r0 = instruction 6531da177e4SLinus Torvalds * r2 = PC+4 6541da177e4SLinus Torvalds * r9 = normal "successful" return address 6551da177e4SLinus Torvalds * r10 = FP workspace 6561da177e4SLinus Torvalds * lr = unrecognised FP instruction return address 6571da177e4SLinus Torvalds */ 6581da177e4SLinus Torvalds 659124efc27SSantosh Shilimkar .pushsection .data 6601da177e4SLinus TorvaldsENTRY(fp_enter) 661db6ccbb6SRussell King .word no_fp 662124efc27SSantosh Shilimkar .popsection 6631da177e4SLinus Torvalds 66483e686eaSCatalin MarinasENTRY(no_fp) 66583e686eaSCatalin Marinas mov pc, lr 66683e686eaSCatalin MarinasENDPROC(no_fp) 667db6ccbb6SRussell King 668db6ccbb6SRussell King__und_usr_unknown: 669ecbab71cSRussell King enable_irq 6701da177e4SLinus Torvalds mov r0, sp 671b86040a5SCatalin Marinas adr lr, BSYM(ret_from_exception) 6721da177e4SLinus Torvalds b do_undefinstr 67393ed3970SCatalin MarinasENDPROC(__und_usr_unknown) 6741da177e4SLinus Torvalds 6751da177e4SLinus Torvalds .align 5 6761da177e4SLinus Torvalds__pabt_usr: 677ccea7a19SRussell King usr_entry 678ac8b9c1cSRussell King pabt_helper 6797e202696SWill Deacon debug_entry r1 6801ec42c0cSRussell King enable_irq @ Enable interrupts 6814fb28474SKirill A. Shutemov mov r2, sp @ regs 6821da177e4SLinus Torvalds bl do_PrefetchAbort @ call abort handler 683c4c5716eSCatalin Marinas UNWIND(.fnend ) 6841da177e4SLinus Torvalds /* fall through */ 6851da177e4SLinus Torvalds/* 6861da177e4SLinus Torvalds * This is the return code to user mode for abort handlers 6871da177e4SLinus Torvalds */ 6881da177e4SLinus TorvaldsENTRY(ret_from_exception) 689c4c5716eSCatalin Marinas UNWIND(.fnstart ) 690c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 6911da177e4SLinus Torvalds get_thread_info tsk 6921da177e4SLinus Torvalds mov why, #0 6931da177e4SLinus Torvalds b ret_to_user 694c4c5716eSCatalin Marinas UNWIND(.fnend ) 69593ed3970SCatalin MarinasENDPROC(__pabt_usr) 69693ed3970SCatalin MarinasENDPROC(ret_from_exception) 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds/* 6991da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors 7001da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info 7011da177e4SLinus Torvalds * previous and next are guaranteed not to be the same. 7021da177e4SLinus Torvalds */ 7031da177e4SLinus TorvaldsENTRY(__switch_to) 704c4c5716eSCatalin Marinas UNWIND(.fnstart ) 705c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 7061da177e4SLinus Torvalds add ip, r1, #TI_CPU_SAVE 7071da177e4SLinus Torvalds ldr r3, [r2, #TI_TP_VALUE] 708b86040a5SCatalin Marinas ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack 709b86040a5SCatalin Marinas THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack 710b86040a5SCatalin Marinas THUMB( str sp, [ip], #4 ) 711b86040a5SCatalin Marinas THUMB( str lr, [ip], #4 ) 712247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 713d6551e88SRussell King ldr r6, [r2, #TI_CPU_DOMAIN] 714afeb90caSHyok S. Choi#endif 715f159f4edSTony Lindgren set_tls r3, r4, r5 716df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP) 717df0698beSNicolas Pitre ldr r7, [r2, #TI_TASK] 718df0698beSNicolas Pitre ldr r8, =__stack_chk_guard 719df0698beSNicolas Pitre ldr r7, [r7, #TSK_STACK_CANARY] 720df0698beSNicolas Pitre#endif 721247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS 7221da177e4SLinus Torvalds mcr p15, 0, r6, c3, c0, 0 @ Set domain register 723afeb90caSHyok S. Choi#endif 724d6551e88SRussell King mov r5, r0 725d6551e88SRussell King add r4, r2, #TI_CPU_SAVE 726d6551e88SRussell King ldr r0, =thread_notify_head 727d6551e88SRussell King mov r1, #THREAD_NOTIFY_SWITCH 728d6551e88SRussell King bl atomic_notifier_call_chain 729df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP) 730df0698beSNicolas Pitre str r7, [r8] 731df0698beSNicolas Pitre#endif 732b86040a5SCatalin Marinas THUMB( mov ip, r4 ) 733d6551e88SRussell King mov r0, r5 734b86040a5SCatalin Marinas ARM( ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previously 735b86040a5SCatalin Marinas THUMB( ldmia ip!, {r4 - sl, fp} ) @ Load all regs saved previously 736b86040a5SCatalin Marinas THUMB( ldr sp, [ip], #4 ) 737b86040a5SCatalin Marinas THUMB( ldr pc, [ip] ) 738c4c5716eSCatalin Marinas UNWIND(.fnend ) 73993ed3970SCatalin MarinasENDPROC(__switch_to) 7401da177e4SLinus Torvalds 7411da177e4SLinus Torvalds __INIT 7422d2669b6SNicolas Pitre 7432d2669b6SNicolas Pitre/* 7442d2669b6SNicolas Pitre * User helpers. 7452d2669b6SNicolas Pitre * 7462d2669b6SNicolas Pitre * These are segment of kernel provided user code reachable from user space 7472d2669b6SNicolas Pitre * at a fixed address in kernel memory. This is used to provide user space 7482d2669b6SNicolas Pitre * with some operations which require kernel help because of unimplemented 7492d2669b6SNicolas Pitre * native feature and/or instructions in many ARM CPUs. The idea is for 7502d2669b6SNicolas Pitre * this code to be executed directly in user mode for best efficiency but 7512d2669b6SNicolas Pitre * which is too intimate with the kernel counter part to be left to user 7522d2669b6SNicolas Pitre * libraries. In fact this code might even differ from one CPU to another 7532d2669b6SNicolas Pitre * depending on the available instruction set and restrictions like on 7542d2669b6SNicolas Pitre * SMP systems. In other words, the kernel reserves the right to change 7552d2669b6SNicolas Pitre * this code as needed without warning. Only the entry points and their 7562d2669b6SNicolas Pitre * results are guaranteed to be stable. 7572d2669b6SNicolas Pitre * 7582d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high 7592d2669b6SNicolas Pitre * vector page. New segments (if ever needed) must be added in front of 7602d2669b6SNicolas Pitre * existing ones. This mechanism should be used only for things that are 7612d2669b6SNicolas Pitre * really small and justified, and not be abused freely. 7622d2669b6SNicolas Pitre * 7632d2669b6SNicolas Pitre * User space is expected to implement those things inline when optimizing 7642d2669b6SNicolas Pitre * for a processor that has the necessary native support, but only if such 7652d2669b6SNicolas Pitre * resulting binaries are already to be incompatible with earlier ARM 7662d2669b6SNicolas Pitre * processors due to the use of unsupported instructions other than what 7672d2669b6SNicolas Pitre * is provided here. In other words don't make binaries unable to run on 7682d2669b6SNicolas Pitre * earlier processors just for the sake of not using these kernel helpers 7692d2669b6SNicolas Pitre * if your compiled code is not going to use the new instructions for other 7702d2669b6SNicolas Pitre * purpose. 7712d2669b6SNicolas Pitre */ 772b86040a5SCatalin Marinas THUMB( .arm ) 7732d2669b6SNicolas Pitre 774ba9b5d76SNicolas Pitre .macro usr_ret, reg 775ba9b5d76SNicolas Pitre#ifdef CONFIG_ARM_THUMB 776ba9b5d76SNicolas Pitre bx \reg 777ba9b5d76SNicolas Pitre#else 778ba9b5d76SNicolas Pitre mov pc, \reg 779ba9b5d76SNicolas Pitre#endif 780ba9b5d76SNicolas Pitre .endm 781ba9b5d76SNicolas Pitre 7822d2669b6SNicolas Pitre .align 5 7832d2669b6SNicolas Pitre .globl __kuser_helper_start 7842d2669b6SNicolas Pitre__kuser_helper_start: 7852d2669b6SNicolas Pitre 7862d2669b6SNicolas Pitre/* 7872d2669b6SNicolas Pitre * Reference prototype: 7882d2669b6SNicolas Pitre * 7897c612bfdSNicolas Pitre * void __kernel_memory_barrier(void) 7907c612bfdSNicolas Pitre * 7917c612bfdSNicolas Pitre * Input: 7927c612bfdSNicolas Pitre * 7937c612bfdSNicolas Pitre * lr = return address 7947c612bfdSNicolas Pitre * 7957c612bfdSNicolas Pitre * Output: 7967c612bfdSNicolas Pitre * 7977c612bfdSNicolas Pitre * none 7987c612bfdSNicolas Pitre * 7997c612bfdSNicolas Pitre * Clobbered: 8007c612bfdSNicolas Pitre * 801b49c0f24SNicolas Pitre * none 8027c612bfdSNicolas Pitre * 8037c612bfdSNicolas Pitre * Definition and user space usage example: 8047c612bfdSNicolas Pitre * 8057c612bfdSNicolas Pitre * typedef void (__kernel_dmb_t)(void); 8067c612bfdSNicolas Pitre * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0) 8077c612bfdSNicolas Pitre * 8087c612bfdSNicolas Pitre * Apply any needed memory barrier to preserve consistency with data modified 8097c612bfdSNicolas Pitre * manually and __kuser_cmpxchg usage. 8107c612bfdSNicolas Pitre * 8117c612bfdSNicolas Pitre * This could be used as follows: 8127c612bfdSNicolas Pitre * 8137c612bfdSNicolas Pitre * #define __kernel_dmb() \ 8147c612bfdSNicolas Pitre * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \ 8156896eec0SPaul Brook * : : : "r0", "lr","cc" ) 8167c612bfdSNicolas Pitre */ 8177c612bfdSNicolas Pitre 8187c612bfdSNicolas Pitre__kuser_memory_barrier: @ 0xffff0fa0 819ed3768a8SDave Martin smp_dmb arm 820ba9b5d76SNicolas Pitre usr_ret lr 8217c612bfdSNicolas Pitre 8227c612bfdSNicolas Pitre .align 5 8237c612bfdSNicolas Pitre 8247c612bfdSNicolas Pitre/* 8257c612bfdSNicolas Pitre * Reference prototype: 8267c612bfdSNicolas Pitre * 8272d2669b6SNicolas Pitre * int __kernel_cmpxchg(int oldval, int newval, int *ptr) 8282d2669b6SNicolas Pitre * 8292d2669b6SNicolas Pitre * Input: 8302d2669b6SNicolas Pitre * 8312d2669b6SNicolas Pitre * r0 = oldval 8322d2669b6SNicolas Pitre * r1 = newval 8332d2669b6SNicolas Pitre * r2 = ptr 8342d2669b6SNicolas Pitre * lr = return address 8352d2669b6SNicolas Pitre * 8362d2669b6SNicolas Pitre * Output: 8372d2669b6SNicolas Pitre * 8382d2669b6SNicolas Pitre * r0 = returned value (zero or non-zero) 8392d2669b6SNicolas Pitre * C flag = set if r0 == 0, clear if r0 != 0 8402d2669b6SNicolas Pitre * 8412d2669b6SNicolas Pitre * Clobbered: 8422d2669b6SNicolas Pitre * 8432d2669b6SNicolas Pitre * r3, ip, flags 8442d2669b6SNicolas Pitre * 8452d2669b6SNicolas Pitre * Definition and user space usage example: 8462d2669b6SNicolas Pitre * 8472d2669b6SNicolas Pitre * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr); 8482d2669b6SNicolas Pitre * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0) 8492d2669b6SNicolas Pitre * 8502d2669b6SNicolas Pitre * Atomically store newval in *ptr if *ptr is equal to oldval for user space. 8512d2669b6SNicolas Pitre * Return zero if *ptr was changed or non-zero if no exchange happened. 8522d2669b6SNicolas Pitre * The C flag is also set if *ptr was changed to allow for assembly 8532d2669b6SNicolas Pitre * optimization in the calling code. 8542d2669b6SNicolas Pitre * 8555964eae8SNicolas Pitre * Notes: 8565964eae8SNicolas Pitre * 8575964eae8SNicolas Pitre * - This routine already includes memory barriers as needed. 8585964eae8SNicolas Pitre * 8592d2669b6SNicolas Pitre * For example, a user space atomic_add implementation could look like this: 8602d2669b6SNicolas Pitre * 8612d2669b6SNicolas Pitre * #define atomic_add(ptr, val) \ 8622d2669b6SNicolas Pitre * ({ register unsigned int *__ptr asm("r2") = (ptr); \ 8632d2669b6SNicolas Pitre * register unsigned int __result asm("r1"); \ 8642d2669b6SNicolas Pitre * asm volatile ( \ 8652d2669b6SNicolas Pitre * "1: @ atomic_add\n\t" \ 8662d2669b6SNicolas Pitre * "ldr r0, [r2]\n\t" \ 8672d2669b6SNicolas Pitre * "mov r3, #0xffff0fff\n\t" \ 8682d2669b6SNicolas Pitre * "add lr, pc, #4\n\t" \ 8692d2669b6SNicolas Pitre * "add r1, r0, %2\n\t" \ 8702d2669b6SNicolas Pitre * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \ 8712d2669b6SNicolas Pitre * "bcc 1b" \ 8722d2669b6SNicolas Pitre * : "=&r" (__result) \ 8732d2669b6SNicolas Pitre * : "r" (__ptr), "rIL" (val) \ 8742d2669b6SNicolas Pitre * : "r0","r3","ip","lr","cc","memory" ); \ 8752d2669b6SNicolas Pitre * __result; }) 8762d2669b6SNicolas Pitre */ 8772d2669b6SNicolas Pitre 8782d2669b6SNicolas Pitre__kuser_cmpxchg: @ 0xffff0fc0 8792d2669b6SNicolas Pitre 880dcef1f63SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG) 8812d2669b6SNicolas Pitre 882dcef1f63SNicolas Pitre /* 883dcef1f63SNicolas Pitre * Poor you. No fast solution possible... 884dcef1f63SNicolas Pitre * The kernel itself must perform the operation. 885dcef1f63SNicolas Pitre * A special ghost syscall is used for that (see traps.c). 886dcef1f63SNicolas Pitre */ 8875e097445SNicolas Pitre stmfd sp!, {r7, lr} 88855afd264SDave Martin ldr r7, 1f @ it's 20 bits 889cc20d429SRussell King swi __ARM_NR_cmpxchg 8905e097445SNicolas Pitre ldmfd sp!, {r7, pc} 891cc20d429SRussell King1: .word __ARM_NR_cmpxchg 892dcef1f63SNicolas Pitre 893dcef1f63SNicolas Pitre#elif __LINUX_ARM_ARCH__ < 6 8942d2669b6SNicolas Pitre 89549bca4c2SNicolas Pitre#ifdef CONFIG_MMU 896b49c0f24SNicolas Pitre 897b49c0f24SNicolas Pitre /* 898b49c0f24SNicolas Pitre * The only thing that can break atomicity in this cmpxchg 899b49c0f24SNicolas Pitre * implementation is either an IRQ or a data abort exception 900b49c0f24SNicolas Pitre * causing another process/thread to be scheduled in the middle 901b49c0f24SNicolas Pitre * of the critical sequence. To prevent this, code is added to 902b49c0f24SNicolas Pitre * the IRQ and data abort exception handlers to set the pc back 903b49c0f24SNicolas Pitre * to the beginning of the critical section if it is found to be 904b49c0f24SNicolas Pitre * within that critical section (see kuser_cmpxchg_fixup). 905b49c0f24SNicolas Pitre */ 906b49c0f24SNicolas Pitre1: ldr r3, [r2] @ load current val 907b49c0f24SNicolas Pitre subs r3, r3, r0 @ compare with oldval 908b49c0f24SNicolas Pitre2: streq r1, [r2] @ store newval if eq 909b49c0f24SNicolas Pitre rsbs r0, r3, #0 @ set return val and C flag 910b49c0f24SNicolas Pitre usr_ret lr 911b49c0f24SNicolas Pitre 912b49c0f24SNicolas Pitre .text 913b49c0f24SNicolas Pitrekuser_cmpxchg_fixup: 914b49c0f24SNicolas Pitre @ Called from kuser_cmpxchg_check macro. 915b49c0f24SNicolas Pitre @ r2 = address of interrupted insn (must be preserved). 916b49c0f24SNicolas Pitre @ sp = saved regs. r7 and r8 are clobbered. 917b49c0f24SNicolas Pitre @ 1b = first critical insn, 2b = last critical insn. 918b49c0f24SNicolas Pitre @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b. 919b49c0f24SNicolas Pitre mov r7, #0xffff0fff 920b49c0f24SNicolas Pitre sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg))) 921b49c0f24SNicolas Pitre subs r8, r2, r7 922b49c0f24SNicolas Pitre rsbcss r8, r8, #(2b - 1b) 923b49c0f24SNicolas Pitre strcs r7, [sp, #S_PC] 924b49c0f24SNicolas Pitre mov pc, lr 925b49c0f24SNicolas Pitre .previous 926b49c0f24SNicolas Pitre 92749bca4c2SNicolas Pitre#else 92849bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing" 92949bca4c2SNicolas Pitre mov r0, #-1 93049bca4c2SNicolas Pitre adds r0, r0, #0 931ba9b5d76SNicolas Pitre usr_ret lr 932b49c0f24SNicolas Pitre#endif 9332d2669b6SNicolas Pitre 9342d2669b6SNicolas Pitre#else 9352d2669b6SNicolas Pitre 936ed3768a8SDave Martin smp_dmb arm 937b49c0f24SNicolas Pitre1: ldrex r3, [r2] 9382d2669b6SNicolas Pitre subs r3, r3, r0 9392d2669b6SNicolas Pitre strexeq r3, r1, [r2] 940b49c0f24SNicolas Pitre teqeq r3, #1 941b49c0f24SNicolas Pitre beq 1b 9422d2669b6SNicolas Pitre rsbs r0, r3, #0 943b49c0f24SNicolas Pitre /* beware -- each __kuser slot must be 8 instructions max */ 944f00ec48fSRussell King ALT_SMP(b __kuser_memory_barrier) 945f00ec48fSRussell King ALT_UP(usr_ret lr) 9462d2669b6SNicolas Pitre 9472d2669b6SNicolas Pitre#endif 9482d2669b6SNicolas Pitre 9492d2669b6SNicolas Pitre .align 5 9502d2669b6SNicolas Pitre 9512d2669b6SNicolas Pitre/* 9522d2669b6SNicolas Pitre * Reference prototype: 9532d2669b6SNicolas Pitre * 9542d2669b6SNicolas Pitre * int __kernel_get_tls(void) 9552d2669b6SNicolas Pitre * 9562d2669b6SNicolas Pitre * Input: 9572d2669b6SNicolas Pitre * 9582d2669b6SNicolas Pitre * lr = return address 9592d2669b6SNicolas Pitre * 9602d2669b6SNicolas Pitre * Output: 9612d2669b6SNicolas Pitre * 9622d2669b6SNicolas Pitre * r0 = TLS value 9632d2669b6SNicolas Pitre * 9642d2669b6SNicolas Pitre * Clobbered: 9652d2669b6SNicolas Pitre * 966b49c0f24SNicolas Pitre * none 9672d2669b6SNicolas Pitre * 9682d2669b6SNicolas Pitre * Definition and user space usage example: 9692d2669b6SNicolas Pitre * 9702d2669b6SNicolas Pitre * typedef int (__kernel_get_tls_t)(void); 9712d2669b6SNicolas Pitre * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0) 9722d2669b6SNicolas Pitre * 9732d2669b6SNicolas Pitre * Get the TLS value as previously set via the __ARM_NR_set_tls syscall. 9742d2669b6SNicolas Pitre * 9752d2669b6SNicolas Pitre * This could be used as follows: 9762d2669b6SNicolas Pitre * 9772d2669b6SNicolas Pitre * #define __kernel_get_tls() \ 9782d2669b6SNicolas Pitre * ({ register unsigned int __val asm("r0"); \ 9792d2669b6SNicolas Pitre * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \ 9802d2669b6SNicolas Pitre * : "=r" (__val) : : "lr","cc" ); \ 9812d2669b6SNicolas Pitre * __val; }) 9822d2669b6SNicolas Pitre */ 9832d2669b6SNicolas Pitre 9842d2669b6SNicolas Pitre__kuser_get_tls: @ 0xffff0fe0 985f159f4edSTony Lindgren ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init 986ba9b5d76SNicolas Pitre usr_ret lr 987f159f4edSTony Lindgren mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code 988f159f4edSTony Lindgren .rep 4 989f159f4edSTony Lindgren .word 0 @ 0xffff0ff0 software TLS value, then 990f159f4edSTony Lindgren .endr @ pad up to __kuser_helper_version 9912d2669b6SNicolas Pitre 9922d2669b6SNicolas Pitre/* 9932d2669b6SNicolas Pitre * Reference declaration: 9942d2669b6SNicolas Pitre * 9952d2669b6SNicolas Pitre * extern unsigned int __kernel_helper_version; 9962d2669b6SNicolas Pitre * 9972d2669b6SNicolas Pitre * Definition and user space usage example: 9982d2669b6SNicolas Pitre * 9992d2669b6SNicolas Pitre * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc) 10002d2669b6SNicolas Pitre * 10012d2669b6SNicolas Pitre * User space may read this to determine the curent number of helpers 10022d2669b6SNicolas Pitre * available. 10032d2669b6SNicolas Pitre */ 10042d2669b6SNicolas Pitre 10052d2669b6SNicolas Pitre__kuser_helper_version: @ 0xffff0ffc 10062d2669b6SNicolas Pitre .word ((__kuser_helper_end - __kuser_helper_start) >> 5) 10072d2669b6SNicolas Pitre 10082d2669b6SNicolas Pitre .globl __kuser_helper_end 10092d2669b6SNicolas Pitre__kuser_helper_end: 10102d2669b6SNicolas Pitre 1011b86040a5SCatalin Marinas THUMB( .thumb ) 10122d2669b6SNicolas Pitre 10131da177e4SLinus Torvalds/* 10141da177e4SLinus Torvalds * Vector stubs. 10151da177e4SLinus Torvalds * 10167933523dSRussell King * This code is copied to 0xffff0200 so we can use branches in the 10177933523dSRussell King * vectors, rather than ldr's. Note that this code must not 10187933523dSRussell King * exceed 0x300 bytes. 10191da177e4SLinus Torvalds * 10201da177e4SLinus Torvalds * Common stub entry macro: 10211da177e4SLinus Torvalds * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 1022ccea7a19SRussell King * 1023ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address 1024ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler. 10251da177e4SLinus Torvalds */ 1026b7ec4795SNicolas Pitre .macro vector_stub, name, mode, correction=0 10271da177e4SLinus Torvalds .align 5 10281da177e4SLinus Torvalds 10291da177e4SLinus Torvaldsvector_\name: 10301da177e4SLinus Torvalds .if \correction 10311da177e4SLinus Torvalds sub lr, lr, #\correction 10321da177e4SLinus Torvalds .endif 10331da177e4SLinus Torvalds 1034ccea7a19SRussell King @ 1035ccea7a19SRussell King @ Save r0, lr_<exception> (parent PC) and spsr_<exception> 1036ccea7a19SRussell King @ (parent CPSR) 1037ccea7a19SRussell King @ 1038ccea7a19SRussell King stmia sp, {r0, lr} @ save r0, lr 1039ccea7a19SRussell King mrs lr, spsr 1040ccea7a19SRussell King str lr, [sp, #8] @ save spsr 1041ccea7a19SRussell King 1042ccea7a19SRussell King @ 1043ccea7a19SRussell King @ Prepare for SVC32 mode. IRQs remain disabled. 1044ccea7a19SRussell King @ 1045ccea7a19SRussell King mrs r0, cpsr 1046b86040a5SCatalin Marinas eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE) 1047ccea7a19SRussell King msr spsr_cxsf, r0 1048ccea7a19SRussell King 1049ccea7a19SRussell King @ 1050ccea7a19SRussell King @ the branch table must immediately follow this code 1051ccea7a19SRussell King @ 1052ccea7a19SRussell King and lr, lr, #0x0f 1053b86040a5SCatalin Marinas THUMB( adr r0, 1f ) 1054b86040a5SCatalin Marinas THUMB( ldr lr, [r0, lr, lsl #2] ) 1055b7ec4795SNicolas Pitre mov r0, sp 1056b86040a5SCatalin Marinas ARM( ldr lr, [pc, lr, lsl #2] ) 1057ccea7a19SRussell King movs pc, lr @ branch to handler in SVC mode 105893ed3970SCatalin MarinasENDPROC(vector_\name) 105988987ef9SCatalin Marinas 106088987ef9SCatalin Marinas .align 2 106188987ef9SCatalin Marinas @ handler addresses follow this label 106288987ef9SCatalin Marinas1: 10631da177e4SLinus Torvalds .endm 10641da177e4SLinus Torvalds 10657933523dSRussell King .globl __stubs_start 10661da177e4SLinus Torvalds__stubs_start: 10671da177e4SLinus Torvalds/* 10681da177e4SLinus Torvalds * Interrupt dispatcher 10691da177e4SLinus Torvalds */ 1070b7ec4795SNicolas Pitre vector_stub irq, IRQ_MODE, 4 10711da177e4SLinus Torvalds 10721da177e4SLinus Torvalds .long __irq_usr @ 0 (USR_26 / USR_32) 10731da177e4SLinus Torvalds .long __irq_invalid @ 1 (FIQ_26 / FIQ_32) 10741da177e4SLinus Torvalds .long __irq_invalid @ 2 (IRQ_26 / IRQ_32) 10751da177e4SLinus Torvalds .long __irq_svc @ 3 (SVC_26 / SVC_32) 10761da177e4SLinus Torvalds .long __irq_invalid @ 4 10771da177e4SLinus Torvalds .long __irq_invalid @ 5 10781da177e4SLinus Torvalds .long __irq_invalid @ 6 10791da177e4SLinus Torvalds .long __irq_invalid @ 7 10801da177e4SLinus Torvalds .long __irq_invalid @ 8 10811da177e4SLinus Torvalds .long __irq_invalid @ 9 10821da177e4SLinus Torvalds .long __irq_invalid @ a 10831da177e4SLinus Torvalds .long __irq_invalid @ b 10841da177e4SLinus Torvalds .long __irq_invalid @ c 10851da177e4SLinus Torvalds .long __irq_invalid @ d 10861da177e4SLinus Torvalds .long __irq_invalid @ e 10871da177e4SLinus Torvalds .long __irq_invalid @ f 10881da177e4SLinus Torvalds 10891da177e4SLinus Torvalds/* 10901da177e4SLinus Torvalds * Data abort dispatcher 10911da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 10921da177e4SLinus Torvalds */ 1093b7ec4795SNicolas Pitre vector_stub dabt, ABT_MODE, 8 10941da177e4SLinus Torvalds 10951da177e4SLinus Torvalds .long __dabt_usr @ 0 (USR_26 / USR_32) 10961da177e4SLinus Torvalds .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32) 10971da177e4SLinus Torvalds .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32) 10981da177e4SLinus Torvalds .long __dabt_svc @ 3 (SVC_26 / SVC_32) 10991da177e4SLinus Torvalds .long __dabt_invalid @ 4 11001da177e4SLinus Torvalds .long __dabt_invalid @ 5 11011da177e4SLinus Torvalds .long __dabt_invalid @ 6 11021da177e4SLinus Torvalds .long __dabt_invalid @ 7 11031da177e4SLinus Torvalds .long __dabt_invalid @ 8 11041da177e4SLinus Torvalds .long __dabt_invalid @ 9 11051da177e4SLinus Torvalds .long __dabt_invalid @ a 11061da177e4SLinus Torvalds .long __dabt_invalid @ b 11071da177e4SLinus Torvalds .long __dabt_invalid @ c 11081da177e4SLinus Torvalds .long __dabt_invalid @ d 11091da177e4SLinus Torvalds .long __dabt_invalid @ e 11101da177e4SLinus Torvalds .long __dabt_invalid @ f 11111da177e4SLinus Torvalds 11121da177e4SLinus Torvalds/* 11131da177e4SLinus Torvalds * Prefetch abort dispatcher 11141da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC 11151da177e4SLinus Torvalds */ 1116b7ec4795SNicolas Pitre vector_stub pabt, ABT_MODE, 4 11171da177e4SLinus Torvalds 11181da177e4SLinus Torvalds .long __pabt_usr @ 0 (USR_26 / USR_32) 11191da177e4SLinus Torvalds .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32) 11201da177e4SLinus Torvalds .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32) 11211da177e4SLinus Torvalds .long __pabt_svc @ 3 (SVC_26 / SVC_32) 11221da177e4SLinus Torvalds .long __pabt_invalid @ 4 11231da177e4SLinus Torvalds .long __pabt_invalid @ 5 11241da177e4SLinus Torvalds .long __pabt_invalid @ 6 11251da177e4SLinus Torvalds .long __pabt_invalid @ 7 11261da177e4SLinus Torvalds .long __pabt_invalid @ 8 11271da177e4SLinus Torvalds .long __pabt_invalid @ 9 11281da177e4SLinus Torvalds .long __pabt_invalid @ a 11291da177e4SLinus Torvalds .long __pabt_invalid @ b 11301da177e4SLinus Torvalds .long __pabt_invalid @ c 11311da177e4SLinus Torvalds .long __pabt_invalid @ d 11321da177e4SLinus Torvalds .long __pabt_invalid @ e 11331da177e4SLinus Torvalds .long __pabt_invalid @ f 11341da177e4SLinus Torvalds 11351da177e4SLinus Torvalds/* 11361da177e4SLinus Torvalds * Undef instr entry dispatcher 11371da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC 11381da177e4SLinus Torvalds */ 1139b7ec4795SNicolas Pitre vector_stub und, UND_MODE 11401da177e4SLinus Torvalds 11411da177e4SLinus Torvalds .long __und_usr @ 0 (USR_26 / USR_32) 11421da177e4SLinus Torvalds .long __und_invalid @ 1 (FIQ_26 / FIQ_32) 11431da177e4SLinus Torvalds .long __und_invalid @ 2 (IRQ_26 / IRQ_32) 11441da177e4SLinus Torvalds .long __und_svc @ 3 (SVC_26 / SVC_32) 11451da177e4SLinus Torvalds .long __und_invalid @ 4 11461da177e4SLinus Torvalds .long __und_invalid @ 5 11471da177e4SLinus Torvalds .long __und_invalid @ 6 11481da177e4SLinus Torvalds .long __und_invalid @ 7 11491da177e4SLinus Torvalds .long __und_invalid @ 8 11501da177e4SLinus Torvalds .long __und_invalid @ 9 11511da177e4SLinus Torvalds .long __und_invalid @ a 11521da177e4SLinus Torvalds .long __und_invalid @ b 11531da177e4SLinus Torvalds .long __und_invalid @ c 11541da177e4SLinus Torvalds .long __und_invalid @ d 11551da177e4SLinus Torvalds .long __und_invalid @ e 11561da177e4SLinus Torvalds .long __und_invalid @ f 11571da177e4SLinus Torvalds 11581da177e4SLinus Torvalds .align 5 11591da177e4SLinus Torvalds 11601da177e4SLinus Torvalds/*============================================================================= 11611da177e4SLinus Torvalds * Undefined FIQs 11621da177e4SLinus Torvalds *----------------------------------------------------------------------------- 11631da177e4SLinus Torvalds * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC 11641da177e4SLinus Torvalds * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg. 11651da177e4SLinus Torvalds * Basically to switch modes, we *HAVE* to clobber one register... brain 11661da177e4SLinus Torvalds * damage alert! I don't think that we can execute any code in here in any 11671da177e4SLinus Torvalds * other mode than FIQ... Ok you can switch to another mode, but you can't 11681da177e4SLinus Torvalds * get out of that mode without clobbering one register. 11691da177e4SLinus Torvalds */ 11701da177e4SLinus Torvaldsvector_fiq: 11711da177e4SLinus Torvalds disable_fiq 11721da177e4SLinus Torvalds subs pc, lr, #4 11731da177e4SLinus Torvalds 11741da177e4SLinus Torvalds/*============================================================================= 11751da177e4SLinus Torvalds * Address exception handler 11761da177e4SLinus Torvalds *----------------------------------------------------------------------------- 11771da177e4SLinus Torvalds * These aren't too critical. 11781da177e4SLinus Torvalds * (they're not supposed to happen, and won't happen in 32-bit data mode). 11791da177e4SLinus Torvalds */ 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvaldsvector_addrexcptn: 11821da177e4SLinus Torvalds b vector_addrexcptn 11831da177e4SLinus Torvalds 11841da177e4SLinus Torvalds/* 11851da177e4SLinus Torvalds * We group all the following data together to optimise 11861da177e4SLinus Torvalds * for CPUs with separate I & D caches. 11871da177e4SLinus Torvalds */ 11881da177e4SLinus Torvalds .align 5 11891da177e4SLinus Torvalds 11901da177e4SLinus Torvalds.LCvswi: 11911da177e4SLinus Torvalds .word vector_swi 11921da177e4SLinus Torvalds 11937933523dSRussell King .globl __stubs_end 11941da177e4SLinus Torvalds__stubs_end: 11951da177e4SLinus Torvalds 11967933523dSRussell King .equ stubs_offset, __vectors_start + 0x200 - __stubs_start 11971da177e4SLinus Torvalds 11987933523dSRussell King .globl __vectors_start 11997933523dSRussell King__vectors_start: 1200b86040a5SCatalin Marinas ARM( swi SYS_ERROR0 ) 1201b86040a5SCatalin Marinas THUMB( svc #0 ) 1202b86040a5SCatalin Marinas THUMB( nop ) 1203b86040a5SCatalin Marinas W(b) vector_und + stubs_offset 1204b86040a5SCatalin Marinas W(ldr) pc, .LCvswi + stubs_offset 1205b86040a5SCatalin Marinas W(b) vector_pabt + stubs_offset 1206b86040a5SCatalin Marinas W(b) vector_dabt + stubs_offset 1207b86040a5SCatalin Marinas W(b) vector_addrexcptn + stubs_offset 1208b86040a5SCatalin Marinas W(b) vector_irq + stubs_offset 1209b86040a5SCatalin Marinas W(b) vector_fiq + stubs_offset 12101da177e4SLinus Torvalds 12117933523dSRussell King .globl __vectors_end 12127933523dSRussell King__vectors_end: 12131da177e4SLinus Torvalds 12141da177e4SLinus Torvalds .data 12151da177e4SLinus Torvalds 12161da177e4SLinus Torvalds .globl cr_alignment 12171da177e4SLinus Torvalds .globl cr_no_alignment 12181da177e4SLinus Torvaldscr_alignment: 12191da177e4SLinus Torvalds .space 4 12201da177e4SLinus Torvaldscr_no_alignment: 12211da177e4SLinus Torvalds .space 4 122252108641Seric miao 122352108641Seric miao#ifdef CONFIG_MULTI_IRQ_HANDLER 122452108641Seric miao .globl handle_arch_irq 122552108641Seric miaohandle_arch_irq: 122652108641Seric miao .space 4 122752108641Seric miao#endif 1228