hos/vmm.h

56 lines
1.5 KiB
C

// vmm.h
// Author: Josh Holtrop
// Date: 09/30/03
// Rewritten from scratch: 12/23/03
// Modified: 12/30/03
#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 {
dword base; //virtual base address
dword size; //size in bytes
dword attributes; //free/used/hole
dword 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(dword bytes);
int free(void *ptr);
void vmm_map1(dword virt, dword physical);
void vmm_mapn(dword virt, dword physical, dword n);
void vmm_unmap1(dword virt);
void vmm_unmapn(dword virt, dword n);
void vmm_heb_init(HeapEntryBlock *heb);
void *vmm_getFreeChunk(dword bytes);
HeapEntry *vmm_nextHeapEntry();
dword vmm_heapEntriesLeft();
HeapEntry *vmm_getLastHeapEntry();
HeapEntry *vmm_getFirstUnusedHeapEntry();
HeapEntry *vmm_getFirstHoleHeapEntry(dword minBytes);
void vmm_addHeapEntryBlock();
int vmm_moreCore(dword bytes);
void vmm_coalesceHeapEntry(HeapEntry *he);
HeapEntry *vmm_getHeapEntryByBase(dword base);
HeapEntry *firstHeapEntry = (HeapEntry *)0xD0000000; //this is where heap memory starts