-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from sifive/esat-25
Add macro & inline for get/set CSR
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* 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 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 |