From c7f8b08e141afaff0062c563d33036c458ef333d Mon Sep 17 00:00:00 2001 From: Jianyong Wu Date: Wed, 5 Jul 2023 09:49:30 +0000 Subject: [PATCH] aarch64: enlarge memory range for grub loading For now, 0x40400000 ~ 0x40480000 is used for loading grub. But it may not be enough sometime. Enlarge this area by movnge the ram_min to 0x40600000. Thus there is 2M range for loading grub that is enough. As PE loader will get image offset and size in the header to put it in the right place, image header should also be updated. Fixes: #261 Signed-off-by: Jianyong Wu --- aarch64-unknown-none.ld | 17 ++++++++++++++--- src/arch/aarch64/ram64.s | 8 +++++--- src/main.rs | 9 +++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/aarch64-unknown-none.ld b/aarch64-unknown-none.ld index 31d1b681..2cbab38c 100644 --- a/aarch64-unknown-none.ld +++ b/aarch64-unknown-none.ld @@ -4,9 +4,17 @@ ENTRY(ram64_start) DRAM: [0x4000_0000-0xfc00_0000] FDT: [0x4000_0000-0x401f_ffff) ACPI: [0x4020_0000-0x403f_ffff) - kernel: [0x4048_0000-] - The stack start is at the end of the DRAM region. */ -ram_min = 0x40480000; + payload:[0x4040_0000-0x405f_ffff) + RHF: [0x40600000-] + Assuming 2MB is enough to load payload. + The stack start is at the end of the RHF region. */ +ram_min = 0x40600000; + +/* This value must be identical with arch::aarch64::layout::map::dram::KERNEL_START. */ +PAYLOAD_START = 0x40400000; + +efi_image_size = rhf_end - ram_min; +efi_image_offset = ram_min - PAYLOAD_START; SECTIONS { @@ -41,4 +49,7 @@ SECTIONS *(.symtab) *(.strtab) } + + . = ALIGN(4K); + rhf_end = .; } diff --git a/src/arch/aarch64/ram64.s b/src/arch/aarch64/ram64.s index 93e28e63..d6cff8d9 100644 --- a/src/arch/aarch64/ram64.s +++ b/src/arch/aarch64/ram64.s @@ -3,6 +3,8 @@ .section .text.boot, "ax" .global ram64_start +.global efi_image_size +.global efi_image_offset ram64_start: /* @@ -14,8 +16,8 @@ ram64_start: add x13, x18, #0x16 /* code0: UEFI "MZ" signature magic instruction */ b jump_to_rust /* code1 */ - .quad 0 /* text_offset */ - .quad 0 /* image_size */ + .quad efi_image_offset /* text_offset */ + .quad efi_image_size /* image_size */ .quad 0 /* flags */ .quad 0 /* res2 */ .quad 0 /* res3 */ @@ -34,4 +36,4 @@ jump_to_rust: mov sp, x30 /* x0: pointer to device tree */ - b rust64_start \ No newline at end of file + b rust64_start diff --git a/src/main.rs b/src/main.rs index ed37984f..4e0b2f05 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,9 @@ use core::panic::PanicInfo; #[cfg(target_arch = "x86_64")] use x86_64::instructions::hlt; +#[cfg(target_arch = "aarch64")] +use crate::arch::aarch64::layout::code_range; + #[macro_use] mod serial; @@ -132,6 +135,12 @@ fn boot_from_device(device: &mut block::VirtioBlockDevice, info: &dyn bootinfo:: } }; + #[cfg(target_arch = "aarch64")] + if code_range().start < (info.kernel_load_addr() + size) as usize { + log!("Error Boot Image is too large"); + return false; + } + log!("Executable loaded"); efi::efi_exec(entry_addr, load_addr, size, info, &f, device); true