#![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 IclassMovRT1;
impl IclassMovRT1 {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let op = (data >> 8) & 3;
let op_post = op;
let Rd = (data >> 0) & 7;
let Rd_post = Rd;
let D = (data >> 7) & 1;
let D_post = D;
let field_15 = (data >> 10) & 63;
let field_15_post = field_15;
let Rm = (data >> 3) & 15;
let Rm_post = Rm;
return MovRT1::decode(data as u32, decoder);
unreachable!()
}
}
pub struct MovRT1;
impl MovRT1 {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::MOV
}
pub fn condition(instr: &Instruction) -> ConditionalInstruction {
ConditionalInstruction::Condition(0, false, false)
}
pub fn size(_instr: &Instruction) -> usize {2}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let D = (data >> 7) & 1;
let D_post = D;
let Rm = (data >> 3) & 15;
let Rm_post = Rm;
let Rd = (data >> 0) & 7;
let Rd_post = Rd;
let D_Rd_post = (D << 3) | Rd;
let Rm_post = Rm;
let op_0 = MnemonicCondition::Al;
let op_1 = Register::decode(D_Rd_post)?;
let op_2 = Register::decode(Rm_post)?;
let mut instr = Instruction::builder(Code::MOV_r_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 D_Rd_pre = instr.op1().as_register()?.encode();
let Rm_pre = instr.op2().as_register()?.encode();
let Rd = (D_Rd_pre & 7);
let D = (D_Rd_pre >> 3) & 1;
let Rm = (Rm_pre & 15);
let mut instr: u32 = 0b0100011000000000;
instr |= (Rd & 7) << 0;
instr |= (D & 1) << 7;
instr |= (Rm & 15) << 3;
let instr = instr as u16;
buf.extend(instr.to_le_bytes());
Ok(2)
}
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(r) = op {
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.mov_r_t1, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t1, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_r_t1, &instr, FormatterQualifier::Narrow, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t1, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t1, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t1, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t1, &instr, 2)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovRT1Aliases {
None,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovRT1Encodings {
None
}
pub(crate) struct IclassMovRT2;
impl IclassMovRT2 {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rd = (data >> 0) & 7;
let Rd_post = Rd;
let imm5 = (data >> 6) & 31;
let imm5_post = imm5;
let field_13 = (data >> 13) & 1;
let field_13_post = field_13;
let op = (data >> 11) & 3;
let op_post = op;
let Rm = (data >> 3) & 7;
let Rm_post = Rm;
let field_15 = (data >> 14) & 3;
let field_15_post = field_15;
return MovRT2::decode(data as u32, decoder);
unreachable!()
}
}
pub struct MovRT2;
impl MovRT2 {
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 op = (data >> 11) & 3;
let op_post = op;
let imm5 = (data >> 6) & 31;
let imm5_post = imm5;
let Rm = (data >> 3) & 7;
let Rm_post = Rm;
let Rd = (data >> 0) & 7;
let Rd_post = Rd;
let imm5_post = imm5;
let Rd_post = Rd;
let Rm_post = Rm;
match decoder.config.instructions.mov_r_t2.aliases {
None => match decoder.config.global.aliases {
FormatAliasGlobal::Never => {},
FormatAliasGlobal::Recommended => {
if ((op_post == 2) && !(decoder.it_block.is_some())) {
return super::AsrsMovRT2::decode(data, decoder);
}
if ((op_post == 2) && decoder.it_block.is_some()) {
return super::AsrMovRT2::decode(data, decoder);
}
if ((op_post == 0) && ((imm5_post != 0) && !(decoder.it_block.is_some()))) {
return super::LslsMovRT2::decode(data, decoder);
}
if ((op_post == 0) && ((imm5_post != 0) && decoder.it_block.is_some())) {
return super::LslMovRT2::decode(data, decoder);
}
if ((op_post == 1) && !(decoder.it_block.is_some())) {
return super::LsrsMovRT2::decode(data, decoder);
}
if ((op_post == 1) && decoder.it_block.is_some()) {
return super::LsrMovRT2::decode(data, decoder);
}
},
FormatAliasGlobal::Always => {
return super::AsrsMovRT2::decode(data, decoder);
return super::AsrMovRT2::decode(data, decoder);
return super::LslsMovRT2::decode(data, decoder);
return super::LslMovRT2::decode(data, decoder);
return super::LsrsMovRT2::decode(data, decoder);
return super::LsrMovRT2::decode(data, decoder);
}
}
Some(pref) => match pref {
FormatAliasInstruction::Never => {},
FormatAliasInstruction::Recommended => {
if ((op_post == 2) && !(decoder.it_block.is_some())) {
return super::AsrsMovRT2::decode(data, decoder);
}
if ((op_post == 2) && decoder.it_block.is_some()) {
return super::AsrMovRT2::decode(data, decoder);
}
if ((op_post == 0) && ((imm5_post != 0) && !(decoder.it_block.is_some()))) {
return super::LslsMovRT2::decode(data, decoder);
}
if ((op_post == 0) && ((imm5_post != 0) && decoder.it_block.is_some())) {
return super::LslMovRT2::decode(data, decoder);
}
if ((op_post == 1) && !(decoder.it_block.is_some())) {
return super::LsrsMovRT2::decode(data, decoder);
}
if ((op_post == 1) && decoder.it_block.is_some()) {
return super::LsrMovRT2::decode(data, decoder);
}
},
FormatAliasInstruction::Preferred(alias) => {
match alias {
MovRT2Aliases::AsrsMovRT2 => {
if ((op_post == 2) && !(decoder.it_block.is_some())) {
return super::AsrsMovRT2::decode(data, decoder);
}
}
MovRT2Aliases::AsrMovRT2 => {
if ((op_post == 2) && decoder.it_block.is_some()) {
return super::AsrMovRT2::decode(data, decoder);
}
}
MovRT2Aliases::LslsMovRT2 => {
if ((op_post == 0) && ((imm5_post != 0) && !(decoder.it_block.is_some()))) {
return super::LslsMovRT2::decode(data, decoder);
}
}
MovRT2Aliases::LslMovRT2 => {
if ((op_post == 0) && ((imm5_post != 0) && decoder.it_block.is_some())) {
return super::LslMovRT2::decode(data, decoder);
}
}
MovRT2Aliases::LsrsMovRT2 => {
if ((op_post == 1) && !(decoder.it_block.is_some())) {
return super::LsrsMovRT2::decode(data, decoder);
}
}
MovRT2Aliases::LsrMovRT2 => {
if ((op_post == 1) && decoder.it_block.is_some()) {
return super::LsrMovRT2::decode(data, decoder);
}
}
};
if ((op_post == 2) && !(decoder.it_block.is_some())) {
return super::AsrsMovRT2::decode(data, decoder);
}
if ((op_post == 2) && decoder.it_block.is_some()) {
return super::AsrMovRT2::decode(data, decoder);
}
if ((op_post == 0) && ((imm5_post != 0) && !(decoder.it_block.is_some()))) {
return super::LslsMovRT2::decode(data, decoder);
}
if ((op_post == 0) && ((imm5_post != 0) && decoder.it_block.is_some())) {
return super::LslMovRT2::decode(data, decoder);
}
if ((op_post == 1) && !(decoder.it_block.is_some())) {
return super::LsrsMovRT2::decode(data, decoder);
}
if ((op_post == 1) && decoder.it_block.is_some()) {
return super::LsrMovRT2::decode(data, decoder);
}
},
FormatAliasInstruction::Always(alias) => {
match alias {
MovRT2Aliases::AsrsMovRT2 => return super::AsrsMovRT2::decode(data, decoder),
MovRT2Aliases::AsrMovRT2 => return super::AsrMovRT2::decode(data, decoder),
MovRT2Aliases::LslsMovRT2 => return super::LslsMovRT2::decode(data, decoder),
MovRT2Aliases::LslMovRT2 => return super::LslMovRT2::decode(data, decoder),
MovRT2Aliases::LsrsMovRT2 => return super::LsrsMovRT2::decode(data, decoder),
MovRT2Aliases::LsrMovRT2 => return super::LsrMovRT2::decode(data, decoder),
}
},
}
}
if let Some(encoding) = decoder.config.instructions.mov_r_t2.encodings {
match encoding {
MovRT2Encodings::Alt1 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let imm5_post = imm5;
let op_3 = match op {
0 => if imm5_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm5_post))
}
1 => if imm5_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm5_post))
}
2 => if imm5_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm5_post))
}
3 => if imm5_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm5_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOV_r_T2, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
return Ok(instr);
}
MovRT2Encodings::Alt2 => {
let Rd_post = Rd;
let op_0 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_1 = Register::decode(Rm_post)?;
let imm5_post = imm5;
let op_2 = match op {
0 => if imm5_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm5_post))
}
1 => if imm5_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm5_post))
}
2 => if imm5_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm5_post))
}
3 => if imm5_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm5_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOV_r_T2, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.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 Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let imm5_post = imm5;
let op_3 = match op {
0 => if imm5_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm5_post))
}
1 => if imm5_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm5_post))
}
2 => if imm5_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm5_post))
}
3 => if imm5_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm5_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOV_r_T2, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
return Ok(instr);
}
if (decoder.it_block.is_none()) {
let Rd_post = Rd;
let op_0 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_1 = Register::decode(Rm_post)?;
let imm5_post = imm5;
let op_2 = match op {
0 => if imm5_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm5_post))
}
1 => if imm5_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm5_post))
}
2 => if imm5_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm5_post))
}
3 => if imm5_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm5_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOV_r_T2, 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 Rm_pre = instr.op2().as_register()?.encode();
let (op, imm5_pre) = {
if let Operand::None = instr.op3() {
(0, 0)
} else {
match instr.op3().as_shift()? {
Shift::LSL(value) => (0, *value),
Shift::LSR(value) => (1, *value),
Shift::ASR(value) => (2, *value),
Shift::ROR(value) => (3, *value),
_ => todo!(),
}
}
};
let Rd = (Rd_pre & 7);
let Rm = (Rm_pre & 7);
let imm5 = (imm5_pre & 31);
let mut instr: u32 = 0b0000000000000000;
instr |= (Rd & 7) << 0;
instr |= (Rm & 7) << 3;
instr |= (imm5 & 31) << 6;
instr |= (op & 3) << 11;
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 Rm_pre = instr.op1().as_register()?.encode();
let (op, imm5_pre) = {
if let Operand::None = instr.op2() {
(0, 0)
} else {
match instr.op2().as_shift()? {
Shift::LSL(value) => (0, *value),
Shift::LSR(value) => (1, *value),
Shift::ASR(value) => (2, *value),
Shift::ROR(value) => (3, *value),
_ => todo!(),
}
}
};
let Rd = (Rd_pre & 7);
let Rm = (Rm_pre & 7);
let imm5 = (imm5_pre & 31);
let mut instr: u32 = 0b0000000000000000;
instr |= (Rd & 7) << 0;
instr |= (Rm & 7) << 3;
instr |= (imm5 & 31) << 6;
instr |= (op & 3) << 11;
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::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::Register(r) = op {
return Ok(())
}
todo!()
}
Encoding::Alt2 => {
if op.is_none() {
return Ok(())
}
if let Operand::Shift(s) = op {
match s {
Shift::LSL(value) => if *value < 1 || *value > 31 {
todo!()
}
Shift::LSR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ASR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ROR(value) => if *value < 1 || *value > 31 {
todo!()
}
_ => todo!(),
}
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt1 => {
if op.is_none() {
return Ok(())
}
if let Operand::Shift(s) = op {
match s {
Shift::LSL(value) => if *value < 1 || *value > 31 {
todo!()
}
Shift::LSR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ASR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ROR(value) => if *value < 1 || *value > 31 {
todo!()
}
_ => todo!(),
}
return Ok(())
}
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_r_t2, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t2, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_r_t2, &instr, FormatterQualifier::Narrow, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t2, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t2, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t2, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t2, &instr, 2)?;
if !instr.op3().is_none() && !(instr.op3().as_shift()?.is_lsl() && instr.op3().as_shift()?.value() == 0) {
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t2, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t2, &instr, 3)?;
};
return Ok(());
}
Encoding::Alt2 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.mov_r_t2, &instr)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_r_t2, &instr, FormatterQualifier::Narrow, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t2, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t2, &instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t2, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t2, &instr, 1)?;
if !instr.op2().is_none() && !(instr.op2().as_shift()?.is_lsl() && instr.op2().as_shift()?.value() == 0) {
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t2, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t2, &instr, 2)?;
};
return Ok(());
}
_ => todo!()
}
unreachable!()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovRT2Aliases {
AsrsMovRT2,AsrMovRT2,LslsMovRT2,LslMovRT2,LsrsMovRT2,LsrMovRT2,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovRT2Encodings {
Alt1,
Alt2,
}
pub(crate) struct IclassMovRT3Rrx;
impl IclassMovRT3Rrx {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rm = (data >> 0) & 15;
let Rm_post = Rm;
let field_31 = (data >> 25) & 127;
let field_31_post = field_31;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let S = (data >> 20) & 1;
let S_post = S;
let imm2 = (data >> 6) & 3;
let imm2_post = imm2;
let stype = (data >> 4) & 3;
let stype_post = stype;
let Rn = (data >> 16) & 15;
let Rn_post = Rn;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let field_15 = (data >> 15) & 1;
let field_15_post = field_15;
let op1 = (data >> 21) & 15;
let op1_post = op1;
if ((S_post == 0) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return MovRT3Rrx::decode(data as u32, decoder);
}
if ((S_post == 0) && !((((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))))) {
return MovRT3::decode(data as u32, decoder);
}
if ((S_post == 1) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return MovsRT3Rrx::decode(data as u32, decoder);
}
if ((S_post == 1) && !((((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))))) {
return MovsRT3::decode(data as u32, decoder);
}
unreachable!()
}
}
pub struct MovRT3Rrx;
impl MovRT3Rrx {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::MOV
}
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 S = (data >> 20) & 1;
let S_post = S;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let imm2 = (data >> 6) & 3;
let imm2_post = imm2;
let stype = (data >> 4) & 3;
let stype_post = stype;
let Rm = (data >> 0) & 15;
let Rm_post = Rm;
let Rd_post = Rd;
let Rm_post = Rm;
match decoder.config.instructions.mov_r_t3_rrx.aliases {
None => match decoder.config.global.aliases {
FormatAliasGlobal::Never => {},
FormatAliasGlobal::Recommended => {
if ((S_post == 0) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return super::RrxMovRT3Rrx::decode(data, decoder);
}
},
FormatAliasGlobal::Always => {
return super::RrxMovRT3Rrx::decode(data, decoder);
}
}
Some(pref) => match pref {
FormatAliasInstruction::Never => {},
FormatAliasInstruction::Recommended => {
if ((S_post == 0) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return super::RrxMovRT3Rrx::decode(data, decoder);
}
},
FormatAliasInstruction::Preferred(alias) => {
match alias {
MovRT3RrxAliases::RrxMovRT3Rrx => {
if ((S_post == 0) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return super::RrxMovRT3Rrx::decode(data, decoder);
}
}
};
if ((S_post == 0) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return super::RrxMovRT3Rrx::decode(data, decoder);
}
},
FormatAliasInstruction::Always(alias) => {
match alias {
MovRT3RrxAliases::RrxMovRT3Rrx => return super::RrxMovRT3Rrx::decode(data, decoder),
}
},
}
}
let op_0 = MnemonicCondition::Al;
let op_1 = Register::decode(Rd_post)?;
let op_2 = Register::decode(Rm_post)?;
let op_3 = Shift::RRX;
let mut instr = Instruction::builder(Code::MOV_r_T3_RRX)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rd_pre = instr.op1().as_register()?.encode();
let Rm_pre = instr.op2().as_register()?.encode();
let Rd = (Rd_pre & 15);
let Rm = (Rm_pre & 15);
let mut instr: u32 = 0b11101010010011110000000000110000;
instr |= (Rd & 15) << 8;
instr |= (Rm & 15) << 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::Register(r) = op {
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Shift(Shift::RRX) = op {
return Ok(())
}
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.mov_r_t3_rrx, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3_rrx, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_r_t3_rrx, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3_rrx, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3_rrx, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3_rrx, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3_rrx, &instr, 2)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3_rrx, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3_rrx, &instr, 3)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovRT3RrxAliases {
RrxMovRT3Rrx,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovRT3RrxEncodings {
None
}
pub struct MovRT3;
impl MovRT3 {
pub fn mnemonic(instr: &Instruction) -> Mnemonic {
match instr.encoding {
Encoding::Alt1 => Mnemonic::MOV,
Encoding::Alt2 => Mnemonic::MOV,
Encoding::Alt3 => 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)
}
Encoding::Alt3 => {
ConditionalInstruction::Condition(0, false, false)
}
_ => todo!()
}
}
pub fn size(instr: &Instruction) -> usize {
match instr.encoding {
Encoding::Alt2 => 4,
Encoding::Alt3 => 4,
Encoding::Alt1 => 4,
_ => todo!()
}
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let S = (data >> 20) & 1;
let S_post = S;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let imm2 = (data >> 6) & 3;
let imm2_post = imm2;
let stype = (data >> 4) & 3;
let stype_post = stype;
let Rm = (data >> 0) & 15;
let Rm_post = Rm;
let imm2_imm3_post = (imm3 << 2) | imm2;
let Rd_post = Rd;
let Rm_post = Rm;
match decoder.config.instructions.mov_r_t3.aliases {
None => match decoder.config.global.aliases {
FormatAliasGlobal::Never => {},
FormatAliasGlobal::Recommended => {
if ((S_post == 0) && (stype_post == 2)) {
return super::AsrMovRT3::decode(data, decoder);
}
if ((((S_post == 0) && ((stype_post == 0) && !(((imm3_post == 0)))))) || (((S_post == 0) && ((stype_post == 0) && !(((imm2_post == 0))))))) {
return super::LslMovRT3::decode(data, decoder);
}
if ((S_post == 0) && (stype_post == 1)) {
return super::LsrMovRT3::decode(data, decoder);
}
if ((((S_post == 0) && ((stype_post == 3) && !(((imm3_post == 0)))))) || (((S_post == 0) && ((stype_post == 3) && !(((imm2_post == 0))))))) {
return super::RorMovRT3::decode(data, decoder);
}
},
FormatAliasGlobal::Always => {
return super::AsrMovRT3::decode(data, decoder);
return super::LslMovRT3::decode(data, decoder);
return super::LsrMovRT3::decode(data, decoder);
return super::RorMovRT3::decode(data, decoder);
}
}
Some(pref) => match pref {
FormatAliasInstruction::Never => {},
FormatAliasInstruction::Recommended => {
if ((S_post == 0) && (stype_post == 2)) {
return super::AsrMovRT3::decode(data, decoder);
}
if ((((S_post == 0) && ((stype_post == 0) && !(((imm3_post == 0)))))) || (((S_post == 0) && ((stype_post == 0) && !(((imm2_post == 0))))))) {
return super::LslMovRT3::decode(data, decoder);
}
if ((S_post == 0) && (stype_post == 1)) {
return super::LsrMovRT3::decode(data, decoder);
}
if ((((S_post == 0) && ((stype_post == 3) && !(((imm3_post == 0)))))) || (((S_post == 0) && ((stype_post == 3) && !(((imm2_post == 0))))))) {
return super::RorMovRT3::decode(data, decoder);
}
},
FormatAliasInstruction::Preferred(alias) => {
match alias {
MovRT3Aliases::AsrMovRT3 => {
if ((S_post == 0) && (stype_post == 2)) {
return super::AsrMovRT3::decode(data, decoder);
}
}
MovRT3Aliases::LslMovRT3 => {
if ((((S_post == 0) && ((stype_post == 0) && !(((imm3_post == 0)))))) || (((S_post == 0) && ((stype_post == 0) && !(((imm2_post == 0))))))) {
return super::LslMovRT3::decode(data, decoder);
}
}
MovRT3Aliases::LsrMovRT3 => {
if ((S_post == 0) && (stype_post == 1)) {
return super::LsrMovRT3::decode(data, decoder);
}
}
MovRT3Aliases::RorMovRT3 => {
if ((((S_post == 0) && ((stype_post == 3) && !(((imm3_post == 0)))))) || (((S_post == 0) && ((stype_post == 3) && !(((imm2_post == 0))))))) {
return super::RorMovRT3::decode(data, decoder);
}
}
};
if ((S_post == 0) && (stype_post == 2)) {
return super::AsrMovRT3::decode(data, decoder);
}
if ((((S_post == 0) && ((stype_post == 0) && !(((imm3_post == 0)))))) || (((S_post == 0) && ((stype_post == 0) && !(((imm2_post == 0))))))) {
return super::LslMovRT3::decode(data, decoder);
}
if ((S_post == 0) && (stype_post == 1)) {
return super::LsrMovRT3::decode(data, decoder);
}
if ((((S_post == 0) && ((stype_post == 3) && !(((imm3_post == 0)))))) || (((S_post == 0) && ((stype_post == 3) && !(((imm2_post == 0))))))) {
return super::RorMovRT3::decode(data, decoder);
}
},
FormatAliasInstruction::Always(alias) => {
match alias {
MovRT3Aliases::AsrMovRT3 => return super::AsrMovRT3::decode(data, decoder),
MovRT3Aliases::LslMovRT3 => return super::LslMovRT3::decode(data, decoder),
MovRT3Aliases::LsrMovRT3 => return super::LsrMovRT3::decode(data, decoder),
MovRT3Aliases::RorMovRT3 => return super::RorMovRT3::decode(data, decoder),
}
},
}
}
if let Some(encoding) = decoder.config.instructions.mov_r_t3.encodings {
match encoding {
MovRT3Encodings::Alt2 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let op_3 = Shift::LSL(0);
let mut instr = Instruction::builder_multi(Code::MOV_r_T3, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
return Ok(instr);
}
MovRT3Encodings::Alt3 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let imm2_imm3_post = (imm3 << 2) | imm2;
let op_3 = match stype {
0 => if imm2_imm3_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm2_imm3_post))
}
1 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm2_imm3_post))
}
2 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm2_imm3_post))
}
3 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm2_imm3_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOV_r_T3, Encoding::Alt3)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
return Ok(instr);
}
MovRT3Encodings::Alt1 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let imm2_imm3_post = (imm3 << 2) | imm2;
let op_3 = match stype {
0 => if imm2_imm3_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm2_imm3_post))
}
1 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm2_imm3_post))
}
2 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm2_imm3_post))
}
3 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm2_imm3_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOV_r_T3, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
return Ok(instr);
}
}
}
if (stype_post == 0) && (imm2_imm3_post == 0) && ((Rd_post <= 15 && Rm_post <= 15)) {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let op_3 = Shift::LSL(0);
let mut instr = Instruction::builder_multi(Code::MOV_r_T3, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
return Ok(instr);
}
if (!decoder.it_block.is_none()) && ((Rd_post <= 7 && Rm_post <= 7)) {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let imm2_imm3_post = (imm3 << 2) | imm2;
let op_3 = match stype {
0 => if imm2_imm3_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm2_imm3_post))
}
1 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm2_imm3_post))
}
2 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm2_imm3_post))
}
3 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm2_imm3_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOV_r_T3, Encoding::Alt3)
.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 Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let imm2_imm3_post = (imm3 << 2) | imm2;
let op_3 = match stype {
0 => if imm2_imm3_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm2_imm3_post))
}
1 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm2_imm3_post))
}
2 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm2_imm3_post))
}
3 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm2_imm3_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOV_r_T3, Encoding::Alt1)
.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::Alt2 => {
let Rd_pre = instr.op1().as_register()?.encode();
let Rm_pre = instr.op2().as_register()?.encode();
let Rd = (Rd_pre & 15);
let Rm = (Rm_pre & 15);
let mut instr: u32 = 0b11101010010011110000000000000000;
instr |= (Rd & 15) << 8;
instr |= (Rm & 15) << 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::Alt3 => {
let Rd_pre = instr.op1().as_register()?.encode();
let Rm_pre = instr.op2().as_register()?.encode();
let (stype, imm2_imm3_pre) = {
if let Operand::None = instr.op3() {
(0, 0)
} else {
match instr.op3().as_shift()? {
Shift::LSL(value) => (0, *value),
Shift::LSR(value) => (1, *value),
Shift::ASR(value) => (2, *value),
Shift::ROR(value) => (3, *value),
_ => todo!(),
}
}
};
let Rd = (Rd_pre & 15);
let Rm = (Rm_pre & 15);
let imm2 = (imm2_imm3_pre & 3);
let imm3 = (imm2_imm3_pre >> 2) & 7;
let mut instr: u32 = 0b11101010010011110000000000000000;
instr |= (Rd & 15) << 8;
instr |= (Rm & 15) << 0;
instr |= (imm2 & 3) << 6;
instr |= (imm3 & 7) << 12;
instr |= (stype & 3) << 4;
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 Rm_pre = instr.op2().as_register()?.encode();
let (stype, imm2_imm3_pre) = {
if let Operand::None = instr.op3() {
(0, 0)
} else {
match instr.op3().as_shift()? {
Shift::LSL(value) => (0, *value),
Shift::LSR(value) => (1, *value),
Shift::ASR(value) => (2, *value),
Shift::ROR(value) => (3, *value),
_ => todo!(),
}
}
};
let Rd = (Rd_pre & 15);
let Rm = (Rm_pre & 15);
let imm2 = (imm2_imm3_pre & 3);
let imm3 = (imm2_imm3_pre >> 2) & 7;
let mut instr: u32 = 0b11101010010011110000000000000000;
instr |= (Rd & 15) << 8;
instr |= (Rm & 15) << 0;
instr |= (imm2 & 3) << 6;
instr |= (imm3 & 7) << 12;
instr |= (stype & 3) << 4;
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::Alt3 => {
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::Alt3 => {
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::Alt3 => {
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::Register(r) = op {
return Ok(())
}
todo!()
}
Encoding::Alt3 => {
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_op3(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
if let Operand::Shift(Shift::LSL(0)) = op {
return Ok(())
}
todo!()
}
Encoding::Alt3 => {
if op.is_none() {
return Ok(())
}
if let Operand::Shift(s) = op {
match s {
Shift::LSL(value) => if *value < 1 || *value > 31 {
todo!()
}
Shift::LSR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ASR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ROR(value) => if *value < 1 || *value > 31 {
todo!()
}
_ => todo!(),
}
return Ok(())
}
todo!()
}
Encoding::Alt1 => {
if op.is_none() {
return Ok(())
}
if let Operand::Shift(s) = op {
match s {
Shift::LSL(value) => if *value < 1 || *value > 31 {
todo!()
}
Shift::LSR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ASR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ROR(value) => if *value < 1 || *value > 31 {
todo!()
}
_ => todo!(),
}
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt3 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt3 => {
todo!()
}
Encoding::Alt1 => {
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt3 => {
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_r_t3, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterQualifier::Wide, true, true)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 2)?;
if !instr.op3().is_none() && !(instr.op3().as_shift()?.is_lsl() && instr.op3().as_shift()?.value() == 0) {
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 3)?;
};
return Ok(());
}
Encoding::Alt3 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.mov_r_t3, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterQualifier::Wide, true, true)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 2)?;
if !instr.op3().is_none() && !(instr.op3().as_shift()?.is_lsl() && instr.op3().as_shift()?.value() == 0) {
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 3)?;
};
return Ok(());
}
Encoding::Alt1 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.mov_r_t3, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 2)?;
if !instr.op3().is_none() && !(instr.op3().as_shift()?.is_lsl() && instr.op3().as_shift()?.value() == 0) {
fmt.format_punctuation(output, &config.global, &config.instructions.mov_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.mov_r_t3, &instr, 3)?;
};
return Ok(());
}
_ => todo!()
}
unreachable!()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovRT3Aliases {
AsrMovRT3,LslMovRT3,LsrMovRT3,RorMovRT3,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovRT3Encodings {
Alt2,
Alt3,
Alt1,
}
pub struct MovsRT3Rrx;
impl MovsRT3Rrx {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::MOVS
}
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 S = (data >> 20) & 1;
let S_post = S;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let imm2 = (data >> 6) & 3;
let imm2_post = imm2;
let stype = (data >> 4) & 3;
let stype_post = stype;
let Rm = (data >> 0) & 15;
let Rm_post = Rm;
let Rd_post = Rd;
let Rm_post = Rm;
match decoder.config.instructions.movs_r_t3_rrx.aliases {
None => match decoder.config.global.aliases {
FormatAliasGlobal::Never => {},
FormatAliasGlobal::Recommended => {
if ((S_post == 1) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return super::RrxsMovsRT3Rrx::decode(data, decoder);
}
},
FormatAliasGlobal::Always => {
return super::RrxsMovsRT3Rrx::decode(data, decoder);
}
}
Some(pref) => match pref {
FormatAliasInstruction::Never => {},
FormatAliasInstruction::Recommended => {
if ((S_post == 1) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return super::RrxsMovsRT3Rrx::decode(data, decoder);
}
},
FormatAliasInstruction::Preferred(alias) => {
match alias {
MovsRT3RrxAliases::RrxsMovsRT3Rrx => {
if ((S_post == 1) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return super::RrxsMovsRT3Rrx::decode(data, decoder);
}
}
};
if ((S_post == 1) && ((imm3_post == 0) && ((imm2_post == 0) && (stype_post == 3)))) {
return super::RrxsMovsRT3Rrx::decode(data, decoder);
}
},
FormatAliasInstruction::Always(alias) => {
match alias {
MovsRT3RrxAliases::RrxsMovsRT3Rrx => return super::RrxsMovsRT3Rrx::decode(data, decoder),
}
},
}
}
let op_0 = MnemonicCondition::Al;
let op_1 = Register::decode(Rd_post)?;
let op_2 = Register::decode(Rm_post)?;
let op_3 = Shift::RRX;
let mut instr = Instruction::builder(Code::MOVS_r_T3_RRX)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rd_pre = instr.op1().as_register()?.encode();
let Rm_pre = instr.op2().as_register()?.encode();
let Rd = (Rd_pre & 15);
let Rm = (Rm_pre & 15);
let mut instr: u32 = 0b11101010010111110000000000110000;
instr |= (Rd & 15) << 8;
instr |= (Rm & 15) << 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::Register(r) = op {
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Shift(Shift::RRX) = op {
return Ok(())
}
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.movs_r_t3_rrx, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3_rrx, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.movs_r_t3_rrx, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_r_t3_rrx, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3_rrx, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_r_t3_rrx, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3_rrx, &instr, 2)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_r_t3_rrx, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3_rrx, &instr, 3)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovsRT3RrxAliases {
RrxsMovsRT3Rrx,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovsRT3RrxEncodings {
None
}
pub struct MovsRT3;
impl MovsRT3 {
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 S = (data >> 20) & 1;
let S_post = S;
let imm3 = (data >> 12) & 7;
let imm3_post = imm3;
let Rd = (data >> 8) & 15;
let Rd_post = Rd;
let imm2 = (data >> 6) & 3;
let imm2_post = imm2;
let stype = (data >> 4) & 3;
let stype_post = stype;
let Rm = (data >> 0) & 15;
let Rm_post = Rm;
let imm2_imm3_post = (imm3 << 2) | imm2;
let Rd_post = Rd;
let Rm_post = Rm;
match decoder.config.instructions.movs_r_t3.aliases {
None => match decoder.config.global.aliases {
FormatAliasGlobal::Never => {},
FormatAliasGlobal::Recommended => {
if ((S_post == 1) && (stype_post == 2)) {
return super::AsrsMovsRT3::decode(data, decoder);
}
if ((((S_post == 1) && ((stype_post == 0) && !(((imm3_post == 0)))))) || (((S_post == 1) && ((stype_post == 0) && !(((imm2_post == 0))))))) {
return super::LslsMovsRT3::decode(data, decoder);
}
if ((S_post == 1) && (stype_post == 1)) {
return super::LsrsMovsRT3::decode(data, decoder);
}
if ((((S_post == 1) && ((stype_post == 3) && !(((imm3_post == 0)))))) || (((S_post == 1) && ((stype_post == 3) && !(((imm2_post == 0))))))) {
return super::RorsMovsRT3::decode(data, decoder);
}
},
FormatAliasGlobal::Always => {
return super::AsrsMovsRT3::decode(data, decoder);
return super::LslsMovsRT3::decode(data, decoder);
return super::LsrsMovsRT3::decode(data, decoder);
return super::RorsMovsRT3::decode(data, decoder);
}
}
Some(pref) => match pref {
FormatAliasInstruction::Never => {},
FormatAliasInstruction::Recommended => {
if ((S_post == 1) && (stype_post == 2)) {
return super::AsrsMovsRT3::decode(data, decoder);
}
if ((((S_post == 1) && ((stype_post == 0) && !(((imm3_post == 0)))))) || (((S_post == 1) && ((stype_post == 0) && !(((imm2_post == 0))))))) {
return super::LslsMovsRT3::decode(data, decoder);
}
if ((S_post == 1) && (stype_post == 1)) {
return super::LsrsMovsRT3::decode(data, decoder);
}
if ((((S_post == 1) && ((stype_post == 3) && !(((imm3_post == 0)))))) || (((S_post == 1) && ((stype_post == 3) && !(((imm2_post == 0))))))) {
return super::RorsMovsRT3::decode(data, decoder);
}
},
FormatAliasInstruction::Preferred(alias) => {
match alias {
MovsRT3Aliases::AsrsMovsRT3 => {
if ((S_post == 1) && (stype_post == 2)) {
return super::AsrsMovsRT3::decode(data, decoder);
}
}
MovsRT3Aliases::LslsMovsRT3 => {
if ((((S_post == 1) && ((stype_post == 0) && !(((imm3_post == 0)))))) || (((S_post == 1) && ((stype_post == 0) && !(((imm2_post == 0))))))) {
return super::LslsMovsRT3::decode(data, decoder);
}
}
MovsRT3Aliases::LsrsMovsRT3 => {
if ((S_post == 1) && (stype_post == 1)) {
return super::LsrsMovsRT3::decode(data, decoder);
}
}
MovsRT3Aliases::RorsMovsRT3 => {
if ((((S_post == 1) && ((stype_post == 3) && !(((imm3_post == 0)))))) || (((S_post == 1) && ((stype_post == 3) && !(((imm2_post == 0))))))) {
return super::RorsMovsRT3::decode(data, decoder);
}
}
};
if ((S_post == 1) && (stype_post == 2)) {
return super::AsrsMovsRT3::decode(data, decoder);
}
if ((((S_post == 1) && ((stype_post == 0) && !(((imm3_post == 0)))))) || (((S_post == 1) && ((stype_post == 0) && !(((imm2_post == 0))))))) {
return super::LslsMovsRT3::decode(data, decoder);
}
if ((S_post == 1) && (stype_post == 1)) {
return super::LsrsMovsRT3::decode(data, decoder);
}
if ((((S_post == 1) && ((stype_post == 3) && !(((imm3_post == 0)))))) || (((S_post == 1) && ((stype_post == 3) && !(((imm2_post == 0))))))) {
return super::RorsMovsRT3::decode(data, decoder);
}
},
FormatAliasInstruction::Always(alias) => {
match alias {
MovsRT3Aliases::AsrsMovsRT3 => return super::AsrsMovsRT3::decode(data, decoder),
MovsRT3Aliases::LslsMovsRT3 => return super::LslsMovsRT3::decode(data, decoder),
MovsRT3Aliases::LsrsMovsRT3 => return super::LsrsMovsRT3::decode(data, decoder),
MovsRT3Aliases::RorsMovsRT3 => return super::RorsMovsRT3::decode(data, decoder),
}
},
}
}
if let Some(encoding) = decoder.config.instructions.movs_r_t3.encodings {
match encoding {
MovsRT3Encodings::Alt2 => {
let Rd_post = Rd;
let op_0 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_1 = Register::decode(Rm_post)?;
let imm2_imm3_post = (imm3 << 2) | imm2;
let op_2 = match stype {
0 => if imm2_imm3_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm2_imm3_post))
}
1 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm2_imm3_post))
}
2 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm2_imm3_post))
}
3 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm2_imm3_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOVS_r_T3, Encoding::Alt2)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
return Ok(instr);
}
MovsRT3Encodings::Alt1 => {
let op_0 = MnemonicCondition::Al;
let Rd_post = Rd;
let op_1 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let imm2_imm3_post = (imm3 << 2) | imm2;
let op_3 = match stype {
0 => if imm2_imm3_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm2_imm3_post))
}
1 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm2_imm3_post))
}
2 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm2_imm3_post))
}
3 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm2_imm3_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOVS_r_T3, Encoding::Alt1)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.operand(3, op_3)?
.build();
return Ok(instr);
}
}
}
if (decoder.it_block.is_none()) && ((Rd_post <= 15 && Rm_post <= 15) || (Rd_post <= 7 && Rm_post <= 7)) {
let Rd_post = Rd;
let op_0 = Register::decode(Rd_post)?;
let Rm_post = Rm;
let op_1 = Register::decode(Rm_post)?;
let imm2_imm3_post = (imm3 << 2) | imm2;
let op_2 = match stype {
0 => if imm2_imm3_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm2_imm3_post))
}
1 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm2_imm3_post))
}
2 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm2_imm3_post))
}
3 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm2_imm3_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOVS_r_T3, 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 Rm_post = Rm;
let op_2 = Register::decode(Rm_post)?;
let imm2_imm3_post = (imm3 << 2) | imm2;
let op_3 = match stype {
0 => if imm2_imm3_post == 0 {
Operand::None
} else {
Operand::Shift(Shift::LSL(imm2_imm3_post))
}
1 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::LSR(32))
} else {
Operand::Shift(Shift::LSR(imm2_imm3_post))
}
2 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::ASR(32))
} else {
Operand::Shift(Shift::ASR(imm2_imm3_post))
}
3 => if imm2_imm3_post == 0 {
Operand::Shift(Shift::RRX)
} else {
Operand::Shift(Shift::ROR(imm2_imm3_post))
}
_ => todo!(),
};
let mut instr = Instruction::builder_multi(Code::MOVS_r_T3, Encoding::Alt1)
.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::Alt2 => {
let Rd_pre = instr.op0().as_register()?.encode();
let Rm_pre = instr.op1().as_register()?.encode();
let (stype, imm2_imm3_pre) = {
if let Operand::None = instr.op2() {
(0, 0)
} else {
match instr.op2().as_shift()? {
Shift::LSL(value) => (0, *value),
Shift::LSR(value) => (1, *value),
Shift::ASR(value) => (2, *value),
Shift::ROR(value) => (3, *value),
_ => todo!(),
}
}
};
let Rd = (Rd_pre & 15);
let Rm = (Rm_pre & 15);
let imm2 = (imm2_imm3_pre & 3);
let imm3 = (imm2_imm3_pre >> 2) & 7;
let mut instr: u32 = 0b11101010010111110000000000000000;
instr |= (Rd & 15) << 8;
instr |= (Rm & 15) << 0;
instr |= (imm2 & 3) << 6;
instr |= (imm3 & 7) << 12;
instr |= (stype & 3) << 4;
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 Rm_pre = instr.op2().as_register()?.encode();
let (stype, imm2_imm3_pre) = {
if let Operand::None = instr.op3() {
(0, 0)
} else {
match instr.op3().as_shift()? {
Shift::LSL(value) => (0, *value),
Shift::LSR(value) => (1, *value),
Shift::ASR(value) => (2, *value),
Shift::ROR(value) => (3, *value),
_ => todo!(),
}
}
};
let Rd = (Rd_pre & 15);
let Rm = (Rm_pre & 15);
let imm2 = (imm2_imm3_pre & 3);
let imm3 = (imm2_imm3_pre >> 2) & 7;
let mut instr: u32 = 0b11101010010111110000000000000000;
instr |= (Rd & 15) << 8;
instr |= (Rm & 15) << 0;
instr |= (imm2 & 3) << 6;
instr |= (imm3 & 7) << 12;
instr |= (stype & 3) << 4;
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::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 op.is_none() {
return Ok(())
}
if let Operand::Shift(s) = op {
match s {
Shift::LSL(value) => if *value < 1 || *value > 31 {
todo!()
}
Shift::LSR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ASR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ROR(value) => if *value < 1 || *value > 31 {
todo!()
}
_ => todo!(),
}
return Ok(())
}
todo!()
}
Encoding::Alt1 => {
if let Operand::Register(r) = op {
return Ok(())
}
todo!()
}
_ => todo!()
}
unreachable!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
match instr.encoding {
Encoding::Alt2 => {
todo!()
}
Encoding::Alt1 => {
if op.is_none() {
return Ok(())
}
if let Operand::Shift(s) = op {
match s {
Shift::LSL(value) => if *value < 1 || *value > 31 {
todo!()
}
Shift::LSR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ASR(value) => if *value < 1 || *value > 32 {
todo!()
}
Shift::ROR(value) => if *value < 1 || *value > 31 {
todo!()
}
_ => todo!(),
}
return Ok(())
}
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_r_t3, &instr)?;
fmt.format_qualifier(output, &config.global, &config.instructions.movs_r_t3, &instr, FormatterQualifier::Wide, true, true)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_r_t3, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3, &instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3, &instr, 1)?;
if !instr.op2().is_none() && !(instr.op2().as_shift()?.is_lsl() && instr.op2().as_shift()?.value() == 0) {
fmt.format_punctuation(output, &config.global, &config.instructions.movs_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3, &instr, 2)?;
};
return Ok(());
}
Encoding::Alt1 => {
fmt.format_mnemonic(output, &config.global, &config.instructions.movs_r_t3, &instr)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3, &instr, 0)?;
fmt.format_qualifier(output, &config.global, &config.instructions.movs_r_t3, &instr, FormatterQualifier::Wide, true, false)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_r_t3, &instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3, &instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.movs_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3, &instr, 2)?;
if !instr.op3().is_none() && !(instr.op3().as_shift()?.is_lsl() && instr.op3().as_shift()?.value() == 0) {
fmt.format_punctuation(output, &config.global, &config.instructions.movs_r_t3, &instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.movs_r_t3, &instr, 3)?;
};
return Ok(());
}
_ => todo!()
}
unreachable!()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovsRT3Aliases {
AsrsMovsRT3,LslsMovsRT3,LsrsMovsRT3,RorsMovsRT3,
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum MovsRT3Encodings {
Alt2,
Alt1,
}