Skip to content

Commit 30bd88d

Browse files
committed
fix riscv-tests and add flag for exit call
1 parent cb6d051 commit 30bd88d

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

Diff for: src/emu.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "trap.h"
1111
#include "csr.h"
1212

13+
static bool allow_ecall_exit = false;
14+
1315
#define AS_SIGNED(val) (*(int32_t*)&val)
1416
#define AS_UNSIGNED(val) (*(uint*)&val)
1517
const uint ZERO = 0;
@@ -203,12 +205,12 @@ DEF(ebreak, FormatEmpty, { // system
203205
SINGLE_STEP=1;
204206
})
205207
DEF(ecall, FormatEmpty, { // system
206-
/* if (cpu->xreg[17] == 93) { */
207-
/* // EXIT CALL */
208-
/* uint status = cpu->xreg[10] >> 1; */
209-
/* printf("ecall EXIT = %d (0x%x)\n", status, status); */
210-
/* exit(status); */
211-
/* } */
208+
if (allow_ecall_exit && cpu->xreg[17] == 93) {
209+
// EXIT CALL
210+
uint status = cpu->xreg[10] >> 1;
211+
printf("ecall EXIT = %d (0x%x)\n", status, status);
212+
exit(status);
213+
}
212214

213215
ret->trap.en = true;
214216
ret->trap.value = cpu->pc;

Diff for: src/main.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ uint8_t* get_mmap_ptr(const char* filename) {
5858
}
5959

6060
void usage() {
61-
printf("Usage: rvc (-e <ELF binary>|-b <raw binary>) [-d <device tree binary>] [-i <initramfs>] [-v (0|1|2|3|4)] [-s] [-t]\n");
61+
printf("Usage: rvc (-e <ELF binary>|-b <raw binary>) [-d <device tree binary>] [-i <initramfs>] [-v (0|1|2|3|4)] [-s] [-t] [-x]\n");
6262
exit(EXIT_FAILURE);
6363
}
6464

@@ -92,9 +92,12 @@ int main(int argc, char *argv[]) {
9292
int c;
9393
bool trace = false;
9494

95-
while ((c = getopt (argc, argv, "e:b:d:v:i:st")) != -1) {
95+
while ((c = getopt (argc, argv, "e:b:d:v:i:stx")) != -1) {
9696
switch (c)
9797
{
98+
case 'x':
99+
allow_ecall_exit = true;
100+
break;
98101
case 'e':
99102
elf = optarg;
100103
break;
@@ -163,7 +166,7 @@ int main(int argc, char *argv[]) {
163166
setvbuf(stdin, NULL, _IONBF, 0);
164167
buf_off();
165168

166-
// LIMITER
169+
// LIMITER (set to high number to ignore)
167170
const unsigned long restr = 200000*1000;
168171
unsigned long cur = 0;
169172
unsigned long t = time(NULL);
@@ -204,13 +207,13 @@ int main(int argc, char *argv[]) {
204207
/* printf("else if (cpu.clock == %d && arb != 0x%08x) ARB_FAIL\n", cpu.clock, arb_f); */
205208
/* } */
206209

207-
if (cpu.pc == 0x80000118) {
210+
/* if (cpu.pc == 0x80000118) { */
208211
/* if (cpu.clock == 6350505) { // divergence: 6350908 */
209212
/* if (cpu.clock == 6400000) { */
210-
printf("BREAKPOINT HIT\n");
211-
SINGLE_STEP = 1;
212-
VERBOSE = 4;
213-
}
213+
/* printf("BREAKPOINT HIT\n"); */
214+
/* SINGLE_STEP = 1; */
215+
/* VERBOSE = 4; */
216+
/* } */
214217

215218
if (VERBOSE >= 4)
216219
cpu_dump(&cpu);

Diff for: test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function run_test {
1919

2020
popd
2121

22-
echo "Running: ./rvc -e \"./riscv-tests/isa/$1\" -v 1"
23-
timeout 5s ./rvc -e "./riscv-tests/isa/$1" -v 1
22+
echo "Running: ./rvc -x -e \"./riscv-tests/isa/$1\" -v 1"
23+
./rvc -x -e "./riscv-tests/isa/$1" -v 1
2424

2525
if [ $? -gt 0 ]; then
2626
echo "Test failed!"

0 commit comments

Comments
 (0)