Use compressed code if the target supports it.
[riscv-tests.git] / debug / targets.py
index 538caaf41d6dadcc5b4f47770b7b3b33051c79a5..bcebc0b613ef83797a01fc4dc7d9d77370bf0223 100644 (file)
@@ -12,6 +12,7 @@ class Target(object):
     temporary_binary = None
     openocd_config = []
     use_fpu = False
+    misa = None
 
     def __init__(self, cmd, run, isolate):
         self.cmd = cmd
@@ -39,9 +40,11 @@ class Target(object):
                     prefix=binary_name + "_")
             binary_name = self.temporary_binary.name
             Target.temporary_files.append(self.temporary_binary)
-        march = "RV%dIMA" % self.xlen
+        march = "rv%dima" % self.xlen
         if self.use_fpu:
-            march += "FD"
+            march += "fd"
+        if self.extensionSupported("c"):
+            march += "c"
         testlib.compile(sources +
                 ("programs/entry.S", "programs/init.c",
                     "-I", "../env",
@@ -49,10 +52,15 @@ class Target(object):
                     "-T", "targets/%s/link.lds" % (self.directory or self.name),
                     "-nostartfiles",
                     "-mcmodel=medany",
+                    "-DXLEN=%d" % self.xlen,
                     "-o", binary_name),
                 xlen=self.xlen)
         return binary_name
 
+    def extensionSupported(self, letter):
+        # target.misa is set by testlib.ExamineTarget
+        return self.misa & (1 << (ord(letter.upper()) - ord('A')))
+
 class SpikeTarget(Target):
     # pylint: disable=abstract-method
     directory = "spike"
@@ -64,6 +72,7 @@ class SpikeTarget(Target):
 class Spike64Target(SpikeTarget):
     name = "spike64"
     xlen = 64
+    use_fpu = True
 
     def server(self):
         return testlib.Spike(self.cmd, halted=True)