Skip to content

Commit

Permalink
feat(cpu): update cpu template
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Jun 18, 2024
1 parent e406b77 commit 77f65e8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
24 changes: 12 additions & 12 deletions src/kernel/arch/aarch64/include/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace {
* 只读接口
* @tparam 寄存器类型
*/
template <class Reg>
template <class RegInfo>
class ReadOnlyRegBase {
public:
/// @name 构造/析构函数
Expand All @@ -76,11 +76,11 @@ class ReadOnlyRegBase {

/**
* 读寄存器
* @return Reg::DataType 寄存器的值
* @return RegInfo::DataType 寄存器的值
*/
static __always_inline Reg::DataType Read() {
typename Reg::DataType value{};
if constexpr (std::is_same<Reg, reginfo::X29Info>::value) {
static __always_inline RegInfo::DataType Read() {
typename RegInfo::DataType value{};
if constexpr (std::is_same<RegInfo, reginfo::X29Info>::value) {
__asm__ volatile("mov %0, x29" : "=r"(value) : :);
} else {
Err("No Type\n");
Expand All @@ -92,14 +92,14 @@ class ReadOnlyRegBase {
/**
* () 重载
*/
static __always_inline Reg::DataType operator()() { return Read(); }
static __always_inline RegInfo::DataType operator()() { return Read(); }
};

/**
* 只写接口
* @tparam 寄存器类型
*/
template <class Reg>
template <class RegInfo>
class WriteOnlyRegBase {
public:
/// @name 构造/析构函数
Expand All @@ -116,8 +116,8 @@ class WriteOnlyRegBase {
* 写寄存器
* @param value 要写的值
*/
static __always_inline void Write(Reg::DataType value) {
if constexpr (std::is_same<Reg, reginfo::X29Info>::value) {
static __always_inline void Write(RegInfo::DataType value) {
if constexpr (std::is_same<RegInfo, reginfo::X29Info>::value) {
__asm__ volatile("mv fp, %0" : : "r"(value) :);
} else {
Err("No Type\n");
Expand All @@ -130,9 +130,9 @@ class WriteOnlyRegBase {
* 读写接口
* @tparam 寄存器类型
*/
template <class Reg>
class ReadWriteRegBase : public ReadOnlyRegBase<Reg>,
public WriteOnlyRegBase<Reg> {
template <class RegInfo>
class ReadWriteRegBase : public ReadOnlyRegBase<RegInfo>,
public WriteOnlyRegBase<RegInfo> {
public:
/// @name 构造/析构函数
/// @{
Expand Down
24 changes: 12 additions & 12 deletions src/kernel/arch/riscv64/include/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace {
* 只读接口
* @tparam 寄存器类型
*/
template <class Reg>
template <class RegInfo>
class ReadOnlyRegBase {
public:
/// @name 构造/析构函数
Expand All @@ -76,11 +76,11 @@ class ReadOnlyRegBase {

/**
* 读寄存器
* @return Reg::DataType 寄存器的值
* @return RegInfo::DataType 寄存器的值
*/
static __always_inline Reg::DataType Read() {
typename Reg::DataType value{};
if constexpr (std::is_same<Reg, reginfo::FpInfo>::value) {
static __always_inline RegInfo::DataType Read() {
typename RegInfo::DataType value{};
if constexpr (std::is_same<RegInfo, reginfo::FpInfo>::value) {
__asm__ volatile("mv %0, fp" : "=r"(value) : :);
} else {
Err("No Type\n");
Expand All @@ -92,14 +92,14 @@ class ReadOnlyRegBase {
/**
* () 重载
*/
static __always_inline Reg::DataType operator()() { return Read(); }
static __always_inline RegInfo::DataType operator()() { return Read(); }
};

/**
* 只写接口
* @tparam 寄存器类型
*/
template <class Reg>
template <class RegInfo>
class WriteOnlyRegBase {
public:
/// @name 构造/析构函数
Expand All @@ -116,8 +116,8 @@ class WriteOnlyRegBase {
* 写寄存器
* @param value 要写的值
*/
static __always_inline void Write(Reg::DataType value) {
if constexpr (std::is_same<Reg, reginfo::FpInfo>::value) {
static __always_inline void Write(RegInfo::DataType value) {
if constexpr (std::is_same<RegInfo, reginfo::FpInfo>::value) {
__asm__ volatile("mv fp, %0" : : "r"(value) :);
} else {
Err("No Type\n");
Expand All @@ -130,9 +130,9 @@ class WriteOnlyRegBase {
* 读写接口
* @tparam 寄存器类型
*/
template <class Reg>
class ReadWriteRegBase : public ReadOnlyRegBase<Reg>,
public WriteOnlyRegBase<Reg> {
template <class RegInfo>
class ReadWriteRegBase : public ReadOnlyRegBase<RegInfo>,
public WriteOnlyRegBase<RegInfo> {
public:
/// @name 构造/析构函数
/// @{
Expand Down
24 changes: 12 additions & 12 deletions src/kernel/arch/x86_64/include/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace {
* 只读接口
* @tparam 寄存器类型
*/
template <class Reg>
template <class RegInfo>
class ReadOnlyRegBase {
public:
/// @name 构造/析构函数
Expand All @@ -226,11 +226,11 @@ class ReadOnlyRegBase {

/**
* 读寄存器
* @return Reg::DataType 寄存器的值
* @return RegInfo::DataType 寄存器的值
*/
static __always_inline Reg::DataType Read() {
typename Reg::DataType value{};
if constexpr (std::is_same<Reg, reginfo::RbpInfo>::value) {
static __always_inline RegInfo::DataType Read() {
typename RegInfo::DataType value{};
if constexpr (std::is_same<RegInfo, reginfo::RbpInfo>::value) {
__asm__ volatile("mov %%rbp, %0" : "=r"(value) : :);
} else {
Err("No Type\n");
Expand All @@ -242,14 +242,14 @@ class ReadOnlyRegBase {
/**
* () 重载
*/
static __always_inline Reg::DataType operator()() { return Read(); }
static __always_inline RegInfo::DataType operator()() { return Read(); }
};

/**
* 只写接口
* @tparam 寄存器类型
*/
template <class Reg>
template <class RegInfo>
class WriteOnlyRegBase {
public:
/// @name 构造/析构函数
Expand All @@ -266,8 +266,8 @@ class WriteOnlyRegBase {
* 写寄存器
* @param value 要写的值
*/
static __always_inline void Write(Reg::DataType value) {
if constexpr (std::is_same<Reg, reginfo::RbpInfo>::value) {
static __always_inline void Write(RegInfo::DataType value) {
if constexpr (std::is_same<RegInfo, reginfo::RbpInfo>::value) {
__asm__ volatile("mv fp, %0" : : "r"(value) :);
} else {
Err("No Type\n");
Expand All @@ -280,9 +280,9 @@ class WriteOnlyRegBase {
* 读写接口
* @tparam 寄存器类型
*/
template <class Reg>
class ReadWriteRegBase : public ReadOnlyRegBase<Reg>,
public WriteOnlyRegBase<Reg> {
template <class RegInfo>
class ReadWriteRegBase : public ReadOnlyRegBase<RegInfo>,
public WriteOnlyRegBase<RegInfo> {
public:
/// @name 构造/析构函数
/// @{
Expand Down

0 comments on commit 77f65e8

Please sign in to comment.