Closed tsatke closed 9 months ago
Are you compiling your kernel as position independent or as static? The bootloader maps static kernel executables at the virtual address specified in the ELF file, which you can override through a linker command (e.g. --image-base
) or a linker script. For dynamic mappings, you can specify a lower address bound in the bootloader config via dynamic_range_start
.
I'm not sure. I'm just doing cargo build
. This is my repo: https://github.com/tsatke/devos
My rustflags:
[target.x86_64-unknown-none]
rustflags = [
"-C", "link-arg=-z",
"-C", "link-arg=nostart-stop-gc",
"-g"
]
So this should be a PIC, right? I've followed your blog posts a while back @phil-opp, and migrated to 0.11 following the migration guide (if that helps).
I'm not doing any of the things you've mentioned (--image-base
, linker script etc.).
EDIT:
I've now tried "-C", "link-arg=--image-base=0x800000000000"
and "-C", "link-args=--image-base=0x800000000000"
, both didn't error, but also didn't work (same result).
EDIT2:
I've looked through the test kernels (specifically the higher half one), where it says config.mappings.dynamic_range_start = Some(0xffff_8000_0000_0000);
, which I guess is what I'm looking for (I've seen that, but from the docs, I didn't understand that that was what I was looking for). I thought it was higher half by default.
This is my bootloader config.
On boot, when printing
boot_info.kernel_image_offset
, I get0x0000_0080_0019_6e00
although I would have expected0x0000_8000_0019_6e00
(or similar). As I understand it, this would only leave0x0
-0x80_0000_0000
(512GiB) to the userspace as everything above would be kernel space? Am I missing a config? Am I misunderstanding something?I've looked through the bootloader code and it seems like that offset is determined by the elf file (
load_kernel.rs:59-90
). Shouldn't this be determined by the bootloader and probably be configurable? At this point, I feel like I'm misunderstanding theboot_info.kernel_image_offset
.