blindly implemented exit system call
This commit is contained in:
1
common.h
1
common.h
@@ -22,6 +22,7 @@ typedef uint32_t vaddr_t;
|
||||
#define PAGE_SIZE 4096
|
||||
#define SYS_PUTCHAR 1
|
||||
#define SYS_GETCHAR 2
|
||||
#define SYS_EXIT 3
|
||||
|
||||
void *memset(void *buf, char c, size_t n);
|
||||
void *memcpy(void *dst, const void *src, size_t n);
|
||||
|
5
kernel.c
5
kernel.c
@@ -315,6 +315,11 @@ void proc_b_entry(void) {
|
||||
|
||||
void handle_syscall(struct trap_frame *f) {
|
||||
switch (f->a3) {
|
||||
case SYS_EXIT:
|
||||
printf("process %d exited\n", current_proc->pid);
|
||||
current_proc->state = PROC_EXITED;
|
||||
yield();
|
||||
PANIC("unreachable");
|
||||
case SYS_GETCHAR:
|
||||
while (1) {
|
||||
long ch = getchar();
|
||||
|
1
kernel.h
1
kernel.h
@@ -4,6 +4,7 @@
|
||||
#define PROCS_MAX 8 // Maximum ammount of processes
|
||||
#define PROC_UNUSED 0 // Unused processes control structure
|
||||
#define PROC_RUNNABLE 1 // Runnable proccess
|
||||
#define PROC_EXITED 2
|
||||
#define SATP_SV32 (1u << 31)
|
||||
#define SSTATUS_SPIE (1 << 5)
|
||||
#define SCAUSE_ECALL 8
|
||||
|
2
shell.c
2
shell.c
@@ -22,6 +22,8 @@ prompt:
|
||||
|
||||
if (strcmp(cmdline, "hello") == 0)
|
||||
printf("Hellow :3\n");
|
||||
else if (strcmp(cmdline, "exit") == 0)
|
||||
exit();
|
||||
else
|
||||
printf("I don't know what is %s yet :(\n", cmdline);
|
||||
}
|
||||
|
Reference in New Issue
Block a user