Skip to content

Commit 3267bcc

Browse files
Updated test generators to not use MTIME if undefined
1 parent 0872070 commit 3267bcc

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

docs/ctp/src/rvmodel.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ The RVMODEL DUT-Specific Macros are given in <<t-rvmodel>>. The "Can Be Empty?"
4040
|RVMODEL_SET_SSW_INT(_R1, _R2)|Sets the Supervisor Software Interrupt `sip.SSIP` using a platform-specific interrupt controller, if supported. _R1 and _R2 are temporary registers that may be trashed by the macro.|If S-mode software interrupts are not tested. | Machine or Supervisor
4141
|RVMODEL_CLR_SSW_INT(_R1, _R2)|Clears the Supervisor Software Interrupt `sip.SSIP` by using a platform-specific interrupt controller, as applicable. _R1 and _R2 are temporary registers that may be trashed by the macro.|If S-mode software interrupts are not tested. | Machine or Supervisor
4242
|RVMODEL_ACCESS_FAULT_ADDRESS|The base physical address of a region of at least 128 bytes that causes an access fault when any part of the region is read or written. This is used to test exceptions.|Omit if DUT does not generate some/all access faults.| n/a
43-
|RVMODEL_MTIME_ADDRESS|The address of the memory-mapped `mtime` register, used for timer accesses and interrupts.|Omit if timer interrupts are not tested. | n/a
44-
|RVMODEL_MTIMECMP_ADDRESS|The address of the memory-mapped `mtimecmp` register, used for timer interrupts.| Omit if Machine timer interrupts are not tested. | n/a
43+
|RVMODEL_MTIME_ADDRESS|The address of the memory-mapped `mtime` register, used for timer accesses and interrupts.|Omit if machine timer interrupts are not tested. | n/a
44+
|RVMODEL_MTIMECMP_ADDRESS|The address of the memory-mapped `mtimecmp` register, used for timer interrupts.| Omit if machine timer interrupts are not tested. | n/a
4545
|RVMODEL_INTERRUPT_LATENCY|Expected latency (in cycles/NOPs) for interrupt trap processing. Ensures interrupt is received and can be processed before test continues.|Can be 0 if interrupt controller adds no delay. | n/a
4646
|RVMODEL_TIMER_INT_SOON_DELAY|The delay (in cycles) before a timer interrupt fires when using `set_mtimer_int_soon()`. Sets `mtimecmp = mtime + delay`. Should be long enough that the core can run a few instructions before the interrupt fires.| If Machine timer interrupts are not tested. | n/a
4747
|RVMODEL_DATA_SECTION|DUT-specific data that will be placed in a .data section. Used for memory-mapped regions like `tohost`/`fromhost`. |Yes, if not needed by DUT. | n/a

generators/testgen/src/testgen/asm/interrupts.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def set_mtimer_int(r_mtime: int, r_mtimecmp: int, r_temp: int, r_temp2: int) ->
2020
r_temp2: Second temp register number for RV32
2121
"""
2222
return [
23-
f"{INDENT}# Cause machine timer interrupt",
23+
f"{INDENT}# Cause machine timer interrupt if supported",
24+
"#ifdef RVMODEL_MTIME_ADDRESS",
2425
f"LA(x{r_mtime}, RVMODEL_MTIME_ADDRESS)",
2526
f"LA(x{r_mtimecmp}, RVMODEL_MTIMECMP_ADDRESS)",
2627
"#if __riscv_xlen == 64",
@@ -37,6 +38,7 @@ def set_mtimer_int(r_mtime: int, r_mtimecmp: int, r_temp: int, r_temp2: int) ->
3738
f"sw x{r_temp2}, 4(x{r_mtimecmp}) # Step 2: Write high word (no smaller than new)",
3839
f"sw x{r_temp}, 0(x{r_mtimecmp}) # Step 3: Write low word (new value)",
3940
"#endif",
41+
"#endif",
4042
]
4143

4244

@@ -72,7 +74,8 @@ def set_mtimer_int_soon(
7274
r_temp1, r_temp2, r_temp3, r_temp4: Temp registers for calculations
7375
"""
7476
return [
75-
f"{INDENT}# Cause machine timer interrupt soon",
77+
f"{INDENT}# Cause machine timer interrupt soon if supported",
78+
"#ifdef RVMODEL_MTIME_ADDRESS",
7679
f"LA(x{r_mtime}, RVMODEL_MTIME_ADDRESS)",
7780
f"LA(x{r_mtimecmp}, RVMODEL_MTIMECMP_ADDRESS)",
7881
"#if __riscv_xlen == 64",
@@ -99,6 +102,7 @@ def set_mtimer_int_soon(
99102
f"sw x{r_temp2}, 4(x{r_mtimecmp})", # Write high word
100103
f"sw x{r_temp3}, 0(x{r_mtimecmp})", # Write low word (final value)
101104
"#endif",
105+
"#endif",
102106
]
103107

104108

@@ -122,7 +126,7 @@ def set_stimer_int(r_mtime: int, r_temp: int, r_temp2: int, r_scratch: int) -> l
122126
f"BEQZ x{r_scratch}, 1f # If STCE=0, use non sstc method",
123127
"",
124128
f"{INDENT}# Sstc method: Write stimecmp",
125-
f"LA(x{r_mtime}, RVMODEL_MTIME_ADDRESS)",
129+
f"LA(x{r_mtime}, RVMODEL_MTIME_ADDRESS) # NOTE: This will need to be replaced by a SBI call because MTIME might not exist or be accessible",
126130
f"LREG x{r_temp}, 0(x{r_mtime})",
127131
f"csrw stimecmp, x{r_temp}",
128132
"nop",
@@ -188,7 +192,7 @@ def set_stimer_int_soon_sstc(r_mtime: int, r_temp1: int, r_temp2: int, r_temp3:
188192
"""
189193
return [
190194
f"{INDENT}# Set supervisor timer interrupt to fire soon with Sstc extension",
191-
f"LA(x{r_mtime}, RVMODEL_MTIME_ADDRESS)",
195+
f"LA(x{r_mtime}, RVMODEL_MTIME_ADDRESS) # NOTE: This will need to be replaced by a SBI call because MTIME might not exist or be accessible",
192196
"#if __riscv_xlen == 64",
193197
f"{INDENT}# Disable comparator first",
194198
f"LI(x{r_temp1}, -1)",

generators/testgen/src/testgen/priv/extensions/Sm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,11 +796,12 @@ def _generate_mcsr_cntr_tests(test_data: TestData) -> list[str]:
796796
lines.append(
797797
comment_banner(
798798
coverpoint,
799-
"Write mtime and read back time",
799+
"Write mtime and read back time if supported",
800800
),
801801
)
802802
lines.extend(
803803
[
804+
"#ifdef RVMODEL_MTIME_ADDRESS",
804805
f"LI(x{r1}, 42) # value to write to mtime",
805806
f"LA(x{r2}, RVMODEL_MTIME_ADDRESS) # load address of mtime",
806807
f"SREG x{r1}, 0(x{r2}) # write mtime = 42 using memory-mapped I/O",
@@ -819,6 +820,7 @@ def _generate_mcsr_cntr_tests(test_data: TestData) -> list[str]:
819820
f"sub x{r2}, x{r2}, x{r1} # difference should be zero",
820821
write_sigupd(r2, test_data),
821822
"#endif",
823+
"#endif",
822824
]
823825
)
824826

tests/env/check_defines.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@
4646
#endif
4747

4848
##### MTIME #####
49-
#ifndef RVMODEL_MTIME_ADDRESS
50-
#error "RVMODEL_MTIME_ADDRESS not defined. Make sure to define it in rvmodel_macros.h."
51-
#endif
52-
53-
#ifndef RVMODEL_MTIMECMP_ADDRESS
54-
#error "RVMODEL_MTIMECMP_ADDRESS not defined. Make sure to define it in rvmodel_macros.h."
49+
# If RVMODEL_MTIME_ADDRESS is not defined, no machine timer interrupts are tested
50+
51+
#ifdef RVMODEL_MTIME_ADDRESS
52+
# If RVMODEL_MTIME_ADDRESS is defined, these other MTIME-related macros must also be defined
53+
# because the tests will need them to cause timer interrupts and test timer functionality.
54+
# If these macros are not defined, the tests will fail to assemble due to the checks below.
55+
#ifndef RVMODEL_MTIMECMP_ADDRESS
56+
#error "RVMODEL_MTIMECMP_ADDRESS not defined. Make sure to define it in rvmodel_macros.h."
57+
#endif
5558
#endif
5659

5760
##### Interrupt Delays #####

0 commit comments

Comments
 (0)