11#! /bin/bash
22
3- nasm -f bin -o build/boot.bin boot.asm
4- nasm -f bin -o build/zeroes.bin bootloader/zeroes.asm
5- nasm -f elf -o build/kernel_entry.o bootloader/kernel_entry.asm
6- nasm -f elf -o build/printk.o kernel/lib/std/printk.asm
7- i386-elf-gcc -ffreestanding -m32 -g -c kernel/kernel.c -o build/kernel.o
3+ # Parse arguments
4+ POSITIONAL_ARGS=()
85
9- i386-elf-ld -o build/full_kernel.bin -Ttext 0x1000 build/* .o --oformat binary
6+ Usage ()
7+ {
8+ echo -e " Usage:\t./run.sh binutils-prefix ... i386-prefix ..."
9+ echo -e " \t./run.sh bp ... ip ...\n"
10+ echo -e " \tbinutils-prefix\t\tbp\tPath to cross compiled binutils"
11+ echo -e " \ti386-prefix\t\tip\tPath to cross compiled GCC i386 elf"
1012
11- cat build/boot.bin build/full_kernel.bin build/zeroes.bin > build/OS.bin
13+ }
1214
13- qemu-system-x86_64 -drive format=raw,file=" build/OS.bin" ,index=0,if=floppy, -m 128M
15+ while [[ $# -gt 0 ]]; do
16+ case $1 in
17+ bp | binutils-prefix)
18+ BIN_PREFIX=" $2 "
19+ shift
20+ shift
21+ ;;
22+ ip | i386-prefix)
23+ GCC_PREFIX=" $2 "
24+ shift
25+ shift
26+ ;;
27+ help)
28+ Usage
29+ shift
30+ ;;
31+ * )
32+ echo " Unknown option $1 "
33+ exit 1
34+ ;;
35+ * )
36+ POSITIONAL_ARGS+=(" $1 " )
37+ shift
38+ ;;
39+ esac
40+ done
41+
42+ # Compile OS
43+
44+ if [[ -z " $GCC_PREFIX " ]] || [[ -z " $BIN_PREFIX " ]] ; then
45+ Usage
46+ exit 2
47+ fi
48+
49+ /usr/bin/nasm -f bin -o build/boot.bin boot.asm
50+ if [ $? != 0 ] ; then
51+ echo " E: Bootloader compilation failed"
52+ exit 3
53+ fi
54+
55+ /usr/bin/nasm -f bin -o build/zeroes.bin bootloader/zeroes.asm
56+ if [ $? != 0 ] ; then
57+ echo " E: Zeroes offset compilation failed"
58+ exit 3
59+ fi
60+
61+ /usr/bin/nasm -f elf -o build/kernel_entry.o bootloader/kernel_entry.asm
62+ if [ $? != 0 ] ; then
63+ echo " E: Kernel entry compilation failed"
64+ exit 3
65+ fi
66+ /usr/bin/nasm -f elf -o build/printk.o kernel/lib/std/printk.asm
67+ if [ $? != 0 ] ; then
68+ echo " E: Library compilation failed"
69+ exit 3
70+ fi
71+
72+ $GCC_PREFIX /i386-elf-gcc -ffreestanding -m32 -g -c kernel/kernel.c -o build/kernel.o
73+ if [ $? != 0 ] ; then
74+ echo " E: Kernel compilation failed"
75+ exit 4
76+ fi
77+
78+ $BIN_PREFIX /i386-elf-ld -o build/full_kernel.bin -Ttext 0x1000 build/* .o --oformat binary
79+ if [ $? != 0 ] ; then
80+ echo " E: Linking failed"
81+ exit 5
82+ fi
83+
84+ /bin/cat build/boot.bin build/full_kernel.bin build/zeroes.bin > build/OS.bin
85+ if [ $? != 0 ] ; then
86+ echo " E: Kernel packing failed"
87+ exit 6
88+ fi
89+
90+ /usr/bin/qemu-system-x86_64 -drive format=raw,file=" build/OS.bin" ,index=0,if=floppy, -m 128M
0 commit comments