diff options
author | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-17 13:30:09 +0200 |
---|---|---|
committer | Alex AUVOLAT <alexis211@gmail.com> | 2012-05-17 13:30:09 +0200 |
commit | 7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef (patch) | |
tree | df44a926f105c913c77525d35441d20a632f1440 /src/kernel/task | |
parent | c6d35a5f4fdda6ae2e98498f19a4adaee6d95692 (diff) | |
download | TCE-7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef.tar.gz TCE-7c9a48b4e6d66cf4f62e7bad9e22ab06923e47ef.zip |
Beginning of a VFS implemented. C++ is great.
Diffstat (limited to 'src/kernel/task')
-rw-r--r-- | src/kernel/task/syscall.cpp | 71 | ||||
-rw-r--r-- | src/kernel/task/task.cpp | 19 | ||||
-rw-r--r-- | src/kernel/task/task.h | 8 |
3 files changed, 81 insertions, 17 deletions
diff --git a/src/kernel/task/syscall.cpp b/src/kernel/task/syscall.cpp index 678677d..797c5db 100644 --- a/src/kernel/task/syscall.cpp +++ b/src/kernel/task/syscall.cpp @@ -3,6 +3,7 @@ #include "timer.h" #include <core/monitor.h> #include <core/sys.h> +#include <vfs/node.h> #define CALL0(name, scname) static void scname(registers* r) { r->eax = name(); } #define CALL1(name, scname) static void scname(registers* r) { \ @@ -11,6 +12,8 @@ r->eax = name(r->ebx, r->ecx); } #define CALL3(name, scname) static void scname(registers* r) { \ r->eax = name(r->ebx, r->ecx, r->edx); } +#define CALL4(name, scname) static void scname(registers* r) { \ + r->eax = name(r->ebx, r->ecx, r->edx, r->esi); } #define CALL0V(name, scname) static void scname(registers* r) { name(); } #define CALL1V(name, scname) static void scname(registers* r) { name(r->ebx); } #define CALL2V(name, scname) static void scname(registers* r) { name(r->ebx, r->ecx); } @@ -26,29 +29,83 @@ CALL0(proc_priv, proc_priv_sc); CALL1(process_sbrk, proc_sbrk_sc); CALL1V(process_brk, proc_brk_sc); +CALL1V(close, close_sc); + static void printk_sc(registers *r) { monitor_write((char*)r->ebx); } static void thread_new_sc(registers* r) { cli(); - new thread(current_thread->process, (thread_entry)r->ebx, (void*)r->ecx, (void*)r->edx); + new thread(current_process, (thread_entry)r->ebx, (void*)r->ecx, (void*)r->edx); sti(); } +static void open_sc(registers *r) { + r->eax = open((char*)r->ebx, r->ecx); +} + +static void open_relative_sc(registers *r) { + r->eax = open_relative(r->ebx, (char*)r->ecx, r->edx); +} + +static void stat_sc(registers *r) { + r->eax = stat((char*)r->ebx, (file_info*)r->ecx); +} + +static void stat_relative_sc(registers *r) { + r->eax = stat_relative(r->ebx, (char*)r->ecx, (file_info*)r->edx); +} + +static void statf_sc(registers *r) { + r->eax = statf(r->ebx, (file_info*)r->ecx); +} + +static void read_sc(registers *r) { + r->eax = read(r->ebx, r->ecx, r->edx, (char*)r->esi); +} + +static void write_sc(registers *r) { + r->eax = write(r->ebx, r->ecx, r->edx, (char*)r->esi); +} + +static void link_sc(registers *r) { + r->eax = link((char*)r->ebx, (char*)r->ecx, r->edx); +} + + int_callback syscalls[NUMBER_OF_SYSCALLS] = { // This must correspond to common/include/tce/syscalls.h - 0, - thread_exit_sc, //0 + 0, // 0 + thread_exit_sc, schedule_sc, thread_sleep_sc, process_exit_sc, - printk_sc, - thread_new_sc, //5 + printk_sc, //5 + thread_new_sc, irq_wait_sc, proc_priv_sc, - proc_sbrk_sc, + 0, + proc_sbrk_sc, //10 proc_brk_sc, - 0 }; + 0, + 0, + 0, + 0, //15 + 0, + 0, + 0, + 0, + open_sc, //20 + open_relative_sc, + stat_sc, + stat_relative_sc, + statf_sc, + close_sc, //25 + read_sc, + write_sc, + link_sc, + 0 + }; /* Called in idt_.asm on a system call (interrupt 64). diff --git a/src/kernel/task/task.cpp b/src/kernel/task/task.cpp index 92820f9..3998bfe 100644 --- a/src/kernel/task/task.cpp +++ b/src/kernel/task/task.cpp @@ -20,7 +20,7 @@ extern "C" uint32_t read_eip(); extern "C" void task_idle(void*); static uint32_t nextpid = 1; -process *processes = 0, *kernel_process; +process *processes = 0, *kernel_process = 0, *current_process = 0; thread *current_thread = 0, *idle_thread = 0; uint32_t tasking_tmpStack[KSTACKSIZE]; @@ -78,8 +78,9 @@ void schedule() { current_thread = sched_dequeue(); ASSERT(current_thread != 0); + current_process = current_thread->process; - pagedir_switch(current_thread->process->pagedir); + pagedir_switch(current_process->pagedir); gdt_setKernelStack(((uint32_t)current_thread->kernelStack_addr) + current_thread->kernelStack_size); @@ -135,8 +136,8 @@ void thread::wakeUp() { /* Returns the privilege level of the current process. */ int proc_priv() { - if (current_thread == 0 || current_thread->process == 0) return PL_UNKNOWN; - return current_thread->process->privilege; + if (current_thread == 0 || current_process == 0) return PL_UNKNOWN; + return current_process->privilege; } /* For internal use only. Called by thread_exit_stackJmp on a stack that will not be deleted. @@ -272,7 +273,7 @@ thread::thread(class process *proc, thread_entry entry_point, void *data, void * } /* Creates a new process. Creates a struct process and fills it up. */ -process::process(process* _parent, uint32_t _uid, uint32_t _privilege) { +process::process(process* _parent, uint32_t _uid, uint32_t _privilege) : fd(12, 64) { pid = (nextpid++); uid = _uid; thread_count = 0; @@ -284,6 +285,8 @@ process::process(process* _parent, uint32_t _uid, uint32_t _privilege) { data = 0; dataseg = 0; + fd.add((node*)-1); // descriptor #0 must not be used + stack = 0; if (privilege >= PL_USER) { //We are running in user mode size_t stacksBottom = K_HIGHHALF_ADDR - 0x01000000; @@ -338,7 +341,7 @@ static void process_delete(process *pr) { } size_t process_sbrk(size_t size) { - process *p = current_thread->process; + process *p = current_process; if (p->data == 0) return -1; ASSERT(p->data < K_HIGHHALF_ADDR); if (p->data + size >= K_HIGHHALF_ADDR) return -1; @@ -378,9 +381,7 @@ size_t process_sbrk(size_t size) { } void process_brk(size_t ptr) { - process *p = current_thread->process; - ASSERT(ptr < K_HIGHHALF_ADDR); - process_sbrk(ptr - p->data); + process_sbrk(ptr - current_process->data); } diff --git a/src/kernel/task/task.h b/src/kernel/task/task.h index 301f8be..1c32657 100644 --- a/src/kernel/task/task.h +++ b/src/kernel/task/task.h @@ -5,6 +5,8 @@ #include <mem/paging.h> #include "idt.h" +#include <lib/earray.h> + #define TS_RUNNING 0 #define TS_WAKEWAIT 2 //Waiting to be waked up by something precise (thread currently blocked) @@ -21,6 +23,7 @@ typedef void (*thread_entry)(void*); class thread; +class node; class process { public: @@ -34,7 +37,9 @@ class process { process *next; //Forms a linked list thread *threads; - process() {} // must not be used directly + earray<node> fd; // file descriptors + + process() : fd(4, 4) {} // must not be used directly process(process *parent, uint32_t uid, uint32_t privilege); }; @@ -55,6 +60,7 @@ class thread { }; extern thread *current_thread; +extern process *current_process; void tasking_init(); #ifdef __cplusplus |