summaryrefslogtreecommitdiff
path: root/src/arm32/instruction_codec/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm32/instruction_codec/mod.rs')
-rw-r--r--src/arm32/instruction_codec/mod.rs31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/arm32/instruction_codec/mod.rs b/src/arm32/instruction_codec/mod.rs
index 841d335..1780c49 100644
--- a/src/arm32/instruction_codec/mod.rs
+++ b/src/arm32/instruction_codec/mod.rs
@@ -19,9 +19,7 @@
// fero General Public License along with Pollex.
// If not, see <https://www.gnu.org/licenses/>.
-#[cfg(test)]
-mod test;
-
+mod decode_thumb;
mod encode_arm;
mod encode_thumb;
@@ -29,8 +27,8 @@ use core::num::Wrapping;
/// Codec for encoding and decoding instruction.
///
-/// Arm instructions can be encoded/decoded using the [`encode_arm`](InstructionCodec::encode_arm) and `decode_arm` (soon).
-/// Thumb instruction will similarly be manipulated using [`encode_thumb`](InstructionCodec::encode_thumb) and `decode_thumb`.
+/// Arm instructions can be encoded/decoded using the [`encode_arm`](InstructionCodec::encode_arm) and (soon) `decode_arm`.
+/// Thumb instruction will similarly be manipulated using [`encode_thumb`](InstructionCodec::encode_thumb) and [`decode_thumb`](InstructionCodec::decode_thumb).
///
/// This structure keeps track of the adress at which instructions are to be placed (see *Rationale*).
/// If encoding causes this internal address to go past `0xFFFFFFFF`, the value is safely wrapped to the origin (i.e. `0x00000000`).
@@ -47,15 +45,36 @@ pub struct InstructionCodec {
}
impl InstructionCodec {
+ /// Constructs a new codec at the origin.
+ #[inline(always)]
+ #[must_use]
+ pub const fn new() -> Self { Self::new_at(0x00000000) }
+
/// Constructs a new codec with a given starting address.
#[inline(always)]
#[must_use]
pub const fn new_at(address: u32) -> Self {
Self { address: Wrapping(address) }
}
+
+ /// Sets the internal address to the provided one.
+ #[inline(always)]
+ pub fn seek_to(&mut self, address: u32) { self.address = Wrapping(address) }
+
+ /// Skips the given ammount of bytes.
+ #[inline(always)]
+ pub fn skip_bytes(&mut self, count: u32) { self.address += Wrapping(count) }
+
+ /// Skips the given ammount of halfwords.
+ #[inline(always)]
+ pub fn skip_halfwords(&mut self, count: u32) { self.address += Wrapping(count) * Wrapping(0x2) }
+
+ /// Skips the given ammount of words.
+ #[inline(always)]
+ pub fn skip_words(&mut self, count: u32) { self.address += Wrapping(count) * Wrapping(0x4) }
}
impl Default for InstructionCodec {
#[inline(always)]
- fn default() -> Self { Self::new_at(0x00000000) }
+ fn default() -> Self { Self::new() }
}