-
Notifications
You must be signed in to change notification settings - Fork 46
/
csr.h
35 lines (27 loc) · 1.02 KB
/
csr.h
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
26
27
28
29
30
31
32
33
34
35
/* Copyright 2019 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */
#ifndef METAL__CSR_H
#define METAL__CSR_H
#include <metal/compiler.h>
#include <stddef.h>
#include <stdint.h>
/*!
* @file csr.h
* @brief A collection of APIs for get and set CSR registers
*/
/*!
* @brief Read a given CSR register without checking validity of CSR offset
* @param crs Register label or hex value offset to read from
* @param value Variable name of uintprt_t type to get the value
*/
#define __ASM_STR(x) #x
#define METAL_CPU_GET_CSR(reg, value) \
__asm__ volatile("csrr %0, " __ASM_STR(reg) : "=r"(value));
/*!
* @brief Write to a given CSR register without checking validity of CSR offset
* @param crs Register label or hex value offset to write to
* @param value Variable name of uintprt_t type to set the value
*/
#define METAL_CPU_SET_CSR(reg, value) \
__asm__ volatile("csrw " __ASM_STR(reg) ", %0" : : "r"(value));
#endif // METAL__CSR_H