12 temporary_binary
= None
16 def __init__(self
, cmd
, run
, isolate
):
19 self
.isolate
= isolate
22 """Start the target, eg. a simulator."""
26 """Start the debug server that gdb connects to, eg. OpenOCD."""
27 if self
.openocd_config
:
28 return testlib
.Openocd(cmd
=self
.cmd
, config
=self
.openocd_config
)
30 raise NotImplementedError
32 def compile(self
, *sources
):
33 binary_name
= "%s_%s-%d" % (
35 os
.path
.basename(os
.path
.splitext(sources
[0])[0]),
38 self
.temporary_binary
= tempfile
.NamedTemporaryFile(
39 prefix
=binary_name
+ "_")
40 binary_name
= self
.temporary_binary
.name
41 Target
.temporary_files
.append(self
.temporary_binary
)
42 march
= "RV%dIMA" % self
.xlen
45 testlib
.compile(sources
+
46 ("programs/entry.S", "programs/init.c",
49 "-T", "targets/%s/link.lds" % (self
.directory
or self
.name
),
52 "-DXLEN=%d" % self
.xlen
,
57 class SpikeTarget(Target
):
58 # pylint: disable=abstract-method
61 ram_size
= 5 * 1024 * 1024
62 instruction_hardware_breakpoint_count
= 4
65 class Spike64Target(SpikeTarget
):
71 return testlib
.Spike(self
.cmd
, halted
=True)
73 class Spike32Target(SpikeTarget
):
78 return testlib
.Spike(self
.cmd
, halted
=True, xlen
=32)
80 class FreedomE300Target(Target
):
85 instruction_hardware_breakpoint_count
= 2
86 openocd_config
= "targets/%s/openocd.cfg" % name
88 class FreedomE300SimTarget(Target
):
89 name
= "freedom-e300-sim"
93 ram_size
= 256 * 1024 * 1024
94 instruction_hardware_breakpoint_count
= 2
95 openocd_config
= "targets/%s/openocd.cfg" % name
98 return testlib
.VcsSim(simv
=self
.run
, debug
=False)
100 class FreedomU500Target(Target
):
101 name
= "freedom-u500"
105 instruction_hardware_breakpoint_count
= 2
106 openocd_config
= "targets/%s/openocd.cfg" % name
108 class FreedomU500SimTarget(Target
):
109 name
= "freedom-u500-sim"
113 ram_size
= 256 * 1024 * 1024
114 instruction_hardware_breakpoint_count
= 2
115 openocd_config
= "targets/%s/openocd.cfg" % name
118 return testlib
.VcsSim(simv
=self
.run
, debug
=False)
125 FreedomE300SimTarget
,
126 FreedomU500SimTarget
]
128 def add_target_options(parser
):
129 group
= parser
.add_mutually_exclusive_group(required
=True)
131 group
.add_argument("--%s" % t
.name
, action
="store_const", const
=t
,
133 parser
.add_argument("--run",
134 help="The command to use to start the actual target (e.g. "
136 parser
.add_argument("--cmd",
137 help="The command to use to start the debug server.")
139 xlen_group
= parser
.add_mutually_exclusive_group()
140 xlen_group
.add_argument("--32", action
="store_const", const
=32, dest
="xlen",
141 help="Force the target to be 32-bit.")
142 xlen_group
.add_argument("--64", action
="store_const", const
=64, dest
="xlen",
143 help="Force the target to be 64-bit.")
145 parser
.add_argument("--isolate", action
="store_true",
146 help="Try to run in such a way that multiple instances can run at "
147 "the same time. This may make it harder to debug a failure if it "