Skip to content

Commit 3e62d38

Browse files
bors[bot]64
andcommitted
Merge #63
63: Update CI badge, use latest version of x86_64 crate and rustfmt r=phil-opp a=64 Check the diff of the first commit because the second commit is the rustfmt run. Co-authored-by: Matt Taylor <[email protected]>
2 parents b2e6eff + 701b53a commit 3e62d38

File tree

6 files changed

+105
-52
lines changed

6 files changed

+105
-52
lines changed

Cargo.lock

+52-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build = "build.rs"
1010

1111
[dependencies]
1212
xmas-elf = "0.6.2"
13-
x86_64 = "0.3.5"
13+
x86_64 = "0.7.2"
1414
usize_conversions = "0.2.0"
1515
fixedvec = "0.2.3"
1616

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# bootloader
22

3-
[![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)
3+
[![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)
44

55
An experimental x86 bootloader written in Rust and inline assembly.
66

src/frame_allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{frame_range, phys_frame_range};
22
use bootloader::bootinfo::{MemoryMap, MemoryRegion, MemoryRegionType};
3-
use x86_64::structures::paging::{PhysFrame, PhysFrameRange};
3+
use x86_64::structures::paging::{frame::PhysFrameRange, PhysFrame};
44

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

src/main.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use core::panic::PanicInfo;
1515
use core::{mem, slice};
1616
use fixedvec::alloc_stack;
1717
use usize_conversions::usize_from;
18-
use x86_64::structures::paging::{Mapper, RecursivePageTable};
1918
use x86_64::structures::paging::{
20-
Page, PageTableFlags, PhysFrame, PhysFrameRange, Size2MiB, Size4KiB,
19+
frame::PhysFrameRange, Mapper, Page, PageTableFlags, PhysFrame, RecursivePageTable, Size2MiB,
20+
Size4KiB,
2121
};
2222
use x86_64::ux::u9;
2323
use x86_64::{PhysAddr, VirtAddr};
@@ -227,13 +227,15 @@ fn load_elf(
227227
.allocate_frame(MemoryRegionType::BootInfo)
228228
.expect("frame allocation failed");
229229
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
230-
page_table::map_page(
231-
page,
232-
frame,
233-
flags,
234-
&mut rec_page_table,
235-
&mut frame_allocator,
236-
)
230+
unsafe {
231+
page_table::map_page(
232+
page,
233+
frame,
234+
flags,
235+
&mut rec_page_table,
236+
&mut frame_allocator,
237+
)
238+
}
237239
.expect("Mapping of bootinfo page failed")
238240
.flush();
239241
page
@@ -249,13 +251,15 @@ fn load_elf(
249251
for frame in PhysFrame::range_inclusive(start_frame, end_frame) {
250252
let page = Page::containing_address(virt_for_phys(frame.start_address()));
251253
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
252-
page_table::map_page(
253-
page,
254-
frame,
255-
flags,
256-
&mut rec_page_table,
257-
&mut frame_allocator,
258-
)
254+
unsafe {
255+
page_table::map_page(
256+
page,
257+
frame,
258+
flags,
259+
&mut rec_page_table,
260+
&mut frame_allocator,
261+
)
262+
}
259263
.expect("Mapping of bootinfo page failed")
260264
.flush();
261265
}

src/page_table.rs

+30-22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::frame_allocator::FrameAllocator;
22
use bootloader::bootinfo::MemoryRegionType;
33
use fixedvec::FixedVec;
4-
use x86_64::structures::paging::{self, MapToError, RecursivePageTable, UnmapError};
4+
use x86_64::structures::paging::mapper::{MapToError, MapperFlush, UnmapError};
55
use x86_64::structures::paging::{
6-
Mapper, MapperFlush, Page, PageSize, PageTableFlags, PhysFrame, Size4KiB,
6+
self, Mapper, Page, PageSize, PageTableFlags, PhysFrame, RecursivePageTable, Size4KiB,
77
};
88
use x86_64::{align_up, PhysAddr, VirtAddr};
99
use xmas_elf::program::{self, ProgramHeader64};
@@ -31,7 +31,7 @@ pub(crate) fn map_kernel(
3131
let frame = frame_allocator
3232
.allocate_frame(region_type)
3333
.ok_or(MapToError::FrameAllocationFailed)?;
34-
map_page(page, frame, flags, page_table, frame_allocator)?.flush();
34+
unsafe { map_page(page, frame, flags, page_table, frame_allocator)? }.flush();
3535
}
3636

3737
Ok(stack_end.start_address())
@@ -68,7 +68,8 @@ pub(crate) fn map_segment(
6868
for frame in PhysFrame::range_inclusive(start_frame, end_frame) {
6969
let offset = frame - start_frame;
7070
let page = start_page + offset;
71-
map_page(page, frame, page_table_flags, page_table, frame_allocator)?.flush();
71+
unsafe { map_page(page, frame, page_table_flags, page_table, frame_allocator)? }
72+
.flush();
7273
}
7374

7475
if mem_size > file_size {
@@ -85,13 +86,15 @@ pub(crate) fn map_segment(
8586
let new_frame = frame_allocator
8687
.allocate_frame(MemoryRegionType::Kernel)
8788
.ok_or(MapToError::FrameAllocationFailed)?;
88-
map_page(
89-
temp_page.clone(),
90-
new_frame.clone(),
91-
page_table_flags,
92-
page_table,
93-
frame_allocator,
94-
)?
89+
unsafe {
90+
map_page(
91+
temp_page.clone(),
92+
new_frame.clone(),
93+
page_table_flags,
94+
page_table,
95+
frame_allocator,
96+
)?
97+
}
9598
.flush();
9699

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

117-
map_page(
118-
last_page,
119-
new_frame,
120-
page_table_flags,
121-
page_table,
122-
frame_allocator,
123-
)?
120+
unsafe {
121+
map_page(
122+
last_page,
123+
new_frame,
124+
page_table_flags,
125+
page_table,
126+
frame_allocator,
127+
)?
128+
}
124129
.flush();
125130
}
126131

@@ -134,7 +139,10 @@ pub(crate) fn map_segment(
134139
let frame = frame_allocator
135140
.allocate_frame(MemoryRegionType::Kernel)
136141
.ok_or(MapToError::FrameAllocationFailed)?;
137-
map_page(page, frame, page_table_flags, page_table, frame_allocator)?.flush();
142+
unsafe {
143+
map_page(page, frame, page_table_flags, page_table, frame_allocator)?
144+
}
145+
.flush();
138146
}
139147

140148
// zero
@@ -149,7 +157,7 @@ pub(crate) fn map_segment(
149157
Ok(())
150158
}
151159

152-
pub(crate) fn map_page<'a, S>(
160+
pub(crate) unsafe fn map_page<'a, S>(
153161
page: Page<S>,
154162
phys_frame: PhysFrame<S>,
155163
flags: PageTableFlags,
@@ -162,8 +170,8 @@ where
162170
{
163171
struct PageTableAllocator<'a, 'b: 'a>(&'a mut FrameAllocator<'b>);
164172

165-
impl<'a, 'b> paging::FrameAllocator<Size4KiB> for PageTableAllocator<'a, 'b> {
166-
fn alloc(&mut self) -> Option<PhysFrame<Size4KiB>> {
173+
unsafe impl<'a, 'b> paging::FrameAllocator<Size4KiB> for PageTableAllocator<'a, 'b> {
174+
fn allocate_frame(&mut self) -> Option<PhysFrame<Size4KiB>> {
167175
self.0.allocate_frame(MemoryRegionType::PageTable)
168176
}
169177
}

0 commit comments

Comments
 (0)