diff options
-rw-r--r-- | doc/syscalls.txt | 2 | ||||
-rw-r--r-- | src/kernel/core/kmain.c | 2 | ||||
-rw-r--r-- | src/kernel/core/monitor.h | 2 | ||||
-rw-r--r-- | src/kernel/task/syscall.c | 16 | ||||
-rw-r--r-- | src/kernel/task/task.c | 9 | ||||
-rw-r--r-- | src/library/grapes/syscall.c | 4 | ||||
-rw-r--r-- | src/library/grapes/syscall.h | 1 | ||||
-rw-r--r-- | src/modules/test/main.c | 19 |
8 files changed, 41 insertions, 14 deletions
diff --git a/doc/syscalls.txt b/doc/syscalls.txt index 236f8c3..530fbab 100644 --- a/doc/syscalls.txt +++ b/doc/syscalls.txt @@ -9,5 +9,7 @@ id=eax Name Parameters Description 2 thread_sleep ebx: time (int) msecs Tell kernel to put current thread to sleep 3 process_exit ebx: return value (int) Tell kernel to end current process, cleaning up everything 4 printk ebx: addr of a string Print a message to screen + 5 thread_new ebx: entry point Creates a new thread + ecx: data pointer If a processes wishes to exit with an error code, it HAS to use process_exit. thread_exit will do nothing. diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c index 4a4da05..0a94fde 100644 --- a/src/kernel/core/kmain.c +++ b/src/kernel/core/kmain.c @@ -49,7 +49,7 @@ void kmain(struct multiboot_info_t* mbd, int32_t magic) { if (elf_check((uint8_t*)mods[i].mod_start)) { monitor_write(" : Invalid ELF file\n"); } else { - if (elf_exec((uint8_t*)mods[i].mod_start, PL_SERVICE) == 0) { + if (elf_exec((uint8_t*)mods[i].mod_start, PL_DRIVER) == 0) { monitor_write(" : Error loading\n"); } else { monitor_write(" : OK\n"); diff --git a/src/kernel/core/monitor.h b/src/kernel/core/monitor.h index 19201ed..f4605cf 100644 --- a/src/kernel/core/monitor.h +++ b/src/kernel/core/monitor.h @@ -9,7 +9,7 @@ void monitor_write(char *s); void monitor_writeHex(uint32_t v); void monitor_writeDec(uint32_t v); -#define NL monitor_put("\n"); +#define NL monitor_put('\n'); #endif diff --git a/src/kernel/task/syscall.c b/src/kernel/task/syscall.c index 5aab011..8195dd0 100644 --- a/src/kernel/task/syscall.c +++ b/src/kernel/task/syscall.c @@ -1,21 +1,29 @@ #include "syscall.h" +#include "task.h" #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); } #define CALL2(name, scname) static void scname(struct registers* r) { \ r->eax = name(r->ebx, r->ecx); } +#define CALL0V(name, scname) static void scname(struct registers* r) { name(); } +#define CALL1V(name, scname) static void scname(struct registers* r) { name(r->ebx); } -CALL0(thread_exit, thread_exit_sc); -CALL0(tasking_switch, schedule_sc); -CALL1(thread_sleep, thread_sleep_sc); -CALL1(process_exit, process_exit_sc); +CALL0V(thread_exit, thread_exit_sc); +CALL0V(tasking_switch, schedule_sc); +CALL1V(thread_sleep, thread_sleep_sc); +CALL1V(process_exit, process_exit_sc); CALL1(monitor_write, printk_sc); +static void thread_new_sc(struct registers* r) { + thread_new(current_thread->process, (thread_entry)r->ebx, (void*)r->ecx); +} + int_callback syscalls[] = { thread_exit_sc, schedule_sc, thread_sleep_sc, process_exit_sc, printk_sc, + thread_new_sc, 0 }; diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index a37d44b..8cdf7b3 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -107,8 +107,13 @@ uint32_t tasking_handleException(struct registers *regs) { "Page Fault","Unknown Interrupt","Coprocessor Fault","Alignment Check","Machine Check"}; monitor_write(exception_messages[regs->int_no]); monitor_write(" at "); monitor_writeHex(regs->eip); - monitor_write("\n>>> Thread exiting.\n"); - thread_exit_stackJmp(EX_TH_EXCEPTION); + if (regs->int_no == 14) { + monitor_write("\n>>> Process exiting.\n"); + thread_exit_stackJmp(EX_PR_EXCEPTION); + } else { + monitor_write("\n>>> Thread exiting.\n"); + thread_exit_stackJmp(EX_TH_EXCEPTION); + } PANIC("This should never have happened. Please report this."); } diff --git a/src/library/grapes/syscall.c b/src/library/grapes/syscall.c index 5a1a26e..a00d9e8 100644 --- a/src/library/grapes/syscall.c +++ b/src/library/grapes/syscall.c @@ -25,3 +25,7 @@ void process_exit(int retval) { void printk(char* str) { call(4, (unsigned)str, 0, 0, 0, 0); } + +void thread_new(void (*entry)(void*), void *data) { + call(5, (unsigned)entry, (unsigned)data, 0, 0, 0); +} diff --git a/src/library/grapes/syscall.h b/src/library/grapes/syscall.h index 9f4c280..e385761 100644 --- a/src/library/grapes/syscall.h +++ b/src/library/grapes/syscall.h @@ -6,5 +6,6 @@ void schedule(); void thread_sleep(int time); void process_exit(int retval); void printk(char* str); +void thread_new(void (*entry)(void*), void *data); #endif diff --git a/src/modules/test/main.c b/src/modules/test/main.c index fbb6eb8..01ab836 100644 --- a/src/modules/test/main.c +++ b/src/modules/test/main.c @@ -1,12 +1,19 @@ #include <grapes/syscall.h> +void thread2(void* d) { + while (1) { + thread_sleep(1400); + printk("$"); + } +} + int main() { printk("[module:test] Hi world !\n"); - thread_sleep(2000); - printk("[module:test] 2sec later...\n"); - printk("[module:test] Performing illegal read in kernel space...\n"); - int *a = (int*)0xE0000004; - if (*a == 0) printk("is null...\n"); - printk("[module:test] HAHA !!!!\n"); + printk("[module:test] Creating new thread...\n"); + thread_new(thread2, 0); + while (1) { + thread_sleep(2000); + printk("."); + } return 0; } |