diff --git a/Makefile.am b/Makefile.am index 39554eab..8057f663 100644 --- a/Makefile.am +++ b/Makefile.am @@ -87,6 +87,7 @@ nobase_include_HEADERS = \ metal/clock.h \ metal/compiler.h \ metal/cpu.h \ + metal/csr.h \ metal/gpio.h \ metal/init.h \ metal/interrupt.h \ diff --git a/Makefile.in b/Makefile.in index ee91f0a6..654c3410 100644 --- a/Makefile.in +++ b/Makefile.in @@ -514,6 +514,7 @@ nobase_include_HEADERS = \ metal/clock.h \ metal/compiler.h \ metal/cpu.h \ + metal/csr.h \ metal/gpio.h \ metal/init.h \ metal/interrupt.h \ diff --git a/metal/csr.h b/metal/csr.h new file mode 100644 index 00000000..8375d8a4 --- /dev/null +++ b/metal/csr.h @@ -0,0 +1,32 @@ +/* Copyright 2019 SiFive, Inc */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#ifndef METAL__CSR_H +#define METAL__CSR_H + +#include +#include +#include + +/*! + * @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 METAL_CPU_GET_CSR(reg, value) \ + __asm__ volatile("csrr %0, " #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 " #reg ", %0" : : "r"(value)); + +#endif // METAL__CSR_H