boot2

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

commit 2859e2697132d3f328b92a6dcaa646d2de336dd8
parent 4706fe9e699582868f1caf3d64e3a68bd040afea
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Mon, 20 Apr 2026 12:53:35 -0700

Drop aarch64_defs.M1, update README for P1 layout

aarch64_defs.M1 is unreferenced now that hello.M1 builds through
p1_<arch>.M1. README rewritten to describe the portable P1 layout
and the ARCH-parameterized Makefile.

Diffstat:
MREADME.md | 40+++++++++++++++++++++++-----------------
Daarch64_defs.M1 | 229-------------------------------------------------------------------------------
2 files changed, 23 insertions(+), 246 deletions(-)

diff --git a/README.md b/README.md @@ -7,37 +7,43 @@ Goal is a 4–6× shrink in auditable LOC. See [PLAN.md](PLAN.md). ## Status -Stage 0: aarch64 hello-world in hand-written M1, assembled and run inside -a pristine alpine container. Toolchain (M1, hex2) builds statically from -the upstream mescc-tools C source. +Stage 0: hello-world in the P1 portable pseudo-ISA (see `../P1.md`), +assembled and run inside a pristine alpine container on all three target +arches (aarch64, amd64, riscv64). The same `hello.M1` source assembles +for every arch; only the backing `p1_<arch>.M1` defs file varies. +Toolchain (M1, hex2) builds statically from the upstream mescc-tools C +source. ## Layout ``` -PLAN.md design doc -hello.M1 hand-written aarch64 hello -aarch64_defs.M1 vendored instruction macros (from M2libc) -ELF-aarch64.hex2 vendored ELF header (from M2libc) +PLAN.md design doc (Lisp-in-M1 → C compiler path) +hello.M1 portable P1 hello, unchanged across arches +p1_<arch>.M1 per-arch P1 defs (aarch64, amd64, riscv64) +ELF-<arch>.hex2 per-arch ELF header template Containerfile builder image: alpine + gcc + musl-dev -Makefile podman-driven build -build/ outputs (M1, hex2, hello.hex2, hello) +Makefile podman-driven build, ARCH-parameterized +build/<arch>/ per-arch outputs (hello.hex2, hello) ``` ## Build & run -Requires podman with an arm64 Linux machine (e.g. `podman machine init` -on Apple Silicon). +Requires podman. Non-native arches run via podman's binfmt + qemu-user +path (works transparently on a default `podman machine` setup). ``` -make image # one-time: build the alpine+gcc builder image -make # build M1/hex2 statically + assemble hello.M1 → build/hello -make run # run build/hello in pristine alpine, prints "Hello, world!" -make clean # wipe build/ +make image # one-time: build the alpine+gcc builder image +make # default ARCH=aarch64 → build/aarch64/hello +make ARCH=amd64 # build/amd64/hello +make ARCH=riscv64 # build/riscv64/hello +make run # run build/$(ARCH)/hello in pristine alpine +make run-all # build + run on all three arches +make clean # wipe build/ ``` Two images are used: `lispcc-builder` (alpine+gcc, ~184 MB) only compiles -M1/hex2; `alpine:latest` (~9 MB) runs everything, with the static binaries -mounted in. +M1/hex2 at host arch; `alpine:latest` pulled per target platform runs +the assembled binary with the static toolchain mounted in. ## Source layout assumption diff --git a/aarch64_defs.M1 b/aarch64_defs.M1 @@ -1,229 +0,0 @@ -## Copyright (C) 2020 deesix <deesix@tuta.io> -## Copyright (C) 2020 Sanne Wouda -## This file is part of M2-Planet. -## -## M2-Planet is free software: you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## M2-Planet is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>. - -DEFINE NULL 0000000000000000 - -# Stack (x18 as SP, 64 bits per element) -DEFINE PUSH_X0 408e1ff8 -DEFINE PUSH_X1 418e1ff8 -DEFINE PUSH_X13 4d8e1ff8 # str x13, [x18,-8]! -DEFINE PUSH_X14 4e8e1ff8 # str x14, [x18,-8]! -DEFINE PUSH_X15 4f8e1ff8 # str x15, [x18,-8]! -DEFINE PUSH_X16 508e1ff8 -DEFINE PUSH_BP 518e1ff8 -DEFINE PUSH_LR 5e8e1ff8 - -DEFINE POP_X0 408640f8 -DEFINE POP_X1 418640f8 -DEFINE POP_X13 4d8640f8 # ldr x13, [x18],8 -DEFINE POP_X14 4e8640f8 # ldr x14, [x18],8 -DEFINE POP_X15 4f8640f8 # ldr x15, [x18],8 -DEFINE POP_X16 508640f8 -DEFINE POP_BP 518640f8 -DEFINE POP_LR 5e8640f8 - -DEFINE INIT_SP f2030091 # mov x18, sp - - -# Jump/branch/call/return -DEFINE BR_X16 00021fd6 -DEFINE BLR_X16 00023fd6 -DEFINE RETURN c0035fd6 - -DEFINE CBZ_X0_PAST_BR a00000b4 -DEFINE CBNZ_X0_PAST_BR a00000b5 - -DEFINE SKIP_INST_EQ 40000054 -DEFINE SKIP_INST_NE 41000054 -DEFINE SKIP_INST_LT 4b000054 -DEFINE SKIP_INST_LE 4d000054 -DEFINE SKIP_INST_GT 4c000054 -DEFINE SKIP_INST_GE 4a000054 - -DEFINE SKIP_INST_LO 43000054 -DEFINE SKIP_INST_LS 49000054 -DEFINE SKIP_INST_HS 42000054 -DEFINE SKIP_INST_HI 48000054 - -DEFINE SKIP_32_DATA 02000014 - - -# Load literals (PC-relative) -DEFINE LOAD_W0_AHEAD 40000098 -DEFINE LOAD_W1_AHEAD 41000018 -DEFINE LOAD_W2_AHEAD 42000018 -DEFINE LOAD_W13_AHEAD 4d000018 ; ldr w13, 8 -DEFINE LOAD_W14_AHEAD 4e000018 ; ldr w14, 8 -DEFINE LOAD_W15_AHEAD 4f000018 ; ldr w15, 8 -DEFINE LOAD_W16_AHEAD 50000018 - - -# Load/store/dereference -DEFINE LDR_X0_[SP] 400240f9 -DEFINE STR_X0_[X1] 200000f9 -DEFINE STR_W0_[X1] 200000B9 -DEFINE STRH_W0_[X1] 20000079 -DEFINE STR_BYTE_W0_[X1] 20000039 -DEFINE DEREF_X0 000040f9 -DEFINE DEREF_X1 210040f9 -DEFINE LDRH_W0_[X0] 00004079 -DEFINE LDRSB_X0_[X0] 00008039 -DEFINE LDRSH_X0_[X0] 00008079 -DEFINE LDR_W0_[X0] 000040B9 -DEFINE DEREF_X0_BYTE 00004039 -DEFINE DEREF_X1_BYTE 21004039 - - -# Move data between registers -DEFINE SET_X0_FROM_BP e00311aa -DEFINE SET_X0_FROM_X13 e0030daa # mov x0, x13 -DEFINE SET_X0_FROM_X14 e0030eaa # mov x0, x14 -DEFINE SET_X0_FROM_X15 e0030faa # mov x0, x15 -DEFINE SET_X0_FROM_X16 e00310aa # mov x0, x16 -DEFINE SET_X1_FROM_X0 e10300aa -DEFINE SET_X1_FROM_X13 e1030daa # mov x1, x13 -DEFINE SET_X1_FROM_X14 e1030eaa # mov x1, x14 -DEFINE SET_X1_FROM_X15 e1030faa # mov x1, x15 -DEFINE SET_X1_FROM_X16 e10310aa # mov x1, x16 -DEFINE SET_X1_FROM_SP e10312aa -DEFINE SET_X2_FROM_X0 e20300aa -DEFINE SET_X2_FROM_X1 e20301aa -DEFINE SET_X13_FROM_SP ed0312aa # mov x13, x18 -DEFINE SET_X14_FROM_X0 ee0300aa # mov x14, x0 -DEFINE SET_X15_FROM_X0 ef0300aa # mov x15, x0 -DEFINE SET_X3_FROM_X0 e30300aa -DEFINE SET_X3_FROM_X1 e30301aa -DEFINE SET_X3_FROM_X2 e30302aa -DEFINE SET_X4_FROM_X0 e40300aa -DEFINE SET_X5_FROM_X0 e50300aa -DEFINE SET_X6_FROM_X0 e60300aa -DEFINE SET_X16_FROM_X0 f00300aa -DEFINE SET_X16_FROM_SP f00312aa -DEFINE SET_BP_FROM_X16 f10310aa -DEFINE SET_BP_FROM_SP f10312aa -DEFINE SET_SP_FROM_X13 f2030daa # mov x18, x13 -DEFINE SET_SP_FROM_BP f20311aa # mov x18, x17 - - -# Move constant to register -DEFINE SET_X0_TO_0 000080d2 -DEFINE SET_X0_TO_1 200080d2 -DEFINE SET_X0_TO_17 200280d2 -DEFINE SET_X0_TO_MINUS_1 00008092 -DEFINE SET_W0_TO_MINUS_1 00008012 -DEFINE SET_X1_TO_0 010080d2 -DEFINE SET_X1_TO_2 410080d2 -DEFINE SET_X1_TO_8 010180d2 -DEFINE SET_X2_TO_0 020080d2 -DEFINE SET_X2_TO_1 220080d2 -DEFINE SET_X0_TO_FCNTL_H_AT_FDCWD 600c8092 -DEFINE SET_X1_TO_FCNTL_H_AT_FDCWD 610c8092 - - -# Arith/logic/relational -DEFINE ADD_X0_X1_X0 2000008b -DEFINE ADD_X0_X14_X0 c001008b ; add x0, x14, x0 -DEFINE ADD_X0_X15_X0 e001008b ; add x0, x15, x0 -DEFINE ADD_X0_X16_X0 0020008b ; add x0, x16, x0 -DEFINE ADD_X0_BP_X0 2002008b -DEFINE ADD_X1_SP_8 41220091 -DEFINE ADD_X1_X14_X1 c101018b ; add x1, x14, x1 -DEFINE ADD_X1_X15_X1 e101018b ; add x1, x15, x1 -DEFINE ADD_X1_X16_X1 0102018b ; add x1, x16, x1 -DEFINE ADD_SP_X14_SP d201128b ; add x18, x14, x18 -DEFINE ADD_SP_X15_SP f201128b ; add x18, x15, x18 -DEFINE ADD_SP_X16_SP 1201128b ; add x18, x16, x18 - -DEFINE SUB_X0_X1_X0 200000cb -DEFINE SUB_X0_X14_X0 c00100cb ; sub x0, x14, x0 -DEFINE SUB_X0_X15_X0 e00100cb ; sub x0, x15, x0 -DEFINE SUB_X0_X16_X0 000200cb ; sub x0, x16, x0 -DEFINE SUB_X0_X0_X14 00000ecb ; sub x0, x0, x14 -DEFINE SUB_X0_X0_X15 00000fcb ; sub x0, x0, x15 -DEFINE SUB_X0_X0_X16 000010cb ; sub x0, x0, x16 -DEFINE SUB_X0_X0_X1 000001cb -DEFINE SUB_X1_X1_X14 21000ecb ; sub x1, x1, x14 -DEFINE SUB_X1_X1_X15 21000fcb ; sub x1, x1, x15 -DEFINE SUB_X1_X1_X16 210010cb ; sub x1, x1, x16 -DEFINE SUB_X1_X14_X1 c10101cb ; sub x1, x14, x1 -DEFINE SUB_X1_X15_X1 e10101cb ; sub x1, x15, x1 -DEFINE SUB_X1_X16_X1 010201cb ; sub x1, x16, x1 -DEFINE SUB_SP_X1_SP 320012cb -DEFINE SUB_SP_X14_SP d20112cb ; sub x18, x14, x18 -DEFINE SUB_SP_X15_SP f20112cb ; sub x18, x15, x18 -DEFINE SUB_SP_X16_SP 120112cb ; sub x18, x16, x18 -DEFINE SUB_SP_SP_X14 52020ecb ; sub x18, x18, x14 -DEFINE SUB_SP_SP_X15 52020fcb ; sub x18, x18, x15 -DEFINE SUB_SP_SP_X16 520210cb ; sub x18, x18, x16 -DEFINE SUB_X0_8 002000d1 -DEFINE SUB_X0_16 004000d1 -DEFINE SUB_X0_24 006000d1 -DEFINE SUB_X0_32 008000d1 -DEFINE SUB_X0_40 00A000d1 -DEFINE MSUB_X0_X0_X2_X1 0084029b - -DEFINE MUL_X0_X1_X0 207c009b -DEFINE MUL_X0_X14_X0 c07d009b -DEFINE MUL_X0_X15_X0 e07d009b -DEFINE MUL_X0_X16_X0 007e009b -DEFINE SDIV_X0_X1_X0 200cc09a -DEFINE SDIV_X2_X1_X0 220cc09a -DEFINE UDIV_X0_X1_X0 2008c09a -DEFINE UDIV_X2_X1_X0 2208c09a - -DEFINE LSHIFT_X0_X0_X2 0020c29a -DEFINE LSHIFT_X0_X1_X0 2020c09a -DEFINE LOGICAL_RSHIFT_X0_X1_X0 2024c09a -DEFINE ARITH_RSHIFT_X0_X1_X0 2028c09a - -DEFINE MVN_X0 e00320aa -DEFINE AND_X0_X1_X0 2000008a -DEFINE OR_X0_X1_X0 200000aa -DEFINE XOR_X0_X1_X0 000001ca - -DEFINE CMP_X1_X0 3f0000eb - - -# Syscall -DEFINE SET_X8_TO_SYS_BRK c81a80d2 -DEFINE SET_X8_TO_SYS_CHDIR 280680d2 -DEFINE SET_X8_TO_SYS_CLONE 881b80d2 -DEFINE SET_X8_TO_SYS_CLOSE 280780d2 -DEFINE SET_X8_TO_SYS_EXECVE a81b80d2 -DEFINE SET_X8_TO_SYS_EXIT a80b80d2 -DEFINE SET_X8_TO_SYS_FACCESSAT 080680d2 -DEFINE SET_X8_TO_SYS_FCHDIR 480680d2 -DEFINE SET_X8_TO_SYS_FCHMOD 880680d2 -DEFINE SET_X8_TO_SYS_FCHMODAT a80680d2 -DEFINE SET_X8_TO_SYS_GETCWD 280280d2 -DEFINE SET_X8_TO_SYS_LSEEK c80780d2 -DEFINE SET_X8_TO_SYS_MKDIRAT 480480d2 -DEFINE SET_X8_TO_SYS_MKNODAT 280480d2 -DEFINE SET_X8_TO_SYS_OPENAT 080780d2 -DEFINE SET_X8_TO_SYS_READ e80780d2 -DEFINE SET_X8_TO_SYS_UNAME 081480d2 -DEFINE SET_X8_TO_SYS_WAIT4 882080d2 -DEFINE SET_X8_TO_SYS_WRITE 080880d2 -DEFINE SET_X8_TO_SYS_UNLINKAT 680480d2 -DEFINE SET_X8_TO_SYS_SYMLINKAT 880480d2 -DEFINE SET_X8_TO_SYS_UMASK c81480d2 -DEFINE SET_X8_TO_SYS_UNSHARE 280c80d2 -DEFINE SET_X8_TO_SYS_GETEUID e81580d2 -DEFINE SET_X8_TO_SYS_GETEGID 081680d2 -DEFINE SET_X8_TO_SYS_CHROOT 680680d2 -DEFINE SET_X8_TO_SYS_MOUNT 080580d2 -DEFINE SYSCALL 010000d4