caveat: introduce ecall.h header
authorDmitry Selyutin <ghostmansd@gmail.com>
Thu, 21 Sep 2023 20:14:07 +0000 (23:14 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Thu, 21 Sep 2023 20:14:07 +0000 (23:14 +0300)
caveat/Makefile
caveat/ecall.c
caveat/ecall.h [new file with mode: 0644]
caveat/make_ecall_tbl.py

index cac0a0bba6bf49e0fabd5f45db41596722554ade..bb149a369157a92883fa3466e68463f2197abebe 100644 (file)
@@ -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
index 8eccfeb5a6ba0f9e1e7c05276d61542891062237..2de27f0e2e8201dcdaf6ee26c26872af5949e2d2 100644 (file)
 #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 (file)
index 0000000..e0cc738
--- /dev/null
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <stdio.h>
+#include <stdint.h>
+#include <sys/time.h>
+
+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;
+}
index 9447738ad8a903091eb4061f6aa5129ca35cfcfa..59a78df79cd6a891eb228191bba0d9a61ab03cdc 100644 (file)
@@ -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):