#![allow(non_snake_case)]
#![allow(unused)]
use crate::error::Result;
use crate::utils::*;
use super::super::formatter::*;
use super::super::instruction::*;
use super::super::operand::*;
use super::super::consts::*;
use super::super::config::*;
use super::super::decoder::*;
pub(crate) struct IclassLdrshLA1;
impl IclassLdrshLA1 {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let field_22 = (data >> 22) & 1;
let field_22_post = field_22;
let U = (data >> 23) & 1;
let U_post = U;
let Rt = (data >> 12) & 15;
let Rt_post = Rt;
let imm4H = (data >> 8) & 15;
let imm4H_post = imm4H;
let P = (data >> 24) & 1;
let P_post = P;
let Rn = (data >> 16) & 15;
let Rn_post = Rn;
let field_25 = (data >> 25) & 1;
let field_25_post = field_25;
let o1 = (data >> 20) & 1;
let o1_post = o1;
let field_27 = (data >> 26) & 3;
let field_27_post = field_27;
let cond = (data >> 28) & 15;
let cond_post = cond;
let op2 = (data >> 5) & 3;
let op2_post = op2;
let field_4 = (data >> 4) & 1;
let field_4_post = field_4;
let imm4L = (data >> 0) & 15;
let imm4L_post = imm4L;
let W = (data >> 21) & 1;
let W_post = W;
let field_7 = (data >> 7) & 1;
let field_7_post = field_7;
if ((P_post == 1) && (W_post == 0)) {
return LdrshLA1Off::decode(data as u32, decoder);
}
if ((P_post == 0) && (W_post == 0)) {
return LdrshLA1Post::decode(data as u32, decoder);
}
if ((P_post == 1) && (W_post == 1)) {
return LdrshLA1Pre::decode(data as u32, decoder);
}
unreachable!()
}
}
pub struct LdrshLA1Off;
impl LdrshLA1Off {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::LDRSH
}
pub fn condition(_instr: &Instruction) -> ConditionalInstruction {
ConditionalInstruction::Condition(0, false, false)
}
pub fn size(instr: &Instruction) -> usize {
4
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let cond = (data >> 28) & 15;
let cond_post = cond;
let U = (data >> 23) & 1;
let U_post = U;
let Rt = (data >> 12) & 15;
let Rt_post = Rt;
let imm4H = (data >> 8) & 15;
let imm4H_post = imm4H;
let imm4L = (data >> 0) & 15;
let imm4L_post = imm4L;
let cond_post = cond;
let op_0 = MnemonicCondition::decode(cond_post)?;
let Rt_post = Rt;
let op_1 = Register::decode(Rt_post)?;
let op_2 = Register::PC;
let U_post = U;
let op_3 = PlusMinus::decode(U_post);
let imm4H_imm4L_post = (imm4H << 4) | imm4L;
let op_4 = imm4H_imm4L_post as u32;
let mut instr = Instruction::builder(Code::LDRSH_l_A1_off)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.operand(4, op_4)?
.build();
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let cond_pre = instr.op0().as_mnemonic_condition()?.encode();
let Rt_pre = instr.op1().as_register()?.encode();
let U_pre = instr.op3().as_plus_minus()?.encode();
let imm4H_imm4L_pre = instr.op4().as_unsigned_immediate()? as u32;
let cond = (cond_pre & 15);
let Rt = (Rt_pre & 15);
let U = (U_pre & 1);
let imm4H_imm4L_pre = imm4H_imm4L_pre;
let imm4L = (imm4H_imm4L_pre & 15);
let imm4H = (imm4H_imm4L_pre >> 4) & 15;
let mut instr: u32 = 0b00000001010111110000000011110000;
instr |= (cond & 15) << 28;
instr |= (Rt & 15) << 12;
instr |= (U & 1) << 23;
instr |= (imm4L & 15) << 0;
instr |= (imm4H & 15) << 8;
let bytes = instr.to_le_bytes();
let len = bytes.len();
buf.extend(bytes);
Ok(len)
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
Self::encode(instr, buf)
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::MnemonicCondition(r) = op {
return Ok(())
}
todo!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(Register::PC) = op {
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::PlusMinus(_) = op {
return Ok(())
}
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::SignedImmediate(i) = op {
if !(0..=255).contains(i) {
todo!()
}
return Ok(())
}
if let Operand::UnsignedImmediate(i) = op {
if !(0..=255).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
fmt.format_mnemonic(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, FormatterTextKind::BracketLeft)?;
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, 2)?;
if *instr.op3().as_plus_minus()? == PlusMinus::Minus || instr.op4().as_unsigned_immediate()? != 0 {
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, FormatterTextKind::NumSign)?;
if *instr.op3().as_plus_minus()? == PlusMinus::Minus {
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, 3)?;
};
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, 4)?;
};
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_off, &instr, FormatterTextKind::BracketRight)?;;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum LdrshLA1OffAliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum LdrshLA1OffEncodings {
None
}
pub struct LdrshLA1Post;
impl LdrshLA1Post {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::LDRSH
}
pub fn condition(_instr: &Instruction) -> ConditionalInstruction {
ConditionalInstruction::Condition(0, false, false)
}
pub fn size(instr: &Instruction) -> usize {
4
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let cond = (data >> 28) & 15;
let cond_post = cond;
let U = (data >> 23) & 1;
let U_post = U;
let Rt = (data >> 12) & 15;
let Rt_post = Rt;
let imm4H = (data >> 8) & 15;
let imm4H_post = imm4H;
let imm4L = (data >> 0) & 15;
let imm4L_post = imm4L;
let cond_post = cond;
let op_0 = MnemonicCondition::decode(cond_post)?;
let Rt_post = Rt;
let op_1 = Register::decode(Rt_post)?;
let op_2 = Register::PC;
let U_post = U;
let op_3 = PlusMinus::decode(U_post);
let imm4H_imm4L_post = (imm4H << 4) | imm4L;
let op_4 = imm4H_imm4L_post as u32;
let mut instr = Instruction::builder(Code::LDRSH_l_A1_post)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.operand(4, op_4)?
.build();
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let cond_pre = instr.op0().as_mnemonic_condition()?.encode();
let Rt_pre = instr.op1().as_register()?.encode();
let U_pre = instr.op3().as_plus_minus()?.encode();
let imm4H_imm4L_pre = instr.op4().as_unsigned_immediate()? as u32;
let cond = (cond_pre & 15);
let Rt = (Rt_pre & 15);
let U = (U_pre & 1);
let imm4H_imm4L_pre = imm4H_imm4L_pre;
let imm4L = (imm4H_imm4L_pre & 15);
let imm4H = (imm4H_imm4L_pre >> 4) & 15;
let mut instr: u32 = 0b00000000010111110000000011110000;
instr |= (cond & 15) << 28;
instr |= (Rt & 15) << 12;
instr |= (U & 1) << 23;
instr |= (imm4L & 15) << 0;
instr |= (imm4H & 15) << 8;
let bytes = instr.to_le_bytes();
let len = bytes.len();
buf.extend(bytes);
Ok(len)
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
Self::encode(instr, buf)
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::MnemonicCondition(r) = op {
return Ok(())
}
todo!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(Register::PC) = op {
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::PlusMinus(_) = op {
return Ok(())
}
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::SignedImmediate(i) = op {
if !(0..=255).contains(i) {
todo!()
}
return Ok(())
}
if let Operand::UnsignedImmediate(i) = op {
if !(0..=255).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
fmt.format_mnemonic(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, FormatterTextKind::BracketLeft)?;
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, 2)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, FormatterTextKind::BracketRight)?;;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, FormatterTextKind::NumSign)?;
if *instr.op3().as_plus_minus()? == PlusMinus::Minus {
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, 3)?;
};
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_post, &instr, 4)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum LdrshLA1PostAliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum LdrshLA1PostEncodings {
None
}
pub struct LdrshLA1Pre;
impl LdrshLA1Pre {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::LDRSH
}
pub fn condition(_instr: &Instruction) -> ConditionalInstruction {
ConditionalInstruction::Condition(0, false, false)
}
pub fn size(instr: &Instruction) -> usize {
4
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let cond = (data >> 28) & 15;
let cond_post = cond;
let U = (data >> 23) & 1;
let U_post = U;
let Rt = (data >> 12) & 15;
let Rt_post = Rt;
let imm4H = (data >> 8) & 15;
let imm4H_post = imm4H;
let imm4L = (data >> 0) & 15;
let imm4L_post = imm4L;
let cond_post = cond;
let op_0 = MnemonicCondition::decode(cond_post)?;
let Rt_post = Rt;
let op_1 = Register::decode(Rt_post)?;
let op_2 = Register::PC;
let U_post = U;
let op_3 = PlusMinus::decode(U_post);
let imm4H_imm4L_post = (imm4H << 4) | imm4L;
let op_4 = imm4H_imm4L_post as u32;
let mut instr = Instruction::builder(Code::LDRSH_l_A1_pre)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.operand(4, op_4)?
.build();
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let cond_pre = instr.op0().as_mnemonic_condition()?.encode();
let Rt_pre = instr.op1().as_register()?.encode();
let U_pre = instr.op3().as_plus_minus()?.encode();
let imm4H_imm4L_pre = instr.op4().as_unsigned_immediate()? as u32;
let cond = (cond_pre & 15);
let Rt = (Rt_pre & 15);
let U = (U_pre & 1);
let imm4H_imm4L_pre = imm4H_imm4L_pre;
let imm4L = (imm4H_imm4L_pre & 15);
let imm4H = (imm4H_imm4L_pre >> 4) & 15;
let mut instr: u32 = 0b00000001011111110000000011110000;
instr |= (cond & 15) << 28;
instr |= (Rt & 15) << 12;
instr |= (U & 1) << 23;
instr |= (imm4L & 15) << 0;
instr |= (imm4H & 15) << 8;
let bytes = instr.to_le_bytes();
let len = bytes.len();
buf.extend(bytes);
Ok(len)
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
Self::encode(instr, buf)
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::MnemonicCondition(r) = op {
return Ok(())
}
todo!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(Register::PC) = op {
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::PlusMinus(_) = op {
return Ok(())
}
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::SignedImmediate(i) = op {
if !(0..=255).contains(i) {
todo!()
}
return Ok(())
}
if let Operand::UnsignedImmediate(i) = op {
if !(0..=255).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
fmt.format_mnemonic(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, FormatterTextKind::BracketLeft)?;
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, 2)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, FormatterTextKind::NumSign)?;
if *instr.op3().as_plus_minus()? == PlusMinus::Minus {
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, 3)?;
};
fmt.format_operand(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, 4)?;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, FormatterTextKind::BracketRight)?;;
fmt.format_punctuation(output, &config.global, &config.instructions.ldrsh_l_a1_pre, &instr, FormatterTextKind::ExclamationMark)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum LdrshLA1PreAliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum LdrshLA1PreEncodings {
None
}