comparison python/cortexm3.py @ 237:81752b0f85a5

Added burn led test program
author Windel Bouwman
date Wed, 17 Jul 2013 22:31:54 +0200
parents 8786811a5a59
children 90637d1bbfad
comparison
equal deleted inserted replaced
236:8786811a5a59 237:81752b0f85a5
199 @armtarget.instruction 199 @armtarget.instruction
200 class dcd_ins(ArmInstruction): 200 class dcd_ins(ArmInstruction):
201 mnemonic = 'dcd' 201 mnemonic = 'dcd'
202 operands = (Imm32,) 202 operands = (Imm32,)
203 def __init__(self, expr): 203 def __init__(self, expr):
204 assert isinstance(expr, Imm32) 204 if isinstance(expr, Imm32):
205 self.expr = expr.imm 205 self.expr = expr.imm
206 self.label = None
207 elif isinstance(expr, LabelRef):
208 self.expr = 0
209 self.label = expr
210 else:
211 raise NotImplementedError()
212
213 def resolve(self, f):
214 if self.label:
215 self.expr = f(self.label.name)
206 216
207 def encode(self): 217 def encode(self):
208 return u32(self.expr) 218 return u32(self.expr)
209 219
210 def __repr__(self): 220 def __repr__(self):
449 h = (opcode << 11) | (rn << 8) | imm 459 h = (opcode << 11) | (rn << 8) | imm
450 return u16(h) 460 return u16(h)
451 461
452 # Jumping: 462 # Jumping:
453 463
454 @armtarget.instruction 464 class jumpBase_ins(ArmInstruction):
455 class jmp_ins(ArmInstruction): 465 operands = (LabelRef,)
456 operands = (Label,)
457 mnemonic = 'jmp'
458 def __init__(self, target_label): 466 def __init__(self, target_label):
459 assert type(target_label) is Label 467 assert type(target_label) is LabelRef
460 self.target = target_label 468 self.target = target_label
461 def fixUp(self): 469 self.offset = 0
462 pass 470
463 def encode(self): 471 def resolve(self, f):
464 h = 0 # TODO 472 la = f(self.target.name)
465 return u16(h) 473 sa = self.address
466 def __repr__(self): 474 self.offset = (la - sa)
467 return 'B {0}'.format(self.target.name) 475 if self.offset < 0:
468 476 # TODO: handle negative jump
469 @armtarget.instruction 477 self.offset = 0
470 class beq_ins(ArmInstruction): 478
471 operands = (Label,) 479 def __repr__(self):
480 return '{} {}'.format(self.mnemonic, self.target.name)
481
482 @armtarget.instruction
483 class b_ins(jumpBase_ins):
484 mnemonic = 'B'
485
486 def encode(self):
487 imm11 = self.offset >> 1
488 h = (0b11100 << 11) | imm11 | 1 # 1 to enable thumb mode
489 return u16(h)
490
491 class cond_base_ins(jumpBase_ins):
492 def encode(self):
493 imm8 = 0
494 h = (0b1101 << 12) | (self.cond << 8) | imm8
495 return u16(h)
496
497 @armtarget.instruction
498 class beq_ins(cond_base_ins):
472 mnemonic = 'beq' 499 mnemonic = 'beq'
473 def __init__(self, target_label): 500 cond = 0
474 assert type(target_label) is Label 501
475 self.target = target_label 502 @armtarget.instruction
476 def fixUp(self): 503 class beq_ins(cond_base_ins):
477 pass 504 mnemonic = 'bne'
478 def encode(self): 505 cond = 1
479 h = 0 # TODO
480 return u16(h)
481 def __repr__(self):
482 return 'BEQ {0}'.format(self.target.name)
483 506
484 @armtarget.instruction 507 @armtarget.instruction
485 class push_ins(ArmInstruction): 508 class push_ins(ArmInstruction):
486 operands = (RegisterSet,) 509 operands = (RegisterSet,)
487 mnemonic = 'push' 510 mnemonic = 'push'