Import backup from 2005-09-11

This commit is contained in:
Josh Holtrop 2005-09-11 22:00:00 -04:00
parent 396c5f3452
commit 0521733e20
10 changed files with 1391 additions and 79 deletions

View File

@ -27,7 +27,7 @@ private_colormap: enabled=0
i440fxsupport: enabled=1 i440fxsupport: enabled=1
clock: sync=realtime, time0=local clock: sync=realtime, time0=local
# no ne2k # no ne2k
newharddrivesupport: enabled=1 #newharddrivesupport: enabled=1
# no loader # no loader
log: - log: -
logprefix: %t%e%d logprefix: %t%e%d

View File

@ -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 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 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: 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/proc.o: functions.h sys/io.h display/kout.h proc/proc.h proc/hash.h
proc/hash.o: hos_defines.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

View File

@ -66,12 +66,12 @@ html:
kernel.o: kernel.h hos_defines.h multiboot.h module.h lang/lang.h functions.h 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: 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: 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/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 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 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: 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: 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: lang/lang.h kernel.h multiboot.h display/vesafb.h
display/display.o: char/keyboard.h display/kout.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 char/keyboard.o: lang/conv.h display/kout.h display/display.h devices.h
lang/lang.o: lang/lang.h hos_defines.h lang/lang.o: lang/lang.h hos_defines.h
sys/pci_classes.o: hos_defines.h sys/pci.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/string.o: lang/string.h lang/lang.h hos_defines.h
lang/new.o: hos_defines.h mm/vmm.h multiboot.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 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: fs/sysfs/sysfs_entry.h lang/vector.h hos_defines.h
fs/sysfs/sysfs_entry.o: lang/string.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 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

View File

@ -9,6 +9,7 @@
extern "C" { extern "C" {
#include "hos_defines.h" #include "hos_defines.h"
#include "display/kout.h" #include "display/kout.h"
#include "functions.h"
} }
#include "vfs.h" #include "vfs.h"

View File

@ -31,9 +31,12 @@ public:
/* Constructors/Destructor */ /* Constructors/Destructor */
vector<type>(); vector<type>();
vector<type>(unsigned int size); vector<type>(unsigned int size);
vector<type>(vector<type> & v1); vector<type>(const vector<type> & v1);
~vector<type>(); ~vector<type>();
/* Assignment operator */
vector<type> & operator=(const vector<type> & v1);
/* Returns the size of the vector */ /* Returns the size of the vector */
unsigned int size() const; unsigned int size() const;
@ -49,7 +52,6 @@ public:
/* Direct access operators */ /* Direct access operators */
const type & operator[](unsigned int index) const; const type & operator[](unsigned int index) const;
type & operator[](unsigned int index); type & operator[](unsigned int index);
}; };
template<typename type> template<typename type>
@ -69,12 +71,12 @@ vector<type>::vector<type>(unsigned int size)
} }
template<typename type> template<typename type>
vector<type>::vector<type>(vector<type> & v1) vector<type>::vector<type>(const vector<type> & v1)
{ {
mySize = v1.mySize; mySize = v1.mySize;
myAllocated = v1.myAllocated; myAllocated = v1.myAllocated;
myData = new (type *)[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]); myData[i] = new type(*v1.myData[i]);
} }
@ -86,6 +88,16 @@ vector<type>::~vector<type>()
delete[] myData; 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> template<typename type>
u32_t vector<type>::size() const u32_t vector<type>::size() const
{ {
@ -110,6 +122,7 @@ vector<type> & vector<type>::add(type elem)
while (mySize >= myAllocated) while (mySize >= myAllocated)
grow(); grow();
myData[mySize++] = new type(elem); myData[mySize++] = new type(elem);
kprintf("vector.h: added element %d @ 0x%x\n", mySize-1, myData[mySize-1]);
return *this; return *this;
} }
@ -145,7 +158,7 @@ vector<type> & vector<type>::insert(type elem, unsigned int position)
{ {
if (position <= mySize) if (position <= mySize)
{ {
if (mySize == myAllocated) if (mySize >= myAllocated)
grow(); grow();
for (unsigned int i = mySize; i > position; i--) for (unsigned int i = mySize; i > position; i--)
myData[i] = myData[i-1]; myData[i] = myData[i-1];

View File

@ -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); 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++) for (i = 0; i < VMM_HE_TYPES; i++)
{ {
heapEntryQueues[i].count = 0;
heapEntryQueues[i].head = &heapEntryHeadNodes[i]; heapEntryQueues[i].head = &heapEntryHeadNodes[i];
heapEntryHeadNodes[i].next = &heapEntryTailNodes[i]; heapEntryHeadNodes[i].next = &heapEntryTailNodes[i];
heapEntryTailNodes[i].prev = &heapEntryHeadNodes[i]; heapEntryTailNodes[i].prev = &heapEntryHeadNodes[i];
@ -159,6 +160,8 @@ void *kmalloc(u32_t size)
void *attempt = vmm_getFreeChunk(size); void *attempt = vmm_getFreeChunk(size);
if (attempt) if (attempt)
{ {
if ((u32_t)attempt == 0xd000c5e4)
kprintf("vmm.c: attempt = 0x%x\n", attempt);
k_leave_critical(); k_leave_critical();
return attempt; return attempt;
} }
@ -168,6 +171,8 @@ void *kmalloc(u32_t size)
return NULL; //we could not get any more heap memory return NULL; //we could not get any more heap memory
} }
attempt = vmm_getFreeChunk(size); attempt = vmm_getFreeChunk(size);
if ((u32_t)attempt == 0xd000c5e4)
kprintf("vmm.c: attempt = 0x%x\n", attempt);
k_leave_critical(); k_leave_critical();
return attempt; return attempt;
} }
@ -338,17 +343,17 @@ void *vmm_getFreeChunk(u32_t size)
} }
he = (HeapEntry_t *)he->next; he = (HeapEntry_t *)he->next;
} }
if (good) if (!good)
{ return NULL;
HeapEntry_t *newHE = vmm_getUnusedEntry(); HeapEntry_t *newHE = vmm_getUnusedEntry();
newHE->base = good->base; newHE->base = good->base;
newHE->length = size; newHE->length = size;
good->base += size; newHE->next = NULL;
good->length -= size; newHE->prev = NULL;
vmm_addToQueue(VMM_HE_USED, heapEntryQueues[VMM_HE_USED].head, newHE); good->base += size;
return newHE->base; good->length -= size;
} vmm_addToQueue(VMM_HE_USED, heapEntryQueues[VMM_HE_USED].head, newHE);
return NULL; return newHE->base;
} }
@ -379,6 +384,8 @@ int vmm_moreCore(u32_t size)
HeapEntry_t *newHE = vmm_getUnusedEntry(); HeapEntry_t *newHE = vmm_getUnusedEntry();
newHE->base = wilderness->base; newHE->base = wilderness->base;
newHE->length = size; newHE->length = size;
newHE->next = 0;
newHE->prev = 0;
wilderness->base += size; wilderness->base += size;
wilderness->length -= size; wilderness->length -= size;
if (vmm_coalesceEntry(VMM_HE_FREE, newHE)) // returns 0 on success (coalesced into previous entry) 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 // 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) void vmm_addToQueue(u32_t queue, HeapEntry_t *preceeding, HeapEntry_t *he)
{ {
heapEntryQueues[queue].count += vmm_countHeapEntries(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 // 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() HeapEntry_t *vmm_getUnusedEntry()
{ {
if (heapEntryQueues[VMM_HE_UNUSED].count < 5) 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 *he = heapEntryQueues[VMM_HE_HOLE].head->next;
HeapEntry_t *wilderness = he; HeapEntry_t *wilderness = he;
while (he) while (he)
@ -484,14 +495,15 @@ HeapEntry_t *vmm_getUnusedEntry()
wilderness = he; wilderness = he;
he = (HeapEntry_t *)he->next; 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 wilderness->length -= 4096; //strip 4k from the top
HeapEntryBlock_t *newHEB = wilderness->base + wilderness->length; HeapEntryBlock_t *newHEB = wilderness->base + wilderness->length;
vmm_map(newHEB); vmm_map(newHEB);
vmm_heb_init(newHEB); vmm_heb_init(newHEB);
HeapEntry_t *newDesc = vmm_stripUnusedEntry(); //descriptor for the new HEB vmm_addToQueue(VMM_HE_UNUSED, heapEntryTailNodes[VMM_HE_UNUSED].prev, &newHEB->entry[0]);
newDesc->base = newHEB;
newDesc->length = 4096;
vmm_addToQueue(VMM_HE_USED, heapEntryTailNodes[VMM_HE_USED].prev, newDesc);
} }
return vmm_stripUnusedEntry(); return vmm_stripUnusedEntry();
} }
@ -502,6 +514,8 @@ HeapEntry_t *vmm_stripUnusedEntry()
{ {
HeapEntry_t *he = heapEntryQueues[VMM_HE_UNUSED].head->next; HeapEntry_t *he = heapEntryQueues[VMM_HE_UNUSED].head->next;
heapEntryQueues[VMM_HE_UNUSED].head->next = he->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; ((HeapEntry_t *)he->next)->prev = he->prev;
heapEntryQueues[VMM_HE_UNUSED].count--; heapEntryQueues[VMM_HE_UNUSED].count--;
he->next = 0; he->next = 0;

View File

@ -33,51 +33,35 @@ hash::hash()
int hash::add(u32_t key, void *val) int hash::add(u32_t key, void *val)
{ {
kprintf("$1$");
u32_t hashed = hash_key(key); u32_t hashed = hash_key(key);
vector<hash_entry_t *> *vec = myTable[hashed]; for (u32_t i = 0; i < myTable[hashed].size(); i++)
kprintf("$2$"); if ( myTable[hashed][i].key == key )
if (!vec)
myTable[hashed] = vec = new vector<hash_entry_t *>;
for (u32_t i = 0; i < vec->size(); i++)
if ( (*vec)[i]->key == key )
return -1; // key exists already return -1; // key exists already
kprintf("$3$"); kprintf("hash.cpp: %d (slot %d) -> %d\n", key, hashed, val);
hash_entry_t *he = (hash_entry_t *) New(hash_entry_t); hash_entry_t he = {key, val};
kprintf("("); kprintf("hash.cpp: going to add {%d, %d} to vector %d\n", he.key, he.data, hashed);
for (u32_t i = 0; i < vec->size(); i++) myTable[hashed].add(he);
kprintf("%d,", (*vec)[i]->key); kprintf("hash.cpp: finished adding %d -> %d\n",
kprintf(")"); myTable[hashed][myTable[hashed].size()-1].key,
he->key = key; myTable[hashed][myTable[hashed].size()-1].data);
he->data = val;
vec->add(he);
mySize++; mySize++;
kprintf("*%d*\t", mySize);
if ( mySize > (hash_primes[mySizeIndex] << 1) ) // re-hash if ( mySize > (hash_primes[mySizeIndex] << 1) ) // re-hash
{ {
kprintf("*1*"); kprintf("re-hashing\n");
vector<hash_entry_t *> **oldTable = myTable; vector< vector<hash_entry_t> > oldTable = myTable;
mySizeIndex++; 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++) for (u32_t i = 0; i < hash_primes[mySizeIndex]; i++)
myTable[i] = NULL; myTable.add(vector<hash_entry_t>());
mySize = 0; mySize = 0;
kprintf("*2*");
for (u32_t i = 0; i < hash_primes[mySizeIndex - 1]; i++) 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 );
add( (*(oldTable[i]))[j]->key,
(*(oldTable[i]))[j]->data );
kfree( (*(oldTable[i]))[j] );
}
delete oldTable[i];
} }
} }
kprintf("*3*");
delete oldTable;
} }
return 0; return 0;
} }
@ -85,26 +69,19 @@ int hash::add(u32_t key, void *val)
void *hash::get(u32_t key) void *hash::get(u32_t key)
{ {
u32_t hashed = hash_key(key); u32_t hashed = hash_key(key);
vector<hash_entry_t *> *vec = myTable[hashed]; for (u32_t i = 0; i < myTable[hashed].size(); i++)
if (!vec) if ( myTable[hashed][i].key == key )
return NULL; return myTable[hashed][i].data;
for (u32_t i = 0; i < vec->size(); i++)
if ( (*vec)[i]->key == key )
return (*vec)[i]->data;
return NULL; return NULL;
} }
int hash::remove(u32_t key) int hash::remove(u32_t key)
{ {
u32_t hashed = hash_key(key); u32_t hashed = hash_key(key);
vector<hash_entry_t *> *vec = myTable[hashed]; for (u32_t i = 0; i < myTable[hashed].size(); i++)
if (!vec) if ( myTable[hashed][i].key == key )
return -1;
for (u32_t i = 0; i < vec->size(); i++)
if ( (*vec)[i]->key == key )
{ {
kfree( (*vec)[i] ); myTable[hashed].remove(i); // remove key
vec->remove(i); // remove key
mySize--; mySize--;
return 0; return 0;
} }
@ -114,11 +91,8 @@ int hash::remove(u32_t key)
int hash::exists(u32_t key) int hash::exists(u32_t key)
{ {
u32_t hashed = hash_key(key); u32_t hashed = hash_key(key);
vector<hash_entry_t *> *vec = myTable[hashed]; for (u32_t i = 0; i < myTable[hashed].size(); i++)
if (!vec) if ( myTable[hashed][i].key == key )
return 0;
for (u32_t i = 0; i < vec->size(); i++)
if ( (*vec)[i]->key == key )
return 1; // key exists return 1; // key exists
return 0; return 0;
} }
@ -132,3 +106,20 @@ u32_t hash::size()
{ {
return mySize; 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");
}

View File

@ -47,6 +47,9 @@ public:
/* Check if the given key exists in the hash table */ /* Check if the given key exists in the hash table */
int exists(u32_t key); int exists(u32_t key);
/* Dump a hash */
void dump();
/* How many values are in the hash table */ /* How many values are in the hash table */
u32_t size(); u32_t size();
}; };

View File

@ -37,13 +37,28 @@ int proc_init()
memset(&tss0, 0, sizeof(tss_t)); memset(&tss0, 0, sizeof(tss_t));
tss0.ss0 = SEG_KERNEL_DATA; tss0.ss0 = SEG_KERNEL_DATA;
tss0.esp0 = VIRT_STACK_TOP; tss0.esp0 = VIRT_STACK_TOP;
kprintf("make new hash\n");
processes = new hash(); 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); 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)) if (i != (u32_t)processes->get(i))
kprintf(" !=: %d -> %d\n", i, processes->get(i)); kprintf(" !=: %d -> %d\n", i, processes->get(i));
processes->remove(i); processes->remove(i);

1272
kernel/vmm.S Normal file

File diff suppressed because it is too large Load Diff