src/kernel/mm/vmm.c
/**
 * Mapping a virtual address to a physical one.
 * 
 * @param phys Physical address to map.
 * @param virt Virtual address to map phys to.
 * @param flags Flags.
 * 
 * @return If everything went well.
 */
Mapping a virtual address to a physical one.

@param phys Physical address to map.
@param virt Virtual address to map phys to.
@param flags Flags.

@return If everything went well.
Mapping a virtual address to a physical one . @param phys Physical address to map . @param virt Virtual address to map phys to . @param flags Flags . @return If everything went well .
bool vMapPage(void *phys, void *virt, uint32_t flags) {
	if (((uint32_t)virt & 0xFFFFF000) != (uint32_t)virt)
		return false;
	uint32_t *pd = PD_VADDR;
	if (!(pd[PAGE_DIRECTORY_INDEX((uint32_t)virt)] & 1)) {
		uint32_t *new_pt = (uint32_t *)pAllocPage();
		pd[PAGE_DIRECTORY_INDEX((uint32_t)virt)] = (uint32_t)new_pt | flags;
	}
	uint32_t *pt = (uint32_t *)(PT_BASE_VADDR + (PAGE_DIRECTORY_INDEX((uint32_t)virt) * 0x1000));
	if (!(pt[PAGE_TABLE_INDEX((uint32_t)virt)] & 1)) {
		pt[PAGE_TABLE_INDEX((uint32_t)virt)] = (uint32_t)phys | flags;
	} else
		return false;
	printf("physical address 0x%x mapped at 0x%x with flags 0x%x\n", phys, virt, flags);
	return true;
}
bool vMapPage ( void * phys , void * virt , uint32_t flags ) { if ( ( ( uint32_t ) virt & 0xFFFFF000 ) != ( uint32_t ) virt ) return false ; uint32_t * pd = PD_VADDR ; if ( ! ( pd [ PAGE_DIRECTORY_INDEX ( ( uint32_t ) virt ) ] & 1 ) ) { uint32_t * new_pt = ( uint32_t * ) pAllocPage ( ) ; pd [ PAGE_DIRECTORY_INDEX ( ( uint32_t ) virt ) ] = ( uint32_t ) new_pt | flags ; } uint32_t * pt = ( uint32_t * ) ( PT_BASE_VADDR + ( PAGE_DIRECTORY_INDEX ( ( uint32_t ) virt ) * 0x1000 ) ) ; if ( ! ( pt [ PAGE_TABLE_INDEX ( ( uint32_t ) virt ) ] & 1 ) ) { pt [ PAGE_TABLE_INDEX ( ( uint32_t ) virt ) ] = ( uint32_t ) phys | flags ; } else return false ; printf ( " \n " , phys , virt , flags ) ; return true ; }
Mapping a virtual address to a physical one.
Mapping a virtual address to a physical one .
// Verify that the address is page-aligned // The page table doesn't exists // Create a new one and map it into the page directory // The page isn't present