From 43d0bb8e3997022e5270f7f75f615a47819c929e Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Tue, 1 May 2012 23:48:56 +0200 Subject: Basic object system - THIS IS STILL A LONG WAY TO GO!! --- src/kernel/task/idt.c | 12 ++------ src/kernel/task/syscall.c | 70 ++++++++++++++++++++++++++++++++++++++--------- src/kernel/task/syscall.h | 2 -- src/kernel/task/task.c | 41 ++++++++++++++------------- src/kernel/task/task.h | 4 +++ 5 files changed, 83 insertions(+), 46 deletions(-) (limited to 'src/kernel/task') diff --git a/src/kernel/task/idt.c b/src/kernel/task/idt.c index aed5ea8..e6105d5 100644 --- a/src/kernel/task/idt.c +++ b/src/kernel/task/idt.c @@ -76,9 +76,9 @@ static struct irq_waiter { void idt_isrHandler(struct registers regs) { if ((regs.int_no == 14 && paging_fault(®s) != 0) || regs.int_no != 14) { if (tasking_handleException(®s) == 0) { - monitor_write("\nREALLY BAD THIS TIME\t\tUnhandled exception\t#"); + monitor_write("\nREALLY BAD THIS TIME : Unhandled exception #"); monitor_writeDec(regs.int_no); - monitor_write("\t@"); monitor_writeHex(regs.eip); + monitor_write(" @ eip:"); monitor_writeHex(regs.eip); PANIC("Unhandled Exception"); } } @@ -105,14 +105,6 @@ void idt_irqHandler(struct registers regs) { if (doSwitch) schedule(); } -/* Called in idt_.asm on a system call (interrupt 64). - Calls the correct syscall handler (if any). */ -void idt_syscallHandler(struct registers regs) { - if (regs.eax < NUMBER_OF_SYSCALLS && syscalls[regs.eax] != 0) { - syscalls[regs.eax](®s); - } -} - /* For internal use only. Sets up an entry of the IDT with given parameters. */ static void idt_setGate(uint8_t num, uint32_t base, uint16_t sel, uint8_t flags) { idt_entries[num].base_lo = base & 0xFFFF; diff --git a/src/kernel/task/syscall.c b/src/kernel/task/syscall.c index bd27eba..8e1005c 100644 --- a/src/kernel/task/syscall.c +++ b/src/kernel/task/syscall.c @@ -2,18 +2,22 @@ #include "task.h" #include +#include + +#define NUMBER_OF_SYSCALLS 32 + #define CALL0(name, scname) static void scname(struct registers* r) { r->eax = name(); } #define CALL1(name, scname) static void scname(struct registers* r) { \ - r->eax = name(r->ebx); } + r->eax = name(r->ecx); } #define CALL2(name, scname) static void scname(struct registers* r) { \ - r->eax = name(r->ebx, r->ecx); } + r->eax = name(r->ecx, r->edx); } #define CALL3(name, scname) static void scname(struct registers* r) { \ - r->eax = name(r->ebx, r->ecx, r->edx); } + r->eax = name(r->ecx, r->edx, r->esi); } #define CALL0V(name, scname) static void scname(struct registers* r) { name(); } -#define CALL1V(name, scname) static void scname(struct registers* r) { name(r->ebx); } -#define CALL2V(name, scname) static void scname(struct registers* r) { name(r->ebx, r->ecx); } -#define CALL3V(name, scname) static void scname(struct registers* r) { name(r->ebx, r->ecx, r->edx); } -#define CALL4V(name, scname) static void scname(struct registers* r) { name(r->ebx, r->ecx, r->edx, r->esi); } +#define CALL1V(name, scname) static void scname(struct registers* r) { name(r->ecx); } +#define CALL2V(name, scname) static void scname(struct registers* r) { name(r->ecx, r->edx); } +#define CALL3V(name, scname) static void scname(struct registers* r) { name(r->ecx, r->edx, r->esi); } +#define CALL4V(name, scname) static void scname(struct registers* r) { name(r->ecx, r->edx, r->esi, r->edi); } CALL0V(thread_exit, thread_exit_sc); CALL0V(schedule, schedule_sc); @@ -25,21 +29,61 @@ CALL0(proc_priv, proc_priv_sc); CALL1(process_sbrk, proc_sbrk_sc); CALL1V(process_brk, proc_brk_sc); +CALL1(open, open_sc); +CALL2(open_relative, open_relative_sc); +CALL1V(close, close_sc); +CALL2(get_methods, get_methods_sc); + static void thread_new_sc(struct registers* r) { cli(); - thread_new(current_thread->process, (thread_entry)r->ebx, (void*)r->ecx, (void*)r->edx); + thread_new(current_thread->process, (thread_entry)r->ecx, (void*)r->edx, (void*)r->esi); sti(); } int_callback syscalls[NUMBER_OF_SYSCALLS] = { - 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, - proc_brk_sc, - 0 }; + proc_brk_sc, //10 + 0, + 0, + 0, + 0, + 0, //15 + 0, + 0, + 0, + 0, + open_sc, //20 + open_relative_sc, + close_sc, + get_methods_sc, + 0, + 0, //25 + 0, + 0, + 0, + 0, + 0, //30 + 0, //31 + + }; + +/* Called in idt_.asm on a system call (interrupt 64). + Calls the correct syscall handler (if any). */ +void idt_syscallHandler(struct registers regs) { + if (regs.eax == 0) { + if (regs.ebx < NUMBER_OF_SYSCALLS && syscalls[regs.ebx] != 0) { + syscalls[regs.ebx](®s); + } + } else { + do_method_call(®s); + } +} diff --git a/src/kernel/task/syscall.h b/src/kernel/task/syscall.h index f03be55..54af108 100644 --- a/src/kernel/task/syscall.h +++ b/src/kernel/task/syscall.h @@ -3,8 +3,6 @@ #include "idt.h" -#define NUMBER_OF_SYSCALLS 32 - extern int_callback syscalls[]; #endif diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index 9d98165..4c99bf7 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -7,6 +7,8 @@ #include #include "timer.h" +#include + #define KSTACKSIZE 0x8000 //Static routines for handling threads exiting and all cleanup @@ -286,6 +288,13 @@ struct process *process_new(struct process* parent, uint32_t uid, uint32_t privi p->data = 0; p->dataseg = 0; + p->handles.ref_vect_init_len = 32; + p->handles.vect_len = 128; + p->handles.data = 0; + earray_init(&p->handles); + ASSERT(earray_add(&p->handles, 0xFFFFFFF0) == 0); + ASSERT(earray_add(&p->handles, 0xFFFFFFF0) == 1); + p->stack = 0; if (p->privilege >= PL_USER) { //We are running in user mode size_t stacksBottom = K_HIGHHALF_ADDR - 0x01000000; @@ -319,6 +328,8 @@ static void thread_delete(struct thread *th) { /* Deletes a process. First, deletes all its threads. Also deletes the corresponding page directory. */ static void process_delete(struct process *pr) { + int i; + struct thread *it = pr->threads; while (it != 0) { thread_delete(it); @@ -336,31 +347,19 @@ static void process_delete(struct process *pr) { it = it->next; } } + for (i = 1; i < pr->handles.elements; i++) { + Object* obj = earray_at(&pr->handles, i); + if (obj != 0) { + obj->handles--; + if (obj->_class->closed != 0) obj->_class->closed(obj); + } + } + earray_free(&pr->handles); + pagedir_delete(pr->pagedir); 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) { struct process *p = current_thread->process; diff --git a/src/kernel/task/task.h b/src/kernel/task/task.h index 63cb35a..dbeb638 100644 --- a/src/kernel/task/task.h +++ b/src/kernel/task/task.h @@ -3,6 +3,7 @@ #include #include +#include #include "idt.h" #define TS_RUNNING 0 @@ -28,6 +29,8 @@ struct process { struct segment_map *dataseg; + struct earray handles; + struct process *next; //Forms a linked list struct thread *threads; }; @@ -44,6 +47,7 @@ struct thread { }; extern struct thread *current_thread; +#define current_process (current_thread != 0 ? current_thread->process : 0) void tasking_init(); void schedule(); -- cgit v1.2.3