> compile NEMU
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 21:56:50 up 6 days, 17:02, 1 user, load average: 1.32, 1.45, 1.16
This commit is contained in:
@ -1,5 +1,20 @@
|
||||
#include <common.h>
|
||||
#include "syscall.h"
|
||||
|
||||
size_t _write(int fd, const void *buf, size_t count) {
|
||||
if ((fd != 1 && fd != 2) || buf == NULL || count == 0) {
|
||||
return -1;
|
||||
}
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
putch(((const char*)buf)[i]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void _sbrk(intptr_t increment) {
|
||||
|
||||
}
|
||||
|
||||
void do_syscall(Context *c) {
|
||||
uintptr_t a[4];
|
||||
a[0] = c->GPR1;
|
||||
@ -10,6 +25,7 @@ void do_syscall(Context *c) {
|
||||
TRACE("syscall %d: %s", a[0], __syscall_names[a[0]]);
|
||||
switch (a[0]) {
|
||||
case SYS_yield: yield(); break;
|
||||
case SYS_write: c->GPRx = _write(a[1], (void*)a[2], a[3]); break;
|
||||
case SYS_exit: halt(0); break;
|
||||
default: panic("Unhandled syscall ID = %d", a[0]);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include "syscall.h"
|
||||
#include <stdint.h>
|
||||
|
||||
// helper macros
|
||||
#define _concat(x, y) x ## y
|
||||
@ -66,7 +67,7 @@ int _open(const char *path, int flags, mode_t mode) {
|
||||
}
|
||||
|
||||
int _write(int fd, void *buf, size_t count) {
|
||||
_exit(SYS_write);
|
||||
_syscall_(SYS_write, fd, buf, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user