pmap cleanup

This commit is contained in:
quackerd 2024-10-20 05:14:55 -04:00
parent a7ed1c3ffd
commit 0dbad8b297
8 changed files with 33 additions and 35 deletions

View File

@ -45,7 +45,7 @@ PMap_Init()
{
int i, j;
kprintf("Initializing PMAP ... ");
kprintf("Initializing PMAP ...\n");
// Setup global state
for (i = 0; i < MAX_CPUS; i++) {
@ -84,8 +84,6 @@ PMap_Init()
60*512, PROT_ALL); // 60GB RWX
PMap_LoadAS(&systemAS);
kprintf("Done!\n");
}
void

View File

@ -12,10 +12,14 @@
* Page Tables
*/
#define PGSHIFT (14)
#define PGSIZE (1 << PGSHIFT)
#define PGSHIFT (14ull)
#define PGSIZE (1ull << PGSHIFT)
#define PGMASK (PGSIZE - 1)
#define LARGE_PGSHIFT (30ull)
#define LARGE_PGSIZE (1ull << LARGE_PGSHIFT)
#define LARGE_PGMASK (LARGE_PGSIZE - 1)
#define ROUNDUP_PGSIZE(x) (((x) + LARGE_PGSIZE - 1) & ~LARGE_PGMASK)
#define ROUNDDOWN_PGSIZE(x) ((x) & ~LARGE_PGMASK)

View File

@ -3,13 +3,6 @@
#include <machine/pmap.h>
#include <sys/types.h>
// 1GB page ident map region
#define REGION_DMAP_PGSHIFT (30)
// 16K page userspace
#define REGION_USER_PGSHIFT (14)
// 16K page XMEM region
#define REGION_XMEM_PGSHIFT (14)
//
// Page Table Pointer (points to a list of struct vmpd)
//

View File

@ -83,11 +83,12 @@ void Machine_Init()
{
Machine_EarlyInit();
kprintf("Initializing GIC ...\n");
if (gic_init() != 0) {
PANIC("gic initialization failed!\n");
}
kprintf("Initialized GIC.\n");
kprintf("GIC initialized.\n");
// enable hardware timer
// __asm__ volatile (
@ -113,12 +114,12 @@ void Machine_Init()
PAlloc_AddRegion(DMPA2VA(16*1024*1024), 16*1024*1024);
pdcache_init();
PMap_Init();
while(1){
hlt();
}
XMem_Init();
PAlloc_LateInit();
MachineBoot_AddMem();
while(1){
hlt();
}
/*
* Initialize Time Keeping

View File

@ -1,4 +1,4 @@
#include "machine/cpu.h"
#include <machine/cpu.h>
#include <machine/metal.h>
#include <machine/mrt.h>
#include <machine/paging.h>
@ -20,13 +20,13 @@ vmm_get_ptb(vaddr_t uva, paddr_t * paddr, unsigned int * pgshift)
paddr_t addr = 0;
if (uva >= MEM_USERSPACE_BASE && uva < MEM_USERSPACE_TOP) {
METAL_RMR(METAL_REG_MPTB_USER, addr);
*pgshift = REGION_USER_PGSHIFT;
*pgshift = PGSHIFT;
} else if (uva >= MEM_DIRECTMAP_BASE && uva < MEM_DIRECTMAP_TOP) {
METAL_RMR(METAL_REG_MPTB_DMAP, addr);
*pgshift = REGION_DMAP_PGSHIFT;
*pgshift = LARGE_PGSHIFT;
} else if (uva >= MEM_XMAP_BASE && uva < MEM_XMAP_TOP) {
METAL_RMR(METAL_REG_MPTB_XMEM, addr);
*pgshift = REGION_XMEM_PGSHIFT;
*pgshift = PGSHIFT;
} else {
return EINVAL;
}

View File

@ -1,3 +1,4 @@
#include "machine/cpu.h"
#include <machine/metalp.h>
#include <machine/paging.h>
#include <machine/pmap.h>
@ -26,9 +27,9 @@ void paging_init()
boot_pd[i].attr = VMPD_ATTR_P | VMPD_ATTR_AO_KRW;
boot_pd[i].paddr = cur;
boot_pd[i].vaddr = MEM_DIRECTMAP_BASE + cur;
cur += (1 << REGION_DMAP_PGSHIFT);
cur += LARGE_PGSIZE;
vm_insert_pd(&boot_pt, &boot_pd[i], REGION_DMAP_PGSHIFT, (paddr_t)DMVA2PA(&boot_pd[i]));
vm_insert_pd(&boot_pt, &boot_pd[i], LARGE_PGSHIFT, (paddr_t)DMVA2PA(&boot_pd[i]));
}
// ident map the first 4GB to device memory space
@ -37,9 +38,9 @@ void paging_init()
boot_dev_pd[i].attr = VMPD_ATTR_P | VMPD_ATTR_DEV | VMPD_ATTR_AO_KRW;
boot_dev_pd[i].paddr = cur;
boot_dev_pd[i].vaddr = MEM_DIRECTMAP_DEV_BASE + cur;
cur += (1 << REGION_DMAP_PGSHIFT);
cur += LARGE_PGSHIFT;
vm_insert_pd(&boot_pt, &boot_dev_pd[i], REGION_DMAP_PGSHIFT, (paddr_t)DMVA2PA(&boot_dev_pd[i]));
vm_insert_pd(&boot_pt, &boot_dev_pd[i], LARGE_PGSHIFT, (paddr_t)DMVA2PA(&boot_dev_pd[i]));
}
// set page table base

View File

@ -79,7 +79,7 @@ pdcache_grow()
pdc.first = first;
pdc.total += free;
kprintf("\nGrowing pdcache: +%d nodes, first: 0x%llx, free: %d nodes, total: %d nodes.\n", free, pdc.first, pdc.free, pdc.total);
kprintf("Growing pdcache: +%d nodes, free: %d nodes, total: %d nodes.\n", free, pdc.free, pdc.total);
return 0;
}

View File

@ -1,4 +1,5 @@
#include "include/cpu.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
@ -62,7 +63,7 @@ PMapAllocPageTable()
void
PMap_Init()
{
kprintf("Initializing PMAP ... ");
kprintf("Initializing PMAP ...\n");
// Setup global state
for (int i = 0; i < MAX_CPUS; i++) {
@ -80,19 +81,19 @@ PMap_Init()
// Setup system mappings
if(!PMap_SystemLMap(0x0, MEM_DIRECTMAP_BASE,
4, PROT_ALL)) // 128GB RWX
512, PROT_ALL)) // 128GB RWX
{
PANIC("Cannot setup direct map");
}
if(!PMap_SystemLMap(0x0, MEM_DIRECTMAP_DEV_BASE,
4, PROT_ALL | MAP_NOCACHE)) // 128GB Device
512, PROT_ALL | MAP_NOCACHE)) // 128GB Device
{
PANIC("Cannot setup device map");
}
PMap_LoadAS(&systemAS);
kprintf("Done!\n");
kprintf("PMAP initialized.\n");
}
void
@ -259,11 +260,11 @@ bool
PMap_Map(AS *as, uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
{
// virt address must be within the usermap region
if (virt < MEM_USERSPACE_BASE || virt + pages * (1ull << REGION_USER_PGSHIFT) > MEM_USERSPACE_TOP) {
if (virt < MEM_USERSPACE_BASE || virt + pages * PGSIZE > MEM_USERSPACE_TOP) {
return false;
}
PMap_MapPage(phys, virt, pages, REGION_USER_PGSHIFT,as->user_tbl, PMapProtToPdattr(flags, false));
PMap_MapPage(phys, virt, pages, PGSHIFT,as->user_tbl, PMapProtToPdattr(flags, false));
return true;
}
@ -343,11 +344,11 @@ bool
PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags)
{
// virt address must be within the dmap (l map) region
if (virt < MEM_DIRECTMAP_BASE || virt + lpages * (1ull << REGION_DMAP_PGSHIFT) > MEM_DIRECTMAP_TOP) {
if (virt < MEM_DIRECTMAP_BASE || virt + lpages * LARGE_PGSIZE > MEM_DIRECTMAP_TOP) {
return false;
}
PMap_MapPage(phys, virt, lpages, REGION_DMAP_PGSHIFT, systemAS.dmap_tbl, PMapProtToPdattr(flags, true));
PMap_MapPage(phys, virt, lpages, LARGE_PGSHIFT, systemAS.dmap_tbl, PMapProtToPdattr(flags, true));
return true;
}
@ -369,11 +370,11 @@ bool
PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
{
// virt address must be within the xmem region
if (virt < MEM_XMAP_BASE || virt + pages * (1ull << REGION_XMEM_PGSHIFT) > MEM_XMAP_TOP) {
if (virt < MEM_XMAP_BASE || virt + pages * PGSIZE > MEM_XMAP_TOP) {
return false;
}
PMap_MapPage(phys, virt, pages, REGION_XMEM_PGSHIFT, systemAS.xmem_tbl, PMapProtToPdattr(flags, true));
PMap_MapPage(phys, virt, pages, PGSHIFT, systemAS.xmem_tbl, PMapProtToPdattr(flags, true));
return true;
}