I have generated random code with unaligned instructions enabled. During code execution, an unaligned jump causes an illegal compressed instruction to be executed. The opcode of the illegal instruction is 0x401a, it consists of c.lwsp with a target register rd=0, which is illegal according to the specification (RD must be different from zero)
The execution of this instruction causes a trap_illegal_instruction on the spike side, but the DUT continues to execute the instruction because the target register is not checked for non-zero, and tries to load at address x80000000 + 132 = 0x80000084, causing a trap_load_page_fault.
To fix this, we added checking the target register to see if it is different from zero
wave
Here are the output signals after the correction, we can clearly see that the instruction is considered illegal.
The signals and logs after the correction also show that the tval of the trap in the spike is 0x0000401A and in the DUT is 0x8931401A because the mask is not applied as you mentioned (TODO)
According to the riscv-compressed-spec, there are several compressed instructions that require a check that the RS and RD registers are different from zero, and these registers are not checked in the DUT, so there are other checks to be done for other instructions.
Hi,
I have generated random code with unaligned instructions enabled. During code execution, an unaligned jump causes an illegal compressed instruction to be executed. The opcode of the illegal instruction is
0x401a
, it consists ofc.lwsp
with a target registerrd=0
, which is illegal according to the specification (RD must be different from zero)The execution of this instruction causes a
trap_illegal_instruction
on the spike side, but the DUT continues to execute the instruction because the target register is not checked for non-zero, and tries to load at addressx80000000 + 132 = 0x80000084
, causing atrap_load_page_fault
.Here is the execution result
Dump
Spike log
Tracer log
To fix this, we added checking the target register to see if it is different from zero
wave
Here are the output signals after the correction, we can clearly see that the instruction is considered illegal.
The signals and logs after the correction also show that the
tval
of the trap in the spike is0x0000401A
and in the DUT is0x8931401A
because the mask is not applied as you mentioned (TODO)https://github.com/SpinalHDL/NaxRiscv/blob/bc18f667c11ed05ddbc248dc90e255d4c16798ad/src/main/scala/naxriscv/frontend/DecompressorPlugin.scala#L51-L52
According to the riscv-compressed-spec, there are several compressed instructions that require a check that the RS and RD registers are different from zero, and these registers are not checked in the DUT, so there are other checks to be done for other instructions.