diff --git a/src/lib.rs b/src/lib.rs
index 24dd630a..55987839 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,7 +9,6 @@
#![feature(lang_items)]
#![feature(const_fn, unique)]
-#![feature(step_by)]
#![no_std]
extern crate rlibc;
diff --git a/src/memory/mod.rs b/src/memory/mod.rs
index dc80ec73..139b69fb 100644
--- a/src/memory/mod.rs
+++ b/src/memory/mod.rs
@@ -33,6 +33,32 @@ impl Frame {
fn clone(&self) -> Frame {
Frame { number: self.number }
}
+
+ fn range_inclusive(start: Frame, end: Frame) -> FrameIter {
+ FrameIter {
+ start: start,
+ end: end,
+ }
+ }
+}
+
+struct FrameIter {
+ start: Frame,
+ end: Frame,
+}
+
+impl Iterator for FrameIter {
+ type Item = Frame;
+
+ fn next(&mut self) -> Option {
+ if self.start <= self.end {
+ let frame = self.start.clone();
+ self.start.number += 1;
+ Some(frame)
+ } else {
+ None
+ }
+ }
}
pub trait FrameAllocator {
diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs
index b0a15bd7..1e12de6e 100644
--- a/src/memory/paging/mod.rs
+++ b/src/memory/paging/mod.rs
@@ -165,19 +165,17 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation)
continue;
}
+ assert!(section.addr as usize % PAGE_SIZE == 0,
+ "sections need to be page aligned");
println!("mapping section at addr: {:#x}, size: {:#x}",
section.addr,
section.size);
let flags = EntryFlags::from_elf_section_flags(section);
- let range = Range {
- start: section.addr as usize,
- end: (section.addr + section.size) as usize,
- };
- for address in range.step_by(PAGE_SIZE) {
- assert!(address % PAGE_SIZE == 0, "sections need to be page aligned");
- let frame = Frame::containing_address(address);
+ let start_frame = Frame::containing_address(section.start_address());
+ let end_frame = Frame::containing_address(section.end_address() - 1);
+ for frame in Frame::range_inclusive(start_frame, end_frame) {
mapper.identity_map(frame, flags, allocator);
}
}
@@ -187,13 +185,10 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation)
mapper.identity_map(vga_buffer_frame, WRITABLE, allocator);
// identity map the multiboot info structure
- let multiboot_start = boot_info as *const _ as usize;
- let range = Range {
- start: multiboot_start,
- end: multiboot_start + (boot_info.total_size as usize),
- };
- for address in range.step_by(PAGE_SIZE) {
- mapper.identity_map(Frame::containing_address(address), PRESENT, allocator);
+ let multiboot_start = Frame::containing_address(boot_info.start_address());
+ let multiboot_end = Frame::containing_address(boot_info.end_address() - 1);
+ for frame in Frame::range_inclusive(multiboot_start, multiboot_end) {
+ mapper.identity_map(frame, PRESENT, allocator);
}
});