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 FreedomE300SimTarget(Target
):
96 name
= "freedom-e300-sim"
100 ram_size
= 256 * 1024 * 1024
101 instruction_hardware_breakpoint_count
= 2
102 openocd_config
= "targets/%s/openocd.cfg" % name
105 return testlib
.VcsSim(simv
=self
.run
, debug
=False)
107 class FreedomU500Target(Target
):
108 name
= "freedom-u500"
112 instruction_hardware_breakpoint_count
= 2
113 openocd_config
= "targets/%s/openocd.cfg" % name
115 class FreedomU500SimTarget(Target
):
116 name
= "freedom-u500-sim"
120 ram_size
= 256 * 1024 * 1024
121 instruction_hardware_breakpoint_count
= 2
122 openocd_config
= "targets/%s/openocd.cfg" % name
125 return testlib
.VcsSim(simv
=self
.run
, debug
=False)
132 FreedomE300SimTarget
,
133 FreedomU500SimTarget
]
135 def add_target_options(parser
):
136 group
= parser
.add_mutually_exclusive_group(required
=True)
138 group
.add_argument("--%s" % t
.name
, action
="store_const", const
=t
,
140 parser
.add_argument("--run",
141 help="The command to use to start the actual target (e.g. "
143 parser
.add_argument("--cmd",
144 help="The command to use to start the debug server.")
146 xlen_group
= parser
.add_mutually_exclusive_group()
147 xlen_group
.add_argument("--32", action
="store_const", const
=32, dest
="xlen",
148 help="Force the target to be 32-bit.")
149 xlen_group
.add_argument("--64", action
="store_const", const
=64, dest
="xlen",
150 help="Force the target to be 64-bit.")
152 parser
.add_argument("--isolate", action
="store_true",
153 help="Try to run in such a way that multiple instances can run at "
154 "the same time. This may make it harder to debug a failure if it "