def test_enqueue_vector_ignores_vector_outside_of_traceable_range(self): rom = bytearray(0x10000) memory = Memory(rom) tracer = Tracer(memory=memory, entry_points=[], vectors=[], traceable_range=range(0x8000, 0x9000)) tracer.enqueue_vector(0xa000) self.assertEqual(len(tracer.queue), 0)
def test_branch_never_taken_clrc_bc(self): rom = bytearray(0x10000) rom[0xf9e6] = 0x81 # clrc ;f9e6 81 rom[0xf9e7] = 0xf9 # bc 0xf9eb ;f9e7 f9 02 branch never rom[0xf9e8] = 0x02 memory = Memory(rom) tracer = Tracer(memory=memory, entry_points=[0xf9e6], vectors=[], traceable_range=range(0xf9e3, 0xf9e8 + 1)) tracer.trace(disassemble_inst) self.assertTrue(memory.is_instruction_start(0xf9e6)) self.assertTrue(memory.is_instruction_start(0xf9e7)) self.assertTrue(memory.is_branch_never_taken(0xf9e7)) self.assertTrue(memory.is_unknown(0xf9e9)) # tracing stopped
def test_branch_never_taken_bn_bn(self): rom = bytearray(0x10000) rom[0xf9e3] = 0xfb # bn 0xf9e9 ;f9e3 fb 04 rom[0xf9e4] = 0x04 rom[0xf9e5] = 0xfb # bn 0xf9e9 ;f9e7 fb 02 branch never rom[0xf9e6] = 0x02 memory = Memory(rom) tracer = Tracer(memory=memory, entry_points=[0xf9e3], vectors=[], traceable_range=range(0xf9e3, 0xf9e6 + 1)) tracer.trace(disassemble_inst) self.assertTrue(memory.is_instruction_start(0xf9e3)) self.assertTrue(memory.is_instruction_start(0xf9e5)) self.assertTrue(memory.is_unknown(0xf9e7)) # tracing stopped self.assertTrue(memory.is_branch_never_taken(0xf9e5))
def test_branch_never_taken_mov_bnz(self): rom = bytearray(0x10000) rom[0xf90c] = 0x04 # mov a, #0x00 ;f90c 04 00 rom[0xf90d] = 0x00 rom[0xf90e] = 0xfc # bnz 0xf8f4 ;f90e fc e4 branch never rom[0xf90f] = 0xe4 memory = Memory(rom) tracer = Tracer(memory=memory, entry_points=[0xf90c], vectors=[], traceable_range=range(0xf90c, 0xf90f + 1)) tracer.trace(disassemble_inst) self.assertTrue(memory.is_instruction_start(0xf90c)) self.assertTrue(memory.is_instruction_start(0xf90e)) self.assertTrue(memory.is_unknown(0xf910)) # tracing stopped self.assertTrue(memory.is_branch_never_taken(0xf90e))
def test_branch_never_taken_bz_bz(self): rom = bytearray(0x10000) rom[0x8ac1] = 0xfd # bz 0x8ac5 ;8ac1 fd 02 rom[0x8ac2] = 0x02 rom[0x8ac3] = 0xfd # bz 0x8ac7 ;8ac3 fd 02 branch never rom[0x8ac4] = 0x02 memory = Memory(rom) tracer = Tracer(memory=memory, entry_points=[0x8ac1], vectors=[], traceable_range=range(0x8ac1, 0x8ac4 + 1)) tracer.trace(disassemble_inst) self.assertTrue(memory.is_instruction_start(0x8ac1)) self.assertTrue(memory.is_instruction_start(0x8ac3)) self.assertTrue(memory.is_unknown(0x8ac5)) # tracing stopped self.assertTrue(memory.is_branch_never_taken(0x8ac3))
def test_branch_always_taken_mov_bn(self): rom = bytearray(0x10000) rom[0xf9e5] = 0x04 # mov a, #0x82 ;f9e5 04 82 rom[0xf9e6] = 0x82 rom[0xf9e7] = 0xfb # bn 0xf9eb ;f9e7 fb 02 branch always rom[0xf9e8] = 0x02 memory = Memory(rom) tracer = Tracer(memory=memory, entry_points=[0xf9e5], vectors=[], traceable_range=range(0xf9e5, 0xf9e8 + 1)) tracer.trace(disassemble_inst) self.assertTrue(memory.is_instruction_start(0xf9e5)) self.assertTrue(memory.is_instruction_start(0xf9e7)) self.assertTrue(memory.is_unknown(0xf9e9)) # tracing stopped self.assertTrue(memory.is_branch_always_taken(0xf9e7))
def test_branch_always_taken_bnc_bc(self): rom = bytearray(0x10000) rom[0xf9e3] = 0xf8 # bnc 0xf9e9 ;f9e3 f8 04 rom[0xf9e4] = 0x04 rom[0xf9e5] = 0xf9 # bc 0xf9eb ;f9e7 f9 02 branch always rom[0xf9e6] = 0x02 memory = Memory(rom) tracer = Tracer(memory=memory, entry_points=[0xf9e3], vectors=[], traceable_range=range(0xf9e3, 0xf9e6 + 1)) tracer.trace(disassemble_inst) self.assertTrue(memory.is_instruction_start(0xf9e3)) self.assertTrue(memory.is_instruction_start(0xf9e5)) self.assertTrue(memory.is_unknown(0xf9e97)) # tracing stopped self.assertTrue(memory.is_branch_always_taken(0xf9e5))
def test_branch_never_taken_movw_bz(self): rom = bytearray(0x10000) rom[0xf90b] = 0xe4 # movw a, #0x0001 ;f90b e4 00 01 rom[0xf90c] = 0x00 rom[0xf90d] = 0x01 rom[0xf90e] = 0xfd # bz 0xf8f4 ;f90e fd e4 branch never rom[0xf90f] = 0xe4 memory = Memory(rom) tracer = Tracer(memory=memory, entry_points=[0xf90b], vectors=[], traceable_range=range(0xf90b, 0xf90e + 1)) tracer.trace(disassemble_inst) self.assertTrue(memory.is_instruction_start(0xf90b)) self.assertTrue(memory.is_instruction_start(0xf90e)) self.assertTrue(memory.is_branch_never_taken(0xf90e)) self.assertTrue(memory.is_unknown(0xf910)) # tracing stopped
def test_ctor_raises_if_vector_outside_of_traceable_range(self): rom = bytearray(0x10000) memory = Memory(rom) try: Tracer(memory=memory, entry_points=[], vectors=[0xa000], traceable_range=range(0x8000, 0x9000)) self.fail() except ValueError as exc: msg = "Vector address 0xA000 outside of traceable range" self.assertEqual(exc.args[0], msg)
def main(): if len(sys.argv) != 2: sys.stderr.write(__doc__) sys.exit(1) with open(sys.argv[1], 'rb') as f: rom = bytearray(f.read()) start_address = 0x10000 - len(rom) memory = Memory(rom) memory.set_reserved_byte(0xfffc) memory.set_mode_byte(0xfffd) entry_points = [0xedba] vectors = [ # callv 0xffc0, 0xffc2, 0xffc4, 0xffc6, 0xffc8, 0xffca, 0xffcc, 0xffce, # irq 0xffd0, 0xffd2, 0xffd4, 0xffd6, 0xffd8, 0xffda, 0xffdc, 0xffde, 0xffe0, 0xffe2, 0xffe4, 0xffe6, 0xffe8, 0xffea, 0xffec, 0xffee, 0xfff0, 0xfff2, 0xfff4, 0xfff6, 0xfff8, 0xfffa, # reset 0xfffe, ] traceable_range = range(start_address, start_address + len(rom) + 1) tracer = Tracer(memory, entry_points, vectors, traceable_range) tracer.trace(disassemble_inst) symbol_table = SymbolTable(MB89620R_SYMBOLS) symbol_table.generate(memory, start_address) # xxx should pass traceable_range printer = Printer( memory, start_address, symbol_table, ) printer.print_listing()