-
Notifications
You must be signed in to change notification settings - Fork 36
/
riscv-pk-xfiles-syscalls.patch
252 lines (232 loc) · 7.63 KB
/
riscv-pk-xfiles-syscalls.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
diff --git a/Makefile.in b/Makefile.in
index b2aca28..323e4a2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -72,11 +72,12 @@ install_exes_dir := $(INSTALLDIR)/bin
sprojs := @subprojects@
sprojs_enabled := @subprojects_enabled@
-sprojs_include := -I. $(addprefix -I$(src_dir)/, $(sprojs_enabled))
+sprojs_include := -I. $(addprefix -I$(src_dir)/, $(sprojs_enabled)) \
+ -I$(src_dir)/../../xfiles-dana
VPATH := $(addprefix $(src_dir)/, $(sprojs_enabled))
#-------------------------------------------------------------------------
-# Programs and flags
+# Programs and flags
#-------------------------------------------------------------------------
# C++ compiler
@@ -84,7 +85,7 @@ VPATH := $(addprefix $(src_dir)/, $(sprojs_enabled))
# - CXXFLAGS : flags for C++ compiler (eg. -Wall,-g,-O3)
CC := @CC@
-CFLAGS := @CFLAGS@ $(CFLAGS) -DBBL_PAYLOAD=\"$(bbl_payload)\"
+CFLAGS := @CFLAGS@ $(CFLAGS) -DBBL_PAYLOAD=\"$(bbl_payload)\" -march=RV64IMAFDXcustom
COMPILE := $(CC) -MMD -MP $(CFLAGS) \
$(sprojs_include)
# Linker
@@ -130,7 +131,7 @@ dist_junk += $(sprojs_mk)
#-------------------------------------------------------------------------
# This function is used by the subproject template to reverse the list
# of dependencies. It uses recursion to perform the reversal.
-#
+#
# Arguments:
# $(1) : space separated input list
# retval : input list in reverse order
@@ -152,7 +153,7 @@ endef
# subprojects defining a certain set of make variables which are all
# prefixed with the subproject name. Since subproject names can have
# dashes in them (and the make variables are assumed to only use
-# underscores) the template takes two arguments - one with the regular
+# underscores) the template takes two arguments - one with the regular
# subproject name and one with dashes replaced with underscores.
#
# Arguments:
@@ -282,7 +283,7 @@ clean-$(1) :
libs += lib$(1).a
objs += $$($(2)_c_objs)
-srcs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_c_srcs))
+srcs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_c_srcs))
hdrs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_hdrs))
junk += $$($(2)_junk)
deps += $$($(2)_c_deps)
@@ -373,7 +374,7 @@ dist_junk += config.status config.h Makefile config.log
# Distribution
#-------------------------------------------------------------------------
# The distribution tarball is named project-ver.tar.gz and it includes
-# both enabled and disabled subprojects.
+# both enabled and disabled subprojects.
dist_files = \
$(sprojs) \
diff --git a/machine/encoding.h b/machine/encoding.h
index 35e0f9f..819b64a 100644
--- a/machine/encoding.h
+++ b/machine/encoding.h
@@ -872,6 +872,7 @@
#define CAUSE_SUPERVISOR_ECALL 0x9
#define CAUSE_HYPERVISOR_ECALL 0xa
#define CAUSE_MACHINE_ECALL 0xb
+#define CAUSE_ROCC 0xc
#endif
#ifdef DECLARE_INSN
DECLARE_INSN(beq, MATCH_BEQ, MASK_BEQ)
diff --git a/machine/machine.mk.in b/machine/machine.mk.in
index 6568dc5..1f2ba55 100644
--- a/machine/machine.mk.in
+++ b/machine/machine.mk.in
@@ -14,6 +14,7 @@ machine_hdrs = \
sbi.h \
unprivileged_memory.h \
vm.h \
+ xfiles-supervisor.h \
machine_c_srcs = \
mtrap.c \
@@ -25,6 +26,7 @@ machine_c_srcs = \
misaligned_ldst.c \
sbi_impl.c \
configstring.c \
+ xfiles-supervisor.c \
machine_asm_srcs = \
mentry.S \
diff --git a/machine/mentry.S b/machine/mentry.S
index 64c60c3..d4bd330 100644
--- a/machine/mentry.S
+++ b/machine/mentry.S
@@ -48,6 +48,9 @@ trap_vector:
# This is an interrupt. Discard the mcause MSB and decode the rest.
sll a1, a1, 1
+ li a0, CAUSE_ROCC * 2
+ beq a0, a1, rocc_trap
+
# Is it a machine timer interrupt?
li a0, IRQ_M_TIMER * 2
bne a0, a1, 1f
diff --git a/machine/minit.c b/machine/minit.c
index 33a1e3b..355881b 100644
--- a/machine/minit.c
+++ b/machine/minit.c
@@ -19,6 +19,7 @@ static void mstatus_init()
uintptr_t ms = 0;
ms = INSERT_FIELD(ms, MSTATUS_VM, VM_CHOICE);
ms = INSERT_FIELD(ms, MSTATUS_FS, 1);
+ ms = INSERT_FIELD(ms, MSTATUS_XS, 1);
write_csr(mstatus, ms);
// Make sure the hart actually supports the VM mode we want
diff --git a/machine/mtrap.c b/machine/mtrap.c
index a68c0d9..e9ad7e5 100644
--- a/machine/mtrap.c
+++ b/machine/mtrap.c
@@ -7,6 +7,8 @@
#include <stdarg.h>
#include <stdio.h>
+#include "xfiles-supervisor.h"
+
volatile uint64_t tohost __attribute__((aligned(64))) __attribute__((section("htif")));
volatile uint64_t fromhost __attribute__((aligned(64))) __attribute__((section("htif")));
@@ -15,6 +17,10 @@ void __attribute__((noreturn)) bad_trap()
die("machine mode: unhandlable trap %d @ %p", read_csr(mcause), read_csr(mepc));
}
+void __attribute__((noreturn)) rocc_trap() {
+ die("XFiles trap %d @ %p", xf_read_csr(csr_CAUSE), read_csr(mepc));
+}
+
static uintptr_t mcall_hart_id()
{
return read_const_csr(mhartid);
@@ -296,6 +302,8 @@ void trap_from_machine_mode(uintptr_t* regs, uintptr_t dummy, uintptr_t mepc)
case CAUSE_FAULT_LOAD:
case CAUSE_FAULT_STORE:
return machine_page_fault(regs, mepc);
+ case CAUSE_ROCC:
+ return rocc_trap();
default:
bad_trap();
}
diff --git a/machine/xfiles-supervisor.c b/machine/xfiles-supervisor.c
new file mode 120000
index 0000000..5b012bc
--- /dev/null
+++ b/machine/xfiles-supervisor.c
@@ -0,0 +1 @@
+../../../xfiles-dana/src/main/c/xfiles-supervisor.c
\ No newline at end of file
diff --git a/machine/xfiles-supervisor.h b/machine/xfiles-supervisor.h
new file mode 120000
index 0000000..1fd714e
--- /dev/null
+++ b/machine/xfiles-supervisor.h
@@ -0,0 +1 @@
+../../../xfiles-dana/src/main/c/xfiles-supervisor.h
\ No newline at end of file
diff --git a/pk/syscall.c b/pk/syscall.c
index 85139e4..4176474 100644
--- a/pk/syscall.c
+++ b/pk/syscall.c
@@ -9,6 +9,8 @@
#include <string.h>
#include <errno.h>
+#include "xfiles-supervisor.h"
+
typedef long (*syscall_t)(long, long, long, long, long, long, long);
#define CLOCK_FREQ 1000000000
@@ -363,7 +365,7 @@ int sys_times(long* loc)
loc[1] = 0;
loc[2] = 0;
loc[3] = 0;
-
+
return 0;
}
@@ -372,7 +374,7 @@ int sys_gettimeofday(long* loc)
uintptr_t t = rdcycle();
loc[0] = t / CLOCK_FREQ;
loc[1] = (t % CLOCK_FREQ) / (CLOCK_FREQ / 1000000);
-
+
return 0;
}
@@ -409,6 +411,24 @@ static int sys_stub_nosys()
return -ENOSYS;
}
+int sys_xfiles_dana_set_asid(asid_type asid)
+{
+ return set_asid(asid);
+}
+
+int sys_xfiles_dana_set_antp(ant_entry * antp, size_t size)
+{
+ return set_antp(antp, size);
+}
+
+int sys_xfiles_dana_debug_echo(uint32_t data)
+{
+ xlen_t out, action_and_data = ((uint64_t)0 << 32) | (uint32_t)data;
+ XFILES_INSTRUCTION(out, action_and_data, 0, t_USR_XFILES_DEBUG);
+ printk("[DEBUG] pk sees out: 0x%x\n", out);
+ return out;
+}
+
long do_syscall(long a0, long a1, long a2, long a3, long a4, long a5, unsigned long n)
{
const static void* syscall_table[] = {
@@ -454,6 +474,9 @@ long do_syscall(long a0, long a1, long a2, long a3, long a4, long a5, unsigned l
[SYS_getrusage] = sys_stub_nosys,
[SYS_getrlimit] = sys_stub_nosys,
[SYS_setrlimit] = sys_stub_nosys,
+ [SYS_xfiles_dana_set_asid] = sys_xfiles_dana_set_asid,
+ [SYS_xfiles_dana_set_antp] = sys_xfiles_dana_set_antp,
+ [SYS_xfiles_dana_debug_echo] = sys_xfiles_dana_debug_echo,
[SYS_chdir] = sys_chdir,
};
diff --git a/pk/syscall.h b/pk/syscall.h
index c1f3d8a..38ca3b5 100644
--- a/pk/syscall.h
+++ b/pk/syscall.h
@@ -50,6 +50,10 @@
#define SYS_getrusage 165
#define SYS_clock_gettime 113
+#define SYS_xfiles_dana_set_asid SYSCALL_SET_ASID
+#define SYS_xfiles_dana_set_antp SYSCALL_SET_ANTP
+#define SYS_xfiles_dana_debug_echo SYSCALL_DEBUG_ECHO
+
#define OLD_SYSCALL_THRESHOLD 1024
#define SYS_open 1024
#define SYS_link 1025