[SOLVED]bootloader can't write to memory at 0xC0000000 which is 3GB on Qemu
Posted: Wed Aug 28, 2024 6:42 am
I'm writing a bootloader to load my kernel to memory address 0xC0000000. It is at the 3GB offset.
I've tested my bootloader on both Qemu and my laptop. It works on laptop but failed on Qemu.
I use gdb to find out what's wrong. No matter what did I write to memory larger than 0xC0000000, I got zeros whan I read it back. In GDB, it says can't access memory at 0xC0000000. The last bytes accessable is 0xBFFFFFFF which is 3GB - 1Byte.
Command to run Qemu:
`qemu-system-i386 -m 5G -serial stdio disk.img`
Part of my source code:
My bootloader is working in 32bit protected mode, without page enabled. I use a flat memory model for all 4GB memory address space in GDT.
I've tested my bootloader on both Qemu and my laptop. It works on laptop but failed on Qemu.
I use gdb to find out what's wrong. No matter what did I write to memory larger than 0xC0000000, I got zeros whan I read it back. In GDB, it says can't access memory at 0xC0000000. The last bytes accessable is 0xBFFFFFFF which is 3GB - 1Byte.
Command to run Qemu:
`qemu-system-i386 -m 5G -serial stdio disk.img`
Part of my source code:
Code: Select all
uint8_t *buffer = (uint8_t *)(1024U * 1024 * 1024 * 3);
memset(buffer, 0, kernel_size);
for (uint32_t i = 0; i < 32; i++) {
buffer[i] = i; // write test value to 0xC0000000
}
printf("memory at 0xc0000000:\n");
print_memory(buffer, 32); // all are zeros
My bootloader is working in 32bit protected mode, without page enabled. I use a flat memory model for all 4GB memory address space in GDT.