summaryrefslogtreecommitdiff
path: root/src/stem/task
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2010-02-05 17:33:08 +0100
committerAlexis211 <alexis211@gmail.com>2010-02-05 17:33:08 +0100
commit674014901a1e90ce1587a7709fe9bf5893b0e36e (patch)
tree0696d09e4a185413df75f8e3ef413b5ae81a090d /src/stem/task
parent6d849bc12d6afe2fe239c5a7dc581ba76d67974b (diff)
downloadTCE-674014901a1e90ce1587a7709fe9bf5893b0e36e.tar.gz
TCE-674014901a1e90ce1587a7709fe9bf5893b0e36e.zip
Start work on syscalls, advanced tasking, segmentation
Diffstat (limited to 'src/stem/task')
-rw-r--r--src/stem/task/idt.c2
-rw-r--r--src/stem/task/syscall.c2
-rw-r--r--src/stem/task/task.c50
-rw-r--r--src/stem/task/task.h11
4 files changed, 50 insertions, 15 deletions
diff --git a/src/stem/task/idt.c b/src/stem/task/idt.c
index 7c05e2e..4866550 100644
--- a/src/stem/task/idt.c
+++ b/src/stem/task/idt.c
@@ -67,7 +67,7 @@ struct idt_ptr idt_ptr;
static int_callback irq_handlers[16] = {0};
void idt_isrHandler(struct registers regs) {
- if ((regs.int_no == 14 && paging_fault(&regs) == 0) || regs.int_no != 14) {
+ if ((regs.int_no == 14 && paging_fault(&regs) != 0) || regs.int_no != 14) {
if (tasking_handleException(&regs) == 0) {
monitor_write(" >> >> SOMETHING BAD HAPPENNED << <<\n");
monitor_write("Unhandled exception ");
diff --git a/src/stem/task/syscall.c b/src/stem/task/syscall.c
index 281d680..6964b34 100644
--- a/src/stem/task/syscall.c
+++ b/src/stem/task/syscall.c
@@ -7,10 +7,12 @@
r->eax = name(r->ebx, r->ecx); }
CALL0(tasking_switch, schedule_sc);
+CALL1(monitor_write, printk_sc);
int_callback syscalls[] = {
0, //Syscall 0 will be thread_exit
schedule_sc,
0, //Syscall 2 will be thread_sleep
0, //Syscall 3 will be process_exit
+ printk_sc,
0 };
diff --git a/src/stem/task/task.c b/src/stem/task/task.c
index 39c2482..8ed5190 100644
--- a/src/stem/task/task.c
+++ b/src/stem/task/task.c
@@ -12,21 +12,24 @@ extern void task_idle(void*);
static uint32_t thread_runnable(struct thread *th);
-uint32_t nextpid = 1;
+static uint32_t nextpid = 1;
-struct process *processes = 0;
-struct thread *threads = 0, *current_thread = 0;
+struct process *processes = 0, *kernel_process;
+struct thread *threads = 0, *current_thread = 0, *idle_thread;
+
+uint32_t tasking_tmpStack[0x4000];
void tasking_init(thread_entry whereToGo, void *data) {
cli();
- struct process *pr = kmalloc(sizeof(struct process)); //This process must be hidden to users
- pr->pid = pr->uid = 0;
- pr->parent = pr;
- pr->pagedir = kernel_pagedir;
- pr->next = 0;
+ kernel_process = kmalloc(sizeof(struct process)); //This process must be hidden to users
+ kernel_process->pid = kernel_process->uid = kernel_process->threads = 0;
+ kernel_process->privilege = PL_KERNEL;
+ kernel_process->parent = kernel_process;
+ kernel_process->pagedir = kernel_pagedir;
+ kernel_process->next = 0;
current_thread = 0;
- thread_new(pr, task_idle, 0);
- thread_new(pr, whereToGo, data);
+ thread_new(kernel_process, task_idle, 0);
+ thread_new(kernel_process, whereToGo, data);
sti();
monitor_write("Tasking starting\n");
tasking_switch();
@@ -75,6 +78,15 @@ void tasking_switch() {
: : "r"(current_thread->ebp), "r"(current_thread->esp), "r"(current_thread->eip));
}
+void tasking_updateKernelPagetable(uint32_t idx, struct page_table *table, uint32_t tablephysical) {
+ struct process* it = processes;
+ while (it != 0) {
+ it->pagedir->tables[idx] = table;
+ it->pagedir->tablesPhysical[idx] = tablephysical;
+ it = it->next;
+ }
+}
+
uint32_t tasking_handleException(struct registers *regs) {
if (threads == 0) return 0; //No tasking yet
return 0;
@@ -87,15 +99,16 @@ static uint32_t thread_runnable(struct thread *t) {
}
static void thread_run(struct thread *thread, thread_entry entry_point, void *data) {
- pagedir_switch(thread->process->pagedir);
+ pagedir_switch(thread->process->pagedir); //TODO : take into account privilege level
asm volatile("sti");
entry_point(data);
asm volatile("int $64");
}
-void thread_new(struct process *proc, thread_entry entry_point, void *data) {
+struct thread *thread_new(struct process *proc, thread_entry entry_point, void *data) {
struct thread *t = kmalloc(sizeof(struct thread));
t->process = proc;
+ proc->threads++;
t->kernelStack_addr = kmalloc(KSTACKSIZE);
t->kernelStack_size = KSTACKSIZE;
@@ -119,5 +132,18 @@ void thread_new(struct process *proc, thread_entry entry_point, void *data) {
while (i->next != 0) i = i->next;
i->next = t;
}
+ return t;
}
+struct process *process_new(struct process* parent, uint32_t uid, uint32_t privilege) {
+ struct process* p = kmalloc(sizeof(struct process));
+ p->pid = (nextpid++);
+ p->uid = uid;
+ p->threads = 0;
+ p->privilege = privilege;
+ p->parent = parent;
+ p->pagedir = pagedir_new();
+ p->next = processes;
+ processes = p;
+ return p;
+}
diff --git a/src/stem/task/task.h b/src/stem/task/task.h
index e91aa8b..f59bb2b 100644
--- a/src/stem/task/task.h
+++ b/src/stem/task/task.h
@@ -6,7 +6,7 @@
#include "idt.h"
struct process {
- uint32_t pid, uid;
+ uint32_t pid, uid, privilege, threads;
struct process *parent;
struct page_directory *pagedir;
@@ -17,6 +17,11 @@ struct process {
#define TS_SLEEPING 1 //Sleeping for a defined amount of time
#define TS_WAIKWAIT 2 //Waiting to be waked up by something precise (thread currently blocked)
+#define PL_USER 3
+#define PL_SERVICE 2
+#define PL_DRIVER 1
+#define PL_KERNEL 0
+
typedef void (*thread_entry)(void*);
struct thread {
@@ -34,8 +39,10 @@ extern struct thread *current_thread;
void tasking_init(thread_entry whereToGo, void *data);
void tasking_switch();
+void tasking_updateKernelPagetable(uint32_t idx, struct page_table *table, uint32_t tablePhysical);
uint32_t tasking_handleException(struct registers *regs);
-void thread_new(struct process *proc, thread_entry entry_point, void *data);
+struct thread * thread_new(struct process *proc, thread_entry entry_point, void *data);
+struct process* process_new(struct process *parent, uint32_t uid, uint32_t privilege);
#endif