From 299a6700c1991faa765c32d193e1c529387e4c27 Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Sun, 1 Oct 2023 17:34:03 -0700 Subject: [PATCH 1/7] Pass the UEFI runtime services table address to the BootInfo if running on UEFI --- api/Cargo.toml | 1 + api/src/info.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/api/Cargo.toml b/api/Cargo.toml index ef687b0c..a21d3a97 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -9,6 +9,7 @@ description = "Makes a kernel compatible with the bootloader crate" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +uefi = "0.24.0" [dev-dependencies] rand = "0.8.4" diff --git a/api/src/info.rs b/api/src/info.rs index 965fcf40..064c4216 100644 --- a/api/src/info.rs +++ b/api/src/info.rs @@ -63,6 +63,9 @@ pub struct BootInfo { /// Virtual address of the loaded kernel image. pub kernel_image_offset: u64, + /// UEFI runtime table address (if running on UEFI) + pub rt_table_addr: Optional, + #[doc(hidden)] pub _test_sentinel: u64, } @@ -85,6 +88,7 @@ impl BootInfo { kernel_addr: 0, kernel_len: 0, kernel_image_offset: 0, + rt_table_addr: Optional::None, _test_sentinel: 0, } } From 68a123e5158d952d1d4261e69f9d394dbb98245d Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Sun, 1 Oct 2023 17:34:12 -0700 Subject: [PATCH 2/7] Pass the UEFI runtime services table address to the BootInfo if running on UEFI --- Cargo.lock | 48 ++++++++++++++++++++++++++++++++++++++-- bios/stage-4/src/main.rs | 1 + common/src/lib.rs | 13 +++++++++-- uefi/src/main.rs | 1 + 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5023a397..ab7f04c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -253,7 +253,7 @@ dependencies = [ "bootloader_api", "log", "serde-json-core", - "uefi", + "uefi 0.20.0", "x86_64", ] @@ -262,6 +262,7 @@ name = "bootloader_api" version = "0.11.4" dependencies = [ "rand", + "uefi 0.24.0", ] [[package]] @@ -1173,7 +1174,22 @@ dependencies = [ "log", "ptr_meta", "ucs2", - "uefi-macros", + "uefi-macros 0.11.0", +] + +[[package]] +name = "uefi" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b63e82686b4bdb0db74f18b2abbd60a0470354fb640aa69e115598d714d0a10" +dependencies = [ + "bitflags 2.3.3", + "log", + "ptr_meta", + "ucs2", + "uefi-macros 0.12.0", + "uefi-raw", + "uguid", ] [[package]] @@ -1187,6 +1203,34 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "uefi-macros" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "023d94ef8e135d068b9a3bd94614ef2610b2b0419ade0a9d8f3501fa9cd08e95" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.23", +] + +[[package]] +name = "uefi-raw" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62642516099c6441a5f41b0da8486d5fc3515a0603b0fdaea67b31600e22082e" +dependencies = [ + "bitflags 2.3.3", + "ptr_meta", + "uguid", +] + +[[package]] +name = "uguid" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16dfbd255defbd727b3a30e8950695d2e6d045841ee250ff0f1f7ced17917f8d" + [[package]] name = "unicode-ident" version = "1.0.10" diff --git a/bios/stage-4/src/main.rs b/bios/stage-4/src/main.rs index 260dd622..a6361c47 100644 --- a/bios/stage-4/src/main.rs +++ b/bios/stage-4/src/main.rs @@ -164,6 +164,7 @@ pub extern "C" fn _start(info: &mut BiosInfo) -> ! { _ => Some(info.ramdisk.start), }, ramdisk_len: info.ramdisk.len, + rt_table_addr: None, }; load_and_switch_to_kernel(kernel, config, frame_allocator, page_tables, system_info); diff --git a/common/src/lib.rs b/common/src/lib.rs index 3c407644..7be711e7 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -5,7 +5,7 @@ use crate::legacy_memory_region::{LegacyFrameAllocator, LegacyMemoryRegion}; use bootloader_api::{ config::Mapping, - info::{FrameBuffer, FrameBufferInfo, MemoryRegion, TlsTemplate}, + info::{FrameBuffer, FrameBufferInfo, MemoryRegion, TlsTemplate, Optional}, BootInfo, BootloaderConfig, }; use bootloader_boot_config::{BootConfig, LevelFilter}; @@ -72,7 +72,7 @@ fn convert_level(level: LevelFilter) -> log::LevelFilter { } /// Required system information that should be queried from the BIOS or UEFI firmware. -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub struct SystemInfo { /// Information about the (still unmapped) framebuffer. pub framebuffer: Option, @@ -80,6 +80,10 @@ pub struct SystemInfo { pub rsdp_addr: Option, pub ramdisk_addr: Option, pub ramdisk_len: u64, + + /// UEFI runtime table address (on a UEFI system) + // #[cfg(target_os = "uefi")] + pub rt_table_addr: Option, } /// The physical address of the framebuffer and information about the framebuffer. @@ -551,6 +555,11 @@ where info.kernel_len = mappings.kernel_slice_len as _; info.kernel_image_offset = mappings.kernel_image_offset.as_u64(); info._test_sentinel = boot_config._test_sentinel; + info.rt_table_addr = if let Some(addr) = system_info.rt_table_addr { + Optional::Some(addr) + } else { + Optional::None + }; info }); diff --git a/uefi/src/main.rs b/uefi/src/main.rs index 93dfb6c7..2c39e877 100644 --- a/uefi/src/main.rs +++ b/uefi/src/main.rs @@ -166,6 +166,7 @@ fn main_inner(image: Handle, mut st: SystemTable) -> Status { }, ramdisk_addr, ramdisk_len, + rt_table_addr: Some(system_table.get_current_system_table_addr()), }; bootloader_x86_64_common::load_and_switch_to_kernel( From c5b6e04e2809bbabb429d5826d9e821e3444fb32 Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Sun, 1 Oct 2023 17:42:19 -0700 Subject: [PATCH 3/7] rustfmt --- common/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index 7be711e7..8770e0d1 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -5,7 +5,7 @@ use crate::legacy_memory_region::{LegacyFrameAllocator, LegacyMemoryRegion}; use bootloader_api::{ config::Mapping, - info::{FrameBuffer, FrameBufferInfo, MemoryRegion, TlsTemplate, Optional}, + info::{FrameBuffer, FrameBufferInfo, MemoryRegion, Optional, TlsTemplate}, BootInfo, BootloaderConfig, }; use bootloader_boot_config::{BootConfig, LevelFilter}; From 0b028dba1852911db37a7e17cd99b1baa507ad18 Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Sun, 1 Oct 2023 17:53:02 -0700 Subject: [PATCH 4/7] Remove redundant dependencies --- Cargo.lock | 48 ++---------------------------------------------- api/Cargo.toml | 5 ----- 2 files changed, 2 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab7f04c9..5023a397 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -253,7 +253,7 @@ dependencies = [ "bootloader_api", "log", "serde-json-core", - "uefi 0.20.0", + "uefi", "x86_64", ] @@ -262,7 +262,6 @@ name = "bootloader_api" version = "0.11.4" dependencies = [ "rand", - "uefi 0.24.0", ] [[package]] @@ -1174,22 +1173,7 @@ dependencies = [ "log", "ptr_meta", "ucs2", - "uefi-macros 0.11.0", -] - -[[package]] -name = "uefi" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b63e82686b4bdb0db74f18b2abbd60a0470354fb640aa69e115598d714d0a10" -dependencies = [ - "bitflags 2.3.3", - "log", - "ptr_meta", - "ucs2", - "uefi-macros 0.12.0", - "uefi-raw", - "uguid", + "uefi-macros", ] [[package]] @@ -1203,34 +1187,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "uefi-macros" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023d94ef8e135d068b9a3bd94614ef2610b2b0419ade0a9d8f3501fa9cd08e95" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.23", -] - -[[package]] -name = "uefi-raw" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62642516099c6441a5f41b0da8486d5fc3515a0603b0fdaea67b31600e22082e" -dependencies = [ - "bitflags 2.3.3", - "ptr_meta", - "uguid", -] - -[[package]] -name = "uguid" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16dfbd255defbd727b3a30e8950695d2e6d045841ee250ff0f1f7ced17917f8d" - [[package]] name = "unicode-ident" version = "1.0.10" diff --git a/api/Cargo.toml b/api/Cargo.toml index a21d3a97..8d075843 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -6,10 +6,5 @@ repository.workspace = true edition = "2021" description = "Makes a kernel compatible with the bootloader crate" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -uefi = "0.24.0" - [dev-dependencies] rand = "0.8.4" From 35bcae6477a15f0a2a2dec04f96cd347856dac44 Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Sun, 1 Oct 2023 17:55:09 -0700 Subject: [PATCH 5/7] Add back the Copy and Clone impls --- common/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index 8770e0d1..9ec13214 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -72,7 +72,7 @@ fn convert_level(level: LevelFilter) -> log::LevelFilter { } /// Required system information that should be queried from the BIOS or UEFI firmware. -#[derive(Debug)] +#[derive(Debug, Copy, Clone)] pub struct SystemInfo { /// Information about the (still unmapped) framebuffer. pub framebuffer: Option, From 5578f36edc46dc3fb68c98c51419dfc6136167d9 Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Sun, 1 Oct 2023 18:00:23 -0700 Subject: [PATCH 6/7] Fix doc comments --- common/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index 9ec13214..a72bca89 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -81,8 +81,9 @@ pub struct SystemInfo { pub ramdisk_addr: Option, pub ramdisk_len: u64, - /// UEFI runtime table address (on a UEFI system) - // #[cfg(target_os = "uefi")] + /// UEFI runtime table address (if running on UEFI). + /// + /// Use a raw pointer from your kernel to this address to access UEFI Runtime Services. pub rt_table_addr: Option, } From 20dbee73e708279ded6ed594eeac127ba1c62e01 Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Sun, 1 Oct 2023 18:07:09 -0700 Subject: [PATCH 7/7] rustfmt --- common/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index a72bca89..20c5c4cc 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -82,7 +82,7 @@ pub struct SystemInfo { pub ramdisk_len: u64, /// UEFI runtime table address (if running on UEFI). - /// + /// /// Use a raw pointer from your kernel to this address to access UEFI Runtime Services. pub rt_table_addr: Option, }