// vmm.h // Author: Josh Holtrop // Date: 09/30/03 // Rewritten from scratch: 12/23/03 // Modified: 03/02/04 #include "hos_defines.h" #ifndef __HOS_VMM__ #define __HOS_VMM__ __HOS_VMM__ #define VMM_HE_UNUSED 0 //available entry #define VMM_HE_FREE 1 //free section of memory #define VMM_HE_USED 2 //used section of memory #define VMM_HE_HOLE 3 //a "hole" (unmapped) section of virtual memory #define VMM_HE_HEB 4 //HeapEntryBlock #define VMM_MALLOC_GRANULARITY 4 //granularity for all memory requests typedef struct { unsigned int base; //virtual base address unsigned int size; //size in bytes unsigned int attributes; //free/used/hole unsigned int link; //link to next HeapEntry } __attribute__((packed)) HeapEntry; typedef struct { HeapEntry entry[256]; //256 HeapEntry objects = 4kb (1 page) } __attribute__((packed)) HeapEntryBlock; void vmm_init(); void *malloc(unsigned int bytes); int free(void *ptr); void vmm_map1(unsigned int virt, unsigned int physical); void vmm_mapn(unsigned int virt, unsigned int physical, unsigned int n); void vmm_unmap1(unsigned int virt); void vmm_unmapn(unsigned int virt, unsigned int n); void vmm_heb_init(HeapEntryBlock *heb); void *vmm_getFreeChunk(unsigned int bytes); HeapEntry *vmm_nextHeapEntry(); unsigned int vmm_heapEntriesLeft(); HeapEntry *vmm_getLastHeapEntry(); HeapEntry *vmm_getFirstUnusedHeapEntry(); HeapEntry *vmm_getFirstHoleHeapEntry(unsigned int minBytes); void vmm_addHeapEntryBlock(); int vmm_moreCore(unsigned int bytes); void vmm_coalesceHeapEntry(HeapEntry *he); HeapEntry *vmm_getHeapEntryByBase(unsigned int base); #endif