A minimal kernel in Swift, running in QEMU
On the 28th of September 2026, Max Desiatov informed the reporter that the @c swift attribute, which marks global functions as C functions implemented in Swift, should be used instead of @_cdecl. The source material details the author's experiment in writing a minimal Swift kernel for the QEMU machine emulator. The goal is not to replace an existing operating system like Linux, but rather to gain a deeper understanding of what is needed to make a program run without an underlying OS.
The Swift kernel developed for this experiment only prints a message through QEMU and then waits indefinitely. To achieve this, the author used Embedded Swift, a subset of Swift designed for environments without an OS and standard library. The project required using a development toolchain due to the lack of Embedded Swift support in public Swift releases.
The kernel was tested on a machine emulator called QEMU running on an Apple Silicon machine. The target machine was described as a 64-bit ARM machine with no OS and no environment provided by a C runtime, identified by the target "aarch64-none-none-elf". The Swift code was compiled for this bare-metal target, which lacked a normal C standard library, hence the absence of functions like putchar and memmove.
The author had to manually configure a stack and specify the program's starting point. The linker script had to explicitly place certain ELF sections to avoid orphan-section errors. The boot code was placed first, followed by read-only data, initialized data, uninitialized data, and a stack. The stack pointer was initialized using the __stack_top symbol.
The assembly code was written to initialize the stack and serve as the kernel's entry point. The PL011 UART, a serial output driver, was used to output characters to the terminal. The emulator received these characters, displaying them in the terminal due to the -nographic option.
The linker script also placed ELF metadata sections to ensure the linker did not generate orphan-section errors. The kernel was designed to run forever in an infinite loop, currently displaying the message "hello" in the terminal. Future steps for the project include implementing additional features like a framebuffer, a real keyboard driver, and a minimal interactive environment.
Rewritten by urgent.news; may contain errors — check the original.
Source: carette.xyz