Fix code snippets and improve their formatting

This commit is contained in:
Philipp Oppermann
2019-01-28 11:31:45 +01:00
parent 7744acd69c
commit cc36ae536b

View File

@@ -558,7 +558,7 @@ To make sure that the entry point function has always the correct signature that
```rust ```rust
// in src/main.rs // in src/main.rs
use bootloader::entry_point; use bootloader::{bootinfo::BootInfo, entry_point};
entry_point!(kernel_main); entry_point!(kernel_main);
@@ -566,7 +566,7 @@ entry_point!(kernel_main);
fn kernel_main(boot_info: &'static BootInfo) -> ! { fn kernel_main(boot_info: &'static BootInfo) -> ! {
[] // initialize GDT, IDT, PICS [] // initialize GDT, IDT, PICS
let mut recursive_page_table = unsafe{ let mut recursive_page_table = unsafe {
memory::init(boot_info.p4_table_addr as usize) memory::init(boot_info.p4_table_addr as usize)
}; };
@@ -595,7 +595,7 @@ pub struct BootInfoFrameAllocator<I> where I: Iterator<Item = PhysFrame> {
impl<I> FrameAllocator<Size4KiB> for BootInfoFrameAllocator<I> impl<I> FrameAllocator<Size4KiB> for BootInfoFrameAllocator<I>
where I: Iterator<Item = PhysFrame> where I: Iterator<Item = PhysFrame>
{ {
fn alloc(&mut self) -> Option<PhysFrame> { fn allocate_frame(&mut self) -> Option<PhysFrame> {
self.frames.next() self.frames.next()
} }
} }
@@ -614,13 +614,13 @@ The initialization of the `BootInfoFrameAllocator` happens in a new `init_frame_
use bootloader::bootinfo::{MemoryMap, MemoryRegionType}; use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
/// Create a FrameAllocator from the passed memory map /// Create a FrameAllocator from the passed memory map
pub fn init_frame_allocator(memory_map: &'static MemoryMap) pub fn init_frame_allocator(
-> BootInfoFrameAllocator<impl Iterator<Item = PhysFrame>> memory_map: &'static MemoryMap,
{ ) -> BootInfoFrameAllocator<impl Iterator<Item = PhysFrame>> {
// get usable regions from memory map // get usable regions from memory map
let regions = memory_map.iter().filter(|r| { let regions = memory_map
r.region_type == MemoryRegionType::Usable .iter()
}); .filter(|r| r.region_type == MemoryRegionType::Usable);
// map each region to its address range // map each region to its address range
let addr_ranges = regions.map(|r| r.range.start_addr()..r.range.end_addr()); let addr_ranges = regions.map(|r| r.range.start_addr()..r.range.end_addr());
// transform to an iterator of frame start addresses // transform to an iterator of frame start addresses