I've been reading and follow a combination of Bran's and James Molloy's tutorials for kernel development. I'm currently on James Molloy's tutorial for paging. I understand that cr3 needs a physical address to the page table. What I don't understand is how James Molloy's kmalloc accomplishes giving both a physical and virtual address.
A link to the tutorial is here.
The relevant code is here:
Code: Select all
u32int kmalloc(u32int sz, int align, u32int *phys)
{
if (align == 1 && (placement_address & 0xFFFFF000)) // If the address is not already page-aligned
{
// Align it.
placement_address &= 0xFFFFF000;
placement_address += 0x1000;
}
if (phys)
{
*phys = placement_address;
}
u32int tmp = placement_address;
placement_address += sz;
return tmp;
}
Can someone explain this to me?