m1n1.fw.asc: Handle DARTless ASCs

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2021-08-29 01:32:27 +09:00
parent eec6bbdeaf
commit 43c93af949
3 changed files with 57 additions and 23 deletions

View file

@ -26,7 +26,7 @@ class StandardASC(ASC):
0xa: ASCDummyEndpoint, # tracekit
}
def __init__(self, u, asc_base, dart):
def __init__(self, u, asc_base, dart=None):
super().__init__(u, asc_base)
self.remote_eps = set()
self.add_ep(0, ASCManagementEndpoint(self, 0))
@ -43,6 +43,8 @@ class StandardASC(ASC):
self.epcls[k] = v
def iomap(self, addr, size):
if self.dart is None:
return addr
return 0xf00000000 | self.dart.iomap(0, addr, size)
def ioalloc(self, size):
@ -50,6 +52,18 @@ class StandardASC(ASC):
dva = self.iomap(paddr, size)
return paddr, dva
def ioread(self, dva, size):
if self.dart:
return self.dart.ioread(0, dva & 0xFFFFFFFF, size)
else:
return self.iface.readmem(dva, size)
def iowrite(self, dva, data):
if self.dart:
return self.dart.iowrite(0, dva & 0xFFFFFFFF, data)
else:
return self.iface.writemem(dva, data)
def start_ep(self, epno):
if epno not in self.epcls:
raise Exception(f"Unknown endpoint {epno:#x}")

View file

@ -3,27 +3,40 @@ from .base import *
from ...utils import *
class CrashLogMessage(Register64):
TYPE = 63, 44
class CrashLog_TranslateDva(Register64):
TYPE = 63, 44, Constant(0x104)
ADDR = 43, 0
class CrashLog_Crashed(Register64):
TYPE = 63, 44, Constant(0x103)
TYPE = 63, 52
SIZE = 51, 44
DVA = 43, 0
class ASCCrashLogEndpoint(ASCBaseEndpoint):
SHORT = "crash"
BASE_MESSAGE = CrashLogMessage
@msg_handler(0x104, CrashLog_TranslateDva)
def TranslateDva(self, msg):
ranges = self.asc.dart.iotranslate(0, msg.ADDR & 0xffffffff, 4096)
assert len(ranges) == 1
self.crashbuf = ranges[0][0]
self.log(f"Translate {msg.ADDR:#x} -> {self.crashbuf:#x}")
self.send(CrashLog_TranslateDva(ADDR=self.crashbuf))
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.iobuffer = None
self.iobuffer_dva = None
self.started = False
@msg_handler(0x1)
def Handle(self, msg):
if self.started:
return self.handle_crashed(msg)
else:
return self.handle_getbuf(msg)
def handle_getbuf(self, msg):
size = 0x1000 * msg.SIZE
if msg.DVA:
self.iobuffer_dva = msg.DVA
self.log(f"buf prealloc at dva {self.iobuffer_dva:#x}")
self.send(CrashLogMessage(TYPE=1, SIZE=msg.SIZE))
else:
self.iobuffer, self.iobuffer_dva = self.asc.ioalloc(size)
self.log(f"buf {self.iobuffer:#x} / {self.iobuffer_dva:#x}")
self.send(CrashLogMessage(TYPE=1, SIZE=msg.SIZE, DVA=self.iobuffer_dva))
self.started = True
return True
def crash_soft(self):
@ -32,10 +45,11 @@ class ASCCrashLogEndpoint(ASCBaseEndpoint):
def crash_hard(self):
self.send(0x22)
@msg_handler(0x103, CrashLog_Crashed)
def Crashed(self, msg):
def handle_crashed(self, msg):
size = 0x1000 * msg.SIZE
self.log(f"Crashed!")
crashdata = self.asc.dart.ioread(0, msg.DVA & 0xffffffff, 2048)
crashdata = self.asc.ioread(msg.DVA, size)
chexdump(crashdata)
return True

View file

@ -49,16 +49,22 @@ class ASCSysLogEndpoint(ASCBaseEndpoint):
if self.iobuffer:
print("WARNING: trying to reset iobuffer!")
self.iobuffer, self.iobuffer_dva = self.asc.ioalloc(size)
self.log(f"buf {self.iobuffer:#x} / {self.iobuffer_dva:#x}")
self.send(Syslog_GetBuf(DVA=self.iobuffer_dva, SIZE=msg.SIZE))
if msg.DVA:
self.iobuffer_dva = msg.DVA
self.log(f"buf prealloc at dva {self.iobuffer_dva:#x}")
self.send(Syslog_GetBuf(SIZE=msg.SIZE))
else:
self.iobuffer, self.iobuffer_dva = self.asc.ioalloc(size)
self.log(f"buf {self.iobuffer:#x} / {self.iobuffer_dva:#x}")
self.send(Syslog_GetBuf(SIZE=msg.SIZE, DVA=self.iobuffer_dva))
self.started = True
return True
@msg_handler(5, Syslog_Log)
def Log(self, msg):
stride = 0x20 + self.entrysize
log = self.asc.iface.readmem(self.iobuffer + msg.INDEX * stride, stride)
log = self.asc.ioread(self.iobuffer_dva + msg.INDEX * stride, stride)
hdr, unk, context, logmsg = struct.unpack(f"<II24s{self.entrysize}s", log)
context = context.split(b"\x00")[0].decode("ascii")
logmsg = logmsg.split(b"\x00")[0].decode("ascii").rstrip("\n")