12 temporary_binary
= None
17 def __init__(self
, cmd
, run
, isolate
):
20 self
.isolate
= isolate
23 """Start the target, eg. a simulator."""
27 """Start the debug server that gdb connects to, eg. OpenOCD."""
28 if self
.openocd_config
:
29 return testlib
.Openocd(cmd
=self
.cmd
, config
=self
.openocd_config
)
31 raise NotImplementedError
33 def compile(self
, *sources
):
34 binary_name
= "%s_%s-%d" % (
36 os
.path
.basename(os
.path
.splitext(sources
[0])[0]),
39 self
.temporary_binary
= tempfile
.NamedTemporaryFile(
40 prefix
=binary_name
+ "_")
41 binary_name
= self
.temporary_binary
.name
42 Target
.temporary_files
.append(self
.temporary_binary
)
43 march
= "rv%dima" % self
.xlen
46 if self
.extensionSupported("c"):
48 testlib
.compile(sources
+
49 ("programs/entry.S", "programs/init.c",
52 "-T", "targets/%s/link.lds" % (self
.directory
or self
.name
),
55 "-DXLEN=%d" % self
.xlen
,
60 def extensionSupported(self
, letter
):
61 # target.misa is set by testlib.ExamineTarget
62 return self
.misa
& (1 << (ord(letter
.upper()) - ord('A')))
64 class SpikeTarget(Target
):
65 # pylint: disable=abstract-method
68 ram_size
= 5 * 1024 * 1024
69 instruction_hardware_breakpoint_count
= 4
72 class Spike64Target(SpikeTarget
):
78 return testlib
.Spike(self
.cmd
, halted
=True)
80 class Spike32Target(SpikeTarget
):
85 return testlib
.Spike(self
.cmd
, halted
=True, xlen
=32)
87 class FreedomE300Target(Target
):
92 instruction_hardware_breakpoint_count
= 2
93 openocd_config
= "targets/%s/openocd.cfg" % name
95 class HiFive1Target(FreedomE300Target
):
97 openocd_config
= "targets/%s/openocd.cfg" % name
99 class FreedomE300SimTarget(Target
):
100 name
= "freedom-e300-sim"
104 ram_size
= 256 * 1024 * 1024
105 instruction_hardware_breakpoint_count
= 2
106 openocd_config
= "targets/%s/openocd.cfg" % name
109 return testlib
.VcsSim(simv
=self
.run
, debug
=False)
111 class FreedomU500Target(Target
):
112 name
= "freedom-u500"
116 instruction_hardware_breakpoint_count
= 2
117 openocd_config
= "targets/%s/openocd.cfg" % name
119 class FreedomU500SimTarget(Target
):
120 name
= "freedom-u500-sim"
124 ram_size
= 256 * 1024 * 1024
125 instruction_hardware_breakpoint_count
= 2
126 openocd_config
= "targets/%s/openocd.cfg" % name
129 return testlib
.VcsSim(simv
=self
.run
, debug
=False)
136 FreedomE300SimTarget
,
137 FreedomU500SimTarget
,
140 def add_target_options(parser
):
141 group
= parser
.add_mutually_exclusive_group(required
=True)
143 group
.add_argument("--%s" % t
.name
, action
="store_const", const
=t
,
145 parser
.add_argument("--run",
146 help="The command to use to start the actual target (e.g. "
148 parser
.add_argument("--cmd",
149 help="The command to use to start the debug server.")
151 xlen_group
= parser
.add_mutually_exclusive_group()
152 xlen_group
.add_argument("--32", action
="store_const", const
=32, dest
="xlen",
153 help="Force the target to be 32-bit.")
154 xlen_group
.add_argument("--64", action
="store_const", const
=64, dest
="xlen",
155 help="Force the target to be 64-bit.")
157 parser
.add_argument("--isolate", action
="store_true",
158 help="Try to run in such a way that multiple instances can run at "
159 "the same time. This may make it harder to debug a failure if it "