Files
2025-02-25 01:14:52 +00:00

29 lines
839 B
Bash
Executable File

#!/bin/bash
set -e
# Set root directory
cd "$(dirname "$0")/.."
# Create build directory if it doesn't exist
mkdir -p build/bios
# Compile C code
gcc -m32 -ffreestanding -fno-pie -fno-stack-protector -nostdlib -nodefaultlibs \
-Wall -Wextra -O2 -c boot/bios/stage2/stage2.c -o build/bios/stage2.o
# Assemble boot code
nasm -f elf32 boot/bios/stage2/boot.s -o build/bios/boot.o
# Link to binary
ld -m elf_i386 -T boot/bios/stage2/stage2.ld \
build/bios/boot.o \
build/bios/stage2.o \
-o build/bios/stage2.bin
# Verify size (stage2 can be multiple sectors, but let's warn if it's too large)
size=$(wc -c < build/bios/stage2.bin)
if [ "$size" -gt 32768 ]; then # 64 sectors (32KB) should be plenty
echo "Warning: stage2.bin is larger than 32KB ($size bytes)"
fi
echo "Successfully built stage2.bin ($size bytes)"