pollex

Crates.iopollex
lib.rspollex
version0.5.1
sourcesrc
created_at2024-06-11 18:54:08.971846
updated_at2024-07-07 14:14:49.611527
descriptionArm instruction manipulator.
homepagehttps://achernar.dk/html/pollex.html
repositoryhttps://mandelbrot.dk/pollex
max_upload_size
id1268810
size135,703
Gabriel Bjørnager Jensen (bjoernager)

documentation

https://docs.rs/pollex/

README

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 & Licensing

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).

Commit count: 0

cargo fmt