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_ASM __REG_SEL(.dword, .word)
27 #define SZREG __REG_SEL(8, 4)
28 #define LGREG __REG_SEL(3, 2)
30 #if __SIZEOF_POINTER__ == 8
32 #define RISCV_PTR .dword
36 #define RISCV_PTR ".dword"
37 #define RISCV_SZPTR "8"
38 #define RISCV_LGPTR "3"
40 #elif __SIZEOF_POINTER__ == 4
42 #define RISCV_PTR .word
46 #define RISCV_PTR ".word"
47 #define RISCV_SZPTR "4"
48 #define RISCV_LGPTR "2"
51 #error "Unexpected __SIZEOF_POINTER__"
54 #if (__SIZEOF_INT__ == 4)
55 #define RISCV_INT __ASM_STR(.word)
56 #define RISCV_SZINT __ASM_STR(4)
57 #define RISCV_LGINT __ASM_STR(2)
59 #error "Unexpected __SIZEOF_INT__"
62 #if (__SIZEOF_SHORT__ == 2)
63 #define RISCV_SHORT __ASM_STR(.half)
64 #define RISCV_SZSHORT __ASM_STR(2)
65 #define RISCV_LGSHORT __ASM_STR(1)
67 #error "Unexpected __SIZEOF_SHORT__"
70 #endif /* _ASM_RISCV_ASM_H */