~run.sh
.sh
Shell
(text/x-sh)
#!/bin/bash

# Setup/cleanup
mkdir {bin,build} 2> /dev/null

echo -e "Cleaning artifacts..."
rm *.bin *.img *.iso *.o *.vmdk 2> /dev/null

# Build
echo -e "Building bootloader (asm)..."
nasm ./src/boot/bootloader.asm -I ./src/boot/ -o ./bin/bootloader.bin || exit 1

echo -e "Building kernel (asm)..."
nasm -felf32 ./src/kernel/asm/entry.asm -I ./src/kernel/asm/ -o ./build/kernelEntryPoint.o || exit 1

use_crystal_kernel=${USE_CRYSTAL_KERNEL:-true}
if [ "$use_crystal_kernel" = true ]
then
	# Build crystal kernel without stdlib, using the custom prelude, and targeting i386-unknown-linux-elf
  echo -e "Building kernel (crystal)..."
	crystal build \
		--no-debug \
		--cross-compile \
		--target i386-unknown-linux-elf \
		-Dkernel \
		--prelude=../prelude.cr \
		-o ./build/kernel ./src/kernel/kernel.cr || exit 1

	# Link the kernel into an ELF executable, then convert it to a flat binary for the bootloader.
	echo -e "Linking kernel.elf (ld)..."
	ld \
	  -m elf_i386 \
	  -nostdlib \
	  -T ./src/linker.ld \
	  -o ./bin/kernel.elf ./build/kernelEntryPoint.o ./build/kernel.o || exit 1
	
	# Copy kernel.elf to kernel.bin properly.
	echo -e "Building kernel.bin (objcopy)..."
	objcopy \
	  -O binary ./bin/kernel.elf ./bin/kernel.bin || exit 1
else
  # Flags
  CC_FLAGS="-ffreestanding -nostdinc -nostdinc++ -Wall -Wextra -o ./bin/kernel.bin -target i386-pc-none-elf -I ./src/kernel/archive/cpp/"
  LD_FLAGS="-nostdlib -Wl,--oformat=binary,-T./src/linker.ld"
  CPP_FILES="./src/kernel/archive/cpp/unityBuild.cpp ./build/kernelEntryPoint.o"

  # Build c++ kernel without stdlib, using the custom prelude, and targeting i386-unknown-linux-elf
  echo -e "Building kernel (cpp)..."
	clang++ -v \
	  $CC_FLAGS \
	  $LD_FLAGS \
	  $CPP_FILES || exit 1
fi

echo -e "Copy kernel.bin into iso/boot/"
cp ./bin/kernel.bin ./iso/boot/kernel.bin || exit 1

echo -e "Make bootable crystalos.img (genVDisk)..."
./tools/genVDisk \
  --output "crystalos" \
  --floppy \
	--bootloader ./bin/bootloader.bin \
	--kernel ./bin/kernel.bin || exit 1

if [ -f "crystalos" ]
then
  # some platforms produce a no ext file, so we rename it to .img, eventually.
	mv crystalos crystalos.img || exit 1
fi

# Run
echo -e "Booting into crystalos.img (qemu)..."

use_vnc=${USE_VNC:-false}
if [ "$use_vnc" = true ]
then
  qemu-system-i386 -drive if=floppy,index=0,format=raw,file=crystalos.img || exit 1
else
  qemu-system-i386 -drive if=floppy,index=0,format=raw,file=crystalos.img -display curses || exit 1
fi

exit 0

GitFOSS - v0.2.0 (#48b426e) - MIT License