-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reserved compressed instructions do not trigger illegal instruction exception #782
Comments
I do have small local patch that fixes the issue that I can quickly create a PR for. Just want to be sure we agree on the expected behavior as it is undefined. |
Hey @mikaelsky
One of the core's core principles (😅) is the trapping on any kind of illegal, unsupported or malformed instruction words. So yeah, we should close this instruction decoding loophole.
Your fix looks good. So, go for it! 👍 |
Added a illegal instruction exception to the register to register branch of the compressed instruction decoder. Signed-off-by: Mikael Mortensen <119539842+mikaelsky@users.noreply.github.com>
PR created. |
Note: the fix passes a couple of seeds of our randomly generated riscvDV undefined compressed instruction test so seems good. |
Describe the bug
When we hit the core with a reserved compressed instruction it doesn't trigger an illegal instruction exception.
This behavior in the RISCV spec is undefined/up to the implementer.
RISCV spec Vol I chapter 2.2.
![image](https://private-user-images.githubusercontent.com/119539842/301198155-3dda622a-ac75-4016-858d-aa943ffc12d0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA4NTYxNjQsIm5iZiI6MTcyMDg1NTg2NCwicGF0aCI6Ii8xMTk1Mzk4NDIvMzAxMTk4MTU1LTNkZGE2MjJhLWFjNzUtNDAxNi04NThkLWFhOTQzZmZjMTJkMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxM1QwNzMxMDRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kZGVhNjVhZDdjY2Y4ZjE0YzY3MzY2ZGYwNDc3NDNlMjM1OGYxN2JhNDIxYmQwNGZjZWRhNjU3MzE3YzllMmI1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.nXY4q9yhpKEKcnPZjhtHeLLA-QO7GnRFMJ5eO1b59gE)
From what I can gather from the non-compressed instruction behavior when the decoder hits reserved/unspecified space an illegal instruction exception is indeed triggered.
Hence the assumption that this is unintended behavior.
To Reproduce
This is the randomized code stream from riscvDV.
The ref vs dut comparison showing that the ref takes an illegal instruction trap, but the dut just rolls on and tries to execute the undefined instruction.
Expected behavior
From the behavior of the rest of the core I would expect the reserved instruction to trip an illegal instruction, I could be wrong though.
Screenshots
NA
Environment:
Hardware:
Additional context
0x9E7D
1001_1110_0111_1101
OP: 01 -> CB, CI, CJ, or CS type instructions
funct3: 100 ->
expanding funct3 to match the extended decoding we get:
Looking at the compressed instruction decoder OP = "01" we get:
when others => -- 100: C.SRLI, C.SRAI, C.ANDI, C.SUB, C.XOR, C.OR, C.AND, reserved
In here we only check bits 11:10 ignoring bit 12
case ci_instr16_i(11 downto 10) is
From a quick handy decoder we get:
![image](https://private-user-images.githubusercontent.com/119539842/301205915-89219be4-8e7f-4f8f-968f-cc8915b41917.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA4NTYxNjQsIm5iZiI6MTcyMDg1NTg2NCwicGF0aCI6Ii8xMTk1Mzk4NDIvMzAxMjA1OTE1LTg5MjE5YmU0LThlN2YtNGY4Zi05NjhmLWNjODkxNWI0MTkxNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxM1QwNzMxMDRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jNzA2M2YyZmNmZDNlMWZiYTdhNTYzYzcwMGJhZmQyYWMxNDA1ZDUyOGRiNjFkNmY1OTZkMzllZTc0NDY3ODNkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.T-MAdKgrnAh2CqzqUABR4Ik1p_vfcqo5EmQyie5NX1Y)
Where it seems that bit 12 for non c.srli/c.srai/c.andi we assume its an alu operation
when others => -- "11" = register-register operation
If we want to generate and illegal instruction here we should add:
from the c.srli/c.srai decoding path.
The text was updated successfully, but these errors were encountered: