Not logged inTalkContributionsCreate accountLog in

Build & Toolchain

From nexOS Wiki
Linux-only Makefile, QEMU with RTL8139/USB and VMware VGA, wallpaper packaging

Windows/MinGW path removed. The old start.bat + link_pe.ld (/DISCARD/ .idata/.reloc/.eh_frame) no longer exists in the tree. Build on Linux/WSL with NASM + 32-bit GCC. The bootloader now reads 60 sectors (was 40) because the kernel grew past 42 sectors.

Contents

[hide]

Requirements

  • NASM — bootloader (-f bin) + entry (-f elf32)
  • GCC with -m32 — freestanding kernel
  • binutils — ld, objcopy
  • QEMU — qemu-system-i386, 256 MiB, rtl8139, vmware VGA

Usage

make              # builds nexos.img
make run          # boots nexos.img in QEMU
make clean        # removes *.bin *.o *.tmp *.img

Build pipeline

boot.bin:        nasm -f bin boot.asm -o boot.bin
kernel_entry.o:  nasm -f elf32 kernel_entry.asm -o kernel_entry.o
ata.o:           gcc -m32 -ffreestanding -nostdlib -fno-pie -O2 -fleading-underscore -c ata.c
fat32.o / pci.o / acpi.o / usb.o:  gcc ... (same flags)
net.o:           gcc ... -c net.c
kernel.o:        gcc ... -c kernel.c
kernel.tmp:      ld -m elf_i386 -N -e _start -T link.ld -o kernel.tmp \
                    kernel_entry.o ata.o fat32.o pci.o acpi.o usb.o net.o kernel.o
                 + nm guard: _start must equal 0x8000 or link fails
kernel.bin:      objcopy -O binary kernel.tmp kernel.bin
wall.bin:        python3+PIL: wallpaper.jpg -> cover-crop 1024x768 raw RGB
                 + NEXOSW01 magic header (8B) + width/height
nexos.img:       dd zero 4864 sectors; dd boot.bin -> sector 0;
                 dd kernel.bin -> sector 1+; dd wall.bin -> sector 256
ToolRole
nasmAssembler
gccC compiler (freestanding, 32-bit)
ldLinker (ELF i386, entry _start)
objcopyStrip to raw binary
ddImage assembly (4864×512, wallpaper at LBA 256)
qemuEmulation

Disk image layout

nexos.img — ~2.4 MiB (4864 sectors x 512)
+---------------------------------------------+
| sector 0 | sectors 1..200 (kernel.bin)      |
| boot.bin | objcopy’d kernel (all objects) |
+---------------------------------------------+
| sector 256+    | wall.bin (NEXOSW01 magic,      |
|                | 1024x768 raw RGB, 4608 sect)   |
+---------------------------------------------+
dd if=/dev/zero of=nexos.img bs=512 count=4864
dd if=boot.bin    of=nexos.img bs=512 count=1 conv=notrunc
dd if=kernel.bin  of=nexos.img bs=512 seek=1 conv=notrunc
dd if=wall.bin    of=nexos.img bs=512 seek=256 conv=notrunc

Linker script (link.ld)

SECTIONS
{
    . = 0x8000;
    .text   : { kernel_entry.o(.text) *(.text) *(.text.startup) }
    .rodata : { *(.rodata) *(.rodata.*) }
    .data   : { *(.data) }
    .bss    : { *(.bss) }
}

kernel_entry.o(.text) first so _start lands at 0x8000 (the bootloader’s KERNEL_OFFSET).

Compiler flags

FlagEffect
-m3232-bit i386
-ffreestandingNo hosted assumptions
-nostdlibNo standard library
-fno-pieFixed 0x8000 base
-fleading-underscoreAsm expects _main/_isr* symbols
-O2Optimize
ld -N / -e _startRW text/data, entry symbol

QEMU invocation

qemu-system-i386 -drive format=raw,file=nexos.img \
  -device rtl8139,netdev=n0 -netdev user,id=n0 -vga vmware -m 256

-vga vmware lets high VESA modes probe; rtl8139 provides the NIC the driver expects at 0x300/IRQ11.