
221220000 张三 Linux zzy 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux 12:26:49 up 6 days, 21:24, 1 user, load average: 0.72, 0.73, 0.62
32 lines
883 B
C
32 lines
883 B
C
#include <common.h>
|
|
#include <syscall.h>
|
|
#include <fs.h>
|
|
|
|
int _brk(void* addr) {
|
|
return 0;
|
|
}
|
|
|
|
#define CASE(syscall, ...) case _SYSCALL_NAME(syscall): __VA_ARGS__; break;
|
|
void do_syscall(Context *c) {
|
|
uintptr_t a[4];
|
|
a[0] = c->GPR1;
|
|
a[1] = c->GPR2;
|
|
a[2] = c->GPR3;
|
|
a[3] = c->GPR4;
|
|
|
|
TRACE("syscall %d: %s", a[0], __syscall_names[a[0]]);
|
|
switch (a[0]) {
|
|
CASE(yield, yield())
|
|
|
|
CASE(open, c->GPRx = _fs_open((const char*)a[1], (int)a[2], (int)a[3]))
|
|
CASE(read, c->GPRx = _fs_read((int)a[1], (void*)a[2], (size_t)a[3]))
|
|
CASE(write, c->GPRx = _fs_write((int)a[1], (const char*)a[2], (size_t)a[3]))
|
|
CASE(lseek, c->GPRx = _fs_lseek((int)a[1], (size_t)a[2], (int)a[3]))
|
|
CASE(close, c->GPRx = _fs_close((int)a[1]))
|
|
|
|
CASE(brk, c->GPRx = _brk((void*)a[1]))
|
|
CASE(exit, halt(0))
|
|
default: panic("Unhandled syscall ID = %d", a[0]);
|
|
}
|
|
}
|