Programming Space Game For X86 In Assembly Without An Operating System

Some assembly code

In this video our hacker [Inkbox] shows us how to create a computer game that runs directly on computer hardware, without an operating system!

[Inkbox] briefly explains what BIOS is, then covers how UEFI replaces it. He talks about the genesis of UEFI from Intel in the late 90s. After Intel’s implementation of UEFI was made open source it got picked up by the TianoCore community who make tools such as the TianoCore EDK II.

[Inkbox] explains that the UEFI implementation provides boot services and runtime services. Boot services include things such as loading memory management facilities or running other UEFI applications, and runtime services include things like system clock access and system reset. In addition to these services there are many more UEFI protocols that are available.

[Inkbox] tells us that when an x64 CPU boots it jumps to memory address 0xfffffff0 that contains the initialization instructions which will enter protected mode, verify the firmware, initialize the memory, load the storage and graphics drivers, then run the UEFI Boot Manager. The UEFI Boot Manager will in turn load the appropriate EFI application, such as the firmware settings manager application (the “BIOS settings”), Windows Boot Manager, or GRUB. In this video we make our very own EFI application that the UEFI Boot Manager can be configured to load and run.

The system used for development and testing has a AMD Ryzen AI 9 HX 370 CPU and 32GB DDR5 RAM.

Having explained how everything gets started [Inkbox] goes on to explain how to write and deploy the assembly language program which will load and play the game. [Inkbox] shows how to read and write to the console and mentions that he did his testing on QEMU with an image on an external USB thumbdrive. He goes on to show how to use the system time and date facilities to get the current month. When trying to read nanoseconds from the system clock he ended up needing to refer to the UEFI Specification Release 2.10 (2.11 is latest as of this writing).

In the rest of the video [Inkbox] does some arithmetic for timing, uses LocateProtocol to load the graphics output provider, configures an appropriate video mode, writes to the screen using BLT operations, and makes the program run on multiple CPU cores (the CPU used has 24). At last, with some simple graphics programming and mouse input, [Inkbox] manages to get Space Game for x86 to run.

If you’re interested in knowing more about UEFI a good place to start is What’s The Deal With UEFI?

10 thoughts on “Programming Space Game For X86 In Assembly Without An Operating System

  1. I understand it can be an interesting challenge, but is there any advantage to bare metal programming over relying on an OS for handling all the annoying and device specific nitty gritty?

    1. I can’t think of any advantage at all. Trying to program a computer without an operating system is not a good idea, except if your goal is to understand more about how the machine works…

        1. Yeah maybe some small theoretical performance boost but none that would be worth the insane development costs you’d be taking on. Ordinarily when you write a normal program that runs in an operating system the program runs in user space and you need to syscall into the operating system to do things the OS facilitates (reading and writing files, for instance). Those syscalls have some overhead. I guess the other thing you could do if you wanted to largely avoid OS overhead is to implement your program as a kernel module or device driver. But operating systems do a lot of good things that you don’t want to throw away or live without.

          1. There are a couple of synthesizers that run bare-metal (so without the Linux OS) on a raspberry pi, that way they can get realtime performance, even on older pi’s.

        2. You may be able to optimize a tiny portion of your code to be blazingly fast, but more than likely that will make the rest of your code suffer. Compilers today generally do a much better job than any individual person.

Leave a Reply to bebopCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.