Limine Bare Bones: Difference between revisions

Build system backports from limine-c-template
[unchecked revision][unchecked revision]
mNo edit summary
(Build system backports from limine-c-template)
Line 11:
This article will demonstrate how to write a small x86-64 higher half Limine-compliant kernel in [[C]], and boot it using the [[Limine]] bootloader.
 
It is also very recommended to check out [https://github.com/limine-bootloader/limine-barebonesc-template this template project] as it provides example buildable code to go along with this guide.
 
===Overview===
Line 218:
# This is the name that our final kernel executable will have.
# Change as needed.
override KERNEL := myos.elf
 
# Convenience macro to reliably declare user overridable variables.
Line 276:
# Internal C preprocessor flags that should not be changed by the user.
override CPPFLAGS := \
-I. src \
$(CPPFLAGS) \
-MMD \
Line 299:
# Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the
# object and header dependency file names.
override CFILES := $(shell cd src && find -L .* -type f -name '*.c' | grep -v 'limine/')
override ASFILES := $(shell cd src && find -L .* -type f -name '*.S' | grep -v 'limine/')
override NASMFILES := $(shell cd src && find -L .* -type f -name '*.asm' | grep -v 'limine/')
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o))
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
 
# Default target.
.PHONY: all
all: bin/$(KERNEL)
 
# Link rules for the final kernel executable.
bin/$(KERNEL): GNUmakefile linker.ld $(OBJ)
mkdir -p "$$(dirname $@)"
$(LD) $(OBJ) $(LDFLAGS) -o $@
 
Line 317 ⟶ 318:
 
# Compilation rules for *.c files.
obj/%.c.o: src/%.c GNUmakefile
mkdir -p "$$(dirname $@)"
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
 
# Compilation rules for *.S files.
obj/%.S.o: src/%.S GNUmakefile
mkdir -p "$$(dirname $@)"
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
 
# Compilation rules for *.asm (nasm) files.
obj/%.asm.o: src/%.asm GNUmakefile
mkdir -p "$$(dirname $@)"
nasm $(NASMFLAGS) $< -o $@
 
Line 331 ⟶ 335:
.PHONY: clean
clean:
rm -rf $(KERNEL)bin $(OBJ) $(HEADER_DEPS)obj
</source>
 
Line 348 ⟶ 352:
 
# Path to the kernel to boot. boot:/// represents the partition on which limine.cfg is located.
KERNEL_PATH=boot:///myos.elf
 
# Same thing, but without KASLR.
Line 357 ⟶ 361:
KASLR=no
 
KERNEL_PATH=boot:///myos.elf
</source>
 
===Compiling the kernel===
 
We can now build our example kernel by running '''make'''. This command, if successful, should generate a file called '''myos.elf''' (or the chosen kernel name). This is our Limine protocol-compliant kernel executable.
 
===Creating the image===
Line 387 ⟶ 391:
 
# Copy the relevant files over.
cp -v myos.elf limine.cfg limine/limine-bios.sys \
limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/
 
Line 437 ⟶ 441:
 
# Copy over the relevant files
mcopy -i image.hdd@@1M myos.elf limine.cfg limine/limine-bios.sys ::/
mcopy -i image.hdd@@1M limine/BOOTX64.EFI ::/EFI/BOOT
mcopy -i image.hdd@@1M limine/BOOTIA32.EFI ::/EFI/BOOT
Line 456 ⟶ 460:
 
* [https://github.com/limine-bootloader/limine/blob/trunk/PROTOCOL.md Limine protocol specification]
* [https://github.com/limine-bootloader/limine-barebonesc-template Buildable Limine Bareprotocol Bonesbased kernel project template in C]
 
[[Category:Bare bones tutorials]]
Anonymous user