Skip to content

Commit f6f89e4

Browse files
committed
ARM: add base-updates to memory instructions
1 parent d4f2df2 commit f6f89e4

14 files changed

+51
-8
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-20250908"
1+
chbversion: str = "0.3.0-20251011"

chb/app/InstrXData.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,12 @@ def get_base_update_xpr(self) -> XXpr:
578578
"Unexpected error value in base-update expression")
579579
return self.xprdictionary.xpr(xbuval)
580580

581+
def is_base_update_xpr_ok(self) -> bool:
582+
xbutag = next(t for t in self.tags if t.startswith("xbu:"))
583+
xix = int(xbutag[4:])
584+
xbuval = self.args[xix]
585+
return (xbuval != -2)
586+
581587
def get_base_update_cxpr(self) -> XXpr:
582588
cbutag = next(t for t in self.tags if t.startswith("cbu:"))
583589
cix = int(cbutag[4:])

chb/arm/ARMAssembly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def opcode(self) -> ARMOpcode:
6262

6363
@property
6464
def mnemonic(self) -> str:
65-
return self.opcode.mnemonic
65+
return self.opcode.mnemonic_stem
6666

6767
def mnemonic_extension(self) -> str:
6868
return self.opcode.mnemonic_extension()

chb/arm/ARMOpcode.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ def get_base_update_xpr(self) -> "XXpr":
229229
raise UF.CHBError(
230230
self.__class__.__name__ + " does not have writeback")
231231

232+
def is_base_update_xpr_ok(self) -> bool:
233+
return self.xdata.is_base_update_xpr_ok()
234+
232235
def get_base_update_cxpr(self) -> "XXpr":
233236
if self.is_writeback:
234237
return self.xdata.get_base_update_cxpr()
@@ -239,7 +242,10 @@ def get_base_update_cxpr(self) -> "XXpr":
239242
def writeback_update(self) -> str:
240243
if self.xdata.has_base_update():
241244
vbu = self.get_base_update_var()
242-
xbu = self.get_base_update_cxpr()
245+
if self.is_base_update_xpr_ok():
246+
xbu = str(self.get_base_update_cxpr())
247+
else:
248+
xbu = "?"
243249
return "; wbu: " + str(vbu) + " := " + str(xbu)
244250
else:
245251
return ""

chb/arm/opcodes/ARMBitwiseBitClear.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ def operands(self) -> List[ARMOperand]:
156156
def opargs(self) -> List[ARMOperand]:
157157
return [self.armd.arm_operand(i) for i in self.args[1: -1]]
158158

159+
def mnemonic_extension(self) -> str:
160+
cc = ARMOpcode.mnemonic_extension(self)
161+
wb = "S" if self.is_writeback else ""
162+
return wb + cc
163+
164+
@property
165+
def is_writeback(self) -> bool:
166+
return self.args[0] == 1
167+
159168
def annotation(self, xdata: InstrXData) -> str:
160169
xd = ARMBitwiseBitClearXData(xdata)
161170
return xd.annotation

chb/arm/opcodes/ARMLoadCoprocessor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
from chb.arm.ARMDictionary import ARMDictionary
4242

4343

44+
@armregistry.register_tag("LDC2", ARMOpcode)
45+
@armregistry.register_tag("LDC2L", ARMOpcode)
4446
@armregistry.register_tag("LDCL", ARMOpcode)
4547
@armregistry.register_tag("LDC", ARMOpcode)
4648
class ARMLoadCoprocessor(ARMOpcode):

chb/arm/opcodes/ARMLoadRegisterByte.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ def operands(self) -> List[ARMOperand]:
198198
def opargs(self) -> List[ARMOperand]:
199199
return [self.armd.arm_operand(self.args[i]) for i in [0, 1, 2, 3]]
200200

201+
@property
202+
def is_write_back(self) -> bool:
203+
return self.opargs[3].is_write_back
204+
201205
def lhs(self, xdata: InstrXData) -> List[XVariable]:
202206
xd = ARMLoadRegisterByteXData(xdata)
203207
return [xd.vrt]
@@ -324,6 +328,11 @@ def has_cast() -> bool:
324328
annotations=annotations)
325329
ll_assigns: List[AST.ASTInstruction] = [ll_assign, ll_addr_assign]
326330

331+
if not xd.is_base_update_xpr_ok():
332+
chklogger.logger.error(
333+
"LDRB: Error encountered for writeback address at address %s", iaddr)
334+
return ([], ll_assigns)
335+
327336
basereg = xd.get_base_update_var()
328337
newaddr = xd.get_base_update_xpr()
329338
hl_addr_lhs = XU.xvariable_to_ast_lval(basereg, xdata, iaddr, astree)

chb/arm/opcodes/ARMLoadRegisterHalfword.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ def operands(self) -> List[ARMOperand]:
193193
def opargs(self) -> List[ARMOperand]:
194194
return [self.armd.arm_operand(self.args[i]) for i in [0, 1, 2, 3]]
195195

196+
@property
197+
def is_write_back(self) -> bool:
198+
return self.opargs[3].is_write_back
199+
196200
def lhs(self, xdata: InstrXData) -> List[XVariable]:
197201
xd = ARMLoadRegisterHalfwordXData(xdata)
198202
return [xd.vrt]

chb/arm/opcodes/ARMLoadRegisterSignedByte.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ def ast_prov(
195195
defuses = xdata.defuses
196196
defuseshigh = xdata.defuseshigh
197197

198-
hl_lhs = XU.xvariable_to_ast_lval(lhs, xdata, iaddr, astree)
199-
hl_rhs = XU.xxpr_to_ast_def_expr(
200-
rhs, xdata, iaddr, astree, size=1, memaddr=xaddr)
201-
202198
hl_assign = astree.mk_assign(
203199
hl_lhs,
204200
hl_rhs,

chb/arm/opcodes/ARMMove.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ def ast_prov_predicate_assign(
340340
chklogger.logger.warning(
341341
"Predicate assignment without associated predicate at "
342342
+ "address %s", iaddr)
343+
astree.add_instr_address(ll_assign, [iaddr])
343344
return ([], [ll_assign])
344345

345346
rhs = xd.cpredicate if xd.is_cpredicate_ok else xd.xpredicate

0 commit comments

Comments
 (0)