commit - 0ed5ecb832e32efc6b14ca4073ee2fb0a6f3018a
commit + 21ec87349ebe2d4f71bf60a93be60c30ef49b804
blob - e7327b6620de46d6741a80b92a4b7b576d5ce2b6
blob + 9e149d28ac6c0edce644559a6645307e573e1329
--- Makefile
+++ Makefile
include config.mk
COPT = -g -O2
-CFLAGS = ${CFLAGS_OS} ${COPT} -std=c2x
+CFLAGS = ${CFLAGS_OS} ${COPT} -std=c2x -Wall
LDFLAGS = ${LDFLAGS_OS} -lpthread
OBJ = src/linurv.o src/ecall.o src/cpu.o src/exec.o
blob - 05d839119a65abac506979add72e7529eddb1714
blob + 57f058885d086e859625805b9891f484dd0b5523
--- src/cpu.c
+++ src/cpu.c
#define log(fmt, ...) eprintf ("%08"PRIx64": " fmt "\n", pc - 4, __VA_ARGS__)
void cpu_exec (u32 instr)
{
- const char *name;
const u8 rd = (instr >> 7) & 0x1f;
const u8 funct3 = (instr >> 12) & 0x7;
const u8 rs1 = (instr >> 15) & 0x1f;
}
cpu_set (rd, c);
break;
-#undef alui
case 0b0011011: // aluiw rd, rs1, iimm
a = cpu_get (rs1);
b = imm_i;
c = (instr >> 30) & 1;
switch (funct3) {
case 0b000: // addiw
- name = "addiw";
- c = a + b;
+ c = extend (a + b);
+ alui ("addiw");
break;
case 0b001: // slliw
if (shamt >> 5)
goto ud;
- name = "slliw";
- c = a << shamt;
+ c = extend (a << shamt);
+ alui ("slliw");
break;
case 0b101: // srliw/sraiw
if (shamt >> 5)
goto ud;
switch (funct7) {
case 0b0000000:
- name = "srliw";
- c = (u32)a >> shamt;
+ c = extend ((u32)a >> shamt);
+ alui ("srliw");
break;
case 0b0100000:
- name = "sraiw";
- c = (i32)a >> shamt;
+ c = extend ((i32)a >> shamt);
+ alui ("sraiw");
break;
default:
goto ud;
default:
goto ud;
}
- c &= 0x00000000ffffffff;
- c = extend (c);
- log ("%s x%u, x%u, %"PRId64, name, (uint)rd, (uint)rs1, (i64)imm_i);
cpu_set (rd, c);
break;
+#undef alui
#define alu(name) log (name " x%u, x%u, x%u ; "name"(%"PRId64", %"PRId64") = %"PRId64, (uint)rd, (uint)rs1, (uint)rs2, a, b, c)
case 0b0110011: // alu rd, rs1, rs2
a = cpu_get (rs1);
blob - 45391396df92dfe98e982e147b7c07508a1ccd41
blob + bfafe890605229b56f681ae7470de4cf224f94fe
--- src/exec.c
+++ src/exec.c
{
Elf64_Ehdr ehdr;
- char buffer[256], *nl, *s, **args, **env;
+ char buffer[256], *nl, *s;
int fd;
fd = open (path, O_RDONLY);
blob - 8528c3aaf97812d6a936b0ea33e916ab0ce836df
blob + 4d5956003429e36105db5398413c20e8fa4d9674
--- src/linurv.c
+++ src/linurv.c
const char *filename;
struct rlimit rl;
size_t stack_size;
- int fd, envc;
+ int envc;
char *base;
- void *ptr;
base = basename (argv[0]);