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

Draft : Added test cases for load address match trigger in sdtrig extension #487

Open
wants to merge 27 commits into
base: dev
Choose a base branch
from

Conversation

anuani21
Copy link
Contributor

@anuani21 anuani21 commented Sep 3, 2024

Description

-  Handwritten test cases for mcontrol6 trigger using tcontrol register.
-  Test cases for mcontrol6 address  match trigger for load operation with different set of match values(0,1,2,3,4,5).  

Related Issues

NA

Ratified/Unratified Extensions

  • Unratified

List Extensions

  • Sdtrig

Reference Model Used

  • Spike

Mandatory Checklist:

Ran reports are placed here

https://gitlab.com/ptprasanna/actreports/-/tree/main/Sdtrig/RV32/Load_Address_match_trigger?ref_type=heads

Copy link

@rtwfroody rtwfroody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never written anything for this framework, so some of my comments might stem from lack of understanding. Is there a document that shows how test cases should adapt to different hardware configurations?

Comment on lines 17 to 22
csrr t1, mstatus # Read current mstatus
li t0, ~(3 << 11) # Create mask to clear mpp bits (bits 11 and 12)
and t1, t1, t0 # Clear the mpp bits
li t0, (3 << 11) # Prepare value to set mpp to 3 (Machine Mode)
or t1, t1, t0 # Set the mpp bits to 3
csrw mstatus, t1 # Write back modified mstatus

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to set MPP? I don't think this test ever returns from an interrupt handler. Or does one of the macros do that?

Comment on lines 31 to 33
# Not in Machine mode, handle accordingly (e.g., trap, ecall, etc.)
li a0, 1 # Example action if not in Machine mode
ret

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the expected behavior of these tests when they don't execute in M-Mode? Is there some documentation on the arch tests that talks about this? It seems reasonable to me to not run this test if you don't get to use M-Mode, but if that's an intentional choice the comment should reflect that.

setup_trap:
la a0, trap_handler
csrw mtvec, a0
csrr t1, mtvec

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why read this back?

Comment on lines 42 to 43
li t3,0
csrw tselect,t3

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
li t3,0
csrw tselect,t3
csrw tselect, zero

Comment on lines 47 to 49
# Read tinfo and append it to the signature
csrr t6, tinfo
RVTEST_SIGUPD(x1, t6)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make the test fail if the DUT and reference don't implement the identical set of trigger types for this trigger. That might make this test break under conditions that have little to do with mcontrol6 load triggers.

Comment on lines 51 to 54
li a1, (CSR_TCONTROL_MTE_ENABLED << 3)
csrw tcontrol, a1
csrr a2,tcontrol
RVTEST_SIGUPD(x1,a2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tcontrol isn't required to be implemented.

There are several possible solutions to this, but just assuming it is implemented doesn't seem right.

Comment on lines 67 to 77
csrw tdata1,t2
RVTEST_SIGUPD(x1,t2)
csrr a3,tdata1
RVTEST_SIGUPD(x1,a3)


# Set the value of tdata2 to the address to match
la t2, 0x80001234
csrw tdata2, t2
csrr t6,tdata2
RVTEST_SIGUPD(x1, t6)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Section 5.7 of the Debug Spec says:
As a result, a debugger can write any supported trigger as follows:

  1. Write 0 to tdata1. (This will result in containing a non-zero value, since the register is WARL.)
  2. Write desired values to tdata2 and tdata3.
  3. Write desired value to tdata1.

RVTEST_SIGUPD(x1, t6)

# Code that accesses the matched data value (this should trigger the break)
# Execute an instruction at the matching address

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comment apply here?

# Execute an instruction at the matching address
la t4,0x80001234
lw t4, 0(t4) # Load to trigger match (this should trigger the break)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This falls through to the trap handler if the trigger didn't fire. Not the end of the world because mepc will have the wrong value, but it's unusual. Deserves a comment at least.

@allenjbaum
Copy link
Collaborator

allenjbaum commented Sep 10, 2024 via email

li t1,(1<<3)
csrw mstatus, t1
csrr t4, mstatus
RVTEST_SIGUPD(x1, t4)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these tests test triggers, but not explicitly test native re-entrant issues, I think it's better not to add this to the signature. Then these tests can compare DUTs and references that have different ways of enabling triggers.

But I might be misunderstanding the philosophy behind these tests.


# Read tinfo and append it to the signature
csrr t6, tinfo
RVTEST_SIGUPD(x1, t6)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For similar reasons, do we want tinfo in the signature? I think we only care that the specific trigger type being tested is supported.


csrw tdata1, zero
csrr a3, tdata1
RVTEST_SIGUPD(x1, a3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another one. The spec only requires that the trigger is now disabled, but there are many encodings that could represent a disabled register.

Comment on lines 103 to 112
RVTEST_DATA_BEGIN
.align 12
page_4k:
.fill 4096/REGWIDTH, REGWIDTH, 0
RVTEST_DATA_END

.align 12
rvtest_Sroot_pg_tbl:
.fill 4096/REGWIDTH, REGWIDTH, 0
.section .data

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need these?

Comment on lines 123 to 131
#ifdef rvtest_mtrap_routine
mtrap_sigptr:
.fill 128*4, 4, 0xdeadbeef
#endif

#ifdef rvtest_gpr_save
gpr_save:
.fill 32*(XLEN/32), 4, 0xdeadbeef
#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can also delete these.

anuani21 and others added 21 commits October 4, 2024 14:20
Signed-off-by: anuani21 <[email protected]>
Copy link

@rtwfroody rtwfroody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how the GT/LT execute tests work. You're using 0x80001234 for the compare value for both. But the code that sets the breakpoints must be either before or after that address. Wouldn't one of these two scenarios fire before tdata1/tdata2 are added to the signature?

Also, there's a lot of repeated code here. Refactoring things so there's a single macro/function that just takes the desired tdata1 and tdata2 values would make each test tiny (call the function to set up, then execute whatever code to test triggering/not triggering).

Comment on lines +47 to +49
# Read tinfo
csrr t6, tinfo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this isn't used anywhere.

csrr a3, tdata1

# Set the address for tdata2 where the trigger should occur
la t2, 0x80008000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this matches when executing an instruction where bit 15 of the address is set. I don't think you're guaranteed what address this program is placed at. Probably you need to not use a fixed address for your test here, but instead pick an address in your code.

E.g. (untested)

la t2, break_here
li t3, 0xffff
and t4, t2, t3
li t3, 0xffff0000
or t4, t3, t4
csrw tdata2, t4
...
j before_break
...
before_break: nop
break_here: nop

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 this pull request may close these issues.

3 participants