summaryrefslogtreecommitdiff
path: root/na/arch
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-05-02 01:38:31 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-05-02 01:38:31 +0800
commit3ee616fac367431261fd2ef99e06cfe3e5d27263 (patch)
treeb5ee5dfe1a2233411e48ae2e5a361084efb152a2 /na/arch
parent729cb9873accdf4ef59fddc8963b14ac3a6c342a (diff)
downloadlume-3ee616fac367431261fd2ef99e06cfe3e5d27263.tar.gz
lume-3ee616fac367431261fd2ef99e06cfe3e5d27263.tar.xz
feat: add timer interrupt enable/disable functions for RISC-V architecture
Diffstat (limited to 'na/arch')
-rw-r--r--na/arch/riscv/include/arch/cpu.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/na/arch/riscv/include/arch/cpu.h b/na/arch/riscv/include/arch/cpu.h
index 644ae37..d16cf2d 100644
--- a/na/arch/riscv/include/arch/cpu.h
+++ b/na/arch/riscv/include/arch/cpu.h
@@ -22,6 +22,11 @@
#define SSTATUS_SPIE (1UL << 5) /* Supervisor Previous Interrupt Enable */
#define SSTATUS_SPP (1UL << 8) /* Supervisor Previous Privilege (0=U, 1=S) */
+/* RISC-V sie register bit definitions */
+#define SIE_SSIE (1UL << 1) /* Supervisor Software Interrupt Enable */
+#define SIE_STIE (1UL << 5) /* Supervisor Timer Interrupt Enable */
+#define SIE_SEIE (1UL << 9) /* Supervisor External Interrupt Enable */
+
namespace arch::cpu {
// Get current CPU ID (from tp register, set by entry.S)
@@ -61,4 +66,14 @@ static inline uint64 read_time() {
return val;
}
+// Enable timer interrupt in sie (sie.STIE = 1)
+static inline void timer_intr_on() {
+ __asm__ volatile("csrs sie, %0" :: "r"(SIE_STIE));
+}
+
+// Disable timer interrupt in sie (sie.STIE = 0)
+static inline void timer_intr_off() {
+ __asm__ volatile("csrc sie, %0" :: "r"(SIE_STIE));
+}
+
} // namespace arch::cpu