diff python/target/arminstructions.py @ 335:582a1aaa3983

Added long branch format
author Windel Bouwman
date Mon, 17 Feb 2014 20:41:30 +0100
parents 6f4753202b9a
children d1ecc493384e
line wrap: on
line diff
--- a/python/target/arminstructions.py	Thu Feb 13 22:02:08 2014 +0100
+++ b/python/target/arminstructions.py	Mon Feb 17 20:41:30 2014 +0100
@@ -216,13 +216,13 @@
         else:
             raise NotImplementedError()
 
-    def resolve(self, f):
-        if self.label:
-            self.expr = f(self.label.name)
-
     def encode(self):
         return u32(self.expr)
 
+    def relocations(self):
+        assert not isinstance(self.expr, LabelRef)
+        return []
+
     def __repr__(self):
         return 'DCD 0x{0:X}'.format(self.expr)
 
@@ -325,12 +325,8 @@
     def fromim(cls, im):
         return cls(im.dst[0], im.others[0])
 
-    def resolve(self, f):
-        la = f(self.label.name)
-        sa = align(self.address + 2, 4)
-        self.offset = (la - sa)
-        if self.offset < 0:
-            self.offset = 0
+    def relocations(self):
+        return [(self.label.name, 'lit_add_8')]
 
     def encode(self):
         rt = self.rt.num
@@ -488,7 +484,7 @@
 
     def __repr__(self):
         return '{} {}, {}'.format(self.mnemonic, self.rd, self.rm)
-        
+
 
 @instruction
 class Mul(ArmInstruction):
@@ -602,15 +598,15 @@
         self.target = target_label
         self.offset = 0
 
-    def resolve(self, f):
-        la = f(self.target.name)
-        sa = self.address + 4
-        self.offset = (la - sa)
-
     def __repr__(self):
         return '{} {}'.format(self.mnemonic, self.target.name)
 
 
+class Imm11Reloc:
+    def apply(self, P, S):
+        pass
+
+
 @instruction
 class B(jumpBase_ins):
     mnemonic = 'B'
@@ -619,6 +615,8 @@
         h = (0b11100 << 11) | imm11 # | 1 # 1 to enable thumb mode
         return u16(h)
 
+    def relocations(self):
+        return [(self.target.name, 'wrap_new11')]
 
 @instruction
 class Bl(jumpBase_ins):
@@ -634,13 +632,32 @@
         h2 = (0b1101 << 12) | (j1 << 13) | (j2 << 11) | imm11
         return u16(h1) + u16(h2)
 
+    def relocations(self):
+        return [(self.target.name, 'bl_imm11_imm10')]
 
-class cond_base_ins(jumpBase_ins):
+
+class cond_base_ins_short(jumpBase_ins):
     def encode(self):
         imm8 = wrap_negative(self.offset >> 1, 8)
         h = (0b1101 << 12) | (self.cond << 8) | imm8
         return u16(h)
 
+    def relocations(self):
+        return [(self.target.name, 'rel8')]
+
+
+class cond_base_ins(jumpBase_ins):
+    """ Encoding T3 """
+    def encode(self):
+        j1 = 1 # TODO: what do these mean?
+        j2 = 1
+        h1 = (0b11110 << 11) | (self.cond << 6)
+        h2 = (0b1101 << 12) | (j1 << 13) | (j2 << 11)
+        return u16(h1) + u16(h2)
+
+    def relocations(self):
+        return [(self.target.name, 'b_imm11_imm6')]
+
 
 @instruction
 class Beq(cond_base_ins):