diff options
Diffstat (limited to 'src/arm32')
-rw-r--r-- | src/arm32/address/mod.rs | 88 | ||||
-rw-r--r-- | src/arm32/condition/mod.rs | 68 | ||||
-rw-r--r-- | src/arm32/instruction/display.rs | 40 | ||||
-rw-r--r-- | src/arm32/instruction/mod.rs | 33 | ||||
-rw-r--r-- | src/arm32/instruction/test.rs | 39 | ||||
-rw-r--r-- | src/arm32/mod.rs | 26 | ||||
-rw-r--r-- | src/arm32/register/mod.rs | 68 |
7 files changed, 362 insertions, 0 deletions
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/arm32/instruction/mod.rs b/src/arm32/instruction/mod.rs new file mode 100644 index 0000000..d10aa6d --- /dev/null +++ b/src/arm32/instruction/mod.rs @@ -0,0 +1,33 @@ +// 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/>. + +#[cfg(test)] +mod test; + +mod display; + +use crate::arm32::Condition; + +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/arm32/mod.rs b/src/arm32/mod.rs new file mode 100644 index 0000000..6727a9c --- /dev/null +++ b/src/arm32/mod.rs @@ -0,0 +1,26 @@ +// 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::use_mod; +use_mod!(pub address); +use_mod!(pub condition); +use_mod!(pub instruction); +use_mod!(pub register); diff --git a/src/arm32/register/mod.rs b/src/arm32/register/mod.rs new file mode 100644 index 0000000..bd8ba0d --- /dev/null +++ b/src/arm32/register/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, Debug, Eq, Ord, PartialEq, PartialOrd)] +#[repr(u8)] +pub enum Register { + 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 { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + use Register::*; + + match *self { + R0 => write!(f, "r0"), + R1 => write!(f, "r1"), + R2 => write!(f, "r2"), + R3 => write!(f, "r3"), + R4 => write!(f, "r4"), + R5 => write!(f, "r5"), + R6 => write!(f, "r6"), + R7 => write!(f, "r7"), + R8 => write!(f, "r8"), + Sb => write!(f, "sb"), + Sl => write!(f, "sl"), + R11 => write!(f, "r11"), + Ip => write!(f, "ip"), + Sp => write!(f, "sp"), + Lr => write!(f, "lr"), + Pc => write!(f, "pc"), + } + } +} |