mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
Implement exit syscall
This commit is contained in:
@@ -20,6 +20,9 @@ _start:
|
|||||||
mov rax, 1 ; DEBUG syscall
|
mov rax, 1 ; DEBUG syscall
|
||||||
syscall ; int 0xee
|
syscall ; int 0xee
|
||||||
|
|
||||||
|
cmp r13, 0
|
||||||
|
je .doexit
|
||||||
|
|
||||||
cmp r12, 1
|
cmp r12, 1
|
||||||
je .dosend
|
je .dosend
|
||||||
jne .doreceive
|
jne .doreceive
|
||||||
@@ -59,3 +62,7 @@ _start:
|
|||||||
mov rdi, 1 ; source is pid 2
|
mov rdi, 1 ; source is pid 2
|
||||||
syscall ; int 0xee
|
syscall ; int 0xee
|
||||||
jmp .preloop
|
jmp .preloop
|
||||||
|
|
||||||
|
.doexit
|
||||||
|
mov rax, 9 ; EXIT syscall
|
||||||
|
syscall
|
||||||
|
|||||||
@@ -4,6 +4,13 @@
|
|||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
process::exit(uint32_t code)
|
||||||
|
{
|
||||||
|
return_code = code;
|
||||||
|
flags -= process_flags::running;
|
||||||
|
}
|
||||||
|
|
||||||
pid_t
|
pid_t
|
||||||
process::fork(uintptr_t in_rsp)
|
process::fork(uintptr_t in_rsp)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ struct process
|
|||||||
uintptr_t kernel_stack;
|
uintptr_t kernel_stack;
|
||||||
size_t kernel_stack_size;
|
size_t kernel_stack_size;
|
||||||
|
|
||||||
|
/// Terminate this process.
|
||||||
|
/// \arg code The return code to exit with.
|
||||||
|
void exit(unsigned code);
|
||||||
|
|
||||||
/// Copy this process.
|
/// Copy this process.
|
||||||
/// \arg in_rsp The RSP of the calling process
|
/// \arg in_rsp The RSP of the calling process
|
||||||
/// \returns Returns the child's pid to the parent, and
|
/// \returns Returns the child's pid to the parent, and
|
||||||
|
|||||||
@@ -127,12 +127,18 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state ®s)
|
|||||||
cons->set_color();
|
cons->set_color();
|
||||||
|
|
||||||
pid_t pid = p->fork(return_rsp);
|
pid_t pid = p->fork(return_rsp);
|
||||||
if (pid == scheduler::get().current()->pid)
|
|
||||||
pid = 0;
|
|
||||||
regs.rax = pid;
|
regs.rax = pid;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
cons->set_color(9);
|
cons->set_color(9);
|
||||||
cons->printf("\nReceived unknown syscall: %02x\n", call);
|
cons->printf("\nReceived unknown syscall: %02x\n", call);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ enum class syscall : uint64_t
|
|||||||
send = 0x0006,
|
send = 0x0006,
|
||||||
receive = 0x0007,
|
receive = 0x0007,
|
||||||
fork = 0x0008,
|
fork = 0x0008,
|
||||||
|
exit = 0x0009,
|
||||||
|
|
||||||
last_syscall
|
last_syscall
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user