Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Russell King | 4baa992 | 2008-08-02 10:55:55 +0100 | [diff] [blame] | 2 | * arch/arm/include/asm/assembler.h |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1996-2000 Russell King |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This file contains arm architecture specific defines |
| 11 | * for the different processors. |
| 12 | * |
| 13 | * Do not include any C declarations in this file - it is included by |
| 14 | * assembler source. |
| 15 | */ |
Magnus Damm | 2bc58a6 | 2011-06-13 06:46:44 +0100 | [diff] [blame] | 16 | #ifndef __ASM_ASSEMBLER_H__ |
| 17 | #define __ASM_ASSEMBLER_H__ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #ifndef __ASSEMBLY__ |
| 20 | #error "Only include this from assembly code" |
| 21 | #endif |
| 22 | |
| 23 | #include <asm/ptrace.h> |
Catalin Marinas | 247055a | 2010-09-13 16:03:21 +0100 | [diff] [blame] | 24 | #include <asm/domain.h> |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 25 | #include <asm/opcodes-virt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Rob Herring | 6f6f6a7 | 2012-03-10 10:30:31 -0600 | [diff] [blame] | 27 | #define IOMEM(x) (x) |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | /* |
| 30 | * Endian independent macros for shifting bytes within registers. |
| 31 | */ |
| 32 | #ifndef __ARMEB__ |
Victor Kamensky | d98b90e | 2014-02-25 08:41:09 +0100 | [diff] [blame] | 33 | #define lspull lsr |
| 34 | #define lspush lsl |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define get_byte_0 lsl #0 |
| 36 | #define get_byte_1 lsr #8 |
| 37 | #define get_byte_2 lsr #16 |
| 38 | #define get_byte_3 lsr #24 |
| 39 | #define put_byte_0 lsl #0 |
| 40 | #define put_byte_1 lsl #8 |
| 41 | #define put_byte_2 lsl #16 |
| 42 | #define put_byte_3 lsl #24 |
| 43 | #else |
Victor Kamensky | d98b90e | 2014-02-25 08:41:09 +0100 | [diff] [blame] | 44 | #define lspull lsl |
| 45 | #define lspush lsr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #define get_byte_0 lsr #24 |
| 47 | #define get_byte_1 lsr #16 |
| 48 | #define get_byte_2 lsr #8 |
| 49 | #define get_byte_3 lsl #0 |
| 50 | #define put_byte_0 lsl #24 |
| 51 | #define put_byte_1 lsl #16 |
| 52 | #define put_byte_2 lsl #8 |
| 53 | #define put_byte_3 lsl #0 |
| 54 | #endif |
| 55 | |
Ben Dooks | 457c240 | 2013-02-12 18:59:57 +0000 | [diff] [blame] | 56 | /* Select code for any configuration running in BE8 mode */ |
| 57 | #ifdef CONFIG_CPU_ENDIAN_BE8 |
| 58 | #define ARM_BE8(code...) code |
| 59 | #else |
| 60 | #define ARM_BE8(code...) |
| 61 | #endif |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /* |
| 64 | * Data preload for architectures that support it |
| 65 | */ |
| 66 | #if __LINUX_ARM_ARCH__ >= 5 |
| 67 | #define PLD(code...) code |
| 68 | #else |
| 69 | #define PLD(code...) |
| 70 | #endif |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* |
Nicolas Pitre | 2239aff | 2008-03-31 12:38:31 -0400 | [diff] [blame] | 73 | * This can be used to enable code to cacheline align the destination |
| 74 | * pointer when bulk writing to memory. Experiments on StrongARM and |
| 75 | * XScale didn't show this a worthwhile thing to do when the cache is not |
| 76 | * set to write-allocate (this would need further testing on XScale when WA |
| 77 | * is used). |
| 78 | * |
| 79 | * On Feroceon there is much to gain however, regardless of cache mode. |
| 80 | */ |
| 81 | #ifdef CONFIG_CPU_FEROCEON |
| 82 | #define CALGN(code...) code |
| 83 | #else |
| 84 | #define CALGN(code...) |
| 85 | #endif |
| 86 | |
| 87 | /* |
Russell King | 9c42954 | 2006-03-23 16:59:37 +0000 | [diff] [blame] | 88 | * Enable and disable interrupts |
| 89 | */ |
| 90 | #if __LINUX_ARM_ARCH__ >= 6 |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 91 | .macro disable_irq_notrace |
Russell King | 9c42954 | 2006-03-23 16:59:37 +0000 | [diff] [blame] | 92 | cpsid i |
| 93 | .endm |
| 94 | |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 95 | .macro enable_irq_notrace |
Russell King | 9c42954 | 2006-03-23 16:59:37 +0000 | [diff] [blame] | 96 | cpsie i |
| 97 | .endm |
| 98 | #else |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 99 | .macro disable_irq_notrace |
Russell King | 9c42954 | 2006-03-23 16:59:37 +0000 | [diff] [blame] | 100 | msr cpsr_c, #PSR_I_BIT | SVC_MODE |
| 101 | .endm |
| 102 | |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 103 | .macro enable_irq_notrace |
Russell King | 9c42954 | 2006-03-23 16:59:37 +0000 | [diff] [blame] | 104 | msr cpsr_c, #SVC_MODE |
| 105 | .endm |
| 106 | #endif |
| 107 | |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 108 | .macro asm_trace_hardirqs_off |
| 109 | #if defined(CONFIG_TRACE_IRQFLAGS) |
| 110 | stmdb sp!, {r0-r3, ip, lr} |
| 111 | bl trace_hardirqs_off |
| 112 | ldmia sp!, {r0-r3, ip, lr} |
| 113 | #endif |
| 114 | .endm |
| 115 | |
| 116 | .macro asm_trace_hardirqs_on_cond, cond |
| 117 | #if defined(CONFIG_TRACE_IRQFLAGS) |
| 118 | /* |
| 119 | * actually the registers should be pushed and pop'd conditionally, but |
| 120 | * after bl the flags are certainly clobbered |
| 121 | */ |
| 122 | stmdb sp!, {r0-r3, ip, lr} |
| 123 | bl\cond trace_hardirqs_on |
| 124 | ldmia sp!, {r0-r3, ip, lr} |
| 125 | #endif |
| 126 | .endm |
| 127 | |
| 128 | .macro asm_trace_hardirqs_on |
| 129 | asm_trace_hardirqs_on_cond al |
| 130 | .endm |
| 131 | |
| 132 | .macro disable_irq |
| 133 | disable_irq_notrace |
| 134 | asm_trace_hardirqs_off |
| 135 | .endm |
| 136 | |
| 137 | .macro enable_irq |
| 138 | asm_trace_hardirqs_on |
| 139 | enable_irq_notrace |
| 140 | .endm |
Russell King | 9c42954 | 2006-03-23 16:59:37 +0000 | [diff] [blame] | 141 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | * Save the current IRQ state and disable IRQs. Note that this macro |
| 143 | * assumes FIQs are enabled, and that the processor is in SVC mode. |
| 144 | */ |
Russell King | 59d1ff3 | 2005-11-09 15:04:22 +0000 | [diff] [blame] | 145 | .macro save_and_disable_irqs, oldcpsr |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 146 | #ifdef CONFIG_CPU_V7M |
| 147 | mrs \oldcpsr, primask |
| 148 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | mrs \oldcpsr, cpsr |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 150 | #endif |
Russell King | 9c42954 | 2006-03-23 16:59:37 +0000 | [diff] [blame] | 151 | disable_irq |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | .endm |
| 153 | |
Rabin Vincent | 8e43a90 | 2012-02-15 16:01:42 +0100 | [diff] [blame] | 154 | .macro save_and_disable_irqs_notrace, oldcpsr |
| 155 | mrs \oldcpsr, cpsr |
| 156 | disable_irq_notrace |
| 157 | .endm |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* |
| 160 | * Restore interrupt state previously stored in a register. We don't |
| 161 | * guarantee that this will preserve the flags. |
| 162 | */ |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 163 | .macro restore_irqs_notrace, oldcpsr |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 164 | #ifdef CONFIG_CPU_V7M |
| 165 | msr primask, \oldcpsr |
| 166 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | msr cpsr_c, \oldcpsr |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 168 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | .endm |
| 170 | |
Uwe Kleine-König | 0d928b0 | 2009-08-13 20:38:17 +0200 | [diff] [blame] | 171 | .macro restore_irqs, oldcpsr |
| 172 | tst \oldcpsr, #PSR_I_BIT |
| 173 | asm_trace_hardirqs_on_cond eq |
| 174 | restore_irqs_notrace \oldcpsr |
| 175 | .endm |
| 176 | |
Catalin Marinas | 39ad04c | 2014-04-02 10:57:48 +0100 | [diff] [blame^] | 177 | /* |
| 178 | * Get current thread_info. |
| 179 | */ |
| 180 | .macro get_thread_info, rd |
| 181 | ARM( mov \rd, sp, lsr #13 ) |
| 182 | THUMB( mov \rd, sp ) |
| 183 | THUMB( lsr \rd, \rd, #13 ) |
| 184 | mov \rd, \rd, lsl #13 |
| 185 | .endm |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | #define USER(x...) \ |
| 188 | 9999: x; \ |
Russell King | 4260415 | 2010-04-19 10:15:03 +0100 | [diff] [blame] | 189 | .pushsection __ex_table,"a"; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | .align 3; \ |
| 191 | .long 9999b,9001f; \ |
Russell King | 4260415 | 2010-04-19 10:15:03 +0100 | [diff] [blame] | 192 | .popsection |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 193 | |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 194 | #ifdef CONFIG_SMP |
| 195 | #define ALT_SMP(instr...) \ |
| 196 | 9998: instr |
Dave Martin | ed3768a | 2010-12-01 15:39:23 +0100 | [diff] [blame] | 197 | /* |
| 198 | * Note: if you get assembler errors from ALT_UP() when building with |
| 199 | * CONFIG_THUMB2_KERNEL, you almost certainly need to use |
| 200 | * ALT_SMP( W(instr) ... ) |
| 201 | */ |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 202 | #define ALT_UP(instr...) \ |
| 203 | .pushsection ".alt.smp.init", "a" ;\ |
| 204 | .long 9998b ;\ |
Dave Martin | ed3768a | 2010-12-01 15:39:23 +0100 | [diff] [blame] | 205 | 9997: instr ;\ |
| 206 | .if . - 9997b != 4 ;\ |
| 207 | .error "ALT_UP() content must assemble to exactly 4 bytes";\ |
| 208 | .endif ;\ |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 209 | .popsection |
| 210 | #define ALT_UP_B(label) \ |
| 211 | .equ up_b_offset, label - 9998b ;\ |
| 212 | .pushsection ".alt.smp.init", "a" ;\ |
| 213 | .long 9998b ;\ |
Dave Martin | ed3768a | 2010-12-01 15:39:23 +0100 | [diff] [blame] | 214 | W(b) . + up_b_offset ;\ |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 215 | .popsection |
| 216 | #else |
| 217 | #define ALT_SMP(instr...) |
| 218 | #define ALT_UP(instr...) instr |
| 219 | #define ALT_UP_B(label) b label |
| 220 | #endif |
| 221 | |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 222 | /* |
Will Deacon | d675d0b | 2011-11-22 17:30:28 +0000 | [diff] [blame] | 223 | * Instruction barrier |
| 224 | */ |
| 225 | .macro instr_sync |
| 226 | #if __LINUX_ARM_ARCH__ >= 7 |
| 227 | isb |
| 228 | #elif __LINUX_ARM_ARCH__ == 6 |
| 229 | mcr p15, 0, r0, c7, c5, 4 |
| 230 | #endif |
| 231 | .endm |
| 232 | |
| 233 | /* |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 234 | * SMP data memory barrier |
| 235 | */ |
Dave Martin | ed3768a | 2010-12-01 15:39:23 +0100 | [diff] [blame] | 236 | .macro smp_dmb mode |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 237 | #ifdef CONFIG_SMP |
| 238 | #if __LINUX_ARM_ARCH__ >= 7 |
Dave Martin | ed3768a | 2010-12-01 15:39:23 +0100 | [diff] [blame] | 239 | .ifeqs "\mode","arm" |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 240 | ALT_SMP(dmb ish) |
Dave Martin | ed3768a | 2010-12-01 15:39:23 +0100 | [diff] [blame] | 241 | .else |
Will Deacon | 3ea1280 | 2013-05-10 18:07:19 +0100 | [diff] [blame] | 242 | ALT_SMP(W(dmb) ish) |
Dave Martin | ed3768a | 2010-12-01 15:39:23 +0100 | [diff] [blame] | 243 | .endif |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 244 | #elif __LINUX_ARM_ARCH__ == 6 |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 245 | ALT_SMP(mcr p15, 0, r0, c7, c10, 5) @ dmb |
| 246 | #else |
| 247 | #error Incompatible SMP platform |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 248 | #endif |
Dave Martin | ed3768a | 2010-12-01 15:39:23 +0100 | [diff] [blame] | 249 | .ifeqs "\mode","arm" |
Russell King | f00ec48 | 2010-09-04 10:47:48 +0100 | [diff] [blame] | 250 | ALT_UP(nop) |
Dave Martin | ed3768a | 2010-12-01 15:39:23 +0100 | [diff] [blame] | 251 | .else |
| 252 | ALT_UP(W(nop)) |
| 253 | .endif |
Russell King | bac4e96 | 2009-05-25 20:58:00 +0100 | [diff] [blame] | 254 | #endif |
| 255 | .endm |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 256 | |
Catalin Marinas | 55bdd69 | 2010-05-21 18:06:41 +0100 | [diff] [blame] | 257 | #if defined(CONFIG_CPU_V7M) |
| 258 | /* |
| 259 | * setmode is used to assert to be in svc mode during boot. For v7-M |
| 260 | * this is done in __v7m_setup, so setmode can be empty here. |
| 261 | */ |
| 262 | .macro setmode, mode, reg |
| 263 | .endm |
| 264 | #elif defined(CONFIG_THUMB2_KERNEL) |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 265 | .macro setmode, mode, reg |
| 266 | mov \reg, #\mode |
| 267 | msr cpsr_c, \reg |
| 268 | .endm |
| 269 | #else |
| 270 | .macro setmode, mode, reg |
| 271 | msr cpsr_c, #\mode |
| 272 | .endm |
| 273 | #endif |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 274 | |
| 275 | /* |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 276 | * Helper macro to enter SVC mode cleanly and mask interrupts. reg is |
| 277 | * a scratch register for the macro to overwrite. |
| 278 | * |
| 279 | * This macro is intended for forcing the CPU into SVC mode at boot time. |
| 280 | * you cannot return to the original mode. |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 281 | */ |
| 282 | .macro safe_svcmode_maskall reg:req |
Dave Martin | 1ecec69 | 2012-12-10 18:35:22 +0100 | [diff] [blame] | 283 | #if __LINUX_ARM_ARCH__ >= 6 |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 284 | mrs \reg , cpsr |
Russell King | 8e9c24a | 2012-12-03 15:39:43 +0000 | [diff] [blame] | 285 | eor \reg, \reg, #HYP_MODE |
| 286 | tst \reg, #MODE_MASK |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 287 | bic \reg , \reg , #MODE_MASK |
Russell King | 8e9c24a | 2012-12-03 15:39:43 +0000 | [diff] [blame] | 288 | orr \reg , \reg , #PSR_I_BIT | PSR_F_BIT | SVC_MODE |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 289 | THUMB( orr \reg , \reg , #PSR_T_BIT ) |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 290 | bne 1f |
Marc Zyngier | 2a552d5 | 2012-10-06 17:03:17 +0100 | [diff] [blame] | 291 | orr \reg, \reg, #PSR_A_BIT |
| 292 | adr lr, BSYM(2f) |
| 293 | msr spsr_cxsf, \reg |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 294 | __MSR_ELR_HYP(14) |
| 295 | __ERET |
Marc Zyngier | 2a552d5 | 2012-10-06 17:03:17 +0100 | [diff] [blame] | 296 | 1: msr cpsr_c, \reg |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 297 | 2: |
Dave Martin | 1ecec69 | 2012-12-10 18:35:22 +0100 | [diff] [blame] | 298 | #else |
| 299 | /* |
| 300 | * workaround for possibly broken pre-v6 hardware |
| 301 | * (akita, Sharp Zaurus C-1000, PXA270-based) |
| 302 | */ |
| 303 | setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, \reg |
| 304 | #endif |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 305 | .endm |
| 306 | |
| 307 | /* |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 308 | * STRT/LDRT access macros with ARM and Thumb-2 variants |
| 309 | */ |
| 310 | #ifdef CONFIG_THUMB2_KERNEL |
| 311 | |
Catalin Marinas | 4e7682d | 2012-01-25 11:38:13 +0100 | [diff] [blame] | 312 | .macro usraccoff, instr, reg, ptr, inc, off, cond, abort, t=TUSER() |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 313 | 9999: |
| 314 | .if \inc == 1 |
Catalin Marinas | 247055a | 2010-09-13 16:03:21 +0100 | [diff] [blame] | 315 | \instr\cond\()b\()\t\().w \reg, [\ptr, #\off] |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 316 | .elseif \inc == 4 |
Catalin Marinas | 247055a | 2010-09-13 16:03:21 +0100 | [diff] [blame] | 317 | \instr\cond\()\t\().w \reg, [\ptr, #\off] |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 318 | .else |
| 319 | .error "Unsupported inc macro argument" |
| 320 | .endif |
| 321 | |
Russell King | 4260415 | 2010-04-19 10:15:03 +0100 | [diff] [blame] | 322 | .pushsection __ex_table,"a" |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 323 | .align 3 |
| 324 | .long 9999b, \abort |
Russell King | 4260415 | 2010-04-19 10:15:03 +0100 | [diff] [blame] | 325 | .popsection |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 326 | .endm |
| 327 | |
| 328 | .macro usracc, instr, reg, ptr, inc, cond, rept, abort |
| 329 | @ explicit IT instruction needed because of the label |
| 330 | @ introduced by the USER macro |
| 331 | .ifnc \cond,al |
| 332 | .if \rept == 1 |
| 333 | itt \cond |
| 334 | .elseif \rept == 2 |
| 335 | ittt \cond |
| 336 | .else |
| 337 | .error "Unsupported rept macro argument" |
| 338 | .endif |
| 339 | .endif |
| 340 | |
| 341 | @ Slightly optimised to avoid incrementing the pointer twice |
| 342 | usraccoff \instr, \reg, \ptr, \inc, 0, \cond, \abort |
| 343 | .if \rept == 2 |
Will Deacon | 1142b71 | 2010-11-19 13:18:31 +0100 | [diff] [blame] | 344 | usraccoff \instr, \reg, \ptr, \inc, \inc, \cond, \abort |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 345 | .endif |
| 346 | |
| 347 | add\cond \ptr, #\rept * \inc |
| 348 | .endm |
| 349 | |
| 350 | #else /* !CONFIG_THUMB2_KERNEL */ |
| 351 | |
Catalin Marinas | 4e7682d | 2012-01-25 11:38:13 +0100 | [diff] [blame] | 352 | .macro usracc, instr, reg, ptr, inc, cond, rept, abort, t=TUSER() |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 353 | .rept \rept |
| 354 | 9999: |
| 355 | .if \inc == 1 |
Catalin Marinas | 247055a | 2010-09-13 16:03:21 +0100 | [diff] [blame] | 356 | \instr\cond\()b\()\t \reg, [\ptr], #\inc |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 357 | .elseif \inc == 4 |
Catalin Marinas | 247055a | 2010-09-13 16:03:21 +0100 | [diff] [blame] | 358 | \instr\cond\()\t \reg, [\ptr], #\inc |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 359 | .else |
| 360 | .error "Unsupported inc macro argument" |
| 361 | .endif |
| 362 | |
Russell King | 4260415 | 2010-04-19 10:15:03 +0100 | [diff] [blame] | 363 | .pushsection __ex_table,"a" |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 364 | .align 3 |
| 365 | .long 9999b, \abort |
Russell King | 4260415 | 2010-04-19 10:15:03 +0100 | [diff] [blame] | 366 | .popsection |
Catalin Marinas | 8b59278 | 2009-07-24 12:32:57 +0100 | [diff] [blame] | 367 | .endr |
| 368 | .endm |
| 369 | |
| 370 | #endif /* CONFIG_THUMB2_KERNEL */ |
| 371 | |
| 372 | .macro strusr, reg, ptr, inc, cond=al, rept=1, abort=9001f |
| 373 | usracc str, \reg, \ptr, \inc, \cond, \rept, \abort |
| 374 | .endm |
| 375 | |
| 376 | .macro ldrusr, reg, ptr, inc, cond=al, rept=1, abort=9001f |
| 377 | usracc ldr, \reg, \ptr, \inc, \cond, \rept, \abort |
| 378 | .endm |
Dave Martin | 8f51965 | 2011-06-23 17:10:05 +0100 | [diff] [blame] | 379 | |
| 380 | /* Utility macro for declaring string literals */ |
| 381 | .macro string name:req, string |
| 382 | .type \name , #object |
| 383 | \name: |
| 384 | .asciz "\string" |
| 385 | .size \name , . - \name |
| 386 | .endm |
| 387 | |
Russell King | 8404663 | 2012-09-07 18:22:28 +0100 | [diff] [blame] | 388 | .macro check_uaccess, addr:req, size:req, limit:req, tmp:req, bad:req |
| 389 | #ifndef CONFIG_CPU_USE_DOMAINS |
| 390 | adds \tmp, \addr, #\size - 1 |
| 391 | sbcccs \tmp, \tmp, \limit |
| 392 | bcs \bad |
| 393 | #endif |
| 394 | .endm |
| 395 | |
Magnus Damm | 2bc58a6 | 2011-06-13 06:46:44 +0100 | [diff] [blame] | 396 | #endif /* __ASM_ASSEMBLER_H__ */ |