caveat/ecall.c: refactor proxy ecall
[cavatools.git] / caveat / ecall.h
1 #pragma once
2
3 #include <stdio.h>
4 #include <stdint.h>
5 #include <sys/time.h>
6
7 struct ecall_entry {
8 long number;
9 char const *name;
10 };
11
12 #include "opcodes.h"
13 #include "insn.h"
14 #include "core.h"
15
16 #include "ecall_nums.h"
17
18 static inline struct ecall_entry const *
19 ecall_entry(long id) {
20 return &rv_to_host[id];
21 }
22
23 static inline long
24 ecall_fetch(struct core_t const *cpu, long arguments[6]) {
25 arguments[0] = cpu->reg[10].l;
26 arguments[1] = cpu->reg[11].l;
27 arguments[2] = cpu->reg[12].l;
28 arguments[3] = cpu->reg[13].l;
29 arguments[4] = cpu->reg[14].l;
30 arguments[5] = cpu->reg[15].l;
31
32 return cpu->reg[17].l;
33 }
34
35 static inline void
36 ecall_store(long const arguments[6], struct core_t *cpu)
37 {
38 cpu->reg[10].l = arguments[0];
39 cpu->reg[11].l = arguments[1];
40 cpu->reg[12].l = arguments[2];
41 cpu->reg[13].l = arguments[3];
42 cpu->reg[14].l = arguments[4];
43 cpu->reg[15].l = arguments[5];
44 }