> 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:11:11 up 6 days, 16:16,  1 user,  load average: 0.94, 0.85, 0.79
This commit is contained in:
tracer-ics2023
2024-09-23 21:11:14 +08:00
committed by zzy
parent 532c35f505
commit 713b20e880
4 changed files with 22 additions and 5 deletions

View File

@ -19,9 +19,9 @@ struct Context {
#define GPR1 gpr[17] // a7
#endif
#define GPR2 gpr[0]
#define GPR3 gpr[0]
#define GPR4 gpr[0]
#define GPRx gpr[0]
#define GPR2 gpr[10] // a0
#define GPR3 gpr[11] // a1
#define GPR4 gpr[12] // a2
#define GPRx gpr[10] // a0
#endif

View File

@ -4,11 +4,21 @@
static Context* (*user_handler)(Event, Context*) = NULL;
static inline int __am_get_event(Context *c) {
switch (c->GPR1)
{
case -1:
return EVENT_YIELD;
default:
return EVENT_SYSCALL;
}
}
Context* __am_irq_handle(Context *c) {
if (user_handler) {
Event ev = {0};
switch (c->mcause) {
case 0xb: ev.event = EVENT_YIELD; break;
case 0xb: ev.event = __am_get_event(c); break;
default: ev.event = EVENT_ERROR; break;
}

View File

@ -1,8 +1,10 @@
#include <common.h>
void do_syscall(Context *c);
static Context* do_event(Event e, Context* c) {
switch (e.event) {
case EVENT_YIELD: printf("EVENT_YIELD\n"); break;
case EVENT_SYSCALL: do_syscall(c); break;
default: panic("Unhandled event ID = %d", e.event);
}

View File

@ -3,8 +3,13 @@
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;
switch (a[0]) {
case SYS_yield: yield();
case SYS_exit: halt(0);
default: panic("Unhandled syscall ID = %d", a[0]);
}
}