boot2

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

boot-build-p1pp.sh (2013B)


      1 #!/bin/sh
      2 ## boot-build-p1pp.sh — in-container .P1pp -> ELF.
      3 ##
      4 ## Pure transformation. Caller (the Makefile) ensures every fixed-path
      5 ## input below already exists, including the per-arch self-hosted m1pp
      6 ## ELF binary (build/$ARCH/m1pp, built by boot2.sh / boot-build-p1.sh).
      7 ##
      8 ## Pipeline:
      9 ##   cat <P1-$ARCH.M1pp> <P1.M1pp> <P1pp.P1pp> <src> -> /tmp/combined.M1pp
     10 ##   m1pp /tmp/combined.M1pp                          -> /tmp/expanded.M1
     11 ##   M0   /tmp/expanded.M1                            -> /tmp/prog.hex2
     12 ##   catm /tmp/elf.hex2 /tmp/prog.hex2                -> /tmp/linked.hex2
     13 ##   hex2-0 /tmp/linked.hex2                          -> $OUT
     14 ##
     15 ## libp1pp (P1/P1pp.P1pp) is concatenated unconditionally so portable
     16 ## sources can use %fn, the control-flow macros, and libp1pp routines
     17 ## (sys_*, print*, parse_*, fmt_*, memcpy/memcmp, bump allocator, panic,
     18 ## %assert_*) without per-program plumbing. M0 has no link-time DCE, so
     19 ## programs that don't reference any libp1pp routine still pay a fixed
     20 ## code-size tax (~a few KB).
     21 ##
     22 ## Env: ARCH=aarch64|amd64|riscv64
     23 ## Usage: boot-build-p1pp.sh <src> <out>
     24 
     25 set -eu
     26 
     27 : "${ARCH:?ARCH must be set}"
     28 [ "$#" -eq 2 ] || { echo "usage: ARCH=<arch> $0 <src> <out>" >&2; exit 2; }
     29 
     30 SRC=$1
     31 OUT=$2
     32 
     33 BACKEND=P1/P1-$ARCH.M1pp
     34 FRONTEND=P1/P1.M1pp
     35 LIBP1PP=P1/P1pp.P1pp
     36 ELF_HDR=vendor/seed/$ARCH/ELF.hex2
     37 TOOLS=build/$ARCH/tools
     38 M1PP_BIN=build/$ARCH/m1pp
     39 NAME=$(basename "$SRC" .P1pp)
     40 WORK=build/$ARCH/.work/$NAME
     41 mkdir -p "$WORK" "$(dirname "$OUT")"
     42 
     43 cat "$BACKEND" "$FRONTEND" "$LIBP1PP" "$SRC" > /tmp/combined.M1pp
     44 "$M1PP_BIN" /tmp/combined.M1pp /tmp/expanded.M1
     45 "$TOOLS/M0" /tmp/expanded.M1 /tmp/prog.hex2
     46 
     47 cp "$ELF_HDR" /tmp/elf.hex2
     48 "$TOOLS/catm"   /tmp/linked.hex2 /tmp/elf.hex2 /tmp/prog.hex2
     49 "$TOOLS/hex2-0" /tmp/linked.hex2 /tmp/prog.bin
     50 
     51 cp /tmp/combined.M1pp "$WORK/combined.M1pp"
     52 cp /tmp/expanded.M1   "$WORK/expanded.M1"
     53 cp /tmp/prog.hex2     "$WORK/prog.hex2"
     54 cp /tmp/linked.hex2   "$WORK/linked.hex2"
     55 cp /tmp/prog.bin      "$OUT"
     56 chmod 0700 "$OUT"