//where P: Page { start: P, end: P } // pub trait MemRange { /// Returns the number of `Page`s in this ranage #[inline] fn length(&self) -> usize; /// Remove `n` pages from the beginning of this `PageRange` fn drop_front(&mut self, n: usize) -> &mut Self; /// Remove `n` pages from the end of this `PageRange` fn drop_back(&mut self, n: usize) -> &mut Self; /// Add `n` pages at the front of this `PageRange` fn add_front(&mut self, n: usize) -> &mut Self; /// Add `n` pages at the back of this `PageRange` fn add_back(&mut self, n: usize) -> &mut Self; } //pub const fn start(&self) -> P { self.start } // ///// Returns a `PageRange` between two pages //pub const fn between(start: P, end: P) -> Range
{ // Range { start: start, end: end } //} // // /// Returns an iterator over this `PageRange` // pub fn iter<'a>(&'a self) -> RangeIter<'a, P> { // RangeIter { range: self, current: self.start.clone() } // } impl
MemRange for Range
where P: Page { /// Returns the number of `Page`s in this ranage #[inline] fn length(&self) -> usize { self.end.number() - self.start.number() } /// Remove `n` pages from the beginning of this `PageRange` fn drop_front(&mut self, n: usize) -> &mut Self { assert!(n < self.length()); self.start += n; self } /// Remove `n` pages from the end of this `PageRange` fn drop_back(&mut self, n: usize) -> &mut Self { assert!(n < self.length()); self.end -= n; self } /// Add `n` pages at the front of this `PageRange` fn add_front(&mut self, n: usize) -> &mut Self { self.start -= n; self } /// Add `n` pages at the back of this `PageRange` fn add_back(&mut self, n: usize) -> &mut Self { self.end += n; self } } /// An iterator over a range of pages pub struct RangeIter<'a, P> where P: Page , P: 'a { range: &'a Range
, current: P } impl<'a, P> Iterator for RangeIter<'a, P> where P: Page , P: Clone { type Item = P; fn next(&mut self) -> Option
{
let end = self.range.end;
assert!(self.range.start <= end);
if self.current < end {
let page = self.current.clone();
self.current += 1;
Some(page)
} else {
None
}
}
}
================================================
FILE: memory/src/macros.rs
================================================
//
// SOS: the Stupid Operating System
// by Eliza Weisman (eliza@elizas.website)
//
// Copyright (c) 2015-2017 Eliza Weisman
// Released under the terms of the MIT license. See `LICENSE` in the root
// directory of this repository for more information.
//
//! Macros to make our custom address types require a lot less repetitive code.
#[macro_export]
macro_rules! Addr {
(($size:ty, $letter:expr) $(pub)* enum $name:ident $($tail:tt)*) => {
Addr! { @impl $name, $size, $letter }
};
(($size:ty, $letter:expr) $(pub)* struct $name:ident $($tail:tt)*) => {
Addr! { @impl $name, $size, $letter }
};
(@impl $ty:ident, $size:ty, $letter:expr) => {
impl ::core::fmt::Debug for $ty {
fn fmt(&self, f: &mut ::core::fmt::Formatter)
-> ::core::fmt::Result {
write!(f, "{}x{:x}", $letter, self.0)
}
}
impl ::core::fmt::Pointer for $ty {
#[inline] fn fmt(&self, f: &mut ::core::fmt::Formatter)
-> ::core::fmt::Result {
write!(f, "{:?}", self)
}
}
impl ::core::convert::Into<$size> for $ty {
#[inline] fn into(self) -> $size { self.0 }
}
impl ::core::convert::From<$size> for $ty {
#[inline] fn from(n: $size) -> Self { $ty(n) }
}
impl" ]
[profile.dev]
opt-level = 3
debug = true
rpath = false
lto = false
debug-assertions = true
codegen-units = 1
panic = "abort"
[profile.release]
opt-level = 3
debug = true
rpath = false
lto = false
panic = "abort"
[dependencies]
util = { path = "../util" }
memory = { path = "../memory" }
sos_alloc = { path = "../sos_alloc" }
elf = { path = "../elf" }
cpu = { path = "../cpu" }
params = { path = "../params" }
bitflags = "0.7"
spin = "0.4.6"
[dependencies.vga]
path = "../vga"
features = ["kinfo"]
[dependencies.lazy_static]
version = "0.2.11"
features = ["spin_no_std"]
[dependencies.macro-attr]
git = "https://github.com/DanielKeep/rust-custom-derive.git"
version = "0.2.1"
default-features = false
# [dependencies.newtype_derive]
# version = "0.1.6"
# default-features = false
[dependencies.log]
version = "0.3.6"
default-features = false
features = ["release_max_level_info"]
================================================
FILE: paging/src/arch/mod.rs
================================================
//
// SOS: the Stupid Operating System
// by Eliza Weisman (hi@hawkweisman.me)
//
// Copyright (c) 2015-2016 Eliza Weisman
// Released under the terms of the MIT license. See `LICENSE` in the root
// directory of this repository for more information.
//
// 64-bit x86_64 (long mode)
#[cfg(target_arch="x86_64")] mod x86_64;
#[cfg(target_arch="x86_64")] pub use self::x86_64::*;
// 32-bit x86 (protected mode)
// TODO: NYI
#[cfg(target_arch = "x86")] mod x86;
#[cfg(target_arch = "x86")] pub use self::x86::*;
================================================
FILE: paging/src/arch/x86_64/cr3.rs
================================================
use super::table::{Table, PML4Level};
use cpu::control_regs::cr3::{read, write};
pub use cpu::control_regs::cr3::*;
/// Returns the current Page Meta-Level 4 table
///
/// # Safety
/// + Reading from control registers while not in kernel mode will cause
/// a general protection fault.
/// + Returns a `*mut` pointer with an arbitrary lifetime.
#[cfg(target_arch = "x86_64")]
#[inline]
pub unsafe fn current_pml4() -> *mut Table {
read().as_mut_ptr::