From 3e8ff210980e83f4ec0627196b8cc72e5a63aaa0 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Thu, 21 Sep 2023 23:14:07 +0300 Subject: [PATCH] caveat: introduce ecall.h header --- caveat/Makefile | 2 ++ caveat/ecall.c | 12 +++++++----- caveat/ecall.h | 33 +++++++++++++++++++++++++++++++++ caveat/make_ecall_tbl.py | 5 +---- 4 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 caveat/ecall.h diff --git a/caveat/Makefile b/caveat/Makefile index cac0a0b..bb149a3 100644 --- a/caveat/Makefile +++ b/caveat/Makefile @@ -82,5 +82,7 @@ $B/%.o : %.cc opcodes.h opcodes_attr.h decode_insn.h execute_insn.h disasm_insn.h constants.c: crunch_isa.py Instructions.def python3 crunch_isa.py +ecall.h: ecall_nums.h opcodes.h insn.h core.h + ecall_nums.h: make_ecall_tbl.py python3 make_ecall_tbl.py diff --git a/caveat/ecall.c b/caveat/ecall.c index 8eccfeb..2de27f0 100644 --- a/caveat/ecall.c +++ b/caveat/ecall.c @@ -17,12 +17,12 @@ #include "arith.h" #include "caveat.h" +#include "ecall.h" #include "opcodes.h" #include "insn.h" #include "shmfifo.h" #include "core.h" #include "riscv-opc.h" -#include "ecall_nums.h" //#define DEBUG @@ -61,18 +61,20 @@ int proxy_ecall( struct core_t* cpu ) cpu->reg[10].l, cpu->reg[11].l, cpu->reg[12].l, cpu->reg[13].l, cpu->reg[14].l, cpu->reg[15].l); abort(); } - long sysnum = rv_to_host[rvnum].sysnum; + struct ecall_entry const *entry = ecall_entry(rvnum); + long sysnum = entry->number; + char const *name = entry->name; #ifdef DEBUG fprintf(stderr, "%10ld: %s[%ld:%ld](%lx, %lx, %lx, %lx, %lx, %lx)", cpu->counter.insn_executed-previous, - rv_to_host[rvnum].name, rvnum, sysnum, + name, rvnum, sysnum, cpu->reg[10].l, cpu->reg[11].l, cpu->reg[12].l, cpu->reg[13].l, cpu->reg[14].l, cpu->reg[15].l); previous = cpu->counter.insn_executed; #endif - switch (sysnum) { + switch (entry->number) { case -1: goto no_mapping; case -2: - fprintf(stderr, "RISCV-V system call %s(#%ld) not supported on host system\n", rv_to_host[rvnum].name, sysnum); + fprintf(stderr, "RISCV-V system call %s(#%ld) not supported on host system\n", name, sysnum); abort(); #if 0 diff --git a/caveat/ecall.h b/caveat/ecall.h new file mode 100644 index 0000000..e0cc738 --- /dev/null +++ b/caveat/ecall.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include + +struct ecall_entry { + long number; + char const *name; +}; + +#include "opcodes.h" +#include "insn.h" +#include "core.h" + +#include "ecall_nums.h" + +static inline struct ecall_entry const * +ecall_entry(long id) { + return &rv_to_host[id]; +} + +static inline long +ecall_idargs(struct core_t const *cpu, long arguments[6]) { + arguments[0] = cpu->reg[10].l; + arguments[1] = cpu->reg[11].l; + arguments[2] = cpu->reg[12].l; + arguments[3] = cpu->reg[13].l; + arguments[4] = cpu->reg[14].l; + arguments[5] = cpu->reg[15].l; + + return cpu->reg[17].l; +} diff --git a/caveat/make_ecall_tbl.py b/caveat/make_ecall_tbl.py index 9447738..59a78df 100644 --- a/caveat/make_ecall_tbl.py +++ b/caveat/make_ecall_tbl.py @@ -47,10 +47,7 @@ for name in sorted(enames.keys()): en.write('#endif\n') en.write("""\n -static const struct { - int sysnum; - const char*name; -} rv_to_host[] = { +static struct ecall_entry const rv_to_host[] = { """) for n in range(0, highest+1): -- 2.30.2