diff --git a/README.md b/README.md index 8b6959d..8fd5bd1 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ Pour l'instant quelques commandes seulement sont disponibles: * REGS affiche les registres CPU, * GDT affiche la table des descripteurs, * IDT affiche la table des interruptions, +* MEM affiche les statistiques d'occupation memoire, * INFO affiche des informations issues de GRUB, * ERR génère une exception (ARGUMENTS), * VIEW visionne la mémoire vive (ARGUMENTS), @@ -224,4 +225,4 @@ Pour l'instant quelques commandes seulement sont disponibles: > tout le reste n'est que de l'information.. > > ― Albert Einstein -> ― Mathématicien, Physicien \ No newline at end of file +> ― Mathématicien, Physicien diff --git a/include/memory.h b/include/memory.h index 7a073c8..7f66edd 100755 --- a/include/memory.h +++ b/include/memory.h @@ -107,3 +107,6 @@ void virtual_range_new(pd *dst, u8 *vaddr, u64 len, u32 flags); void malloc_init(void); void identity_init(void); void registry_init(void); +u32 getmallocused(void); +u32 getmallocfree(void); +u32 getmallocnonallocated(void); diff --git a/include/shell.h b/include/shell.h index df53bf1..6e7e8e9 100644 --- a/include/shell.h +++ b/include/shell.h @@ -28,3 +28,4 @@ int sfont(u8* commandline); int help(); int logo(); int detectpci(); +int mem(); diff --git a/lib/memory.c b/lib/memory.c index b1f7dba..ffbf3ae 100755 --- a/lib/memory.c +++ b/lib/memory.c @@ -37,6 +37,46 @@ tmalloc *mallocpage(u8 size) return chunk; } +/*******************************************************************************/ +/* Retourne la mémoire virtuelle utilisée de façon dynamique (heap) */ + +u32 getmallocused(void) +{ + u32 realsize=0; + tmalloc *chunk, *new; + chunk = KERNEL_HEAP; + while (chunk < (tmalloc *) kernelcurrentheap) { + if (chunk->used) + realsize+=chunk->size; + chunk = chunk + chunk->size; + } + return realsize; +} + +/*******************************************************************************/ +/* Retourne la mémoire virtuelle libre de façon dynamique (heap) */ + +u32 getmallocfree(void) +{ + u32 realsize=0; + tmalloc *chunk, *new; + chunk = KERNEL_HEAP; + while (chunk < (tmalloc *) kernelcurrentheap) { + if (!chunk->used) + realsize+=chunk->size; + chunk = chunk + chunk->size; + } + return realsize; +} + +/*******************************************************************************/ +/* Retourne la mémoire virtuelle non allouée de façon dynamique (heap) */ + +u32 getmallocnonallocated(void) +{ + return VESA_FBMEM-((u32) kernelcurrentheap); +} + /*******************************************************************************/ /* Alloue de la mémoire virtuelle au noyau de façon dynamique (heap) */ @@ -91,8 +131,10 @@ u64 physical_getmemorysize() multiboot_memory_map_t *mmap; for (mmap = ((struct multiboot_tag_mmap *) tag)->entries;(u8 *) mmap < (u8 *) tag + tag->size; mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + ((struct multiboot_tag_mmap *) tag)->entry_size)) - if (mmap->addr+mmap->len>maxaddr) + if ((mmap->addr+mmap->len>maxaddr) && mmap->type==1) maxaddr=mmap->addr+mmap->len; + if (maxaddr>=MAXMEMSIZE) + maxaddr=MAXMEMSIZE-1; return maxaddr; } diff --git a/lib/shell.c b/lib/shell.c index 4737a86..adadf21 100644 --- a/lib/shell.c +++ b/lib/shell.c @@ -39,6 +39,7 @@ static command commands[] = { {"font" , "", &sfont}, {"test3d" , "", &test3d}, {"detectpci" , "", &detectpci}, + {"mem" , "", &mem}, }; /*******************************************************************************/ @@ -78,6 +79,17 @@ int test(void) return; } +/*******************************************************************************/ +/* Affiche des informations sur la mémoire */ +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()); + return; +} + /*******************************************************************************/ /* Affiche les périphériques PCI */ int detectpci()