UEFI Game Development with LLMs: An AI Coding Debugging Retrospective
This article reports a practical test of large language models in UEFI game development, where limited documentation, constrained tooling, and high failure costs expose engineering weaknesses. Two models were asked to build Breakout and Tetris; one compiled and ran, while the other did not finish setting up the build environment. The better-performing model then took over a seven-file legacy codebase in two phases: reviewing and fixing a crash, then investigating missing graphics. The article documents the debugging process, a reusable checklist, and the limits of model-generated conclusions, which still require human verification through logs and runtime tests.
1. Why Test in a UEFI Environment
It is already difficult to differentiate large language models on LeetCode-style algorithm problems. Engineering scenarios with scarce references, many constraints, and low fault tolerance better reflect real capability. UEFI development satisfies all three:
- Scarce references: Most development happens above the operating system. Applications that run directly at the firmware layer are a niche area with less representation in training data.
- Many constraints: There is no standard library, common debuggers are unavailable, and output mainly depends on serial logs and direct framebuffer writes.
- High cost of errors: A single pointer error can cause the program to exit directly, with no exception-handling fallback.
In the test, I asked Model A and Model B to develop Breakout and Tetris respectively. Model A completed compilation and ran relatively quickly. Model B took a long time and still had not set up the build environment. Because the two tasks were different, this result cannot be treated as a direct ranking of model capability, but it prompted a second round of testing.
Risk note: UEFI application development involves the firmware layer. Experiment in a virtual machine (such as QEMU) or an isolated test machine, back up the existing firmware before making changes, and do not flash production devices or daily work machines directly.
2. Handing Legacy Code to AI
Some might argue that comparing two different tasks is unfair. That is a valid point. However, taking over a legacy codebase that is “well structured but does not actually run” is itself a test for a model.
The failed code had seven source files with clear module separation, including the entry function, main loop, game logic, rendering, and input handling. The problems were in the details. In the second round, I copied this code as-is into a new environment and handed it to the better-performing Model A, proceeding in two phases: first make the program basically run, then optimize it.
3. Phase One: Review and Crash Triage
3.1 Review Capability
The first instruction was: review this code and identify possible issues. The model did not speak in generalities. It checked module by module and produced a structured issue list within minutes, covering initialization order, pointer lifetime, protocol acquisition, and related areas. It also claimed that the code would run after the fixes.
Useful entries from the list can be organized into the following review template:
- Initialization order: Are protocols and resources initialized before use?
- Pointer lifetime: Who allocates a pointer returned by a function, and when is it released?
- Protocol acquisition: Does the GUID used correspond to the required protocol, and is the return value checked?
- Error handling: Is the return status of critical calls checked?
3.2 Problem One: The Program Crashes
Actual execution produced only partial results. The program started, printed “Starting Game Loop”, and then exited. This was better than failing to compile at all, but still far from the goal.
During troubleshooting, I asked the model to add debug output and observe execution progress through the serial port. The logs showed that the program exited after a Graphics Output Protocol (GOP) call. The model initially concluded that the Info pointer returned by QueryMode became invalid after SetMode.
That judgment needed correction. In the UEFI specification, Info is allocated by QueryMode, and the caller should release it through FreePool after use. SetMode itself does not necessarily invalidate that memory. A more robust approach is: after SetMode, read the current mode information and framebuffer address directly from GOP->Mode, rather than relying on a previously saved pointer.
// Illustrative code; error checks omittedGOP->QueryMode(GOP, ModeNum, &SizeOfInfo, &Info);FreePool(Info); // Released by caller after useGOP->SetMode(GOP, ModeNum);FrameBase = GOP->Mode->FrameBufferBase; // Read from current modePitch = GOP->Mode->Info->PixelsPerScanLine;
After this change, the crash no longer appeared. However, this retrospective did not preserve complete serial logs and runtime environment information, so it cannot confirm that this change was the sole cause of the crash. When encountering similar issues, first confirm the root cause through logs and call stacks.
3.3 Problem Two: Nothing Is Displayed
The program no longer crashed, but the screen still did not appear. After I fed the symptom back to the model, it pointed to the Graphics Output Protocol acquisition process and suspected an error in GUID or protocol instance acquisition.
UEFI has many graphics-related GUIDs and protocols with similar names, making them easy to select incorrectly. The standard Graphics Output Protocol GUID is named EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID. This retrospective did not retain specific error logs, so it cannot determine whether the problem was here. This step may be a GUID or protocol-instance acquisition issue and needs item-by-item verification against logs.
4. Reusable Checklist
After the retrospective, I organized the approach into a checklist for direct use next time.
Environment setup
- Develop in a virtual machine or isolated machine, and keep a firmware backup.
- Record the versions of the compiler, development framework, and runtime environment.
Log collection
- Output serial information before and after key steps, indicating the current stage.
- Check return values and pointers, and print status codes.
Review
- Ask the model to list issues module by module and explain the basis for each issue.
- Verify every conclusion from the model against logs or code locations.
Phased acceptance
- Phase one criterion: the program can start, enter the main loop, and not crash.
- Phase two criterion: graphics are correct, input responds normally, and the code structure remains clear.
The core of this checklist is to make every step verifiable. Conclusions from the model need to be confirmed through logs and actual execution.
5. Conclusion
In this case, the large language model could write clearly structured code and find clues from logs. But its judgments still require human verification; the pointer cause above is one example. In this type of task, it can take on part of junior engineering work. Humans still need to provide clear symptom descriptions, feedback loops, and stage goals, and remain responsible for final verification and backstop.
