Import backup from 2004-07-17
This commit is contained in:
1 parent
d4aadbea38
commit
286b5e9ae1
13 files changed
+480
-29
No files matched your search
+47
-19
@@ -5,6 +5,7 @@
|
||||
// Modified: 07/13/04
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "kernel.h"
|
||||
#include "mm/vmm.h"
|
||||
#include "asmfuncs.h"
|
||||
#include "mm/mm.h"
|
||||
@@ -24,7 +25,13 @@ void vmm_init()
|
||||
int i;
|
||||
for (i = 0; i < mb_info_block.mods_count; i++) //page in the kernel modules
|
||||
vmm_map_range((void*)mb_modules[i].mod_start, (void*)mb_modules[i].mod_end- 1, mb_modules[i].mod_start - VIRT_OFFSET);
|
||||
|
||||
vmm_heb_init(initialHEB);
|
||||
vmm_addToQueue(VMM_HE_UNUSED, initialHEB[0]);
|
||||
HeapEntry_t *wilderness = vmm_stripUnusedEntry();
|
||||
wilderness->base = HEAP_START;
|
||||
wilderness->length = HEAP_LENGTH;
|
||||
wilderneww->next = 0;
|
||||
vmm_addToQueue(VMM_HE_HOLE, wilderness);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,32 +47,33 @@ u32_t vmm_map(void *virt)
|
||||
|
||||
|
||||
// This function maps a virtual address to a physical address using the page directory / page table
|
||||
void vmm_map1(unsigned int virt, unsigned int physical)
|
||||
int vmm_map1(unsigned int virt, unsigned int physical)
|
||||
{
|
||||
unsigned int pde = virt >> 22;
|
||||
unsigned int pte = (virt & 0x003FF000) >> 12;
|
||||
unsigned int *pageTables = (unsigned int *)0xFFFFF000; //this is the location of the page directory
|
||||
if (!(pageTables[pde] & 0x01)) //the page directory entry does not exist, we must allocate a page for it
|
||||
if (!(pageTables[pde] & 0x01)) //the page directory entry is not present, we must allocate a page table
|
||||
{
|
||||
u32_t newpagetable = mm_palloc();
|
||||
u32_t newpagetable;
|
||||
if (!(newpagetable = mm_palloc())
|
||||
return 1; //out of physical memory
|
||||
pageTables[pde] = newpagetable | 0x03;
|
||||
invlpg_(virt); //in case it was cached, so we can fill page table safely
|
||||
unsigned int *newpteptr = (unsigned int *)(0xFFC00000 | (pde << 12)); //points to first unsigned int of newly allocated page table
|
||||
int a;
|
||||
for (a = 0; a < 1024; a++)
|
||||
*newpteptr++ = 0;
|
||||
memsetd((void*)(0xFFC00000 | (pde << 12)), 0, 1024); //zero out new page table
|
||||
}
|
||||
*(unsigned int *)(0xFFC00000 | (pde << 12) | (pte << 2)) = (physical & 0xFFFFF000) | 0x03;
|
||||
invlpg_(virt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// This function maps a variable number of pages in a row
|
||||
void vmm_mapn(unsigned int virt, unsigned int physical, unsigned int n)
|
||||
int vmm_mapn(unsigned int virt, unsigned int physical, unsigned int n)
|
||||
{
|
||||
while (n > 0)
|
||||
{
|
||||
vmm_map1(virt, physical);
|
||||
if (vmm_map1(virt, physical))
|
||||
return 1; // error mapping page
|
||||
virt += 4096;
|
||||
physical += 4096;
|
||||
n--;
|
||||
@@ -96,10 +104,11 @@ void vmm_unmapn(unsigned int virt, unsigned int 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)
|
||||
{
|
||||
vmm_map1((u32_t)virt_start, phys_start);
|
||||
if (vmm_map1((u32_t)virt_start, phys_start))
|
||||
return 2; // out of memory
|
||||
virt_start += 4096;
|
||||
phys_start += 4096;
|
||||
}
|
||||
@@ -107,6 +116,20 @@ int vmm_map_range(void *virt_start, void *virt_end, u32_t phys_start)
|
||||
}
|
||||
|
||||
|
||||
void *kmalloc(u32_t size)
|
||||
{
|
||||
k_enter_critical();
|
||||
k_leave_critical();
|
||||
}
|
||||
|
||||
|
||||
void *vmm_palloc()
|
||||
{
|
||||
k_enter_critical();
|
||||
k_leave_critical();
|
||||
}
|
||||
|
||||
|
||||
// This function allocates and zeros memory for the given number of objects,
|
||||
// given the size of each object
|
||||
/*
|
||||
@@ -158,7 +181,6 @@ int vmm_countHeapEntries(HeapEntry_t *he)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// This function follows a chain of HeapEntry objects and returns a pointer to the last one
|
||||
HeapEntry_t *vmm_followChain(HeapEntry_t *he)
|
||||
{
|
||||
@@ -169,18 +191,24 @@ HeapEntry_t *vmm_followChain(HeapEntry_t *he)
|
||||
|
||||
|
||||
// This function breaks an unused chunk from its queue and returns a pointer to it
|
||||
HeapEntry_t *vmm_getUnusedChunk()
|
||||
HeapEntry_t *vmm_getUnusedEntry()
|
||||
{
|
||||
if (heapEntryQueues[VMM_HE_UNUSED].count < 5)
|
||||
{
|
||||
heapEntryQueues[VMM_HE_UNUSED].count += 256;//not good idea
|
||||
HeapEntryBlock_t *newHEB = vmm_palloc(); //INFINITE LOOP?
|
||||
vmm_mcb_init(newHEB);
|
||||
HeapEntry_t *wilderness = vmm_followChain(
|
||||
HeapEntryBlock_t *newHEB;
|
||||
vmm_heb_init(newHEB);
|
||||
vmm_addToQueue(VMM_HE_UNUSED, newHEB);
|
||||
heapEntryQueues[VMM_HE_UNUSED].count -= 256;
|
||||
}
|
||||
return vmm_stripUnusedEntry();
|
||||
}
|
||||
|
||||
|
||||
// Return pointer to an unused HeapEntry object, ASSUMES THERE IS ONE PRESENT IN QUEUE
|
||||
HeapEntry_t *vmm_stripUnusedEntry()
|
||||
{
|
||||
HeapEntry_t *he = heapEntryQueues[VMM_HE_UNUSED].start;
|
||||
heapEntryQueues[VMM_HE_UNUSED].start = he->link;
|
||||
heapEntryQueues[VMM_HE_UNUSED].start = he->next;
|
||||
heapEntryQueues[VMM_HE_UNUSED].count--;
|
||||
return he;
|
||||
}
|
||||
|
||||
+3
-3
@@ -27,7 +27,6 @@ typedef struct {
|
||||
u32_t padding;
|
||||
} __attribute__((packed)) HeapEntry_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
HeapEntry_t entry[256]; //256 HeapEntry objects = 4kb (1 page)
|
||||
} __attribute__((packed)) HeapEntryBlock_t;
|
||||
@@ -37,10 +36,11 @@ typedef struct {
|
||||
HeapEntry_t *start;
|
||||
} HeapEntryQueue_t;
|
||||
|
||||
|
||||
void vmm_init();
|
||||
u32_t vmm_map(void *virt);
|
||||
void vmm_map1(unsigned int virt, unsigned int physical);
|
||||
void vmm_mapn(unsigned int virt, unsigned int physical, unsigned int n);
|
||||
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);
|
||||
int vmm_map_range(void *virt_start, void *virt_end, u32_t phys_start);
|
||||
|
||||
Reference in new issue
Block a user