commit - a67f2fcdcd5d5cc91b1aac7a4c600482f600a732
commit + 0ec92ecb47a3a0093deb0f285e0d05d011cf06d9
blob - c1b64dea367cf49f7f9f16f859eb4ff99407573e
blob + 56c7fd9329171d775185b57763c510b8323df1a0
--- Makefile
+++ Makefile
CFLAGS = -std=c2x -fPIC -O0 -g
LDFLAGS = -pie -static -lpthread
OBJ = rvemu.o ecall.o cpu.o exec.o
-PROGS = test.elf hello.elf
+PROGS = test.elf test2.elf hello.elf
all: rvemu ${PROGS}
blob - 6d0a65ab8870c771e0c20ac41212797db275fd74
blob + a705236c9bc04ebc05144792b2c9cc7cded54f0a
--- cpu.c
+++ cpu.c
case 0b001:
name = "bne";
c = a != b;
+ break;
case 0b100:
name = "blt";
c = (i64)a < (i64)b;
eprintf ("%08llx: efence\n", pc - 4);
break;
case 0b1110011: // ecall/ebreak
- log (
- "ecall a0=%llu, a1=%llu, a2=%llu, a3=%llu, a4=%llu, a5=%llu, a7=%llu",
- cpu_get (10),
- cpu_get (11),
- cpu_get (12),
- cpu_get (13),
- cpu_get (14),
- cpu_get (15),
- cpu_get (17)
- );
- ecall ();
+ if ((instr >> 20) & 1) {
+ eprintf ("%08llx: ebreak\n", pc - 4);
+ __asm __volatile__ ("int $3");
+ } else {
+ log (
+ "ecall a0=%llu, a1=%llu, a2=%llu, a3=%llu, a4=%llu, a5=%llu, a7=%llu",
+ cpu_get (10),
+ cpu_get (11),
+ cpu_get (12),
+ cpu_get (13),
+ cpu_get (14),
+ cpu_get (15),
+ cpu_get (17)
+ );
+ ecall ();
+ }
break;
default:
ud:
blob - 4cb95aa505e1a5d33bd0d37ed1fb0f4f115b2b67
blob + f1fa870f78600a53528abcc226d280124e392286
--- rvemu.h
+++ rvemu.h
#include <stdio.h>
#include <err.h>
-#define DEBUG 1
+#define DEBUG 0
#if DEBUG
# define eprintf(...) fprintf (stderr, __VA_ARGS__)
blob - 70f3e50ce557283d9025cf3c7e821c05c080395b
blob + 7ae62507ac23f2c3e6716f44bfdb437b02dbc5f6
--- test.c
+++ test.c
const char *volatile str = "Hello World!\n";
-size_t my_strlen (const char *s)
+__attribute__((always_inline))
+inline static void ebreak (void)
{
- size_t i;
- for (i = 0; s[i] != '\0'; ++i);
- return i;
+ __asm __volatile__ ("ebreak");
}
int main (void) {
- const size_t len = my_strlen (str);
- return len;
+ const size_t len = strlen (str);
+ write (1, str, len);
+ return 0;
}