Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update x86_64 dependency to version 0.11.0 #117

Merged
merged 1 commit into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ required-features = ["binary"]

[dependencies]
xmas-elf = { version = "0.6.2", optional = true }
x86_64 = { version = "0.8.3", optional = true }
x86_64 = { version = "0.11.0", optional = true }
usize_conversions = { version = "0.2.0", optional = true }
fixedvec = { version = "0.2.4", optional = true }
bit_field = { version = "0.10.0", optional = true }
Expand Down
43 changes: 3 additions & 40 deletions example-kernel/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example-kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ authors = ["Philipp Oppermann <[email protected]>"]
edition = "2018"

[dependencies]
x86_64 = "0.3.4"
x86_64 = "0.11.0"
17 changes: 6 additions & 11 deletions src/frame_allocator.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use super::{frame_range, phys_frame_range};
use bootloader::bootinfo::{MemoryMap, MemoryRegion, MemoryRegionType};
use x86_64::structures::paging::{frame::PhysFrameRange, PhysFrame, UnusedPhysFrame};
use x86_64::structures::paging::{frame::PhysFrameRange, PhysFrame};

pub(crate) struct FrameAllocator<'a> {
pub memory_map: &'a mut MemoryMap,
}

impl<'a> FrameAllocator<'a> {
pub(crate) fn allocate_frame(
&mut self,
region_type: MemoryRegionType,
) -> Option<UnusedPhysFrame> {
pub(crate) fn allocate_frame(&mut self, region_type: MemoryRegionType) -> Option<PhysFrame> {
// try to find an existing region of same type that can be enlarged
let mut iter = self.memory_map.iter_mut().peekable();
while let Some(region) = iter.next() {
Expand All @@ -20,8 +17,7 @@ impl<'a> FrameAllocator<'a> {
&& next.region_type == MemoryRegionType::Usable
&& !next.range.is_empty()
{
let frame =
unsafe { UnusedPhysFrame::new(phys_frame_range(region.range).end) };
let frame = phys_frame_range(region.range).end;
region.range.end_frame_number += 1;
iter.next().unwrap().range.start_frame_number += 1;
return Some(frame);
Expand All @@ -30,7 +26,7 @@ impl<'a> FrameAllocator<'a> {
}
}

fn split_usable_region<'a, I>(iter: &mut I) -> Option<(UnusedPhysFrame, PhysFrameRange)>
fn split_usable_region<'a, I>(iter: &mut I) -> Option<(PhysFrame, PhysFrameRange)>
where
I: Iterator<Item = &'a mut MemoryRegion>,
{
Expand All @@ -42,10 +38,9 @@ impl<'a> FrameAllocator<'a> {
continue;
}

let physframe = phys_frame_range(region.range).start;
let unused_frame = unsafe { UnusedPhysFrame::new(physframe) };
let frame = phys_frame_range(region.range).start;
region.range.start_frame_number += 1;
return Some((unused_frame, PhysFrame::range(physframe, physframe + 1)));
return Some((frame, PhysFrame::range(frame, frame + 1)));
}
None
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use usize_conversions::usize_from;
use x86_64::instructions::tlb;
use x86_64::structures::paging::{
frame::PhysFrameRange, page_table::PageTableEntry, Mapper, Page, PageTable, PageTableFlags,
PageTableIndex, PhysFrame, RecursivePageTable, Size2MiB, Size4KiB, UnusedPhysFrame,
PageTableIndex, PhysFrame, RecursivePageTable, Size2MiB, Size4KiB,
};
use x86_64::{PhysAddr, VirtAddr};

Expand Down Expand Up @@ -309,7 +309,7 @@ fn bootloader_main(
unsafe {
page_table::map_page(
page,
UnusedPhysFrame::new(frame),
frame,
flags,
&mut rec_page_table,
&mut frame_allocator,
Expand Down
29 changes: 10 additions & 19 deletions src/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use fixedvec::FixedVec;
use x86_64::structures::paging::mapper::{MapToError, MapperFlush, UnmapError};
use x86_64::structures::paging::{
self, Mapper, Page, PageSize, PageTableFlags, PhysFrame, RecursivePageTable, Size4KiB,
UnusedPhysFrame,
};
use x86_64::{align_up, PhysAddr, VirtAddr};
use xmas_elf::program::{self, ProgramHeader64};
Expand All @@ -18,12 +17,12 @@ pub struct MemoryInfo {

#[derive(Debug)]
pub enum MapKernelError {
Mapping(MapToError),
Mapping(MapToError<Size4KiB>),
MultipleTlsSegments,
}

impl From<MapToError> for MapKernelError {
fn from(e: MapToError) -> Self {
impl From<MapToError<Size4KiB>> for MapKernelError {
fn from(e: MapToError<Size4KiB>) -> Self {
MapKernelError::Mapping(e)
}
}
Expand Down Expand Up @@ -71,7 +70,7 @@ pub(crate) fn map_segment(
kernel_start: PhysAddr,
page_table: &mut RecursivePageTable,
frame_allocator: &mut FrameAllocator,
) -> Result<Option<TlsTemplate>, MapToError> {
) -> Result<Option<TlsTemplate>, MapToError<Size4KiB>> {
let typ = segment.get_type().unwrap();
match typ {
program::Type::Load => {
Expand All @@ -97,16 +96,8 @@ pub(crate) fn map_segment(
for frame in PhysFrame::range_inclusive(start_frame, end_frame) {
let offset = frame - start_frame;
let page = start_page + offset;
unsafe {
map_page(
page,
UnusedPhysFrame::new(frame),
page_table_flags,
page_table,
frame_allocator,
)?
}
.flush();
unsafe { map_page(page, frame, page_table_flags, page_table, frame_allocator)? }
.flush();
}

if mem_size > file_size {
Expand All @@ -126,7 +117,7 @@ pub(crate) fn map_segment(
unsafe {
map_page(
temp_page.clone(),
UnusedPhysFrame::new(new_frame.clone()),
new_frame.clone(),
page_table_flags,
page_table,
frame_allocator,
Expand Down Expand Up @@ -202,19 +193,19 @@ pub(crate) fn map_segment(

pub(crate) unsafe fn map_page<'a, S>(
page: Page<S>,
phys_frame: UnusedPhysFrame<S>,
phys_frame: PhysFrame<S>,
flags: PageTableFlags,
page_table: &mut RecursivePageTable<'a>,
frame_allocator: &mut FrameAllocator,
) -> Result<MapperFlush<S>, MapToError>
) -> Result<MapperFlush<S>, MapToError<S>>
where
S: PageSize,
RecursivePageTable<'a>: Mapper<S>,
{
struct PageTableAllocator<'a, 'b: 'a>(&'a mut FrameAllocator<'b>);

unsafe impl<'a, 'b> paging::FrameAllocator<Size4KiB> for PageTableAllocator<'a, 'b> {
fn allocate_frame(&mut self) -> Option<UnusedPhysFrame<Size4KiB>> {
fn allocate_frame(&mut self) -> Option<PhysFrame<Size4KiB>> {
self.0.allocate_frame(MemoryRegionType::PageTable)
}
}
Expand Down
43 changes: 3 additions & 40 deletions test-kernel/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test-kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ authors = ["Philipp Oppermann <[email protected]>"]
edition = "2018"

[dependencies]
x86_64 = "0.3.4"
x86_64 = "0.11.0"