From 830ac8e4ae43780ddae0f9c18a3e132add50f740 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Sat, 7 Mar 2020 10:53:25 +0100 Subject: [PATCH 1/2] Implement boot-info-address --- README.md | 4 ++++ build.rs | 11 +++++++++-- src/main.rs | 15 +++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 510c65f6..21b1f97a 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ kernel-stack-size = 128 # Only applies if the `map_physical_memory` feature of the crate is enabled. # If not provided, the bootloader dynamically searches for a location. physical-memory-offset = "0xFFFF800000000000" + +# The address at which the bootinfo struct will be placed. if not provided, +# the bootloader will dynamically search for a location. +boot-info-address = "0xFFFFFFFF80000000" ``` Note that the addresses **must** be given as strings (in either hex or decimal format), as [TOML](https://github.com/toml-lang/toml) does not support unsigned 64-bit integers. diff --git a/build.rs b/build.rs index 6ccc5faa..7918c624 100644 --- a/build.rs +++ b/build.rs @@ -7,6 +7,7 @@ struct BootloaderConfig { physical_memory_offset: Option, kernel_stack_address: Option, kernel_stack_size: Option, + boot_info_address: Option, } #[cfg(feature = "binary")] @@ -39,7 +40,8 @@ fn parse_to_config(cfg: &mut BootloaderConfig, table: &toml::value::Table) { for (key, value) in table { match (key.as_str(), value.clone()) { ("kernel-stack-address", Value::Integer(i)) - | ("physical-memory-offset", Value::Integer(i)) => { + | ("physical-memory-offset", Value::Integer(i)) + | ("boot-info-address", Value::Integer(i)) => { panic!( "`{0}` in the kernel manifest must be given as a string, \ as toml does not support unsigned 64-bit integers (try `{0} = \"{1}\"`)", @@ -50,6 +52,9 @@ fn parse_to_config(cfg: &mut BootloaderConfig, table: &toml::value::Table) { ("kernel-stack-address", Value::String(s)) => { cfg.kernel_stack_address = Some(parse_aligned_addr(key.as_str(), &s)); } + ("boot-info-address", Value::String(s)) => { + cfg.boot_info_address = Some(parse_aligned_addr(key.as_str(), &s)); + } #[cfg(not(feature = "map_physical_memory"))] ("physical-memory-offset", Value::String(_)) => { panic!( @@ -269,10 +274,12 @@ fn main() { format!( "const PHYSICAL_MEMORY_OFFSET: Option = {:?}; const KERNEL_STACK_ADDRESS: Option = {:?}; - const KERNEL_STACK_SIZE: u64 = {};", + const KERNEL_STACK_SIZE: u64 = {}; + const BOOT_INFO_ADDRESS: Option = {:?};", bootloader_config.physical_memory_offset, bootloader_config.kernel_stack_address, bootloader_config.kernel_stack_size.unwrap_or(512), // size is in number of pages + bootloader_config.boot_info_address, ) .as_bytes(), ) diff --git a/src/main.rs b/src/main.rs index a937f228..269a9561 100644 --- a/src/main.rs +++ b/src/main.rs @@ -240,12 +240,15 @@ fn bootloader_main( // Map a page for the boot info structure let boot_info_page = { - let page: Page = Page::from_page_table_indices( - level4_entries.get_free_entry(), - PageTableIndex::new(0), - PageTableIndex::new(0), - PageTableIndex::new(0), - ); + let page: Page = match BOOT_INFO_ADDRESS { + Some(addr) => Page::containing_address(VirtAddr::new(addr)) + None => Page::from_page_table_indices( + level4_entries.get_free_entry(), + PageTableIndex::new(0), + PageTableIndex::new(0), + PageTableIndex::new(0), + ), + }; let frame = frame_allocator .allocate_frame(MemoryRegionType::BootInfo) .expect("frame allocation failed"); From eb5e2cb484be81bdc2f1e24c0eb7da84fc9c9943 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Sat, 7 Mar 2020 11:01:46 +0100 Subject: [PATCH 2/2] Add missing , --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 269a9561..921259f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -241,7 +241,7 @@ fn bootloader_main( // Map a page for the boot info structure let boot_info_page = { let page: Page = match BOOT_INFO_ADDRESS { - Some(addr) => Page::containing_address(VirtAddr::new(addr)) + Some(addr) => Page::containing_address(VirtAddr::new(addr)), None => Page::from_page_table_indices( level4_entries.get_free_entry(), PageTableIndex::new(0),