2 * arch/arm/include/asm/assembler.h
4 * Copyright (C) 1996-2000 Russell King
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.
10 * This file contains arm architecture specific defines
11 * for the different processors.
13 * Do not include any C declarations in this file - it is included by
17 #error "Only include this from assembly code"
20 #include <asm/ptrace.h>
21 #include <asm/domain.h>
24 * Endian independent macros for shifting bytes within registers.
29 #define get_byte_0 lsl #0
30 #define get_byte_1 lsr #8
31 #define get_byte_2 lsr #16
32 #define get_byte_3 lsr #24
33 #define put_byte_0 lsl #0
34 #define put_byte_1 lsl #8
35 #define put_byte_2 lsl #16
36 #define put_byte_3 lsl #24
40 #define get_byte_0 lsr #24
41 #define get_byte_1 lsr #16
42 #define get_byte_2 lsr #8
43 #define get_byte_3 lsl #0
44 #define put_byte_0 lsl #24
45 #define put_byte_1 lsl #16
46 #define put_byte_2 lsl #8
47 #define put_byte_3 lsl #0
51 * Data preload for architectures that support it
53 #if __LINUX_ARM_ARCH__ >= 5
54 #define PLD(code...) code
60 * This can be used to enable code to cacheline align the destination
61 * pointer when bulk writing to memory. Experiments on StrongARM and
62 * XScale didn't show this a worthwhile thing to do when the cache is not
63 * set to write-allocate (this would need further testing on XScale when WA
66 * On Feroceon there is much to gain however, regardless of cache mode.
68 #ifdef CONFIG_CPU_FEROCEON
69 #define CALGN(code...) code
71 #define CALGN(code...)
75 * Enable and disable interrupts
77 #if __LINUX_ARM_ARCH__ >= 6
78 .macro disable_irq_notrace
82 .macro enable_irq_notrace
86 .macro disable_irq_notrace
87 msr cpsr_c
, #PSR_I_BIT | SVC_MODE
90 .macro enable_irq_notrace
95 .macro asm_trace_hardirqs_off
96 #if defined(CONFIG_TRACE_IRQFLAGS)
97 stmdb sp
!, {r0
-r3
, ip
, lr
}
99 ldmia sp
!, {r0
-r3
, ip
, lr
}
103 .macro asm_trace_hardirqs_on_cond
, cond
104 #if defined(CONFIG_TRACE_IRQFLAGS)
106 * actually the registers should be pushed and pop'd conditionally, but
107 * after bl the flags are certainly clobbered
109 stmdb sp
!, {r0
-r3
, ip
, lr
}
110 bl\cond trace_hardirqs_on
111 ldmia sp
!, {r0
-r3
, ip
, lr
}
115 .macro asm_trace_hardirqs_on
116 asm_trace_hardirqs_on_cond al
121 asm_trace_hardirqs_off
125 asm_trace_hardirqs_on
129 * Save the current IRQ state and disable IRQs. Note that this macro
130 * assumes FIQs are enabled, and that the processor is in SVC mode.
132 .macro save_and_disable_irqs
, oldcpsr
138 * Restore interrupt state previously stored in a register. We don't
139 * guarantee that this will preserve the flags.
141 .macro restore_irqs_notrace
, oldcpsr
145 .macro restore_irqs
, oldcpsr
146 tst \oldcpsr
, #PSR_I_BIT
147 asm_trace_hardirqs_on_cond eq
148 restore_irqs_notrace \oldcpsr
153 .pushsection __ex_table,"a"; \
159 #define ALT_SMP(instr...) \
162 * Note: if you get assembler errors from ALT_UP() when building with
163 * CONFIG_THUMB2_KERNEL, you almost certainly need to use
164 * ALT_SMP( W(instr) ... )
166 #define ALT_UP(instr...) \
167 .pushsection ".alt.smp.init", "a" ;\
170 .if . - 9997b != 4 ;\
171 .error "ALT_UP() content must assemble to exactly 4 bytes";\
174 #define ALT_UP_B(label) \
175 .equ up_b_offset, label - 9998b ;\
176 .pushsection ".alt.smp.init", "a" ;\
178 W(b) . + up_b_offset ;\
181 #define ALT_SMP(instr...)
182 #define ALT_UP(instr...) instr
183 #define ALT_UP_B(label) b label
187 * SMP data memory barrier
191 #if __LINUX_ARM_ARCH__ >= 7
197 #elif __LINUX_ARM_ARCH__ == 6
198 ALT_SMP(mcr p15
, 0, r0
, c7
, c10
, 5) @ dmb
200 #error Incompatible SMP platform
210 #ifdef CONFIG_THUMB2_KERNEL
211 .macro setmode
, mode
, reg
216 .macro setmode
, mode
, reg
222 * STRT/LDRT access macros with ARM and Thumb-2 variants
224 #ifdef CONFIG_THUMB2_KERNEL
226 .macro usraccoff
, instr
, reg
, ptr
, inc
, off
, cond
, abort
, t
=T()
229 \instr\cond\
()b\
()\t\
().w
\reg
, [\ptr
, #\off]
231 \instr\cond\
()\t\
().w
\reg
, [\ptr
, #\off]
233 .error
"Unsupported inc macro argument"
236 .pushsection __ex_table
,"a"
242 .macro usracc
, instr
, reg
, ptr
, inc
, cond
, rept
, abort
243 @
explicit IT instruction needed because of the label
244 @ introduced by the USER macro
251 .error
"Unsupported rept macro argument"
255 @ Slightly optimised to avoid incrementing the pointer twice
256 usraccoff \instr
, \reg
, \ptr
, \inc
, 0, \cond
, \abort
258 usraccoff \instr
, \reg
, \ptr
, \inc
, \inc
, \cond
, \abort
261 add\cond \ptr
, #\rept * \inc
264 #else /* !CONFIG_THUMB2_KERNEL */
266 .macro usracc
, instr
, reg
, ptr
, inc
, cond
, rept
, abort
, t
=T()
270 \instr\cond\
()b\
()\t \reg
, [\ptr
], #\inc
272 \instr\cond\
()\t \reg
, [\ptr
], #\inc
274 .error
"Unsupported inc macro argument"
277 .pushsection __ex_table
,"a"
284 #endif /* CONFIG_THUMB2_KERNEL */
286 .macro strusr
, reg
, ptr
, inc
, cond
=al
, rept
=1, abort
=9001f
287 usracc str
, \reg
, \ptr
, \inc
, \cond
, \rept
, \abort
290 .macro ldrusr
, reg
, ptr
, inc
, cond
=al
, rept
=1, abort
=9001f
291 usracc ldr
, \reg
, \ptr
, \inc
, \cond
, \rept
, \abort