Thinner phy page pre-booking
This commit is contained in:
parent
32446b3603
commit
4887984322
@ -71,7 +71,7 @@ static inline void __native_flush_tlb_single(unsigned long addr)
|
||||
asm volatile("invlpg (%0)" ::"r"(addr) : "memory");
|
||||
}
|
||||
|
||||
int pagingSetup(paddr_t upperKernelAddr)
|
||||
int pagingSetup(paddr_t lowerKernelAddr, paddr_t upperKernelAddr)
|
||||
{
|
||||
struct pdbr cr3;
|
||||
|
||||
@ -85,7 +85,7 @@ int pagingSetup(paddr_t upperKernelAddr)
|
||||
|
||||
// MMU not enabled for the moment. No need to use mirroring
|
||||
// Identity mapping up to upperKernelAddr
|
||||
for (paddr_t i = 0; i < upperKernelAddr; i += PAGE_SIZE) {
|
||||
for (paddr_t i = lowerKernelAddr; i < upperKernelAddr; i += PAGE_SIZE) {
|
||||
uint pdEntry = i >> (PD_SHIFT);
|
||||
uint ptEntry = (i >> PT_SHIFT) & PTE_MASK;
|
||||
struct pte *pt;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#define PAGING_MEM_READ (1U << 1)
|
||||
#define PAGING_MEM_WRITE (1U << 2)
|
||||
|
||||
int pagingSetup(paddr_t upperKernelAddr);
|
||||
int pagingSetup(paddr_t lowerKernelAddr, paddr_t upperKernelAddr);
|
||||
|
||||
int pageMap(vaddr_t vaddr, paddr_t paddr, int flags);
|
||||
int pageUnmap(vaddr_t vaddr);
|
||||
|
@ -2,3 +2,5 @@
|
||||
#include "paging.h"
|
||||
|
||||
void areaInit(void);
|
||||
vaddr_t areaAlloc(unsigned int nbPages);
|
||||
int areaFree(vaddr_t addr);
|
||||
|
16
core/main.c
16
core/main.c
@ -40,6 +40,7 @@ void kmain(unsigned long magic, unsigned long addr)
|
||||
unsigned long upperMemKB = 0;
|
||||
int memMapAvailable = 0;
|
||||
paddr_t lastUsedByMem;
|
||||
paddr_t firstUsedByMem;
|
||||
|
||||
VGASetup(BLACK, GREEN);
|
||||
|
||||
@ -82,6 +83,7 @@ void kmain(unsigned long magic, unsigned long addr)
|
||||
if (CHECK_FLAG(mbi->flags, 6)) {
|
||||
memMapAvailable = 1;
|
||||
}
|
||||
printf("Framebuffer from 0x%llx size (%dx%d) pitch %d bpp %d\n", mbi->framebuffer_addr, mbi->framebuffer_width, mbi->framebuffer_height, mbi->framebuffer_pitch, mbi->framebuffer_bpp);
|
||||
}
|
||||
|
||||
if (upperMemKB == 0) {
|
||||
@ -90,7 +92,8 @@ void kmain(unsigned long magic, unsigned long addr)
|
||||
}
|
||||
|
||||
printf("Setting up Mem\n");
|
||||
memSetup(upperMemKB, &lastUsedByMem);
|
||||
|
||||
memSetup(upperMemKB, &firstUsedByMem, &lastUsedByMem);
|
||||
|
||||
if (memMapAvailable) {
|
||||
multiboot_info_t *mbi = (multiboot_info_t *)addr;
|
||||
@ -102,20 +105,27 @@ void kmain(unsigned long magic, unsigned long addr)
|
||||
for (uint i = 0; i < size; i++) {
|
||||
printf(" base_addr 0x%llx, length = 0x%llx, type = 0x%x\n", mmap[i].addr,
|
||||
mmap[i].len, (uint32_t)mmap[i].type);
|
||||
if(mmap[i].addr < 0x100000){ //Consider low memory taken (https://wiki.osdev.org/Detecting_Memory_(x86). For example by VGA
|
||||
continue;
|
||||
}
|
||||
memAddBank(max(mmap[i].addr, (multiboot_uint64_t)lastUsedByMem),
|
||||
mmap[i].addr + mmap[i].len, mmap[i].type == MULTIBOOT_MEMORY_AVAILABLE);
|
||||
}
|
||||
} else {
|
||||
printf("Cannot get memory Mapping information, using default value\n");
|
||||
memAddBank(0, lastUsedByMem, 0);
|
||||
memAddBank(lastUsedByMem, upperMemKB * 1024, 1);
|
||||
}
|
||||
printf("%d pages taken by kernel(0x%x->0x%x))\n", (lastUsedByMem - firstUsedByMem)/PAGE_SIZE, firstUsedByMem, lastUsedByMem);
|
||||
printf("with %d pages taken for memory management\n", (lastUsedByMem - (paddr_t)&__ld_kernel_end)/PAGE_SIZE);
|
||||
|
||||
#ifdef RUN_TEST
|
||||
testPhymem();
|
||||
#endif
|
||||
printf("Setting up Pagination\n");
|
||||
pagingSetup(lastUsedByMem);
|
||||
pagingSetup(firstUsedByMem, lastUsedByMem);
|
||||
for (paddr_t i = VGA_ADDR; i < VGA_ADDR + VGA_WIDTH * VGA_HEIGHT * sizeof(short) ; i += PAGE_SIZE) {
|
||||
pageMap(i, i, PAGING_MEM_WRITE);
|
||||
}
|
||||
|
||||
printf("Setting up IRQ handlers\n");
|
||||
irqSetRoutine(IRQ_KEYBOARD, keyboard_handler);
|
||||
|
13
core/mem.c
13
core/mem.c
@ -1,5 +1,5 @@
|
||||
#include "assert.h"
|
||||
#include "mem.h"
|
||||
#include "assert.h"
|
||||
#include "kernel.h"
|
||||
#include "klibc.h"
|
||||
#include "list.h"
|
||||
@ -13,7 +13,7 @@ paddr_t upperMem;
|
||||
|
||||
static unsigned long allocatedPage = 0;
|
||||
|
||||
int memSetup(paddr_t upperMemKB, paddr_t *lastMemUsedOut)
|
||||
int memSetup(paddr_t upperMemKB, paddr_t *firstUsed, paddr_t *lastMemUsedOut)
|
||||
{
|
||||
list_init(freePage);
|
||||
list_init(usedPage);
|
||||
@ -30,8 +30,13 @@ int memSetup(paddr_t upperMemKB, paddr_t *lastMemUsedOut)
|
||||
pageDescEnd = (unsigned long)pageDesc + nbPage * sizeof(struct memDesc);
|
||||
*lastMemUsedOut = ALIGN(pageDescEnd, PAGE_SIZE);
|
||||
upperMem = upperMemKB * 1024;
|
||||
*firstUsed = ALIGN_DOWN((paddr_t)&__ld_kernel_begin, PAGE_SIZE);
|
||||
|
||||
// Remove addr from 0 to PAGE_SIZE so we can return 0 for no page available
|
||||
memAddBank(0, PAGE_SIZE, 0);
|
||||
|
||||
memAddBank(*lastMemUsedOut, *lastMemUsedOut, 0);
|
||||
|
||||
memAddBank(0, *lastMemUsedOut, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -136,7 +141,7 @@ int unrefPhyPage(paddr_t addr)
|
||||
if (!mem) {
|
||||
return -1;
|
||||
}
|
||||
assert(mem->ref >0);
|
||||
assert(mem->ref > 0);
|
||||
mem->ref--;
|
||||
if (mem->ref == 0) {
|
||||
allocatedPage--;
|
||||
|
@ -15,7 +15,7 @@ struct memDesc {
|
||||
struct memDesc *next, *prev;
|
||||
};
|
||||
|
||||
int memSetup(paddr_t upperMem, paddr_t *lastUsed);
|
||||
int memSetup(paddr_t upperMem, paddr_t * firstUsed, paddr_t *lastUsed);
|
||||
int memAddBank(paddr_t bottomMem, paddr_t topMem, int isFree);
|
||||
paddr_t allocPhyPage(uint nbPage);
|
||||
int unrefPhyPage(paddr_t addr);
|
||||
|
Loading…
Reference in New Issue
Block a user