diff options
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/config.h | 8 | ||||
-rw-r--r-- | src/kernel/linker/elf.cpp | 4 | ||||
-rw-r--r-- | src/kernel/task/idt.cpp | 2 | ||||
-rw-r--r-- | src/kernel/task/syscall.cpp | 2 | ||||
-rw-r--r-- | src/kernel/task/task.cpp | 98 | ||||
-rw-r--r-- | src/kernel/task/task.h | 22 | ||||
-rw-r--r-- | src/kernel/task/timer.cpp | 2 |
7 files changed, 56 insertions, 82 deletions
diff --git a/src/kernel/config.h b/src/kernel/config.h index ee6141e..c39a832 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -5,13 +5,5 @@ #define K_OS_VER "0.0.2" #define K_OS_CODENAME "CPLUSPLUS==\\o/" -/* HEAP CODE TO USE : - Two kernel heap implementations are available : - - Basic implementation, slow but bug-free - - Standard implementation, efficient, buggy, based on the heap code from JamesM's OSDev tutorial - Comment the following define to use the second version */ -// #define K_USE_BASIC_HEAP - - #endif diff --git a/src/kernel/linker/elf.cpp b/src/kernel/linker/elf.cpp index ab8e349..c94e5c0 100644 --- a/src/kernel/linker/elf.cpp +++ b/src/kernel/linker/elf.cpp @@ -47,11 +47,11 @@ thread_entry elf_load(uint8_t *data, process* process) { process* elf_exec(uint8_t *data, int privilege) { if (elf_check(data)) return 0; - process* p = process_new(0, 0, privilege); + process* p = new process(0, 0, privilege); thread_entry e = elf_load(data, p); - thread_new(p, e, 0, 0); + new thread(p, e, 0, 0); return p; } diff --git a/src/kernel/task/idt.cpp b/src/kernel/task/idt.cpp index ebc092d..9008083 100644 --- a/src/kernel/task/idt.cpp +++ b/src/kernel/task/idt.cpp @@ -98,7 +98,7 @@ extern "C" void idt_irqHandler(registers regs) { outb(0x20, 0x20); while (irq_wakeup[regs.err_code] != 0) { irq_waiter *tmp = irq_wakeup[regs.err_code]; - thread_wakeUp(tmp->thread); + tmp->thread->wakeUp(); irq_wakeup[regs.err_code] = tmp->next; kfree(tmp); doSwitch = 1; diff --git a/src/kernel/task/syscall.cpp b/src/kernel/task/syscall.cpp index 6880745..7a83c25 100644 --- a/src/kernel/task/syscall.cpp +++ b/src/kernel/task/syscall.cpp @@ -32,7 +32,7 @@ static void printk_sc(registers *r) { static void thread_new_sc(registers* r) { cli(); - thread_new(current_thread->process, (thread_entry)r->ebx, (void*)r->ecx, (void*)r->edx); + new thread(current_thread->process, (thread_entry)r->ebx, (void*)r->ecx, (void*)r->edx); sti(); } diff --git a/src/kernel/task/task.cpp b/src/kernel/task/task.cpp index b7c8f45..96864da 100644 --- a/src/kernel/task/task.cpp +++ b/src/kernel/task/task.cpp @@ -37,7 +37,7 @@ void tasking_init() { kernel_process->next = 0; kernel_process->threads = 0; current_thread = 0; - idle_thread = thread_new(kernel_process, task_idle, 0, 0); + idle_thread = new thread(kernel_process, task_idle, 0, 0); sti(); monitor_write("[Tasking] "); } @@ -126,10 +126,10 @@ void thread_goInactive() { } /* Wakes up the given thread. */ -void thread_wakeUp(thread* t) { - if (t->state == TS_WAKEWAIT) { - t->state = TS_RUNNING; - sched_enqueue(t); +void thread::wakeUp() { + if (state == TS_WAKEWAIT) { + state = TS_RUNNING; + sched_enqueue(this); } } @@ -237,65 +237,61 @@ static void thread_run(void* u_esp, thread *thread, thread_entry entry_point, vo /* Creates a new thread for given process. Allocates a kernel stack and a user stack if necessary. Sets up the kernel stack for values to be passed to thread_run. */ -thread *thread_new(process *proc, thread_entry entry_point, void *data, void *u_esp) { - thread *t = new thread(); - t->process = proc; - t->next = 0; +thread::thread(class process *proc, thread_entry entry_point, void *data, void *u_esp) { + process = proc; + next = 0; proc->thread_count++; if (u_esp == 0) u_esp = (void*)proc->stack; - t->kernelStack_addr = kmalloc(KSTACKSIZE); - t->kernelStack_size = KSTACKSIZE; + kernelStack_addr = kmalloc(KSTACKSIZE); + kernelStack_size = KSTACKSIZE; - uint32_t *stack = (uint32_t*)((size_t)t->kernelStack_addr + t->kernelStack_size); + uint32_t *stack = (uint32_t*)((size_t)kernelStack_addr + kernelStack_size); //Pass parameters stack--; *stack = (uint32_t)data; stack--; *stack = (uint32_t)entry_point; - stack--; *stack = (uint32_t)t; + stack--; *stack = (uint32_t)this; stack--; *stack = (uint32_t)u_esp; stack--; *stack = 0; - t->esp = (uint32_t)stack; - t->ebp = t->esp + 8; - t->eip = (uint32_t)thread_run; + esp = (uint32_t)stack; + ebp = esp + 8; + eip = (uint32_t)thread_run; - t->state = TS_RUNNING; - sched_enqueue(t); + state = TS_RUNNING; + sched_enqueue(this); if (proc->threads == 0) { - proc->threads = t; + proc->threads = this; } else { thread *i = proc->threads; while (i->next != 0) i = i->next; - i->next = t; + i->next = this; } - return t; } /* Creates a new process. Creates a struct process and fills it up. */ -process *process_new(process* parent, uint32_t uid, uint32_t privilege) { - process* p = new process(); - p->pid = (nextpid++); - p->uid = uid; - p->thread_count = 0; - p->threads = 0; - p->privilege = privilege; - p->parent = parent; - p->pagedir = pagedir_new(); - p->next = processes; - p->data = 0; - p->dataseg = 0; - - p->stack = 0; - if (p->privilege >= PL_USER) { //We are running in user mode +process::process(process* parent, uint32_t uid, uint32_t privilege) { + pid = (nextpid++); + uid = uid; + thread_count = 0; + threads = 0; + privilege = privilege; + parent = parent; + pagedir = pagedir_new(); + next = processes; + data = 0; + dataseg = 0; + + stack = 0; + if (privilege >= PL_USER) { //We are running in user mode size_t stacksBottom = K_HIGHHALF_ADDR - 0x01000000; - seg_map(simpleseg_make(stacksBottom, USER_STACK_SIZE, 1), p->pagedir, 0); - p->stack = stacksBottom + USER_STACK_SIZE - 4; + seg_map(simpleseg_make(stacksBottom, USER_STACK_SIZE, 1), pagedir, 0); + stack = stacksBottom + USER_STACK_SIZE - 4; } - processes = p; - return p; + processes = this; } /* Deletes given thread, freeing the stack(s). */ @@ -341,28 +337,6 @@ static void process_delete(process *pr) { kfree(pr); } -/* System call. Called by the app to define the place for the heap. */ -/*int process_setheapseg(size_t start, size_t end) { //syscall - struct process *p = current_thread->process; - if (start >= K_HIGHHALF_ADDR || end >= K_HIGHHALF_ADDR) return -1; - if (p->heapseg == 0) { - struct segment *s = simpleseg_make(start, end - start, 1); - if (s == 0) return -5; - p->heapseg = seg_map(s, p->pagedir, 0); - if (p->heapseg == 0) return -1; - return 0; - } else if (p->heapseg->start != start) { - seg_unmap(p->heapseg); - struct segment *s = simpleseg_make(start, end - start, 1); - if (s == 0) return -5; - p->heapseg = seg_map(s, p->pagedir, 0); - if (p->heapseg == 0) return -1; - return 0; - } else { - return simpleseg_resize(p->heapseg, end - start); - } -}*/ - size_t process_sbrk(size_t size) { process *p = current_thread->process; if (p->data == 0) return -1; diff --git a/src/kernel/task/task.h b/src/kernel/task/task.h index 47d7632..69b431d 100644 --- a/src/kernel/task/task.h +++ b/src/kernel/task/task.h @@ -20,8 +20,10 @@ typedef void (*thread_entry)(void*); -struct thread; -struct process { +class thread; +class process { + public: + uint32_t pid, uid, privilege, thread_count; process *parent; page_directory *pagedir; @@ -31,10 +33,15 @@ struct process { process *next; //Forms a linked list thread *threads; + + process() {} // must not be used directly + process(process *parent, uint32_t uid, uint32_t privilege); }; -struct thread { - struct process *process; +class thread { + public: + + class process *process; uint32_t esp, ebp, eip; uint8_t state; uint32_t timeWait; @@ -42,6 +49,10 @@ struct thread { uint32_t kernelStack_size; thread *next, *queue_next; //queue_next is used in sched.c + + thread(class process *proc, thread_entry entry_point, void *data, void *u_esp); + + void wakeUp(); }; extern thread *current_thread; @@ -56,10 +67,7 @@ void tasking_updateKernelPagetable(uint32_t idx, page_table *table, uint32_t tab uint32_t tasking_handleException(registers *regs); void thread_goInactive(); //Blocks the current thread. it is then waked up by another thread or a system event. -void thread_wakeUp(thread *t); int proc_priv(); //Returns current privilege level -thread * thread_new(process *proc, thread_entry entry_point, void *data, void *u_esp); -process* process_new(process *parent, uint32_t uid, uint32_t privilege); void thread_exit(); //syscall void process_exit(size_t retval); //syscall diff --git a/src/kernel/task/timer.cpp b/src/kernel/task/timer.cpp index 05c4550..ccc3c79 100644 --- a/src/kernel/task/timer.cpp +++ b/src/kernel/task/timer.cpp @@ -84,7 +84,7 @@ void timer_wakeUpSleepingThreads() { uint32_t time = timer_time(); while (sleeping_threads != 0 && sleeping_threads->wakeup_time <= time) { sleeping_thread *tmp = sleeping_threads; - thread_wakeUp(tmp->thread); + tmp->thread->wakeUp(); sleeping_threads = tmp->next; kfree(tmp); } |