This repository will demonstrate how to set up a basic x86-64 kernel in C using Limine.
It is recommended to cross reference the contents of this repository with the Limine Bare Bones OSDev wiki page.
Any make command depends on GNU make (gmake) and is expected to be run
using it. This usually means using make on most GNU/Linux distros, or gmake
on other non-GNU systems.
All make all* targets depend on a GNU-compatible C toolchain capable of
generating x86-64 ELF objects. Usually gcc/binutils or clang/llvm/lld
provided by any x86-64 UNIX like (including Linux) distribution will suffice.
Building also requires git, used to fetch the kernel's dependencies (see
kernel/get-deps), curl, used to download the Limine release and the EDK2
OVMF firmware images, and a C compiler for the host (cc by default, see the
HOST_CC make variable), used to build the limine host utility.
Additionally, building an ISO with make all requires xorriso, and building
a HDD/USB image with make all-hdd requires sgdisk (usually from gdisk or
gptfdisk packages) and mtools.
Assembly files with the *.S extension are built using the same toolchain as
the C sources. Only *.asm files, of which the template ships none, require
nasm. The run targets require qemu.
The TOOLCHAIN and TOOLCHAIN_PREFIX make variables can be used to set the
toolchain. TOOLCHAIN can be set to llvm to use Clang/LLVM.
For example:
make TOOLCHAIN=llvm
or:
make TOOLCHAIN_PREFIX=x86_64-elf-
The kernel is linked through the compiler driver, using its default linker for
GCC and LLD for Clang. A different linker can be picked by adding a -fuse-ld=
option to LDFLAGS.
Link-time optimisation can be enabled by adding -flto to CFLAGS, for
example:
make CFLAGS='-g -O2 -pipe -flto'
Running make all will compile the kernel (from the kernel/ directory) and
then generate a bootable ISO image.
Running make all-hdd will compile the kernel and then generate a raw image
suitable to be flashed onto a USB stick or hard drive/SSD.
Running make run will build the kernel and a bootable ISO (equivalent to make
all) and then run it using qemu (if installed).
Running make run-hdd will build the kernel and a raw HDD image (equivalent to
make all-hdd) and then run it using qemu (if installed).
The run-uefi and run-hdd-uefi targets are equivalent to their non -uefi
counterparts except that they boot qemu using a UEFI-compatible firmware.