-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtbuild.sh
More file actions
executable file
·84 lines (75 loc) · 2.08 KB
/
Copy pathtbuild.sh
File metadata and controls
executable file
·84 lines (75 loc) · 2.08 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
#!/bin/sh
# =============================================================================
# tbuild — the glowieStopper compilation pipeline driver.
# =============================================================================
# Runs the toolchain end-to-end:
#
# foo.s --(tasm0)--> hex --(seed)--> foo.img
#
# Usage:
# ./tbuild.sh <source.s> [output.img]
# ./tbuild.sh all # build everything in boot/*.s
# ./tbuild.sh test # run the toolchain self-tests
# ./tbuild.sh demo # build & note the mbr_hello demo
#
# Zero C, zero Python, zero external assembler. Uses only:
# - POSIX sh + awk + printf (host escape hatch)
# - ./build/tools/seed (our own hand-crafted 331-byte ELF)
# =============================================================================
set -eu
ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT"
TASM0="$ROOT/toolchain/tasm0/tasm0.sh"
SEED="$ROOT/build/tools/seed"
OUTDIR="$ROOT/build"
die() { echo "tbuild: $*" >&2; exit 1; }
need_seed() {
if [ ! -x "$SEED" ]; then
die "$SEED not found. Run ./bootstrap/verify.sh first to build it from hex."
fi
}
assemble() {
src="$1"
out="${2:-}"
[ -f "$src" ] || die "no such file: $src"
need_seed
mkdir -p "$OUTDIR"
if [ -z "$out" ]; then
out="$OUTDIR/$(basename "${src%.s}").img"
fi
"$TASM0" "$src" | "$SEED" > "$out"
size=$(wc -c < "$out")
echo " $src -> $out ($size bytes)"
}
run_tests() {
echo "[tbuild] tasm0 self-tests"
"$ROOT/toolchain/tasm0/tests/run.sh"
}
build_all() {
for s in "$ROOT"/boot/*.s; do
[ -f "$s" ] || continue
assemble "$s"
done
}
case "${1:-}" in
""|-h|--help)
sed -n '2,20p' "$0"
;;
test)
run_tests
;;
all)
run_tests
build_all
;;
demo)
run_tests
assemble "$ROOT/boot/mbr_hello.s"
echo
echo "Boot the demo with:"
echo " qemu-system-x86_64 -drive file=$OUTDIR/mbr_hello.img,format=raw -serial stdio"
;;
*)
assemble "$1" "${2:-}"
;;
esac