summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md11
-rw-r--r--Cargo.toml2
-rw-r--r--src/arch/mod.rs28
-rw-r--r--src/arm32/address/mod.rs88
-rw-r--r--src/arm32/condition/mod.rs68
-rw-r--r--src/arm32/instruction/display.rs40
-rw-r--r--src/arm32/instruction/mod.rs (renamed from src/register/display.rs)17
-rw-r--r--src/arm32/instruction/test.rs39
-rw-r--r--src/arm32/mod.rs (renamed from src/register/mod.rs)10
-rw-r--r--src/arm32/register/mod.rs (renamed from src/instruction/mod.rs)32
-rw-r--r--src/lib.rs7
11 files changed, 309 insertions, 33 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dbdf5f0..d7135ca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,17 @@
This is the changelog of Pollex.
See `"README.md"` for more information.
+## 0.1.0
+
+* Bump minor
+* Add `arm32` module
+* Add `arm32::Address` type
+* Add `arm32::Condition` type
+* Add new ARM32 instructions: `BranchLink`
+* Add tests
+* Use `alloc`
+* Add `Arch` type
+
## 0.0.0
* Fork from Luma and eAS
diff --git a/Cargo.toml b/Cargo.toml
index d9341e5..3ddac61 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pollex"
-version = "0.0.0"
+version = "0.1.0"
authors = ["Gabriel Bjørnager Jensen"]
edition = "2021"
description = "Arms and thumbs."
diff --git a/src/arch/mod.rs b/src/arch/mod.rs
new file mode 100644
index 0000000..2df0176
--- /dev/null
+++ b/src/arch/mod.rs
@@ -0,0 +1,28 @@
+// Copyright 2021-2024 Gabriel Bjørnager Jensen.
+//
+// This file is part of Pollex.
+//
+// Pollex is free software: you can redistribute it
+// and/or modify it under the terms of the GNU Af-
+// fero General Public License as published by the
+// Free Software Foundation, either version 3 of
+// the License, or (at your option) any later ver-
+// sion.
+//
+// Pollex 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 Af-
+// fero General Public License along with Pollex.
+// If not, see <https://www.gnu.org/licenses/>.
+
+
+#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
+#[repr(u8)]
+pub enum Arch {
+ Arm32 = 0x00,
+ Arm64 = 0x01,
+}
diff --git a/src/arm32/address/mod.rs b/src/arm32/address/mod.rs
new file mode 100644
index 0000000..fa3488c
--- /dev/null
+++ b/src/arm32/address/mod.rs
@@ -0,0 +1,88 @@
+// Copyright 2021-2024 Gabriel Bjørnager Jensen.
+//
+// This file is part of Pollex.
+//
+// Pollex is free software: you can redistribute it
+// and/or modify it under the terms of the GNU Af-
+// fero General Public License as published by the
+// Free Software Foundation, either version 3 of
+// the License, or (at your option) any later ver-
+// sion.
+//
+// Pollex 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 Af-
+// fero General Public License along with Pollex.
+// If not, see <https://www.gnu.org/licenses/>.
+
+use crate::arm32::Register;
+
+use core::fmt::Display;
+
+pub enum Address {
+ ArithmeticShiftRightImmediate { source: Register, shift: u32 },
+
+ ArithmeticShiftRightRegister { source: Register, shift: Register },
+
+ Immediage { immediate: u32 },
+
+ LogicalShiftLeftImmediate { source: Register, shift: u32 },
+
+ LogicalShiftLeftRegister { source: Register, shift: Register },
+
+ LogicalShiftRightImmediate { source: Register, shift: u32 },
+
+ LogicalShiftRightRegister { source: Register, shift: Register },
+
+ RotateRightExtend { source: Register },
+
+ RotateRightRegister { source: Register, shift: Register },
+}
+
+impl Display for Address {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
+ use Address::*;
+
+ match *self {
+ ArithmeticShiftRightImmediate { source, shift } => {
+ write!(f, "{source}, ASR #{shift}")
+ },
+
+ ArithmeticShiftRightRegister { source, shift } => {
+ write!(f, "{source}, ASR {shift}")
+ },
+
+ Immediage { immediate } => {
+ write!(f, "#{immediate}<")
+ },
+
+ LogicalShiftLeftImmediate { source, shift } => {
+ write!(f, "{source}, LSL #{shift}")
+ },
+
+ LogicalShiftLeftRegister { source, shift } => {
+ write!(f, "{source}, LSL {shift}")
+ },
+
+ LogicalShiftRightImmediate { source, shift } => {
+ write!(f, "{source}, LSR #{shift}")
+ },
+
+ LogicalShiftRightRegister { source, shift } => {
+ write!(f, "{source}, LSR {shift}")
+ },
+
+ RotateRightExtend { source } => {
+ write!(f, "{source}, RRX")
+ },
+
+ RotateRightRegister { source, shift } => {
+ write!(f, "{source}, ROR {shift}")
+ },
+ }
+ }
+}
diff --git a/src/arm32/condition/mod.rs b/src/arm32/condition/mod.rs
new file mode 100644
index 0000000..5d595f9
--- /dev/null
+++ b/src/arm32/condition/mod.rs
@@ -0,0 +1,68 @@
+// Copyright 2021-2024 Gabriel Bjørnager Jensen.
+//
+// This file is part of Pollex.
+//
+// Pollex is free software: you can redistribute it
+// and/or modify it under the terms of the GNU Af-
+// fero General Public License as published by the
+// Free Software Foundation, either version 3 of
+// the License, or (at your option) any later ver-
+// sion.
+//
+// Pollex 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 Af-
+// fero General Public License along with Pollex.
+// If not, see <https://www.gnu.org/licenses/>.
+
+use core::fmt::Display;
+
+#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
+#[repr(u8)]
+pub enum Condition {
+ Equal = 0b0000,
+ NotEqual = 0b0001,
+ HigherOrSame = 0b0010,
+ Lower = 0b0011,
+ Minus = 0b0100,
+ Plus = 0b0101,
+ Overflow = 0b0110,
+ NoOverflow = 0b0111,
+ Higher = 0b1000,
+ LowerOrSame = 0b1001,
+ GreaterThanOrEqual = 0b1010,
+ LessThan = 0b1011,
+ GreaterThan = 0b1100,
+ LessThanOrEqual = 0b1101,
+ Always = 0b1110,
+ //Never = 0b1111,
+}
+
+impl Display for Condition {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
+ use Condition::*;
+
+ match *self {
+ Equal => write!(f, "EQ"),
+ NotEqual => write!(f, "NE"),
+ HigherOrSame => write!(f, "HS"),
+ Lower => write!(f, "LO"),
+ Minus => write!(f, "MI"),
+ Plus => write!(f, "PL"),
+ Overflow => write!(f, "VS"),
+ NoOverflow => write!(f, "VC"),
+ Higher => write!(f, "HI"),
+ LowerOrSame => write!(f, "LS"),
+ GreaterThanOrEqual => write!(f, "GE"),
+ LessThan => write!(f, "LT"),
+ GreaterThan => write!(f, "GT"),
+ LessThanOrEqual => write!(f, "LE"),
+ Always => write!(f, "AL"),
+ //Never => write!(f, "NV"),
+ }
+ }
+}
diff --git a/src/arm32/instruction/display.rs b/src/arm32/instruction/display.rs
new file mode 100644
index 0000000..d3e359a
--- /dev/null
+++ b/src/arm32/instruction/display.rs
@@ -0,0 +1,40 @@
+// Copyright 2021-2024 Gabriel Bjørnager Jensen.
+//
+// This file is part of Pollex.
+//
+// Pollex is free software: you can redistribute it
+// and/or modify it under the terms of the GNU Af-
+// fero General Public License as published by the
+// Free Software Foundation, either version 3 of
+// the License, or (at your option) any later ver-
+// sion.
+//
+// Pollex 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 Af-
+// fero General Public License along with Pollex.
+// If not, see <https://www.gnu.org/licenses/>.
+
+use crate::arm32::Instruction;
+
+use core::fmt::Display;
+
+impl Display for Instruction {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
+ use Instruction::*;
+
+ match *self {
+ Branch { condition, immediate } => {
+ write!(f, "B{condition} <#{immediate}>")
+ },
+
+ BranchLink { condition, immediate } => {
+ write!(f, "BL{condition} <#{immediate}>")
+ },
+ }
+ }
+}
diff --git a/src/register/display.rs b/src/arm32/instruction/mod.rs
index 5a5b027..d10aa6d 100644
--- a/src/register/display.rs
+++ b/src/arm32/instruction/mod.rs
@@ -19,16 +19,15 @@
// fero General Public License along with Pollex.
// If not, see <https://www.gnu.org/licenses/>.
-use crate::Instruction;
+#[cfg(test)]
+mod test;
-use core::fmt::Display;
+mod display;
-impl Display for Instruction {
- fn fmt(&self, _f: &mut core::fmt::Formatter) -> core::fmt::Result {
- use Instruction::*;
+use crate::arm32::Condition;
- match *self {
- Branch => todo!(),
- }
- }
+pub enum Instruction {
+ Branch { condition: Condition, immediate: i32 },
+
+ BranchLink { condition: Condition, immediate: i32 },
}
diff --git a/src/arm32/instruction/test.rs b/src/arm32/instruction/test.rs
new file mode 100644
index 0000000..5c8d523
--- /dev/null
+++ b/src/arm32/instruction/test.rs
@@ -0,0 +1,39 @@
+// Copyright 2021-2024 Gabriel Bjørnager Jensen.
+//
+// This file is part of Pollex.
+//
+// Pollex is free software: you can redistribute it
+// and/or modify it under the terms of the GNU Af-
+// fero General Public License as published by the
+// Free Software Foundation, either version 3 of
+// the License, or (at your option) any later ver-
+// sion.
+//
+// Pollex 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 Af-
+// fero General Public License along with Pollex.
+// If not, see <https://www.gnu.org/licenses/>.
+
+use crate::arm32::{Condition, Instruction};
+
+use alloc::format;
+
+#[test]
+fn test_arm32_instruction() {
+ let assert_display = |instruction: Instruction, display: &str| {
+ assert_eq!(format!("{instruction}"), display);
+ };
+
+ assert_display(
+ Instruction::BranchLink {
+ condition: Condition::HigherOrSame,
+ immediate: 0xF,
+ },
+ "BLHS <#15>",
+ );
+}
diff --git a/src/register/mod.rs b/src/arm32/mod.rs
index 3262c3b..6727a9c 100644
--- a/src/register/mod.rs
+++ b/src/arm32/mod.rs
@@ -19,8 +19,8 @@
// fero General Public License along with Pollex.
// If not, see <https://www.gnu.org/licenses/>.
-mod display;
-
-pub enum Instruction {
- Branch,
-}
+use crate::use_mod;
+use_mod!(pub address);
+use_mod!(pub condition);
+use_mod!(pub instruction);
+use_mod!(pub register);
diff --git a/src/instruction/mod.rs b/src/arm32/register/mod.rs
index e9aac26..bd8ba0d 100644
--- a/src/instruction/mod.rs
+++ b/src/arm32/register/mod.rs
@@ -24,22 +24,22 @@ use core::fmt::Display;
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[repr(u8)]
pub enum Register {
- R0 = 0x00,
- R1 = 0x01,
- R2 = 0x02,
- R3 = 0x03,
- R4 = 0x04,
- R5 = 0x05,
- R6 = 0x06,
- R7 = 0x07,
- R8 = 0x08,
- Sb = 0x09, // R9
- Sl = 0x0A, // R10
- R11 = 0x0B,
- Ip = 0x0C, // R12
- Sp = 0x0D, // R13
- Lr = 0x0E, // R14
- Pc = 0x0F, // R15
+ R0 = 0b0000,
+ R1 = 0b0001,
+ R2 = 0b0010,
+ R3 = 0b0011,
+ R4 = 0b0100,
+ R5 = 0b0101,
+ R6 = 0b0110,
+ R7 = 0b0111,
+ R8 = 0b1000,
+ Sb = 0b1001, // R9
+ Sl = 0b1010, // R10
+ R11 = 0b1011,
+ Ip = 0b1100, // R12
+ Sp = 0b1101, // R13
+ Lr = 0b1110, // R14
+ Pc = 0b1111, // R15
}
impl Display for Register {
diff --git a/src/lib.rs b/src/lib.rs
index 7a1af36..d925125 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -21,6 +21,10 @@
#![no_std]
+extern crate alloc;
+
+pub mod arm32;
+
macro_rules! use_mod {
($vis:vis $name:ident) => {
mod $name;
@@ -29,5 +33,4 @@ macro_rules! use_mod {
}
pub(in crate) use use_mod;
-use_mod!(pub instruction);
-use_mod!(pub register);
+use_mod!(arch);