m1n1.fw.agx.{cmdqueue,microsequence}: Lots of struct updates

Signed-off-by: Asahi Lina <lina@asahilina.net>
This commit is contained in:
Asahi Lina 2022-08-17 13:42:10 +09:00
parent 54f9f22578
commit 438ec70baa
2 changed files with 107 additions and 102 deletions

View file

@ -18,7 +18,7 @@ class WorkCommandBarrier(ConstructClass):
subcon = Struct(
"magic" / Const(0x4, Int32ul),
"stamp_addr" / Int64ul,
"stamp" / ROPointer(this.stamp_addr, Int32ul),
"stamp" / ROPointer(this.stamp_addr, StampCounter),
"stamp_value1" / Int32ul,
"event" / Int32ul, # Event number that signals a stamp check
"stamp_value2" / Int32ul,
@ -37,7 +37,7 @@ class WorkCommandInitBM(ConstructClass):
subcon = Struct(
"magic" / Const(0x6, Hex(Int32ul)),
"context_id" / Hex(Int32ul), # Might be context?
"unk_8" / Hex(Int32ul), # 0
"buffer_mgr_slot" / Hex(Int32ul), # 0
"unk_c" / Hex(Int32ul), # 0
"unk_10" / Hex(Int32ul), # 0x30
"buffer_mgr_addr" / Int64ul,
@ -45,41 +45,57 @@ class WorkCommandInitBM(ConstructClass):
"stamp_value" / Hex(Int32ul), # 0x100
)
class LinkedListHead(ConstructClass):
subcon = Struct(
"prev" / Int64ul,
"next" / Int64ul,
)
def __init__(self):
self.prev = 0
self.next = 0
class EventControl(ConstructClass):
subcon = Struct(
"event_count_addr" / Int64ul,
"event_count" / ROPointer(this.event_count_addr, Int32ul),
"base_stamp" / Int32ul,
"unk_c" / Int32ul,
"unk_10" / Int64ul,
"unk_10" / Int32ul,
"unk_14" / Int32ul,
"unk_18" / Int64ul,
"unk_20" / Int32ul,
"unk_24" / Int32ul,
"unk_28" / Int32ul,
"unkptr_2c" / Int64ul,
"unk_34" / HexDump(Bytes(24)),
"unk_4c" / Int32ul,
"unkptr_50" / Int64ul,
"unk_58" / HexDump(Bytes(0x94 - 0x58)),
"unk_94" / Int32ul,
"unk_98" / Int64ul,
"context_ptr" / Int64ul,
"has_ta" / Int32ul,
"pstamp_ta" / Int64ul,
"unk_ta" / HexDump(Bytes(0x18)),
"has_3d" / Int32ul,
"pstamp_3d" / Int64ul,
"unk_3d" / HexDump(Bytes(0x18)),
"has_cp" / Int32ul,
"pstamp_cp" / Int64ul,
"unk_cp" / HexDump(Bytes(0x18)),
"in_list" / Int32ul,
"list_head" / LinkedListHead,
)
def __init__(self):
super().__init__()
self.unk_14 = 0
self.unk_18 = 0
self.unk_20 = 0
self.unk_24 = 0
self.unk_28 = 0
self.unkptr_2c = 0
self.unk_34 = bytes(24)
self.unk_4c = 0
self.unkptr_50 = 0
self.unk_58 = bytes(0x94 - 0x58)
self.unk_94 = 0
self.unk_98 = 0
self.context_ptr = 0
self.has_ta = 0
self.pstamp_ta = 0
self.unk_ta = bytes(24)
self.has_3d = 0
self.pstamp_3d = 0
self.unk_3d = bytes(24)
self.has_cp = 0
self.pstamp_cp = 0
self.unk_cp = bytes(24)
self.in_list = 0
self.list_head = LinkedListHead()
class WorkCommandCP(ConstructClass):
"""
@ -124,12 +140,6 @@ class WorkCommandCP(ConstructClass):
"microsequence" / ROPointer(this.microsequence_ptr, MicroSequence),
)
def __str__(self) -> str:
str = super().__str__(ignore=['magic'])
str += f" Control List - {self.microsequence_size:#x} bytes @ {self.microsequence_ptr:#x}:\n"
str += textwrap.indent(repr(self.microsequence), ' ' * 3)
return str
class WorkCommand0_UnkBuf(ConstructValueClass):
subcon = HexDump(Bytes(0x18))
@ -137,10 +147,10 @@ class WorkCommand0_UnkBuf(ConstructValueClass):
self.value = bytes(0x18)
class WorkCommand1_UnkBuf(ConstructValueClass):
subcon = HexDump(Bytes(0x118))
subcon = HexDump(Bytes(0x110))
def __init__(self):
self.value = bytes(0x118)
self.value = bytes(0x110)
class WorkCommand1_UnkBuf2(ConstructClass):
subcon = Struct(
@ -149,6 +159,12 @@ class WorkCommand1_UnkBuf2(ConstructClass):
"unk_10" / Int64ul,
)
class Flag(ConstructValueClass):
subcon = Hex(Int32ul)
def __init__(self):
self.value = 0
class WorkCommand3D(ConstructClass):
"""
For 3D
@ -205,8 +221,10 @@ class WorkCommand3D(ConstructClass):
# Embedded structures that are also pointed to by other stuff
"struct_2" / Start3DStruct2,
"struct_1" / Start3DStruct1,
"unk_758" / Flag,
"unk_75c" / Flag,
"unk_buf" / WorkCommand1_UnkBuf,
"unk_word" / BarrierCounter,
"busy_flag" / Flag,
"struct_6" / Start3DStruct6,
"struct_7" / Start3DStruct7,
"unk_buf2" / WorkCommand1_UnkBuf2,
@ -220,12 +238,6 @@ class WorkCommand3D(ConstructClass):
"pad_928" / Default(HexDump(Bytes(0x18)), bytes(0x18)),
)
def __str__(self) -> str:
str = super().__str__()
# str += f" Control List - {self.microsequence_size:#x} bytes @ {self.microsequence_ptr:#x}:\n"
# str += textwrap.indent(repr(self.microsequence), ' ' * 3)
return str
class WorkCommand0_UnkBuf(ConstructValueClass):
subcon = HexDump(Bytes(0x18))
@ -262,7 +274,7 @@ class WorkCommandTA(ConstructClass):
"unk_8" / Hex(Int32ul),
"event_control_addr" / Hex(Int64ul),
"event_control" / ROPointer(this.event_control_addr, EventControl),
"unk_14" / Hex(Int64ul),
"buffer_mgr_slot" / Hex(Int64ul),
"buffer_mgr_addr" / Int64ul,
"buffer_mgr" / ROPointer(this.buffer_mgr_addr, BufferManagerInfo),
"buf_thing_addr" / Int64ul,
@ -300,12 +312,6 @@ class WorkCommandTA(ConstructClass):
"pad_5d5" / Default(HexDump(Bytes(0xb)), bytes(0xb)),
)
def __str__(self) -> str:
str = super().__str__(ignore=['magic'])
#str += f" Control List - {self.microsequence_size:#x} bytes @ {self.microsequence_ptr:#x}:\n"
#str += textwrap.indent(repr(self.microsequence), ' ' * 3)
return str
class UnknownWorkCommand(ConstructClass):
subcon = Struct(
"magic" / Hex(Int32ul),
@ -330,10 +336,10 @@ class CmdBufWork(ConstructClass):
})
)
class ContextInfo(ConstructClass):
class JobList(ConstructClass):
subcon = Struct(
"fb_ptr" / Default(Int64ul, 0),
"self" / Int64ul,
"first_job" / Default(Int64ul, 0),
"last_head" / Int64ul,
"unkptr_10" / Default(Int64ul, 0),
)
@ -399,23 +405,23 @@ class CommandQueueInfo(ConstructClass):
"pointers_addr" / Hex(Int64ul),
"pointers" / ROPointer(this.pointers_addr, CommandQueuePointers),
"rb_addr" / Hex(Int64ul), # 0x4ff pointers
"context_info_addr" / Hex(Int64ul), # ffffffa000000000, size 0x18 (shared by 3D and TA)
"context_info" / ROPointer(this.context_info_addr, ContextInfo),
"job_list_addr" / Hex(Int64ul), # ffffffa000000000, size 0x18 (shared by 3D and TA)
"job_list" / ROPointer(this.job_list_addr, JobList),
"gpu_buf_addr" / Hex(Int64ul), # GPU space for this queue, 0x2c18 bytes?
#"gpu_buf" / ROPointer(this.gpu_buf_addr, HexDump(Bytes(0x2c18))),
"gpu_rptr1" / Hex(Int32ul),
"gpu_rptr2" / Hex(Int32ul),
"gpu_rptr3" / Hex(Int32ul),
"unk_2c" / Int32ul, # busy flags?
"unk_2c" / Int32sl, # busy flags?
"unk_30" / Hex(Int32ul), # read by CPU
"unk_34" / Hex(Int32ul),
"unk_38" / Hex(Int64ul), # 0xffffffffffff0000, page mask?
"unk_38" / Hex(Int64ul),
"unk_40" / Hex(Int32ul), # 1
"unk_44" / Hex(Int32ul), # 0
"unk_48" / Hex(Int32ul), # 1, 2
"unk_4c" / Int32sl, # -1
"unk_50" / Hex(Int32ul), # Counts up for each new process or command queue
"unk_54" / Hex(Int32ul), # always 0x04
"unk_54" / Int32sl,
"unk_58" / Hex(Int64ul), # 0
"busy" / Hex(Int32ul), # 1 = gpu busy
Padding(0x20),
@ -432,16 +438,16 @@ class CommandQueueInfo(ConstructClass):
self.gpu_rptr1 = 0
self.gpu_rptr2 = 0
self.gpu_rptr3 = 0
self.unk_2c = 0xffffffff
self.unk_2c = -1
self.unk_30 = 0x0
self.unk_34 = 0x0
self.unk_38 = 0xffffffffffff0000
self.unk_40 = 0x1
self.unk_44 = 0x0
self.unk_48 = 0x1
self.unk_4c = -0x1
self.unk_50 = 0x96
self.unk_54 = 0xffffffff
self.unk_4c = -1
self.unk_50 = 0xdeadbeef # some kind of ID
self.unk_54 = -1
self.unk_58 = 0x0
self.busy = 0x0
self.blocked_on_barrier = 0x0

View file

@ -28,7 +28,13 @@ class Timestamp(ConstructValueClass):
def __init__(self, value=0):
self.value = value
class BarrierCounter(ConstructValueClass):
class WrappedPointer(ConstructValueClass):
subcon = Int64ul
def __init__(self, value=0):
self.value = value
class StampCounter(ConstructValueClass):
subcon = Hex(Int32ul)
def __init__(self):
@ -63,8 +69,8 @@ class BufferManagerInfo(ConstructClass):
subcon = Struct(
"gpu_counter" / Int32ul,
"unk_4" / Int32ul,
"active" / Int32ul,
"unk_c" / Int32ul,
"last_id" / Int32ul,
"cur_id" / Int32ul,
"unk_10" / Int32ul,
"gpu_counter2" / Int32ul,
"unk_18" / Int32ul,
@ -95,23 +101,15 @@ class BufferManagerInfo(ConstructClass):
"unk_88" / Int32ul,
"unk_8c" / Int32ul,
"unk_90" / HexDump(Bytes(0x30)),
"unk_c0" / Int32ul, # written by GPU
"unk_c4" / HexDump(Bytes(0x14)),
"unkptr_d8" / Int64ul,
"unk_e0" / Int32ul,
"misc_addr" / Int64ul, # like unkptr_24 in Start3DStruct3
"misc" / ROPointer(this.misc_addr, BufferManagerMisc),
"unk_ec" / Int32ul,
"unk_f0" / Int64ul,
"unk_f8" / Int64ul,
)
def __init__(self):
super().__init__()
self.gpu_counter = 0x0
self.unk_4 = 0
self.active = 0x0
self.unk_c = 0xffffffff
self.last_id = 0x0
self.cur_id = 0xffffffff
self.unk_10 = 0x0
self.gpu_counter2 = 0x0
self.unk_18 = 0x0
@ -131,12 +129,7 @@ class BufferManagerInfo(ConstructClass):
self.unk_88 = 0x1178
self.unk_8c = 0x0
self.unk_90 = bytes(0x30)
self.unk_c0 = 0x0
self.unk_c4 = bytes(0x14)
self.unk_e0 = 0x0
self.unk_ec = 0x0
self.unk_f0 = 0x0
self.unk_f8 = 0x0
class Start3DClearPipelineBinding(ConstructClass):
subcon = Struct(
@ -305,7 +298,7 @@ class BufferThing(ConstructClass):
class Start3DStruct6(ConstructClass):
subcon = Struct(
"unk_0" / Int64ul,
"tvb_overflow_count" / Int64ul,
"unk_8" / Int64ul,
"unk_10" / Int32ul,
"encoder_id" / Int64ul,
@ -319,10 +312,10 @@ class Start3DStruct6(ConstructClass):
class Start3DStruct7(ConstructClass):
subcon = Struct(
"unk_0" / Int64ul,
"stamp1_addr" / Int64ul, # same contents as below
"stamp1" / ROPointer(this.stamp1_addr, BarrierCounter),
"stamp2_addr" / Int64ul, # same as FinalizeComputeCmd.stamp - some kind of fence/token
"stamp2" / ROPointer(this.stamp2_addr, BarrierCounter),
"stamp1_addr" / WrappedPointer, # same contents as below
"stamp1" / ROPointer(this.stamp1_addr.value, StampCounter),
"stamp2_addr" / WrappedPointer, # same as FinalizeComputeCmd.stamp - some kind of fence/token
"stamp2" / ROPointer(this.stamp2_addr.value, StampCounter),
"stamp_value" / Int32ul,
"ev_3d" / Int32ul,
"unk_20" / Int32ul,
@ -332,6 +325,11 @@ class Start3DStruct7(ConstructClass):
"unk_30" / Int32ul,
)
def __init__(self):
super().__init__()
self.stamp1_addr = StampCounter()
self.stamp2_addr = StampCounter()
class Attachment(ConstructClass):
subcon = Struct(
"address" / Int64ul,
@ -353,10 +351,8 @@ class Start3DCmd(ConstructClass):
"struct2" / ROPointer(this.struct2_addr, Start3DStruct2),
"buf_thing_addr" / Int64ul,
"buf_thing" / ROPointer(this.buf_thing_addr, BufferThing),
"unkptr_1c" / Int64ul, # constant 0xffffffa00c33ec88, AKA initdata->unkptr_178+8
"unk_1c" / ROPointer(this.unkptr_1c, HexDump(Bytes(0x4))),
"unkptr_24" / Int64ul, # 4 bytes
"unk_24" / ROPointer(this.unkptr_24, Int32ul),
"stats_ptr" / Int64ul,
"busy_flag_ptr" / Int64ul, # 4 bytes
"struct6_addr" / Int64ul, # 0x3c bytes
"struct6" / ROPointer(this.struct6_addr, Start3DStruct6),
"struct7_addr" / Int64ul, # 0x34 bytes
@ -366,7 +362,7 @@ class Start3DCmd(ConstructClass):
"context_id" / Int32ul,
"unk_50" / Int32ul,
"unk_54" / Int32ul,
"unk_58" / Int32ul,
"buffer_mgr_slot" / Int32ul,
"unk_5c" / Int32ul,
"prev_stamp_value" / Int64ul, # 0
"unk_68" / Int32ul, # 0
@ -388,7 +384,7 @@ class Finalize3DCmd(ConstructClass):
"uuid" / Int32ul, # uuid for tracking
"unk_8" / Int32ul, # 0
"stamp_addr" / Int64ul,
"stamp" / ROPointer(this.stamp_addr, BarrierCounter),
"stamp" / ROPointer(this.stamp_addr, StampCounter),
"stamp_value" / Int32ul,
"unk_18" / Int32ul,
"buf_thing_addr" / Int64ul,
@ -396,10 +392,10 @@ class Finalize3DCmd(ConstructClass):
"buffer_mgr_addr" / Int64ul,
"buffer_mgr" / ROPointer(this.buffer_mgr_addr, BufferManagerInfo),
"unk_2c" / Int64ul, # 1
"unkptr_34" / Int64ul, # Same as Start3DCmd.unkptr_1c
"stats_ptr" / Int64ul,
"struct7_addr" / Int64ul,
"struct7" / ROPointer(this.struct7_addr, Start3DStruct7),
"unkptr_44" / Int64ul, # Same as Start3DCmd.unkptr_24
"busy_flag_ptr" / Int64ul,
"cmdqueue_ptr" / Int64ul,
"workitem_ptr" / Int64ul,
"unk_5c" / Int64ul,
@ -409,7 +405,7 @@ class Finalize3DCmd(ConstructClass):
"unk_7c" / Int64ul, # 0
"unk_84" / Int64ul, # 0
"unk_8c" / Int64ul, # 0
"startcmd_offset" / Int32sl, # relative offset from start of Finalize to StartComputeCmd
"restart_branch_offset" / Int32sl,
"unk_98" / Int32ul, # 1
)
@ -444,7 +440,7 @@ class StartTACmdStruct2(ConstructClass):
"unk_40" / Int64ul,
"unk_48" / Int64ul,
"unk_50" / Int64ul,
"tvb_heapmeta_addr" / Int64ul, # like Start3DStruct2.unkptr_e0/f0
"tvb_heapmeta_addr2" / Int64ul,
"unk_60" / Int64ul,
"unk_68" / Int64ul,
"iogpu_deflake_1" / Int64ul,
@ -487,10 +483,10 @@ class StartTACmdStruct3(ConstructClass):
"unknown_buffer" / Int64ul,
"unk_548" / Int64ul,
"unk_550" / Array(6, Int32ul),
"stamp1_addr" / Int64ul, # same contents as below
"stamp1" / ROPointer(this.stamp1_addr, BarrierCounter),
"stamp2_addr" / Int64ul, # same as FinalizeComputeCmd.stamp - some kind of fence/token
"stamp2" / ROPointer(this.stamp2_addr, BarrierCounter),
"stamp1_addr" / WrappedPointer, # same contents as below
"stamp1" / ROPointer(this.stamp1_addr.value, StampCounter),
"stamp2_addr" / WrappedPointer, # same as FinalizeComputeCmd.stamp - some kind of fence/token
"stamp2" / ROPointer(this.stamp2_addr.value, StampCounter),
"stamp_value" / Int32ul,
"ev_ta" / Int32ul,
"unk_580" / Int32ul,
@ -499,6 +495,11 @@ class StartTACmdStruct3(ConstructClass):
"unk_58c" / Array(2, Int32ul),
)
def __init__(self):
super().__init__()
self.stamp1_addr = StampCounter()
self.stamp2_addr = StampCounter()
class StartTACmd(ConstructClass):
subcon = Struct(
"magic" / Const(0x22, Int32ul),
@ -510,14 +511,12 @@ class StartTACmd(ConstructClass):
"buffer_mgr" / ROPointer(this.buffer_mgr_addr, BufferManagerInfo),
"buf_thing_addr" / Int64ul,
"buf_thing" / ROPointer(this.buf_thing_addr, BufferThing),
"unkptr_24" / Int64ul,
# unkptr_1c in Start3DCmd comes after this struct
"unk_24" / ROPointer(this.unkptr_24, HexDump(Bytes(0x4))),
"stats_ptr" / Int64ul,
"cmdqueue_ptr" / Int64ul,
"context_id" / Int32ul,
"unk_38" / Int32ul,
"unk_3c" / Int32ul,
"unk_40" / Int64ul,
"buffer_mgr_slot" / Int64ul,
"unk_48" / Int64ul,
"unk_50" / Int32ul,
"struct3_addr" / Int64ul,
@ -543,7 +542,7 @@ class FinalizeTACmd(ConstructClass):
"buf_thing" / ROPointer(this.buf_thing_addr, BufferThing),
"buffer_mgr_addr" / Int64ul,
"buffer_mgr" / ROPointer(this.buffer_mgr_addr, BufferManagerInfo),
"unkptr_14" / Int64ul, # StartTACmd.unkptr_24
"stats_ptr" / Int64ul,
"cmdqueue_ptr" / Int64ul, #
"context_id" / Int32ul,
"unk_28" / Int32ul,
@ -552,7 +551,7 @@ class FinalizeTACmd(ConstructClass):
"unk_34" / Int32ul,
"uuid" / Int32ul,
"stamp_addr" / Int64ul,
"stamp" / ROPointer(this.stamp_addr, BarrierCounter),
"stamp" / ROPointer(this.stamp_addr, StampCounter),
"stamp_value" / Int32ul,
"unk_48" / Int64ul,
"unk_50" / Int32ul,
@ -561,7 +560,7 @@ class FinalizeTACmd(ConstructClass):
"unk_60" / Int32ul,
"unk_64" / Int32ul,
"unk_68" / Int32ul,
"startcmd_offset" / Int32sl,
"restart_branch_offset" / Int32sl,
"unk_70" / Int32ul,
)
@ -673,7 +672,7 @@ class FinalizeComputeCmd(ConstructClass):
"unk_50" / Int32ul,
"unk_54" / Int32ul,
"unk_58" / Int32ul,
"startcmd_offset" / Int32sl, # realative offset from start of Finalize to StartComputeCmd
"restart_branch_offset" / Int32sl, # realative offset from start of Finalize to StartComputeCmd
"unk_60" / Int32ul,
)