"""Builders for the tasks-and-memory scenarios (docs/testing.md, sections 6.10-6.11): tasks whose page tables the scenario lays out leaf by leaf, raw task commands with any field, and the heap-texture payload. Everything here restates the guest ABI from byte offsets, as task.py does; nothing is taken from the implementation. """ import struct from . import abi from .abi import PAGE from .task import GPUTask, ObjectList, Task, buffer_record, rec, seg # Blit fill (the blit decoder's record 306): {u32 buffer ref, u64 offset, # u64 length, u8 value} (the same layout smoke_blit uses). BLIT_FILL = 306 BLIT_COPY = 301 def fill_rec(ref, off, n, byte): return rec(BLIT_FILL, struct.pack("> shift) & 0xFFF table = self._table(level, prefix) if level == d - 1: w = self.writable is True or (self.writable not in (True, False) and vpn in self.writable) s.u32(s.pa(table, 4 * idx), s.pfn(self.leaves[vpn]) | (abi.PTE_WRITABLE if w else 0)) else: nxt = self._table(level + 1, (prefix << 12) | idx) s.u32(s.pa(table, 4 * idx), s.pfn(nxt)) prefix = (prefix << 12) | idx def table_gpa(self, level, prefix, idx=0): """The guest address of entry idx of the level-`level` table reached through `prefix` (the higher indices, concatenated).""" return self.s.pa(self._tables[(level, prefix)], 4 * idx) def gpa(self, va): return self.s.pa(self.leaves[va // PAGE], va % PAGE) def diff(self, label=None): self.s.diff(label=label, gpa=self.s.pa(self.data), length=(self._data_end - self.data) * PAGE) class XGPUTask(XTask): """GPUTask's layout (task.py) over an XTask: page 0 the object list, pages 1-3 records, pages 4-7 command buffers, 8.. buffer contents.""" def __init__(self, s, tid=1, pages=64, **kw): super().__init__(s, tid=tid, pages=pages, **kw) self.ol = ObjectList(self, 0, 1 * PAGE) self._cmd = 4 * PAGE self._blob = 8 * PAGE buffer = GPUTask.buffer reserve = GPUTask.reserve blob = GPUTask.blob cmdbuf = GPUTask.cmdbuf reset_cmdbufs = GPUTask.reset_cmdbufs install = GPUTask.install # ---- raw commands (the FIFO payloads, any field) ---- def define_raw(s, word0, length, root_pfn, **kw): """DefineTask2 (56): {u32 bit 0 | taskID << 1, u64 length, u32 task root page}.""" return s.submit(abi.OP_DEFINE_TASK2, struct.pack("