10‐004. Bare Bones - skybonep/fishboneOS GitHub Wiki
Preparation
The Cross Compiler is ready.
boot.s
i686-elf-as boot.s -o boot.o
Why bootstrap must be written by assembly but cannot written in C?
C requires a stack, but bootstrap code runs BEFORE any stack exists.
Bottom line: Assembly = "create universe from nothing". C = "work within universe". Bootstrap needs the former
kernel.c
i686-elf-gcc -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
linker.ld
Build the kernel myos.bin from boot.o and kernel.o
i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc
Building a bootable cdrom image
Need to install:
sudo apt-get install xorriso
sudo apt-get install mtools
sudo apt-get install qemu-system-x86
grub.cfg:
menuentry "myos" {
multiboot /boot/myos.bin
}
grub-mkrescue -o myos.iso isodir
And it works!
qemu-system-i386 -cdrom myos.iso
qemu-system-i386 -kernel myos.bin
It works in read hardware too! (Well, not exactly working, some VGA mode not support. But i think it is ok for now.)
sudo dd if=myos.iso of=/dev/sdx && sync
Reference: https://wiki.osdev.org/Bare_Bones
Created: 20251225