12 temporary_binary
= None
15 def __init__(self
, cmd
, run
, isolate
):
18 self
.isolate
= isolate
21 """Start the target, eg. a simulator."""
25 """Start the debug server that gdb connects to, eg. OpenOCD."""
26 if self
.openocd_config
:
27 return testlib
.Openocd(cmd
=self
.cmd
, config
=self
.openocd_config
)
29 raise NotImplementedError
31 def compile(self
, *sources
):
32 binary_name
= "%s_%s-%d" % (
34 os
.path
.basename(os
.path
.splitext(sources
[0])[0]),
37 self
.temporary_binary
= tempfile
.NamedTemporaryFile(
38 prefix
=binary_name
+ "_")
39 binary_name
= self
.temporary_binary
.name
40 Target
.temporary_files
.append(self
.temporary_binary
)
41 testlib
.compile(sources
+
42 ("programs/entry.S", "programs/init.c",
44 "-march=RV%dIMAFD" % self
.xlen
,
45 "-T", "targets/%s/link.lds" % (self
.directory
or self
.name
),
52 class SpikeTarget(Target
):
53 # pylint: disable=abstract-method
56 ram_size
= 5 * 1024 * 1024
57 instruction_hardware_breakpoint_count
= 4
60 class Spike64Target(SpikeTarget
):
65 return testlib
.Spike(self
.cmd
, halted
=True)
67 class Spike32Target(SpikeTarget
):
72 return testlib
.Spike(self
.cmd
, halted
=True, xlen
=32)
74 class FreedomE300Target(Target
):
79 instruction_hardware_breakpoint_count
= 2
80 openocd_config
= "targets/%s/openocd.cfg" % name
82 class FreedomE300SimTarget(Target
):
83 name
= "freedom-e300-sim"
87 ram_size
= 256 * 1024 * 1024
88 instruction_hardware_breakpoint_count
= 2
89 openocd_config
= "targets/%s/openocd.cfg" % name
92 return testlib
.VcsSim(simv
=self
.run
, debug
=False)
94 class FreedomU500Target(Target
):
99 instruction_hardware_breakpoint_count
= 2
100 openocd_config
= "targets/%s/openocd.cfg" % name
102 class FreedomU500SimTarget(Target
):
103 name
= "freedom-u500-sim"
107 ram_size
= 256 * 1024 * 1024
108 instruction_hardware_breakpoint_count
= 2
109 openocd_config
= "targets/%s/openocd.cfg" % name
112 return testlib
.VcsSim(simv
=self
.run
, debug
=False)
119 FreedomE300SimTarget
,
120 FreedomU500SimTarget
]
122 def add_target_options(parser
):
123 group
= parser
.add_mutually_exclusive_group(required
=True)
125 group
.add_argument("--%s" % t
.name
, action
="store_const", const
=t
,
127 parser
.add_argument("--run",
128 help="The command to use to start the actual target (e.g. "
130 parser
.add_argument("--cmd",
131 help="The command to use to start the debug server.")
133 xlen_group
= parser
.add_mutually_exclusive_group()
134 xlen_group
.add_argument("--32", action
="store_const", const
=32, dest
="xlen",
135 help="Force the target to be 32-bit.")
136 xlen_group
.add_argument("--64", action
="store_const", const
=64, dest
="xlen",
137 help="Force the target to be 64-bit.")
139 parser
.add_argument("--isolate", action
="store_true",
140 help="Try to run in such a way that multiple instances can run at "
141 "the same time. This may make it harder to debug a failure if it "