Skip to content

Commit 59766fb

Browse files
committed
Print .text and .data section separately
1 parent 15a631a commit 59766fb

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

tools/disassemble.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def chunk_into_words(code, bytes_per_word, byteorder):
164164

165165

166166
def print_ulp_header(h):
167+
print('header')
167168
print('ULP magic : %s (0x%08x)' % (h.magic.to_bytes(4, 'little'), h.magic))
168169
print('.text offset : %s (0x%02x)' % (h.text_offset, h.text_offset))
169170
print('.text size : %s (0x%02x)' % (h.text_size, h.text_size))
@@ -193,6 +194,25 @@ def decode_instruction_and_print(byte_offset, i, verbose=False):
193194
print(" {:10} = {:3}{}".format(field, val, extra))
194195

195196

197+
def print_text_section(code, verbose=False):
198+
print('.text')
199+
200+
words = chunk_into_words(code, bytes_per_word=4, byteorder='little')
201+
202+
for idx, i in enumerate(words):
203+
decode_instruction_and_print(idx << 2,i , verbose)
204+
205+
206+
def print_data_section(data_offset, code):
207+
print('.data')
208+
209+
words = chunk_into_words(code, bytes_per_word=4, byteorder='little')
210+
211+
for idx, i in enumerate(words):
212+
asm = "<empty>" if i == 0 else "<non-empty>"
213+
print_code_line(data_offset + (idx << 2), i, asm)
214+
215+
196216
def disassemble_manually(byte_sequence_string, verbose=False):
197217
sequence = byte_sequence_string.strip().replace(' ','')
198218
chars_per_instruction = 8
@@ -227,11 +247,15 @@ def disassemble_file(filename, verbose=False):
227247
if verbose:
228248
print_ulp_header(h)
229249

230-
code = data[h.text_offset:]
231-
words = chunk_into_words(code, bytes_per_word=4, byteorder='little')
250+
code = data[h.text_offset:(h.text_offset+h.text_size)]
251+
print_text_section(code, verbose)
232252

233-
for idx, i in enumerate(words):
234-
decode_instruction_and_print(idx << 2, i, verbose)
253+
if verbose:
254+
print('----------------------------------------')
255+
256+
data_offset = h.text_offset+h.text_size
257+
code = data[data_offset:(data_offset+h.data_size)]
258+
print_data_section(data_offset-h.text_offset, code)
235259

236260

237261
def print_help():

0 commit comments

Comments
 (0)