summaryrefslogtreecommitdiff
path: root/src/kernel/task
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2012-05-01 23:48:56 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2012-05-01 23:48:56 +0200
commit43d0bb8e3997022e5270f7f75f615a47819c929e (patch)
tree937992d286966edecf81b405e414230c85d19bad /src/kernel/task
parente9683297bf480f9590b0e5796f4520fb430e2e03 (diff)
downloadTCE-43d0bb8e3997022e5270f7f75f615a47819c929e.tar.gz
TCE-43d0bb8e3997022e5270f7f75f615a47819c929e.zip
Basic object system - THIS IS STILL A LONG WAY TO GO!!
Diffstat (limited to 'src/kernel/task')
-rw-r--r--src/kernel/task/idt.c12
-rw-r--r--src/kernel/task/syscall.c70
-rw-r--r--src/kernel/task/syscall.h2
-rw-r--r--src/kernel/task/task.c41
-rw-r--r--src/kernel/task/task.h4
5 files changed, 83 insertions, 46 deletions
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(&regs) != 0) || regs.int_no != 14) {
if (tasking_handleException(&regs) == 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](&regs);
- }
-}
-
/* 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 <core/sys.h>
+#include <Object/Object.h>
+
+#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](&regs);
+ }
+ } else {
+ do_method_call(&regs);
+ }
+}
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 <mem/gdt.h>
#include "timer.h"
+#include <Object/Object.h>
+
#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 <types.h>
#include <mem/paging.h>
+#include <lib/earray.h>
#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();