59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/disassembler.rb', line 59
def annotate_tables
$stderr.puts "Annotating tables..." if verbose
tables = rom_xml.xpath('/rom/table')
count = 0
tables.each do |table|
elements = 1 scaling = rom_xml.xpath("/rom/scaling[@name='#{table.attr('scaling')}']")
if scaling.count == 0
$stderr.puts "WARNING: Failed to find scaling: #{table.attr('scaling')}, skipping table #{table.attr('name')}" if verbose
next
end
element_size = scaling.attr('storagetype').value().gsub(/[^\d]+/,'').to_i / 8
address = from_hex table.attr('address')
is_data = false
table.xpath('table').each do |subtable|
elements = elements * subtable.attr('elements').to_i
is_data = true
end
possible_offsets = []
case elements
when 1,4
possible_offsets << 0
when 3..20
possible_offsets << 4
possible_offsets << 6
when 44
possible_offsets << 28 else
possible_offsets << 7
possible_offsets << 10
possible_offsets << 16
end
possible_offsets.each do |offset|
offset_hex = (address - offset).to_s(16)
if verbose and @reference_addresses.include? offset_hex
$stderr.puts "WARNING: Reference hunt collision at 0x#{offset_hex} (#{@reference_addresses[offset_hex]} vs #{table.attr('name')})! Check code carefully!"
end
@reference_addresses[offset_hex] = table.attr('name')
end
storage_size = element_size * elements
storage_size.times do |n|
instruction = instruction_at(address + n)
instruction.[0] = table.attr('name') + "(0x#{table.attr('address')} -> 0x#{(address + storage_size - 1).to_s(16)}, #{storage_size} bytes)"
instruction.data = is_data
end
$stderr.puts "Annotated: #{table.attr('name')}" if verbose
count = count + 1
end
$stderr.puts "#{count} tables annotated." if verbose
end
|