Build & Toolchain
From nexOS Wiki
Linux-only Makefile, QEMU with RTL8139 and VMware VGA
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: gcc ... -c fat32.c
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 net.o kernel.o
kernel.bin: objcopy -O binary kernel.tmp kernel.bin
nexos.img: dd zero 64 sectors; dd boot.bin -> sector 0; dd kernel.bin -> sector 1+
| Tool | Role |
|---|---|
| nasm | Assembler |
| gcc | C compiler (freestanding, 32-bit) |
| ld | Linker (ELF i386, entry _start) |
| objcopy | Strip to raw binary |
| dd | Image assembly (64×512) |
| qemu | Emulation |
Disk image layout
nexos.img — 32,768 bytes (64 sectors x 512) +---------------------------------------------+ | sector 0 | sectors 1..63 (kernel.bin padded)| | boot.bin | objcopy'd kernel (ata+fat32+net) | +---------------------------------------------+ dd if=/dev/zero of=nexos.img bs=512 count=64 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
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
| Flag | Effect |
|---|---|
| -m32 | 32-bit i386 |
| -ffreestanding | No hosted assumptions |
| -nostdlib | No standard library |
| -fno-pie | Fixed 0x8000 base |
| -fleading-underscore | Asm expects _main/_isr* symbols |
| -O2 | Optimize |
| ld -N / -e _start | RW 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.
Categories: nexOS | Development