Skip to content

Commit a2b32f8

Browse files
committed
AST: add scaled writeback semantics to LDR
1 parent 48e244c commit a2b32f8

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

chb/app/CHVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
chbversion: str = "0.3.0-20240829"
1+
chbversion: str = "0.3.0-20240830"

chb/arm/opcodes/ARMLoadRegister.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,41 @@ def ast_prov(
210210
basereg = xdata.vars[2]
211211
newaddr = xdata.xprs[5]
212212
hl_addr_lhs = XU.xvariable_to_ast_lval(basereg, xdata, iaddr, astree)
213-
hl_addr_rhs = XU.xxpr_to_ast_def_expr(newaddr, xdata, iaddr, astree)
213+
214+
hl_addr_lhs_type = hl_addr_lhs.ctype(astree.ctyper)
215+
if hl_addr_lhs_type is not None and len(xdata.ints) > 0:
216+
if hl_addr_lhs_type.is_pointer:
217+
addrtype = cast(AST.ASTTypPtr, hl_addr_lhs_type)
218+
tgttyp = addrtype.tgttyp
219+
tgttypsize = astree.type_size_in_bytes(tgttyp)
220+
if tgttypsize is not None:
221+
incr = xdata.ints[0]
222+
ptrincr = incr // tgttypsize
223+
hl_addr_rhs = astree.mk_binary_op(
224+
"plus",
225+
astree.mk_lval_expression(hl_addr_lhs),
226+
astree.mk_integer_constant(ptrincr))
227+
else:
228+
hl_addr_rhs = XU.xxpr_to_ast_def_expr(
229+
newaddr, xdata, iaddr, astree)
230+
chklogger.logger.warning(
231+
"LDR address adjustment not scaled due to missing "
232+
+ "size of pointer target type %s at address %s",
233+
str(tgttyp), iaddr)
234+
else:
235+
hl_addr_rhs = XU.xxpr_to_ast_def_expr(
236+
newaddr, xdata, iaddr, astree)
237+
chklogger.logger.warning(
238+
"LDR address adjustment not scaled due to unexpected "
239+
+ "address type: %s at address %s",
240+
str(hl_addr_lhs_type), iaddr)
241+
else:
242+
hl_addr_rhs = XU.xxpr_to_ast_def_expr(
243+
newaddr, xdata, iaddr, astree)
244+
chklogger.logger.warning(
245+
"LDR address adjustment not scaled due to lack of type "
246+
+ "information at address %s",
247+
iaddr)
214248

215249
hl_addr_assign = astree.mk_assign(
216250
hl_addr_lhs,

0 commit comments

Comments
 (0)