Page 1 of 1

gkos - Cortex M7 OS for a handheld game console

Posted: Tue Apr 15, 2025 12:16 pm
by jnc100
This is a little project I have been working on for a little over a year. gkos is an operating system for a STM32H7S7 (Cortex M7) microcontroller that allows it to work (surprisingly well) as a handheld game console.

Unlike RTOSs gkos has no realtime guarantees but rather aims to be a general purpose operating system for this chip. Currently it is sufficiently full-featured to run userspace libraries including SDL1/2, Mesa 4 software rendering, FluidSynth, OpenAL, Ogg/Vorbis, TCL etc. This allows it to run emulators including Mednafen and Hatari at playable framerates as well as native ports of Doom, Quake, Descent and Red Alert.

The "interesting" features of the OS are documented in https://github.com/jncronin/gk/tree/main/Firmware/doc. Features include:

- Priority based round robin scheduler
- Standard synchronization primitives to support pthreads
- IPv4 networking (with USB RNDIS and Wifi drivers)
- Buddy system for memory block allocation - this ensures power-of-2 alignment for memory blocks which is required by the memory protection unit
- Internal SD card driver
- Lwext4 as the VFS file system driver
- ELF loader with support for the "hot" attribute to place these functions in faster RAM if possible
- Relocating static binaries for the MMU-less Cortex M7 (it has a memory protection unit to catch unauthorised accesses but no virtual memory support)
- Hardware accelerated rendering using the various peripherals of the STM32 - GFXMMU for vertical hardware scaling, DMA2D for fast blits, GPU2D for very experimental hardware triangle rasterisation
- Sound output to a PCM chip
- The SD driver, ext4 driver, GPU driver, USB driver and network drivers all run in their own separate kernel threads similar to a microkernel. In particular, for most kernel services there are built-in methods to restart any critical process on failure.

Otherwise it exposes a relatively standard POSIX syscall interface, and there are corresponding userspace libraries (gcc toolchain, newlib, ports of above listed libraries) at https://github.com/jncronin/gk-userland. However, being a microcontroller startup is nearly instantaneous.

There are images of the system in action at https://github.com/jncronin/gk and a video at https://www.youtube.com/watch?v=_2ip4UrAZJk