Closed br0kenpixel closed 4 months ago
boot_info.memory_regions
contains physical addresses, not virtual addresses. In order to access the memory you first have to translate the physical addresses into virtual addresses e.g. by adding boot_info.physical_memory_offset
.
Thanks! That made it work! By the way, is there a way to calculate/get the physical memory size? Adding up the sizes of all usable regions is not even close to the memory given to the VM. I know, some of it will be reserved, but still. I always get 176128
bytes of total usable memory no matter how much I give the VM (using the -m
flag).
Thanks! That made it work! By the way, is there a way to calculate/get the physical memory size? Adding up the sizes of all usable regions is not even close to the memory given to the VM. I know, some of it will be reserved, but still. I always get
176128
bytes of total usable memory no matter how much I give the VM (using the-m
flag).
Adding up all the regions should work. 176128 sounds suspiciously low. If you want to share your code, I can take a look at it.
I'm trying to use the
MemoryRegions
provided byBootInfo
to store data. However I have noticed that writing to any region (marked asMemoryRegionKind::Usable
) causes QEMU to reboot the VM. I'm assuming it's probably because of some access violation.My
kernel_main()
:Bootloader config
```rust const CONFIG: bootloader_api::BootloaderConfig = { let mut config = bootloader_api::BootloaderConfig::new_default(); config.kernel_stack_size = 100 * 1024; config.mappings.physical_memory = Some(Mapping::Dynamic); config }; ```I'd expect this code to simply write
9
to the first address of a usable region. When running the VM, the start address of this regions is0x3A7000
, and the end address is0x800000
.Things I tried:
skip(1)
- I added this because the first result was always a region starting at address0
, which was suspicious for me.skip(75)
mem.start + 1
insteadI'm using
qemu-system-x86_64 v9.0.0
on macOS Monterey. QEMU Flags: Just-drive format=raw,file={uefi_path}
I don't have any experience writing kernels (I'm mostly just exploring out of curiosity). I'm assuming I have to do more than just create a pointer to those addresses to use them.