hos/kernel/mm/vmm.h

56 lines
1.5 KiB
C

// vmm.h
// Author: Josh Holtrop
// Date: 09/30/03
// Rewritten from scratch: 12/23/03, 07/13/04
// Modified: 08/28/04
#ifndef __HOS_VMM__
#define __HOS_VMM__ __HOS_VMM__
#include "hos_defines.h"
#include "multiboot.h"
#define VMM_HE_TYPES 4 //4 types of heap entries
#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/wilderness) section of virtual memory
#define VMM_MALLOC_GRANULARITY 4 //a power of 2, granularity for all memory requests
#define VMM_MALLOC_GRAN_MASK VMM_MALLOC_GRANULARITY-1 //mask for determining how much of a request is past granularity
typedef struct {
void *base; //virtual base address
u32_t length; //size in bytes
void *next; //link to next HeapEntry
void *prev; //link to previous HeapEntry
} __attribute__((packed)) HeapEntry_t;
typedef struct {
HeapEntry_t entry[256]; //256 HeapEntry objects = 4kb (1 page)
} __attribute__((packed)) HeapEntryBlock_t;
typedef struct {
int count;
HeapEntry_t *head;
} HeapEntryQueue_t;
void vmm_init();
void *kmalloc(u32_t size);
int kfree(void *addr);
void *vmm_palloc();
int vmm_pfree(void *addr);
void *kcalloc(unsigned int number, unsigned int size);
int vmm_map(void *virt);
int vmm_map1(unsigned int virt, unsigned int physical);
int 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);
#endif