From 3967c0f291ce0f360658fa9a3fe36f3992500550 Mon Sep 17 00:00:00 2001 From: ticki Date: Sun, 14 Aug 2016 19:21:21 +0200 Subject: [PATCH] Strongly typed virtual/physical memory seperation. This minicommit introduces two newtpyes, `Physical` and `Virtual`, respectively. These serves as a way to segregate the different forms of addresses to avoid the issues we had in the old kernel. --- kernel/arch/x86_64/mod.rs | 2 ++ kernel/arch/x86_64/physical.rs | 11 +++++++++++ kernel/paging/mod.rs | 6 ++++++ 3 files changed, 19 insertions(+) create mode 100644 kernel/arch/x86_64/physical.rs create mode 100644 kernel/paging/mod.rs diff --git a/kernel/arch/x86_64/mod.rs b/kernel/arch/x86_64/mod.rs index f9239d2..d5180fc 100644 --- a/kernel/arch/x86_64/mod.rs +++ b/kernel/arch/x86_64/mod.rs @@ -23,3 +23,5 @@ pub mod serial; /// Task state segment. pub mod tss; + +pub mod physical; diff --git a/kernel/arch/x86_64/physical.rs b/kernel/arch/x86_64/physical.rs new file mode 100644 index 0000000..8885cd1 --- /dev/null +++ b/kernel/arch/x86_64/physical.rs @@ -0,0 +1,11 @@ +//! Typestrong address segregation. + +/// A physical address in memory. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Physical { + /// The position. + /// + /// Note that we do not use a pointer here to avoid simple mistakes where the programmer + /// confuse virtual and physical. + pub inner: u64, +} diff --git a/kernel/paging/mod.rs b/kernel/paging/mod.rs new file mode 100644 index 0000000..f017962 --- /dev/null +++ b/kernel/paging/mod.rs @@ -0,0 +1,6 @@ +/// A newtype representing a virtual address. +#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] +pub struct Virtual { + /// The inner value. + pub inner: usize, +}