Fix decoding of illegal/reserved opcodes as other valid opcodes
This commit is contained in:
parent
a13512c86a
commit
bf9687028d
50
picorv32.v
50
picorv32.v
|
@ -835,7 +835,7 @@ module picorv32 #(
|
||||||
instr_lui <= mem_rdata_latched[6:0] == 7'b0110111;
|
instr_lui <= mem_rdata_latched[6:0] == 7'b0110111;
|
||||||
instr_auipc <= mem_rdata_latched[6:0] == 7'b0010111;
|
instr_auipc <= mem_rdata_latched[6:0] == 7'b0010111;
|
||||||
instr_jal <= mem_rdata_latched[6:0] == 7'b1101111;
|
instr_jal <= mem_rdata_latched[6:0] == 7'b1101111;
|
||||||
instr_jalr <= mem_rdata_latched[6:0] == 7'b1100111;
|
instr_jalr <= mem_rdata_latched[6:0] == 7'b1100111 && mem_rdata_latched[14:12] == 3'b000;
|
||||||
instr_retirq <= mem_rdata_latched[6:0] == 7'b0001011 && mem_rdata_latched[31:25] == 7'b0000010 && ENABLE_IRQ;
|
instr_retirq <= mem_rdata_latched[6:0] == 7'b0001011 && mem_rdata_latched[31:25] == 7'b0000010 && ENABLE_IRQ;
|
||||||
instr_waitirq <= mem_rdata_latched[6:0] == 7'b0001011 && mem_rdata_latched[31:25] == 7'b0000100 && ENABLE_IRQ;
|
instr_waitirq <= mem_rdata_latched[6:0] == 7'b0001011 && mem_rdata_latched[31:25] == 7'b0000100 && ENABLE_IRQ;
|
||||||
|
|
||||||
|
@ -890,9 +890,11 @@ module picorv32 #(
|
||||||
2'b01: begin // Quadrant 1
|
2'b01: begin // Quadrant 1
|
||||||
case (mem_rdata_latched[15:13])
|
case (mem_rdata_latched[15:13])
|
||||||
3'b000: begin // C.NOP / C.ADDI
|
3'b000: begin // C.NOP / C.ADDI
|
||||||
is_alu_reg_imm <= 1;
|
if (!mem_rdata_latched[12:2] || mem_rdata_latched[11:7]) begin
|
||||||
decoded_rd <= mem_rdata_latched[11:7];
|
is_alu_reg_imm <= 1;
|
||||||
decoded_rs1 <= mem_rdata_latched[11:7];
|
decoded_rd <= mem_rdata_latched[11:7];
|
||||||
|
decoded_rs1 <= mem_rdata_latched[11:7];
|
||||||
|
end
|
||||||
end
|
end
|
||||||
3'b001: begin // C.JAL
|
3'b001: begin // C.JAL
|
||||||
instr_jal <= 1;
|
instr_jal <= 1;
|
||||||
|
@ -904,18 +906,20 @@ module picorv32 #(
|
||||||
decoded_rs1 <= 0;
|
decoded_rs1 <= 0;
|
||||||
end
|
end
|
||||||
3'b 011: begin
|
3'b 011: begin
|
||||||
if (mem_rdata_latched[11:7] == 2) begin // C.ADDI16SP
|
if (mem_rdata_latched[12] || mem_rdata_latched[6:2]) begin
|
||||||
is_alu_reg_imm <= 1;
|
if (mem_rdata_latched[11:7] == 2) begin // C.ADDI16SP
|
||||||
decoded_rd <= mem_rdata_latched[11:7];
|
is_alu_reg_imm <= 1;
|
||||||
decoded_rs1 <= mem_rdata_latched[11:7];
|
decoded_rd <= mem_rdata_latched[11:7];
|
||||||
end else begin // C.LUI
|
decoded_rs1 <= mem_rdata_latched[11:7];
|
||||||
instr_lui <= 1;
|
end else begin // C.LUI
|
||||||
decoded_rd <= mem_rdata_latched[11:7];
|
instr_lui <= 1;
|
||||||
decoded_rs1 <= 0;
|
decoded_rd <= mem_rdata_latched[11:7];
|
||||||
|
decoded_rs1 <= 0;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
3'b100: begin
|
3'b100: begin
|
||||||
if (mem_rdata_latched[11] == 1'b0) begin // C.SRLI, C.SRAI
|
if (!mem_rdata_latched[11] && !mem_rdata_latched[12]) begin // C.SRLI, C.SRAI
|
||||||
is_alu_reg_imm <= 1;
|
is_alu_reg_imm <= 1;
|
||||||
decoded_rd <= 8 + mem_rdata_latched[9:7];
|
decoded_rd <= 8 + mem_rdata_latched[9:7];
|
||||||
decoded_rs1 <= 8 + mem_rdata_latched[9:7];
|
decoded_rs1 <= 8 + mem_rdata_latched[9:7];
|
||||||
|
@ -951,18 +955,22 @@ module picorv32 #(
|
||||||
2'b10: begin // Quadrant 2
|
2'b10: begin // Quadrant 2
|
||||||
case (mem_rdata_latched[15:13])
|
case (mem_rdata_latched[15:13])
|
||||||
3'b000: begin // C.SLLI
|
3'b000: begin // C.SLLI
|
||||||
is_alu_reg_imm <= 1;
|
if (!mem_rdata_latched[12]) begin
|
||||||
decoded_rd <= mem_rdata_latched[11:7];
|
is_alu_reg_imm <= 1;
|
||||||
decoded_rs1 <= mem_rdata_latched[11:7];
|
decoded_rd <= mem_rdata_latched[11:7];
|
||||||
decoded_rs2 <= {mem_rdata_latched[12], mem_rdata_latched[6:2]};
|
decoded_rs1 <= mem_rdata_latched[11:7];
|
||||||
|
decoded_rs2 <= {mem_rdata_latched[12], mem_rdata_latched[6:2]};
|
||||||
|
end
|
||||||
end
|
end
|
||||||
3'b010: begin // C.LWSP
|
3'b010: begin // C.LWSP
|
||||||
is_lb_lh_lw_lbu_lhu <= 1;
|
if (mem_rdata_latched[11:7]) begin
|
||||||
decoded_rd <= mem_rdata_latched[11:7];
|
is_lb_lh_lw_lbu_lhu <= 1;
|
||||||
decoded_rs1 <= 2;
|
decoded_rd <= mem_rdata_latched[11:7];
|
||||||
|
decoded_rs1 <= 2;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
3'b100: begin
|
3'b100: begin
|
||||||
if (mem_rdata_latched[12] == 0 && mem_rdata_latched[6:2] == 0) begin // C.JR
|
if (mem_rdata_latched[12] == 0 && mem_rdata_latched[11:7] != 0 && mem_rdata_latched[6:2] == 0) begin // C.JR
|
||||||
instr_jalr <= 1;
|
instr_jalr <= 1;
|
||||||
decoded_rd <= 0;
|
decoded_rd <= 0;
|
||||||
decoded_rs1 <= mem_rdata_latched[11:7];
|
decoded_rs1 <= mem_rdata_latched[11:7];
|
||||||
|
|
Loading…
Reference in New Issue