boot3.sh (4047B)
1 #!/bin/sh 2 ## boot3.sh — bootstrap tcc0 from cc.scm. 3 ## 4 ## Stage A of the four-stage tcc chain: cc.scm compiles tcc.flat.c into 5 ## tcc0. boot4 picks up tcc0 and self-hosts the rest of the chain 6 ## (tcc0 → tcc1 → tcc2 → tcc3, with tcc2 == tcc3 as the fixed-point 7 ## check). 8 ## 9 ## tcc0 = tcc-source compiled by cc.scm ← produced here 10 ## tcc1 = tcc-source compiled by tcc0 ← boot4 11 ## tcc2 = tcc-source compiled by tcc1 ← boot4 12 ## tcc3 = tcc-source compiled by tcc2 ← boot4 13 ## 14 ## ─── Inputs (sources, from canonical tree) ─────────────────────────── 15 ## build/$ARCH/src/src/scheme1/prelude.scm scheme bundle 16 ## build/$ARCH/src/src/cc/{cc.scm, main.scm} scheme bundle 17 ## build/$ARCH/src/src/P1/{P1-$ARCH.M1pp, P1.M1pp, P1pp.P1pp} M1pp pipeline 18 ## build/$ARCH/src/src/P1/{entry-libc.P1pp, elf-end.P1pp} link framing 19 ## build/$ARCH/src/src/vendor-seed/ELF.hex2 ELF header 20 ## build/$ARCH/src/src/tcc/tcc.flat.c flattened tcc TU 21 ## build/$ARCH/src/src/libc/libc.flat.c flattened mes-libc TU 22 ## 23 ## ─── Inputs (binaries from prior stages) ────────────────────────────── 24 ## build/$ARCH/$DRIVER/boot1/{M1pp, hex2pp} 25 ## build/$ARCH/$DRIVER/boot2/{catm, scheme1} 26 ## 27 ## ─── Tools ──────────────────────────────────────────────────────────── 28 ## scheme1 evaluates scripts/boot3-run.scm against the flat staging 29 ## root. Same run.scm drives both DRIVER=podman (cwd=/work) and 30 ## DRIVER=seed (cwd=/). Stage A is pure scheme1 + M1pp + hex2pp; no 31 ## asm step. 32 ## 33 ## ─── Outputs ────────────────────────────────────────────────────────── 34 ## build/$ARCH/$DRIVER/boot3/tcc0 — cc.scm-built bootstrap tcc 35 ## build/$ARCH/$DRIVER/boot3/libc.P1pp — cc.scm-built mes-libc (lib mode); 36 ## consumed by the cc-libc test suite 37 ## build/$ARCH/$DRIVER/boot3/tcc.flat.P1pp — cc.scm-built tcc TU (lib mode); 38 ## debug/inspection artifact 39 ## 40 ## Usage: scripts/boot3.sh <arch> 41 ## <arch> ∈ {aarch64, amd64, riscv64} for either DRIVER (default podman). 42 43 set -eu 44 45 . scripts/lib-arch.sh 46 bootlib_init boot3 "${1:-}" 47 driver_init empty 48 require_src 49 50 BOOT1=build/$ARCH/$DRIVER/boot1 51 BOOT2=build/$ARCH/$DRIVER/boot2 52 SRC=build/$ARCH/src 53 54 require_prev "$BOOT1" M1pp hex2pp 55 require_prev "$BOOT2" catm scheme1 56 57 # ── stage inputs and run scheme1 + boot3-run.scm under $DRIVER ──────── 58 . scripts/lib-runscm.sh 59 runscm_init "$STAGE" "$OUT" 60 runscm_scheme1 "$BOOT2/scheme1" 61 runscm_prelude "$SRC/src/scheme1/prelude.scm" 62 runscm_runscm scripts/boot3-run.scm 63 64 runscm_input catm "$BOOT2/catm" 65 runscm_input M1pp "$BOOT1/M1pp" 66 runscm_input hex2pp "$BOOT1/hex2pp" 67 # scheme1 binary itself is staged by runscm_run (so a `(run "scheme1" …)` 68 # inside boot3-run.scm finds it at cwd-relative ./scheme1). 69 70 runscm_input_from_src scheme1/prelude.scm 71 runscm_input_from_src cc/cc.scm 72 runscm_input_from_src cc/main.scm 73 74 runscm_input_from_src "P1/P1-$ARCH.M1pp" backend.M1pp 75 runscm_input_from_src P1/P1.M1pp frontend.M1pp 76 runscm_input_from_src P1/P1pp.P1pp libp1pp.P1pp 77 runscm_input_from_src P1/entry-libc.P1pp 78 runscm_input_from_src P1/elf-end.P1pp 79 runscm_input_from_src vendor-seed/ELF.hex2 80 81 runscm_input_from_src tcc/tcc.flat.c 82 runscm_input_from_src libc/libc.flat.c 83 84 runscm_export tcc0 libc.P1pp tcc.flat.P1pp 85 runscm_run "${BOOT3_TIMEOUT:-1800}" 86 87 echo "[$BOOT_TAG] sizes: tcc0=$(wc -c <"$OUT/tcc0") libc.P1pp=$(wc -c <"$OUT/libc.P1pp")" 88 echo "[$BOOT_TAG] OK -> $OUT/tcc0"