From 4f25ff7a097e5c7738e3b64677656af1cd347c00 Mon Sep 17 00:00:00 2001 From: pjht Date: Mon, 11 Feb 2019 09:47:28 -0600 Subject: [PATCH] Add yield syscall (Not working in umode) --- cpu/i386/isr.c | 6 ++++++ cpu/i386/tasking.c | 14 +++++++------- cpu/tasking.h | 12 ++++++------ kernel/kernel.c | 3 ++- libc/tasking.c | 6 ++++++ libc/tasking.h | 6 ++++++ 6 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 libc/tasking.c create mode 100644 libc/tasking.h diff --git a/cpu/i386/isr.c b/cpu/i386/isr.c index 1ef55bb..1f02b76 100644 --- a/cpu/i386/isr.c +++ b/cpu/i386/isr.c @@ -3,6 +3,7 @@ #include "ports.h" #include "../halt.h" #include "../drivers/vga.h" +#include "../tasking.h" #include #include void irq_handler(registers_t r); @@ -163,6 +164,11 @@ void isr_handler(registers_t r) { // } halt(); break; + case 80: + if (r.eax==1) { + tasking_yield(); + } + break; } } } diff --git a/cpu/i386/tasking.c b/cpu/i386/tasking.c index 5df045f..b3fbb4d 100644 --- a/cpu/i386/tasking.c +++ b/cpu/i386/tasking.c @@ -16,11 +16,11 @@ static Task* headTask; void tasking_init() { currentTask=NULL; next_pid=0; - headTask=createTask(NULL); + headTask=tasking_createTask(NULL); currentTask=headTask; } -Task* createTaskEax(void* eip,uint32_t eax) { +Task* tasking_createTaskEax(void* eip,uint32_t eax) { Task* task=malloc(sizeof(Task)); task->regs.eax=eax; task->regs.ebx=0; @@ -45,11 +45,11 @@ Task* createTaskEax(void* eip,uint32_t eax) { return task; } -Task* createTask(void* eip) { - return createTaskEax(eip,0); +Task* tasking_createTask(void* eip) { + return tasking_createTaskEax(eip,0); } -void send_msg(uint32_t pid,char* msg) { +void tasking_send_msg(uint32_t pid,char* msg) { for (Task* task=headTask;task!=NULL;task=task->next) { if (task->pid==pid) { if (task->msg_store==NULL) { @@ -66,7 +66,7 @@ void send_msg(uint32_t pid,char* msg) { } } -char* get_msg(uint32_t* sender) { +char* tasking_get_msg(uint32_t* sender) { if (!currentTask->msg_store) { return NULL; } @@ -88,7 +88,7 @@ char* get_msg(uint32_t* sender) { return data; } -void yield() { +void tasking_yield() { Task* task=currentTask->next; if (!task) { task=headTask; diff --git a/cpu/tasking.h b/cpu/tasking.h index 14f4d58..8d0e8a6 100644 --- a/cpu/tasking.h +++ b/cpu/tasking.h @@ -1,10 +1,10 @@ -#ifndef TASKING_H -#define TASKING_H +#ifndef CPU_TASKING_H +#define CPU_TASKING_H #include "i386/tasking.h" void tasking_init(); -void yield(); -Task* createTask(void* eip); -void send_msg(uint32_t pid,char* msg); -char* get_msg(uint32_t* sender); +void tasking_yield(); +Task* tasking_createTask(void* eip); +void tasking_send_msg(uint32_t pid,char* msg); +char* tasking_get_msg(uint32_t* sender); #endif diff --git a/kernel/kernel.c b/kernel/kernel.c index b2a5c78..af0a95d 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -4,6 +4,7 @@ #include "../drivers/vga.h" #include #include +#include #include "multiboot.h" void task() { @@ -56,7 +57,7 @@ void kmain(multiboot_info_t* header) { port_byte_out(0xe9,'!'); port_byte_out(0xe9,'\n'); vga_write_string("Task create\n"); - createTask(task); + tasking_createTask(task); vga_write_string("Task switch\n"); yield(); vga_write_string("Back in main\n"); diff --git a/libc/tasking.c b/libc/tasking.c new file mode 100644 index 0000000..b318fbb --- /dev/null +++ b/libc/tasking.c @@ -0,0 +1,6 @@ +void yield() { + asm volatile(" \ + mov $1, %eax; \ + int $80; \ + "); +} diff --git a/libc/tasking.h b/libc/tasking.h new file mode 100644 index 0000000..fd97688 --- /dev/null +++ b/libc/tasking.h @@ -0,0 +1,6 @@ +#ifndef TASKING_H +#define TASKING_H + +void yield(); + +#endif