Import backup from 2005-09-13
This commit is contained in:
parent
0521733e20
commit
79ca453f66
@ -64,7 +64,6 @@ segmented_start:
|
|||||||
mov fs, cx
|
mov fs, cx
|
||||||
mov esp, STACK_V+0x1000 ;ok, now we can access our data
|
mov esp, STACK_V+0x1000 ;ok, now we can access our data
|
||||||
|
|
||||||
|
|
||||||
;Then the multiboot info structures are saved to local data variables.
|
;Then the multiboot info structures are saved to local data variables.
|
||||||
add ebx, VIRT_OFFSET
|
add ebx, VIRT_OFFSET
|
||||||
push eax
|
push eax
|
||||||
|
@ -52,6 +52,9 @@ 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);
|
||||||
|
|
||||||
|
/* Returns pointer to data */
|
||||||
|
type **data();
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename type>
|
template<typename type>
|
||||||
@ -122,7 +125,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,4 +170,11 @@ vector<type> & vector<type>::insert(type elem, unsigned int position)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename type>
|
||||||
|
type **vector<type>::data()
|
||||||
|
{
|
||||||
|
return myData;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Author: Josh Holtrop
|
// Author: Josh Holtrop
|
||||||
// Date: 09/30/03
|
// Date: 09/30/03
|
||||||
// Rewritten from scratch: 12/23/03
|
// Rewritten from scratch: 12/23/03
|
||||||
// Modified: 08/17/05
|
// Modified: 09/12/05
|
||||||
|
|
||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
@ -157,11 +157,13 @@ void *kmalloc(u32_t size)
|
|||||||
if (size % VMM_MALLOC_GRANULARITY)
|
if (size % VMM_MALLOC_GRANULARITY)
|
||||||
size = size + VMM_MALLOC_GRANULARITY -
|
size = size + VMM_MALLOC_GRANULARITY -
|
||||||
(size % VMM_MALLOC_GRANULARITY);
|
(size % VMM_MALLOC_GRANULARITY);
|
||||||
|
/* added 09/12/05 by josh - fixed bug returning size 0 segments
|
||||||
|
multiple times */
|
||||||
|
if (size < VMM_MALLOC_GRANULARITY)
|
||||||
|
size = VMM_MALLOC_GRANULARITY;
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -171,8 +173,6 @@ 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;
|
||||||
}
|
}
|
||||||
@ -485,8 +485,6 @@ 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)
|
||||||
@ -515,7 +513,7 @@ 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)
|
if (! he->next)
|
||||||
kprintf(" he->next is NULL\n");
|
k_check(1, "kernel panic: 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;
|
||||||
|
@ -37,17 +37,11 @@ int hash::add(u32_t key, void *val)
|
|||||||
for (u32_t i = 0; i < myTable[hashed].size(); i++)
|
for (u32_t i = 0; i < myTable[hashed].size(); i++)
|
||||||
if ( myTable[hashed][i].key == key )
|
if ( myTable[hashed][i].key == key )
|
||||||
return -1; // key exists already
|
return -1; // key exists already
|
||||||
kprintf("hash.cpp: %d (slot %d) -> %d\n", key, hashed, val);
|
|
||||||
hash_entry_t he = {key, 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);
|
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++;
|
mySize++;
|
||||||
if ( mySize > (hash_primes[mySizeIndex] << 1) ) // re-hash
|
if ( mySize > (hash_primes[mySizeIndex] << 1) ) // re-hash
|
||||||
{
|
{
|
||||||
kprintf("re-hashing\n");
|
|
||||||
vector< vector<hash_entry_t> > oldTable = myTable;
|
vector< vector<hash_entry_t> > oldTable = myTable;
|
||||||
mySizeIndex++;
|
mySizeIndex++;
|
||||||
myTable = vector< vector<hash_entry_t> >();
|
myTable = vector< vector<hash_entry_t> >();
|
||||||
@ -99,7 +93,7 @@ int hash::exists(u32_t key)
|
|||||||
|
|
||||||
u32_t hash::hash_key(u32_t key)
|
u32_t hash::hash_key(u32_t key)
|
||||||
{
|
{
|
||||||
return key % hash_primes[mySizeIndex];
|
return ((key * 11) + mySizeIndex) % hash_primes[mySizeIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
u32_t hash::size()
|
u32_t hash::size()
|
||||||
|
@ -27,9 +27,12 @@ extern "C" {
|
|||||||
u32_t cur_task = 0;
|
u32_t cur_task = 0;
|
||||||
u32_t n_processes = 0;
|
u32_t n_processes = 0;
|
||||||
tss_t tss0;
|
tss_t tss0;
|
||||||
|
u32_t pid_base = 1024;
|
||||||
|
u32_t pid_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
hash *processes;
|
hash *processes;
|
||||||
|
vector<u32_t> *pids;
|
||||||
|
|
||||||
int proc_init()
|
int proc_init()
|
||||||
{
|
{
|
||||||
@ -37,54 +40,54 @@ 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();
|
||||||
vector< vector<int> > test;
|
process_t *proc = (process_t *)New(process_t);
|
||||||
for (u32_t i = 0; i < 5; i++)
|
proc->p_page_dir = read_cr3();
|
||||||
test.add(vector<int>());
|
proc->page_dir = (u32_t *)0xFFFFF000;
|
||||||
for (u32_t i = 0; i < 5; i++)
|
processes->add(0, proc);
|
||||||
for (u32_t j = 0; j < 3; j++)
|
pids = new vector<u32_t>();
|
||||||
test[i].add(i*10+j);
|
pids->add(0);
|
||||||
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);
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
kprintf("size: %d\n", processes->size());
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void proc_sched(int_stack_t *int_stack)
|
void proc_sched(int_stack_t *int_stack)
|
||||||
{
|
{
|
||||||
|
u32_t new_pid_index = (pid_index + 1) % pids->size();
|
||||||
|
switch_task(int_stack, (*pids)[new_pid_index]);
|
||||||
|
pid_index = new_pid_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32_t get_pid()
|
||||||
|
{
|
||||||
|
u32_t potential = pid_base;
|
||||||
|
while (processes->exists(potential))
|
||||||
|
{
|
||||||
|
potential++;
|
||||||
|
if (potential == 0)
|
||||||
|
potential = PROC_MIN_USER_PID;
|
||||||
|
}
|
||||||
|
pid_base = potential + 1;
|
||||||
|
if (pid_base == 0)
|
||||||
|
pid_base = PROC_MIN_USER_PID;
|
||||||
|
return potential;
|
||||||
}
|
}
|
||||||
|
|
||||||
void switch_task(int_stack_t *int_stack, u32_t new_task)
|
void switch_task(int_stack_t *int_stack, u32_t new_task)
|
||||||
{
|
{
|
||||||
// memcpy((*processes)[cur_task]->int_stack, int_stack, sizeof(int_stack_t));
|
memcpy(&((process_t *)processes->get(cur_task))->int_stack,
|
||||||
|
(void *) int_stack,
|
||||||
|
sizeof(int_stack_t));
|
||||||
cur_task = new_task;
|
cur_task = new_task;
|
||||||
// memcpy(int_stack, (*processes)[cur_task]->int_stack, sizeof(int_stack_t));
|
memcpy(int_stack, &((process_t *)processes->get(cur_task))->int_stack,
|
||||||
// write_cr3((*processes)[cur_task]->p_page_dir);
|
sizeof(int_stack_t));
|
||||||
|
write_cr3( ((process_t *)processes->get(cur_task))->p_page_dir );
|
||||||
}
|
}
|
||||||
|
|
||||||
u32_t create_task(void *base, u32_t image_size, u32_t bss_size, void *entry)
|
u32_t create_task(void *base, u32_t image_size, u32_t bss_size, void *entry)
|
||||||
{
|
{
|
||||||
u32_t pid;
|
u32_t pid = get_pid();
|
||||||
// processes[++n_processes] = create_process(base, image_size, bss_size, entry);
|
processes->add(pid, create_process(base, image_size, bss_size, entry));
|
||||||
|
pids->add(pid);
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ extern "C" {
|
|||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
|
#define PROC_MIN_USER_PID 1024
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u32_t *page_dir; /* Page directory with physical PT addys */
|
u32_t *page_dir; /* Page directory with physical PT addys */
|
||||||
@ -67,6 +69,7 @@ typedef struct
|
|||||||
|
|
||||||
int proc_init();
|
int proc_init();
|
||||||
void proc_sched(int_stack_t *int_stack);
|
void proc_sched(int_stack_t *int_stack);
|
||||||
|
u32_t get_pid();
|
||||||
void switch_task(int_stack_t *int_stack, u32_t new_task);
|
void switch_task(int_stack_t *int_stack, u32_t new_task);
|
||||||
u32_t create_task(void *base, u32_t image_size, u32_t bss_size, void *entry);
|
u32_t create_task(void *base, u32_t image_size, u32_t bss_size, void *entry);
|
||||||
process_t *create_process(void *base, u32_t image_size, u32_t bss_size, void *entry);
|
process_t *create_process(void *base, u32_t image_size, u32_t bss_size, void *entry);
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
; ebx = return address
|
; ebx = return address
|
||||||
; ecx = where to store real mode parameter table
|
; ecx = where to store real mode parameter table
|
||||||
start:
|
start:
|
||||||
|
jmp blah
|
||||||
|
blah:
|
||||||
|
jmp $
|
||||||
jmp 0:start_refreshed
|
jmp 0:start_refreshed
|
||||||
|
|
||||||
%include "conio.inc"
|
%include "conio.inc"
|
||||||
@ -29,6 +32,8 @@ start_refreshed:
|
|||||||
mov ax, cs ; 0
|
mov ax, cs ; 0
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov es, ax
|
mov es, ax
|
||||||
|
mov fs, ax
|
||||||
|
mov gs, ax
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
mov esp, 0x7000
|
mov esp, 0x7000
|
||||||
mov [dat_rmadd], ecx
|
mov [dat_rmadd], ecx
|
||||||
|
Loading…
x
Reference in New Issue
Block a user