Update to uefi 0.32
This commit is contained in:
parent
01c8fc37cd
commit
843c4ba466
4 changed files with 37 additions and 36 deletions
12
loader/Cargo.lock
generated
12
loader/Cargo.lock
generated
|
@ -143,9 +143,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uefi"
|
||||
version = "0.31.0"
|
||||
version = "0.32.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "920793ff1148ab68a07ab0b2b866870886cd1e5c0b1b94f451d66158d0ff1a77"
|
||||
checksum = "91f17ea8502a6bd414acb2bf5194f90ca4c48e33a2d18cb57eab3294d2050d99"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
|
@ -159,9 +159,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uefi-macros"
|
||||
version = "0.15.0"
|
||||
version = "0.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0732e421268a2d6d53c95c3c0f4496ccc5c08aa7381458c677153d5d77ce39e"
|
||||
checksum = "c19ee3a01d435eda42cb9931269b349d28a1762f91ddf01c68d276f74b957cc3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -170,9 +170,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uefi-raw"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e537b93f83150df09588ca6658e881b2784e8b5f9588f1c7b72a85b72ea71ce"
|
||||
checksum = "b463030b802e1265a3800fab24df95d3229c202c2e408832a206f05b4d1496ca"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"ptr_meta",
|
||||
|
|
|
@ -8,4 +8,4 @@ elf = {version = "0.7.4", default-features = false}
|
|||
kernel-common = {path = "../lib/kernel-common"}
|
||||
log = "0.4.22"
|
||||
static-alloc = "0.2.5"
|
||||
uefi = "0.31.0"
|
||||
uefi = "0.32.0"
|
||||
|
|
|
@ -2,14 +2,14 @@ use core::ptr;
|
|||
|
||||
use elf::{abi::PT_LOAD, endian::LittleEndian, ElfBytes};
|
||||
use kernel_common::paging::{PageTable, KERNEL_VIRT_START};
|
||||
use uefi::table::{
|
||||
boot::{AllocateType, MemoryType},
|
||||
Boot, SystemTable,
|
||||
use uefi::{
|
||||
boot::allocate_pages,
|
||||
table::boot::{AllocateType, MemoryType},
|
||||
};
|
||||
|
||||
use crate::paging::map;
|
||||
|
||||
pub fn load_kernel(kernel: &[u8], system_table: &SystemTable<Boot>) -> (u64, u64) {
|
||||
pub fn load_kernel(kernel: &[u8]) -> (u64, u64) {
|
||||
let file: ElfBytes<LittleEndian> = ElfBytes::minimal_parse(kernel).unwrap();
|
||||
let mut kernel_size = 0;
|
||||
for i in file.segments().unwrap() {
|
||||
|
@ -23,10 +23,9 @@ pub fn load_kernel(kernel: &[u8], system_table: &SystemTable<Boot>) -> (u64, u64
|
|||
kernel_size = end_addr;
|
||||
}
|
||||
}
|
||||
let phys_start = system_table
|
||||
.boot_services()
|
||||
.allocate_pages(AllocateType::AnyPages, MemoryType::LOADER_DATA, (kernel_size as usize + 0xfff) / 0x1000)
|
||||
.unwrap();
|
||||
let phys_start = allocate_pages(AllocateType::AnyPages, MemoryType::LOADER_DATA, (kernel_size as usize + 0xfff) / 0x1000)
|
||||
.unwrap()
|
||||
.as_ptr() as u64;
|
||||
for i in file.segments().unwrap() {
|
||||
if i.p_type != PT_LOAD {
|
||||
continue;
|
||||
|
|
|
@ -4,7 +4,11 @@
|
|||
|
||||
extern crate alloc;
|
||||
|
||||
use core::{mem, panic::PanicInfo};
|
||||
use core::{
|
||||
mem,
|
||||
panic::PanicInfo,
|
||||
sync::atomic::{AtomicU64, Ordering},
|
||||
};
|
||||
|
||||
use elf::{load_kernel, map_kernel};
|
||||
use kernel_common::{
|
||||
|
@ -18,12 +22,11 @@ use log::{error, info};
|
|||
use paging::setup_paging;
|
||||
use static_alloc::Bump;
|
||||
use uefi::{
|
||||
boot::{allocate_pages, exit_boot_services},
|
||||
entry,
|
||||
table::{
|
||||
boot::{AllocateType, MemoryType},
|
||||
Boot, SystemTable,
|
||||
},
|
||||
Handle, Status,
|
||||
system::with_config_table,
|
||||
table::boot::{AllocateType, MemoryType},
|
||||
Status,
|
||||
};
|
||||
|
||||
mod elf;
|
||||
|
@ -36,30 +39,29 @@ static ALLOC: Bump<[u8; 8 * 1024 * 1024]> = Bump::uninit();
|
|||
const KERNEL: &[u8] = include_bytes!("../../kernel/target/x86_64-unknown-none/release/kernel");
|
||||
|
||||
#[entry]
|
||||
fn main(image_handle: Handle, system_table: SystemTable<Boot>) -> Status {
|
||||
fn main() -> Status {
|
||||
init_logger();
|
||||
info!("Starting bootloader...");
|
||||
uefi::helpers::init().unwrap();
|
||||
let (kernel_start, kernel_entry) = load_kernel(KERNEL, &system_table);
|
||||
let heap_start = system_table
|
||||
.boot_services()
|
||||
.allocate_pages(AllocateType::AnyPages, MemoryType::LOADER_DATA, KERNEL_HEAP_INITIAL_SIZE / 0x1000)
|
||||
.unwrap();
|
||||
let mut rsdp = 0;
|
||||
for i in system_table.config_table() {
|
||||
if i.guid == uefi::table::cfg::ACPI2_GUID {
|
||||
rsdp = i.address as u64;
|
||||
break;
|
||||
let (kernel_start, kernel_entry) = load_kernel(KERNEL);
|
||||
let heap_start = allocate_pages(AllocateType::AnyPages, MemoryType::LOADER_DATA, KERNEL_HEAP_INITIAL_SIZE / 0x1000).unwrap().as_ptr() as u64;
|
||||
let rsdp = AtomicU64::new(0);
|
||||
with_config_table(|tables| {
|
||||
for i in tables {
|
||||
if i.guid == uefi::table::cfg::ACPI2_GUID {
|
||||
rsdp.store(i.address as u64, Ordering::Relaxed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_ne!(rsdp, 0, "RSDP not found");
|
||||
});
|
||||
assert_ne!(rsdp.load(Ordering::Relaxed), 0, "RSDP not found");
|
||||
let memory_map;
|
||||
unsafe {
|
||||
memory_map = system_table.exit_boot_services(MemoryType::LOADER_DATA).1;
|
||||
memory_map = exit_boot_services(MemoryType::LOADER_DATA);
|
||||
}
|
||||
let pml4 = setup_paging(&memory_map, heap_start);
|
||||
map_kernel(KERNEL, pml4, kernel_start);
|
||||
let loader_struct = generate_loader_struct(&memory_map, kernel_start, heap_start, rsdp);
|
||||
let loader_struct = generate_loader_struct(&memory_map, kernel_start, heap_start, rsdp.load(Ordering::Relaxed));
|
||||
info!("Jumping to kernel...");
|
||||
unsafe {
|
||||
(mem::transmute::<_, extern "C" fn(&LoaderStruct) -> !>(kernel_entry))(&loader_struct);
|
||||
|
|
Loading…
Add table
Reference in a new issue