Skip to content

Commit

Permalink
fix: overflow
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Sep 11, 2024
1 parent e275766 commit 5503b97
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/kernel/arch/riscv64/include/cpu/regs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,10 +1203,10 @@ class ReadWriteField : public ReadOnlyField<Reg, RegInfo>,
* @param value 新值
*/
static __always_inline void Write(RegInfo::DataType value) {
uint64_t org_value = Reg::Read();
uint64_t new_value =
(org_value & ~RegInfo::kBitMask) |
(((uint64_t)value << RegInfo::kBitOffset) & RegInfo::kBitMask);
auto org_value = Reg::Read();
auto new_value = (org_value & ~RegInfo::kBitMask) |
(((decltype(org_value))value << RegInfo::kBitOffset) &
RegInfo::kBitMask);
Reg::Write(new_value);
}

Expand All @@ -1216,10 +1216,10 @@ class ReadWriteField : public ReadOnlyField<Reg, RegInfo>,
* @return RegInfo::DataType 由寄存器规定的数据类型
*/
static __always_inline RegInfo::DataType ReadWrite(RegInfo::DataType value) {
uint64_t org_value = Reg::Read();
uint64_t new_value =
(org_value & ~RegInfo::kBitMask) |
(((uint64_t)value << RegInfo::kBitOffset) & RegInfo::kBitMask);
auto org_value = Reg::Read();
auto new_value = (org_value & ~RegInfo::kBitMask) |
(((decltype(org_value))value << RegInfo::kBitOffset) &
RegInfo::kBitMask);
Reg::Write(new_value);
return (RegInfo::DataType)((org_value & RegInfo::kBitMask) >>
RegInfo::kBitOffset);
Expand Down

0 comments on commit 5503b97

Please sign in to comment.