Skip to content

Commit 77b3f6d

Browse files
committed
recognize indexed accesses into array via the subi/sbci pair also
1 parent b283fa1 commit 77b3f6d

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

atxmega128a4u/scripts/avr_dumb_seq_load_xrefs.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def dref_range_fixer(startEA, endEA):
4646
if xref.iscode or xref.frm == idc.BADADDR or str(xref.type) != 'Data_Text': # only try to fix data references from code in ROM of the Data_Text type (as created by the dumb seq xref routine above)
4747
continue
4848
logger.debug("fixing xref (type:%s) to %s from ROM:%x" % (xref.type, safe_name(line.ea), xref.frm))
49-
sark.Line(xref.frm).comments.repeat = safe_name(line.ea)
49+
sark.Line(xref.frm).comments.repeat = str(sark.Line(xref.frm).comments.repeat).replace("0x%x" % line.ea, safe_name(line.ea))
5050
return
5151

5252
def dref_fixer():
@@ -83,13 +83,29 @@ def avr_dumb_seq_load_xrefs(startEA, endEA):
8383
if (is_latter_of_rxN_sequential_instructions(prev, line, 0) and
8484
str(prev_insn.operands[1].type) == 'Immediate_Value' and str(curr_insn.operands[1].type) == 'Immediate_Value'
8585
):
86-
word = int(curr_insn.operands[1].text, 0) * 256 + int(prev_insn.operands[1].text, 0)
87-
address = ram_segment.startEA + word
88-
89-
if address <= ram_segment.endEA:
90-
result = add_dref(line.ea, address, dr_T)
91-
logger.info("%s adding dref to %s at 0x%x \"%s\"" % ("Success" if result else "Error", safe_name(address), line.ea, line))
92-
line.comments.repeat = safe_name(address)
86+
idc.OpHex(prev.ea, 1)
87+
idc.OpHex(line.ea, 1)
88+
if prev_insn.mnem == 'subi' and curr_insn.mnem == 'sbci':
89+
word = (int(curr_insn.operands[1].text, 0) + 1) * -256 + int(prev_insn.operands[1].text, 0) * -1
90+
address = ram_segment.startEA + word
91+
92+
if (address > ram_segment.startEA + 0x2000 and address < ram_segment.endEA and
93+
str(prev_insn.operands[0]) != 'YL' and str(prev_insn.operands[0].reg) != 'r28' # ignore indexed access into stack
94+
):
95+
result = add_dref(line.ea, address, dr_T)
96+
logger.info("%s adding dref to %s at ROM:%x \"%s\"" % ("Success" if result else "Error", safe_name(address), line.ea, line))
97+
line.comments.repeat = "indexed access into %s" % safe_name(address)
98+
else:
99+
word = int(curr_insn.operands[1].text, 0) * 256 + int(prev_insn.operands[1].text, 0)
100+
address = ram_segment.startEA + word
101+
102+
if address >= ram_segment.startEA and address < ram_segment.endEA:
103+
result = add_dref(line.ea, address, dr_T)
104+
logger.info("%s adding dref to %s at ROM:%x \"%s\"" % ("Success" if result else "Error", safe_name(address), line.ea, line))
105+
if address <= ram_segment.startEA + 32:
106+
line.comments.repeat = "possible %s" % sark.Line(address).comments.repeat # use the ioport name in the comments
107+
else:
108+
line.comments.repeat = safe_name(address)
93109

94110
prev = line
95111

0 commit comments

Comments
 (0)