Add yield syscall (Not working in umode)

This commit is contained in:
pjht 2019-02-11 09:47:28 -06:00
parent fdd7afa1c8
commit 4f25ff7a09
6 changed files with 33 additions and 14 deletions

View File

@ -3,6 +3,7 @@
#include "ports.h" #include "ports.h"
#include "../halt.h" #include "../halt.h"
#include "../drivers/vga.h" #include "../drivers/vga.h"
#include "../tasking.h"
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
void irq_handler(registers_t r); void irq_handler(registers_t r);
@ -163,6 +164,11 @@ void isr_handler(registers_t r) {
// } // }
halt(); halt();
break; break;
case 80:
if (r.eax==1) {
tasking_yield();
}
break;
} }
} }
} }

View File

@ -16,11 +16,11 @@ static Task* headTask;
void tasking_init() { void tasking_init() {
currentTask=NULL; currentTask=NULL;
next_pid=0; next_pid=0;
headTask=createTask(NULL); headTask=tasking_createTask(NULL);
currentTask=headTask; currentTask=headTask;
} }
Task* createTaskEax(void* eip,uint32_t eax) { Task* tasking_createTaskEax(void* eip,uint32_t eax) {
Task* task=malloc(sizeof(Task)); Task* task=malloc(sizeof(Task));
task->regs.eax=eax; task->regs.eax=eax;
task->regs.ebx=0; task->regs.ebx=0;
@ -45,11 +45,11 @@ Task* createTaskEax(void* eip,uint32_t eax) {
return task; return task;
} }
Task* createTask(void* eip) { Task* tasking_createTask(void* eip) {
return createTaskEax(eip,0); 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) { for (Task* task=headTask;task!=NULL;task=task->next) {
if (task->pid==pid) { if (task->pid==pid) {
if (task->msg_store==NULL) { 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) { if (!currentTask->msg_store) {
return NULL; return NULL;
} }
@ -88,7 +88,7 @@ char* get_msg(uint32_t* sender) {
return data; return data;
} }
void yield() { void tasking_yield() {
Task* task=currentTask->next; Task* task=currentTask->next;
if (!task) { if (!task) {
task=headTask; task=headTask;

View File

@ -1,10 +1,10 @@
#ifndef TASKING_H #ifndef CPU_TASKING_H
#define TASKING_H #define CPU_TASKING_H
#include "i386/tasking.h" #include "i386/tasking.h"
void tasking_init(); void tasking_init();
void yield(); void tasking_yield();
Task* createTask(void* eip); Task* tasking_createTask(void* eip);
void send_msg(uint32_t pid,char* msg); void tasking_send_msg(uint32_t pid,char* msg);
char* get_msg(uint32_t* sender); char* tasking_get_msg(uint32_t* sender);
#endif #endif

View File

@ -4,6 +4,7 @@
#include "../drivers/vga.h" #include "../drivers/vga.h"
#include <grub/text_fb_info.h> #include <grub/text_fb_info.h>
#include <stdlib.h> #include <stdlib.h>
#include <tasking.h>
#include "multiboot.h" #include "multiboot.h"
void task() { void task() {
@ -56,7 +57,7 @@ void kmain(multiboot_info_t* header) {
port_byte_out(0xe9,'!'); port_byte_out(0xe9,'!');
port_byte_out(0xe9,'\n'); port_byte_out(0xe9,'\n');
vga_write_string("Task create\n"); vga_write_string("Task create\n");
createTask(task); tasking_createTask(task);
vga_write_string("Task switch\n"); vga_write_string("Task switch\n");
yield(); yield();
vga_write_string("Back in main\n"); vga_write_string("Back in main\n");

6
libc/tasking.c Normal file
View File

@ -0,0 +1,6 @@
void yield() {
asm volatile(" \
mov $1, %eax; \
int $80; \
");
}

6
libc/tasking.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef TASKING_H
#define TASKING_H
void yield();
#endif