#![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 IclassMovIT1;
impl IclassMovIT1 {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rd = (data >> 8) & 7;
let Rd_post = Rd;
let imm8 = (data >> 0) & 255;
let imm8_post = imm8;
let field_13 = (data >> 13) & 1;
let field_13_post = field_13;
let op = (data >> 11) & 3;
let op_post = op;
let field_15 = (data >> 14) & 3;
let field_15_post = field_15;
return MovIT1::decode(data as u32, decoder);
unreachable!()
}
}
pub struct MovIT1;
impl MovIT1 {
pub fn mnemonic(instr: &Instruction) -> Mnemonic {
match instr.encoding {
Encoding::Alt1 => Mnemonic::MOV,
Encoding::Alt2 => Mnemonic::MOVS,
_ => todo!()
}
}
pub fn condition(instr: &Instruction) -> ConditionalInstruction {
match instr.encoding {
Encoding::Alt1 => {
ConditionalInstruction::Condition(0, false, false)
}
Encoding::Alt2 => {
ConditionalInstruction::None
}
_ => todo!()
}
}
pub fn size(instr: &Instruction) -> usize {
match instr.encoding {
Encoding::Alt1 => 2 ,
Encoding::Alt2 => 2 ,
_ => todo!()
}
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rd = (data >> 8) & 7;
let Rd_post = Rd;
let imm8 = (data >> 0) & 255;
let imm8_post = imm8;
let Rd_post = Rd;
let imm8_post = imm8;
if let Some(encoding) = decoder.config.instructions.mov_i_t1.encodings {
match encoding {
MovIT1Encodings::Alt1 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let imm8_post = imm8;
let op_2 = imm8_post as u32;
let mut instr = Instruction::builder_multi(Code::MOV_i_T1, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
MovIT1Encodings::Alt2 => {
let Rd_post = Rd;
let op_0 = Register::decode(Rd_post)?;
let imm8_post = imm8;
let op_1 = imm8_post as u32;
let mut instr = Instruction::builder_multi(Code::MOV_i_T1, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.build();
return Ok(instr);
}
}
}
if (!decoder.it_block.is_none()) {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let imm8_post = imm8;
let op_2 = imm8_post as u32;
let mut instr = Instruction::builder_multi(Code::MOV_i_T1, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
if (decoder.it_block.is_none()) {
let Rd_post = Rd;
let op_0 = Register::decode(Rd_post)?;
let imm8_post = imm8;
let op_1 = imm8_post as u32;
let mut instr = Instruction::builder_multi(Code::MOV_i_T1, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.build();
return Ok(instr);
}
unreachable!()
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
match instr.encoding {
Encoding::Alt1 => {
let Rd_pre = instr.op1().as_register()?.encode();
let imm8_pre = instr.op2().as_unsigned_immediate()? as u32;
let Rd = (Rd_pre & 7);
let imm8_pre = imm8_pre;
let imm8 = (imm8_pre & 255);
let mut instr: u32 = 0b0010000000000000;
instr |= (Rd & 7) << 8;
instr |= (imm8 & 255) << 0;
let instr = instr as u16;
buf.extend(instr.to_le_bytes());
return Ok(2);
}
Encoding::Alt2 => {
let Rd_pre = instr.op0().as_register()?.encode();
let imm8_pre = instr.op1().as_unsigned_immediate()? as u32;
let Rd = (Rd_pre & 7);
let imm8_pre = imm8_pre;
let imm8 = (imm8_pre & 255);
let mut instr: u32 = 0b0010000000000000;
instr |= (Rd & 7) << 8;
instr |= (imm8 & 255) << 0;
let instr = instr as u16;
buf.extend(instr.to_le_bytes());
return Ok(2);
}
_ => 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 => {
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::Register(r) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
Encoding::Alt2 => {
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!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
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!()
}
Encoding::Alt2 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
todo!()
}
Encoding::Alt2 => {
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.mov_i_t1, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t1, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_i_t1, &instr, FormatterQualifier::Narrow, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t1, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t1, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t1, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t1, &instr, FormatterTextKind::NumSign)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t1, &instr, 2)?;
return Ok(());
}
Encoding::Alt2 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.mov_i_t1, &instr)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_i_t1, &instr, FormatterQualifier::Narrow, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t1, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t1, &instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t1, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t1, &instr, FormatterTextKind::NumSign)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t1, &instr, 1)?;
return Ok(());
}
_ => todo!()
}
unreachable!()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovIT1Aliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovIT1Encodings {
Alt1,
Alt2,
}
pub(crate) struct IclassMovIT2;
impl IclassMovIT2 {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let imm8 = (data >> 0) & 255;
let imm8_post = imm8;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let S = (data >> 20) & 1;
let S_post = S;
let i = (data >> 26) & 1;
let i_post = i;
let Rn = (data >> 16) & 15;
let Rn_post = Rn;
let field_25 = (data >> 25) & 1;
let field_25_post = field_25;
let field_15 = (data >> 15) & 1;
let field_15_post = field_15;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let op1 = (data >> 21) & 15;
let op1_post = op1;
let field_31 = (data >> 27) & 31;
let field_31_post = field_31;
if (S_post == 0) {
return MovIT2::decode(data as u32, decoder);
}
if (S_post == 1) {
return MovsIT2::decode(data as u32, decoder);
}
unreachable!()
}
}
pub struct MovIT2;
impl MovIT2 {
pub fn mnemonic(instr: &Instruction) -> Mnemonic {
match instr.encoding {
Encoding::Alt1 => Mnemonic::MOV,
Encoding::Alt2 => Mnemonic::MOV,
_ => 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::Alt2 => 4,
Encoding::Alt1 => 4,
_ => todo!()
}
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let i = (data >> 26) & 1;
let i_post = i;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let imm8 = (data >> 0) & 255;
let imm8_post = imm8;
let Rd_post = Rd;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
if let Some(encoding) = decoder.config.instructions.mov_i_t2.encodings {
match encoding {
MovIT2Encodings::Alt2 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
let op_2 = ModifiedImmediate::decode(i_imm3_imm8_post);
let mut instr = Instruction::builder_multi(Code::MOV_i_T2, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
MovIT2Encodings::Alt1 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
let op_2 = ModifiedImmediate::decode(i_imm3_imm8_post);
let mut instr = Instruction::builder_multi(Code::MOV_i_T2, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
}
}
if (!decoder.it_block.is_none()) && ((Rd_post <= 7 && i_imm3_imm8_post <= 255)) {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
let op_2 = ModifiedImmediate::decode(i_imm3_imm8_post);
let mut instr = Instruction::builder_multi(Code::MOV_i_T2, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
let op_2 = ModifiedImmediate::decode(i_imm3_imm8_post);
let mut instr = Instruction::builder_multi(Code::MOV_i_T2, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
unreachable!()
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
match instr.encoding {
Encoding::Alt2 => {
let Rd_pre = instr.op1().as_register()?.encode();
let i_imm3_imm8_pre = instr.op2().as_modified_immediate()?.encode();
let Rd = (Rd_pre & 15);
let imm8 = (i_imm3_imm8_pre & 255);
let imm3 = (i_imm3_imm8_pre >> 8) & 7;
let i = (i_imm3_imm8_pre >> 11) & 1;
let mut instr: u32 = 0b11110000010011110000000000000000;
instr |= (Rd & 15) << 8;
instr |= (imm8 & 255) << 0;
instr |= (imm3 & 7) << 12;
instr |= (i & 1) << 26;
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::Alt1 => {
let Rd_pre = instr.op1().as_register()?.encode();
let i_imm3_imm8_pre = instr.op2().as_modified_immediate()?.encode();
let Rd = (Rd_pre & 15);
let imm8 = (i_imm3_imm8_pre & 255);
let imm3 = (i_imm3_imm8_pre >> 8) & 7;
let i = (i_imm3_imm8_pre >> 11) & 1;
let mut instr: u32 = 0b11110000010011110000000000000000;
instr |= (Rd & 15) << 8;
instr |= (imm8 & 255) << 0;
instr |= (imm3 & 7) << 12;
instr |= (i & 1) << 26;
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::Alt2 => {
Self::encode(instr, buf)
}
Encoding::Alt1 => {
Self::encode(instr, buf)
}
_ => todo!()
}
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
if let Operand::MnemonicCondition(r) = op {
return Ok(())
}
todo!()
}
Encoding::Alt1 => {
if let Operand::MnemonicCondition(r) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
Encoding::Alt1 => {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
if let Operand::ModifiedImmediate(i) = op {
if i.0 >= 1 << 13 {
todo!()
}
return Ok(())
}
todo!()
}
Encoding::Alt1 => {
if let Operand::ModifiedImmediate(i) = op {
if i.0 >= 1 << 13 {
todo!()
}
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.mov_i_t2, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t2, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_i_t2, &instr, FormatterQualifier::Wide, true, true)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t2, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t2, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t2, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t2, &instr, FormatterTextKind::NumSign)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t2, &instr, 2)?;
return Ok(());
}
Encoding::Alt1 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.mov_i_t2, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t2, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_i_t2, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t2, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t2, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t2, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t2, &instr, FormatterTextKind::NumSign)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t2, &instr, 2)?;
return Ok(());
}
_ => todo!()
}
unreachable!()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovIT2Aliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovIT2Encodings {
Alt2,
Alt1,
}
pub struct MovsIT2;
impl MovsIT2 {
pub fn mnemonic(instr: &Instruction) -> Mnemonic {
match instr.encoding {
Encoding::Alt1 => Mnemonic::MOVS,
Encoding::Alt2 => Mnemonic::MOVS,
_ => todo!()
}
}
pub fn condition(instr: &Instruction) -> ConditionalInstruction {
match instr.encoding {
Encoding::Alt1 => {
ConditionalInstruction::Condition(0, false, false)
}
Encoding::Alt2 => {
ConditionalInstruction::None
}
_ => todo!()
}
}
pub fn size(instr: &Instruction) -> usize {
match instr.encoding {
Encoding::Alt2 => 4,
Encoding::Alt1 => 4,
_ => todo!()
}
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let i = (data >> 26) & 1;
let i_post = i;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let imm8 = (data >> 0) & 255;
let imm8_post = imm8;
let Rd_post = Rd;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
if let Some(encoding) = decoder.config.instructions.movs_i_t2.encodings {
match encoding {
MovsIT2Encodings::Alt2 => {
let Rd_post = Rd;
let op_0 = Register::decode(Rd_post)?;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
let op_1 = ModifiedImmediate::decode(i_imm3_imm8_post);
let mut instr = Instruction::builder_multi(Code::MOVS_i_T2, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.build();
return Ok(instr);
}
MovsIT2Encodings::Alt1 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
let op_2 = ModifiedImmediate::decode(i_imm3_imm8_post);
let mut instr = Instruction::builder_multi(Code::MOVS_i_T2, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
}
}
if (decoder.it_block.is_none()) && ((Rd_post <= 7 && i_imm3_imm8_post <= 255)) {
let Rd_post = Rd;
let op_0 = Register::decode(Rd_post)?;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
let op_1 = ModifiedImmediate::decode(i_imm3_imm8_post);
let mut instr = Instruction::builder_multi(Code::MOVS_i_T2, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.build();
return Ok(instr);
}
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm8_post = (i << 11) | (imm3 << 8) | imm8;
let op_2 = ModifiedImmediate::decode(i_imm3_imm8_post);
let mut instr = Instruction::builder_multi(Code::MOVS_i_T2, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
unreachable!()
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
match instr.encoding {
Encoding::Alt2 => {
let Rd_pre = instr.op0().as_register()?.encode();
let i_imm3_imm8_pre = instr.op1().as_modified_immediate()?.encode();
let Rd = (Rd_pre & 15);
let imm8 = (i_imm3_imm8_pre & 255);
let imm3 = (i_imm3_imm8_pre >> 8) & 7;
let i = (i_imm3_imm8_pre >> 11) & 1;
let mut instr: u32 = 0b11110000010111110000000000000000;
instr |= (Rd & 15) << 8;
instr |= (imm8 & 255) << 0;
instr |= (imm3 & 7) << 12;
instr |= (i & 1) << 26;
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::Alt1 => {
let Rd_pre = instr.op1().as_register()?.encode();
let i_imm3_imm8_pre = instr.op2().as_modified_immediate()?.encode();
let Rd = (Rd_pre & 15);
let imm8 = (i_imm3_imm8_pre & 255);
let imm3 = (i_imm3_imm8_pre >> 8) & 7;
let i = (i_imm3_imm8_pre >> 11) & 1;
let mut instr: u32 = 0b11110000010111110000000000000000;
instr |= (Rd & 15) << 8;
instr |= (imm8 & 255) << 0;
instr |= (imm3 & 7) << 12;
instr |= (i & 1) << 26;
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::Alt2 => {
Self::encode(instr, buf)
}
Encoding::Alt1 => {
Self::encode(instr, buf)
}
_ => todo!()
}
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
Encoding::Alt1 => {
if let Operand::MnemonicCondition(r) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
if let Operand::ModifiedImmediate(i) = op {
if i.0 >= 1 << 13 {
todo!()
}
return Ok(())
}
todo!()
}
Encoding::Alt1 => {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
if let Operand::ModifiedImmediate(i) = op {
if i.0 >= 1 << 13 {
todo!()
}
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.movs_i_t2, &instr)?;
fmt.format_qualifier(output, &config.global, &config.instructions.movs_i_t2, &instr, FormatterQualifier::Wide, true, true)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_i_t2, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_i_t2, &instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_i_t2, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_i_t2, &instr, FormatterTextKind::NumSign)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_i_t2, &instr, 1)?;
return Ok(());
}
Encoding::Alt1 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.movs_i_t2, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_i_t2, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.movs_i_t2, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_i_t2, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_i_t2, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_i_t2, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_i_t2, &instr, FormatterTextKind::NumSign)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_i_t2, &instr, 2)?;
return Ok(());
}
_ => todo!()
}
unreachable!()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovsIT2Aliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovsIT2Encodings {
Alt2,
Alt1,
}
pub(crate) struct IclassMovIT3;
impl IclassMovIT3 {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let field_20 = (data >> 20) & 1;
let field_20_post = field_20;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let field_22 = (data >> 21) & 3;
let field_22_post = field_22;
let field_28 = (data >> 27) & 3;
let field_28_post = field_28;
let imm8 = (data >> 0) & 255;
let imm8_post = imm8;
let o1 = (data >> 23) & 1;
let o1_post = o1;
let i = (data >> 26) & 1;
let i_post = i;
let field_31 = (data >> 29) & 7;
let field_31_post = field_31;
let field_25 = (data >> 25) & 1;
let field_25_post = field_25;
let field_15 = (data >> 15) & 1;
let field_15_post = field_15;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let imm4 = (data >> 16) & 15;
let imm4_post = imm4;
let field_24 = (data >> 24) & 1;
let field_24_post = field_24;
return MovIT3::decode(data as u32, decoder);
unreachable!()
}
}
pub struct MovIT3;
impl MovIT3 {
pub fn mnemonic(instr: &Instruction) -> Mnemonic {
match instr.encoding {
Encoding::Alt1 => Mnemonic::MOV,
Encoding::Alt2 => Mnemonic::MOVW,
_ => 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 i = (data >> 26) & 1;
let i_post = i;
let imm4 = (data >> 16) & 15;
let imm4_post = imm4;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let imm8 = (data >> 0) & 255;
let imm8_post = imm8;
let Rd_post = Rd;
let i_imm3_imm4_imm8_post = (imm4 << 12) | (i << 11) | (imm3 << 8) | imm8;
if let Some(encoding) = decoder.config.instructions.mov_i_t3.encodings {
match encoding {
MovIT3Encodings::Alt1 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm4_imm8_post = (imm4 << 12) | (i << 11) | (imm3 << 8) | imm8;
let op_2 = i_imm3_imm4_imm8_post as u32;
let mut instr = Instruction::builder_multi(Code::MOV_i_T3, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
MovIT3Encodings::Alt2 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm4_imm8_post = (imm4 << 12) | (i << 11) | (imm3 << 8) | imm8;
let op_2 = i_imm3_imm4_imm8_post as u32;
let mut instr = Instruction::builder_multi(Code::MOV_i_T3, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
}
}
if (!((i_imm3_imm4_imm8_post <= 255) || (is_modified_immediate(i_imm3_imm4_imm8_post.into())))) {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm4_imm8_post = (imm4 << 12) | (i << 11) | (imm3 << 8) | imm8;
let op_2 = i_imm3_imm4_imm8_post as u32;
let mut instr = Instruction::builder_multi(Code::MOV_i_T3, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
if ((i_imm3_imm4_imm8_post <= 255) || (is_modified_immediate(i_imm3_imm4_imm8_post.into()))) {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let i_imm3_imm4_imm8_post = (imm4 << 12) | (i << 11) | (imm3 << 8) | imm8;
let op_2 = i_imm3_imm4_imm8_post as u32;
let mut instr = Instruction::builder_multi(Code::MOV_i_T3, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
unreachable!()
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
match instr.encoding {
Encoding::Alt1 => {
let Rd_pre = instr.op1().as_register()?.encode();
let i_imm3_imm4_imm8_pre = instr.op2().as_unsigned_immediate()? as u32;
let Rd = (Rd_pre & 15);
let i_imm3_imm4_imm8_pre = i_imm3_imm4_imm8_pre;
let imm8 = (i_imm3_imm4_imm8_pre & 255);
let imm3 = (i_imm3_imm4_imm8_pre >> 8) & 7;
let i = (i_imm3_imm4_imm8_pre >> 11) & 1;
let imm4 = (i_imm3_imm4_imm8_pre >> 12) & 15;
let mut instr: u32 = 0b11110010010000000000000000000000;
instr |= (Rd & 15) << 8;
instr |= (imm8 & 255) << 0;
instr |= (imm3 & 7) << 12;
instr |= (i & 1) << 26;
instr |= (imm4 & 15) << 16;
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 Rd_pre = instr.op1().as_register()?.encode();
let i_imm3_imm4_imm8_pre = instr.op2().as_unsigned_immediate()? as u32;
let Rd = (Rd_pre & 15);
let i_imm3_imm4_imm8_pre = i_imm3_imm4_imm8_pre;
let imm8 = (i_imm3_imm4_imm8_pre & 255);
let imm3 = (i_imm3_imm4_imm8_pre >> 8) & 7;
let i = (i_imm3_imm4_imm8_pre >> 11) & 1;
let imm4 = (i_imm3_imm4_imm8_pre >> 12) & 15;
let mut instr: u32 = 0b11110010010000000000000000000000;
instr |= (Rd & 15) << 8;
instr |= (imm8 & 255) << 0;
instr |= (imm3 & 7) << 12;
instr |= (i & 1) << 26;
instr |= (imm4 & 15) << 16;
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 => {
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::Register(r) = op {
return Ok(())
}
todo!()
}
Encoding::Alt2 => {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
if let Operand::SignedImmediate(i) = op {
if *i < 0 || *i > 65535 {
todo!()
}
return Ok(())
}
if let Operand::UnsignedImmediate(i) = op {
if !(0..=65535).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
Encoding::Alt2 => {
if let Operand::SignedImmediate(i) = op {
if *i < 0 || *i > 65535 {
todo!()
}
return Ok(())
}
if let Operand::UnsignedImmediate(i) = op {
if !(0..=65535).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
todo!()
}
Encoding::Alt2 => {
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.mov_i_t3, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t3, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_i_t3, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t3, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t3, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t3, &instr, FormatterTextKind::NumSign)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t3, &instr, 2)?;
return Ok(());
}
Encoding::Alt2 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.mov_i_t3, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t3, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_i_t3, &instr, FormatterQualifier::Wide, false, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t3, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t3, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_i_t3, &instr, FormatterTextKind::NumSign)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_i_t3, &instr, 2)?;
return Ok(());
}
_ => todo!()
}
unreachable!()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovIT3Aliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovIT3Encodings {
Alt1,
Alt2,
}