#!/bin/sh
# Build.sh
set -e

nasm boot.asm -f bin -o boot.bin

smlrc kernel.c kernel.asm

cat > kernel_entry.asm << 'EOF'
bits 16
org 0x0000

section .text
global _start

_start:
    ; Set DS = CS
    push cs
    pop ds

    call _main ; Call main
    
    ; Hang
    cli
    hlt

; Include the generated code
%include "kernel.asm"
EOF

nasm kernel_entry.asm -f bin -o kernel.bin

cat boot.bin kernel.bin > os.img

qemu-system-i386 -fda os.img -monitor stdio -d int -m 1M
