pmap cleanup
This commit is contained in:
parent
a7ed1c3ffd
commit
0dbad8b297
@ -45,7 +45,7 @@ PMap_Init()
|
|||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
kprintf("Initializing PMAP ... ");
|
kprintf("Initializing PMAP ...\n");
|
||||||
|
|
||||||
// Setup global state
|
// Setup global state
|
||||||
for (i = 0; i < MAX_CPUS; i++) {
|
for (i = 0; i < MAX_CPUS; i++) {
|
||||||
@ -84,8 +84,6 @@ PMap_Init()
|
|||||||
60*512, PROT_ALL); // 60GB RWX
|
60*512, PROT_ALL); // 60GB RWX
|
||||||
|
|
||||||
PMap_LoadAS(&systemAS);
|
PMap_LoadAS(&systemAS);
|
||||||
|
|
||||||
kprintf("Done!\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -12,10 +12,14 @@
|
|||||||
* Page Tables
|
* Page Tables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PGSHIFT (14)
|
#define PGSHIFT (14ull)
|
||||||
#define PGSIZE (1 << PGSHIFT)
|
#define PGSIZE (1ull << PGSHIFT)
|
||||||
#define PGMASK (PGSIZE - 1)
|
#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 ROUNDUP_PGSIZE(x) (((x) + LARGE_PGSIZE - 1) & ~LARGE_PGMASK)
|
||||||
#define ROUNDDOWN_PGSIZE(x) ((x) & ~LARGE_PGMASK)
|
#define ROUNDDOWN_PGSIZE(x) ((x) & ~LARGE_PGMASK)
|
||||||
|
|
||||||
|
@ -3,13 +3,6 @@
|
|||||||
#include <machine/pmap.h>
|
#include <machine/pmap.h>
|
||||||
#include <sys/types.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)
|
// Page Table Pointer (points to a list of struct vmpd)
|
||||||
//
|
//
|
||||||
|
@ -83,11 +83,12 @@ void Machine_Init()
|
|||||||
{
|
{
|
||||||
Machine_EarlyInit();
|
Machine_EarlyInit();
|
||||||
|
|
||||||
|
kprintf("Initializing GIC ...\n");
|
||||||
if (gic_init() != 0) {
|
if (gic_init() != 0) {
|
||||||
PANIC("gic initialization failed!\n");
|
PANIC("gic initialization failed!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
kprintf("Initialized GIC.\n");
|
kprintf("GIC initialized.\n");
|
||||||
|
|
||||||
// enable hardware timer
|
// enable hardware timer
|
||||||
// __asm__ volatile (
|
// __asm__ volatile (
|
||||||
@ -113,12 +114,12 @@ void Machine_Init()
|
|||||||
PAlloc_AddRegion(DMPA2VA(16*1024*1024), 16*1024*1024);
|
PAlloc_AddRegion(DMPA2VA(16*1024*1024), 16*1024*1024);
|
||||||
pdcache_init();
|
pdcache_init();
|
||||||
PMap_Init();
|
PMap_Init();
|
||||||
while(1){
|
|
||||||
hlt();
|
|
||||||
}
|
|
||||||
XMem_Init();
|
XMem_Init();
|
||||||
PAlloc_LateInit();
|
PAlloc_LateInit();
|
||||||
MachineBoot_AddMem();
|
MachineBoot_AddMem();
|
||||||
|
while(1){
|
||||||
|
hlt();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize Time Keeping
|
* Initialize Time Keeping
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "machine/cpu.h"
|
#include <machine/cpu.h>
|
||||||
#include <machine/metal.h>
|
#include <machine/metal.h>
|
||||||
#include <machine/mrt.h>
|
#include <machine/mrt.h>
|
||||||
#include <machine/paging.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;
|
paddr_t addr = 0;
|
||||||
if (uva >= MEM_USERSPACE_BASE && uva < MEM_USERSPACE_TOP) {
|
if (uva >= MEM_USERSPACE_BASE && uva < MEM_USERSPACE_TOP) {
|
||||||
METAL_RMR(METAL_REG_MPTB_USER, addr);
|
METAL_RMR(METAL_REG_MPTB_USER, addr);
|
||||||
*pgshift = REGION_USER_PGSHIFT;
|
*pgshift = PGSHIFT;
|
||||||
} else if (uva >= MEM_DIRECTMAP_BASE && uva < MEM_DIRECTMAP_TOP) {
|
} else if (uva >= MEM_DIRECTMAP_BASE && uva < MEM_DIRECTMAP_TOP) {
|
||||||
METAL_RMR(METAL_REG_MPTB_DMAP, addr);
|
METAL_RMR(METAL_REG_MPTB_DMAP, addr);
|
||||||
*pgshift = REGION_DMAP_PGSHIFT;
|
*pgshift = LARGE_PGSHIFT;
|
||||||
} else if (uva >= MEM_XMAP_BASE && uva < MEM_XMAP_TOP) {
|
} else if (uva >= MEM_XMAP_BASE && uva < MEM_XMAP_TOP) {
|
||||||
METAL_RMR(METAL_REG_MPTB_XMEM, addr);
|
METAL_RMR(METAL_REG_MPTB_XMEM, addr);
|
||||||
*pgshift = REGION_XMEM_PGSHIFT;
|
*pgshift = PGSHIFT;
|
||||||
} else {
|
} else {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "machine/cpu.h"
|
||||||
#include <machine/metalp.h>
|
#include <machine/metalp.h>
|
||||||
#include <machine/paging.h>
|
#include <machine/paging.h>
|
||||||
#include <machine/pmap.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].attr = VMPD_ATTR_P | VMPD_ATTR_AO_KRW;
|
||||||
boot_pd[i].paddr = cur;
|
boot_pd[i].paddr = cur;
|
||||||
boot_pd[i].vaddr = MEM_DIRECTMAP_BASE + 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
|
// 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].attr = VMPD_ATTR_P | VMPD_ATTR_DEV | VMPD_ATTR_AO_KRW;
|
||||||
boot_dev_pd[i].paddr = cur;
|
boot_dev_pd[i].paddr = cur;
|
||||||
boot_dev_pd[i].vaddr = MEM_DIRECTMAP_DEV_BASE + 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
|
// set page table base
|
||||||
|
@ -79,7 +79,7 @@ pdcache_grow()
|
|||||||
pdc.first = first;
|
pdc.first = first;
|
||||||
pdc.total += free;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
#include "include/cpu.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -62,7 +63,7 @@ PMapAllocPageTable()
|
|||||||
void
|
void
|
||||||
PMap_Init()
|
PMap_Init()
|
||||||
{
|
{
|
||||||
kprintf("Initializing PMAP ... ");
|
kprintf("Initializing PMAP ...\n");
|
||||||
|
|
||||||
// Setup global state
|
// Setup global state
|
||||||
for (int i = 0; i < MAX_CPUS; i++) {
|
for (int i = 0; i < MAX_CPUS; i++) {
|
||||||
@ -80,19 +81,19 @@ PMap_Init()
|
|||||||
|
|
||||||
// Setup system mappings
|
// Setup system mappings
|
||||||
if(!PMap_SystemLMap(0x0, MEM_DIRECTMAP_BASE,
|
if(!PMap_SystemLMap(0x0, MEM_DIRECTMAP_BASE,
|
||||||
4, PROT_ALL)) // 128GB RWX
|
512, PROT_ALL)) // 128GB RWX
|
||||||
{
|
{
|
||||||
PANIC("Cannot setup direct map");
|
PANIC("Cannot setup direct map");
|
||||||
}
|
}
|
||||||
if(!PMap_SystemLMap(0x0, MEM_DIRECTMAP_DEV_BASE,
|
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");
|
PANIC("Cannot setup device map");
|
||||||
}
|
}
|
||||||
|
|
||||||
PMap_LoadAS(&systemAS);
|
PMap_LoadAS(&systemAS);
|
||||||
|
|
||||||
kprintf("Done!\n");
|
kprintf("PMAP initialized.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -259,11 +260,11 @@ bool
|
|||||||
PMap_Map(AS *as, uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
|
PMap_Map(AS *as, uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
|
||||||
{
|
{
|
||||||
// virt address must be within the usermap region
|
// 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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -343,11 +344,11 @@ bool
|
|||||||
PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags)
|
PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags)
|
||||||
{
|
{
|
||||||
// virt address must be within the dmap (l map) region
|
// 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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,11 +370,11 @@ bool
|
|||||||
PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
|
PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
|
||||||
{
|
{
|
||||||
// virt address must be within the xmem region
|
// 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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user