Fix handling of C.MV and C.JR

- Decoding must give precedence to rs2 (i.e. instr_i[6:2]) to
  switch between C.MV and C.JR.
  "C.MV is only valid when rs2̸=x0; the code points with rs2=x0
   correspond to the C.JR instruction. The code points with rs2̸=x0
   and rd=x0 are HINTs."

- C.JR is only valid with rs1==x0. Throw an illegal instruction
  exception if that's not the case.
  "C.JR is only valid when rs1̸=x0; the code point with rs1=x0
   is reserved." RV32 Spec, p103

All spec references based on RISC-V Unprivileged ISA
V20190305-Base-Ratification
This commit is contained in:
Philipp Wagner 2019-05-22 18:50:58 +01:00 committed by Philipp Wagner
parent 3de95df060
commit 409892ec8c

View file

@ -206,12 +206,14 @@ module ibex_compressed_decoder (
3'b100: begin
if (instr_i[12] == 1'b0) begin
// c.mv -> add rd/rs1, x0, rs2
instr_o = {7'b0, instr_i[6:2], 5'b0, 3'b0, instr_i[11:7], {OPCODE_OP}};
if (instr_i[6:2] == 5'b0) begin
if (instr_i[6:2] != 5'b0) begin
// c.mv -> add rd/rs1, x0, rs2
// (c.mv hints are translated into an add hint)
instr_o = {7'b0, instr_i[6:2], 5'b0, 3'b0, instr_i[11:7], {OPCODE_OP}};
end else begin
// c.jr -> jalr x0, rd/rs1, 0
instr_o = {12'b0, instr_i[11:7], 3'b0, 5'b0, {OPCODE_JALR}};
if (instr_i[11:7] == 5'b0) illegal_instr_o = 1'b1;
end
end else begin
if (instr_i[6:2] != 5'b0) begin