9 # XLEN of the hart. May be overridden with --32 or --64 command line
13 # Will be autodetected (by running ExamineTarget) if left unset. Set to
17 # Path to linker script relative to the .py file where the target is
18 # defined. Defaults to <name>.lds.
19 link_script_path
= None
21 # Implements dmode in tdata1 as described in the spec. Harts that need
22 # this value set to False are not compliant with the spec (but still usable
23 # as long as running code doesn't try to mess with triggers set by an
25 honors_tdata1_hmode
= True
27 # Address where a r/w/x block of RAM starts, together with its size.
31 # Number of instruction triggers the hart supports.
32 instruction_hardware_breakpoint_count
= 0
34 # Defaults to target-<index>
37 def extensionSupported(self
, letter
):
38 # target.misa is set by testlib.ExamineTarget
40 return self
.misa
& (1 << (ord(letter
.upper()) - ord('A')))
45 # pylint: disable=too-many-instance-attributes
47 # List of Hart object instances, one for each hart in the target.
50 # Name of the target. Defaults to the name of the class.
53 # GDB remotetimeout setting.
56 # Timeout waiting for the server to start up. This is different than the
57 # GDB timeout, which is how long GDB waits for commands to execute.
58 # The server_timeout is how long this script waits for the Server to be
59 # ready for GDB connections.
60 server_timeout_sec
= 60
62 # Path to OpenOCD configuration file relative to the .py file where the
63 # target is defined. Defaults to <name>.cfg.
64 openocd_config_path
= None
66 # List of commands that should be executed in gdb after connecting but
67 # before starting the test.
70 # Supports mtime at 0x2004000
71 supports_clint_mtime
= True
77 def __init__(self
, path
, parsed
):
80 self
.directory
= os
.path
.dirname(path
)
81 self
.server_cmd
= parsed
.server_cmd
82 self
.sim_cmd
= parsed
.sim_cmd
83 self
.temporary_binary
= None
84 Target
.isolate
= parsed
.isolate
86 self
.name
= type(self
).__name
__
87 # Default OpenOCD config file to <name>.cfg
88 if not self
.openocd_config_path
:
89 self
.openocd_config_path
= "%s.cfg" % self
.name
90 self
.openocd_config_path
= os
.path
.join(self
.directory
,
91 self
.openocd_config_path
)
92 for i
, hart
in enumerate(self
.harts
):
95 hart
.name
= "%s-%d" % (self
.name
, i
)
96 # Default link script to <name>.lds
97 if not hart
.link_script_path
:
98 hart
.link_script_path
= "%s.lds" % self
.name
99 hart
.link_script_path
= os
.path
.join(self
.directory
,
100 hart
.link_script_path
)
103 """Create the target out of thin air, eg. start a simulator."""
107 """Start the debug server that gdb connects to, eg. OpenOCD."""
108 return testlib
.Openocd(server_cmd
=self
.server_cmd
,
109 config
=self
.openocd_config_path
)
111 def compile(self
, hart
, *sources
):
112 binary_name
= "%s_%s-%d" % (
114 os
.path
.basename(os
.path
.splitext(sources
[0])[0]),
117 self
.temporary_binary
= tempfile
.NamedTemporaryFile(
118 prefix
=binary_name
+ "_")
119 binary_name
= self
.temporary_binary
.name
120 Target
.temporary_files
.append(self
.temporary_binary
)
121 march
= "rv%dima" % hart
.xlen
123 if hart
.extensionSupported(letter
):
125 testlib
.compile(sources
+
126 ("programs/entry.S", "programs/init.c",
127 "-DNHARTS=%d" % len(self
.harts
),
130 "-T", hart
.link_script_path
,
133 "-DXLEN=%d" % hart
.xlen
,
138 def add_target_options(parser
):
139 parser
.add_argument("target", help=".py file that contains definition for "
140 "the target to test with.")
141 parser
.add_argument("--sim_cmd",
142 help="The command to use to start the actual target (e.g. "
143 "simulation)", default
="spike")
144 parser
.add_argument("--server_cmd",
145 help="The command to use to start the debug server (e.g. OpenOCD)")
147 xlen_group
= parser
.add_mutually_exclusive_group()
148 xlen_group
.add_argument("--32", action
="store_const", const
=32, dest
="xlen",
149 help="Force the target to be 32-bit.")
150 xlen_group
.add_argument("--64", action
="store_const", const
=64, dest
="xlen",
151 help="Force the target to be 64-bit.")
153 parser
.add_argument("--isolate", action
="store_true",
154 help="Try to run in such a way that multiple instances can run at "
155 "the same time. This may make it harder to debug a failure if it "
159 directory
= os
.path
.dirname(parsed
.target
)
160 filename
= os
.path
.basename(parsed
.target
)
161 module_name
= os
.path
.splitext(filename
)[0]
163 sys
.path
.append(directory
)
164 module
= importlib
.import_module(module_name
)
166 for name
in dir(module
):
167 definition
= getattr(module
, name
)
168 if type(definition
) == type and issubclass(definition
, Target
):
169 found
.append(definition
)
170 assert len(found
) == 1, "%s does not define exactly one subclass of " \
171 "targets.Target" % parsed
.target
173 t
= found
[0](parsed
.target
, parsed
)
174 assert t
.harts
, "%s doesn't have any harts defined!" % t
.name