changeset 238:90637d1bbfad

Added test sequence 2
author Windel Bouwman
date Sat, 20 Jul 2013 13:18:04 +0200
parents 81752b0f85a5
children 63bb40758066
files python/cortexm3.py python/testasm.py python/zcc.py
diffstat 3 files changed, 29 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/python/cortexm3.py	Wed Jul 17 22:31:54 2013 +0200
+++ b/python/cortexm3.py	Sat Jul 20 13:18:04 2013 +0200
@@ -345,19 +345,14 @@
 class movregreg_ins(ArmInstruction):
     """ mov Rd, Rm """
     mnemonic = 'mov'
-    operands = (RegOp, RegOp)
+    operands = (Reg8Op, Reg8Op)
     def __init__(self, rd, rm):
         self.rd = rd
         self.rm = rm
     def encode(self):
         rd = self.rd.num
-        D = (rd & 0x8) >> 3
-        assert D < 2
-        rd = rd & 0x7
         rm = self.rm.num
-        assert rm < 16
-        opcode = self.opcode
-        h = (1 << 14) | (3 << 9) | (D << 7) | (rm << 3) | rd
+        h = 0 | (rm << 3) | rd
         return u16(h)
 
 
@@ -461,6 +456,11 @@
 
 # Jumping:
 
+def wrap_negative(x, bits):
+    b = struct.unpack('<I', struct.pack('<i', x))[0]
+    mask = (1 << bits) - 1
+    return b & mask
+
 class jumpBase_ins(ArmInstruction):
     operands = (LabelRef,)
     def __init__(self, target_label):
@@ -470,11 +470,11 @@
 
     def resolve(self, f):
         la = f(self.target.name)
-        sa = self.address
+        sa = self.address + 4
         self.offset = (la - sa)
-        if self.offset < 0:
-            # TODO: handle negative jump
-            self.offset = 0
+        #if self.offset < 0:
+        #    # TODO: handle negative jump
+        #    self.offset = 0
 
     def __repr__(self):
         return '{} {}'.format(self.mnemonic, self.target.name)
@@ -482,15 +482,14 @@
 @armtarget.instruction
 class b_ins(jumpBase_ins):
     mnemonic = 'B'
-
     def encode(self):
-        imm11 = self.offset >> 1
-        h = (0b11100 << 11) | imm11 | 1 # 1 to enable thumb mode
+        imm11 = wrap_negative(self.offset >> 1, 11)
+        h = (0b11100 << 11) | imm11 # | 1 # 1 to enable thumb mode
         return u16(h)
 
 class cond_base_ins(jumpBase_ins):
     def encode(self):
-        imm8 = 0
+        imm8 = wrap_negative(self.offset >> 1, 8)
         h = (0b1101 << 12) | (self.cond << 8) | imm8
         return u16(h)
 
--- a/python/testasm.py	Wed Jul 17 22:31:54 2013 +0200
+++ b/python/testasm.py	Sat Jul 20 13:18:04 2013 +0200
@@ -257,6 +257,20 @@
         self.feed('loop: add r6, r4, 7')
         self.feed('cmp r6, 5')
         self.check('0325 2c1c e61d 052e')
+    def testSequence2(self):
+        self.feed('henkie:')
+        self.feed('push {r1,r4,r5}')
+        self.feed('add r5, r2, r4')
+        self.feed('cmp r4, r2')
+        self.feed('ldr r0, [sp + 4]')
+        self.feed('str r3, [sp + 16]')
+        self.feed('pop {r1, r4, r5}')
+        self.feed('lsl r3, r4')
+        self.feed('cmp r3, r5')
+        self.feed('beq henkie')
+        self.feed('bne henkie')
+        self.feed('b henkie')
+        self.check('32b41519 94420198 049332bc a340ab42 f6d0f5d1 f4e7')
 
 if __name__ == '__main__':
     #cProfile.run('unittest.main()')
--- a/python/zcc.py	Wed Jul 17 22:31:54 2013 +0200
+++ b/python/zcc.py	Sat Jul 20 13:18:04 2013 +0200
@@ -42,7 +42,7 @@
         outs.dump()
 
     code_bytes = outs.sections['code'].to_bytes()
-    print('bytes:', code_bytes)
+    #print('bytes:', code_bytes)
     if args.output:
         output_filename = args.output
     else: