Skip to content

Commit c0e60d6

Browse files
authored
Implement boot-info-address (#101)
1 parent 04e8118 commit c0e60d6

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ kernel-stack-size = 128
2828
# Only applies if the `map_physical_memory` feature of the crate is enabled.
2929
# If not provided, the bootloader dynamically searches for a location.
3030
physical-memory-offset = "0xFFFF800000000000"
31+
32+
# The address at which the bootinfo struct will be placed. if not provided,
33+
# the bootloader will dynamically search for a location.
34+
boot-info-address = "0xFFFFFFFF80000000"
3135
```
3236

3337
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.

build.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct BootloaderConfig {
77
physical_memory_offset: Option<u64>,
88
kernel_stack_address: Option<u64>,
99
kernel_stack_size: Option<u64>,
10+
boot_info_address: Option<u64>,
1011
}
1112

1213
#[cfg(feature = "binary")]
@@ -39,7 +40,8 @@ fn parse_to_config(cfg: &mut BootloaderConfig, table: &toml::value::Table) {
3940
for (key, value) in table {
4041
match (key.as_str(), value.clone()) {
4142
("kernel-stack-address", Value::Integer(i))
42-
| ("physical-memory-offset", Value::Integer(i)) => {
43+
| ("physical-memory-offset", Value::Integer(i))
44+
| ("boot-info-address", Value::Integer(i)) => {
4345
panic!(
4446
"`{0}` in the kernel manifest must be given as a string, \
4547
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) {
5052
("kernel-stack-address", Value::String(s)) => {
5153
cfg.kernel_stack_address = Some(parse_aligned_addr(key.as_str(), &s));
5254
}
55+
("boot-info-address", Value::String(s)) => {
56+
cfg.boot_info_address = Some(parse_aligned_addr(key.as_str(), &s));
57+
}
5358
#[cfg(not(feature = "map_physical_memory"))]
5459
("physical-memory-offset", Value::String(_)) => {
5560
panic!(
@@ -269,10 +274,12 @@ fn main() {
269274
format!(
270275
"const PHYSICAL_MEMORY_OFFSET: Option<u64> = {:?};
271276
const KERNEL_STACK_ADDRESS: Option<u64> = {:?};
272-
const KERNEL_STACK_SIZE: u64 = {};",
277+
const KERNEL_STACK_SIZE: u64 = {};
278+
const BOOT_INFO_ADDRESS: Option<u64> = {:?};",
273279
bootloader_config.physical_memory_offset,
274280
bootloader_config.kernel_stack_address,
275281
bootloader_config.kernel_stack_size.unwrap_or(512), // size is in number of pages
282+
bootloader_config.boot_info_address,
276283
)
277284
.as_bytes(),
278285
)

src/main.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,15 @@ fn bootloader_main(
240240

241241
// Map a page for the boot info structure
242242
let boot_info_page = {
243-
let page: Page = Page::from_page_table_indices(
244-
level4_entries.get_free_entry(),
245-
PageTableIndex::new(0),
246-
PageTableIndex::new(0),
247-
PageTableIndex::new(0),
248-
);
243+
let page: Page = match BOOT_INFO_ADDRESS {
244+
Some(addr) => Page::containing_address(VirtAddr::new(addr)),
245+
None => Page::from_page_table_indices(
246+
level4_entries.get_free_entry(),
247+
PageTableIndex::new(0),
248+
PageTableIndex::new(0),
249+
PageTableIndex::new(0),
250+
),
251+
};
249252
let frame = frame_allocator
250253
.allocate_frame(MemoryRegionType::BootInfo)
251254
.expect("frame allocation failed");

0 commit comments

Comments
 (0)