xref: /openbmc/linux/arch/riscv/include/asm/asm.h (revision 6d99a79c)
1 /*
2  * Copyright (C) 2015 Regents of the University of California
3  *
4  *   This program is free software; you can redistribute it and/or
5  *   modify it under the terms of the GNU General Public License
6  *   as published by the Free Software Foundation, version 2.
7  *
8  *   This program is distributed in the hope that it will be useful,
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *   GNU General Public License for more details.
12  */
13 
14 #ifndef _ASM_RISCV_ASM_H
15 #define _ASM_RISCV_ASM_H
16 
17 #ifdef __ASSEMBLY__
18 #define __ASM_STR(x)	x
19 #else
20 #define __ASM_STR(x)	#x
21 #endif
22 
23 #if __riscv_xlen == 64
24 #define __REG_SEL(a, b)	__ASM_STR(a)
25 #elif __riscv_xlen == 32
26 #define __REG_SEL(a, b)	__ASM_STR(b)
27 #else
28 #error "Unexpected __riscv_xlen"
29 #endif
30 
31 #define REG_L		__REG_SEL(ld, lw)
32 #define REG_S		__REG_SEL(sd, sw)
33 #define SZREG		__REG_SEL(8, 4)
34 #define LGREG		__REG_SEL(3, 2)
35 
36 #if __SIZEOF_POINTER__ == 8
37 #ifdef __ASSEMBLY__
38 #define RISCV_PTR		.dword
39 #define RISCV_SZPTR		8
40 #define RISCV_LGPTR		3
41 #else
42 #define RISCV_PTR		".dword"
43 #define RISCV_SZPTR		"8"
44 #define RISCV_LGPTR		"3"
45 #endif
46 #elif __SIZEOF_POINTER__ == 4
47 #ifdef __ASSEMBLY__
48 #define RISCV_PTR		.word
49 #define RISCV_SZPTR		4
50 #define RISCV_LGPTR		2
51 #else
52 #define RISCV_PTR		".word"
53 #define RISCV_SZPTR		"4"
54 #define RISCV_LGPTR		"2"
55 #endif
56 #else
57 #error "Unexpected __SIZEOF_POINTER__"
58 #endif
59 
60 #if (__SIZEOF_INT__ == 4)
61 #define RISCV_INT		__ASM_STR(.word)
62 #define RISCV_SZINT		__ASM_STR(4)
63 #define RISCV_LGINT		__ASM_STR(2)
64 #else
65 #error "Unexpected __SIZEOF_INT__"
66 #endif
67 
68 #if (__SIZEOF_SHORT__ == 2)
69 #define RISCV_SHORT		__ASM_STR(.half)
70 #define RISCV_SZSHORT		__ASM_STR(2)
71 #define RISCV_LGSHORT		__ASM_STR(1)
72 #else
73 #error "Unexpected __SIZEOF_SHORT__"
74 #endif
75 
76 #endif /* _ASM_RISCV_ASM_H */
77