diff --git a/flake.nix b/flake.nix index 69b4884..990d66d 100644 --- a/flake.nix +++ b/flake.nix @@ -61,6 +61,15 @@ gdb ] ++ builtins.attrValues self.packages.${system}; }; + + devShells.nemu = pkgs.mkShell { + packages = with pkgs; [ + clang-tools + ]; + inputsFrom = [ + self.packages.${system}.nemu + ]; + }; } ); } diff --git a/nemu/src/isa/riscv32/inst.c b/nemu/src/isa/riscv32/inst.c index 39e0e08..7d7d8e7 100644 --- a/nemu/src/isa/riscv32/inst.c +++ b/nemu/src/isa/riscv32/inst.c @@ -48,6 +48,11 @@ static void decode_operand(Decode *s, int *rd, word_t *src1, word_t *src2, word_ } } +static void do_jump(Decode *s, int rd, int relative_address) { + R(rd) = s->pc + 4; + s->dnpc = s->pc + relative_address; +} + static int decode_exec(Decode *s) { int rd = 0; word_t src1 = 0, src2 = 0, imm = 0; @@ -62,8 +67,8 @@ static int decode_exec(Decode *s) { INSTPAT_START(); INSTPAT("??????? ????? ????? ??? ????? 01101 11", lui , U, R(rd) = imm); INSTPAT("??????? ????? ????? ??? ????? 00101 11", auipc , U, R(rd) = s->pc + imm); - // INSTPAT("??????? ????? ????? ??? ????? 11011 11", jal, , J, do {s->dnpc = s->pc + imm; R(rd) = s->pc + 4; } while(0)); - // INSTPAT("??????? ????? ????? ??? ????? 11001 11", jalr , I, do {s->dnpc = s->pc + src1; R(rd) = s->pc + 4); } while(0); + // INSTPAT("??????? ????? ????? ??? ????? 11011 11", jal, , J, do_jump(s, rd, imm) ); + INSTPAT("??????? ????? ????? ??? ????? 11001 11", jalr , I, do_jump(s, rd, imm) ); INSTPAT("??????? ????? ????? 100 ????? 00000 11", lbu , I, R(rd) = Mr(src1 + imm, 1)); INSTPAT("??????? ????? ????? 000 ????? 01000 11", sb , S, Mw(src1 + imm, 1, src2)); INSTPAT("??????? ????? ????? 000 ????? 00100 11", addi , I, R(rd) = src1 + (sword_t)imm);