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

CLIC or vectored mode leads to misaligned load #285

Closed
marcfedorow opened this issue Sep 20, 2022 · 6 comments
Closed

CLIC or vectored mode leads to misaligned load #285

marcfedorow opened this issue Sep 20, 2022 · 6 comments

Comments

@marcfedorow
Copy link
Contributor

This line

lw t6, 0(t2) // get original mtvec target

suggests that mtvec (thus t2) contains a correct address.
This is not always true, e.g. if MODE (MTVEC[1:0]) == 3 (CLIC).
andi t2, t2, -4 should be added before this line.

marcfedorow pushed a commit to marcfedorow/riscv-arch-test that referenced this issue Oct 30, 2022
marcfedorow added a commit to marcfedorow/riscv-arch-test that referenced this issue Oct 30, 2022
@allenjbaum
Copy link
Collaborator

This should be closed when new trap handler is merged

@pawks
Copy link
Collaborator

pawks commented Feb 9, 2023

Closing this as PR #277 has addressed this issue. Reopen if problem persists.

@pawks pawks closed this as completed Feb 9, 2023
@marcfedorow
Copy link
Contributor Author

marcfedorow commented May 17, 2023

This obviously does not work.
https://github.com/riscv-non-isa/riscv-arch-test/blob/main/riscv-test-suite/env/arch_test.h#L1018
Here MCAUSE is checked to be in range [8, 11], which is not true if CLIC is enabled.

@allenjbaum
Copy link
Collaborator

allenjbaum commented May 18, 2023 via email

@marcfedorow
Copy link
Contributor Author

Is specifically checking for exception codes 8..11.

Let us say that the exception code is 0xb (ecall), XLEN=32, CLIC is enabled

  csrr t5, CSR_XCAUSE // t5 contains 0x3000000b
  addi t4, t5, -8     // t4 contains 0x30000003
  andi t4, t4, -4     // t4 contains 0x30000000
  bnez t4, ...        // jump will be performed
                      // t5 still contains 0x3000000b

I've patched it via

diff --git a/riscv-test-suite/env/arch_test.h b/riscv-test-suite/env/arch_test.h
index aaaaaaa..bbbbbbb 100644
--- a/riscv-test-suite/env/arch_test.h
+++ b/riscv-test-suite/env/arch_test.h
@@ -1013,6 +1013,8 @@ common_\__MODE__\()entry:
 //spcl case handling for ECALL in GOTO_MMODE mode,)  ****tests can't use ECALL t2=0****
 spcl_\__MODE__\()2mmode_test:
         csrr    t5, CSR_XCAUSE
+        li      t4, ~0x7fff0000                 // bits reserved for mpp, mpie, etc
+        and     t5, t5, t4                      // clear such bits
         addi    t4, t5, -8                      // is cause 8..11? Mmode should avoid ECALL 0
         andi    t4, t4, -4                      // NOTE: cause 10 is RSVD.  Sail will diverge, but buggy anyway  
         bnez    t4, \__MODE__\()trapsig_ptr_upd // no, not in special mode, just continue
@@ -1068,6 +1070,7 @@ rvtest_\__MODE__\()endtest:                     // target may be too far away, s
 //------end atomic------------------------------------------------
 
         LREG    t3, xtvec_new_off(sp)           // get pointer to actual tramp table
+        andi    t3, t3, -4                      // clear CLIC-related bits
 //----------------------------------------------------------------
 
   /*************************************************************************/

, because it is simple and it works. Of course this does not test if CLIC is enabled (which can not be checked via isa-string) or even implemented.

I'm good with what I've done, but if one needs to run arch-tests with CLIC enabled, this should be adressed.

@allenjbaum
Copy link
Collaborator

allenjbaum commented May 19, 2023 via email

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.

3 participants