diff --git a/src/kernel/arch/aarch64/backtrace.cpp b/src/kernel/arch/aarch64/backtrace.cpp
index 30d1741cc..d1233305d 100644
--- a/src/kernel/arch/aarch64/backtrace.cpp
+++ b/src/kernel/arch/aarch64/backtrace.cpp
@@ -14,9 +14,9 @@
*/
#include "arch.h"
-#include "cpu.hpp"
-#include "sk_cstdio"
+#include "cpu/cpu.hpp"
#include "kernel_elf.hpp"
+#include "sk_cstdio"
#include "sk_libc.h"
int backtrace(void **buffer, int size) {
diff --git a/src/kernel/arch/aarch64/include/cpu/cpu.hpp b/src/kernel/arch/aarch64/include/cpu/cpu.hpp
new file mode 100644
index 000000000..0650d97d9
--- /dev/null
+++ b/src/kernel/arch/aarch64/include/cpu/cpu.hpp
@@ -0,0 +1,30 @@
+
+/**
+ * @file cpu.hpp
+ * @brief aarch64 cpu 相关定义
+ * @author Zone.N (Zone.Niuzh@hotmail.com)
+ * @version 1.0
+ * @date 2024-03-05
+ * @copyright MIT LICENSE
+ * https://github.com/Simple-XX/SimpleKernel
+ * @par change log:
+ *
+ * Date | Author | Description
+ * |
---|
2024-03-05 | Zone.N (Zone.Niuzh@hotmail.com) | 创建文件
+ * |
+ */
+
+#ifndef SIMPLEKERNEL_SRC_KERNEL_ARCH_AARCH64_INCLUDE_CPU_CPU_HPP_
+#define SIMPLEKERNEL_SRC_KERNEL_ARCH_AARCH64_INCLUDE_CPU_CPU_HPP_
+
+#include
+#include
+#include
+#include
+
+#include "kernel_log.hpp"
+#include "sk_cstdio"
+#include "sk_iostream"
+#include "sr.hpp"
+
+#endif // SIMPLEKERNEL_SRC_KERNEL_ARCH_AARCH64_INCLUDE_CPU_CPU_HPP_
diff --git a/src/kernel/arch/aarch64/include/cpu.hpp b/src/kernel/arch/aarch64/include/cpu/sr.hpp
similarity index 86%
rename from src/kernel/arch/aarch64/include/cpu.hpp
rename to src/kernel/arch/aarch64/include/cpu/sr.hpp
index f0e740793..eccd8a7ae 100644
--- a/src/kernel/arch/aarch64/include/cpu.hpp
+++ b/src/kernel/arch/aarch64/include/cpu/sr.hpp
@@ -1,7 +1,7 @@
/**
- * @file cpu.hpp
- * @brief aarch64 cpu 相关定义
+ * @file sr.hpp
+ * @brief aarch64 sr 相关定义
* @author Zone.N (Zone.Niuzh@hotmail.com)
* @version 1.0
* @date 2024-03-05
@@ -14,17 +14,17 @@
*
*/
-#ifndef SIMPLEKERNEL_SRC_KERNEL_ARCH_AARCH64_INCLUDE_CPU_HPP_
-#define SIMPLEKERNEL_SRC_KERNEL_ARCH_AARCH64_INCLUDE_CPU_HPP_
+#ifndef SIMPLEKERNEL_SRC_KERNEL_ARCH_AARCH64_INCLUDE_CPU_SR_HPP_
+#define SIMPLEKERNEL_SRC_KERNEL_ARCH_AARCH64_INCLUDE_CPU_SR_HPP_
#include
#include
#include
#include
+#include "kernel_log.hpp"
#include "sk_cstdio"
#include "sk_iostream"
-#include "kernel_log.hpp"
/**
* aarch64 cpu 相关定义
@@ -33,7 +33,7 @@
namespace cpu {
// 第一部分:寄存器定义
-namespace reginfo {
+namespace register_info {
struct RegInfoBase {
/// 寄存器数据类型
@@ -53,7 +53,7 @@ struct RegInfoBase {
/// 通用寄存器
struct X29Info : public RegInfoBase {};
-}; // namespace reginfo
+}; // namespace register_info
// 第二部分:读/写模版实现
namespace {
@@ -80,10 +80,10 @@ class ReadOnlyRegBase {
*/
static __always_inline RegInfo::DataType Read() {
typename RegInfo::DataType value{};
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("mov %0, x29" : "=r"(value) : :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
return value;
@@ -117,10 +117,10 @@ class WriteOnlyRegBase {
* @param value 要写的值
*/
static __always_inline void Write(RegInfo::DataType value) {
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("mv fp, %0" : : "r"(value) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
}
@@ -146,7 +146,7 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
};
// 第三部分:寄存器实例
-class X29 : public ReadWriteRegBase {
+class X29 : public ReadWriteRegBase {
public:
friend sk_std::ostream &operator<<(sk_std::ostream &os, const X29 &x29) {
printf("val: 0x%p", (void *)x29.Read());
@@ -166,4 +166,4 @@ struct AllXreg {
}; // namespace cpu
-#endif // SIMPLEKERNEL_SRC_KERNEL_ARCH_AARCH64_INCLUDE_CPU_HPP_
+#endif // SIMPLEKERNEL_SRC_KERNEL_ARCH_AARCH64_INCLUDE_CPU_SR_HPP_
diff --git a/src/kernel/arch/aarch64/interrupt.cpp b/src/kernel/arch/aarch64/interrupt.cpp
index aad7ae143..b4fea79d4 100644
--- a/src/kernel/arch/aarch64/interrupt.cpp
+++ b/src/kernel/arch/aarch64/interrupt.cpp
@@ -15,10 +15,10 @@
#include "interrupt.h"
-#include "cstdio"
#include "kernel_log.hpp"
+#include "sk_cstdio"
-Interrupt::Interrupt() { Info("Interrupt init.\n"); }
+Interrupt::Interrupt() { klog::Info("Interrupt init.\n"); }
void Interrupt::Do(uint64_t cause, uint8_t *context) {
(void)cause;
@@ -31,7 +31,7 @@ void Interrupt::RegisterInterruptFunc(uint64_t cause, InterruptFunc func) {
}
uint32_t InterruptInit(uint32_t, uint8_t *) {
- Info("Hello InterruptInit\n");
+ klog::Info("Hello InterruptInit\n");
return 0;
}
diff --git a/src/kernel/arch/aarch64/interrupt.h b/src/kernel/arch/aarch64/interrupt.h
index 9cc8277c0..cf03a83a1 100644
--- a/src/kernel/arch/aarch64/interrupt.h
+++ b/src/kernel/arch/aarch64/interrupt.h
@@ -19,10 +19,10 @@
#include
-#include "cpu.hpp"
+#include "cpu/cpu.hpp"
#include "interrupt_base.h"
#include "singleton.hpp"
-#include "stdio.h"
+#include "sk_stdio.h"
class Interrupt final : public InterruptBase {
public:
diff --git a/src/kernel/arch/riscv64/arch_main.cpp b/src/kernel/arch/riscv64/arch_main.cpp
index 1cbe6e87f..57f692e02 100644
--- a/src/kernel/arch/riscv64/arch_main.cpp
+++ b/src/kernel/arch/riscv64/arch_main.cpp
@@ -16,7 +16,7 @@
#include
#include "basic_info.hpp"
-#include "cpu.hpp"
+#include "cpu/cpu.hpp"
#include "kernel_elf.hpp"
#include "kernel_fdt.hpp"
#include "ns16550a.h"
@@ -78,7 +78,7 @@ uint32_t ArchInit(uint32_t argc, uint8_t *argv) {
// 解析内核 elf 信息
kKernelElf.GetInstance() = KernelElf();
- log::Info("Hello riscv64 ArchInit\n");
+ klog::Info("Hello riscv64 ArchInit\n");
return 0;
}
diff --git a/src/kernel/arch/riscv64/backtrace.cpp b/src/kernel/arch/riscv64/backtrace.cpp
index 529188a9f..9aac9952a 100644
--- a/src/kernel/arch/riscv64/backtrace.cpp
+++ b/src/kernel/arch/riscv64/backtrace.cpp
@@ -15,10 +15,10 @@
*/
#include "arch.h"
-#include "cpu.hpp"
-#include "sk_cstdio"
+#include "cpu/cpu.hpp"
#include "kernel_elf.hpp"
#include "kernel_fdt.hpp"
+#include "sk_cstdio"
#include "sk_libc.h"
int backtrace(void **buffer, int size) {
diff --git a/src/kernel/arch/riscv64/include/cpu/cpu.hpp b/src/kernel/arch/riscv64/include/cpu/cpu.hpp
new file mode 100644
index 000000000..88f27f727
--- /dev/null
+++ b/src/kernel/arch/riscv64/include/cpu/cpu.hpp
@@ -0,0 +1,30 @@
+
+/**
+ * @file cpu.hpp
+ * @brief riscv64 cpu 相关定义
+ * @author Zone.N (Zone.Niuzh@hotmail.com)
+ * @version 1.0
+ * @date 2024-03-05
+ * @copyright MIT LICENSE
+ * https://github.com/Simple-XX/SimpleKernel
+ * @par change log:
+ *
+ * Date | Author | Description
+ * |
---|
2024-03-05 | Zone.N (Zone.Niuzh@hotmail.com) | 创建文件
+ * |
+ */
+
+#ifndef SIMPLEKERNEL_SRC_KERNEL_ARCH_RISCV64_INCLUDE_CPU_CPU_HPP_
+#define SIMPLEKERNEL_SRC_KERNEL_ARCH_RISCV64_INCLUDE_CPU_CPU_HPP_
+
+#include
+#include
+#include
+#include
+
+#include "csr.hpp"
+#include "kernel_log.hpp"
+#include "sk_cstdio"
+#include "sk_iostream"
+
+#endif // SIMPLEKERNEL_SRC_KERNEL_ARCH_RISCV64_INCLUDE_CPU_CPU_HPP_
diff --git a/src/kernel/arch/riscv64/include/cpu.hpp b/src/kernel/arch/riscv64/include/cpu/csr.hpp
similarity index 70%
rename from src/kernel/arch/riscv64/include/cpu.hpp
rename to src/kernel/arch/riscv64/include/cpu/csr.hpp
index 634f478bb..7ac8e68ca 100644
--- a/src/kernel/arch/riscv64/include/cpu.hpp
+++ b/src/kernel/arch/riscv64/include/cpu/csr.hpp
@@ -1,7 +1,7 @@
/**
- * @file cpu.hpp
- * @brief riscv64 cpu 相关定义
+ * @file csr.hpp
+ * @brief riscv64 csr 相关定义
* @author Zone.N (Zone.Niuzh@hotmail.com)
* @version 1.0
* @date 2024-03-05
@@ -14,8 +14,8 @@
*
*/
-#ifndef SIMPLEKERNEL_SRC_KERNEL_ARCH_RISCV64_INCLUDE_CPU_HPP_
-#define SIMPLEKERNEL_SRC_KERNEL_ARCH_RISCV64_INCLUDE_CPU_HPP_
+#ifndef SIMPLEKERNEL_SRC_KERNEL_ARCH_RISCV64_INCLUDE_CPU_CSR_HPP_
+#define SIMPLEKERNEL_SRC_KERNEL_ARCH_RISCV64_INCLUDE_CPU_CSR_HPP_
#include
#include
@@ -27,7 +27,7 @@
#include "sk_iostream"
/**
- * riscv64 cpu 相关定义
+ * riscv64 cpu Control and Status Registers 相关定义
* @note 寄存器读写设计见 arch/README.md
* @see priv-isa.pdf
* https://github.com/riscv/riscv-isa-manual/releases/tag/20240411/priv-isa-asciidoc.pdf
@@ -39,7 +39,7 @@
namespace cpu {
// 第一部分:寄存器定义
-namespace reginfo {
+namespace register_info {
struct RegInfoBase {
/// 寄存器数据类型
@@ -384,7 +384,7 @@ struct StimecmpInfo : public RegInfoBase {};
}; // namespace csr
-}; // namespace reginfo
+}; // namespace register_info
// 第二部分:读/写模版实现
namespace {
@@ -411,44 +411,51 @@ class ReadOnlyRegBase {
*/
static __always_inline RegInfo::DataType Read() {
typename RegInfo::DataType value{};
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("mv %0, fp" : "=r"(value) : :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SstatusInfo>::value) {
__asm__ volatile("csrr %0, sstatus" : "=r"(value) : :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrr %0, stvec" : "=r"(value) : :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrr %0, sip" : "=r"(value) : :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrr %0, sie" : "=r"(value) : :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrr %0, time" : "=r"(value) : :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::CycleInfo>::value) {
__asm__ volatile("csrr %0, cycle" : "=r"(value) : :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::InstretInfo>::value) {
__asm__ volatile("csrr %0, instret" : "=r"(value) : :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrr %0, sscratch" : "=r"(value) : :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrr %0, sepc" : "=r"(value) : :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrr %0, scause" : "=r"(value) : :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrr %0, stval" : "=r"(value) : :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrr %0, satp" : "=r"(value) : :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SatpInfo>::value) {
+ __asm__ volatile("csrr %0, satp" : "=r"(value) : :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::StimecmpInfo>::value) {
__asm__ volatile("csrr %0, stimecmp" : "=r"(value) : :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
return value;
@@ -482,33 +489,38 @@ class WriteOnlyRegBase {
* @param value 要写的值
*/
static __always_inline void Write(RegInfo::DataType value) {
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("mv fp, %0" : : "r"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SstatusInfo>::value) {
__asm__ volatile("csrw sstatus, %0" : : "r"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrw stvec, %0" : : "r"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrw sip, %0" : : "r"(value) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrw sie, %0" : : "r"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrw sie, %0" : : "r"(value) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrw sscratch, %0" : : "r"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrw sepc, %0" : : "r"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrw scause, %0" : : "r"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrw stval, %0" : : "r"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrw satp, %0" : : "r"(value) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
}
@@ -519,30 +531,36 @@ class WriteOnlyRegBase {
* @note 只能写 kCsrImmOpMask 范围内的值
*/
static __always_inline void WriteImm(const uint8_t value) {
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrwi sstatus, %0" : : "i"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrwi stvec, %0" : : "i"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrwi sip, %0" : : "i"(value) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrwi sie, %0" : : "i"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrwi sie, %0" : : "i"(value) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrwi sscratch, %0" : : "i"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrwi sepc, %0" : : "i"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrwi scause, %0" : : "i"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrwi stval, %0" : : "i"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrwi satp, %0" : : "i"(value) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
}
@@ -552,30 +570,36 @@ class WriteOnlyRegBase {
* @param mask 掩码
*/
static __always_inline void SetBits(uint64_t mask) {
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrs zero, sstatus, %0" : : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrs zero, stvec, %0" : : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrs zero, sip, %0" : : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrs zero, sie, %0" : : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrs zero, sie, %0" : : "r"(mask) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrs zero, sscratch, %0" : : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrs zero, sepc, %0" : : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrs zero, scause, %0" : : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrs zero, stval, %0" : : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrs zero, satp, %0" : : "r"(mask) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
}
@@ -585,30 +609,36 @@ class WriteOnlyRegBase {
* @param mask 掩码
*/
static __always_inline void ClearBits(uint64_t mask) {
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrc zero, sstatus, %0" : : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrc zero, stvec, %0" : : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrc zero, sip, %0" : : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrc zero, sie, %0" : : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrc zero, sie, %0" : : "r"(mask) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrc zero, sscratch, %0" : : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrc zero, sepc, %0" : : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrc zero, scause, %0" : : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrc zero, stval, %0" : : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrc zero, satp, %0" : : "r"(mask) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
}
@@ -619,30 +649,36 @@ class WriteOnlyRegBase {
* @note 只能写 kCsrImmOpMask 范围内的值
*/
static __always_inline void SetBitsImm(const uint8_t mask) {
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrsi zero, sstatus, %0" : : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrsi zero, stvec, %0" : : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrsi zero, sip, %0" : : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrsi zero, sie, %0" : : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrsi zero, sie, %0" : : "i"(mask) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrsi zero, sscratch, %0" : : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrsi zero, sepc, %0" : : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrsi zero, scause, %0" : : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrsi zero, stval, %0" : : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrsi zero, satp, %0" : : "i"(mask) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
}
@@ -653,30 +689,36 @@ class WriteOnlyRegBase {
* @note 只能写 kCsrImmOpMask 范围内的值
*/
static __always_inline void ClearBitsImm(const uint8_t mask) {
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrci zero, sstatus, %0" : : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrci zero, stvec, %0" : : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrci zero, sip, %0" : : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrci zero, sie, %0" : : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrci zero, sie, %0" : : "i"(mask) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrci zero, sscratch, %0" : : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrci zero, sepc, %0" : : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrci zero, scause, %0" : : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrci zero, stval, %0" : : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrci zero, satp, %0" : : "i"(mask) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
}
@@ -687,7 +729,7 @@ class WriteOnlyRegBase {
*/
template
static void WriteConst() {
- if constexpr ((value & reginfo::csr::kCsrImmOpMask) == value) {
+ if constexpr ((value & register_info::csr::kCsrImmOpMask) == value) {
WriteImm(value);
} else {
Write(value);
@@ -700,7 +742,7 @@ class WriteOnlyRegBase {
*/
template
static void SetConst() {
- if constexpr ((mask & reginfo::csr::kCsrImmOpMask) == mask) {
+ if constexpr ((mask & register_info::csr::kCsrImmOpMask) == mask) {
SetBitsImm(mask);
} else {
SetBits(mask);
@@ -713,7 +755,7 @@ class WriteOnlyRegBase {
*/
template
static void ClearConst() {
- if constexpr ((mask & reginfo::csr::kCsrImmOpMask) == mask) {
+ if constexpr ((mask & register_info::csr::kCsrImmOpMask) == mask) {
ClearBitsImm(mask);
} else {
ClearBits(mask);
@@ -751,36 +793,42 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
*/
static __always_inline RegInfo::DataType ReadWrite(RegInfo::DataType value) {
typename RegInfo::DataType old_value{};
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrw %0, sstatus, %1"
: "=r"(old_value)
: "r"(value)
:);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrw %0, stvec, %1" : "=r"(old_value) : "r"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrw %0, sip, %1" : "=r"(old_value) : "r"(value) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrw %0, sie, %1" : "=r"(old_value) : "r"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrw %0, sie, %1" : "=r"(old_value) : "r"(value) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrw %0, sscratch, %1"
: "=r"(old_value)
: "r"(value)
:);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrw %0, sepc, %1" : "=r"(old_value) : "r"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrw %0, scause, %1" : "=r"(old_value) : "r"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrw %0, stval, %1" : "=r"(old_value) : "r"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrw %0, satp, %1" : "=r"(old_value) : "r"(value) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
return old_value;
@@ -794,39 +842,45 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
*/
static __always_inline RegInfo::DataType ReadWriteImm(const uint8_t value) {
typename RegInfo::DataType old_value{};
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrwi %0, sstatus, %1"
: "=r"(old_value)
: "i"(value)
:);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrwi %0, stvec, %1" : "=r"(old_value) : "i"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrwi %0, sip, %1" : "=r"(old_value) : "i"(value) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrwi %0, sie, %1" : "=r"(old_value) : "i"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrwi %0, sie, %1" : "=r"(old_value) : "i"(value) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrwi %0, sscratch, %1"
: "=r"(old_value)
: "i"(value)
:);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrwi %0, sepc, %1" : "=r"(old_value) : "i"(value) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrwi %0, scause, %1"
: "=r"(old_value)
: "i"(value)
:);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrwi %0, stval, %1" : "=r"(old_value) : "i"(value) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrwi %0, satp, %1" : "=r"(old_value) : "i"(value) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
return old_value;
@@ -839,7 +893,7 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
*/
template
static RegInfo::DataType ReadWriteConst() {
- if constexpr ((value & reginfo::csr::kCsrImmOpMask) == value) {
+ if constexpr ((value & register_info::csr::kCsrImmOpMask) == value) {
return ReadWriteRegBase::ReadWriteImm(value);
} else {
return ReadWrite(value);
@@ -853,30 +907,36 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
*/
static __always_inline RegInfo::DataType ReadSetBits(uint64_t mask) {
typename RegInfo::DataType value{};
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrs %0, sstatus, %1" : "=r"(value) : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrs %0, stvec, %1" : "=r"(value) : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrs %0, sip, %1" : "=r"(value) : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrs %0, sie, %1" : "=r"(value) : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrs %0, sie, %1" : "=r"(value) : "r"(mask) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrs %0, sscratch, %1" : "=r"(value) : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrs %0, sepc, %1" : "=r"(value) : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrs %0, scause, %1" : "=r"(value) : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrs %0, stval, %1" : "=r"(value) : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrs %0, satp, %1" : "=r"(value) : "r"(mask) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
return value;
@@ -889,30 +949,36 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
*/
static __always_inline RegInfo::DataType ReadSetBitsImm(const uint8_t mask) {
typename RegInfo::DataType value{};
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrsi %0, sstatus, %1" : "=r"(value) : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrsi %0, stvec, %1" : "=r"(value) : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrsi %0, sip, %1" : "=r"(value) : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrsi %0, sie, %1" : "=r"(value) : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrsi %0, sie, %1" : "=r"(value) : "i"(mask) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrsi %0, sscratch, %1" : "=r"(value) : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrsi %0, sepc, %1" : "=r"(value) : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrsi %0, scause, %1" : "=r"(value) : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrsi %0, stval, %1" : "=r"(value) : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrsi %0, satp, %1" : "=r"(value) : "i"(mask) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
return value;
@@ -925,7 +991,7 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
*/
template
static RegInfo::DataType ReadSetBitsConst() {
- if constexpr ((mask & reginfo::csr::kCsrImmOpMask) == mask) {
+ if constexpr ((mask & register_info::csr::kCsrImmOpMask) == mask) {
return ReadSetBitsImm(mask);
} else {
return ReadSetBits(mask);
@@ -939,30 +1005,36 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
*/
static __always_inline RegInfo::DataType ReadClearBits(uint64_t mask) {
typename RegInfo::DataType value{};
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrc %0, sstatus, %1" : "=r"(value) : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrc %0, stvec, %1" : "=r"(value) : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrc %0, sip, %1" : "=r"(value) : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrc %0, sie, %1" : "=r"(value) : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrc %0, sie, %1" : "=r"(value) : "r"(mask) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrc %0, sscratch, %1" : "=r"(value) : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrc %0, sepc, %1" : "=r"(value) : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrc %0, scause, %1" : "=r"(value) : "r"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrc %0, stval, %1" : "=r"(value) : "r"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrc %0, satp, %1" : "=r"(value) : "r"(mask) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
return value;
@@ -976,30 +1048,36 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
static __always_inline RegInfo::DataType ReadClearBitsImm(
const uint8_t mask) {
typename RegInfo::DataType value{};
- if constexpr (std::is_same::value) {
+ if constexpr (std::is_same::value) {
__asm__ volatile("csrrci %0, sstatus, %1" : "=r"(value) : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvecInfo>::value) {
__asm__ volatile("csrrci %0, stvec, %1" : "=r"(value) : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrci %0, sip, %1" : "=r"(value) : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
- __asm__ volatile("csrrci %0, sie, %1" : "=r"(value) : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::SieInfo>::value) {
+ __asm__ volatile("csrrci %0, sie, %1" : "=r"(value) : "i"(mask) :);
+ } else if constexpr (std::is_same<
+ RegInfo,
+ register_info::csr::SscratchInfo>::value) {
__asm__ volatile("csrrci %0, sscratch, %1" : "=r"(value) : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrci %0, sepc, %1" : "=r"(value) : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::ScauseInfo>::value) {
__asm__ volatile("csrrci %0, scause, %1" : "=r"(value) : "i"(mask) :);
} else if constexpr (std::is_same::value) {
+ register_info::csr::StvalInfo>::value) {
__asm__ volatile("csrrci %0, stval, %1" : "=r"(value) : "i"(mask) :);
- } else if constexpr (std::is_same::value) {
+ } else if constexpr (std::is_same::value) {
__asm__ volatile("csrrci %0, satp, %1" : "=r"(value) : "i"(mask) :);
} else {
- log::Err("No Type\n");
+ klog::Err("No Type\n");
throw;
}
return value;
@@ -1012,7 +1090,7 @@ class ReadWriteRegBase : public ReadOnlyRegBase,
*/
template
static RegInfo::DataType ReadClearBitsConst() {
- if constexpr ((mask & reginfo::csr::kCsrImmOpMask) == mask) {
+ if constexpr ((mask & register_info::csr::kCsrImmOpMask) == mask) {
return WriteOnlyRegBase::ReadClearBitsImm(mask);
} else {
return ReadClearBits(mask);
@@ -1080,7 +1158,7 @@ class WriteOnlyField {
* 置位对应 Reg 的由 RegInfo 规定的指定位
*/
static __always_inline void Set() {
- if constexpr ((RegInfo::kBitMask & reginfo::csr::kCsrImmOpMask) ==
+ if constexpr ((RegInfo::kBitMask & register_info::csr::kCsrImmOpMask) ==
RegInfo::kBitMask) {
Reg::SetBitsImm(RegInfo::kBitMask);
} else {
@@ -1092,7 +1170,7 @@ class WriteOnlyField {
* 清零对应 Reg 的由 RegInfo 规定的指定位
*/
static __always_inline void Clear() {
- if constexpr ((RegInfo::kBitMask & reginfo::csr::kCsrImmOpMask) ==
+ if constexpr ((RegInfo::kBitMask & register_info::csr::kCsrImmOpMask) ==
RegInfo::kBitMask) {
Reg::ClearBitsImm(RegInfo::kBitMask);
} else {
@@ -1147,7 +1225,7 @@ class ReadWriteField : public ReadOnlyField,
};
// 第三部分:寄存器实例
-class Fp : public ReadWriteRegBase {
+class Fp : public ReadWriteRegBase {
public:
friend sk_std::ostream &operator<<(sk_std::ostream &os, const Fp &fp) {
printf("val: 0x%p", (void *)fp.Read());
@@ -1162,16 +1240,16 @@ struct AllXreg {
namespace csr {
-class Sstatus : public ReadWriteRegBase {
+class Sstatus : public ReadWriteRegBase {
public:
- ReadWriteField,
- reginfo::csr::SstatusInfo::Sie>
+ ReadWriteField,
+ register_info::csr::SstatusInfo::Sie>
sie;
- ReadWriteField,
- reginfo::csr::SstatusInfo::Spie>
+ ReadWriteField,
+ register_info::csr::SstatusInfo::Spie>
spie;
- ReadWriteField,
- reginfo::csr::SstatusInfo::Spp>
+ ReadWriteField,
+ register_info::csr::SstatusInfo::Spp>
spp;
/// @name 构造/析构函数
@@ -1184,7 +1262,8 @@ class Sstatus : public ReadWriteRegBase {
virtual ~Sstatus() = default;
/// @}
- friend sk_std::ostream &operator<<(sk_std::ostream &os, const Sstatus &sstatus) {
+ friend sk_std::ostream &operator<<(sk_std::ostream &os,
+ const Sstatus &sstatus) {
auto sie = sstatus.sie.Get();
auto spie = sstatus.spie.Get();
auto spp = sstatus.spp.Get();
@@ -1198,18 +1277,18 @@ class Sstatus : public ReadWriteRegBase {
}
};
-class Stvec : public ReadWriteRegBase {
+class Stvec : public ReadWriteRegBase {
public:
- ReadWriteField,
- reginfo::csr::StvecInfo::Base>
+ ReadWriteField,
+ register_info::csr::StvecInfo::Base>
base;
- ReadWriteField,
- reginfo::csr::StvecInfo::Mode>
+ ReadWriteField,
+ register_info::csr::StvecInfo::Mode>
mode;
void SetDirect(uint64_t addr) {
base.Write(addr);
- mode.Write(reginfo::csr::StvecInfo::kDirect);
+ mode.Write(register_info::csr::StvecInfo::kDirect);
}
/// @name 构造/析构函数
@@ -1226,22 +1305,23 @@ class Stvec : public ReadWriteRegBase {
auto mode = stvec.mode.Get();
auto base = stvec.base.Get();
printf("val: 0x%p, mode: %s, base: 0x%lX", (void *)stvec.Read(),
- (mode == reginfo::csr::StvecInfo::kDirect ? "Direct" : "Vectored"),
+ (mode == register_info::csr::StvecInfo::kDirect ? "Direct"
+ : "Vectored"),
base);
return os;
}
};
-class Sip : public ReadWriteRegBase {
+class Sip : public ReadWriteRegBase {
public:
- ReadWriteField,
- reginfo::csr::SipInfo::Ssip>
+ ReadWriteField,
+ register_info::csr::SipInfo::Ssip>
ssip;
- ReadWriteField,
- reginfo::csr::SipInfo::Stip>
+ ReadWriteField,
+ register_info::csr::SipInfo::Stip>
stip;
- ReadWriteField,
- reginfo::csr::SipInfo::Seip>
+ ReadWriteField,
+ register_info::csr::SipInfo::Seip>
seip;
/// @name 构造/析构函数
@@ -1266,16 +1346,16 @@ class Sip : public ReadWriteRegBase {
}
};
-class Sie : public ReadWriteRegBase {
+class Sie : public ReadWriteRegBase {
public:
- ReadWriteField,
- reginfo::csr::SieInfo::Ssie>
+ ReadWriteField,
+ register_info::csr::SieInfo::Ssie>
ssie;
- ReadWriteField,
- reginfo::csr::SieInfo::Stie>
+ ReadWriteField,
+ register_info::csr::SieInfo::Stie>
stie;
- ReadWriteField,
- reginfo::csr::SieInfo::Seie>
+ ReadWriteField,
+ register_info::csr::SieInfo::Seie>
seie;
/// @name 构造/析构函数
@@ -1300,7 +1380,7 @@ class Sie : public ReadWriteRegBase