syscalls: start adding fork syscall, not done yet
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include <stddef.h>
|
||||
#include "../include/stdio.h"
|
||||
#include "../include/liballoc.h"
|
||||
#include "../include/paging.h"
|
||||
#include "../include/string.h"
|
||||
|
||||
#define STDIN_FILENO 0
|
||||
#define STDOUT_FILENO 1
|
||||
@@ -56,6 +58,23 @@ int sys_exit(TrapFrame *tf)
|
||||
return error_code;
|
||||
}
|
||||
|
||||
int sys_fork(TrapFrame *tf)
|
||||
{
|
||||
debug_log("FORKFORKFORKFORK\n");
|
||||
|
||||
uint32_t* new_pd = copy_page_dir(current->pagedir);
|
||||
|
||||
Process* child = task_create(0, 0, 3, new_pd);
|
||||
|
||||
memcpy(child, current, sizeof(Process));
|
||||
memcpy(child->kstack, current->kstack, KSTACKSIZE);
|
||||
|
||||
child->tf->eax = 0;
|
||||
tf->eax = child->pid;
|
||||
|
||||
return child->pid;
|
||||
}
|
||||
|
||||
int sys_read(TrapFrame *tf)
|
||||
{
|
||||
if(tf->ebx < 3)
|
||||
@@ -145,6 +164,7 @@ int sys_close(TrapFrame *tf)
|
||||
|
||||
void handle_syscall(TrapFrame *tf)
|
||||
{
|
||||
asm("cli");
|
||||
/*
|
||||
debug_log("EAX: %X ", tf->eax);
|
||||
debug_log("EBX: %X ", tf->ebx);
|
||||
@@ -157,6 +177,12 @@ void handle_syscall(TrapFrame *tf)
|
||||
int r = sys_exit(tf);
|
||||
tf->eax = r;
|
||||
}
|
||||
|
||||
if(tf->eax == 2)
|
||||
{
|
||||
int r = sys_fork(tf);
|
||||
tf->eax = r;
|
||||
}
|
||||
|
||||
if(tf->eax == 3)//read
|
||||
{
|
||||
@@ -179,4 +205,5 @@ void handle_syscall(TrapFrame *tf)
|
||||
int r = sys_close(tf);
|
||||
tf->eax = r;
|
||||
}
|
||||
asm("sti");
|
||||
}
|
||||
Reference in New Issue
Block a user