blindly implemented exit system call

This commit is contained in:
2025-07-31 13:14:28 +03:00
parent b65dc62257
commit 7bc28c2331
5 changed files with 11 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ typedef uint32_t vaddr_t;
#define PAGE_SIZE 4096 #define PAGE_SIZE 4096
#define SYS_PUTCHAR 1 #define SYS_PUTCHAR 1
#define SYS_GETCHAR 2 #define SYS_GETCHAR 2
#define SYS_EXIT 3
void *memset(void *buf, char c, size_t n); void *memset(void *buf, char c, size_t n);
void *memcpy(void *dst, const void *src, size_t n); void *memcpy(void *dst, const void *src, size_t n);

View File

@@ -315,6 +315,11 @@ void proc_b_entry(void) {
void handle_syscall(struct trap_frame *f) { void handle_syscall(struct trap_frame *f) {
switch (f->a3) { 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: case SYS_GETCHAR:
while (1) { while (1) {
long ch = getchar(); long ch = getchar();

View File

@@ -4,6 +4,7 @@
#define PROCS_MAX 8 // Maximum ammount of processes #define PROCS_MAX 8 // Maximum ammount of processes
#define PROC_UNUSED 0 // Unused processes control structure #define PROC_UNUSED 0 // Unused processes control structure
#define PROC_RUNNABLE 1 // Runnable proccess #define PROC_RUNNABLE 1 // Runnable proccess
#define PROC_EXITED 2
#define SATP_SV32 (1u << 31) #define SATP_SV32 (1u << 31)
#define SSTATUS_SPIE (1 << 5) #define SSTATUS_SPIE (1 << 5)
#define SCAUSE_ECALL 8 #define SCAUSE_ECALL 8

View File

@@ -22,6 +22,8 @@ prompt:
if (strcmp(cmdline, "hello") == 0) if (strcmp(cmdline, "hello") == 0)
printf("Hellow :3\n"); printf("Hellow :3\n");
else if (strcmp(cmdline, "exit") == 0)
exit();
else else
printf("I don't know what is %s yet :(\n", cmdline); printf("I don't know what is %s yet :(\n", cmdline);
} }

3
user.c
View File

@@ -18,7 +18,8 @@ int syscall(int sysno, int arg0, int arg1, int arg2) {
} }
__attribute__((noreturn)) void exit(void) { __attribute__((noreturn)) void exit(void) {
for(;;); syscall(SYS_EXIT, 0, 0, 0);
for (;;); // just in case
} }
void putchar(char ch) { void putchar(char ch) {