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
16 #ifndef __ASM_ASSEMBLER_H__
17 #define __ASM_ASSEMBLER_H__
20 #error "Only include this from assembly code"
23 #include <asm/ptrace.h>
24 #include <asm/domain.h>
25 #include <asm/opcodes-virt.h>
30 * Endian independent macros for shifting bytes within registers.
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
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
57 * Data preload for architectures that support it
59 #if __LINUX_ARM_ARCH__ >= 5
60 #define PLD(code...) code
66 * This can be used to enable code to cacheline align the destination
67 * pointer when bulk writing to memory. Experiments on StrongARM and
68 * XScale didn't show this a worthwhile thing to do when the cache is not
69 * set to write-allocate (this would need further testing on XScale when WA
72 * On Feroceon there is much to gain however, regardless of cache mode.
74 #ifdef CONFIG_CPU_FEROCEON
75 #define CALGN(code...) code
77 #define CALGN(code...)
81 * Enable and disable interrupts
83 #if __LINUX_ARM_ARCH__ >= 6
84 .macro disable_irq_notrace
88 .macro enable_irq_notrace
92 .macro disable_irq_notrace
93 msr cpsr_c
, #PSR_I_BIT | SVC_MODE
96 .macro enable_irq_notrace
101 .macro asm_trace_hardirqs_off
102 #if defined(CONFIG_TRACE_IRQFLAGS)
103 stmdb sp
!, {r0
-r3
, ip
, lr
}
104 bl trace_hardirqs_off
105 ldmia sp
!, {r0
-r3
, ip
, lr
}
109 .macro asm_trace_hardirqs_on_cond
, cond
110 #if defined(CONFIG_TRACE_IRQFLAGS)
112 * actually the registers should be pushed and pop'd conditionally, but
113 * after bl the flags are certainly clobbered
115 stmdb sp
!, {r0
-r3
, ip
, lr
}
116 bl\cond trace_hardirqs_on
117 ldmia sp
!, {r0
-r3
, ip
, lr
}
121 .macro asm_trace_hardirqs_on
122 asm_trace_hardirqs_on_cond al
127 asm_trace_hardirqs_off
131 asm_trace_hardirqs_on
135 * Save the current IRQ state and disable IRQs. Note that this macro
136 * assumes FIQs are enabled, and that the processor is in SVC mode.
138 .macro save_and_disable_irqs
, oldcpsr
139 #ifdef CONFIG_CPU_V7M
140 mrs \oldcpsr
, primask
147 .macro save_and_disable_irqs_notrace
, oldcpsr
153 * Restore interrupt state previously stored in a register. We don't
154 * guarantee that this will preserve the flags.
156 .macro restore_irqs_notrace
, oldcpsr
157 #ifdef CONFIG_CPU_V7M
158 msr primask
, \oldcpsr
164 .macro restore_irqs
, oldcpsr
165 tst \oldcpsr
, #PSR_I_BIT
166 asm_trace_hardirqs_on_cond eq
167 restore_irqs_notrace \oldcpsr
172 .pushsection __ex_table,"a"; \
178 #define ALT_SMP(instr...) \
181 * Note: if you get assembler errors from ALT_UP() when building with
182 * CONFIG_THUMB2_KERNEL, you almost certainly need to use
183 * ALT_SMP( W(instr) ... )
185 #define ALT_UP(instr...) \
186 .pushsection ".alt.smp.init", "a" ;\
189 .if . - 9997b != 4 ;\
190 .error "ALT_UP() content must assemble to exactly 4 bytes";\
193 #define ALT_UP_B(label) \
194 .equ up_b_offset, label - 9998b ;\
195 .pushsection ".alt.smp.init", "a" ;\
197 W(b) . + up_b_offset ;\
200 #define ALT_SMP(instr...)
201 #define ALT_UP(instr...) instr
202 #define ALT_UP_B(label) b label
206 * Instruction barrier
209 #if __LINUX_ARM_ARCH__ >= 7
211 #elif __LINUX_ARM_ARCH__ == 6
212 mcr p15
, 0, r0
, c7
, c5
, 4
217 * SMP data memory barrier
221 #if __LINUX_ARM_ARCH__ >= 7
227 #elif __LINUX_ARM_ARCH__ == 6
228 ALT_SMP(mcr p15
, 0, r0
, c7
, c10
, 5) @ dmb
230 #error Incompatible SMP platform
240 #if defined(CONFIG_CPU_V7M)
242 * setmode is used to assert to be in svc mode during boot. For v7-M
243 * this is done in __v7m_setup, so setmode can be empty here.
245 .macro setmode
, mode
, reg
247 #elif defined(CONFIG_THUMB2_KERNEL)
248 .macro setmode
, mode
, reg
253 .macro setmode
, mode
, reg
259 * Helper macro to enter SVC mode cleanly and mask interrupts. reg is
260 * a scratch register for the macro to overwrite.
262 * This macro is intended for forcing the CPU into SVC mode at boot time.
263 * you cannot return to the original mode.
265 .macro safe_svcmode_maskall reg
:req
266 #if __LINUX_ARM_ARCH__ >= 6
268 eor
\reg
, \reg
, #HYP_MODE
270 bic
\reg
, \reg
, #MODE_MASK
271 orr
\reg
, \reg
, #PSR_I_BIT | PSR_F_BIT | SVC_MODE
272 THUMB( orr
\reg
, \reg
, #PSR_T_BIT )
274 orr
\reg
, \reg
, #PSR_A_BIT
283 * workaround for possibly broken pre-v6 hardware
284 * (akita, Sharp Zaurus C-1000, PXA270-based)
286 setmode PSR_F_BIT
| PSR_I_BIT
| SVC_MODE
, \reg
291 * STRT/LDRT access macros with ARM and Thumb-2 variants
293 #ifdef CONFIG_THUMB2_KERNEL
295 .macro usraccoff
, instr
, reg
, ptr
, inc
, off
, cond
, abort
, t
=TUSER()
298 \instr\cond\
()b\
()\t\
().w
\reg
, [\ptr
, #\off]
300 \instr\cond\
()\t\
().w
\reg
, [\ptr
, #\off]
302 .error
"Unsupported inc macro argument"
305 .pushsection __ex_table
,"a"
311 .macro usracc
, instr
, reg
, ptr
, inc
, cond
, rept
, abort
312 @
explicit IT instruction needed because of the label
313 @ introduced by the USER macro
320 .error
"Unsupported rept macro argument"
324 @ Slightly optimised to avoid incrementing the pointer twice
325 usraccoff \instr
, \reg
, \ptr
, \inc
, 0, \cond
, \abort
327 usraccoff \instr
, \reg
, \ptr
, \inc
, \inc
, \cond
, \abort
330 add\cond \ptr
, #\rept * \inc
333 #else /* !CONFIG_THUMB2_KERNEL */
335 .macro usracc
, instr
, reg
, ptr
, inc
, cond
, rept
, abort
, t
=TUSER()
339 \instr\cond\
()b\
()\t \reg
, [\ptr
], #\inc
341 \instr\cond\
()\t \reg
, [\ptr
], #\inc
343 .error
"Unsupported inc macro argument"
346 .pushsection __ex_table
,"a"
353 #endif /* CONFIG_THUMB2_KERNEL */
355 .macro strusr
, reg
, ptr
, inc
, cond
=al
, rept
=1, abort
=9001f
356 usracc str
, \reg
, \ptr
, \inc
, \cond
, \rept
, \abort
359 .macro ldrusr
, reg
, ptr
, inc
, cond
=al
, rept
=1, abort
=9001f
360 usracc ldr
, \reg
, \ptr
, \inc
, \cond
, \rept
, \abort
363 /* Utility macro for declaring string literals */
364 .macro string name
:req
, string
365 .type
\name
, #object
368 .size
\name
, . - \name
371 .macro check_uaccess
, addr
:req
, size
:req
, limit
:req
, tmp
:req
, bad
:req
372 #ifndef CONFIG_CPU_USE_DOMAINS
373 adds
\tmp
, \addr
, #\size - 1
374 sbcccs
\tmp
, \tmp
, \limit
379 #endif /* __ASM_ASSEMBLER_H__ */