1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2015 Regents of the University of California
4 */
5
6#ifndef _ASM_RISCV_ASM_H
7#define _ASM_RISCV_ASM_H
8
9#ifdef __ASSEMBLY__
10#define __ASM_STR(x)	x
11#else
12#define __ASM_STR(x)	#x
13#endif
14
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)
19#else
20#error "Unexpected __riscv_xlen"
21#endif
22
23#define REG_L		__REG_SEL(ld, lw)
24#define REG_S		__REG_SEL(sd, sw)
25#define SZREG		__REG_SEL(8, 4)
26#define LGREG		__REG_SEL(3, 2)
27
28#if __SIZEOF_POINTER__ == 8
29#ifdef __ASSEMBLY__
30#define RISCV_PTR		.dword
31#define RISCV_SZPTR		8
32#define RISCV_LGPTR		3
33#else
34#define RISCV_PTR		".dword"
35#define RISCV_SZPTR		"8"
36#define RISCV_LGPTR		"3"
37#endif
38#elif __SIZEOF_POINTER__ == 4
39#ifdef __ASSEMBLY__
40#define RISCV_PTR		.word
41#define RISCV_SZPTR		4
42#define RISCV_LGPTR		2
43#else
44#define RISCV_PTR		".word"
45#define RISCV_SZPTR		"4"
46#define RISCV_LGPTR		"2"
47#endif
48#else
49#error "Unexpected __SIZEOF_POINTER__"
50#endif
51
52#if (__SIZEOF_INT__ == 4)
53#define RISCV_INT		__ASM_STR(.word)
54#define RISCV_SZINT		__ASM_STR(4)
55#define RISCV_LGINT		__ASM_STR(2)
56#else
57#error "Unexpected __SIZEOF_INT__"
58#endif
59
60#if (__SIZEOF_SHORT__ == 2)
61#define RISCV_SHORT		__ASM_STR(.half)
62#define RISCV_SZSHORT		__ASM_STR(2)
63#define RISCV_LGSHORT		__ASM_STR(1)
64#else
65#error "Unexpected __SIZEOF_SHORT__"
66#endif
67
68#endif /* _ASM_RISCV_ASM_H */
69