diff python/ppci/target/arm/instructions.py @ 354:5477e499b039

Added some sort of string functionality
author Windel Bouwman
date Thu, 13 Mar 2014 18:59:06 +0100
parents b8ad45b3a573
children 52492b304adf
line wrap: on
line diff
--- a/python/ppci/target/arm/instructions.py	Sun Mar 09 18:49:10 2014 +0100
+++ b/python/ppci/target/arm/instructions.py	Thu Mar 13 18:59:06 2014 +0100
@@ -173,7 +173,7 @@
     return Mul1(args[0], args[1], args[2])
 
 
-class Mul(ArmInstruction):
+class Mul1(ArmInstruction):
     def __init__(self, rd, rn, rm):
         super().__init__()
         self.rd = rd
@@ -211,18 +211,21 @@
         return self.token.encode()
 
     def __repr__(self):
-        return 'add {}, {}, {}'.format(self.rd, self.rn, self.rm)
+        return '{} {}, {}, {}'.format(self.mnemonic, self.rd, self.rn, self.rm)
 
 
 class Add1(OpRegRegReg):
+    mnemonic = 'ADD'
     opcode = 0b0000100
 
 
 class Sub1(OpRegRegReg):
+    mnemonic = 'SUB'
     opcode = 0b0000010
 
 
 class Orr1(OpRegRegReg):
+    mnemonic = 'ORR'
     opcode = 0b0001100
 
 
@@ -245,14 +248,16 @@
         return self.token.encode()
 
     def __repr__(self):
-        return 'add {}, {}, {}'.format(self.rd, self.rn, self.imm)
+        return '{} {}, {}, {}'.format(self.mnemonic, self.rd, self.rn, self.imm)
 
 
 class Add2(OpRegRegImm):
+    mnemonic = 'ADD'
     opcode = 0b0010100
 
 
 class Sub2(OpRegRegImm):
+    mnemonic = 'SUB'
     opcode = 0b0010010
 
 
@@ -393,6 +398,7 @@
         return '{} {}, [{}, {}]'.format(self.mnemonic, self.rt, self.rn, 
                 hex(self.offset))
 
+
 class Str1(LdrStrBase):
     opcode = 0b010
     bit20 = 0
@@ -405,6 +411,27 @@
     mnemonic = 'LDR'
 
 
+class Adr(ArmInstruction):
+    def __init__(self, rd, label):
+        super().__init__()
+        self.rd = rd
+        self.label = label
+
+    def __repr__(self):
+        return 'ADR {}, {}'.format(self.rd, self.label)
+
+    def relocations(self):
+        return [(self.label, 'adr_imm12')]
+
+    def encode(self):
+        self.token.cond = AL
+        self.token[0:12] = 0  # Filled by linker
+        self.token[12:16] = self.rd.num
+        self.token[16:20] = 0b1111
+        self.token[25] = 1
+        return self.token.encode()
+
+
 class Ldr3(ArmInstruction):
     """ Load PC relative constant value
         LDR rt, label