Skip to content

Commit de3a845

Browse files
ycsindkalowsk
authored andcommitted
arch: riscv: add macro to access hardware registers
Add macros to read / write hardware registers. Signed-off-by: Yong Cong Sin <[email protected]> Signed-off-by: Yong Cong Sin <[email protected]>
1 parent d267402 commit de3a845

File tree

1 file changed

+19
-0
lines changed
  • include/zephyr/arch/riscv

1 file changed

+19
-0
lines changed

include/zephyr/arch/riscv/reg.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2024 Meta Platforms
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_ZEPHYR_ARCH_RISCV_REG_H_
8+
#define ZEPHYR_INCLUDE_ZEPHYR_ARCH_RISCV_REG_H_
9+
10+
#define reg_read(reg) \
11+
({ \
12+
register unsigned long __rv; \
13+
__asm__ volatile("mv %0, " STRINGIFY(reg) : "=r"(__rv)); \
14+
__rv; \
15+
})
16+
17+
#define reg_write(reg, val) ({ __asm__("mv " STRINGIFY(reg) ", %0" : : "r"(val)); })
18+
19+
#endif /* ZEPHYR_INCLUDE_ZEPHYR_ARCH_RISCV_REG_H_ */

0 commit comments

Comments
 (0)