Skip to content
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

Allow for non-word aligned mtvec #72

Closed
vogelpi opened this issue Oct 25, 2019 · 11 comments
Closed

Allow for non-word aligned mtvec #72

vogelpi opened this issue Oct 25, 2019 · 11 comments

Comments

@vogelpi
Copy link

vogelpi commented Oct 25, 2019

I just wanted to raise awareness that the RISC-V compliance suite currently seems not respect coarser alignment restrictions on the BASE field for mtvec of a given target implementation.

The minimum alignment mandated by the RISC-V Privileged Spec v.1.11 is 4-byte but it explicitly allows for coarser restrictions:

If mtvec is writable, the set of values the register may hold can vary by implementation. The value in the BASE field must always be aligned on a 4-byte boundary, and the MODE setting may impose additional alignment constraints on the value in the BASE field.

An implementation may have different alignment constraints for different modes. In particular, MODE=Vectored may have stricter alignment constraints than MODE=Direct.

Allowing coarser alignments in Vectored mode enables vectoring to be implemented without a hardware adder circuit.

Ibex requires mtvec to be 256-byte aligned. Since the RISC-V compliance suite currently requires a finer alignment, the I-EBREAK and I-ECALL tests keep failing.

We are not sure what your view on this is, but we thought this should maybe be tracked here. For further information, please also have a look here lowRISC/ibex#428, lowRISC/ibex#99, lowRISC/ibex#100.

@vogelpi
Copy link
Author

vogelpi commented Oct 25, 2019

I am also pinging @eroom1966 as we have discussed this a while ago.

@allenjbaum
Copy link
Collaborator

allenjbaum commented Oct 25, 2019 via email

@vogelpi
Copy link
Author

vogelpi commented Nov 4, 2019

Thanks @allenjbaum for your quick response. I am happy to learn that this problem is being addressed.

@allenjbaum
Copy link
Collaborator

Well, it will be addressed in the future. It isn't clear to me that it is possible to fix this in v.1, though.

@neelgala
Copy link
Collaborator

Therer are currently 4 tests: I-EBREAK, I-ECALL, I-MISALIGN_JMP and I-MISALIGN_LDST which require access and update of mtvec. While riscof accounts for capturing the platform specifc constraints for mtvec, these tests would also have to be updated along with a linker script changes as well to account for this issue.

@allenjbaum
Copy link
Collaborator

Is this possible to fix in the current framework to handle arbitrary alignments?
if we only need to modify linker scripts which are already implementation specific, that is doable
If we need to modify tests, that will be implementation specific, and until we can import YAML parameters, we can't have a general test, in which case this should be deferred until we get to v.2.
I don't think we have a way of "deferring" issues; should this get a "fixed in riscof" tag?

@eroom1966
Copy link
Collaborator

I think the issue here is that the idiom adopted by Andrew Waterman was used early in the test development, so that the mtvec address is set to be the address of an instruction after the faulting address, in other words (pseudo code)

l1: some_instruction
l2: set mtvec = &l4
l3: faulting_instruction
l4: some_instruction

if the intention is to use a READONLY MTVEC, then a trap handler must be written and located at the fixed MTVEC address, this traphandler could read the EPC and perform a jump to EPC+2 (compressed) or EPC+4 (uncompressed) thus resuming execution at l4

I think it is a test issue, not a framework issue

Thx
Lee

@allenjbaum
Copy link
Collaborator

allenjbaum commented Apr 1, 2020 via email

@allenjbaum
Copy link
Collaborator

OK, the tests that have just merged have a standard trap handler that any test can use.
The prolog/setup sets mtvec to a trampoline in the handler that enables saving trap state.
If it is unable to set mtvec to that handler, it instead replaces whatever mtvec points to with the trampoline code.
Only if that fails does it give up & the test fails
A future version may allow implementors to point to a RWX area to place the trampoline table. So:

  • An implementation that has a fixed MTVEC that vectors to ROM will always fail
  • An implementation that has partially writable MTVEC that is initialized point to ROM when the initialization routine is entered will fail.
    Otherwise, it should work.

@allenjbaum
Copy link
Collaborator

Has this been retested with the updated RFQ tests?
If not, I suggest you reclone the entire riscv-arch-test (the new name for the old riscv-compliance repo) repo and try again
The new tests should save and overwrite the region that MTVEC points to with a trap vector table, and restore it after the test. Any traps will then get vectored to ther standard trap handler, save trap state, and return past the trap point.

@allenjbaum
Copy link
Collaborator

Seeing no comments, I believe this has been fixed in the latest version of the tests; that is, the tests that were failing because of mtvec alignment shouldn't be failing now. I am closing this, but please reopen if you see further failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants