Skip to content

Commit

Permalink
update nightly to 2020-06-04
Browse files Browse the repository at this point in the history
  • Loading branch information
wangrunji0408 committed Jun 6, 2020
1 parent 228ef79 commit 79d4326
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2020-04-06
toolchain: nightly-2020-06-04
override: true
components: rustfmt
- name: Check code format
Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2020-04-06
toolchain: nightly-2020-06-04
override: true
components: rust-src
- name: Build
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[package]
name = "rboot"
version = "0.1.2"
version = "0.1.3"
authors = ["Runji Wang <[email protected]>"]
edition = "2018"
description = "The x86_64 UEFI bootloader for rCore"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
uefi = "=0.4.4"
uefi-services = { version = "0.2", optional = true }
uefi = "=0.4.6"
uefi-services = { version = "0.2.4", optional = true }
log = "0.4"
xmas-elf = "0.7"
x86_64 = "0.9"
x86_64 = "0.11"
rlibc = "1.0.0"

[features]
rboot = ["uefi-services"]
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2020-04-06
nightly-2020-06-04
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
//! 2. Load kernel ELF file
//! 3. Map ELF segments to virtual memory
//! 4. Map kernel stack and all physical memory
//! 5. Startup all processors
//! 6. Exit boot and jump to ELF entry
//! 5. Exit boot and jump to ELF entry
#![no_std]
#![no_main]
#![feature(asm, abi_efiapi)]
#![feature(llvm_asm, abi_efiapi)]
#![deny(warnings)]

#[macro_use]
extern crate alloc;
#[macro_use]
extern crate log;
extern crate rlibc;

use alloc::boxed::Box;
use rboot::{BootInfo, GraphicInfo, MemoryMap};
Expand Down Expand Up @@ -229,13 +229,12 @@ fn current_page_table() -> OffsetPageTable<'static> {
struct UEFIFrameAllocator<'a>(&'a BootServices);

unsafe impl FrameAllocator<Size4KiB> for UEFIFrameAllocator<'_> {
fn allocate_frame(&mut self) -> Option<UnusedPhysFrame> {
fn allocate_frame(&mut self) -> Option<PhysFrame> {
let addr = self
.0
.allocate_pages(AllocateType::AnyPages, MemoryType::LOADER_DATA, 1)
.expect_success("failed to allocate frame");
let frame =
unsafe { UnusedPhysFrame::new(PhysFrame::containing_address(PhysAddr::new(addr))) };
let frame = PhysFrame::containing_address(PhysAddr::new(addr));
Some(frame)
}
}
Expand Down Expand Up @@ -295,7 +294,7 @@ extern "efiapi" fn ap_main(_arg: *mut core::ffi::c_void) {

/// Jump to ELF entry according to global variable `ENTRY`
unsafe fn jump_to_entry(bootinfo: *const BootInfo, stacktop: u64) -> ! {
asm!("call $0" :: "r"(ENTRY), "{rsp}"(stacktop), "{rdi}"(bootinfo) :: "intel");
llvm_asm!("call $0" :: "r"(ENTRY), "{rsp}"(stacktop), "{rdi}"(bootinfo) :: "intel");
loop {}
}

Expand Down
35 changes: 20 additions & 15 deletions src/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ pub fn map_stack(
let frame = frame_allocator
.allocate_frame()
.ok_or(MapToError::FrameAllocationFailed)?;
page_table
.map_to(page, frame, flags, frame_allocator)?
.flush();
unsafe {
page_table
.map_to(page, frame, flags, frame_allocator)?
.flush();
}
}

Ok(())
Expand Down Expand Up @@ -74,10 +76,11 @@ fn map_segment(
for frame in PhysFrame::range_inclusive(start_frame, end_frame) {
let offset = frame - start_frame;
let page = start_page + offset;
let frame = unsafe { UnusedPhysFrame::new(frame) };
page_table
.map_to(page, frame, page_table_flags, frame_allocator)?
.flush();
unsafe {
page_table
.map_to(page, frame, page_table_flags, frame_allocator)?
.flush();
}
}

if mem_size > file_size {
Expand Down Expand Up @@ -112,10 +115,11 @@ fn map_segment(
UnmapError::InvalidFrameAddress(_) => unreachable!(),
});
}

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

// Map additional frames.
Expand All @@ -126,9 +130,11 @@ fn map_segment(
let frame = frame_allocator
.allocate_frame()
.ok_or(MapToError::FrameAllocationFailed)?;
page_table
.map_to(page, frame, page_table_flags, frame_allocator)?
.flush();
unsafe {
page_table
.map_to(page, frame, page_table_flags, frame_allocator)?
.flush();
}
}

// zero bss
Expand Down Expand Up @@ -158,7 +164,6 @@ pub fn map_physical_memory(
let page = Page::containing_address(VirtAddr::new(frame.start_address().as_u64() + offset));
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
unsafe {
let frame = UnusedPhysFrame::new(frame);
page_table
.map_to(page, frame, flags, frame_allocator)
.expect("failed to map physical memory")
Expand Down

0 comments on commit 79d4326

Please sign in to comment.