Import backup from 2005-09-11
This commit is contained in:
parent
396c5f3452
commit
0521733e20
2
.bochsrc
2
.bochsrc
@ -27,7 +27,7 @@ private_colormap: enabled=0
|
||||
i440fxsupport: enabled=1
|
||||
clock: sync=realtime, time0=local
|
||||
# no ne2k
|
||||
newharddrivesupport: enabled=1
|
||||
#newharddrivesupport: enabled=1
|
||||
# no loader
|
||||
log: -
|
||||
logprefix: %t%e%d
|
||||
|
@ -102,5 +102,7 @@ fs/sysfs/sysfs_entry.o: fs/sysfs/sysfs_entry.h lang/vector.h hos_defines.h
|
||||
fs/sysfs/sysfs_entry.o: lang/string.h
|
||||
sys/pci.o: hos_defines.h display/kout.h sys/io.h sys/pci.h lang/vector.h
|
||||
proc/proc.o: hos_defines.h mm/mm.h kernel.h multiboot.h mm/vmm.h lang/lang.h
|
||||
proc/proc.o: functions.h sys/io.h proc/proc.h proc/hash.h
|
||||
proc/hash.o: hos_defines.h proc/hash.h
|
||||
proc/proc.o: functions.h sys/io.h display/kout.h proc/proc.h proc/hash.h
|
||||
proc/proc.o: lang/vector.h
|
||||
proc/hash.o: hos_defines.h proc/hash.h lang/vector.h display/kout.h mm/vmm.h
|
||||
proc/hash.o: multiboot.h
|
||||
|
@ -66,12 +66,12 @@ html:
|
||||
kernel.o: kernel.h hos_defines.h multiboot.h module.h lang/lang.h functions.h
|
||||
kernel.o: sys/io.h mm/mm.h mm/vmm.h lang/conv.h devices.h display/display.h
|
||||
kernel.o: display/kout.h sys/pic.h char/keyboard.h block/ramdisk.h fs/vfs.h
|
||||
kernel.o: fs/ext2/ext2.h
|
||||
kernel.o: fs/ext2/ext2.h sys/pci.h proc/proc.h
|
||||
mm/mm.o: kernel.h hos_defines.h multiboot.h mm/mm.h
|
||||
mm/vmm.o: hos_defines.h kernel.h multiboot.h mm/vmm.h lang/lang.h mm/mm.h
|
||||
lang/conv.o: lang/conv.h hos_defines.h
|
||||
display/kout.o: hos_defines.h display/kout.h lang/conv.h devices.h
|
||||
display/kout.o: char/misc_char.h char/misc_char.h
|
||||
display/kout.o: char/misc_char.h char/misc_char.h functions.h sys/io.h
|
||||
display/display.o: devices.h hos_defines.h char/vconsole.h display/display.h
|
||||
display/display.o: lang/lang.h kernel.h multiboot.h display/vesafb.h
|
||||
display/display.o: char/keyboard.h display/kout.h
|
||||
@ -80,8 +80,6 @@ char/keyboard.o: hos_defines.h char/keyboard.h sys/io.h functions.h
|
||||
char/keyboard.o: lang/conv.h display/kout.h display/display.h devices.h
|
||||
lang/lang.o: lang/lang.h hos_defines.h
|
||||
sys/pci_classes.o: hos_defines.h sys/pci.h
|
||||
proc/proc.o: hos_defines.h proc/proc.h mm/mm.h kernel.h multiboot.h mm/vmm.h
|
||||
proc/proc.o: lang/lang.h
|
||||
lang/string.o: lang/string.h lang/lang.h hos_defines.h
|
||||
lang/new.o: hos_defines.h mm/vmm.h multiboot.h
|
||||
char/misc_char.o: hos_defines.h devices.h char/misc_char.h sys/io.h
|
||||
@ -103,3 +101,6 @@ fs/sysfs/sysfs.o: lang/string.h fs/sysfs/sysfs_entry.h
|
||||
fs/sysfs/sysfs_entry.o: fs/sysfs/sysfs_entry.h lang/vector.h hos_defines.h
|
||||
fs/sysfs/sysfs_entry.o: lang/string.h
|
||||
sys/pci.o: hos_defines.h display/kout.h sys/io.h sys/pci.h lang/vector.h
|
||||
proc/proc.o: hos_defines.h mm/mm.h kernel.h multiboot.h mm/vmm.h lang/lang.h
|
||||
proc/proc.o: functions.h sys/io.h proc/proc.h proc/hash.h
|
||||
proc/hash.o: hos_defines.h proc/hash.h
|
||||
|
@ -9,6 +9,7 @@
|
||||
extern "C" {
|
||||
#include "hos_defines.h"
|
||||
#include "display/kout.h"
|
||||
#include "functions.h"
|
||||
}
|
||||
|
||||
#include "vfs.h"
|
||||
|
@ -31,9 +31,12 @@ public:
|
||||
/* Constructors/Destructor */
|
||||
vector<type>();
|
||||
vector<type>(unsigned int size);
|
||||
vector<type>(vector<type> & v1);
|
||||
vector<type>(const vector<type> & v1);
|
||||
~vector<type>();
|
||||
|
||||
/* Assignment operator */
|
||||
vector<type> & operator=(const vector<type> & v1);
|
||||
|
||||
/* Returns the size of the vector */
|
||||
unsigned int size() const;
|
||||
|
||||
@ -49,7 +52,6 @@ public:
|
||||
/* Direct access operators */
|
||||
const type & operator[](unsigned int index) const;
|
||||
type & operator[](unsigned int index);
|
||||
|
||||
};
|
||||
|
||||
template<typename type>
|
||||
@ -69,12 +71,12 @@ vector<type>::vector<type>(unsigned int size)
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
vector<type>::vector<type>(vector<type> & v1)
|
||||
vector<type>::vector<type>(const vector<type> & v1)
|
||||
{
|
||||
mySize = v1.mySize;
|
||||
myAllocated = v1.myAllocated;
|
||||
myData = new (type *)[myAllocated];
|
||||
for (int i = 0; i < mySize; i++)
|
||||
for (u32_t i = 0; i < mySize; i++)
|
||||
myData[i] = new type(*v1.myData[i]);
|
||||
}
|
||||
|
||||
@ -86,6 +88,16 @@ vector<type>::~vector<type>()
|
||||
delete[] myData;
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
vector<type> & vector<type>::operator=(const vector<type> & v1)
|
||||
{
|
||||
mySize = v1.mySize;
|
||||
myAllocated = v1.myAllocated;
|
||||
myData = new (type *)[myAllocated];
|
||||
for (u32_t i = 0; i < mySize; i++)
|
||||
myData[i] = new type(*v1.myData[i]);
|
||||
}
|
||||
|
||||
template<typename type>
|
||||
u32_t vector<type>::size() const
|
||||
{
|
||||
@ -110,6 +122,7 @@ vector<type> & vector<type>::add(type elem)
|
||||
while (mySize >= myAllocated)
|
||||
grow();
|
||||
myData[mySize++] = new type(elem);
|
||||
kprintf("vector.h: added element %d @ 0x%x\n", mySize-1, myData[mySize-1]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -145,7 +158,7 @@ vector<type> & vector<type>::insert(type elem, unsigned int position)
|
||||
{
|
||||
if (position <= mySize)
|
||||
{
|
||||
if (mySize == myAllocated)
|
||||
if (mySize >= myAllocated)
|
||||
grow();
|
||||
for (unsigned int i = mySize; i > position; i--)
|
||||
myData[i] = myData[i-1];
|
||||
|
@ -41,6 +41,7 @@ void vmm_init()
|
||||
vmm_map_range((void*)mb_modules[i].mod_start, (void*)mb_modules[i].mod_end - 1, mb_modules[i].mod_start - VIRT_OFFSET);
|
||||
for (i = 0; i < VMM_HE_TYPES; i++)
|
||||
{
|
||||
heapEntryQueues[i].count = 0;
|
||||
heapEntryQueues[i].head = &heapEntryHeadNodes[i];
|
||||
heapEntryHeadNodes[i].next = &heapEntryTailNodes[i];
|
||||
heapEntryTailNodes[i].prev = &heapEntryHeadNodes[i];
|
||||
@ -159,6 +160,8 @@ void *kmalloc(u32_t size)
|
||||
void *attempt = vmm_getFreeChunk(size);
|
||||
if (attempt)
|
||||
{
|
||||
if ((u32_t)attempt == 0xd000c5e4)
|
||||
kprintf("vmm.c: attempt = 0x%x\n", attempt);
|
||||
k_leave_critical();
|
||||
return attempt;
|
||||
}
|
||||
@ -168,6 +171,8 @@ void *kmalloc(u32_t size)
|
||||
return NULL; //we could not get any more heap memory
|
||||
}
|
||||
attempt = vmm_getFreeChunk(size);
|
||||
if ((u32_t)attempt == 0xd000c5e4)
|
||||
kprintf("vmm.c: attempt = 0x%x\n", attempt);
|
||||
k_leave_critical();
|
||||
return attempt;
|
||||
}
|
||||
@ -338,18 +343,18 @@ void *vmm_getFreeChunk(u32_t size)
|
||||
}
|
||||
he = (HeapEntry_t *)he->next;
|
||||
}
|
||||
if (good)
|
||||
{
|
||||
if (!good)
|
||||
return NULL;
|
||||
HeapEntry_t *newHE = vmm_getUnusedEntry();
|
||||
newHE->base = good->base;
|
||||
newHE->length = size;
|
||||
newHE->next = NULL;
|
||||
newHE->prev = NULL;
|
||||
good->base += size;
|
||||
good->length -= size;
|
||||
vmm_addToQueue(VMM_HE_USED, heapEntryQueues[VMM_HE_USED].head, newHE);
|
||||
return newHE->base;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// This function retrieves more core memory for the virtual memory allocator to allocate
|
||||
@ -379,6 +384,8 @@ int vmm_moreCore(u32_t size)
|
||||
HeapEntry_t *newHE = vmm_getUnusedEntry();
|
||||
newHE->base = wilderness->base;
|
||||
newHE->length = size;
|
||||
newHE->next = 0;
|
||||
newHE->prev = 0;
|
||||
wilderness->base += size;
|
||||
wilderness->length -= size;
|
||||
if (vmm_coalesceEntry(VMM_HE_FREE, newHE)) // returns 0 on success (coalesced into previous entry)
|
||||
@ -438,6 +445,7 @@ void vmm_heb_init(HeapEntryBlock_t *heb)
|
||||
|
||||
|
||||
// This function adds a HeapEntry structure to the queue following 'preceeding' the queue
|
||||
// fails if add to tail (add one element before tail node)
|
||||
void vmm_addToQueue(u32_t queue, HeapEntry_t *preceeding, HeapEntry_t *he)
|
||||
{
|
||||
heapEntryQueues[queue].count += vmm_countHeapEntries(he);
|
||||
@ -472,10 +480,13 @@ HeapEntry_t *vmm_followChain(HeapEntry_t *he)
|
||||
|
||||
|
||||
// This function breaks an unused chunk from its queue and returns a pointer to it
|
||||
// 09/10/05 nasty bug fixed by josh, wasn't adding unused entries when we ran out of them
|
||||
HeapEntry_t *vmm_getUnusedEntry()
|
||||
{
|
||||
if (heapEntryQueues[VMM_HE_UNUSED].count < 5)
|
||||
{
|
||||
kprintf(" heapEntryQueues[VMM_HE_UNUSED].count = %d\n",
|
||||
heapEntryQueues[VMM_HE_UNUSED].count);
|
||||
HeapEntry_t *he = heapEntryQueues[VMM_HE_HOLE].head->next;
|
||||
HeapEntry_t *wilderness = he;
|
||||
while (he)
|
||||
@ -484,14 +495,15 @@ HeapEntry_t *vmm_getUnusedEntry()
|
||||
wilderness = he;
|
||||
he = (HeapEntry_t *)he->next;
|
||||
}
|
||||
if (wilderness->length < 10000)
|
||||
{
|
||||
k_check(-1, "Kernel panic: out of virtual memory\n");
|
||||
}
|
||||
wilderness->length -= 4096; //strip 4k from the top
|
||||
HeapEntryBlock_t *newHEB = wilderness->base + wilderness->length;
|
||||
vmm_map(newHEB);
|
||||
vmm_heb_init(newHEB);
|
||||
HeapEntry_t *newDesc = vmm_stripUnusedEntry(); //descriptor for the new HEB
|
||||
newDesc->base = newHEB;
|
||||
newDesc->length = 4096;
|
||||
vmm_addToQueue(VMM_HE_USED, heapEntryTailNodes[VMM_HE_USED].prev, newDesc);
|
||||
vmm_addToQueue(VMM_HE_UNUSED, heapEntryTailNodes[VMM_HE_UNUSED].prev, &newHEB->entry[0]);
|
||||
}
|
||||
return vmm_stripUnusedEntry();
|
||||
}
|
||||
@ -502,6 +514,8 @@ HeapEntry_t *vmm_stripUnusedEntry()
|
||||
{
|
||||
HeapEntry_t *he = heapEntryQueues[VMM_HE_UNUSED].head->next;
|
||||
heapEntryQueues[VMM_HE_UNUSED].head->next = he->next;
|
||||
if (! he->next)
|
||||
kprintf(" he->next is NULL\n");
|
||||
((HeapEntry_t *)he->next)->prev = he->prev;
|
||||
heapEntryQueues[VMM_HE_UNUSED].count--;
|
||||
he->next = 0;
|
||||
|
@ -33,51 +33,35 @@ hash::hash()
|
||||
|
||||
int hash::add(u32_t key, void *val)
|
||||
{
|
||||
kprintf("$1$");
|
||||
u32_t hashed = hash_key(key);
|
||||
vector<hash_entry_t *> *vec = myTable[hashed];
|
||||
kprintf("$2$");
|
||||
if (!vec)
|
||||
myTable[hashed] = vec = new vector<hash_entry_t *>;
|
||||
for (u32_t i = 0; i < vec->size(); i++)
|
||||
if ( (*vec)[i]->key == key )
|
||||
for (u32_t i = 0; i < myTable[hashed].size(); i++)
|
||||
if ( myTable[hashed][i].key == key )
|
||||
return -1; // key exists already
|
||||
kprintf("$3$");
|
||||
hash_entry_t *he = (hash_entry_t *) New(hash_entry_t);
|
||||
kprintf("(");
|
||||
for (u32_t i = 0; i < vec->size(); i++)
|
||||
kprintf("%d,", (*vec)[i]->key);
|
||||
kprintf(")");
|
||||
he->key = key;
|
||||
he->data = val;
|
||||
vec->add(he);
|
||||
kprintf("hash.cpp: %d (slot %d) -> %d\n", key, hashed, val);
|
||||
hash_entry_t he = {key, val};
|
||||
kprintf("hash.cpp: going to add {%d, %d} to vector %d\n", he.key, he.data, hashed);
|
||||
myTable[hashed].add(he);
|
||||
kprintf("hash.cpp: finished adding %d -> %d\n",
|
||||
myTable[hashed][myTable[hashed].size()-1].key,
|
||||
myTable[hashed][myTable[hashed].size()-1].data);
|
||||
mySize++;
|
||||
kprintf("*%d*\t", mySize);
|
||||
if ( mySize > (hash_primes[mySizeIndex] << 1) ) // re-hash
|
||||
{
|
||||
kprintf("*1*");
|
||||
vector<hash_entry_t *> **oldTable = myTable;
|
||||
kprintf("re-hashing\n");
|
||||
vector< vector<hash_entry_t> > oldTable = myTable;
|
||||
mySizeIndex++;
|
||||
myTable = new (vector<hash_entry_t *> *)[hash_primes[mySizeIndex]];
|
||||
myTable = vector< vector<hash_entry_t> >();
|
||||
for (u32_t i = 0; i < hash_primes[mySizeIndex]; i++)
|
||||
myTable[i] = NULL;
|
||||
myTable.add(vector<hash_entry_t>());
|
||||
mySize = 0;
|
||||
kprintf("*2*");
|
||||
for (u32_t i = 0; i < hash_primes[mySizeIndex - 1]; i++)
|
||||
{
|
||||
if (oldTable[i])
|
||||
for (u32_t j = 0; j < oldTable[i].size(); j++)
|
||||
{
|
||||
for (u32_t j = 0; j < oldTable[i]->size(); j++)
|
||||
{
|
||||
add( (*(oldTable[i]))[j]->key,
|
||||
(*(oldTable[i]))[j]->data );
|
||||
kfree( (*(oldTable[i]))[j] );
|
||||
}
|
||||
delete oldTable[i];
|
||||
add( oldTable[i][j].key,
|
||||
oldTable[i][j].data );
|
||||
}
|
||||
}
|
||||
kprintf("*3*");
|
||||
delete oldTable;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -85,26 +69,19 @@ int hash::add(u32_t key, void *val)
|
||||
void *hash::get(u32_t key)
|
||||
{
|
||||
u32_t hashed = hash_key(key);
|
||||
vector<hash_entry_t *> *vec = myTable[hashed];
|
||||
if (!vec)
|
||||
return NULL;
|
||||
for (u32_t i = 0; i < vec->size(); i++)
|
||||
if ( (*vec)[i]->key == key )
|
||||
return (*vec)[i]->data;
|
||||
for (u32_t i = 0; i < myTable[hashed].size(); i++)
|
||||
if ( myTable[hashed][i].key == key )
|
||||
return myTable[hashed][i].data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int hash::remove(u32_t key)
|
||||
{
|
||||
u32_t hashed = hash_key(key);
|
||||
vector<hash_entry_t *> *vec = myTable[hashed];
|
||||
if (!vec)
|
||||
return -1;
|
||||
for (u32_t i = 0; i < vec->size(); i++)
|
||||
if ( (*vec)[i]->key == key )
|
||||
for (u32_t i = 0; i < myTable[hashed].size(); i++)
|
||||
if ( myTable[hashed][i].key == key )
|
||||
{
|
||||
kfree( (*vec)[i] );
|
||||
vec->remove(i); // remove key
|
||||
myTable[hashed].remove(i); // remove key
|
||||
mySize--;
|
||||
return 0;
|
||||
}
|
||||
@ -114,11 +91,8 @@ int hash::remove(u32_t key)
|
||||
int hash::exists(u32_t key)
|
||||
{
|
||||
u32_t hashed = hash_key(key);
|
||||
vector<hash_entry_t *> *vec = myTable[hashed];
|
||||
if (!vec)
|
||||
return 0;
|
||||
for (u32_t i = 0; i < vec->size(); i++)
|
||||
if ( (*vec)[i]->key == key )
|
||||
for (u32_t i = 0; i < myTable[hashed].size(); i++)
|
||||
if ( myTable[hashed][i].key == key )
|
||||
return 1; // key exists
|
||||
return 0;
|
||||
}
|
||||
@ -132,3 +106,20 @@ u32_t hash::size()
|
||||
{
|
||||
return mySize;
|
||||
}
|
||||
|
||||
void hash::dump()
|
||||
{
|
||||
kprintf("hash table @ 0x%x : {\n", &myTable);
|
||||
for (u32_t i = 0; i < hash_primes[mySizeIndex]; i++)
|
||||
{
|
||||
kprintf("\t%d @ 0x%x (", i, &myTable[i]);
|
||||
for (u32_t j = 0; j < myTable[i].size(); j++)
|
||||
kprintf("%s%d -> %d @ 0x%x", (j ? ", " : ""),
|
||||
myTable[i][j].key,
|
||||
myTable[i][j].data,
|
||||
&myTable[i][j]);
|
||||
kprintf(")\n");
|
||||
}
|
||||
kprintf("}\n");
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,9 @@ public:
|
||||
/* Check if the given key exists in the hash table */
|
||||
int exists(u32_t key);
|
||||
|
||||
/* Dump a hash */
|
||||
void dump();
|
||||
|
||||
/* How many values are in the hash table */
|
||||
u32_t size();
|
||||
};
|
||||
|
@ -37,13 +37,28 @@ int proc_init()
|
||||
memset(&tss0, 0, sizeof(tss_t));
|
||||
tss0.ss0 = SEG_KERNEL_DATA;
|
||||
tss0.esp0 = VIRT_STACK_TOP;
|
||||
kprintf("make new hash\n");
|
||||
processes = new hash();
|
||||
for (u32_t i = 0; i < 110; i++)
|
||||
vector< vector<int> > test;
|
||||
for (u32_t i = 0; i < 5; i++)
|
||||
test.add(vector<int>());
|
||||
for (u32_t i = 0; i < 5; i++)
|
||||
for (u32_t j = 0; j < 3; j++)
|
||||
test[i].add(i*10+j);
|
||||
for (u32_t i = 0; i < 5; i++)
|
||||
for (u32_t j = 0; j < 3; j++)
|
||||
kprintf("<%d>", test[i][j]);
|
||||
for (u32_t i = 0; i < 11; i++)
|
||||
{
|
||||
kprintf("add %d to hash\n", i);
|
||||
processes->add(i, (void *) i);
|
||||
}
|
||||
for (u32_t i = 0; i < 110; i++)
|
||||
kprintf("\n\n");
|
||||
processes->dump();
|
||||
kprintf("\n\n");
|
||||
for (u32_t i = 0; i < 11; i++)
|
||||
{
|
||||
kprintf("get %d from hash\n", i);
|
||||
if (i != (u32_t)processes->get(i))
|
||||
kprintf(" !=: %d -> %d\n", i, processes->get(i));
|
||||
processes->remove(i);
|
||||
|
1272
kernel/vmm.S
Normal file
1272
kernel/vmm.S
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user