boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

boot3.sh (4108B)


      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/stage0-posix/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 build/$ARCH/src/run/boot3.scm against the flat
     29 ##   staging root (copied from bootprep/assets/boot3-run.scm by
     30 ##   prep-src). Same run.scm drives both DRIVER=podman (cwd=/work) and
     31 ##   DRIVER=seed (cwd=/). Stage A is pure scheme1 + M1pp + hex2pp; no
     32 ##   asm step.
     33 ##
     34 ## ─── Outputs ──────────────────────────────────────────────────────────
     35 ##   build/$ARCH/$DRIVER/boot3/tcc0          — cc.scm-built bootstrap tcc
     36 ##   build/$ARCH/$DRIVER/boot3/libc.P1pp     — cc.scm-built mes-libc (lib mode);
     37 ##                                             consumed by the cc-libc test suite
     38 ##   build/$ARCH/$DRIVER/boot3/tcc.flat.P1pp — cc.scm-built tcc TU (lib mode);
     39 ##                                             debug/inspection artifact
     40 ##
     41 ## Usage: boot/boot3.sh <arch>
     42 ##   <arch> ∈ {aarch64, amd64, riscv64} for either DRIVER (default podman).
     43 
     44 set -eu
     45 
     46 . boot/lib-arch.sh
     47 bootlib_init boot3 "${1:-}"
     48 driver_init empty
     49 require_src
     50 
     51 BOOT1=build/$ARCH/$DRIVER/boot1
     52 BOOT2=build/$ARCH/$DRIVER/boot2
     53 SRC=build/$ARCH/src
     54 
     55 require_prev "$BOOT1" M1pp hex2pp
     56 require_prev "$BOOT2" catm scheme1
     57 
     58 # ── stage inputs and run scheme1 + boot3-run.scm under $DRIVER ────────
     59 . boot/lib-runscm.sh
     60 runscm_init "$STAGE" "$OUT"
     61 runscm_scheme1 "$BOOT2/scheme1"
     62 runscm_prelude "$SRC/src/scheme1/prelude.scm"
     63 runscm_runscm  "$SRC/run/boot3.scm"
     64 
     65 runscm_input catm           "$BOOT2/catm"
     66 runscm_input M1pp           "$BOOT1/M1pp"
     67 runscm_input hex2pp         "$BOOT1/hex2pp"
     68 # scheme1 binary itself is staged by runscm_run (so a `(run "scheme1" …)`
     69 # inside boot3-run.scm finds it at cwd-relative ./scheme1).
     70 
     71 runscm_input_from_src scheme1/prelude.scm
     72 runscm_input_from_src cc/cc.scm
     73 runscm_input_from_src cc/main.scm
     74 
     75 runscm_input_from_src "P1/P1-$ARCH.M1pp"   backend.M1pp
     76 runscm_input_from_src P1/P1.M1pp           frontend.M1pp
     77 runscm_input_from_src P1/P1pp.P1pp         libp1pp.P1pp
     78 runscm_input_from_src P1/entry-libc.P1pp
     79 runscm_input_from_src P1/elf-end.P1pp
     80 runscm_input_from_src stage0-posix/ELF.hex2
     81 
     82 runscm_input_from_src tcc/tcc.flat.c
     83 runscm_input_from_src libc/libc.flat.c
     84 
     85 runscm_export tcc0 libc.P1pp tcc.flat.P1pp
     86 runscm_run "${BOOT3_TIMEOUT:-1800}"
     87 
     88 echo "[$BOOT_TAG] sizes: tcc0=$(wc -c <"$OUT/tcc0") libc.P1pp=$(wc -c <"$OUT/libc.P1pp")"
     89 echo "[$BOOT_TAG] OK -> $OUT/tcc0"