aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv/include/csr.h
blob: ab25bdd0462c1302995b1ecf514b7a9750361e5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef APOS_CSR_H
#define APOS_CSR_H

#include <apos/utils.h>

#define SATP_MODE_Sv32 0x80000000
#define SATP_MODE_Sv39 0x8000000000000000
#define SATP_MODE_Sv48 0x9000000000000000

#define CSR_SATP 0x180

/* directly lifted from Linux:/arch/riscv/include/asm/asm.h:9-13 */
#ifdef __ASSEMBLY__
#define __ASM_STR(x) x
#else
#define __ASM_STR(x) #x
#endif

#define csr_read(csr, res)\
	__asm__ ("csrr %0, " __ASM_STR(csr) : "=r" (res) : : "memory")

#define csr_write(csr, val)\
	__asm__ ("csrw " __ASM_STR(csr) ", %0" : : "rK" (val) : "memory")

#endif /* APOS_CSR_H */