Import backup from 2005-08-17
This commit is contained in:
1 parent
2cefd9441c
commit
e1682a2fe7
10 files changed
+141
-84
No files matched your search
+32
-13
@@ -2,7 +2,7 @@
|
||||
// Author: Josh Holtrop
|
||||
// Date: 09/30/03
|
||||
// Rewritten from scratch: 12/23/03
|
||||
// Modified: 07/30/04
|
||||
// Modified: 08/17/05
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "kernel.h"
|
||||
@@ -18,6 +18,7 @@ int vmm_coalesceEntry(u32_t queue, HeapEntry_t *newHE);
|
||||
void vmm_heb_init(HeapEntryBlock_t *heb);
|
||||
void vmm_addToQueue(u32_t queue, HeapEntry_t *preceeding, HeapEntry_t *he);
|
||||
int vmm_countHeapEntries(HeapEntry_t *he);
|
||||
int vmm_unmapp(void *addr);
|
||||
HeapEntry_t *vmm_followChain(HeapEntry_t *he);
|
||||
HeapEntry_t *vmm_getUnusedEntry();
|
||||
HeapEntry_t *vmm_stripUnusedEntry();
|
||||
@@ -101,10 +102,13 @@ int vmm_mapn(u32_t virt, u32_t physical, u32_t n)
|
||||
}
|
||||
|
||||
|
||||
// This function removes the virtual address's entry in the page directory / page table
|
||||
// This function removes the virtual address's entry in the
|
||||
// page directory / page table
|
||||
void vmm_unmap1(u32_t virt)
|
||||
{
|
||||
*(u32_t *)(0xFFC00000 | ((virt & 0xFFC00000) >> 10) | ((virt & 0x003FF000) >> 10)) = 0;
|
||||
*(u32_t *)(0xFFC00000 |
|
||||
((virt & 0xFFC00000) >> 10) |
|
||||
((virt & 0x003FF000) >> 10)) = 0;
|
||||
invlpg_(virt);
|
||||
}
|
||||
|
||||
@@ -125,7 +129,7 @@ void vmm_unmapn(u32_t virt, u32_t n)
|
||||
int vmm_map_range(void *virt_start, void *virt_end, u32_t phys_start)
|
||||
{
|
||||
if (virt_end < virt_start)
|
||||
return -1; // invalid region
|
||||
return -1; // invalid region
|
||||
while (virt_start < virt_end)
|
||||
{
|
||||
if (vmm_map1((u32_t)virt_start, phys_start))
|
||||
@@ -139,11 +143,12 @@ int vmm_map_range(void *virt_start, void *virt_end, u32_t phys_start)
|
||||
|
||||
|
||||
// kernel virtual memory allocator
|
||||
void *kmalloc(u32_t size)
|
||||
void *kmalloc(u32_t size)
|
||||
{
|
||||
k_enter_critical();
|
||||
if (size % VMM_MALLOC_GRANULARITY)
|
||||
size = size + VMM_MALLOC_GRANULARITY - (size % VMM_MALLOC_GRANULARITY);
|
||||
size = size + VMM_MALLOC_GRANULARITY -
|
||||
(size % VMM_MALLOC_GRANULARITY);
|
||||
void *attempt = vmm_getFreeChunk(size);
|
||||
if (attempt)
|
||||
{
|
||||
@@ -153,7 +158,7 @@ void *kmalloc(u32_t size)
|
||||
if (vmm_moreCore(size))
|
||||
{
|
||||
k_leave_critical();
|
||||
return NULL; //we could not get any more heap memory
|
||||
return NULL; //we could not get any more heap memory
|
||||
}
|
||||
attempt = vmm_getFreeChunk(size);
|
||||
k_leave_critical();
|
||||
@@ -162,7 +167,7 @@ void *kmalloc(u32_t size)
|
||||
|
||||
|
||||
// kernel virtual memory de-allocator
|
||||
int kfree(void *addr)
|
||||
int kfree(void *addr)
|
||||
{
|
||||
k_enter_critical();
|
||||
HeapEntry_t *he = heapEntryQueues[VMM_HE_USED].head->next;
|
||||
@@ -185,7 +190,7 @@ int kfree(void *addr)
|
||||
|
||||
|
||||
// This function allocates a virtual page and maps it to a physical page
|
||||
void *vmm_palloc()
|
||||
void *vmm_palloc()
|
||||
{
|
||||
k_enter_critical();
|
||||
HeapEntry_t *he = heapEntryQueues[VMM_HE_HOLE].head->next;
|
||||
@@ -196,7 +201,8 @@ void *vmm_palloc()
|
||||
{
|
||||
vmm_removeHeapEntry(VMM_HE_HOLE, he);
|
||||
vmm_addToQueue(VMM_HE_USED, &heapEntryHeadNodes[VMM_HE_USED], he);
|
||||
vmm_map(he->base);
|
||||
if (vmm_map(he->base))
|
||||
he->base = NULL;
|
||||
k_leave_critical();
|
||||
return he->base;
|
||||
}
|
||||
@@ -214,22 +220,35 @@ void *vmm_palloc()
|
||||
he->base = wilderness->base + wilderness->length;
|
||||
he->length = 4096;
|
||||
vmm_addToQueue(VMM_HE_USED, &heapEntryHeadNodes[VMM_HE_USED], he);
|
||||
vmm_map(he->base);
|
||||
if (vmm_map(he->base))
|
||||
he->base = NULL;
|
||||
k_leave_critical();
|
||||
return he->base;
|
||||
}
|
||||
|
||||
|
||||
// This function frees a previously-allocated virtual page
|
||||
int vmm_pfree(void *addr)
|
||||
int vmm_pfree(void *addr)
|
||||
{
|
||||
u32_t pbase = *(u32_t *)(0xFFC00000 |
|
||||
(((u32_t)addr & 0xFFC00000) >> 10) |
|
||||
(((u32_t)addr & 0x003FF000) >> 10));
|
||||
if (vmm_unmapp(addr))
|
||||
return -1;
|
||||
mm_pfree(pbase);
|
||||
}
|
||||
|
||||
int vmm_unmapp(void *addr)
|
||||
{
|
||||
if (!addr)
|
||||
return -2;
|
||||
k_enter_critical();
|
||||
HeapEntry_t *he = heapEntryQueues[VMM_HE_USED].head->next;
|
||||
while (he->next)
|
||||
{
|
||||
if (he->base == addr) //found the page to free
|
||||
{
|
||||
vmm_removeHeapEntry(VMM_HE_USED, he);
|
||||
vmm_removeHeapEntry(VMM_HE_USED, he);
|
||||
vmm_unmap1((u32_t)he->base);
|
||||
vmm_addToQueue(VMM_HE_HOLE, &heapEntryHeadNodes[VMM_HE_HOLE], he);
|
||||
k_leave_critical();
|
||||
|
||||
Reference in new issue
Block a user