Import backup from 2005-08-29

This commit is contained in:
Josh Holtrop 2005-08-29 22:00:00 -04:00
parent daa29212d0
commit 2b67ff6f49
11 changed files with 276 additions and 84 deletions

View File

@ -22,18 +22,18 @@ LDFLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
OBJS=boot.o lang/lang_a.o \
kernel.o mm/mm.o mm/vmm.o lang/conv.o display/kout.o \
display/display.o sys/pic.o char/keyboard.o lang/lang.o \
sys/pci_classes.o proc/proc.o \
sys/pci_classes.o proc/proc.o proc/hash.o \
lang/string.o lang/new.o char/misc_char.o char/vconsole.o \
devices.o block/ramdisk.o fs/vfs.o fs/FileSystem.o fs/VFSMount.o \
fs/ext2/ext2.o fs/sysfs/sysfs.o fs/sysfs/sysfs_entry.o \
sys/pci.o
CSRC=kernel.c mm/mm.c mm/vmm.c lang/conv.c display/kout.c \
display/display.c sys/pic.c char/keyboard.c lang/lang.c \
sys/pci_classes.c proc/proc.c
sys/pci_classes.c
CXXSRC=lang/string.cpp lang/new.cpp char/misc_char.cpp char/vconsole.cpp \
block/ramdisk.cpp devices.cpp fs/vfs.cpp fs/FileSystem.o fs/VFSMount.o\
fs/ext2/ext2.cpp fs/sysfs/sysfs.cpp fs/sysfs/sysfs_entry.cpp \
sys/pci.cpp
sys/pci.cpp proc/proc.cpp proc/hash.cpp
.PHONY: all depend clean html
@ -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

View File

@ -22,18 +22,18 @@ LDFLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
OBJS=boot.o lang/lang_a.o \
kernel.o mm/mm.o mm/vmm.o lang/conv.o display/kout.o \
display/display.o sys/pic.o char/keyboard.o lang/lang.o \
sys/pci_classes.o proc/proc.o \
sys/pci_classes.o proc/proc.o proc/hash.o \
lang/string.o lang/new.o char/misc_char.o char/vconsole.o \
devices.o block/ramdisk.o fs/vfs.o fs/FileSystem.o fs/VFSMount.o \
fs/ext2/ext2.o fs/sysfs/sysfs.o fs/sysfs/sysfs_entry.o \
sys/pci.o
CSRC=kernel.c mm/mm.c mm/vmm.c lang/conv.c display/kout.c \
display/display.c sys/pic.c char/keyboard.c lang/lang.c \
sys/pci_classes.c proc/proc.c
sys/pci_classes.c
CXXSRC=lang/string.cpp lang/new.cpp char/misc_char.cpp char/vconsole.cpp \
block/ramdisk.cpp devices.cpp fs/vfs.cpp fs/FileSystem.o fs/VFSMount.o\
fs/ext2/ext2.cpp fs/sysfs/sysfs.cpp fs/sysfs/sysfs_entry.cpp \
sys/pci.cpp
sys/pci.cpp proc/proc.cpp proc/hash.cpp
.PHONY: all depend clean html
@ -44,7 +44,7 @@ all: $(OBJS)
depend:
makedepend -- $(CPPFLAGS) -- $(CSRC) $(CXXSRC)
boot.o: boot.asm
boot.o: boot.asm idt.inc gdt.inc
$(NASM) $(NASM_FLAGS) -l boot.lst boot.asm -o boot.o
lang/lang_a.o: lang/lang.asm
@ -79,6 +79,7 @@ sys/pic.o: hos_defines.h sys/pic.h sys/io.h
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
@ -96,3 +97,9 @@ fs/vfs.o: fs/FileSystem.h fs/VFSMount.h fs/FileSystem.h fs/vfs.h
fs/vfs.o: fs/ext2/ext2.h lang/vector.h
fs/ext2/ext2.o: display/kout.h hos_defines.h mm/vmm.h multiboot.h lang/lang.h
fs/ext2/ext2.o: fs/ext2/ext2.h fs/vfs.h devices.h
fs/sysfs/sysfs.o: display/kout.h hos_defines.h fs/vfs.h devices.h
fs/sysfs/sysfs.o: fs/sysfs/sysfs.h fs/FileSystem.h lang/vector.h
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

View File

@ -26,7 +26,6 @@
%define KERNEL_V KERNEL_P+VIRT_OFFSET ;3gb+1mb+32kb, the virtual address of the kernel
extern _k_init, _isr, _k_mbsave, _end, _rm_params, _initrd, _tss0, _kprintf
extern _proc_new_esp, _proc_new_ss
[bits 32]
@ -180,11 +179,6 @@ newgdtcontinue:
mov ax, TSS0_SEG
ltr ax
; push esp
; push msg1
; call _kprintf
; add esp, 8
mov eax, esp
push KERNEL_DATA
push eax
@ -194,9 +188,6 @@ idle_loop: ; system idle loop
hlt
jmp idle_loop
msg1:
db "esp before idle_loop: 0x%x", 10, 0
;-------------------------------------------------------
gdtrbs32:
dw gdt_endbs32-gdtbs32-1

View File

@ -1 +0,0 @@
53 97 193 389 769 1543 3079 6151 12289 24593 49157

View File

@ -12,14 +12,6 @@ idtr:
isr_%1:
push eax
mov eax, %1
; push eax
; push esp
; push msg
; call _kprintf
; add esp, 12
; hlt
jmp isr_main
%endmacro
@ -91,11 +83,6 @@ isr_main:
call _isr
add esp, 8
; mov eax, [_proc_new_ss]
; mov ebx, [_proc_new_esp]
; mov ss, ax
; mov esp, ebx
pop gs
pop fs
pop es
@ -110,5 +97,3 @@ isr_main:
iret
msg:
db "esp is 0x%x after int %d", 10, 0

View File

@ -23,18 +23,21 @@ typedef struct
u32_t fs;
u32_t es;
u32_t ds;
u32_t ebp;
u32_t esi;
u32_t edi;
u32_t edx;
u32_t ecx;
u32_t ebx;
u32_t eax;
u32_t eip;
u32_t cs;
u32_t eflags;
u32_t esp;
u32_t ss; /* present if ring3->ring0 transition ?? */
u32_t esp; /* present if ring3->ring0 transition ?? */
u32_t ss;
} int_stack_t;
/* returns true to callee if we should jump to a real mode module */

135
kernel/proc/hash.cpp Normal file
View File

@ -0,0 +1,135 @@
// hash.cpp
// Author: Josh Holtrop
// Date: 08/28/05
// Modified: 08/28/05
// Implements a basic hash table (u32_t -> void*)
#define __HOS_CPP__
#include "hos_defines.h"
#include "hash.h"
#include "lang/vector.h"
extern "C"{
#include "display/kout.h"
#include "mm/vmm.h"
}
/* Hash Primes come from
* http://planetmath.org/encyclopedia/GoodHashTablePrimes.html
*/
const u32_t hash_primes[] =
{53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317,
196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843,
50331653, 100663319, 201326611, 402653189, 805306457, 1610612741};
hash::hash()
{
mySizeIndex = 0;
mySize = 0;
myTable = new (vector<hash_entry_t *> *)[hash_primes[mySizeIndex]];
for (u32_t i = 0; i < hash_primes[mySizeIndex]; i++)
myTable[i] = NULL;
}
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 )
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);
mySize++;
kprintf("*%d*\t", mySize);
if ( mySize > (hash_primes[mySizeIndex] << 1) ) // re-hash
{
kprintf("*1*");
vector<hash_entry_t *> **oldTable = myTable;
mySizeIndex++;
myTable = new (vector<hash_entry_t *> *)[hash_primes[mySizeIndex]];
for (u32_t i = 0; i < hash_primes[mySizeIndex]; i++)
myTable[i] = NULL;
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++)
{
add( (*(oldTable[i]))[j]->key,
(*(oldTable[i]))[j]->data );
kfree( (*(oldTable[i]))[j] );
}
delete oldTable[i];
}
}
kprintf("*3*");
delete oldTable;
}
return 0;
}
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;
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 )
{
kfree( (*vec)[i] );
vec->remove(i); // remove key
mySize--;
return 0;
}
return -1;
}
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 )
return 1; // key exists
return 0;
}
u32_t hash::hash_key(u32_t key)
{
return key % hash_primes[mySizeIndex];
}
u32_t hash::size()
{
return mySize;
}

55
kernel/proc/hash.h Normal file
View File

@ -0,0 +1,55 @@
// hash.h
// Author: Josh Holtrop
// Date: 08/28/05
// Modified: 08/28/05
// Implements a basic hash table (u32_t -> void*)
#ifndef __HOS_HASH_H__
#define __HOS_HASH_H__ __HOS_HASH_H__
#include "hos_defines.h"
#include "lang/vector.h"
typedef struct
{
u32_t key;
void *data;
} hash_entry_t;
class hash
{
private:
/* index into hash_primes[] */
u32_t mySizeIndex;
/* How many values in the hash table */
u32_t mySize;
/* array of hash entries */
vector<hash_entry_t *> **myTable;
/* hash the key to a table index */
u32_t hash_key(u32_t key);
public:
/* Constructor */
hash();
/* Add a value to the hash table */
int add(u32_t key, void *val);
/* Retrieve a value from the hash table */
void *get(u32_t key);
/* Remove a value from the hash table */
int remove(u32_t key);
/* Check if the given key exists in the hash table */
int exists(u32_t key);
/* How many values are in the hash table */
u32_t size();
};
#endif

View File

@ -3,24 +3,33 @@
// Date; 08/18/05
// Modified: 08/18/05
extern int mm_freepages;
#define __HOS_CPP__
extern "C" {
#include "hos_defines.h"
#include "proc.h"
#include "mm/mm.h"
#include "mm/vmm.h"
#include "lang/lang.h"
#include "kernel.h"
#include "functions.h" //halt()
extern u32_t idle_loop;
#include "display/kout.h"
extern u32_t mm_freepages;
}
#include "proc.h"
#include "proc/hash.h"
extern "C" {
u32_t cur_task = 0;
u32_t n_processes = 0;
process_t *processes[3];
tss_t tss0;
u32_t proc_new_esp;
u32_t proc_new_ss;
}
hash *processes;
int proc_init()
{
@ -28,32 +37,40 @@ int proc_init()
memset(&tss0, 0, sizeof(tss_t));
tss0.ss0 = SEG_KERNEL_DATA;
tss0.esp0 = VIRT_STACK_TOP;
/* tss0.pdbr = read_cr3();
tss0.eip = &idle_loop;
tss0.eflags = 0x0202;
tss0.esp = VIRT_STACK_TOP-32; // idle_loop won't use -- a good thing
tss0.es = tss0.ds = tss0.fs = tss0.gs = tss0.ss = SEG_KERNEL_DATA;
tss0.cs = SEG_KERNEL_CODE; */
processes[0] = New(process_t);
processes[0]->p_page_dir = read_cr3();
processes[0]->page_dir = (void *)0xFFFFF000;
processes = new hash();
for (u32_t i = 0; i < 110; i++)
{
processes->add(i, (void *) i);
}
for (u32_t i = 0; i < 110; 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;
}
void proc_sched(int_stack_t *int_stack)
{
memcpy(&processes[cur_task]->int_stack, int_stack, sizeof(int_stack_t));
cur_task++;
if (cur_task == 3)
cur_task = 0;
memcpy(int_stack, &processes[cur_task]->int_stack, sizeof(int_stack_t));
write_cr3(processes[cur_task]->p_page_dir);
}
void switch_task(int_stack_t *int_stack, u32_t new_task)
{
// memcpy((*processes)[cur_task]->int_stack, int_stack, sizeof(int_stack_t));
cur_task = new_task;
// memcpy(int_stack, (*processes)[cur_task]->int_stack, sizeof(int_stack_t));
// write_cr3((*processes)[cur_task]->p_page_dir);
}
u32_t create_task(void *base, u32_t image_size, u32_t bss_size, void *entry)
{
processes[++n_processes] = create_process(base, image_size, bss_size, entry);
return n_processes;
u32_t pid;
// processes[++n_processes] = create_process(base, image_size, bss_size, entry);
return pid;
}
/* Create process_t struct for a new process
@ -63,17 +80,17 @@ process_t *create_process(void *base, u32_t image_size, u32_t bss_size, void *en
{
if (mm_freepages < ((image_size + bss_size) >> 12) + 25)
return 0;
process_t *process = New(process_t); /* Allocate process_t struct */
process_t *process = (process_t *) New(process_t); /* Allocate process_t struct */
create_address_space(process);
create_process_stack(process, entry);
int i;
u32_t *ptr32 = process->v_page_dir = vmm_palloc();
u32_t *ptr32 = process->v_page_dir = (u32_t *) vmm_palloc();
for (i = 0; i < 1024; i++)
*ptr32++ = 0;
u32_t code_data_pages = (image_size + 4095) >> 12;
u32_t bss_pages = (bss_size + 4095) >> 12;
/* Load program at address 0 */
copy_into_address_space(0, base, code_data_pages, process);
copy_into_address_space(0, (char *) base, code_data_pages, process);
zero_address_space(code_data_pages << 12, bss_pages, process);
ptr32 = process->v_page_dir;
for (i = 0; i < 1024; i++)
@ -88,7 +105,7 @@ process_t *create_process(void *base, u32_t image_size, u32_t bss_size, void *en
void create_address_space(process_t *p)
{
/* Allocate a new page directory */
p->page_dir = vmm_palloc_addr(&p->p_page_dir);
p->page_dir = (u32_t *) vmm_palloc_addr(&p->p_page_dir);
int i;
u32_t *ptr32 = p->page_dir;
for (i = 0; i < 768; i++) /* zero 3 gigs */
@ -99,8 +116,8 @@ void create_address_space(process_t *p)
void create_process_stack(process_t *p, void *entry)
{
u32_t p_stack_table, p_stack;
u32_t *v_stack_table = vmm_palloc_addr(&p_stack_table);
u32_t *v_stack = vmm_palloc_addr(&p_stack);
u32_t *v_stack_table = (u32_t *) vmm_palloc_addr(&p_stack_table);
u32_t *v_stack = (u32_t *) vmm_palloc_addr(&p_stack);
int i;
u32_t *ptr32 = v_stack_table;
for (i = 0; i < 1023; i++)
@ -122,7 +139,7 @@ void create_process_stack(process_t *p, void *entry)
/* Copy pages into new address space (v_page_dir must be set up) */
void copy_into_address_space(u32_t dest_addr,
void *src_addr,
char *src_addr,
u32_t pages,
process_t *p)
{
@ -138,7 +155,6 @@ void copy_into_address_space(u32_t dest_addr,
/* Time for a new page table & page directory entry! */
p->v_page_dir[pde] = (u32_t)vmm_palloc_addr(&p_page_addr);
p->page_dir[pde] = p_page_addr | 0x7;
// vmm_unmapp((void *)p->v_page_dir[pde]);
}
page = vmm_palloc_addr(&p_page_addr);
((u32_t *)(p->v_page_dir[pde]))[pte] = p_page_addr | 0x7;
@ -176,7 +192,3 @@ void zero_address_space(u32_t dest_addr, u32_t pages, process_t *p)
}
}
u32_t fork(process_t *p)
{
return 0;
}

View File

@ -6,6 +6,10 @@
#ifndef __HOS_PROC_H__
#define __HOS_PROC_H__ __HOS_PROC_H__
#ifdef __HOS_CPP__
extern "C" {
#endif
#include "hos_defines.h"
#include "kernel.h"
@ -15,11 +19,7 @@ typedef struct
u32_t *v_page_dir; /* Virtual page table addresses for init */
u32_t p_page_dir; /* Physical address of page directory */
u32_t size; /* Process size, bytes from 0 through bss */
// u32_t ss;
// u32_t esp;
// u32_t eflags;
// u32_t cs;
// u32_t eip;
u32_t uid; /* Process owner */
int_stack_t int_stack;
} process_t;
@ -67,17 +67,20 @@ typedef struct
int proc_init();
void proc_sched(int_stack_t *int_stack);
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);
process_t *create_process(void *base, u32_t image_size, u32_t bss_size, void *entry);
void create_address_space(process_t *p);
void create_process_stack(process_t *p, void *entry);
void copy_into_address_space(u32_t dest_addr,
void *src_addr,
char *src_addr,
u32_t pages,
process_t *p);
void zero_address_space(u32_t dest_addr, u32_t pages, process_t *p);
u32_t fork(process_t *p);
#ifdef __HOS_CPP__
}
#endif
#endif

View File

@ -1,8 +1,9 @@
NASM=nasm
all:
@echo ' $$(NASM) rmmod.bin'
@$(NASM) -f bin rmmod.asm -l rmmod.lst -o rmmod.bin
all: rmmod.bin
rmmod.bin: rmmod.asm
$(NASM) -f bin rmmod.asm -l rmmod.lst -o rmmod.bin
clean:
-rm -f *~ *.o *.bin *.lst