diff --git a/nemu/src/isa/riscv32/inst.c b/nemu/src/isa/riscv32/inst.c index 1208cb4..c8d18d1 100644 --- a/nemu/src/isa/riscv32/inst.c +++ b/nemu/src/isa/riscv32/inst.c @@ -89,28 +89,14 @@ static int decode_exec(Decode *s) { 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 = src1 + imm; - R(rd) = s->pc + 4; - } while (0)); - INSTPAT("??????? ????? ????? 000 ????? 11000 11", beq, B, - do_branch(s, src1 == src2, imm)); - INSTPAT("??????? ????? ????? 001 ????? 11000 11", bne, B, - do_branch(s, src1 != src2, imm)); - INSTPAT("??????? ????? ????? 100 ????? 11000 11", blt, B, - do_branch(s, (sword_t)src1 < (sword_t)src2, imm)); - INSTPAT("??????? ????? ????? 101 ????? 11000 11", bge, B, - do_branch(s, (sword_t)src1 >= (sword_t)src2, imm)); - INSTPAT("??????? ????? ????? 110 ????? 11000 11", bltu, B, - do_branch(s, src1 < src2, imm)); - INSTPAT("??????? ????? ????? 111 ????? 11000 11", bgeu, B, - do_branch(s, src1 >= src2, 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 = src1 + imm; R(rd) = s->pc + 4; } while(0)); + INSTPAT("??????? ????? ????? 000 ????? 11000 11", beq , B, do_branch(s, src1 == src2, imm)); + INSTPAT("??????? ????? ????? 001 ????? 11000 11", bne , B, do_branch(s, src1 != src2, imm)); + INSTPAT("??????? ????? ????? 100 ????? 11000 11", blt , B, do_branch(s, (sword_t)src1 < (sword_t)src2, imm)); + INSTPAT("??????? ????? ????? 101 ????? 11000 11", bge , B, do_branch(s, (sword_t)src1 >= (sword_t)src2, imm)); + INSTPAT("??????? ????? ????? 110 ????? 11000 11", bltu , B, do_branch(s, src1 < src2, imm)); + INSTPAT("??????? ????? ????? 111 ????? 11000 11", bgeu , B, do_branch(s, src1 >= src2, imm)); INSTPAT("??????? ????? ????? 000 ????? 00000 11", lb , I, R(rd) = SEXT(Mr(src1 + imm, 1), 8)); INSTPAT("??????? ????? ????? 001 ????? 00000 11", lh , I, R(rd) = SEXT(Mr(src1 + imm, 2), 16)); @@ -135,14 +121,14 @@ static int decode_exec(Decode *s) { INSTPAT("??????? ????? ????? ??? ????? ????? ??", inv , N, INV(s->pc)); // "M" - // INSTPAT("0000001 ????? ????? 000 ????? 01100 11", mul, R, R(rd) = src1 * src2); - // INSTPAT("0000001 ????? ????? 001 ????? 01100 11", mulh, R, R(rd) = (uint64_t)src1 * (uint64_t)src2 >> 32); - // INSTPAT("0000001 ????? ????? 010 ????? 01100 11", mulhsu, R, R(rd) = (int64_t)src1 * (uint64_t)src2 >> 32); - // INSTPAT("0000001 ????? ????? 011 ????? 01100 11", mulhu, R, R(rd) = (int64_t)src1 * (int64_t)src2 >> 32); - // INSTPAT("0000001 ????? ????? 100 ????? 01100 11", div, R, R(rd) = (sword_t)src1 / (sword_t)src2); - // INSTPAT("0000001 ????? ????? 101 ????? 01100 11", divu, R, R(rd) = src1 / src2); - // INSTPAT("0000001 ????? ????? 110 ????? 01100 11", rem, R, R(rd) = (sword_t)src1 % (sword_t)src2); - // INSTPAT("0000001 ????? ????? 111 ????? 01100 11", remu, R, R(rd) = src1 % src2); + INSTPAT("0000001 ????? ????? 000 ????? 01100 11", mul, R, R(rd) = src1 * src2); + INSTPAT("0000001 ????? ????? 001 ????? 01100 11", mulh, R, R(rd) = (uint64_t)src1 * (uint64_t)src2 >> 32); + INSTPAT("0000001 ????? ????? 010 ????? 01100 11", mulhsu, R, R(rd) = (int64_t)src1 * (uint64_t)src2 >> 32); + INSTPAT("0000001 ????? ????? 011 ????? 01100 11", mulhu, R, R(rd) = (int64_t)src1 * (int64_t)src2 >> 32); + INSTPAT("0000001 ????? ????? 100 ????? 01100 11", div, R, R(rd) = (sword_t)src1 / (sword_t)src2); + INSTPAT("0000001 ????? ????? 101 ????? 01100 11", divu, R, R(rd) = src1 / src2); + INSTPAT("0000001 ????? ????? 110 ????? 01100 11", rem, R, R(rd) = (sword_t)src1 % (sword_t)src2); + INSTPAT("0000001 ????? ????? 111 ????? 01100 11", remu, R, R(rd) = src1 % src2); INSTPAT_END();