Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement boot-info-address #101

Merged
merged 2 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct BootloaderConfig {
physical_memory_offset: Option<u64>,
kernel_stack_address: Option<u64>,
kernel_stack_size: Option<u64>,
boot_info_address: Option<u64>,
}

#[cfg(feature = "binary")]
Expand Down Expand Up @@ -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}\"`)",
Expand All @@ -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!(
Expand Down Expand Up @@ -269,10 +274,12 @@ fn main() {
format!(
"const PHYSICAL_MEMORY_OFFSET: Option<u64> = {:?};
const KERNEL_STACK_ADDRESS: Option<u64> = {:?};
const KERNEL_STACK_SIZE: u64 = {};",
const KERNEL_STACK_SIZE: u64 = {};
const BOOT_INFO_ADDRESS: Option<u64> = {:?};",
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(),
)
Expand Down
15 changes: 9 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down