From d918b066b6d2e0861eeec551a3f22b84277cc04d Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Thu, 25 Feb 2021 00:29:23 +0900 Subject: [PATCH] utils.py: add silent and call arguments to msr/mrs call allows the caller to override the function used for the function call, e.g. to use EL0. Use silent=True for find_all_regs.py Signed-off-by: Hector Martin --- proxyclient/find_all_regs.py | 4 ++-- proxyclient/utils.py | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/proxyclient/find_all_regs.py b/proxyclient/find_all_regs.py index 480755cf..4054da41 100644 --- a/proxyclient/find_all_regs.py +++ b/proxyclient/find_all_regs.py @@ -46,9 +46,9 @@ for op1 in range(1 << 3): print("s3_%d_c%d_c%d_%d (3, %d, %d, %d, %d) = 0x%x" % ( op1, CRn, CRm, op2, op1, CRn, CRm, op2, v)) try: - u.msr((3, op1, CRn, CRm, op2), v) + u.msr((3, op1, CRn, CRm, op2), v, silent=True) except: - pass + print(" - READONLY") else: print(" - writable") i += 1 diff --git a/proxyclient/utils.py b/proxyclient/utils.py index f4160457..f21ddddc 100644 --- a/proxyclient/utils.py +++ b/proxyclient/utils.py @@ -41,7 +41,9 @@ class ProxyUtils(object): self.code_buffer = self.malloc(0x10000) - def mrs(self, reg): + def mrs(self, reg, silent=False, call=None): + if call is None: + call = self.proxy.call op0, op1, CRn, CRm, op2 = reg op = (((op0 & 1) << 19) | (op1 << 16) | (CRn << 12) | @@ -53,15 +55,17 @@ class ProxyUtils(object): self.proxy.dc_cvau(self.code_buffer, 8) self.proxy.ic_ivau(self.code_buffer, 8) - self.proxy.set_exc_guard(self.proxy.GUARD_MARK) - retval = self.proxy.call(self.code_buffer) + self.proxy.set_exc_guard(self.proxy.GUARD_MARK | (self.proxy.GUARD_SILENT if silent else 0)) + retval = call(self.code_buffer) cnt = self.proxy.get_exc_count() self.proxy.set_exc_guard(self.proxy.GUARD_OFF) if cnt: raise ProxyError("Exception occurred") return retval - def msr(self, reg, val): + def msr(self, reg, val, silent=False, el0=False, call=None): + if call is None: + call = self.proxy.call op0, op1, CRn, CRm, op2 = reg op = (((op0 & 1) << 19) | (op1 << 16) | (CRn << 12) | @@ -73,14 +77,16 @@ class ProxyUtils(object): self.proxy.dc_cvau(self.code_buffer, 8) self.proxy.ic_ivau(self.code_buffer, 8) - self.proxy.set_exc_guard(self.proxy.GUARD_SKIP) - self.proxy.call(self.code_buffer, val) + self.proxy.set_exc_guard(self.proxy.GUARD_SKIP | (self.proxy.GUARD_SILENT if silent else 0)) + call(self.code_buffer, val) cnt = self.proxy.get_exc_count() self.proxy.set_exc_guard(self.proxy.GUARD_OFF) if cnt: raise ProxyError("Exception occurred") - def inst(self, op, r0=0, r1=0, r2=0, r3=0, silent=False): + def inst(self, op, r0=0, r1=0, r2=0, r3=0, silent=False, el0=False): + if call is None: + call = self.proxy.call func = struct.pack("