Arm instruction manipulator.
Find a file
2024-06-19 19:02:13 +02:00
src Document assert_or_err; Add docs logo; Restructure tests; Bump minor; Update lints; Add new errors: IllegalFlag, IllegalShifter, InvalidOpcode, UnknownMnemonic; Update readme; Update documentation; Improve diagnostics. Arm32: Encode more instructions for Thumb; Make InstructionCodec::encode_thumb return tuple; Add new instructions: Test, TestEquivalence, UnsignedSaturate, PreloadData, BranchLinkExchange, Swap, Load, Store; Rework Flag; Add Address type; Add as_register method to Shifter; Add skip_words, skip_halfwords, and skib_bytes methods to InstructionCodec; Add from_register method to Shifter; Add Thumb decoding to InstructionCodec; Add from_u8 method to Predicate; Add from_u8 method to Register; Implement FromStr for Instruction; Add new Sflag, Bflag, and Tflag flags; Add seek_to method to InstructionCodec. 2024-06-19 19:02:13 +02:00
.gitignore Fork from Luma and eAS; Add gitignore; Add changelog; Add readme; License under AGPL; Add Instruction type; Add Register type; 2024-06-11 19:17:53 +02:00
Cargo.toml Document assert_or_err; Add docs logo; Restructure tests; Bump minor; Update lints; Add new errors: IllegalFlag, IllegalShifter, InvalidOpcode, UnknownMnemonic; Update readme; Update documentation; Improve diagnostics. Arm32: Encode more instructions for Thumb; Make InstructionCodec::encode_thumb return tuple; Add new instructions: Test, TestEquivalence, UnsignedSaturate, PreloadData, BranchLinkExchange, Swap, Load, Store; Rework Flag; Add Address type; Add as_register method to Shifter; Add skip_words, skip_halfwords, and skib_bytes methods to InstructionCodec; Add from_register method to Shifter; Add Thumb decoding to InstructionCodec; Add from_u8 method to Predicate; Add from_u8 method to Register; Implement FromStr for Instruction; Add new Sflag, Bflag, and Tflag flags; Add seek_to method to InstructionCodec. 2024-06-19 19:02:13 +02:00
CHANGELOG.md Document assert_or_err; Add docs logo; Restructure tests; Bump minor; Update lints; Add new errors: IllegalFlag, IllegalShifter, InvalidOpcode, UnknownMnemonic; Update readme; Update documentation; Improve diagnostics. Arm32: Encode more instructions for Thumb; Make InstructionCodec::encode_thumb return tuple; Add new instructions: Test, TestEquivalence, UnsignedSaturate, PreloadData, BranchLinkExchange, Swap, Load, Store; Rework Flag; Add Address type; Add as_register method to Shifter; Add skip_words, skip_halfwords, and skib_bytes methods to InstructionCodec; Add from_register method to Shifter; Add Thumb decoding to InstructionCodec; Add from_u8 method to Predicate; Add from_u8 method to Register; Implement FromStr for Instruction; Add new Sflag, Bflag, and Tflag flags; Add seek_to method to InstructionCodec. 2024-06-19 19:02:13 +02:00
COPYING Fork from Luma and eAS; Add gitignore; Add changelog; Add readme; License under AGPL; Add Instruction type; Add Register type; 2024-06-11 19:17:53 +02:00
pollex-monochrome.svg Document assert_or_err; Add docs logo; Restructure tests; Bump minor; Update lints; Add new errors: IllegalFlag, IllegalShifter, InvalidOpcode, UnknownMnemonic; Update readme; Update documentation; Improve diagnostics. Arm32: Encode more instructions for Thumb; Make InstructionCodec::encode_thumb return tuple; Add new instructions: Test, TestEquivalence, UnsignedSaturate, PreloadData, BranchLinkExchange, Swap, Load, Store; Rework Flag; Add Address type; Add as_register method to Shifter; Add skip_words, skip_halfwords, and skib_bytes methods to InstructionCodec; Add from_register method to Shifter; Add Thumb decoding to InstructionCodec; Add from_u8 method to Predicate; Add from_u8 method to Register; Implement FromStr for Instruction; Add new Sflag, Bflag, and Tflag flags; Add seek_to method to InstructionCodec. 2024-06-19 19:02:13 +02:00
pollex-wordmark.svg Bump minor version; Add logo; Add more errors; Add macro assert_or_err; Document errors; Remove Arch. Arm32: Add encode_thumb method to InstructionCodec; Add is_low and is_high methods to Register; Implement FromStr for Register; Rename Sb, Sl, and Ip in Register to R9, R10, and R12; Display instruction synonyms; Document Flag. Arm64: Add module. 2024-06-15 22:20:30 +02:00
pollex.svg Bump minor version; Add logo; Add more errors; Add macro assert_or_err; Document errors; Remove Arch. Arm32: Add encode_thumb method to InstructionCodec; Add is_low and is_high methods to Register; Implement FromStr for Register; Rename Sb, Sl, and Ip in Register to R9, R10, and R12; Display instruction synonyms; Document Flag. Arm64: Add module. 2024-06-15 22:20:30 +02:00
README.md Document assert_or_err; Add docs logo; Restructure tests; Bump minor; Update lints; Add new errors: IllegalFlag, IllegalShifter, InvalidOpcode, UnknownMnemonic; Update readme; Update documentation; Improve diagnostics. Arm32: Encode more instructions for Thumb; Make InstructionCodec::encode_thumb return tuple; Add new instructions: Test, TestEquivalence, UnsignedSaturate, PreloadData, BranchLinkExchange, Swap, Load, Store; Rework Flag; Add Address type; Add as_register method to Shifter; Add skip_words, skip_halfwords, and skib_bytes methods to InstructionCodec; Add from_register method to Shifter; Add Thumb decoding to InstructionCodec; Add from_u8 method to Predicate; Add from_u8 method to Register; Implement FromStr for Instruction; Add new Sflag, Bflag, and Tflag flags; Add seek_to method to InstructionCodec. 2024-06-19 19:02:13 +02:00

Pollex

Pollex is a Rust-written library for manipulating instructions of Arm ISAs.

See Docs.rs for documentation.

Support

Pollex supports encoding of instructions to both Arm and Thumb on Arm32 targets. Arm64 support is planned.

Usage

Instructions can be created directly using the Instruction type:

use pollex::arm32::{
    Instruction,
    Predicate,
    Register,
    Sflag,
    Shifter,
};

// MOVS r0, r1
let instr = Instruction::Move {
    predicate:   Predicate::Always,
    destination: Register::R0,
    source:      Shifter::from_register(Register::R1),
    s:           Sflag::On,
};

Instructions can also be parsed from strings:

use pollex::arm32::{
    Instruction,
    Predicate,
    Register,
    Sflag,
    Shifter,
};

let instr: Instruction = "CPY r0, r1".parse()?;

// Is equivalent to:

let instr = Instruction::Move {
    predicate:   Predicate::Always,
    destination: Register::R0,
    source:      Shifter::from_register(Register::R1),
    s:           Sflag::Off,
};

# Ok::<(), Box<dyn std::error::Error>>(())

But do note that the latter is currently not implemented.

Instructions can be encoded to both Arm and Thumb using the InstructionCodec type:

use pollex::arm32::{Instruction, InstructionCodec};

let instr: Instruction = "BX lr".parse()?;

let mut codec = InstructionCodec::new();

let arm_opcode   = codec.encode_arm(instr)?;
let thumb_opcode = codec.encode_thumb(instr)?;

assert_eq!(arm_opcode, 0b11100001_00101111_11111111_00011110);
assert_eq!(thumb_opcode.0, 0b01000111_01110000);
assert_eq!(thumb_opcode.1, None);

# Ok::<(), Box<dyn std::error::Error>>(())

Copyright 2024 Gabriel Bjørnager Jensen.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Trademarks

Arm and Thumb are registered trademarks or trademarks of Arm Limited (or its subsidiaries or affiliates).