feat: mémoire paginée...

This commit is contained in:
Nicolas Hordé 2018-11-23 09:00:59 +01:00
parent 6acbddab8d
commit f0a64729ee
2 changed files with 34 additions and 14 deletions

View File

@ -89,6 +89,11 @@ u8* physical_page_getfree(void);
void physical_init(void); void physical_init(void);
void initpaging(void); void initpaging(void);
void virtual_init(void); void virtual_init(void);
tmalloc *mallocpage(u8 size);
void *vmalloc(u32 size);
void vfree(void *vaddr);
page *virtual_page_getfree(void);
pd *virtual_pd_create();
/* /*
Fonction à ajouter...pour gestion mémoire virtuelle Fonction à ajouter...pour gestion mémoire virtuelle

View File

@ -72,7 +72,7 @@ void *vmalloc(u32 size)
/*******************************************************************************/ /*******************************************************************************/
/* Libère de la mémoire virtuelle depuis le heap noyau */ /* Libère de la mémoire virtuelle depuis le heap noyau */
void vmfree(void *vaddr) void vfree(void *vaddr)
{ {
tmalloc *chunk, *new; tmalloc *chunk, *new;
chunk = (tmalloc *) (vaddr - sizeof(tmalloc)); chunk = (tmalloc *) (vaddr - sizeof(tmalloc));
@ -207,17 +207,16 @@ page *virtual_page_getfree(void)
paddr = physical_page_getfree(); paddr = physical_page_getfree();
if (paddr == NULL) if (paddr == NULL)
panic ("Plus de memoire physique disponible !\n"); panic ("Plus de memoire physique disponible !\n");
if (TAILQ_EMPTY(&freepages) if (TAILQ_EMPTY(&freepages))
panic ("Plus de place disponible dans la reserve de page !\n"); panic("Plus de place disponible dans la reserve de page !\n");
vpages = TAILQ_FIRST(&freepages); vpages = TAILQ_FIRST(&freepages);
vaddr = vpages->vaddrlow; vaddr = vpages->vaddrlow;
vpages->vaddrlow += PAGESIZE; vpages->vaddrlow += PAGESIZE;
if (pages->vaddrlow == pages->vaddrhigh) { if (vpages->vaddrlow == vpages->vaddrhigh) {
TAILQ_REMOVE(&freepages, vpages, tailq); TAILQ_REMOVE(&freepages, vpages, tailq);
vfree(vpages); vfree(vpages);
} }
pd0_add_page(v_addr, p_addr, 0);*/ virtual_pd_page_add(kerneldirectory,vaddr,paddr, 0);
virtual_pd_page_add(pd,vaddr,paddr, 0)
pg = (page*) vmalloc(sizeof(page)); pg = (page*) vmalloc(sizeof(page));
pg->vaddr = vaddr; pg->vaddr = vaddr;
pg->paddr = paddr; pg->paddr = paddr;
@ -230,23 +229,39 @@ page *virtual_page_getfree(void)
pd *virtual_pd_create() pd *virtual_pd_create()
{ {
pd *new; pd *new;
u32 *pdir,pd0; u32 *pdir,*pd0;
u32 i; u32 i;
pd = (pd *) vmalloc(sizeof(pd)); new = (pd *) vmalloc(sizeof(pd));
pd->addr = virtual_page_getfree(); new->addr = virtual_page_getfree();
if (kerneldirectory!=NULL) if (kerneldirectory!=NULL)
{ {
pdir = (u32 *) pd->base->vaddr; pdir = (u32 *) new->addr->vaddr;
pd0 = (u32 *) kerneldirectory->base->vaddr; pd0 = (u32 *) kerneldirectory->addr->vaddr;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
pdir[i] = pd0[i]; pdir[i] = pd0[i];
for (i = 256; i < 1023; i++) for (i = 256; i < 1023; i++)
pdir[i] = 0; pdir[i] = 0;
pdir[1023] = ((u32) pd->base->p_addr | (PG_PRESENT | PG_WRITE)); pdir[1023] = ((u32) new->addr->paddr | (PAGE_PRESENT | PAGE_WRITE));
} }
TAILQ_INIT(&pd->addr); //TAILQ_INIT(&new->addr);
return pd; return new;
} }
/*******************************************************************************/
/* Destruction d'un directory pour la gestion virtuelle de la mémoire */
void pd_destroy(pd *dst)
{
page *pg;
list_for_each_safe(p, n, &pd->pt) {
pg = list_entry(p, struct page, list);
release_page_from_heap(pg->vaddr);
list_del(p);
vfree(pg);
}
release_page_from_heap(dst->add->vaddr);
vfree(dst);
return 0;
} }
/*******************************************************************************/ /*******************************************************************************/