From a3e50e8f446b3e170f19d839b0e957adf6082849 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Mon, 3 May 2021 21:02:32 +0900 Subject: [PATCH] proxy.py: Use the enum module for GUARD_/USAGE_/IODEV_ Signed-off-by: Hector Martin --- proxyclient/find_all_regs.py | 4 ++-- proxyclient/fptest.py | 4 ++-- proxyclient/hacr_trap_bits.py | 4 ++-- proxyclient/proxy.py | 30 ++++++++++++++++++------------ proxyclient/proxyutils.py | 12 ++++++------ 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/proxyclient/find_all_regs.py b/proxyclient/find_all_regs.py index fcc05b13..691dc5fc 100644 --- a/proxyclient/find_all_regs.py +++ b/proxyclient/find_all_regs.py @@ -32,7 +32,7 @@ for op1 in range(1 << 3): p.dc_cvau(code_buffer, code_len) p.ic_ivau(code_buffer, code_len) - p.set_exc_guard(p.GUARD_SILENT | p.GUARD_SKIP) + p.set_exc_guard(GUARD.SILENT | GUARD.SKIP) p.call(code_buffer, BAD, data_buffer) cnt = p.get_exc_count() @@ -61,4 +61,4 @@ for op1 in range(1 << 3): print(" - *** EL0 accessible ***") i += 1 -p.set_exc_guard(p.GUARD_OFF) +p.set_exc_guard(GUARD.OFF) diff --git a/proxyclient/fptest.py b/proxyclient/fptest.py index 9c818848..451dbbbc 100644 --- a/proxyclient/fptest.py +++ b/proxyclient/fptest.py @@ -46,9 +46,9 @@ def test_denormals(): iface.writemem(data_buffer, struct.pack("<%dI" % len(data), *data)) - p.set_exc_guard(p.GUARD_SKIP) + p.set_exc_guard(GUARD.SKIP) ret = p.el0_call(code_buffer, data_buffer | EL0_REGION) - p.set_exc_guard(p.GUARD_OFF) + p.set_exc_guard(GUARD.OFF) v1 = p.read32(data_buffer + 8) v2 = p.read32(data_buffer + 20) diff --git a/proxyclient/hacr_trap_bits.py b/proxyclient/hacr_trap_bits.py index 7240dd3d..308ec093 100644 --- a/proxyclient/hacr_trap_bits.py +++ b/proxyclient/hacr_trap_bits.py @@ -42,7 +42,7 @@ def test(): p.dc_cvau(code_buffer, code_len) p.ic_ivau(code_buffer, code_len) - p.set_exc_guard(p.GUARD_SILENT | p.GUARD_SKIP) + p.set_exc_guard(GUARD.SILENT | GUARD.SKIP) p.el1_call(code_buffer, BAD, data_buffer) cnt = p.get_exc_count() @@ -81,4 +81,4 @@ for bit in range(64): print("s3_%d_c%d_c%d_%d (3, %d, %d, %d, %d)" % ( op1, CRn, CRm, op2, op1, CRn, CRm, op2)) -p.set_exc_guard(p.GUARD_OFF) +p.set_exc_guard(GUARD.OFF) diff --git a/proxyclient/proxy.py b/proxyclient/proxy.py index f2980a68..dc776f9b 100755 --- a/proxyclient/proxy.py +++ b/proxyclient/proxy.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT import os, sys, struct, serial, time +from enum import IntEnum, IntFlag from serial.tools.miniterm import Miniterm def hexdump(s, sep=" "): @@ -306,6 +307,23 @@ class ProxyCommandError(ProxyRemoteError): class AlignmentError(Exception): pass +class IODEV(IntEnum): + UART = 0 + FB = 1 + USB0 = 2 + USB1 = 3 + +class USAGE(IntFlag): + CONSOLE = (1 << 0) + UARTPROXY = (1 << 1) + +class GUARD(IntFlag): + OFF = 0 + SKIP = 1 + MARK = 2 + RETURN = 3 + SILENT = 0x100 + class M1N1Proxy: S_OK = 0 S_BADCMD = -1 @@ -323,18 +341,6 @@ class M1N1Proxy: P_EL1_CALL = 0x00a P_VECTOR = 0x00b - GUARD_OFF = 0 - GUARD_SKIP = 1 - GUARD_MARK = 2 - GUARD_RETURN = 3 - GUARD_SILENT = 0x100 - - IODEV_UART = 0 - IODEV_FB = 1 - - USAGE_CONSOLE = (1 << 0) - USAGE_UARTPROXY = (1 << 1) - P_WRITE64 = 0x100 P_WRITE32 = 0x101 P_WRITE16 = 0x102 diff --git a/proxyclient/proxyutils.py b/proxyclient/proxyutils.py index 2ca5176a..d3afb20e 100644 --- a/proxyclient/proxyutils.py +++ b/proxyclient/proxyutils.py @@ -60,10 +60,10 @@ 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 | (self.proxy.GUARD_SILENT if silent else 0)) + self.proxy.set_exc_guard(GUARD.MARK | (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) + self.proxy.set_exc_guard(GUARD.OFF) if cnt: raise ProxyError("Exception occurred") return retval @@ -82,10 +82,10 @@ 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.GUARD_SILENT if silent else 0)) + self.proxy.set_exc_guard(GUARD.SKIP | (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) + self.proxy.set_exc_guard(GUARD.OFF) if cnt: raise ProxyError("Exception occurred") @@ -98,10 +98,10 @@ 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.GUARD_SILENT if silent else 0)) + self.proxy.set_exc_guard(GUARD.SKIP | (GUARD.SILENT if silent else 0)) ret = call(self.code_buffer, r0, r1, r2, r3) cnt = self.proxy.get_exc_count() - self.proxy.set_exc_guard(self.proxy.GUARD_OFF) + self.proxy.set_exc_guard(GUARD.OFF) if cnt: raise ProxyError("Exception occurred") return ret