mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Merge branch 'post-11' into post-12
This commit is contained in:
14
Cargo.lock
generated
14
Cargo.lock
generated
@@ -33,7 +33,7 @@ dependencies = [
|
|||||||
"spin",
|
"spin",
|
||||||
"uart_16550",
|
"uart_16550",
|
||||||
"volatile",
|
"volatile",
|
||||||
"x86_64",
|
"x86_64 0.11.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -188,7 +188,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "d44b0f30cb82b0fbc15b78ade1064226529ad52028bc8cb8accb98ff6f3d7131"
|
checksum = "d44b0f30cb82b0fbc15b78ade1064226529ad52028bc8cb8accb98ff6f3d7131"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"x86_64",
|
"x86_64 0.9.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -206,3 +206,13 @@ dependencies = [
|
|||||||
"bit_field",
|
"bit_field",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "x86_64"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "365de37eb7c6da582cbb510dd0f3f1235d24ff6309a8a96e8a9909cc9bfd608f"
|
||||||
|
dependencies = [
|
||||||
|
"bit_field",
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ harness = false
|
|||||||
bootloader = { version = "0.9.3", features = ["map_physical_memory"]}
|
bootloader = { version = "0.9.3", features = ["map_physical_memory"]}
|
||||||
volatile = "0.2.6"
|
volatile = "0.2.6"
|
||||||
spin = "0.5.2"
|
spin = "0.5.2"
|
||||||
x86_64 = "0.9.6"
|
x86_64 = "0.11.0"
|
||||||
uart_16550 = "0.2.0"
|
uart_16550 = "0.2.0"
|
||||||
pic8259_simple = "0.1.1"
|
pic8259_simple = "0.1.1"
|
||||||
pc-keyboard = "0.5.0"
|
pc-keyboard = "0.5.0"
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub fn init_heap(
|
|||||||
.allocate_frame()
|
.allocate_frame()
|
||||||
.ok_or(MapToError::FrameAllocationFailed)?;
|
.ok_or(MapToError::FrameAllocationFailed)?;
|
||||||
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
||||||
mapper.map_to(page, frame, flags, frame_allocator)?.flush();
|
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() };
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
|||||||
use x86_64::{
|
use x86_64::{
|
||||||
structures::paging::{
|
structures::paging::{
|
||||||
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB,
|
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB,
|
||||||
UnusedPhysFrame,
|
|
||||||
},
|
},
|
||||||
PhysAddr, VirtAddr,
|
PhysAddr, VirtAddr,
|
||||||
};
|
};
|
||||||
@@ -45,11 +44,12 @@ pub fn create_example_mapping(
|
|||||||
use x86_64::structures::paging::PageTableFlags as Flags;
|
use x86_64::structures::paging::PageTableFlags as Flags;
|
||||||
|
|
||||||
let frame = PhysFrame::containing_address(PhysAddr::new(0xb8000));
|
let frame = PhysFrame::containing_address(PhysAddr::new(0xb8000));
|
||||||
// FIXME: ONLY FOR TEMPORARY TESTING
|
|
||||||
let unused_frame = unsafe { UnusedPhysFrame::new(frame) };
|
|
||||||
let flags = Flags::PRESENT | Flags::WRITABLE;
|
let flags = Flags::PRESENT | Flags::WRITABLE;
|
||||||
|
|
||||||
let map_to_result = mapper.map_to(page, unused_frame, flags, frame_allocator);
|
let map_to_result = unsafe {
|
||||||
|
// FIXME: this is not safe, we do it only for testing
|
||||||
|
mapper.map_to(page, frame, flags, frame_allocator)
|
||||||
|
};
|
||||||
map_to_result.expect("map_to failed").flush();
|
map_to_result.expect("map_to failed").flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ pub fn create_example_mapping(
|
|||||||
pub struct EmptyFrameAllocator;
|
pub struct EmptyFrameAllocator;
|
||||||
|
|
||||||
unsafe impl FrameAllocator<Size4KiB> for EmptyFrameAllocator {
|
unsafe impl FrameAllocator<Size4KiB> for EmptyFrameAllocator {
|
||||||
fn allocate_frame(&mut self) -> Option<UnusedPhysFrame> {
|
fn allocate_frame(&mut self) -> Option<PhysFrame> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ impl BootInfoFrameAllocator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over the usable frames specified in the memory map.
|
/// Returns an iterator over the usable frames specified in the memory map.
|
||||||
fn usable_frames(&self) -> impl Iterator<Item = UnusedPhysFrame> {
|
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> {
|
||||||
// get usable regions from memory map
|
// get usable regions from memory map
|
||||||
let regions = self.memory_map.iter();
|
let regions = self.memory_map.iter();
|
||||||
let usable_regions = regions.filter(|r| r.region_type == MemoryRegionType::Usable);
|
let usable_regions = regions.filter(|r| r.region_type == MemoryRegionType::Usable);
|
||||||
@@ -91,14 +91,12 @@ impl BootInfoFrameAllocator {
|
|||||||
// transform to an iterator of frame start addresses
|
// transform to an iterator of frame start addresses
|
||||||
let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096));
|
let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096));
|
||||||
// create `PhysFrame` types from the start addresses
|
// create `PhysFrame` types from the start addresses
|
||||||
let frames = frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr)));
|
frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr)))
|
||||||
// we know that the frames are really unused
|
|
||||||
frames.map(|f| unsafe { UnusedPhysFrame::new(f) })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl FrameAllocator<Size4KiB> for BootInfoFrameAllocator {
|
unsafe impl FrameAllocator<Size4KiB> for BootInfoFrameAllocator {
|
||||||
fn allocate_frame(&mut self) -> Option<UnusedPhysFrame> {
|
fn allocate_frame(&mut self) -> Option<PhysFrame> {
|
||||||
let frame = self.usable_frames().nth(self.next);
|
let frame = self.usable_frames().nth(self.next);
|
||||||
self.next += 1;
|
self.next += 1;
|
||||||
frame
|
frame
|
||||||
|
|||||||
Reference in New Issue
Block a user