Fixed panic on shift outta bounds

- Pointed out by 5225225
This commit is contained in:
Erin 2023-07-24 16:37:37 +02:00 committed by ondra05
parent d9eb6f1409
commit 15d18ee169

View file

@ -50,6 +50,20 @@ macro_rules! binary_op {
}}; }};
} }
/// Parform bitshift operations
macro_rules! binary_op_sh {
($self:expr, $ty:ident, $handler:expr) => {{
let ParamBBB(tg, a0, a1) = param!($self, ParamBBB);
$self.write_reg(
tg,
$handler(
Value::$ty(&$self.read_reg(a0)),
$self.read_reg(a1).as_u64() as u32,
)
)
}};
}
/// Perform binary operation with immediate `#0 ← #1 OP imm #2` /// Perform binary operation with immediate `#0 ← #1 OP imm #2`
macro_rules! binary_op_imm { macro_rules! binary_op_imm {
($self:expr, $ty:ident, $handler:expr) => {{ ($self:expr, $ty:ident, $handler:expr) => {{
@ -168,9 +182,9 @@ impl<'a, PfHandler: HandlePageFault, const TIMER_QUOTIENT: usize>
AND => binary_op!(self, as_u64, ops::BitAnd::bitand), AND => binary_op!(self, as_u64, ops::BitAnd::bitand),
OR => binary_op!(self, as_u64, ops::BitOr::bitor), OR => binary_op!(self, as_u64, ops::BitOr::bitor),
XOR => binary_op!(self, as_u64, ops::BitXor::bitxor), XOR => binary_op!(self, as_u64, ops::BitXor::bitxor),
SL => binary_op!(self, as_u64, ops::Shl::shl), SL => binary_op_sh!(self, as_u64, u64::wrapping_shl),
SR => binary_op!(self, as_u64, ops::Shr::shr), SR => binary_op_sh!(self, as_u64, u64::wrapping_shr),
SRS => binary_op!(self, as_i64, ops::Shr::shr), SRS => binary_op_sh!(self, as_i64, i64::wrapping_shr),
CMP => { CMP => {
// Compare a0 <=> a1 // Compare a0 <=> a1
// < → -1 // < → -1