1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2015 Regents of the University of California
6 #ifndef _ASM_RISCV_ASM_H
7 #define _ASM_RISCV_ASM_H
10 #define __ASM_STR(x) x
12 #define __ASM_STR(x) #x
15 #if __riscv_xlen == 64
16 #define __REG_SEL(a, b) __ASM_STR(a)
17 #elif __riscv_xlen == 32
18 #define __REG_SEL(a, b) __ASM_STR(b)
20 #error "Unexpected __riscv_xlen"
23 #define REG_L __REG_SEL(ld, lw)
24 #define REG_S __REG_SEL(sd, sw)
25 #define REG_SC __REG_SEL(sc.d, sc.w)
26 #define REG_AMOSWAP_AQ __REG_SEL(amoswap.d.aq, amoswap.w.aq)
27 #define REG_ASM __REG_SEL(.dword, .word)
28 #define SZREG __REG_SEL(8, 4)
29 #define LGREG __REG_SEL(3, 2)
31 #if __SIZEOF_POINTER__ == 8
33 #define RISCV_PTR .dword
37 #define RISCV_PTR ".dword"
38 #define RISCV_SZPTR "8"
39 #define RISCV_LGPTR "3"
41 #elif __SIZEOF_POINTER__ == 4
43 #define RISCV_PTR .word
47 #define RISCV_PTR ".word"
48 #define RISCV_SZPTR "4"
49 #define RISCV_LGPTR "2"
52 #error "Unexpected __SIZEOF_POINTER__"
55 #if (__SIZEOF_INT__ == 4)
56 #define RISCV_INT __ASM_STR(.word)
57 #define RISCV_SZINT __ASM_STR(4)
58 #define RISCV_LGINT __ASM_STR(2)
60 #error "Unexpected __SIZEOF_INT__"
63 #if (__SIZEOF_SHORT__ == 2)
64 #define RISCV_SHORT __ASM_STR(.half)
65 #define RISCV_SZSHORT __ASM_STR(2)
66 #define RISCV_LGSHORT __ASM_STR(1)
68 #error "Unexpected __SIZEOF_SHORT__"
72 #include <asm/asm-offsets.h>
74 /* Common assembly source macros */
87 #define PER_CPU_OFFSET_SHIFT 2
89 #define PER_CPU_OFFSET_SHIFT 3
92 .macro asm_per_cpu dst sym tmp
93 REG_L
\tmp
, TASK_TI_CPU_NUM(tp
)
94 slli
\tmp
, \tmp
, PER_CPU_OFFSET_SHIFT
95 la \dst
, __per_cpu_offset
101 #else /* CONFIG_SMP */
102 .macro asm_per_cpu dst sym tmp
105 #endif /* CONFIG_SMP */
107 .macro load_per_cpu dst ptr tmp
108 asm_per_cpu \dst \ptr
\tmp
112 #ifdef CONFIG_SHADOW_CALL_STACK
113 /* gp is used as the shadow call stack pointer instead */
114 .macro load_global_pointer
117 /* load __global_pointer to gp */
118 .macro load_global_pointer
121 la gp
, __global_pointer$
124 #endif /* CONFIG_SHADOW_CALL_STACK */
126 /* save all GPs except x1 ~ x5 */
127 .macro save_from_x6_to_x31
148 REG_S x26
, PT_S10(sp
)
149 REG_S x27
, PT_S11(sp
)
156 /* restore all GPs except x1 ~ x5 */
157 .macro restore_from_x6_to_x31
178 REG_L x26
, PT_S10(sp
)
179 REG_L x27
, PT_S11(sp
)
186 /* Annotate a function as being unsuitable for kprobes. */
187 #ifdef CONFIG_KPROBES
188 #define ASM_NOKPROBE(name) \
189 .pushsection "_kprobe_blacklist", "aw"; \
193 #define ASM_NOKPROBE(name)
196 #endif /* __ASSEMBLY__ */
198 #endif /* _ASM_RISCV_ASM_H */