From 624a153311e727f3a63a16045c6ba3d99de7d7e0 Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 15 Sep 2020 21:40:04 -0700 Subject: it's a start --- .gitignore | 1 + Cargo.lock | 32 +++++++++++++++ Cargo.toml | 11 +++++ src/lib.rs | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test.rs | 24 +++++++++++ 5 files changed, 197 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/lib.rs create mode 100644 test/test.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..7983b37 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,32 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +dependencies = [ + "autocfg", +] + +[[package]] +name = "yaxpeax-arch" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d4d184a208255bb62f2d55c3875ee3fe459f2b8d9190b8427986b91d11ced7f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "yaxpeax-ia64" +version = "0.0.1" +dependencies = [ + "yaxpeax-arch", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5d64136 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "yaxpeax-ia64" +version = "0.0.1" +authors = ["iximeow "] +edition = "2018" +license = "0BSD" +repository = "http://git.iximeow.net/yaxpeax-ia64/" +description = "ia64 decoder for the yaxpeax project" + +[dependencies] +yaxpeax-arch = { version = "0.0.4", default-features = false, features = [] } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..bfd0b37 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,129 @@ +use yaxpeax_arch::{Arch, AddressDiff, Decoder, LengthedInstruction, NoColors, YaxColors}; + +use core::fmt; + +/// TODO: ia64 reference doc + +pub struct IA64; + +impl Arch for IA64 { + type Address = u64; + type Instruction = Instruction; + type DecodeError = DecodeError; + type Decoder = InstDecoder; + type Operand = Operand; +} + +#[derive(Debug, PartialEq, Eq)] +pub struct Instruction {} +impl yaxpeax_arch::LengthedInstruction for Instruction { + type Unit = yaxpeax_arch::AddressDiff; + fn len(&self) -> Self::Unit { AddressDiff::from_const(1) } + fn min_size() -> Self::Unit { AddressDiff::from_const(1) } +} +impl yaxpeax_arch::Instruction for Instruction { + fn well_defined(&self) -> bool { + true + } +} +impl Default for Instruction { + fn default() -> Self { + Instruction { } + } +} +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub enum DecodeError { + ExhaustedInput, + BadOpcode, + BadOperand, + BadBundle, +} +impl fmt::Display for DecodeError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + DecodeError::ExhaustedInput => f.write_str("exhausted input"), + DecodeError::BadBundle => f.write_str("bad bundle"), + DecodeError::BadOpcode => f.write_str("bad opcode"), + DecodeError::BadOperand => f.write_str("bad operand"), + } + } +} +impl yaxpeax_arch::DecodeError for DecodeError { + fn data_exhausted(&self) -> bool { + if let DecodeError::ExhaustedInput = self { + true + } else { + false + } + } + fn bad_opcode(&self) -> bool { + if let DecodeError::BadBundle = self { + true + } else if let DecodeError::BadOpcode = self { + true + } else { + false + } + } + fn bad_operand(&self) -> bool { + if let DecodeError::BadOperand = self { + true + } else { + false + } + } +} +#[derive(Default)] +pub struct InstDecoder {} +#[derive(Debug)] +pub enum Operand {} + +impl Decoder for InstDecoder { + type Error = DecodeError; + + fn decode_into>(&self, inst: &mut Instruction, bytes: T) -> Result<(), Self::Error> { + let mut bytes_iter = bytes.into_iter(); + let bundle = bytes_iter.next().ok_or(DecodeError::ExhaustedInput)?; + let bundle_tag = bundle & 0x1f; + let bundle_desc = match bundle_tag { + 0x00 => { "M I I " }, + 0x01 => { "M I I|" }, + 0x02 => { "M I|I " }, + 0x03 => { "M I|I|" }, + 0x04 => { "M L X " }, + 0x05 => { "M L X|" }, + 0x06 => { return Err(DecodeError::BadBundle) }, + 0x07 => { return Err(DecodeError::BadBundle) }, + 0x08 => { "M M I " }, + 0x09 => { "M M I|" }, + 0x0a => { "M|M I " }, + 0x0b => { "M|M I|" }, + 0x0c => { "M F I " }, + 0x0d => { "M F I|" }, + 0x0e => { "M M F " }, + 0x0f => { "M M F|" }, + 0x10 => { "M I B " }, + 0x11 => { "M I B|" }, + 0x12 => { "M B B " }, + 0x13 => { "M B B|" }, + 0x14 => { return Err(DecodeError::BadBundle) }, + 0x15 => { return Err(DecodeError::BadBundle) }, + 0x16 => { "B B B " }, + 0x17 => { "B B B|" }, + 0x18 => { "M M B " }, + 0x19 => { "M M B|" }, + 0x1a => { return Err(DecodeError::BadBundle) }, + 0x1b => { return Err(DecodeError::BadBundle) }, + 0x1c => { "M F B " }, + 0x1d => { "M F B|" }, + 0x1e => { return Err(DecodeError::BadBundle) }, + 0x1f => { return Err(DecodeError::BadBundle) }, + _ => { unreachable!(); } + }; + eprintln!("bundle tag: {}", bundle_desc); + + // from here, `itanium-architecture-vol-1-2-3-4-reference-set-manual.pdf` volume 3 is + // remaining necessary details + Ok(()) + } +} diff --git a/test/test.rs b/test/test.rs new file mode 100644 index 0000000..128e601 --- /dev/null +++ b/test/test.rs @@ -0,0 +1,24 @@ + + +// from elf64-ia64-vms.c +// 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, 0x00, 0x41, 0x3c, 0x70, 0x27, 0xc0, 0x01, 0x08, 0x00, 0x84 +// [MMI] addl r15=0,r1;; +// ld8.acq r16=[r15],8 +// mov r14=r1;; +// 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, 0x60, 0x00, 0x80, 0x00 +// [MIB] ld8 r1=[r15] +// mov b6=r16 +// br.few b6;; +// 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0 +// [MLX] nop.m 0 +// brl.sptk.few tgt;; + +// from ia64 bash_4.2+dfsg-0.1+deb7u3_ia64: +// 0410 1c00 8045 024c 8009 0060 f013 1a60 +// 0510 4118 0021 0000 0000 6020 0023 c86f +// 0908 2144 1814 a000 4444 0820 0100 c000 +// 0100 0c50 2a04 1048 040a 40c0 0461 0084 +// 0158 80fb f027 0082 f5e5 4f60 04ed c79f +// 0918 0016 1810 0002 8030 2080 04e9 b79f +// 0818 0146 1810 4002 9030 2000 0000 0400 +// 1000 2806 9811 5002 2000 4200 50a5 ff58 -- cgit v1.1