fix: correction HEAP de page et ajout d'information concernant les pages et la mémoire utilisée

This commit is contained in:
Nicolas Hordé 2018-11-30 11:27:45 +01:00
parent 4f92e419e2
commit b6e2ead659
3 changed files with 48 additions and 6 deletions

View File

@ -110,3 +110,4 @@ void registry_init(void);
u32 getmallocused(void);
u32 getmallocfree(void);
u32 getmallocnonallocated(void);
u32 virtual_getpagesfree();

View File

@ -37,13 +37,29 @@ tmalloc *mallocpage(u8 size)
return chunk;
}
/*******************************************************************************/
/* Retourne le nombre de blocs dynamiques (heap) */
u32 getmallocnb(void)
{
u32 realsize=0;
tmalloc *chunk;
chunk = KERNEL_HEAP;
while (chunk < (tmalloc *) kernelcurrentheap) {
realsize++;
chunk = chunk + chunk->size;
}
return realsize;
}
/*******************************************************************************/
/* Retourne la mémoire virtuelle utilisée de façon dynamique (heap) */
u32 getmallocused(void)
{
u32 realsize=0;
tmalloc *chunk, *new;
tmalloc *chunk;
chunk = KERNEL_HEAP;
while (chunk < (tmalloc *) kernelcurrentheap) {
if (chunk->used)
@ -59,7 +75,7 @@ u32 getmallocused(void)
u32 getmallocfree(void)
{
u32 realsize=0;
tmalloc *chunk, *new;
tmalloc *chunk;
chunk = KERNEL_HEAP;
while (chunk < (tmalloc *) kernelcurrentheap) {
if (!chunk->used)
@ -435,6 +451,28 @@ void virtual_range_new_kernel(u8 *vaddr, u64 len, u32 flags)
virtual_range_new(NULL, vaddr, len, flags);
}
/*******************************************************************************/
/* Renvoie le nombre de pages virtuelles occupées */
u32 virtual_getpagesused()
{
u32 maxpage=((u32) MAXPAGESSIZE)/((u16) PAGESIZE);
return maxpage-virtual_getpagesfree();
}
/*******************************************************************************/
/* Renvoie le nombre de pages virtuelles libres */
u32 virtual_getpagesfree()
{
vrange *next;
u32 realsize=0;
TAILQ_FOREACH(next, &vrange_head, tailq)
realsize+=(next->vaddrhigh - next->vaddrlow)/PAGESIZE;
return realsize;
}
/*******************************************************************************/
/* Libère une page virtuelle de la mémoire */
@ -514,8 +552,8 @@ void malloc_init(void)
void virtual_init(void)
{
vrange *vpages = (vrange*) vmalloc(sizeof(vrange));
vpages->vaddrlow = (u8 *) KERNEL_HEAP+PAGESIZE;
vpages->vaddrhigh = (u8 *) KERNEL_HEAP+MAXHEAPSIZE;
vpages->vaddrlow = (u8 *) KERNEL_PAGES+PAGESIZE;
vpages->vaddrhigh = (u8 *) KERNEL_PAGES+MAXPAGESSIZE;
TAILQ_INIT(&vrange_head);
TAILQ_INSERT_TAIL(&vrange_head, vpages, tailq);
}

View File

@ -17,6 +17,7 @@
#include "VGA/ansi.c"
#include "3D/sphere.c"
#include "3D/man.c"
#include "memory.h"
static command commands[] = {
{"reboot" , "", &rebootnow},
@ -85,8 +86,10 @@ int mem()
{
u32 libre=getmemoryfree();
u32 total=physical_getmemorysize();
printf("Memoire physique\r\n -libre : %H\r\n -occupee : %H\r\n -total : %H\r\n\r\n",libre,total-libre,total);
printf("Memoire tas noyau\r\n -libre : %H\r\n -occupee : %H\r\n -allouables : %H\r\n",getmallocfree(),getmallocused(),getmallocnonallocated());
printf("Memoire physique (TOTAL)\r\n -libre \33[40D\33[15C%H\r\n -occupee \33[40D\33[15C%H\r\n -total \33[40D\33[15C%H\r\n\r\n",libre,total-libre,total);
printf("Memoire HEAP (NOYAU) - % u blocs\r\n -libre \33[40D\33[15C%H\r\n -occupee \33[40D\33[15C%H\r\n -allouables \33[40D\33[15C%H\r\n\r\n",getmallocnb(),getmallocfree(),getmallocused(),getmallocnonallocated());
printf("Plan de memoire (NOYAU)\r\n -IDT \33[40D\33[15C%X\r\n -GDT \33[40D\33[15C%X\r\n -PGD \33[40D\33[15C%X\r\n -STACK \33[40D\33[15C%X\r\n -CODE \33[40D\33[15C%X\r\n -PAGES \33[40D\33[15C%X\r\n -HEAP \33[40D\33[15C%X\r\n -VESAFB \33[40D\33[15C%X\r\n\r\n",IDT_ADDR,GDT_ADDR,KERNEL_PD_ADDR,KERNEL_STACK_ADDR,KERNEL_CODE_ADDR,KERNEL_PAGES,KERNEL_HEAP,VESA_FBMEM);
printf("Memoire Virtuelle (NOYAU)\r\n -pages libres \33[40D\33[16C% u\r\n -pages occupees \33[40D\33[16C% u\r\n",virtual_getpagesfree(),virtual_getpagesused());
return;
}