Replace buggy range.step_by with a Frame::range_inclusive function

This commit is contained in:
Philipp Oppermann
2016-03-06 12:39:15 +01:00
parent 23df363136
commit 03ed3ce9a0
3 changed files with 35 additions and 15 deletions

View File

@@ -9,7 +9,6 @@
#![feature(lang_items)] #![feature(lang_items)]
#![feature(const_fn, unique)] #![feature(const_fn, unique)]
#![feature(step_by)]
#![no_std] #![no_std]
extern crate rlibc; extern crate rlibc;

View File

@@ -33,6 +33,32 @@ impl Frame {
fn clone(&self) -> Frame { fn clone(&self) -> Frame {
Frame { number: self.number } 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<Frame> {
if self.start <= self.end {
let frame = self.start.clone();
self.start.number += 1;
Some(frame)
} else {
None
}
}
} }
pub trait FrameAllocator { pub trait FrameAllocator {

View File

@@ -165,19 +165,17 @@ pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
continue; continue;
} }
assert!(section.addr as usize % PAGE_SIZE == 0,
"sections need to be page aligned");
println!("mapping section at addr: {:#x}, size: {:#x}", println!("mapping section at addr: {:#x}, size: {:#x}",
section.addr, section.addr,
section.size); section.size);
let flags = EntryFlags::from_elf_section_flags(section); let flags = EntryFlags::from_elf_section_flags(section);
let range = Range { let start_frame = Frame::containing_address(section.start_address());
start: section.addr as usize, let end_frame = Frame::containing_address(section.end_address() - 1);
end: (section.addr + section.size) as usize, for frame in Frame::range_inclusive(start_frame, end_frame) {
};
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);
mapper.identity_map(frame, flags, allocator); mapper.identity_map(frame, flags, allocator);
} }
} }
@@ -187,13 +185,10 @@ pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
mapper.identity_map(vga_buffer_frame, WRITABLE, allocator); mapper.identity_map(vga_buffer_frame, WRITABLE, allocator);
// identity map the multiboot info structure // identity map the multiboot info structure
let multiboot_start = boot_info as *const _ as usize; let multiboot_start = Frame::containing_address(boot_info.start_address());
let range = Range { let multiboot_end = Frame::containing_address(boot_info.end_address() - 1);
start: multiboot_start, for frame in Frame::range_inclusive(multiboot_start, multiboot_end) {
end: multiboot_start + (boot_info.total_size as usize), mapper.identity_map(frame, PRESENT, allocator);
};
for address in range.step_by(PAGE_SIZE) {
mapper.identity_map(Frame::containing_address(address), PRESENT, allocator);
} }
}); });