Skip to content

Commit a176b65

Browse files
authored
Merge pull request #514 from lz-bro/timer_configurable
Make CLINT address configurable
2 parents 7453fe9 + 4dfd2e7 commit a176b65

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

debug/gdbserver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def early_applicable(self):
912912
def test(self):
913913
self.gdb.b("main:start")
914914
self.gdb.c()
915-
mtime_addr = 0x02000000 + 0xbff8
915+
mtime_addr = self.target.clint_addr + 0xbff8
916916
count = 1024
917917
output = self.gdb.command(
918918
f"monitor riscv repeat_read {count} 0x{mtime_addr:x} 4")
@@ -1048,8 +1048,8 @@ def test(self):
10481048

10491049
def postMortem(self):
10501050
GdbSingleHartTest.postMortem(self)
1051-
self.gdb.p("*((long long*) 0x200bff8)")
1052-
self.gdb.p("*((long long*) 0x2004000)")
1051+
self.gdb.p(f"*((long long*) 0x{self.target.clint_addr + 0xbff8:x})")
1052+
self.gdb.p(f"*((long long*) 0x{self.target.clint_addr + 0x4000:x})")
10531053
self.gdb.p("interrupt_count")
10541054
self.gdb.p("local")
10551055

debug/programs/init.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#ifndef INIT_H
22
#define INIT_H
33

4-
#define MTIME (*(volatile long long *)(0x02000000 + 0xbff8))
5-
#define MTIMECMP ((volatile long long *)(0x02000000 + 0x4000))
4+
#ifdef CLINT
5+
#define MTIME (*(volatile long long *)(CLINT + 0xbff8))
6+
#define MTIMECMP ((volatile long long *)(CLINT + 0x4000))
7+
#endif
68

79
typedef void* (*trap_handler_t)(unsigned hartid, unsigned mcause, void *mepc,
810
void *sp);

debug/programs/run_halt_timing.S

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
# define LREG lw
77
# define SREG sw
88
# define REGBYTES 4
9+
#endif
10+
11+
#ifdef CLINT
12+
#define MTIME_ADDR CLINT + 0xbff8
913
#endif
1014

1115
.global main
1216
main:
1317
li s0, 0
14-
li s1, 0x0200bff8
18+
li s1, MTIME_ADDR
1519
loop:
1620
addi s0, s0, 1
1721
LREG s2, 0(s1)

debug/targets.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ class Target:
9393
# before starting the test.
9494
gdb_setup = []
9595

96-
# Supports mtime at 0x2004000
96+
# Supports mtime default at clint_addr + 0x4000
9797
supports_clint_mtime = True
9898

99+
# CLINT register address, set to the default value of spike.
100+
clint_addr = 0x02000000
101+
99102
# Implements custom debug registers like spike does. It seems unlikely any
100103
# hardware will every do that.
101104
implements_custom_test = False
@@ -189,6 +192,7 @@ def do_compile(self, hart, *sources):
189192
Target.temporary_files.append(self.temporary_binary)
190193

191194
args = list(sources) + [
195+
f"-DCLINT={self.clint_addr}",
192196
"programs/entry.S", "programs/init.c",
193197
f"-DNHARTS={len(self.harts)}",
194198
"-I", "../env",

0 commit comments

Comments
 (0)