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

I-MISALIGN_JMP-01.S outdated use of mbadaddr in trap handler? #31

Closed
debs-sifive opened this issue Jan 25, 2019 · 7 comments · Fixed by #101
Closed

I-MISALIGN_JMP-01.S outdated use of mbadaddr in trap handler? #31

debs-sifive opened this issue Jan 25, 2019 · 7 comments · Fixed by #101

Comments

@debs-sifive
Copy link
Contributor

From line 280, the beginning of the trap handler has:

_trap_handler:
    # increment return address
    csrr    x30, mbadaddr
    addi    x30, x30, -2
    csrw    mepc, x30

The privileged spec states, "The mtval register replaces the mbadaddr register in the previous specification."

It also states, "When a hardware breakpoint is triggered, or an instruction-fetch, load, or store address-misaligned, access, or page-fault exception occurs, mtval is written with the faulting e�ffective address... For other exceptions, mtval is set to zero..."

So within the trap handler, mtval is used in place of mbadaddr, but the behavior of the two do not match up, since the spec does not actually define mtval behavior during misaligned jumps.

What I'm seeing is mtvec (i.e. mbadaddr in the test) being set to 0x0 as the spec says, so then mepc gets set to some large invalid address, which causes mret to return back into the trap handler, and then gets stuck in a loop.

@neelgala
Copy link
Collaborator

Agreed that mtval should replace mbadaddr not only here but in all other tests as well.
Will probably raise a pull-request for the same soon. Thanks for the catch.

I think the problem here is how you have interpreted the spec. I would interpret the following
... or an instruction-fetch, load, or store address-misaligned, access, or page-fault exception occurs, mtval is written with the faulting effective address ... as:

instruction-fetch-misaligned, load-address-misaligned, store-address-misaligned,
instruction-fetch-access, load-address-access, store-address-access,
instruction-fetch-pagefault, load-address-pagefault and store-address-pagefault exceptions.

Also there is no exception defined as: instruction-fetch-exception.

In which case a jal/jalr instruction which causes an instruction-fetch-misaligned exception should update mtval with the corresponding instruction-fetch-address.

Also you can find the same behaviour in spike and riscvOPVSim and also quite a few other implementations.

@debs-sifive
Copy link
Contributor Author

Ah, that makes more sense! Thanks for your help!

@debs-sifive
Copy link
Contributor Author

I missed this earlier, but in the paragraph above, the spec states:

"When a trap is taken into M-mode, mtval is either set to zero or written with exception-specific information to assist software in handling the trap. Otherwise, mtval is never written by the implementation, though it may be explicitly written by software. The hardware platform will specify which exceptions must set mtval informatively and which may unconditionally set it to zero."

So the behavior desired by the test isn't actually required by spec. This seems like it would render several tests that use mtval less useful for some targets. Thoughts?

@debs-sifive debs-sifive reopened this Jan 28, 2019
@aswaterman
Copy link

I think the ISA-compliance tests should be revised to permit either zero or the expected nonzero value. These tests will still be useful. Implementations will choose to write the expected nonzero value for exceptions that are meant to be resumable, and we still want to test that they produce the right value if they do produce a value.

Platform-compliance tests should be responsible for checking whether mtval is populated with nonzero values for the exceptions that platform cares about (e.g., misaligned ld/st on platforms that emulate those operations; all page-fault exceptions on platforms that use virtual memory).

@allenjbaum
Copy link
Collaborator

allenjbaum commented Jan 28, 2019 via email

@debs-sifive debs-sifive mentioned this issue Jan 29, 2019
5 tasks
@allenjbaum
Copy link
Collaborator

Note that the riscof framework will handle this correctly by dreclaring that MTVAL is unimplemented in the DUT YAML configuration file. The reference model will need to allow that kind of configuration (and many, many others) as well.

@allenjbaum
Copy link
Collaborator

So, I am unclear: is it possible to modify the test so it works for both MTVAL implemented or not?
I thought the current v.1 framework only allows a single assertion, which make it unfixable in v.1

@neelgala neelgala mentioned this issue Mar 19, 2020
neelgala added a commit that referenced this issue Mar 25, 2020
Changes in this pull-request:

    * restructuring the riscv-test-suite to indicate clearly what is deprecated, wip and usable
      tests.
    * based on the above fixed the directory structure for riscv-targets where-ever applicable. Only
      tested riscvOVPsim and spike.
    * fixed script bugs for spike as well
    * renamed rv32i/I-IO.S to rv32i/I-IO-01.S along with necessary changes to the reference files
      and Makefrag
    * renamed mbadaddr csr to mtval as raised in issue #31
    * C.SWSP-01.S test updated to fix issue #37

Close: #8 , #31 , #30 , #32 , #33 , #37, #47 , #67 , #96
pawks pushed a commit to pawks/riscv-arch-test that referenced this issue Nov 10, 2022
Changes in this pull-request:

    * restructuring the riscv-test-suite to indicate clearly what is deprecated, wip and usable
      tests.
    * based on the above fixed the directory structure for riscv-targets where-ever applicable. Only
      tested riscvOVPsim and spike.
    * fixed script bugs for spike as well
    * renamed rv32i/I-IO.S to rv32i/I-IO-01.S along with necessary changes to the reference files
      and Makefrag
    * renamed mbadaddr csr to mtval as raised in issue riscv-non-isa#31
    * C.SWSP-01.S test updated to fix issue riscv-non-isa#37

Close: riscv-non-isa#8 , riscv-non-isa#31 , riscv-non-isa#30 , riscv-non-isa#32 , riscv-non-isa#33 , riscv-non-isa#37, riscv-non-isa#47 , riscv-non-isa#67 , riscv-non-isa#96
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

Successfully merging a pull request may close this issue.

4 participants