Mercurial > lcfOS
comparison python/ppci/target/arm/__init__.py @ 362:c05ab629976a
Added CPUID for arm
author | Windel Bouwman |
---|---|
date | Sat, 15 Mar 2014 10:56:34 +0100 |
parents | b4ac28efcdf4 |
children | c49459768aaa |
comparison
equal
deleted
inserted
replaced
361:614a7f6d4d4d | 362:c05ab629976a |
---|---|
6 | 6 |
7 from .instructions import Dcd, Mov, Mov1, Add, Add2, Sub, Orr1, Mul, Mov2, Add1, Mul1 | 7 from .instructions import Dcd, Mov, Mov1, Add, Add2, Sub, Orr1, Mul, Mov2, Add1, Mul1 |
8 from .instructions import Lsr1, Lsl1, And1, Sub1 | 8 from .instructions import Lsr1, Lsl1, And1, Sub1 |
9 from .instructions import B, Bl, Ble, Bgt, Beq, Blt, Cmp, Cmp2 | 9 from .instructions import B, Bl, Ble, Bgt, Beq, Blt, Cmp, Cmp2 |
10 from .instructions import Push, Pop, Str, Ldr, Ldr3, Str1, Ldr1, Adr | 10 from .instructions import Push, Pop, Str, Ldr, Ldr3, Str1, Ldr1, Adr |
11 from .instructions import Mcr, Mrc | |
11 from .selector import ArmInstructionSelector | 12 from .selector import ArmInstructionSelector |
12 from .frame import ArmFrame | 13 from .frame import ArmFrame |
13 | 14 |
14 class ArmTarget(Target): | 15 class ArmTarget(Target): |
15 def __init__(self): | 16 def __init__(self): |
72 self.add_instruction(['dcd', 'imm32'], | 73 self.add_instruction(['dcd', 'imm32'], |
73 lambda rhs: Dcd(rhs[1])) | 74 lambda rhs: Dcd(rhs[1])) |
74 | 75 |
75 self.add_keyword('mov') | 76 self.add_keyword('mov') |
76 self.add_instruction(['mov', 'reg', ',', 'imm32'], | 77 self.add_instruction(['mov', 'reg', ',', 'imm32'], |
78 lambda rhs: Mov(rhs[1], rhs[3])) | |
79 self.add_instruction(['mov', 'reg', ',', 'reg'], | |
77 lambda rhs: Mov(rhs[1], rhs[3])) | 80 lambda rhs: Mov(rhs[1], rhs[3])) |
78 | 81 |
79 self.add_keyword('cmp') | 82 self.add_keyword('cmp') |
80 self.add_instruction(['cmp', 'reg', ',', 'imm32'], | 83 self.add_instruction(['cmp', 'reg', ',', 'imm32'], |
81 lambda rhs: Cmp(rhs[1], rhs[3])) | 84 lambda rhs: Cmp(rhs[1], rhs[3])) |
167 lambda rhs: rhs[0] | rhs[2]) | 170 lambda rhs: rhs[0] | rhs[2]) |
168 self.add_rule('reg_or_range', ['reg'], lambda rhs: {rhs[0]}) | 171 self.add_rule('reg_or_range', ['reg'], lambda rhs: {rhs[0]}) |
169 | 172 |
170 self.add_rule('reg_or_range', ['reg', '-', 'reg'], | 173 self.add_rule('reg_or_range', ['reg', '-', 'reg'], |
171 lambda rhs: register_range(rhs[0], rhs[2])) | 174 lambda rhs: register_range(rhs[0], rhs[2])) |
175 | |
176 # Add MCR and MRC (co-processor) | |
177 for i in range(16): | |
178 creg = 'c{}'.format(i) | |
179 self.add_keyword(creg) | |
180 self.add_rule('coreg', [creg], i) | |
181 | |
182 for i in range(8, 16): | |
183 px = 'p{}'.format(i) | |
184 self.add_keyword(px) | |
185 # Ran into trouble when using i inside lambda function: | |
186 # When using inside lambda (as a closure), i is bound to the latest | |
187 # value (15) | |
188 self.add_rule('coproc', [px], i) | |
189 | |
190 self.add_keyword('mcr') | |
191 self.add_instruction(['mcr', 'coproc', ',', 'imm3', ',', 'reg', ',', 'coreg', ',', 'coreg', ',', 'imm3'], | |
192 lambda rhs: Mcr(rhs[1], rhs[3], rhs[5], rhs[7], rhs[9], rhs[11])) | |
193 | |
194 self.add_keyword('mrc') | |
195 self.add_instruction(['mrc', 'coproc', ',', 'imm3', ',', 'reg', ',', 'coreg', ',', 'coreg', ',', 'imm3'], | |
196 lambda rhs: Mrc(rhs[1], rhs[3], rhs[5], rhs[7], rhs[9], rhs[11])) |