Compare commits

..

2 commits

Author SHA1 Message Date
c9ad69a32d
nemu: break before executing instruction
Some checks failed
Build abstract machine with nix / build-abstract-machine (push) Failing after 45s
Run CTests within npc / npc-test (push) Failing after 47s
2024-07-25 17:56:30 +08:00
385d448746
abstract-machine(nemu): support context switch 2024-07-25 17:16:41 +08:00
3 changed files with 9 additions and 3 deletions

View file

@ -2,6 +2,7 @@
#include <am.h> #include <am.h>
#include <klib.h> #include <klib.h>
#include <riscv/riscv.h> #include <riscv/riscv.h>
#include <stdint.h>
static Context *(*user_handler)(Event, Context *) = NULL; static Context *(*user_handler)(Event, Context *) = NULL;
@ -37,7 +38,10 @@ bool cte_init(Context *(*handler)(Event, Context *)) {
} }
Context *kcontext(Area kstack, void (*entry)(void *), void *arg) { Context *kcontext(Area kstack, void (*entry)(void *), void *arg) {
return NULL; Context *c = kstack.end - sizeof(Context);
c->mepc = (uintptr_t)entry;
c->gpr[10] = (uintptr_t)arg;
return c;
} }
void yield() { void yield() {

View file

@ -60,6 +60,8 @@ __am_asm_trap:
mv a0, sp mv a0, sp
jal __am_irq_handle jal __am_irq_handle
mv sp, a0
LOAD t1, OFFSET_STATUS(sp) LOAD t1, OFFSET_STATUS(sp)
LOAD t2, OFFSET_EPC(sp) LOAD t2, OFFSET_EPC(sp)
csrw mstatus, t1 csrw mstatus, t1

View file

@ -158,8 +158,6 @@ breakpoint_t *cpu_exec_with_bp(uint64_t n, breakpoint_t *bp, size_t len) {
static Decode s; static Decode s;
nemu_state.state = NEMU_RUNNING; nemu_state.state = NEMU_RUNNING;
do { do {
exec_once(&s, cpu.pc);
g_nr_guest_inst++;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
size_t addr = bp[i].addr; size_t addr = bp[i].addr;
bp_type_t bptype = bp[i].type; bp_type_t bptype = bp[i].type;
@ -176,6 +174,8 @@ breakpoint_t *cpu_exec_with_bp(uint64_t n, breakpoint_t *bp, size_t len) {
return bp + i; return bp + i;
} }
} }
exec_once(&s, cpu.pc);
g_nr_guest_inst++;
if (nemu_state.state != NEMU_RUNNING) if (nemu_state.state != NEMU_RUNNING)
return NULL; return NULL;
} while (--n); } while (--n);