Implement exit syscall

This commit is contained in:
Justin C. Miller
2019-03-14 22:28:21 -07:00
parent f7558e3d18
commit be007c6278
5 changed files with 27 additions and 2 deletions

View File

@@ -20,6 +20,9 @@ _start:
mov rax, 1 ; DEBUG syscall
syscall ; int 0xee
cmp r13, 0
je .doexit
cmp r12, 1
je .dosend
jne .doreceive
@@ -59,3 +62,7 @@ _start:
mov rdi, 1 ; source is pid 2
syscall ; int 0xee
jmp .preloop
.doexit
mov rax, 9 ; EXIT syscall
syscall

View File

@@ -4,6 +4,13 @@
#include "scheduler.h"
void
process::exit(uint32_t code)
{
return_code = code;
flags -= process_flags::running;
}
pid_t
process::fork(uintptr_t in_rsp)
{

View File

@@ -57,6 +57,10 @@ struct process
uintptr_t kernel_stack;
size_t kernel_stack_size;
/// Terminate this process.
/// \arg code The return code to exit with.
void exit(unsigned code);
/// Copy this process.
/// \arg in_rsp The RSP of the calling process
/// \returns Returns the child's pid to the parent, and

View File

@@ -127,12 +127,18 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state &regs)
cons->set_color();
pid_t pid = p->fork(return_rsp);
if (pid == scheduler::get().current()->pid)
pid = 0;
regs.rax = pid;
}
break;
case syscall::exit:
cons->set_color(11);
cons->printf("\nProcess %u: Received EXIT syscall\n", p->pid);
cons->set_color();
p->exit(regs.rdi);
return_rsp = s.schedule(return_rsp);
break;
default:
cons->set_color(9);
cons->printf("\nReceived unknown syscall: %02x\n", call);

View File

@@ -15,6 +15,7 @@ enum class syscall : uint64_t
send = 0x0006,
receive = 0x0007,
fork = 0x0008,
exit = 0x0009,
last_syscall
};