#!/bin/sh -e print_u32() { printf "\\$(printf %o $(($1&0xFF)))\\$(printf %o $((($1 >> 8)&0xFF)))\\$(printf %o $((($1 >> 16)&0xFF)))\\$(printf %o $((($1 >> 24)&0xFF)))" } write_u32() { print_u32 $1 | dd if=/dev/stdin of=$3 conv=notrunc bs=1 seek=$2 status=none } # :Tell hare to use our custom runtime # and linker scripts (this feature is so simple and neat :)) export HAREPATH=. # :Tell the linker to add this argument to discard # unused sections export LDFLAGS="--gc-sections" # :Do the build hare build -X^ -T+x86_64 -T+bios # :Create a flat binary out of the elf file # (while also removing the breaking gnu note) objcopy \ --remove-section .note.gnu.property \ -I elf64-x86-64 -O binary \ --binary-architecture=i386:x86-64 \ boot boot.bin size=$(stat -c %s boot.bin) sectors=$((size/512 + 1)) write_u32 1 $((446 + 8)) boot.bin write_u32 $sectors $((446 + 12)) boot.bin [ -f boot.img ] && rm boot.img ../gptman/gptman convert boot.bin boot.img chmod +rw boot.img bochs