riscv-non-isa/riscv-arch-test

Test misalign-jal-01.S generates compressed instruction for platforms that support only RV32I

Closed this issue · 7 comments

Test is compiled using riscv32-unknown-elf-gcc -march=rv32i_zicsr -mabi=ilp32 ... and the generated instructions are:

...
0000                	.short	0x0000
00354513          	xor	a0,a0,3
00000013          	nop
0001                	.insn	2, 0x0001
00000117          	auipc	sp,0x0
02610113          	add	sp,sp,38
...

Toolchain is compiled without compressed instruction support.
This seems to be related with the alignment in LA macro:

/**** fixed length LA macro; alignment and rvc/norvc unknown before execution ****/
#define LA(reg,val)     ;\

This will fail this tests because a second exception will happen that is illegal instruction for RV32I platforms!

Attaching the requested part as a file!
inst_0.disass.txt

@ArbnorSh This test is deliberately causing a misaligned-fetch trap by jumping to a misaligned-address. The disass is showing you misaligned address where pc will jump in order to check that feature. Here is the complete disassembly and Sail_log file through which you can understand the behavior of the test. Let me breakdown the behavior of the test for your better understanding.

address 0x8000026c instr jal a0,80000476 is causing pc to jump to a misaligned address.
If misaligned access is enabled and DUT/Sail has compressed instruction support, then DUT/Sail will execute c.nop instruction and no exception will be thrown,
but in your case, when misaligned-access is disabled and/or compressed instruction support does not exist, then it will cause misaligned-fetch exception and will call the trap handler. You will see the following prompt in Sail log file in your case,

mem[X,0x8000026C] -> 0x056F
mem[X,0x8000026E] -> 0x20A0
[107] [M]: 0x8000026C (0x20A0056F) jal a0, 522
trapping from M to M to handle misaligned-fetch
handling exc#0x00 at priv M with tval 0x80000476
CSR mstatus <- 0x00001800
For reference => Line 645-650 (in the given log file)

Here mtval is getting 0x80000476 value showing you the misaligned address. This address is same as where you have seen .short 0x0000 or .2byte 0x0 (both are the same things).
Upon returning from the trap (or no trap in case-1), the program will keep executing instructions line by line.


Now, the address 0x80000476 is also in code region, so DUT/Sail will eventually reach to this address to execute this instruction. Over here, it will fetch a compressed instruction, if compressed instruction is supported by DUT/Sail, it will execute that c.nop instruction, otherwise (when compressed support is not there => Your case) it will cause illegal-instruction exception and once again calls the trap handler. For your case, you will see the following prompt in Sail log.

mem[X,0x80000474] -> 0x0000
[453] [M]: 0x80000474 (0x0000) c.illegal 0
trapping from M to M to handle illegal-instruction
handling exc#0x02 at priv M with tval 0x00000000
CSR mstatus <- 0x00001800
For reference => Line 2636-2641 in the given log file

In either case (trap or no trap), the program will complete its execution without any trouble, so you should be getting an exit from this program and this test will be passing on both DUT and Sail in all possible cases (with/without misaligned, with/without compressed support), so dont worry if you are seeing any compressed instruction in your disass, it is there for deliberate reason.

@UmerShahidengr
My understanding was that the testcase has one objective to test the misaligned fetch implementation on RV32I cores, now I understand that a core that implements misaligned fetch exception but it does not implement illegal instruction exception should fail this test. Thank you for the detailed explanation! Now it is clear on the generated compressed instructions.

@allenjbaum
Signatures were different from DUT and Sail. Will close this as resolved because test is deliberately inserting c.nop! Thank you for your help!