diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2025-12-28 00:48:24 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2025-12-28 00:48:24 +0800 |
| commit | a82ab8ad6d277ededc128678aebabf5fbdb01c45 (patch) | |
| tree | 71d1d333d45e7272ba79a1868942dc710f673ff3 /include | |
| parent | 7ececbe2818510a8acaa2a2e513085c768b14d15 (diff) | |
| download | lume-a82ab8ad6d277ededc128678aebabf5fbdb01c45.tar.gz lume-a82ab8ad6d277ededc128678aebabf5fbdb01c45.tar.xz | |
feat(syscall): Implement syscall dispatch and process lifecycle (exit/wait/sleep)
Diffstat (limited to 'include')
| -rw-r--r-- | include/kernel/proc.h | 12 | ||||
| -rw-r--r-- | include/kernel/spinlock.h | 20 | ||||
| -rw-r--r-- | include/kernel/syscall.h | 26 | ||||
| -rw-r--r-- | include/lib/string.h | 13 |
4 files changed, 69 insertions, 2 deletions
diff --git a/include/kernel/proc.h b/include/kernel/proc.h index 559b137..b557267 100644 --- a/include/kernel/proc.h +++ b/include/kernel/proc.h @@ -1,6 +1,7 @@ #pragma once #include "common/types.h" #include "kernel/trap.h" +#include "kernel/spinlock.h" struct Context { @@ -44,7 +45,9 @@ struct Proc char name[16]; uint64 sz; - // + struct Proc *parent; + void *chan; + int xstate; }; @@ -57,8 +60,13 @@ namespace ProcManager void create_kernel_thread(void (*func)(), const char *name); void user_init(); + void exit(int status); + int wait(uint64 addr); + void sleep(void *chan, struct spinlock *lk); + void wakeup(void *chan); } void forkret(); struct Proc *myproc(); -void usertrapret();
\ No newline at end of file +void usertrapret(); +int fork();
\ No newline at end of file diff --git a/include/kernel/spinlock.h b/include/kernel/spinlock.h new file mode 100644 index 0000000..aec4b6a --- /dev/null +++ b/include/kernel/spinlock.h @@ -0,0 +1,20 @@ +#pragma once +#include "common/types.h" + +struct spinlock +{ + uint locked; + + char *name; + int cpu_id; +}; + +namespace Spinlock +{ + void init(struct spinlock *lk, char *name); + void acquire(struct spinlock *lk); + void release(struct spinlock *lk); + int holding(struct spinlock *lk); + void push_off(); + void pop_off(); +}
\ No newline at end of file diff --git a/include/kernel/syscall.h b/include/kernel/syscall.h new file mode 100644 index 0000000..571741e --- /dev/null +++ b/include/kernel/syscall.h @@ -0,0 +1,26 @@ +#pragma once + +#define SYS_putc 1 +#define SYS_fork 2 +#define SYS_exit 3 +#define SYS_wait 4 +#define SYS_pipe 5 +#define SYS_read 6 +#define SYS_kill 7 +#define SYS_exec 8 +#define SYS_fstat 9 +#define SYS_chdir 10 +#define SYS_dup 11 +#define SYS_getpid 12 +#define SYS_sbrk 13 +#define SYS_sleep 14 +#define SYS_uptime 15 +#define SYS_open 16 +#define SYS_write 17 +#define SYS_mknod 18 +#define SYS_unlink 19 +#define SYS_link 20 +#define SYS_mkdir 21 +#define SYS_close 22 + +void syscall();
\ No newline at end of file diff --git a/include/lib/string.h b/include/lib/string.h new file mode 100644 index 0000000..aa87489 --- /dev/null +++ b/include/lib/string.h @@ -0,0 +1,13 @@ +#pragma once +#include "common/types.h" + + +void *memset(void *dst, int c, uint n); +int memcmp(const void *v1, const void *v2, uint n); +void *memmove(void *dst, const void *src, uint n); +void *memcpy(void *dst, const void *src, uint n); + + +void strcpy(char *dst, const char *src); +int strlen(const char *s); +int strcmp(const char *s1, const char *s2);
\ No newline at end of file |
