Writing bare-metal apps in C

In times of ever growing software complexity, it can be fun to see your programs running right on top of bare hardware. Unfortunately, modern consumer devices like smartphones make it next to impossible for hobbyists to build low-level apps. Even on purposefully programmable platforms like Arduino or RPi, accessing keyboards and displays can be mundane and heavily tied to a particular device.

On the other hand, PCs shipped for decades with a legacy, but fun and hackable 16-bit platform, featuring standarized firmware (BIOS) for accessing input and output devices. For some reason though, there hasn't been really a culture of building standalone apps for this platform. Most (if not all) bare-bones tutorials seem to focus either on tiny bootsector-sized demos, or entire operating systems.

I wondered how hard would it be to boot a PC straight into a C app, and use BIOS to handle the keyboard and the display. It turned out surprisingly simple, requiring only need 3 pieces of assembly to get started:

The rest is just plain C code of the app. You can find a sample repo demonstrating my approach on https://github.com/luke8086/boot2c

screenshot

~luke, 2019-09-29 (updated 2022-09-10)