#![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 IclassCbhgt16Regs;
impl IclassCbhgt16Regs {
pub(crate) fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rm = (data >> 16) & 31;
let Rm_post = Rm;
let H = (data >> 14) & 1;
let H_post = H;
let Rt = (data >> 0) & 31;
let Rt_post = Rt;
let field_31 = (data >> 24) & 255;
let field_31_post = field_31;
let field_15 = (data >> 15) & 1;
let field_15_post = field_15;
let imm9 = (data >> 5) & 511;
let imm9_post = imm9;
let cc = (data >> 21) & 7;
let cc_post = cc;
if (cc_post == 0) {
return Cbhgt16Regs::decode(data as u32, decoder);
}
if (cc_post == 1) {
return Cbhge16Regs::decode(data as u32, decoder);
}
if (cc_post == 2) {
return Cbhhi16Regs::decode(data as u32, decoder);
}
if (cc_post == 3) {
return Cbhhs16Regs::decode(data as u32, decoder);
}
if (cc_post == 6) {
return Cbheq16Regs::decode(data as u32, decoder);
}
if (cc_post == 7) {
return Cbhne16Regs::decode(data as u32, decoder);
}
unreachable!()
}
}
pub struct Cbhgt16Regs;
impl Cbhgt16Regs {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::CBHGT
}
pub fn size(_instr: &Instruction) -> usize {
4
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rm = (data >> 16) & 31;
let Rm_post = Rm;
let imm9 = (data >> 5) & 511;
let imm9_post = imm9;
let Rt = (data >> 0) & 31;
let Rt_post = Rt;
let Rt_post = Rt;
let op_0 = Register::aarch32(Rt_post, false)?;
let Rm_post = Rm;
let op_1 = Register::aarch32(Rm_post, false)?;
let imm9_post = ((((imm9) as i64) * 4) << 53) >> 53;
let op_2 = Label::decode(imm9_post.into());
let mut instr = Instruction::builder(Code::CBHGT_16_regs)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
if decoder.block_decoding {
let pc = match instr.op2().as_label()? {
Label::Label(imm) => (decoder.pc as i128 + imm as i128) as u64,
_ => unreachable!(),
};
decoder.labels.insert(pc);
instr.set_op(2, Label::LabelName(pc as u64))?;
}
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rt_pre = instr.op0().as_register()?.encode();
let Rm_pre = instr.op1().as_register()?.encode();
let imm9_pre = instr.op2().as_label()?.encode()?;
let Rt = (Rt_pre & 31);
let Rm = (Rm_pre & 31);
let imm9_pre = ((imm9_pre) / 4) as u32;
let imm9 = (imm9_pre & 511);
let mut instr: u32 = 0b01110100000000001100000000000000;
instr |= (Rt & 31) << 0;
instr |= (Rm & 31) << 16;
instr |= (imm9 & 511) << 5;
let bytes = instr.to_le_bytes();
let len = bytes.len();
buf.extend(bytes);
Ok(len)
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
if let Label::LabelName(label_name) = instr.op2().as_label()? {
if let Some(label_pc) = labels.get(&label_name) {
let pc = *label_pc as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
} else {
let pc = label_name as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
}
}
Self::encode(instr, buf)
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Label(Label::LabelName(_)) = op {
return Ok(())
}
if let Operand::Label(Label::Label(i)) = op {
if !(-1024..=1020).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
fmt.format_mnemonic(output, &config.global, &config.instructions.cbhgt_16_regs, instr)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhgt_16_regs, instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhgt_16_regs, instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhgt_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhgt_16_regs, instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhgt_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhgt_16_regs, instr, 2)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum Cbhgt16RegsAliases {
None,
}
pub struct Cbhge16Regs;
impl Cbhge16Regs {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::CBHGE
}
pub fn size(_instr: &Instruction) -> usize {
4
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rm = (data >> 16) & 31;
let Rm_post = Rm;
let imm9 = (data >> 5) & 511;
let imm9_post = imm9;
let Rt = (data >> 0) & 31;
let Rt_post = Rt;
let Rt_post = Rt;
let op_0 = Register::aarch32(Rt_post, false)?;
let Rm_post = Rm;
let op_1 = Register::aarch32(Rm_post, false)?;
let imm9_post = ((((imm9) as i64) * 4) << 53) >> 53;
let op_2 = Label::decode(imm9_post.into());
let mut instr = Instruction::builder(Code::CBHGE_16_regs)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
if decoder.block_decoding {
let pc = match instr.op2().as_label()? {
Label::Label(imm) => (decoder.pc as i128 + imm as i128) as u64,
_ => unreachable!(),
};
decoder.labels.insert(pc);
instr.set_op(2, Label::LabelName(pc as u64))?;
}
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rt_pre = instr.op0().as_register()?.encode();
let Rm_pre = instr.op1().as_register()?.encode();
let imm9_pre = instr.op2().as_label()?.encode()?;
let Rt = (Rt_pre & 31);
let Rm = (Rm_pre & 31);
let imm9_pre = ((imm9_pre) / 4) as u32;
let imm9 = (imm9_pre & 511);
let mut instr: u32 = 0b01110100001000001100000000000000;
instr |= (Rt & 31) << 0;
instr |= (Rm & 31) << 16;
instr |= (imm9 & 511) << 5;
let bytes = instr.to_le_bytes();
let len = bytes.len();
buf.extend(bytes);
Ok(len)
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
if let Label::LabelName(label_name) = instr.op2().as_label()? {
if let Some(label_pc) = labels.get(&label_name) {
let pc = *label_pc as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
} else {
let pc = label_name as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
}
}
Self::encode(instr, buf)
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Label(Label::LabelName(_)) = op {
return Ok(())
}
if let Operand::Label(Label::Label(i)) = op {
if !(-1024..=1020).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
fmt.format_mnemonic(output, &config.global, &config.instructions.cbhge_16_regs, instr)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhge_16_regs, instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhge_16_regs, instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhge_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhge_16_regs, instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhge_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhge_16_regs, instr, 2)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum Cbhge16RegsAliases {
None,
}
pub struct Cbhhi16Regs;
impl Cbhhi16Regs {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::CBHHI
}
pub fn size(_instr: &Instruction) -> usize {
4
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rm = (data >> 16) & 31;
let Rm_post = Rm;
let imm9 = (data >> 5) & 511;
let imm9_post = imm9;
let Rt = (data >> 0) & 31;
let Rt_post = Rt;
let Rt_post = Rt;
let op_0 = Register::aarch32(Rt_post, false)?;
let Rm_post = Rm;
let op_1 = Register::aarch32(Rm_post, false)?;
let imm9_post = ((((imm9) as i64) * 4) << 53) >> 53;
let op_2 = Label::decode(imm9_post.into());
let mut instr = Instruction::builder(Code::CBHHI_16_regs)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
if decoder.block_decoding {
let pc = match instr.op2().as_label()? {
Label::Label(imm) => (decoder.pc as i128 + imm as i128) as u64,
_ => unreachable!(),
};
decoder.labels.insert(pc);
instr.set_op(2, Label::LabelName(pc as u64))?;
}
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rt_pre = instr.op0().as_register()?.encode();
let Rm_pre = instr.op1().as_register()?.encode();
let imm9_pre = instr.op2().as_label()?.encode()?;
let Rt = (Rt_pre & 31);
let Rm = (Rm_pre & 31);
let imm9_pre = ((imm9_pre) / 4) as u32;
let imm9 = (imm9_pre & 511);
let mut instr: u32 = 0b01110100010000001100000000000000;
instr |= (Rt & 31) << 0;
instr |= (Rm & 31) << 16;
instr |= (imm9 & 511) << 5;
let bytes = instr.to_le_bytes();
let len = bytes.len();
buf.extend(bytes);
Ok(len)
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
if let Label::LabelName(label_name) = instr.op2().as_label()? {
if let Some(label_pc) = labels.get(&label_name) {
let pc = *label_pc as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
} else {
let pc = label_name as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
}
}
Self::encode(instr, buf)
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Label(Label::LabelName(_)) = op {
return Ok(())
}
if let Operand::Label(Label::Label(i)) = op {
if !(-1024..=1020).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
fmt.format_mnemonic(output, &config.global, &config.instructions.cbhhi_16_regs, instr)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhhi_16_regs, instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhhi_16_regs, instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhhi_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhhi_16_regs, instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhhi_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhhi_16_regs, instr, 2)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum Cbhhi16RegsAliases {
None,
}
pub struct Cbhhs16Regs;
impl Cbhhs16Regs {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::CBHHS
}
pub fn size(_instr: &Instruction) -> usize {
4
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rm = (data >> 16) & 31;
let Rm_post = Rm;
let imm9 = (data >> 5) & 511;
let imm9_post = imm9;
let Rt = (data >> 0) & 31;
let Rt_post = Rt;
let Rt_post = Rt;
let op_0 = Register::aarch32(Rt_post, false)?;
let Rm_post = Rm;
let op_1 = Register::aarch32(Rm_post, false)?;
let imm9_post = ((((imm9) as i64) * 4) << 53) >> 53;
let op_2 = Label::decode(imm9_post.into());
let mut instr = Instruction::builder(Code::CBHHS_16_regs)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
if decoder.block_decoding {
let pc = match instr.op2().as_label()? {
Label::Label(imm) => (decoder.pc as i128 + imm as i128) as u64,
_ => unreachable!(),
};
decoder.labels.insert(pc);
instr.set_op(2, Label::LabelName(pc as u64))?;
}
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rt_pre = instr.op0().as_register()?.encode();
let Rm_pre = instr.op1().as_register()?.encode();
let imm9_pre = instr.op2().as_label()?.encode()?;
let Rt = (Rt_pre & 31);
let Rm = (Rm_pre & 31);
let imm9_pre = ((imm9_pre) / 4) as u32;
let imm9 = (imm9_pre & 511);
let mut instr: u32 = 0b01110100011000001100000000000000;
instr |= (Rt & 31) << 0;
instr |= (Rm & 31) << 16;
instr |= (imm9 & 511) << 5;
let bytes = instr.to_le_bytes();
let len = bytes.len();
buf.extend(bytes);
Ok(len)
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
if let Label::LabelName(label_name) = instr.op2().as_label()? {
if let Some(label_pc) = labels.get(&label_name) {
let pc = *label_pc as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
} else {
let pc = label_name as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
}
}
Self::encode(instr, buf)
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Label(Label::LabelName(_)) = op {
return Ok(())
}
if let Operand::Label(Label::Label(i)) = op {
if !(-1024..=1020).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
fmt.format_mnemonic(output, &config.global, &config.instructions.cbhhs_16_regs, instr)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhhs_16_regs, instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhhs_16_regs, instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhhs_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhhs_16_regs, instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhhs_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhhs_16_regs, instr, 2)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum Cbhhs16RegsAliases {
None,
}
pub struct Cbheq16Regs;
impl Cbheq16Regs {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::CBHEQ
}
pub fn size(_instr: &Instruction) -> usize {
4
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rm = (data >> 16) & 31;
let Rm_post = Rm;
let imm9 = (data >> 5) & 511;
let imm9_post = imm9;
let Rt = (data >> 0) & 31;
let Rt_post = Rt;
let Rt_post = Rt;
let op_0 = Register::aarch32(Rt_post, false)?;
let Rm_post = Rm;
let op_1 = Register::aarch32(Rm_post, false)?;
let imm9_post = ((((imm9) as i64) * 4) << 53) >> 53;
let op_2 = Label::decode(imm9_post.into());
let mut instr = Instruction::builder(Code::CBHEQ_16_regs)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
if decoder.block_decoding {
let pc = match instr.op2().as_label()? {
Label::Label(imm) => (decoder.pc as i128 + imm as i128) as u64,
_ => unreachable!(),
};
decoder.labels.insert(pc);
instr.set_op(2, Label::LabelName(pc as u64))?;
}
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rt_pre = instr.op0().as_register()?.encode();
let Rm_pre = instr.op1().as_register()?.encode();
let imm9_pre = instr.op2().as_label()?.encode()?;
let Rt = (Rt_pre & 31);
let Rm = (Rm_pre & 31);
let imm9_pre = ((imm9_pre) / 4) as u32;
let imm9 = (imm9_pre & 511);
let mut instr: u32 = 0b01110100110000001100000000000000;
instr |= (Rt & 31) << 0;
instr |= (Rm & 31) << 16;
instr |= (imm9 & 511) << 5;
let bytes = instr.to_le_bytes();
let len = bytes.len();
buf.extend(bytes);
Ok(len)
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
if let Label::LabelName(label_name) = instr.op2().as_label()? {
if let Some(label_pc) = labels.get(&label_name) {
let pc = *label_pc as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
} else {
let pc = label_name as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
}
}
Self::encode(instr, buf)
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Label(Label::LabelName(_)) = op {
return Ok(())
}
if let Operand::Label(Label::Label(i)) = op {
if !(-1024..=1020).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
fmt.format_mnemonic(output, &config.global, &config.instructions.cbheq_16_regs, instr)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbheq_16_regs, instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.cbheq_16_regs, instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbheq_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbheq_16_regs, instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbheq_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbheq_16_regs, instr, 2)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum Cbheq16RegsAliases {
None,
}
pub struct Cbhne16Regs;
impl Cbhne16Regs {
pub fn mnemonic(_instr: &Instruction) -> Mnemonic {
Mnemonic::CBHNE
}
pub fn size(_instr: &Instruction) -> usize {
4
}
pub fn decode(data: u32, decoder: &mut Decoder) -> Result<Instruction> {
let Rm = (data >> 16) & 31;
let Rm_post = Rm;
let imm9 = (data >> 5) & 511;
let imm9_post = imm9;
let Rt = (data >> 0) & 31;
let Rt_post = Rt;
let Rt_post = Rt;
let op_0 = Register::aarch32(Rt_post, false)?;
let Rm_post = Rm;
let op_1 = Register::aarch32(Rm_post, false)?;
let imm9_post = ((((imm9) as i64) * 4) << 53) >> 53;
let op_2 = Label::decode(imm9_post.into());
let mut instr = Instruction::builder(Code::CBHNE_16_regs)
.operand(0, op_0)?
.operand(1, op_1)?
.operand(2, op_2)?
.build();
if decoder.block_decoding {
let pc = match instr.op2().as_label()? {
Label::Label(imm) => (decoder.pc as i128 + imm as i128) as u64,
_ => unreachable!(),
};
decoder.labels.insert(pc);
instr.set_op(2, Label::LabelName(pc as u64))?;
}
Ok(instr)
}
pub fn encode(instr: &Instruction, buf: &mut Vec<u8>) -> Result<usize> {
let Rt_pre = instr.op0().as_register()?.encode();
let Rm_pre = instr.op1().as_register()?.encode();
let imm9_pre = instr.op2().as_label()?.encode()?;
let Rt = (Rt_pre & 31);
let Rm = (Rm_pre & 31);
let imm9_pre = ((imm9_pre) / 4) as u32;
let imm9 = (imm9_pre & 511);
let mut instr: u32 = 0b01110100111000001100000000000000;
instr |= (Rt & 31) << 0;
instr |= (Rm & 31) << 16;
instr |= (imm9 & 511) << 5;
let bytes = instr.to_le_bytes();
let len = bytes.len();
buf.extend(bytes);
Ok(len)
}
pub fn encode_block(instr: &mut Instruction, buf: &mut Vec<u8>, labels: &std::collections::HashMap<u64, u64>) -> Result<usize> {
if let Label::LabelName(label_name) = instr.op2().as_label()? {
if let Some(label_pc) = labels.get(&label_name) {
let pc = *label_pc as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
} else {
let pc = label_name as i128 - instr.pc as i128;
instr.set_op(2, Label::decode(pc as i64))?;
}
}
Self::encode(instr, buf)
}
pub fn check_op0(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op1(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Register(r) = op {
if !r.is_aarch32() {
todo!()
}
if *r == Register::WSP {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op2(instr: &Instruction, op: &Operand) -> Result<()> {
if let Operand::Label(Label::LabelName(_)) = op {
return Ok(())
}
if let Operand::Label(Label::Label(i)) = op {
if !(-1024..=1020).contains(i) {
todo!()
}
return Ok(())
}
todo!()
}
pub fn check_op3(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op4(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op5(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn check_op6(instr: &Instruction, op: &Operand) -> Result<()> {
todo!()
}
pub fn format(instr: &Instruction, fmt: &mut impl Formatter, output: &mut impl FormatterOutput, config: &Config) -> Result<()> {
fmt.format_mnemonic(output, &config.global, &config.instructions.cbhne_16_regs, instr)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhne_16_regs, instr, FormatterTextKind::Space)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhne_16_regs, instr, 0)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhne_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhne_16_regs, instr, 1)?;
fmt.format_punctuation(output, &config.global, &config.instructions.cbhne_16_regs, instr, FormatterTextKind::Comma)?;
fmt.format_operand(output, &config.global, &config.instructions.cbhne_16_regs, instr, 2)?;
Ok(())
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub enum Cbhne16RegsAliases {
None,
}