logoalt Hacker News

bri3d • yesterday at 8:32 PM • 0 replies • view on HN

Perform static analysis and then dynamic analysis; in many ways it's a lot easier than forward engineering drivers since the weird sequencing issues and errata that always come up are already fixed. Stuff like "which chicken bits to set" and "what clock/power domain blows the other one up if you get the ordering wrong" doesn't cause issues, since the instrumented traces and analyzed code already do everything in the right order.

Usually the way this is done by hand (and reading the source for this driver, it looks like Claude did things about the same way) is:

* Statically analyze enough of the system to understand how commands (mapped registers, mailboxes, buffers) are sent and structured at the highest level.

* Write a dynamic analysis tool which can trace the state changes sent to the hardware (ie - dump every register poke, every mailbox, every buffer)

* Dump enough of the bring-up to be able to do it yourself, even if you don't understand it (ie - these 500 registers need to be set to these values for "normal operation," we have no idea what they are, but we know how to poke them and in what sequence).

* Use static analysis to try to back out the meaning of each register/buffer and to define structures (ie - "this register has bit x set to y in a function called EnableFooClockDomain, it must be the FOO_CLK_EN bit" or "this structure is allocated in AllocateBigTransferBufferA, the type of this structure is clearly a big_transfer_buffer_a"). If you don't know what the functions are called, name them using context clues (observed logging, where in time said function is called, known values in the inputs, etc.)

Then you basically rinse and repeat this process using techniques like fuzzing observed inputs->outputs, tracing known constants, and finding context clues from documentation and parallel architectures.

The Asahi Linux RE process is a good way to understand how this kind of hardware RE worked pre-LLMs (and how LLMs learned to do it); they first constructed a hypervisor (m1n1) for the OS, then instrumented how the OS manipulated the hardware, then fuzzed the inputs to the OS to understand the resultant hardware-state-communication outputs.

I also doubt this driver will get too far down the game specialization rabbit hole, so they don't need to know quite as much; they seem to be targeting mostly basic display acceleration and GPGPU, so the stack of hacks isn't quite as tall.