-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·108 lines (95 loc) · 3.28 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·108 lines (95 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# =============================================================
# VM Build Pipeline
# Usage:
# ./build.sh [program] — standalone (direct cpu run)
# ./build.sh [program] --os — full OS (boot → kernel → program)
# ./build.sh [program] --headless — standalone, no window
# =============================================================
set -e
PROGRAM=""
OS_MODE=false
HEADLESS=""
DEBUG=""
for arg in "$@"; do
case "$arg" in
--os) OS_MODE=true ;;
--headless) HEADLESS="--headless" ;;
--debug) DEBUG="--debug" ;;
-*) echo "Unknown flag: $arg"; exit 1 ;;
*) PROGRAM="$arg" ;;
esac
done
PROGRAM="${PROGRAM:-dvd}"
ASM_FILE="programs/${PROGRAM}.asm"
# --- Validate program ---
if [ ! -f "$ASM_FILE" ]; then
echo "Error: No such program: $ASM_FILE"
echo ""
echo "Available programs:"
for f in programs/*.asm; do
name=$(basename "$f" .asm)
case "$name" in boot|kernel|boot_temp|crt0) continue ;; esac
./assembler "$f" "${name}.bin" 20000 >/dev/null
done
exit 1
fi
echo "┌──────────────────────────────────────┐"
echo "│ VM Build Pipeline │"
if $OS_MODE; then
echo "│ Mode: Full OS │ Program: $PROGRAM"
else
echo "│ Mode: Standalone │ Program: $PROGRAM"
fi
echo "└──────────────────────────────────────┘"
echo ""
# Step 1: Build tools
printf "[ 1/5 ] Building tools... "
make -s all
echo "done"
# Step 2: Generate font
printf "[ 2/5 ] Generating font... "
./font_maker > /dev/null
echo "done"
# Step 3: Assemble
printf "[ 3/5 ] Assembling... "
if $OS_MODE; then
# Compile the C Kernel
../chibicc/chibicc -S -o programs/kernel_temp.asm programs/kernel.c
cat programs/crt0.asm programs/kernel_temp.asm > programs/kernel.asm
# Assemble Bootloader & Kernel
./assembler programs/boot.asm boot.bin >/dev/null
./assembler programs/kernel.asm kernel.bin 4096 >/dev/null
# Assemble ALL other programs to be included on the disk
for f in programs/*.asm; do
name=$(basename "$f" .asm)
case "$name" in boot|kernel|kernel_temp|crt0) continue ;; esac
./assembler "$f" "${name}.bin" 200000 >/dev/null # <-- Changed to 200000
done
else
# STANDALONE C COMPILATION FIX
if [ -f "programs/${PROGRAM}.c" ]; then
../chibicc/chibicc -S -o programs/${PROGRAM}_temp.asm programs/${PROGRAM}.c
cat programs/crt0.asm programs/${PROGRAM}_temp.asm > programs/${PROGRAM}.asm
fi
./assembler "programs/${PROGRAM}.asm" "${PROGRAM}.bin" >/dev/null
fi
echo "done"
# Step 4: Build disk image
if $OS_MODE; then
printf "[ 4/5 ] Building disk image... "
# Grab all compiled binaries EXCEPT boot and kernel
FILES=$(ls *.bin | grep -v "boot.bin" | grep -v "kernel.bin")
./imager drive.img boot.bin kernel.bin font.bin $FILES 2>&1 | grep -v "^$" | sed 's/^/ /'
echo ""
else
echo "[ 4/5 ] Disk image skipped (standalone mode)"
fi
# Step 5: Launch
echo "[ 5/5 ] Launching: $PROGRAM"
echo ""
if $OS_MODE; then
./cpu $HEADLESS $DEBUG
else
./cpu "${PROGRAM}.bin" $HEADLESS $DEBUG
fi