I started writing a new iteration of my kernel from scratch, taking inspiration from multiple locations (including James Molley's Kernel tutorials, a little from Bran's Kernel tutorials, and some from BrokenThorne tutorials). I have managed to construct a simple bootloader that finds and loads the kernel image into memory at 0x10000 after setting up the GDT and enabling the A20 gate. My kernel then flushes the GDT (essentially reinitializing it), sets up the IDT and the IVT, and starts the PIT. I decided to go ahead and start working on memory management based on BrokenThorne's tutorials, as I've done in the past, but this time whenever I initialize the Physical Memory Manager (PMM) it crashes the OS.
Code: Select all
void pmm_init(uint32_t size, uint32_t bitmap) {
pmm_memory_size = size;
pmm_bitmap = (uint32_t *)bitmap;
pmm_max_blocks = (pmm_memory_size * 1024) / PMM_BLOCK_SIZE;
pmm_used_blocks = pmm_max_blocks;
// By default, all memory is in use
printf("%x | size: %x\n", pmm_bitmap, pmm_max_blocks / PMM_BLOCKS_PER_BYTE);
memset((void *)pmm_bitmap, 0xF, (pmm_max_blocks / PMM_BLOCKS_PER_BYTE));
}
Code: Select all
uint8_t * memset(uint8_t * dest, uint8_t val, size_t len) {
for (; len != 0; len--) {
*dest++ = val;
}
return dest;
}
If anyone has any ideas on what might be the cause of the issue here, I would love to hear them. I have attached my code below for reference.
Another quick thing that I have noted is that if I keep hardware interrupts disabled (never call "sti" from my kernel) then the issue "disappears", although the next printed line is in a weird location.
Also, if I add 6 sectors to the kernel size when initializing the memory, the issue vanishes, but I don't want to use arbitrary numbers if I have no idea why they would be needed in the first place. All I know is that the OS loads the correct number of sectors (17 sectors since the binary image is 8548 bytes) so the starting location for my PMM Bitmap (0x10000 + (17 * 512)) shouldn't conflict with the kernel, and I know the memory (based on the memory map) between 0x100000 and 0x7EE0000 is available for use.
Thanks in advance!