Skip to content

Update CI badge, use latest version of x86_64 crate and rustfmt #63

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

Merged
merged 2 commits into from
Jul 9, 2019
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
63 changes: 52 additions & 11 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build = "build.rs"

[dependencies]
xmas-elf = "0.6.2"
x86_64 = "0.3.5"
x86_64 = "0.7.2"
usize_conversions = "0.2.0"
fixedvec = "0.2.3"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bootloader

[![Build Status](https://travis-ci.org/rust-osdev/bootloader.svg?branch=master)](https://travis-ci.org/rust-osdev/bootloader) [![Join the chat at https://gitter.im/rust-osdev/bootloader](https://badges.gitter.im/rust-osdev/bootloader.svg)](https://gitter.im/rust-osdev/bootloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://dev.azure.com/rust-osdev/bootloader/_apis/build/status/rust-osdev.bootloader?branchName=master)](https://dev.azure.com/rust-osdev/bootloader/_build/latest?definitionId=1&branchName=master) [![Join the chat at https://gitter.im/rust-osdev/bootloader](https://badges.gitter.im/rust-osdev/bootloader.svg)](https://gitter.im/rust-osdev/bootloader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

An experimental x86 bootloader written in Rust and inline assembly.

Expand Down
2 changes: 1 addition & 1 deletion src/frame_allocator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{frame_range, phys_frame_range};
use bootloader::bootinfo::{MemoryMap, MemoryRegion, MemoryRegionType};
use x86_64::structures::paging::{PhysFrame, PhysFrameRange};
use x86_64::structures::paging::{frame::PhysFrameRange, PhysFrame};

pub(crate) struct FrameAllocator<'a> {
pub memory_map: &'a mut MemoryMap,
Expand Down
36 changes: 20 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use core::panic::PanicInfo;
use core::{mem, slice};
use fixedvec::alloc_stack;
use usize_conversions::usize_from;
use x86_64::structures::paging::{Mapper, RecursivePageTable};
use x86_64::structures::paging::{
Page, PageTableFlags, PhysFrame, PhysFrameRange, Size2MiB, Size4KiB,
frame::PhysFrameRange, Mapper, Page, PageTableFlags, PhysFrame, RecursivePageTable, Size2MiB,
Size4KiB,
};
use x86_64::ux::u9;
use x86_64::{PhysAddr, VirtAddr};
Expand Down Expand Up @@ -227,13 +227,15 @@ fn load_elf(
.allocate_frame(MemoryRegionType::BootInfo)
.expect("frame allocation failed");
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
page_table::map_page(
page,
frame,
flags,
&mut rec_page_table,
&mut frame_allocator,
)
unsafe {
page_table::map_page(
page,
frame,
flags,
&mut rec_page_table,
&mut frame_allocator,
)
}
.expect("Mapping of bootinfo page failed")
.flush();
page
Expand All @@ -249,13 +251,15 @@ fn load_elf(
for frame in PhysFrame::range_inclusive(start_frame, end_frame) {
let page = Page::containing_address(virt_for_phys(frame.start_address()));
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
page_table::map_page(
page,
frame,
flags,
&mut rec_page_table,
&mut frame_allocator,
)
unsafe {
page_table::map_page(
page,
frame,
flags,
&mut rec_page_table,
&mut frame_allocator,
)
}
.expect("Mapping of bootinfo page failed")
.flush();
}
Expand Down
52 changes: 30 additions & 22 deletions src/page_table.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::frame_allocator::FrameAllocator;
use bootloader::bootinfo::MemoryRegionType;
use fixedvec::FixedVec;
use x86_64::structures::paging::{self, MapToError, RecursivePageTable, UnmapError};
use x86_64::structures::paging::mapper::{MapToError, MapperFlush, UnmapError};
use x86_64::structures::paging::{
Mapper, MapperFlush, Page, PageSize, PageTableFlags, PhysFrame, Size4KiB,
self, Mapper, Page, PageSize, PageTableFlags, PhysFrame, RecursivePageTable, Size4KiB,
};
use x86_64::{align_up, PhysAddr, VirtAddr};
use xmas_elf::program::{self, ProgramHeader64};
Expand Down Expand Up @@ -31,7 +31,7 @@ pub(crate) fn map_kernel(
let frame = frame_allocator
.allocate_frame(region_type)
.ok_or(MapToError::FrameAllocationFailed)?;
map_page(page, frame, flags, page_table, frame_allocator)?.flush();
unsafe { map_page(page, frame, flags, page_table, frame_allocator)? }.flush();
}

Ok(stack_end.start_address())
Expand Down Expand Up @@ -68,7 +68,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;
map_page(page, 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 @@ -85,13 +86,15 @@ pub(crate) fn map_segment(
let new_frame = frame_allocator
.allocate_frame(MemoryRegionType::Kernel)
.ok_or(MapToError::FrameAllocationFailed)?;
map_page(
temp_page.clone(),
new_frame.clone(),
page_table_flags,
page_table,
frame_allocator,
)?
unsafe {
map_page(
temp_page.clone(),
new_frame.clone(),
page_table_flags,
page_table,
frame_allocator,
)?
}
.flush();

type PageArray = [u64; Size4KiB::SIZE as usize / 8];
Expand All @@ -114,13 +117,15 @@ pub(crate) fn map_segment(
});
}

map_page(
last_page,
new_frame,
page_table_flags,
page_table,
frame_allocator,
)?
unsafe {
map_page(
last_page,
new_frame,
page_table_flags,
page_table,
frame_allocator,
)?
}
.flush();
}

Expand All @@ -134,7 +139,10 @@ pub(crate) fn map_segment(
let frame = frame_allocator
.allocate_frame(MemoryRegionType::Kernel)
.ok_or(MapToError::FrameAllocationFailed)?;
map_page(page, frame, page_table_flags, page_table, frame_allocator)?.flush();
unsafe {
map_page(page, frame, page_table_flags, page_table, frame_allocator)?
}
.flush();
}

// zero
Expand All @@ -149,7 +157,7 @@ pub(crate) fn map_segment(
Ok(())
}

pub(crate) fn map_page<'a, S>(
pub(crate) unsafe fn map_page<'a, S>(
page: Page<S>,
phys_frame: PhysFrame<S>,
flags: PageTableFlags,
Expand All @@ -162,8 +170,8 @@ where
{
struct PageTableAllocator<'a, 'b: 'a>(&'a mut FrameAllocator<'b>);

impl<'a, 'b> paging::FrameAllocator<Size4KiB> for PageTableAllocator<'a, 'b> {
fn alloc(&mut self) -> Option<PhysFrame<Size4KiB>> {
unsafe impl<'a, 'b> paging::FrameAllocator<Size4KiB> for PageTableAllocator<'a, 'b> {
fn allocate_frame(&mut self) -> Option<PhysFrame<Size4KiB>> {
self.0.allocate_frame(MemoryRegionType::PageTable)
}
}
Expand Down