proxy.py: Use the enum module for GUARD_/USAGE_/IODEV_

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2021-05-03 21:02:32 +09:00
parent ec9221cf32
commit a3e50e8f44
5 changed files with 30 additions and 24 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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