diff --git a/sys/amd64/pmap.c b/sys/amd64/pmap.c index 2c94e5f..75ddbca 100644 --- a/sys/amd64/pmap.c +++ b/sys/amd64/pmap.c @@ -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 diff --git a/sys/arm64/include/cpu.h b/sys/arm64/include/cpu.h index 9d82419..aad929f 100644 --- a/sys/arm64/include/cpu.h +++ b/sys/arm64/include/cpu.h @@ -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) diff --git a/sys/arm64/include/paging.h b/sys/arm64/include/paging.h index e5b624c..ee2b794 100644 --- a/sys/arm64/include/paging.h +++ b/sys/arm64/include/paging.h @@ -3,13 +3,6 @@ #include #include -// 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) // diff --git a/sys/arm64/machine.c b/sys/arm64/machine.c index 1e1c5bc..b4d79d2 100644 --- a/sys/arm64/machine.c +++ b/sys/arm64/machine.c @@ -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 diff --git a/sys/arm64/mrt/paging.c b/sys/arm64/mrt/paging.c index d5a7cfd..da2cda4 100644 --- a/sys/arm64/mrt/paging.c +++ b/sys/arm64/mrt/paging.c @@ -1,4 +1,4 @@ -#include "machine/cpu.h" +#include #include #include #include @@ -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; } diff --git a/sys/arm64/paging.c b/sys/arm64/paging.c index 951b9a1..b23d0da 100644 --- a/sys/arm64/paging.c +++ b/sys/arm64/paging.c @@ -1,3 +1,4 @@ +#include "machine/cpu.h" #include #include #include @@ -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 diff --git a/sys/arm64/pdcache.c b/sys/arm64/pdcache.c index 8ec7bb8..3075915 100644 --- a/sys/arm64/pdcache.c +++ b/sys/arm64/pdcache.c @@ -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; } diff --git a/sys/arm64/pmap.c b/sys/arm64/pmap.c index fcd6968..d3f355a 100644 --- a/sys/arm64/pmap.c +++ b/sys/arm64/pmap.c @@ -1,4 +1,5 @@ +#include "include/cpu.h" #include #include #include @@ -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; }