def dump_context_map(f, mem, addr, end_addr, depth, state_map): ''' Dump Vivante context map. ''' indent = ' ' * len(depth) f.write('{\n') state_base = 0 state_count = 0 state_format = 0 next_cmd = 0 payload_start_ptr = 0 payload_end_ptr = 0 op = 0 size = (end_addr - addr)//4 ptr = 0 while ptr < size: hide = False (value,) = WORD_SPEC.unpack(mem[addr+ptr*4:addr+ptr*4+4]) if value != 0: f.write(indent + ' {0x%x, 0x%05X}' % (value, ptr*4)) try: path = state_map.lookup_address(ptr*4) desc = format_path(path) except KeyError: desc = '' if ptr != (size-1): f.write(", /* %s */\n" % desc) else: f.write(" /* %s */\n" % desc) ptr += 1 f.write(indent + '}')
def dump_context_map(f, mem, addr, end_addr, depth, state_map): ''' Dump Vivante context map. ''' indent = ' ' * len(depth) f.write('{\n') state_base = 0 state_count = 0 state_format = 0 next_cmd = 0 payload_start_ptr = 0 payload_end_ptr = 0 op = 0 size = (end_addr - addr) // 4 ptr = 0 while ptr < size: hide = False (value, ) = WORD_SPEC.unpack(mem[addr + ptr * 4:addr + ptr * 4 + 4]) if value != 0: f.write(indent + ' {0x%x, 0x%05X}' % (value, ptr * 4)) try: path = state_map.lookup_address(ptr * 4) desc = format_path(path) except KeyError: desc = '' if ptr != (size - 1): f.write(", /* %s */\n" % desc) else: f.write(" /* %s */\n" % desc) ptr += 1 f.write(indent + '}')
def iter_memory(mem, addr, end_addr): size = (end_addr - addr) // 4 ptr = 0 while ptr < size: hide = False (value, ) = WORD_SPEC.unpack(mem[addr + ptr * 4:addr + ptr * 4 + 4]) yield value ptr += 1
def iter_memory(mem, addr, end_addr): size = (end_addr - addr)//4 ptr = 0 while ptr < size: hide = False (value,) = WORD_SPEC.unpack(mem[addr+ptr*4:addr+ptr*4+4]) yield value ptr += 1
def dump_command_buffer(f, mem, addr, end_addr, depth, state_map): ''' Dump Vivante command buffer contents in human-readable format. ''' indent = ' ' * len(depth) f.write('{\n') state_base = 0 state_count = 0 state_format = 0 next_cmd = CMDBUF_IGNORE_INITIAL payload_start_ptr = 0 payload_end_ptr = 0 op = 0 size = (end_addr - addr)//4 ptr = 0 states = [] # list of (ptr, state_addr) tuples while ptr < size: hide = False (value,) = WORD_SPEC.unpack(mem[addr+ptr*4:addr+ptr*4+4]) if ptr >= next_cmd: #f.write('\n') op = value >> 27 payload_start_ptr = payload_end_ptr = ptr + 1 if op == 1: state_base = (value & 0xFFFF)<<2 state_count = (value >> 16) & 0x3FF if state_count == 0: state_count = 0x400 state_format = (value >> 26) & 1 payload_end_ptr = payload_start_ptr + state_count desc = "LOAD_STATE (1) Base: 0x%05X Size: %i Fixp: %i" % (state_base, state_count, state_format) if options.hide_load_state: hide = True elif op == 2: desc = "END (2)" elif op == 3: desc = "NOP (3)" elif op == 4: desc = "DRAW_2D (4)" elif op == 5: desc = "DRAW_PRIMITIVES (5)" payload_end_ptr = payload_start_ptr + 3 elif op == 6: desc = "DRAW_INDEXED_PRIMITIVES (6)" elif op == 7: desc = "WAIT (7)" elif op == 8: desc = "LINK (8)" payload_end_ptr = payload_start_ptr + 1 elif op == 9: desc = "STALL (9)" payload_end_ptr = payload_start_ptr + 1 elif op == 10: desc = "CALL (10)" payload_end_ptr = payload_start_ptr + 1 elif op == 11: desc = "RETURN (11)" elif op == 13: desc = "CHIP_SELECT (13)" else: desc = "UNKNOWN (%i)" % op next_cmd = (payload_end_ptr + 1) & (~1) elif ptr < payload_end_ptr: # Parse payload if op == 1: pos = (ptr - payload_start_ptr)*4 + state_base states.append((ptr, pos, state_format, value)) desc = format_state(pos, value, state_format, state_map) else: desc = "" else: desc = "PAD" if not hide: f.write(indent + ' 0x%08x' % value) if ptr != (size-1): f.write(", /* %s */\n" % desc) else: f.write(" /* %s */\n" % desc) ptr += 1 f.write(indent + '}') if options.list_address_states: # Print addresses; useful for making a re-play program #f.write('\n' + indent + 'GPU addresses {\n') uniqaddr = defaultdict(list) for (ptr, pos, state_format, value) in states: try: path = state_map.lookup_address(pos) except KeyError: continue type = path[-1][0].type if isinstance(type, Domain): # type Domain refers to another memory space #f.write(indent) addrname = format_addr(value) #f.write(' {0x%x,0x%05X}, /* %s = 0x%08x (%s) */\n' % (ptr, pos, format_path(path), value, addrname)) uniqaddr[value].append(ptr) #f.write(indent + '},') f.write('\n' + indent + 'Grouped GPU addresses {\n') for (value, ptrs) in uniqaddr.iteritems(): lvalues = ' = '.join([('cmdbuf[0x%x]' % ptr) for ptr in ptrs]) f.write(indent + ' ' + lvalues + ' = ' + format_addr(value) + ('; /* 0x%x */' % value) + '\n') f.write(indent + '}') if options.dump_shaders: state_by_pos = {} for (ptr, pos, state_format, value) in states: state_by_pos[pos]=value # 0x04000 and 0x06000 contain shader instructions dump_shader(f, 'vs', state_by_pos, 0x04000, 0x05000) dump_shader(f, 'ps', state_by_pos, 0x06000, 0x07000)