arch: riscv: add macro to access hardware registers
Add macros to read / write hardware registers. Signed-off-by: Yong Cong Sin <ycsin@meta.com> Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
This commit is contained in:
parent
d267402404
commit
de3a845612
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Meta Platforms
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_ZEPHYR_ARCH_RISCV_REG_H_
|
||||
#define ZEPHYR_INCLUDE_ZEPHYR_ARCH_RISCV_REG_H_
|
||||
|
||||
#define reg_read(reg) \
|
||||
({ \
|
||||
register unsigned long __rv; \
|
||||
__asm__ volatile("mv %0, " STRINGIFY(reg) : "=r"(__rv)); \
|
||||
__rv; \
|
||||
})
|
||||
|
||||
#define reg_write(reg, val) ({ __asm__("mv " STRINGIFY(reg) ", %0" : : "r"(val)); })
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_ZEPHYR_ARCH_RISCV_REG_H_ */
|
Loading…
Reference in New Issue