Expand description
§yaxpeax-arch
shared traits for architecture definitions, instruction decoders, and related interfaces for instruction decoders from the yaxpeax project.
typically this crate is only interesting if you’re writing code to operate on multiple architectures that all implement yaxpeax-arch traits. for example, yaxpeax-dis implements disassembly and display logic generic over the traits defined here, so adding a new decoder is usually only a one or two line addition.
yaxpeax-arch has several crate features, which implementers are encouraged to also support:
std: opt-in forstd-specific support - in this crate,stdenables astd::error::Errorrequirement onDecodeError, allowing users to?-unwrap decode results.colors: enables (optional)crossterm-based ANSI colorization. default coloring rules are defined byColorSettings, when enabled.address-parse: enable a requirement thatyaxpeax_arch::Addressbe parsable from&str. this is useful for use cases that, for example, read addresses from humans.use-serde: enableserdeserialization and deserialization bounds for types likeAddress.
with all features disabled, yaxpeax-arch’s only direct dependency is num-traits, and is suitable for #![no_std] usage.
§design
yaxpeax-arch has backwards-incompatible changes from time to time, but there’s not much to make incompatible. the main benefit of this crate is the Arch trait, for other libraries to build architecture-agnostic functionality.
nontrivial additions to yaxpeax-arch should include some discussion summarized by an addition to the crate docs/. you may ask, “where does discussion happen?”, and the answer currently is in my (iximeow’s) head, or various discord/irc/discord/email conversations. if there’s need in the future, yaxpeax may develop a more consistent process.
yaxpeax-arch intends to support ad-hoc development of architecture support. maintainers of various architectures’ crates may not want to implement all available interfaces to a complete level of detail, and must not be required to. incomplete implementations may be an issue for downstream users, but library quality is mediated by human conversation, not yaxpeax-arch interfaces. extensions to these fundamental definitions should be considerate of partial and incomplete implementations.
§implementations
there are numerous architectures for which decoders are implemented, at varying levels of completion. now and in the future, they will be enumerated here:
| symbol | meaning |
|---|---|
| 🥳 | complete, reliable |
| ⚠️ | “complete”, likely has gaps |
| 🚧 | incomplete |
| ❓ | unimplemented |
| architecture | library | decode | tests | benchmarks | note |
|---|---|---|---|---|---|
x86_64 | yaxpeax-x86 | 🥳 | 🥳 | 🥳 | |
x86:32 | yaxpeax-x86 | 🥳 | 🥳 | ❓ | sse and sse2 support cannot be disabled |
x86:16 | yaxpeax-x86 | 🥳 | 🥳 | ❓ | instructions above the 8086 or 286 cannot be disabled |
ia64 | yaxpeax-ia64 | 🥳 | ⚠️ | ❓ | lack of a good oracle has complicated testing |
armv7 | yaxpeax-arm | 🚧 | 🚧 | ❓ | NEON is not yet supported |
armv8 | yaxpeax-arm | 🚧 | 🚧 | ❓ | a32 decoding is not yet supported, NEON is not supported |
m16c | yaxpeax-m16c | ⚠️ | 🚧 | ❓ | |
mips | yaxpeax-mips | 🚧 | 🚧 | ❓ | |
msp430 | yaxpeax-msp430 | 🚧 | 🚧 | ❓ | |
pic17 | yaxpeax-pic17 | 🚧 | 🚧 | ❓ | |
pic18 | yaxpeax-pic18 | 🚧 | 🚧 | ❓ | |
pic24 | yaxpeax-pic24 | ❓ | ❓ | ❓ | exists, but only decodes NOP |
sm83 | yaxpeax-sm83 | 🥳 | 🚧 | ❓ | |
avr | yaxpeax-avr | 🥳 | 🚧 | ❓ | contributed by @the6p4c! |
sh/sh2/j2/sh3/sh4 | yaxpeax-superh | 🥳 | 🚧 | ❓ | contributed by наб |
MOS 6502 | yaxpeax-6502 | ⚠️ | ❓ | ❓ | contributed by @cr1901 |
lc87 | yaxpeax-lc87 | 🥳 | ⚠️ | ❓ |
§feature support
yaxpeax-arch defines a few typically-optional features that decoders can also implement, in addition to simple (bytes) -> instruction decoding. these are yaxpeax-arch traits (or collections thereof) which architectures implement, not crate features.
description_spans: implementation of AnnotatingDecoder, to decode instructions with bit-level details of what incoming bitstreams mean.
contextualize: implementation of ShowContextual, to display instructions with user-defined information in place of default instruction data. typically expected to show label names instead of relative branch addresses. i do not recommend implementing this trait, it needs significant reconsideration.
| architecture | description_spans | contextualize |
|---|---|---|
x86_64 | 🥳 | ❓ |
ia64 | ⚠️ | ❓ |
msp430 | 🥳 | ❓ |
§mirrors
the canonical copy of yaxpeax-arch is at https://git.iximeow.net/yaxpeax-arch.
yaxpeax-arch is also mirrored on GitHub at https://www.github.com/iximeow/yaxpeax-arch.
Modules§
- traits (and convenient impls) for decoders that also produce descriptions of parsed bit fields.
Structs§
- a struct describing the differece between some pair of
A: Address. this is primarily useful in describing the size of an instruction, or the relative offset of a branch. - a struct for
Readerimpls that can operate on units ofu8.
Enums§
- a minimal enum implementing
DecodeError. this is intended to be enough for a low effort, low-fidelity error taxonomy, without boilerplate of aDecodeErrorimplementation. - a slightly less minimal enum
DecodeError. similar toStandardDecodeError, this is an anti-boilerplate measure. it additionally providesIncompleteDecoder, making it suitable to represent error kinds for decoders that are … not yet complete.
Traits§
- a collection of associated type parameters that constitute the definitions for an instruction set.
Archprovides anInstructionand its associatedOperands, which is guaranteed to be decodable by thisArch::Decoder.Arch::Decodercan always be constructed with aDefaultimplementation, and decodes from aReader<Arch::Address, Arch::Word>. - the minimum set of errors a
yaxpeax-archdisassembler may produce. - this is not a particularly interesting trait. it just exists to add a
std::error::Errorbound ontoDecodeErrorforstdbuilds. - an interface to decode
Arch::Instructionwords from a reader ofArch::Words. errors are the architecture-definedDecodeErrorimplemention. - instructions have lengths, and minimum possible sizes for advancing a decoder on error.
- a trait defining how
Item-sized words are read atAddress-positioned offsets into some stream of data. for most uses,crate::U8Readerprobably is sufficient. when reading from data sources that aren’t&[u8],Addressisn’t a multiple ofu8, orItemisn’t a multiple of 8 bits,U8Readerwon’t be sufficient. - a trait defining how to build a
Reader<Address, Item>from some data source (Self). definitions ofReaderBuilderare provided forU8ReaderonAddressandWordtypes thatyaxpeax_archprovides - external decoder implementations should also provideReaderBuilderimpls if they use customReadertypes.