summaryrefslogtreecommitdiff
path: root/src/kernel/task/task.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/task/task.cpp')
-rw-r--r--src/kernel/task/task.cpp98
1 files changed, 36 insertions, 62 deletions
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;