Mercurial > lcfOS
comparison python/ppci/target/arm/instructions.py @ 350:2b02bd286fe9
Fixed A9 hello worle
author | Windel Bouwman |
---|---|
date | Sat, 08 Mar 2014 16:29:03 +0100 |
parents | 3bb7dcfe5529 |
children | 899ae3aea803 |
comparison
equal
deleted
inserted
replaced
349:13a6e73b448f | 350:2b02bd286fe9 |
---|---|
32 | 32 |
33 def encode(self): | 33 def encode(self): |
34 self.token[0:32] = self.v | 34 self.token[0:32] = self.v |
35 return self.token.encode() | 35 return self.token.encode() |
36 | 36 |
37 def __repr__(self): | |
38 return 'DCD {}'.format(hex(self.v)) | |
39 | |
37 | 40 |
38 def Mov(*args): | 41 def Mov(*args): |
39 if len(args) == 2: | 42 if len(args) == 2: |
40 if isinstance(args[1], int): | 43 if isinstance(args[1], int): |
41 return Mov1(*args) | 44 return Mov1(*args) |
81 self.token[16:20] = 0 | 84 self.token[16:20] = 0 |
82 self.token.S = 0 | 85 self.token.S = 0 |
83 self.token[21:28] = 0xD | 86 self.token[21:28] = 0xD |
84 self.token.cond = AL | 87 self.token.cond = AL |
85 return self.token.encode() | 88 return self.token.encode() |
89 | |
90 def __repr__(self): | |
91 return 'MOV {}, {}'.format(self.rd, self.rm) | |
86 | 92 |
87 | 93 |
88 def Add(*args): | 94 def Add(*args): |
89 if len(args) == 3 and isinstance(args[0], ArmRegister) and \ | 95 if len(args) == 3 and isinstance(args[0], ArmRegister) and \ |
90 isinstance(args[1], ArmRegister): | 96 isinstance(args[1], ArmRegister): |
204 return self.token.encode() | 210 return self.token.encode() |
205 | 211 |
206 def relocations(self): | 212 def relocations(self): |
207 return [(self.target, 'b_imm24')] | 213 return [(self.target, 'b_imm24')] |
208 | 214 |
215 def __repr__(self): | |
216 mnemonic = self.__class__.__name__ | |
217 return '{} {}'.format(mnemonic, self.target) | |
218 | |
209 | 219 |
210 EQ, NE, CS, CC, MI, PL, VS, VC, HI, LS, GE, LT, GT, LE, AL = range(15) | 220 EQ, NE, CS, CC, MI, PL, VS, VC, HI, LS, GE, LT, GT, LE, AL = range(15) |
211 | 221 |
212 class BranchBase(BranchBaseRoot): | 222 class BranchBase(BranchBaseRoot): |
213 opcode = 0b1010 | 223 opcode = 0b1010 |
253 self.token[16:28] = 0b100100101101 | 263 self.token[16:28] = 0b100100101101 |
254 reg_list = 0 | 264 reg_list = 0 |
255 self.token[0:16] = reg_list_to_mask(self.reg_list) | 265 self.token[0:16] = reg_list_to_mask(self.reg_list) |
256 return self.token.encode() | 266 return self.token.encode() |
257 | 267 |
268 def __repr__(self): | |
269 return 'PUSH {}'.format(self.reg_list) | |
270 | |
271 | |
258 class Pop(ArmInstruction): | 272 class Pop(ArmInstruction): |
259 def __init__(self, register_set): | 273 def __init__(self, register_set): |
260 super().__init__() | 274 super().__init__() |
261 self.reg_list = register_set | 275 self.reg_list = register_set |
262 | 276 |
264 self.token.cond = AL | 278 self.token.cond = AL |
265 self.token[16:28] = 0b100010111101 | 279 self.token[16:28] = 0b100010111101 |
266 self.token[0:16] = reg_list_to_mask(self.reg_list) | 280 self.token[0:16] = reg_list_to_mask(self.reg_list) |
267 return self.token.encode() | 281 return self.token.encode() |
268 | 282 |
283 def __repr__(self): | |
284 return 'POP {}'.format(self.reg_list) | |
285 | |
269 | 286 |
270 def Ldr(*args): | 287 def Ldr(*args): |
271 if len(args) == 3 and isinstance(args[1], ArmRegister): | 288 """ Convenience function that creates the correct instruction """ |
272 return Ldr1(*args) | 289 if len(args) == 3: |
273 elif len(args) == 2 and isinstance(args[1], ArmRegister): | 290 if isinstance(args[1], ArmRegister): |
274 return Ldr1(args[0], args[1], 0) | 291 return Ldr1(*args) |
275 raise Exception() | 292 elif len(args) == 2: |
293 if isinstance(args[1], ArmRegister): | |
294 return Ldr1(args[0], args[1], 0) | |
295 elif isinstance(args[1], str): | |
296 return Ldr3(*args) | |
297 raise Exception() | |
298 | |
276 | 299 |
277 def Str(*args): | 300 def Str(*args): |
278 if len(args) == 3 and isinstance(args[1], ArmRegister): | 301 if len(args) == 3 and isinstance(args[1], ArmRegister): |
279 return Str1(*args) | 302 return Str1(*args) |
280 elif len(args) == 2 and isinstance(args[1], ArmRegister): | 303 elif len(args) == 2 and isinstance(args[1], ArmRegister): |
302 else: | 325 else: |
303 self.token[23] = 0 | 326 self.token[23] = 0 |
304 self.token[0:12] = -self.offset | 327 self.token[0:12] = -self.offset |
305 return self.token.encode() | 328 return self.token.encode() |
306 | 329 |
330 def __repr__(self): | |
331 return '{} {}, [{}, {}]'.format(self.mnemonic, self.rt, self.rn, | |
332 hex(self.offset)) | |
307 | 333 |
308 class Str1(LdrStrBase): | 334 class Str1(LdrStrBase): |
309 opcode = 0b010 | 335 opcode = 0b010 |
310 bit20 = 0 | 336 bit20 = 0 |
337 mnemonic = 'STR' | |
311 | 338 |
312 | 339 |
313 class Ldr1(LdrStrBase): | 340 class Ldr1(LdrStrBase): |
314 opcode = 0b010 | 341 opcode = 0b010 |
315 bit20 = 1 | 342 bit20 = 1 |
343 mnemonic = 'LDR' | |
316 | 344 |
317 | 345 |
318 class Ldr3(ArmInstruction): | 346 class Ldr3(ArmInstruction): |
319 """ Load PC relative constant value """ | 347 """ Load PC relative constant value |
348 LDR rt, label | |
349 encoding A1 | |
350 """ | |
320 def __init__(self, rt, label): | 351 def __init__(self, rt, label): |
352 super().__init__() | |
321 self.rt = rt | 353 self.rt = rt |
322 self.label = label | 354 self.label = label |
323 | 355 |
356 def __repr__(self): | |
357 return 'LDR {}, {}'.format(self.rt, self.label) | |
358 | |
359 def relocations(self): | |
360 return [(self.label, 'ldr_imm12')] | |
361 | |
362 def encode(self): | |
363 self.token.cond = AL | |
364 self.token[0:12] = 0 # Filled by linker | |
365 self.token[12:16] = self.rt.num | |
366 self.token[16:23] = 0b0011111 | |
367 self.token[24:28] = 0b0101 | |
368 return self.token.encode() |