boot2

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

boot3.sh (4036B)


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