mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-25 10:23:23 +00:00
Migrate to latest UEFI dependencies
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
2af9916de9
commit
68adca4b40
70
Cargo.lock
generated
70
Cargo.lock
generated
@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "acpi"
|
name = "acpi"
|
||||||
@ -875,9 +875,9 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"uart_16550",
|
"uart_16550",
|
||||||
"uefi",
|
"uefi",
|
||||||
"uefi-services",
|
"uefi-raw",
|
||||||
"x86_64",
|
"x86_64 0.15.1",
|
||||||
"xmas-elf 0.8.0",
|
"xmas-elf 0.9.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -953,7 +953,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"multiboot2-common",
|
"multiboot2-common",
|
||||||
"ptr_meta",
|
"ptr_meta",
|
||||||
"uefi-raw 0.8.0",
|
"uefi-raw",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1119,7 +1119,7 @@ dependencies = [
|
|||||||
"unwinding",
|
"unwinding",
|
||||||
"volatile",
|
"volatile",
|
||||||
"x86",
|
"x86",
|
||||||
"x86_64",
|
"x86_64 0.14.11",
|
||||||
"xarray",
|
"xarray",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1238,6 +1238,12 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "qemu-exit"
|
||||||
|
version = "3.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8bb0fd6580eeed0103c054e3fba2c2618ff476943762f28a645b63b8692b21c9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.37"
|
version = "1.0.37"
|
||||||
@ -1470,7 +1476,7 @@ dependencies = [
|
|||||||
"iced-x86",
|
"iced-x86",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"raw-cpuid",
|
"raw-cpuid",
|
||||||
"x86_64",
|
"x86_64 0.14.11",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1572,50 +1578,41 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ucs2"
|
name = "ucs2"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bad643914094137d475641b6bab89462505316ec2ce70907ad20102d28a79ab8"
|
checksum = "df79298e11f316400c57ec268f3c2c29ac3c4d4777687955cd3d4f3a35ce7eba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit_field",
|
"bit_field",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uefi"
|
name = "uefi"
|
||||||
version = "0.26.0"
|
version = "0.32.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "07ead9f748a4646479b850add36b527113a80e80a7e0f44d7b0334291850dcc5"
|
checksum = "91f17ea8502a6bd414acb2bf5194f90ca4c48e33a2d18cb57eab3294d2050d99"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
|
"cfg-if",
|
||||||
"log",
|
"log",
|
||||||
"ptr_meta",
|
"ptr_meta",
|
||||||
|
"qemu-exit",
|
||||||
"ucs2",
|
"ucs2",
|
||||||
"uefi-macros",
|
"uefi-macros",
|
||||||
"uefi-raw 0.5.0",
|
"uefi-raw",
|
||||||
"uguid",
|
"uguid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uefi-macros"
|
name = "uefi-macros"
|
||||||
version = "0.13.0"
|
version = "0.16.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "26a7b1c2c808c3db854a54d5215e3f7e7aaf5dcfbce095598cba6af29895695d"
|
checksum = "c19ee3a01d435eda42cb9931269b349d28a1762f91ddf01c68d276f74b957cc3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.77",
|
"syn 2.0.77",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "uefi-raw"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "864ac69eadd877bfb34e7814be1928122ed0057d9f975169a56ee496aa7bdfd7"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.6.0",
|
|
||||||
"ptr_meta",
|
|
||||||
"uguid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uefi-raw"
|
name = "uefi-raw"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
@ -1627,17 +1624,6 @@ dependencies = [
|
|||||||
"uguid",
|
"uguid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "uefi-services"
|
|
||||||
version = "0.23.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a79fcb420624743c895bad0f9480fbc2f64e7c8d8611fb1ada6bdd799942feb4"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"log",
|
|
||||||
"uefi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uguid"
|
name = "uguid"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
@ -1751,6 +1737,18 @@ dependencies = [
|
|||||||
"volatile",
|
"volatile",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "x86_64"
|
||||||
|
version = "0.15.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4bc79523af8abf92fb1a970c3e086c5a343f6bcc1a0eb890f575cbb3b45743df"
|
||||||
|
dependencies = [
|
||||||
|
"bit_field",
|
||||||
|
"bitflags 2.6.0",
|
||||||
|
"rustversion",
|
||||||
|
"volatile",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xarray"
|
name = "xarray"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -18,14 +18,14 @@ core2 = { version = "0.4.0", default-features = false, features = ["nightly"] }
|
|||||||
libflate = { version = "2.1.0", default-features = false }
|
libflate = { version = "2.1.0", default-features = false }
|
||||||
linux-boot-params = { path = "../boot-params", version = "0.1.0" }
|
linux-boot-params = { path = "../boot-params", version = "0.1.0" }
|
||||||
uart_16550 = "0.3.0"
|
uart_16550 = "0.3.0"
|
||||||
xmas-elf = "0.8.0"
|
xmas-elf = "0.9.1"
|
||||||
|
|
||||||
[target.x86_64-unknown-none.dependencies]
|
[target.x86_64-unknown-none.dependencies]
|
||||||
bitflags = "2.4.1"
|
bitflags = "2.4.1"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
uefi = "0.26.0"
|
uefi = { version = "0.32.0", features = ["global_allocator", "panic_handler", "logger", "qemu"]}
|
||||||
uefi-services = "0.23.0"
|
uefi-raw = "0.8.0"
|
||||||
x86_64 = "0.14.11"
|
x86_64 = "0.15.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
use linux_boot_params::BootParams;
|
use linux_boot_params::BootParams;
|
||||||
use uefi::{
|
use uefi::{
|
||||||
data_types::Handle,
|
prelude::*,
|
||||||
proto::loaded_image::LoadedImage,
|
proto::loaded_image::LoadedImage,
|
||||||
table::{
|
boot::{exit_boot_services, open_protocol_exclusive},
|
||||||
boot::MemoryMap,
|
mem::memory_map::{MemoryMapOwned, MemoryMap},
|
||||||
cfg::{ACPI2_GUID, ACPI_GUID},
|
|
||||||
Boot, Runtime, SystemTable,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
use uefi_raw::table::system::SystemTable;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
decoder::decode_payload,
|
decoder::decode_payload,
|
||||||
@ -22,77 +20,78 @@ use super::{
|
|||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[allow(clippy::diverging_sub_expression)]
|
#[allow(clippy::diverging_sub_expression)]
|
||||||
#[export_name = "efi_stub_entry"]
|
#[export_name = "efi_stub_entry"]
|
||||||
extern "sysv64" fn efi_stub_entry(handle: Handle, mut system_table: SystemTable<Boot>) -> ! {
|
extern "sysv64" fn efi_stub_entry(handle: Handle, system_table: *const SystemTable) -> ! {
|
||||||
unsafe {
|
unsafe {
|
||||||
system_table.boot_services().set_image_handle(handle);
|
boot::set_image_handle(handle);
|
||||||
|
uefi::table::set_system_table(system_table);
|
||||||
}
|
}
|
||||||
uefi_services::init(&mut system_table).unwrap();
|
uefi::helpers::init().unwrap();
|
||||||
|
|
||||||
let boot_params = todo!("Use EFI boot services to fill boot params");
|
let boot_params = todo!("Use EFI boot services to fill boot params");
|
||||||
|
|
||||||
efi_phase_boot(handle, system_table, boot_params);
|
efi_phase_boot(boot_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export_name = "efi_handover_entry"]
|
#[export_name = "efi_handover_entry"]
|
||||||
extern "sysv64" fn efi_handover_entry(
|
extern "sysv64" fn efi_handover_entry(
|
||||||
handle: Handle,
|
handle: Handle,
|
||||||
mut system_table: SystemTable<Boot>,
|
system_table: *const SystemTable,
|
||||||
boot_params_ptr: *mut BootParams,
|
boot_params_ptr: *mut BootParams,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
unsafe {
|
unsafe {
|
||||||
system_table.boot_services().set_image_handle(handle);
|
boot::set_image_handle(handle);
|
||||||
|
uefi::table::set_system_table(system_table);
|
||||||
}
|
}
|
||||||
uefi_services::init(&mut system_table).unwrap();
|
uefi::helpers::init().unwrap();
|
||||||
|
|
||||||
// SAFETY: boot_params is a valid pointer.
|
// SAFETY: boot_params is a valid pointer.
|
||||||
let boot_params = unsafe { &mut *boot_params_ptr };
|
let boot_params = unsafe { &mut *boot_params_ptr };
|
||||||
|
|
||||||
efi_phase_boot(handle, system_table, boot_params)
|
efi_phase_boot(boot_params)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn efi_phase_boot(
|
fn efi_phase_boot(boot_params: &mut BootParams) -> ! {
|
||||||
handle: Handle,
|
// SAFETY: This is the right time to initialize the console and it is only
|
||||||
system_table: SystemTable<Boot>,
|
// called once here before all console operations.
|
||||||
boot_params: &mut BootParams,
|
unsafe {
|
||||||
) -> ! {
|
crate::console::init();
|
||||||
// SAFETY: this init function is only called once.
|
}
|
||||||
unsafe { crate::console::init() };
|
|
||||||
|
|
||||||
// SAFETY: this is the right time to apply relocations.
|
// SAFETY: this is the right time to apply relocations.
|
||||||
unsafe { apply_rela_dyn_relocations() };
|
unsafe { apply_rela_dyn_relocations() };
|
||||||
|
|
||||||
uefi_services::println!("[EFI stub] Relocations applied.");
|
uefi::println!("[EFI stub] Relocations applied.");
|
||||||
|
uefi::println!("[EFI stub] Stub loaded at {:#x?}", crate::x86::get_image_loaded_offset());
|
||||||
|
|
||||||
// Fill the boot params with the RSDP address if it is not provided.
|
// Fill the boot params with the RSDP address if it is not provided.
|
||||||
if boot_params.acpi_rsdp_addr == 0 {
|
if boot_params.acpi_rsdp_addr == 0 {
|
||||||
boot_params.acpi_rsdp_addr = get_rsdp_addr(&system_table);
|
boot_params.acpi_rsdp_addr = get_rsdp_addr();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the kernel payload to memory.
|
// Load the kernel payload to memory.
|
||||||
let payload = crate::get_payload(boot_params);
|
let payload = crate::get_payload(boot_params);
|
||||||
let kernel = decode_payload(payload);
|
let kernel = decode_payload(payload);
|
||||||
|
|
||||||
uefi_services::println!("[EFI stub] Loading payload.");
|
uefi::println!("[EFI stub] Loading payload.");
|
||||||
crate::loader::load_elf(&kernel);
|
crate::loader::load_elf(&kernel);
|
||||||
|
|
||||||
uefi_services::println!("[EFI stub] Exiting EFI boot services.");
|
uefi::println!("[EFI stub] Exiting EFI boot services.");
|
||||||
let memory_type = {
|
let memory_type = {
|
||||||
let boot_services = system_table.boot_services();
|
let Ok(loaded_image) = open_protocol_exclusive::<LoadedImage>(boot::image_handle()) else {
|
||||||
let Ok(loaded_image) = boot_services.open_protocol_exclusive::<LoadedImage>(handle) else {
|
|
||||||
panic!("Failed to open LoadedImage protocol");
|
panic!("Failed to open LoadedImage protocol");
|
||||||
};
|
};
|
||||||
loaded_image.data_type()
|
loaded_image.data_type()
|
||||||
};
|
};
|
||||||
let (system_table, memory_map) = system_table.exit_boot_services(memory_type);
|
// SAFETY: All allocations in the boot services phase are not used after
|
||||||
|
// this point.
|
||||||
|
let memory_map = unsafe {
|
||||||
|
exit_boot_services(memory_type)
|
||||||
|
};
|
||||||
|
|
||||||
efi_phase_runtime(system_table, memory_map, boot_params);
|
efi_phase_runtime(memory_map, boot_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn efi_phase_runtime(
|
fn efi_phase_runtime(memory_map: MemoryMapOwned, boot_params: &mut BootParams) -> ! {
|
||||||
_system_table: SystemTable<Runtime>,
|
|
||||||
memory_map: MemoryMap<'static>,
|
|
||||||
boot_params: &mut BootParams,
|
|
||||||
) -> ! {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
crate::console::print_str("[EFI stub] Entered runtime services.\n");
|
crate::console::print_str("[EFI stub] Entered runtime services.\n");
|
||||||
}
|
}
|
||||||
@ -218,9 +217,10 @@ fn efi_phase_runtime(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_rsdp_addr(boot_table: &SystemTable<Boot>) -> u64 {
|
fn get_rsdp_addr() -> u64 {
|
||||||
let config_table = boot_table.config_table();
|
use uefi::table::cfg::{ACPI2_GUID, ACPI_GUID};
|
||||||
for entry in config_table {
|
uefi::system::with_config_table(|table| {
|
||||||
|
for entry in table {
|
||||||
// Prefer ACPI2 over ACPI.
|
// Prefer ACPI2 over ACPI.
|
||||||
if entry.guid == ACPI2_GUID {
|
if entry.guid == ACPI2_GUID {
|
||||||
return entry.address as usize as u64;
|
return entry.address as usize as u64;
|
||||||
@ -230,4 +230,5 @@ fn get_rsdp_addr(boot_table: &SystemTable<Boot>) -> u64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic!("ACPI RSDP not found");
|
panic!("ACPI RSDP not found");
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user