#![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 IclassPliIT1;
impl IclassPliIT1 {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rt = (data >> 12) & 15;
let Rt_post = Rt;
let imm12 = (data >> 0) & 4095;
let imm12_post = imm12;
let size = (data >> 21) & 3;
let size_post = size;
let field_20 = (data >> 20) & 1;
let field_20_post = field_20;
let field_28 = (data >> 25) & 15;
let field_28_post = field_28;
let field_31 = (data >> 29) & 7;
let field_31_post = field_31;
let Rn = (data >> 16) & 15;
let Rn_post = Rn;
let field_24 = (data >> 23) & 3;
let field_24_post = field_24;
return PliIT1::decode(data as u32, decoder);
unreachable!()
}
}
pub struct PliIT1;
impl PliIT1 {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::PLI
}
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 Rn = (data >> 16) & 15;
let Rn_post = Rn;
let imm12 = (data >> 0) & 4095;
let imm12_post = imm12;
let Rn_post = Rn;
let imm12_post = imm12;
let op_0 = MnemonicCondition::Al;
let op_1 = Register::decode(Rn_post)?;
let op_2 = imm12_post as u32;
let mut instr = Instruction::builder(Code::PLI_i_T1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rn_pre = instr.op1().as_register()?.encode();
let imm12_pre = instr.op2().as_unsigned_immediate()? as u32;
let Rn = (Rn_pre & 15);
let imm12_pre = imm12_pre;
let imm12 = (imm12_pre & 4095);
let mut instr: u32 = 0b11111001100100001111000000000000;
instr |= (Rn & 15) << 16;
instr |= (imm12 & 4095) << 0;
let instr_1 = (instr & 0xffff) as u16;
let instr_2 = ((instr >> 16) & 0xffff) as u16;
buf.extend(instr_2.to_le_bytes());
buf.extend(instr_1.to_le_bytes());
Ok(4)
}
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::SignedImmediate(i) = op {
if *i < 0 || *i > 4095 {
todo!()
}
return Ok(())
}
if let Operand::UnsignedImmediate(i) = op {
if !(0..=4095).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
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.pli_i_t1, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t1, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.pli_i_t1, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t1, &instr, FormatterTextKind::Space)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t1, &instr, FormatterTextKind::BracketLeft)?;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t1, &instr, 1)?;
if instr.op2().as_unsigned_immediate()? != 0 {
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t1, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t1, &instr, FormatterTextKind::NumSign)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t1, &instr, FormatterTextKind::Plus)?;
;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t1, &instr, 2)?;
};
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t1, &instr, FormatterTextKind::BracketRight)?;;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum PliIT1Aliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum PliIT1Encodings {
None
}
pub(crate) struct IclassPliIT2;
impl IclassPliIT2 {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rt = (data >> 12) & 15;
let Rt_post = Rt;
let size = (data >> 21) & 3;
let size_post = size;
let field_20 = (data >> 20) & 1;
let field_20_post = field_20;
let field_11 = (data >> 11) & 1;
let field_11_post = field_11;
let U = (data >> 9) & 1;
let U_post = U;
let imm8 = (data >> 0) & 255;
let imm8_post = imm8;
let field_28 = (data >> 25) & 15;
let field_28_post = field_28;
let field_31 = (data >> 29) & 7;
let field_31_post = field_31;
let Rn = (data >> 16) & 15;
let Rn_post = Rn;
let W = (data >> 8) & 1;
let W_post = W;
let field_24 = (data >> 23) & 3;
let field_24_post = field_24;
let P = (data >> 10) & 1;
let P_post = P;
return PliIT2::decode(data as u32, decoder);
unreachable!()
}
}
pub struct PliIT2;
impl PliIT2 {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::PLI
}
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 Rn = (data >> 16) & 15;
let Rn_post = Rn;
let imm8 = (data >> 0) & 255;
let imm8_post = imm8;
let imm8_post = imm8;
let Rn_post = Rn;
let op_0 = MnemonicCondition::Al;
let op_1 = Register::decode(Rn_post)?;
let op_2 = imm8_post as u32;
let mut instr = Instruction::builder(Code::PLI_i_T2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rn_pre = instr.op1().as_register()?.encode();
let imm8_pre = instr.op2().as_unsigned_immediate()? as u32;
let Rn = (Rn_pre & 15);
let imm8_pre = imm8_pre;
let imm8 = (imm8_pre & 255);
let mut instr: u32 = 0b11111001000100001111110000000000;
instr |= (Rn & 15) << 16;
instr |= (imm8 & 255) << 0;
let instr_1 = (instr & 0xffff) as u16;
let instr_2 = ((instr >> 16) & 0xffff) as u16;
buf.extend(instr_2.to_le_bytes());
buf.extend(instr_1.to_le_bytes());
Ok(4)
}
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::SignedImmediate(i) = op {
if *i < 0 || *i > 255 {
todo!()
}
return Ok(())
}
if let Operand::UnsignedImmediate(i) = op {
if !(0..=255).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
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.pli_i_t2, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t2, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.pli_i_t2, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t2, &instr, FormatterTextKind::Space)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t2, &instr, FormatterTextKind::BracketLeft)?;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t2, &instr, 1)?;
if true || instr.op2().as_unsigned_immediate()? != 0 {
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t2, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t2, &instr, FormatterTextKind::NumSign)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t2, &instr, FormatterTextKind::Minus)?;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t2, &instr, 2)?;
};
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t2, &instr, FormatterTextKind::BracketRight)?;;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum PliIT2Aliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum PliIT2Encodings {
None
}
pub(crate) struct IclassPliIT3;
impl IclassPliIT3 {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let U = (data >> 23) & 1;
let U_post = U;
let field_19 = (data >> 16) & 15;
let field_19_post = field_19;
let Rt = (data >> 12) & 15;
let Rt_post = Rt;
let imm12 = (data >> 0) & 4095;
let imm12_post = imm12;
let size = (data >> 21) & 3;
let size_post = size;
let field_20 = (data >> 20) & 1;
let field_20_post = field_20;
let field_28 = (data >> 25) & 15;
let field_28_post = field_28;
let field_31 = (data >> 29) & 7;
let field_31_post = field_31;
let field_24 = (data >> 24) & 1;
let field_24_post = field_24;
return PliIT3::decode(data as u32, decoder);
unreachable!()
}
}
pub struct PliIT3;
impl PliIT3 {
pub fn mnemonic(instr: &Instruction) -> Mnemonic {
match instr.encoding {
Encoding::Alt1 => Mnemonic::PLI,
Encoding::Alt2 => Mnemonic::PLI,
_ => todo!()
}
}
pub fn condition(instr: &Instruction) -> ConditionalInstruction {
match instr.encoding {
Encoding::Alt1 => {
ConditionalInstruction::Condition(0, false, false)
}
Encoding::Alt2 => {
ConditionalInstruction::Condition(0, false, false)
}
_ => todo!()
}
}
pub fn size(instr: &Instruction) -> usize {
match instr.encoding {
Encoding::Alt1 => 4,
Encoding::Alt2 => 4,
_ => todo!()
}
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let U = (data >> 23) & 1;
let U_post = U;
let imm12 = (data >> 0) & 4095;
let imm12_post = imm12;
let imm12_post = (((imm12) as i32) << 20) >> 20;
let U_post = U;
let imm12_post = imm12;
if let Some(encoding) = decoder.config.instructions.pli_i_t3.encodings {
match encoding {
PliIT3Encodings::Alt1 => {
let op_0 = MnemonicCondition::Al;
let imm12_post = (((imm12) as i32) << 20) >> 20;
let op_1 = Label::decode(imm12_post.into());
let mut instr = Instruction::builder_multi(Code::PLI_i_T3, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.build();
if decoder.block_decoding {
let size = 4;
let pc = size + match instr.op1().as_label()? {
Label::Label(imm) => ((decoder.pc as u64) as i64 + *imm as i64) as u32,
_ => unreachable!(),
};
decoder.labels.insert(pc);
instr.set_op(1, Label::LabelName(pc as u64))?;
}
return Ok(instr);
}
PliIT3Encodings::Alt2 => {
let op_0 = MnemonicCondition::Al;
let op_1 = Register::PC;
let U_post = U;
let op_2 = PlusMinus::decode(U_post);
let imm12_post = imm12;
let op_3 = imm12_post as u32;
let mut instr = Instruction::builder_multi(Code::PLI_i_T3, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
return Ok(instr);
}
}
}
let op_0 = MnemonicCondition::Al;
let imm12_post = (((imm12) as i32) << 20) >> 20;
let op_1 = Label::decode(imm12_post.into());
let mut instr = Instruction::builder_multi(Code::PLI_i_T3, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.build();
if decoder.block_decoding {
let size = 4;
let pc = size + match instr.op1().as_label()? {
Label::Label(imm) => ((decoder.pc as u64) as i64 + *imm as i64) as u32,
_ => unreachable!(),
};
decoder.labels.insert(pc);
instr.set_op(1, Label::LabelName(pc as u64))?;
}
return Ok(instr);
let op_0 = MnemonicCondition::Al;
let op_1 = Register::PC;
let U_post = U;
let op_2 = PlusMinus::decode(U_post);
let imm12_post = imm12;
let op_3 = imm12_post as u32;
let mut instr = Instruction::builder_multi(Code::PLI_i_T3, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
return Ok(instr);
unreachable!()
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
match instr.encoding {
Encoding::Alt1 => {
let imm12_pre = instr.op1().as_label()?.encode()?;
let imm12_pre = imm12_pre;
let imm12 = (imm12_pre & 4095);
let mut instr: u32 = 0b11111001000111111111000000000000;
instr |= (imm12 & 4095) << 0;
let instr_1 = (instr & 0xffff) as u16;
let instr_2 = ((instr >> 16) & 0xffff) as u16;
buf.extend(instr_2.to_le_bytes());
buf.extend(instr_1.to_le_bytes());
return Ok(4);
}
Encoding::Alt2 => {
let U_pre = instr.op2().as_plus_minus()?.encode();
let imm12_pre = instr.op3().as_unsigned_immediate()? as u32;
let U = (U_pre & 1);
let imm12_pre = imm12_pre;
let imm12 = (imm12_pre & 4095);
let mut instr: u32 = 0b11111001000111111111000000000000;
instr |= (U & 1) << 23;
instr |= (imm12 & 4095) << 0;
let instr_1 = (instr & 0xffff) as u16;
let instr_2 = ((instr >> 16) & 0xffff) as u16;
buf.extend(instr_2.to_le_bytes());
buf.extend(instr_1.to_le_bytes());
return Ok(4);
}
_ => todo!()
}
unreachable!()
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
match instr.encoding {
Encoding::Alt1 => {
if let Label::LabelName(label_name) = instr.op1().as_label()? {
let size =4;
if let Some(label_pc) = labels.get(label_name) {
let pc = *label_pc as i64 - size - instr.pc as i64;
instr.set_op(1, Label::Label(pc))?;
} else {
let pc = *label_name as i64 - size - instr.pc as i64;
instr.set_op(1, Label::Label(pc))?;
}
}
Self::encode(instr, buf)
}
Encoding::Alt2 => {
Self::encode(instr, buf)
}
_ => todo!()
}
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
if let Operand::MnemonicCondition(r) = op {
return Ok(())
}
todo!()
}
Encoding::Alt2 => {
if let Operand::MnemonicCondition(r) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
if let Operand::Label(Label::LabelName(_)) = op {
return Ok(())
}
if let Operand::Label(Label::Label(i)) = op {
if !(-4095..=4095).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
Encoding::Alt2 => {
if let Operand::Register(Register::PC) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
todo!()
}
Encoding::Alt2 => {
if let Operand::PlusMinus(_) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
todo!()
}
Encoding::Alt2 => {
if let Operand::SignedImmediate(i) = op {
if *i < 0 || *i > 4095 {
todo!()
}
return Ok(())
}
if let Operand::UnsignedImmediate(i) = op {
if !(0..=4095).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
todo!()
}
Encoding::Alt2 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
todo!()
}
Encoding::Alt2 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
todo!()
}
Encoding::Alt2 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.pli_i_t3, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t3, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.pli_i_t3, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t3, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t3, &instr, 1)?;
return Ok(());
}
Encoding::Alt2 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.pli_i_t3, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t3, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.pli_i_t3, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t3, &instr, FormatterTextKind::Space)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t3, &instr, FormatterTextKind::BracketLeft)?;
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t3, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t3, &instr, FormatterTextKind::NumSign)?;
if *instr.op2().as_plus_minus()? == PlusMinus::Minus {
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t3, &instr, 2)?;
};
fmt.format_operand(output, &config.global, &config.instructions.pli_i_t3, &instr, 3)?;
fmt.format_punctuation(output, &config.global, &config.instructions.pli_i_t3, &instr, FormatterTextKind::BracketRight)?;;
return Ok(());
}
_ => todo!()
}
unreachable!()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum PliIT3Aliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum PliIT3Encodings {
Alt1,
Alt2,
}