blob: 750bac4e637e5323f29bd4859b6e655b3a035d95 [file] [log] [blame]
Catalin Marinas0be73202012-03-05 11:49:26 +00001/*
2 * Based on arch/arm/include/asm/assembler.h
3 *
4 * Copyright (C) 1996-2000 Russell King
5 * Copyright (C) 2012 ARM Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef __ASSEMBLY__
20#error "Only include this from assembly code"
21#endif
22
Marc Zyngierf3e39272015-02-20 13:53:13 +000023#ifndef __ASM_ASSEMBLER_H
24#define __ASM_ASSEMBLER_H
25
Catalin Marinas0be73202012-03-05 11:49:26 +000026#include <asm/ptrace.h>
Will Deacon2a283072014-04-29 19:04:06 +010027#include <asm/thread_info.h>
Catalin Marinas0be73202012-03-05 11:49:26 +000028
29/*
30 * Stack pushing/popping (register pairs only). Equivalent to store decrement
31 * before, load increment after.
32 */
33 .macro push, xreg1, xreg2
34 stp \xreg1, \xreg2, [sp, #-16]!
35 .endm
36
37 .macro pop, xreg1, xreg2
38 ldp \xreg1, \xreg2, [sp], #16
39 .endm
40
41/*
42 * Enable and disable interrupts.
43 */
44 .macro disable_irq
45 msr daifset, #2
46 .endm
47
48 .macro enable_irq
49 msr daifclr, #2
50 .endm
51
52/*
53 * Save/disable and restore interrupts.
54 */
55 .macro save_and_disable_irqs, olddaif
56 mrs \olddaif, daif
57 disable_irq
58 .endm
59
60 .macro restore_irqs, olddaif
61 msr daif, \olddaif
62 .endm
63
64/*
65 * Enable and disable debug exceptions.
66 */
67 .macro disable_dbg
68 msr daifset, #8
69 .endm
70
71 .macro enable_dbg
72 msr daifclr, #8
73 .endm
74
Will Deacon2a283072014-04-29 19:04:06 +010075 .macro disable_step_tsk, flgs, tmp
76 tbz \flgs, #TIF_SINGLESTEP, 9990f
Catalin Marinas0be73202012-03-05 11:49:26 +000077 mrs \tmp, mdscr_el1
78 bic \tmp, \tmp, #1
79 msr mdscr_el1, \tmp
Will Deacon2a283072014-04-29 19:04:06 +010080 isb // Synchronise with enable_dbg
819990:
Catalin Marinas0be73202012-03-05 11:49:26 +000082 .endm
83
Will Deacon2a283072014-04-29 19:04:06 +010084 .macro enable_step_tsk, flgs, tmp
85 tbz \flgs, #TIF_SINGLESTEP, 9990f
86 disable_dbg
Catalin Marinas0be73202012-03-05 11:49:26 +000087 mrs \tmp, mdscr_el1
88 orr \tmp, \tmp, #1
89 msr mdscr_el1, \tmp
Will Deacon2a283072014-04-29 19:04:06 +0100909990:
Catalin Marinas0be73202012-03-05 11:49:26 +000091 .endm
92
Will Deacon2a283072014-04-29 19:04:06 +010093/*
94 * Enable both debug exceptions and interrupts. This is likely to be
95 * faster than two daifclr operations, since writes to this register
96 * are self-synchronising.
97 */
98 .macro enable_dbg_and_irq
99 msr daifclr, #(8 | 2)
Catalin Marinas0be73202012-03-05 11:49:26 +0000100 .endm
101
102/*
103 * SMP data memory barrier
104 */
105 .macro smp_dmb, opt
106#ifdef CONFIG_SMP
107 dmb \opt
108#endif
109 .endm
110
111#define USER(l, x...) \
1129999: x; \
113 .section __ex_table,"a"; \
114 .align 3; \
115 .quad 9999b,l; \
116 .previous
117
118/*
119 * Register aliases.
120 */
121lr .req x30 // link register
Marc Zyngierdc637f12012-10-19 17:37:35 +0100122
123/*
124 * Vector entry
125 */
126 .macro ventry label
127 .align 7
128 b \label
129 .endm
Matthew Leache68beda2013-10-11 14:52:15 +0100130
131/*
132 * Select code when configured for BE.
133 */
134#ifdef CONFIG_CPU_BIG_ENDIAN
135#define CPU_BE(code...) code
136#else
137#define CPU_BE(code...)
138#endif
139
140/*
141 * Select code when configured for LE.
142 */
143#ifdef CONFIG_CPU_BIG_ENDIAN
144#define CPU_LE(code...)
145#else
146#define CPU_LE(code...) code
147#endif
148
Matthew Leach55b89542013-10-11 14:52:13 +0100149/*
150 * Define a macro that constructs a 64-bit value by concatenating two
151 * 32-bit registers. Note that on big endian systems the order of the
152 * registers is swapped.
153 */
154#ifndef CONFIG_CPU_BIG_ENDIAN
155 .macro regs_to_64, rd, lbits, hbits
156#else
157 .macro regs_to_64, rd, hbits, lbits
158#endif
159 orr \rd, \lbits, \hbits, lsl #32
160 .endm
Marc Zyngierf3e39272015-02-20 13:53:13 +0000161
162#endif /* __ASM_ASSEMBLER_H */