|
| 1 | +//! Implements PLD (Preload Data) instructions. |
| 2 | +//! |
| 3 | +//! Emulation of this instruction has no effect and is similar to NOP instruction. |
| 4 | +
|
| 5 | +use super::{ |
| 6 | + Encoding::{self, T1, T2}, |
| 7 | + Pattern, |
| 8 | +}; |
| 9 | +use crate::{ |
| 10 | + arith::Shift, |
| 11 | + core::{ |
| 12 | + ArmVersion::{V7EM, V7M, V8M}, |
| 13 | + Effect, ItState, Processor, RunError, |
| 14 | + }, |
| 15 | + decoder::DecodeError, |
| 16 | + helpers::BitAccess, |
| 17 | + instructions::{indexing_args, other, unpredictable, DecodeHelper, Instruction}, |
| 18 | + registers::RegisterIndex, |
| 19 | +}; |
| 20 | + |
| 21 | +/// PLD (immediate) instruction. |
| 22 | +/// |
| 23 | +/// Preload Data. |
| 24 | +pub struct PldImm { |
| 25 | + /// Base register. |
| 26 | + rn: RegisterIndex, |
| 27 | + /// True to add offset, false to subtract. |
| 28 | + add: bool, |
| 29 | + /// Immediate offset applied to Rn. |
| 30 | + imm32: u32, |
| 31 | + /// Encoding. |
| 32 | + encoding: Encoding, |
| 33 | +} |
| 34 | + |
| 35 | +impl Instruction for PldImm { |
| 36 | + fn patterns() -> &'static [Pattern] { |
| 37 | + &[ |
| 38 | + Pattern { |
| 39 | + encoding: T1, |
| 40 | + versions: &[V7M, V7EM, V8M], |
| 41 | + expression: "111110001001xxxx1111xxxxxxxxxxxx", |
| 42 | + }, |
| 43 | + Pattern { |
| 44 | + encoding: T2, |
| 45 | + versions: &[V7M, V7EM, V8M], |
| 46 | + expression: "111110000001xxxx11111100xxxxxxxx", |
| 47 | + }, |
| 48 | + ] |
| 49 | + } |
| 50 | + |
| 51 | + fn try_decode(encoding: Encoding, ins: u32, _state: ItState) -> Result<Self, DecodeError> { |
| 52 | + let rn = ins.reg4(16); |
| 53 | + other(rn.is_pc())?; // PLD (literal) |
| 54 | + Ok(match encoding { |
| 55 | + T1 => Self { |
| 56 | + rn, |
| 57 | + add: true, |
| 58 | + imm32: ins.imm12(0), |
| 59 | + encoding, |
| 60 | + }, |
| 61 | + T2 => Self { |
| 62 | + rn, |
| 63 | + add: false, |
| 64 | + imm32: ins.imm8(0), |
| 65 | + encoding, |
| 66 | + }, |
| 67 | + _ => panic!(), |
| 68 | + }) |
| 69 | + } |
| 70 | + |
| 71 | + fn execute(&self, _proc: &mut Processor) -> Result<Effect, RunError> { |
| 72 | + Ok(Effect::None) |
| 73 | + } |
| 74 | + |
| 75 | + fn name(&self) -> String { |
| 76 | + "pld".into() |
| 77 | + } |
| 78 | + |
| 79 | + fn args(&self, _pc: u32) -> String { |
| 80 | + // #0 and #-0 offsets generate different instructions. Therefore for encoding T2 we want |
| 81 | + // the sign to be explicit. |
| 82 | + indexing_args( |
| 83 | + self.rn, |
| 84 | + self.imm32, |
| 85 | + self.encoding == T2, |
| 86 | + true, |
| 87 | + self.add, |
| 88 | + false, |
| 89 | + ) |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +/// PLD (literal) instruction. |
| 94 | +/// |
| 95 | +/// Preload Data. |
| 96 | +pub struct PldLit { |
| 97 | + /// Label offset. |
| 98 | + imm32: u32, |
| 99 | + /// True to add offset, false to subtract. |
| 100 | + add: bool, |
| 101 | +} |
| 102 | + |
| 103 | +impl Instruction for PldLit { |
| 104 | + fn patterns() -> &'static [Pattern] { |
| 105 | + &[Pattern { |
| 106 | + encoding: T1, |
| 107 | + versions: &[V7M, V7EM, V8M], |
| 108 | + expression: "11111000x00111111111xxxxxxxxxxxx", |
| 109 | + }] |
| 110 | + } |
| 111 | + |
| 112 | + fn try_decode(encoding: Encoding, ins: u32, _state: ItState) -> Result<Self, DecodeError> { |
| 113 | + debug_assert_eq!(encoding, T1); |
| 114 | + Ok(Self { |
| 115 | + imm32: ins.imm12(0), |
| 116 | + add: ins.bit(23), |
| 117 | + }) |
| 118 | + } |
| 119 | + |
| 120 | + fn execute(&self, _proc: &mut Processor) -> Result<Effect, RunError> { |
| 121 | + Ok(Effect::None) |
| 122 | + } |
| 123 | + |
| 124 | + fn name(&self) -> String { |
| 125 | + "pld".into() |
| 126 | + } |
| 127 | + |
| 128 | + fn args(&self, _pc: u32) -> String { |
| 129 | + indexing_args(RegisterIndex::Pc, self.imm32, true, true, self.add, false) |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +/// PLD (register) instruction. |
| 134 | +/// |
| 135 | +/// Preload Data. |
| 136 | +pub struct PldReg { |
| 137 | + /// Base register. |
| 138 | + rn: RegisterIndex, |
| 139 | + /// Offset register. |
| 140 | + rm: RegisterIndex, |
| 141 | + /// Shift to be applied to Rm. |
| 142 | + shift: Shift, |
| 143 | +} |
| 144 | + |
| 145 | +impl Instruction for PldReg { |
| 146 | + fn patterns() -> &'static [Pattern] { |
| 147 | + &[Pattern { |
| 148 | + encoding: T1, |
| 149 | + versions: &[V7M, V7EM, V8M], |
| 150 | + expression: "111110000001xxxx1111000000xxxxxx", |
| 151 | + }] |
| 152 | + } |
| 153 | + |
| 154 | + fn try_decode(encoding: Encoding, ins: u32, _state: ItState) -> Result<Self, DecodeError> { |
| 155 | + debug_assert_eq!(encoding, T1); |
| 156 | + let rn = ins.reg4(16); |
| 157 | + let rm = ins.reg4(0); |
| 158 | + other(rn.is_pc())?; // PLD (literal) |
| 159 | + unpredictable(rm.is_sp_or_pc())?; |
| 160 | + Ok(Self { |
| 161 | + rn, |
| 162 | + rm, |
| 163 | + shift: Shift::lsl(ins.imm2(4)), |
| 164 | + }) |
| 165 | + } |
| 166 | + |
| 167 | + fn execute(&self, _proc: &mut Processor) -> Result<Effect, RunError> { |
| 168 | + Ok(Effect::None) |
| 169 | + } |
| 170 | + |
| 171 | + fn name(&self) -> String { |
| 172 | + "pld".into() |
| 173 | + } |
| 174 | + |
| 175 | + fn args(&self, _pc: u32) -> String { |
| 176 | + format!("[{}, {}{}]", self.rn, self.rm, self.shift.arg_string()) |
| 177 | + } |
| 178 | +} |
0 commit comments