boot2

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

commit 5757513857ba4807e5642573a662659b4a4ad398
parent 56dfcbf7c27c97396b11fa3e71bee8d9a03a6eed
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Fri, 24 Apr 2026 16:57:08 -0700

Push container builds onto tmpfs; restructure scripts/ around boot-* convention

* Convention: every script invoked via `podman run` is named boot*.sh.
  Rename scripts/bootstrap.sh -> scripts/boot1.sh; new scripts/boot2.sh
  builds M1pp + pokem inside the container; scripts/boot-build-p1.sh and
  scripts/boot-build-p1pp.sh are the generic in-container builders called
  by Make for individual programs and test fixtures.
* Make becomes the single source of truth for build dependencies. The old
  host-side dispatchers scripts/build-p1.sh and scripts/build-p1pp.sh are
  gone; their work now lives in boot-build-p1.sh / boot-build-p1pp.sh, and
  Make rules wrap them with `podman run ... sh scripts/boot-*.sh ARGS` —
  no inline shell.
* /tmp inside the container is now a real RAM tmpfs (--tmpfs /tmp:size=512M).
  Previously /tmp fell through to the container overlay, still backed by
  virtiofs on Apple Silicon, so the stage0 tools' per-byte fputc/fgetc
  paid a virtiofs round-trip per byte. Real RAM tmpfs cuts a clean m1pp
  build ~3s and is propagated to all podman invocations (Make + run-tests).
* boot1.sh stages its hex0/hex1/hex2-0/catm/M0 chain entirely through /tmp
  and copies the final tools to the bind mount at the end; intermediates
  never touch virtiofs.
* Pre-prune the per-arch P1 backend tables once, check in the result.
  scripts/prune-p1-table.sh emits P1/P1-<arch>.M1 from the full generated
  table (now at build/p1/<arch>.M1) keeping only the DEFINEs referenced by
  M1pp/M1pp.P1, pokem/pokem.P1, and tests/M1pp/*.M1. Routine builds skip
  the per-build prune; `make tables` regenerates after editing P1/gen/*.py
  or the prune-source set.
* Drop the ELF p_filesz trim. The kernel zero-fills BSS at load time, so
  the trailing zero padding in raw hex2-0 output is wasted bytes on disk
  but functionally identical at exec.
* Drop NATIVE=1 mode. The bootstrap chain is now the only path; the host
  native tools (build-native-tools.sh / `make tools-native`) are kept as
  an opt-in helper but no longer wired into any default rule.

Verified: make all + make hello + make run print "Hello, World!"; the
aarch64 m1pp suite passes 20/20 in ~5s. Cross-arch m1pp builds run under
qemu-user emulation and are slow but correct (per-byte syscalls × qemu
overhead). The .P1pp suite still hits the known self-hosted m1pp buffer
overflow on the combined backend+frontend+source — to be fixed by bumping
M1pp_*_CAP constants in M1pp/M1pp.P1.

Diffstat:
MMakefile | 218+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
AP1/P1-aarch64.M1 | 521+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AP1/P1-amd64.M1 | 520+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AP1/P1-riscv64.M1 | 521+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MP1/gen/p1_gen.py | 7+++----
Ascripts/boot-build-p1.sh | 44++++++++++++++++++++++++++++++++++++++++++++
Ascripts/boot-build-p1pp.sh | 46++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/boot1.sh | 46++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/boot2.sh | 35+++++++++++++++++++++++++++++++++++
Dscripts/bootstrap.sh | 39---------------------------------------
Mscripts/build-native-tools.sh | 93+++++++++++++++++++++++++++++++++----------------------------------------------
Dscripts/build-p1.sh | 110-------------------------------------------------------------------------------
Dscripts/build-p1pp.sh | 79-------------------------------------------------------------------------------
Ascripts/prune-p1-table.sh | 29+++++++++++++++++++++++++++++
Mscripts/run-tests.sh | 50++++++++++++++++++++++++++++++--------------------
15 files changed, 1957 insertions(+), 401 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,26 +1,29 @@ # boot2 — P1 portable pseudo-ISA + M1pp. # -# Everything here drives `scripts/*.sh`; nothing builds or runs in podman -# outside the per-arch `boot2-busybox:<arch>` image (built from -# `scripts/Containerfile.busybox`). Bootstrap inputs are vendored in -# `vendor/seed/<arch>/`. +# Make declares all build dependencies and ensures every input + tool +# exists before any script runs. Scripts in scripts/ are pure +# transformations: they assume their inputs are present, do one thing, +# write outputs. Any script that runs inside podman starts with `boot`; +# the rest run on the host. +# +# Bootstrap inputs are vendored in vendor/seed/<arch>/. The only image +# used is per-arch boot2-busybox:<arch>, built from +# scripts/Containerfile.busybox. # # Common entrypoints: # make all (m1pp + pokem for ARCH) -# make m1pp ARCH=amd64 build the m1pp expander for one arch +# make m1pp build the m1pp expander for ARCH # make pokem build pokem for ARCH -# make hello build+run hello via the bootstrap chain +# make hello build hello via the bootstrap chain +# make run run hello in the container # make test every suite, every arch # make test SUITE=m1pp m1pp suite, every arch # make test SUITE=p1 ARCH=amd64 p1 suite, one arch # make image build the per-arch container image # make tools bootstrap M0/hex2-0/catm for ARCH -# make tools-native build host-native M1/hex2/m1pp for dev speed +# make tables regen pre-pruned P1/P1-<arch>.M1 tables +# make tools-native build host-native M1/hex2/m1pp (opt-in) # make clean rm -rf build/ -# -# ARCH defaults to aarch64 and applies to every program/image/tools target. -# It also restricts test runs to one arch when set; without it, tests fan -# out across all three. ARCH ?= aarch64 @@ -29,115 +32,151 @@ ALL_ARCHES := aarch64 amd64 riscv64 PLATFORM_aarch64 := linux/arm64 PLATFORM_amd64 := linux/amd64 PLATFORM_riscv64 := linux/riscv64 -PLATFORM := $(PLATFORM_$(ARCH)) -ifeq ($(PLATFORM),) - $(error ARCH '$(ARCH)' not supported — use aarch64, amd64, or riscv64) -endif -IMAGE := boot2-busybox:$(ARCH) +ifeq ($(filter $(ARCH),$(ALL_ARCHES)),) + $(error ARCH '$(ARCH)' not supported — use one of $(ALL_ARCHES)) +endif OUT_DIR := build/$(ARCH) TOOLS_DIR := $(OUT_DIR)/tools IMAGE_STAMP := $(OUT_DIR)/.image -# `--pull=never`: image is built once per arch by the IMAGE_STAMP rule -# and lives in the local store. No registry traffic at run time. -PODMAN := podman run --rm --pull=never --platform $(PLATFORM) \ - -v $(CURDIR):/work \ - -w /work \ - $(IMAGE) +# All container invocations go through this. Just env/args + one named +# script in scripts/; never inline shell. +# +# --tmpfs /tmp: backstop for the stage0 tools' per-byte fputc/fgetc. Without +# it /tmp falls through to the container overlay (still backed by virtiofs +# on Apple Silicon), and a 1MB M0 input pays a virtiofs round-trip per +# byte. Real RAM tmpfs collapses that to local memory access. +PODMAN = podman run --rm --pull=never --platform $(PLATFORM_$(1)) \ + --tmpfs /tmp:size=512M \ + -v $(CURDIR):/work -w /work boot2-busybox:$(1) -# --- Targets --------------------------------------------------------------- +# --- Targets -------------------------------------------------------------- -.PHONY: all m1pp pokem hello run test image tools tools-native \ - clean help $(ALL_ARCHES:%=image-%) $(ALL_ARCHES:%=tools-%) +.PHONY: all m1pp pokem hello run test image tools tables \ + tools-native clean help all: m1pp pokem help: @sed -n '/^# Common entrypoints:/,/^$$/p' Makefile | sed 's/^# *//' -# --- Container image (per arch) ------------------------------------------- +clean: + rm -rf build/ + +# --- Per-arch container image --------------------------------------------- + +IMAGE_STAMPS := $(foreach a,$(ALL_ARCHES),build/$(a)/.image) image: $(IMAGE_STAMP) -$(IMAGE_STAMP): scripts/Containerfile.busybox | $(OUT_DIR) - podman build --platform $(PLATFORM) -t $(IMAGE) \ +$(IMAGE_STAMPS): build/%/.image: scripts/Containerfile.busybox + mkdir -p $(@D) + podman build --platform $(PLATFORM_$*) -t boot2-busybox:$* \ -f scripts/Containerfile.busybox scripts/ @touch $@ -$(OUT_DIR) $(TOOLS_DIR): - mkdir -p $@ - # --- Bootstrap toolchain (per arch) --------------------------------------- # -# Produce M0/hex2-0/catm (and throwaway hex0/hex1) from the vendored -# hex0-seed by chaining inside the busybox container. One shot per arch. +# Stage 1: vendored hex0-seed -> M0/hex2-0/catm in the container. + +TOOLS_M0 := $(foreach a,$(ALL_ARCHES),build/$(a)/tools/M0) tools: $(TOOLS_DIR)/M0 -$(TOOLS_DIR)/M0 $(TOOLS_DIR)/hex2-0 $(TOOLS_DIR)/catm $(TOOLS_DIR)/hex0 $(TOOLS_DIR)/hex1 &: \ - scripts/bootstrap.sh $(wildcard vendor/seed/$(ARCH)/*) | $(TOOLS_DIR) $(IMAGE_STAMP) - $(PODMAN) sh scripts/bootstrap.sh $(ARCH) $(TOOLS_DIR) +$(TOOLS_M0): build/%/tools/M0: scripts/boot1.sh build/%/.image \ + vendor/seed/%/hex0-seed vendor/seed/%/hex0.hex0 \ + vendor/seed/%/hex1.hex0 vendor/seed/%/hex2.hex1 \ + vendor/seed/%/catm.hex2 vendor/seed/%/M0.hex2 \ + vendor/seed/%/ELF.hex2 + mkdir -p build/$*/tools + $(call PODMAN,$*) sh scripts/boot1.sh $* build/$*/tools -# --- Native tools (host-side, dev-loop convenience) ----------------------- +# --- Pre-pruned P1 backend tables ----------------------------------------- # -# Drives scripts/build-native-tools.sh; produces build/native-tools/{M1,hex2,m1pp} -# on the host. These are byte-equivalent substitutes for the bootstrap -# tools when invoked with the right flags (see scripts/build-p1.sh). +# Generated once from P1/gen/p1_gen.py and pruned to just the DEFINEs +# referenced by M1pp/pokem/.M1 fixtures. Result is checked in to +# P1/P1-<arch>.M1; routine builds skip the prune step. Re-run `make +# tables` after editing P1/gen/*.py or any of the prune-source files +# below, then commit the updated P1/*.M1. -tools-native: - sh scripts/build-native-tools.sh +P1_PRUNE_SRCS := M1pp/M1pp.P1 pokem/pokem.P1 $(wildcard tests/M1pp/*.M1) -# --- P1 backend tables -------------------------------------------------- -# -# build/p1/<arch>/p1_<arch>.M1 is the M1-format DEFINE table for that -# arch, generated by P1/gen/p1_gen.py. Used by scripts/build-p1.sh (the .P1 -# pipeline; .P1pp uses the M1pp form under P1/P1-<arch>.M1pp instead). +tables: $(foreach a,$(ALL_ARCHES),P1/P1-$(a).M1) -build/p1/aarch64/p1_aarch64.M1: $(wildcard P1/gen/*.py) +build/p1/aarch64.M1 build/p1/amd64.M1 build/p1/riscv64.M1 &: \ + $(wildcard P1/gen/*.py) + mkdir -p build/p1 python3 P1/gen/p1_gen.py --arch aarch64 build/p1 - -build/p1/amd64/p1_amd64.M1: $(wildcard P1/gen/*.py) - python3 P1/gen/p1_gen.py --arch amd64 build/p1 - -build/p1/riscv64/p1_riscv64.M1: $(wildcard P1/gen/*.py) + python3 P1/gen/p1_gen.py --arch amd64 build/p1 python3 P1/gen/p1_gen.py --arch riscv64 build/p1 +P1/P1-%.M1: build/p1/%.M1 scripts/prune-p1-table.sh $(P1_PRUNE_SRCS) + sh scripts/prune-p1-table.sh $< $@ $(P1_PRUNE_SRCS) + # --- Programs (per arch) -------------------------------------------------- -m1pp: $(OUT_DIR)/m1pp +M1PP_BINS := $(foreach a,$(ALL_ARCHES),build/$(a)/m1pp) +POKEM_BINS := $(foreach a,$(ALL_ARCHES),build/$(a)/pokem) +HELLO_SRC := tests/M1pp/00-hello.M1 +HELLO_BINS := $(foreach a,$(ALL_ARCHES),build/$(a)/hello) + +m1pp: $(OUT_DIR)/m1pp pokem: $(OUT_DIR)/pokem +hello: $(OUT_DIR)/hello -$(OUT_DIR)/m1pp: M1pp/M1pp.P1 build/p1/$(ARCH)/p1_$(ARCH).M1 \ - scripts/build-p1.sh scripts/lint.sh - sh scripts/build-p1.sh $(ARCH) M1pp/M1pp.P1 $@ +# Per-arch deps shared by every .P1/.M1 build. +P1_BUILD_DEPS = scripts/lint.sh scripts/boot-build-p1.sh \ + build/%/.image build/%/tools/M0 \ + vendor/seed/%/ELF.hex2 P1/P1-%.M1 -$(OUT_DIR)/pokem: pokem/pokem.P1 build/p1/$(ARCH)/p1_$(ARCH).M1 \ - scripts/build-p1.sh scripts/lint.sh - sh scripts/build-p1.sh $(ARCH) pokem/pokem.P1 $@ +$(M1PP_BINS): build/%/m1pp: M1pp/M1pp.P1 $(P1_BUILD_DEPS) + sh scripts/lint.sh P1/P1-$*.M1 M1pp/M1pp.P1 + $(call PODMAN,$*) sh scripts/boot-build-p1.sh \ + P1/P1-$*.M1 M1pp/M1pp.P1 vendor/seed/$*/ELF.hex2 \ + build/$*/.work/m1pp build/$*/tools $@ -# Bootstrap-chain showcase: build hello via the full M0/hex2-0 path inside -# the container. Demonstrates the seed -> tool -> ELF flow end to end. -HELLO_SRC := tests/M1pp/00-hello.M1 +$(POKEM_BINS): build/%/pokem: pokem/pokem.P1 $(P1_BUILD_DEPS) + sh scripts/lint.sh P1/P1-$*.M1 pokem/pokem.P1 + $(call PODMAN,$*) sh scripts/boot-build-p1.sh \ + P1/P1-$*.M1 pokem/pokem.P1 vendor/seed/$*/ELF.hex2 \ + build/$*/.work/pokem build/$*/tools $@ -hello: $(OUT_DIR)/hello +$(HELLO_BINS): build/%/hello: $(HELLO_SRC) $(P1_BUILD_DEPS) + sh scripts/lint.sh P1/P1-$*.M1 $(HELLO_SRC) + $(call PODMAN,$*) sh scripts/boot-build-p1.sh \ + P1/P1-$*.M1 $(HELLO_SRC) vendor/seed/$*/ELF.hex2 \ + build/$*/.work/hello build/$*/tools $@ -$(OUT_DIR)/hello: $(HELLO_SRC) build/p1/$(ARCH)/p1_$(ARCH).M1 \ - scripts/build-p1.sh scripts/lint.sh $(TOOLS_DIR)/M0 - M1PP_BOOTSTRAP_TOOLS=1 sh scripts/build-p1.sh $(ARCH) $(HELLO_SRC) $@ +run: $(OUT_DIR)/hello $(IMAGE_STAMP) + $(call PODMAN,$(ARCH)) ./$(OUT_DIR)/hello -run: $(OUT_DIR)/hello | $(IMAGE_STAMP) - $(PODMAN) ./$(OUT_DIR)/hello +# --- Native tools (opt-in dev-loop helpers) ------------------------------- + +NATIVE_TOOLS := build/native-tools/M1 build/native-tools/hex2 build/native-tools/m1pp + +tools-native: $(NATIVE_TOOLS) + +build/native-tools/M1: scripts/build-native-tools.sh + sh scripts/build-native-tools.sh M1 + +build/native-tools/hex2: scripts/build-native-tools.sh + sh scripts/build-native-tools.sh hex2 + +build/native-tools/m1pp: scripts/build-native-tools.sh M1pp/M1pp.c + sh scripts/build-native-tools.sh m1pp # --- Tests ---------------------------------------------------------------- # -# `make test` runs every suite on every arch. SUITE/ARCH narrow it. -# Test runner is scripts/run-tests.sh, parameterized by --suite/--arch. +# `make test` runs every suite. SUITE selects one; ARCH restricts to one +# arch. Make ensures every dependency (images, tools, tables, m1pp +# expanders) exists before scripts/run-tests.sh is invoked. The runner +# itself only loops fixtures, builds per-fixture binaries via the boot-* +# scripts, runs them in the container, and diffs. SUITE ?= -# When ARCH is set on the command line, restrict tests to that arch. ifeq ($(origin ARCH),file) ARCH_FILTER := TEST_ARCHES := $(ALL_ARCHES) @@ -146,35 +185,24 @@ else TEST_ARCHES := $(ARCH) endif +# m1pp suite per-arch deps: image, tools, table, expander. +TEST_M1PP_DEPS := $(foreach a,$(TEST_ARCHES), \ + build/$(a)/.image build/$(a)/tools/M0 P1/P1-$(a).M1 build/$(a)/m1pp) + +# p1 suite per-arch deps: image, tools, expander. +TEST_P1_DEPS := $(foreach a,$(TEST_ARCHES), \ + build/$(a)/.image build/$(a)/tools/M0 build/$(a)/m1pp) + test: ifeq ($(SUITE),) @$(MAKE) --no-print-directory test SUITE=m1pp @$(MAKE) --no-print-directory test SUITE=p1 -else - @$(MAKE) --no-print-directory \ - $(foreach a,$(TEST_ARCHES),image-$(a)) \ - $(foreach a,$(TEST_ARCHES),build/p1/$(a)/p1_$(a).M1) -ifeq ($(SUITE),m1pp) +else ifeq ($(SUITE),m1pp) + @$(MAKE) --no-print-directory $(TEST_M1PP_DEPS) sh scripts/run-tests.sh --suite=m1pp $(if $(ARCH_FILTER),--arch=$(ARCH_FILTER)) else ifeq ($(SUITE),p1) - sh scripts/run-tests.sh --suite=p1 $(if $(ARCH_FILTER),--arch=$(ARCH_FILTER)) + @$(MAKE) --no-print-directory $(TEST_P1_DEPS) + sh scripts/run-tests.sh --suite=p1 $(if $(ARCH_FILTER),--arch=$(ARCH_FILTER)) else @echo "unknown SUITE='$(SUITE)' (expected m1pp | p1)" >&2; exit 2 endif -endif - -# --- Per-arch convenience targets ----------------------------------------- -# -# `make image-amd64` etc. — used by `make test` to materialise every arch's -# container/table before run-tests.sh starts looping. - -$(ALL_ARCHES:%=image-%): - @$(MAKE) --no-print-directory ARCH=$(@:image-%=%) image - -$(ALL_ARCHES:%=tools-%): - @$(MAKE) --no-print-directory ARCH=$(@:tools-%=%) tools - -# -------------------------------------------------------------------------- - -clean: - rm -rf build/ diff --git a/P1/P1-aarch64.M1 b/P1/P1-aarch64.M1 @@ -0,0 +1,521 @@ +## aarch64.M1 — GENERATED by p1/gen/p1_gen.py. Do not edit by hand. +## +## This table targets the P1 ISA described in docs/P1.md. +## Row shapes are shared; per-arch lowering lives in p1/gen/<arch>.py. + + +## ---- Materialization +DEFINE li_a0 4000005803000014 +DEFINE li_a1 4100005803000014 +DEFINE li_a2 4200005803000014 +DEFINE li_a3 4300005803000014 +DEFINE li_t0 4900005803000014 +DEFINE li_t1 4A00005803000014 +DEFINE li_t2 4B00005803000014 +DEFINE la_a0 4000001802000014 +DEFINE la_a1 4100001802000014 +DEFINE la_a2 4200001802000014 +DEFINE la_a3 4300001802000014 +DEFINE la_t0 4900001802000014 +DEFINE la_t1 4A00001802000014 +DEFINE la_t2 4B00001802000014 +DEFINE la_br 5100001802000014 + +## ---- Moves +DEFINE mov_a0,a3 E00303AA +DEFINE mov_a0,t0 E00309AA +DEFINE mov_a0,t1 E0030AAA +DEFINE mov_a0,t2 E0030BAA +DEFINE mov_a1,a0 E10300AA +DEFINE mov_a1,t0 E10309AA +DEFINE mov_a1,t1 E1030AAA +DEFINE mov_a1,t2 E1030BAA +DEFINE mov_a2,a1 E20301AA +DEFINE mov_a2,t0 E20309AA +DEFINE mov_a2,t1 E2030AAA +DEFINE mov_a3,t0 E30309AA +DEFINE mov_a3,t1 E3030AAA +DEFINE mov_t0,a0 E90300AA +DEFINE mov_t1,a0 EA0300AA +DEFINE mov_t2,a0 EB0300AA +DEFINE mov_t2,t1 EB030AAA + +## ---- Register Arithmetic +DEFINE add_a0,a0,a1 0000018B +DEFINE add_a0,a0,a2 0000028B +DEFINE add_a0,a0,t0 0000098B +DEFINE add_a0,a0,t1 00000A8B +DEFINE add_a0,a0,t2 00000B8B +DEFINE add_a0,a2,a0 4000008B +DEFINE add_a0,a2,t2 40000B8B +DEFINE add_a0,t0,a3 2001038B +DEFINE add_a0,t1,a0 4001008B +DEFINE add_a0,t1,t2 40010B8B +DEFINE add_a0,t2,a1 6001018B +DEFINE add_a1,a0,a1 0100018B +DEFINE add_a1,a1,a0 2100008B +DEFINE add_a1,a1,a2 2100028B +DEFINE add_a1,a1,a3 2100038B +DEFINE add_a1,a1,t0 2100098B +DEFINE add_a1,a1,t1 21000A8B +DEFINE add_a1,a2,a1 4100018B +DEFINE add_a1,a2,a3 4100038B +DEFINE add_a1,a2,t0 4100098B +DEFINE add_a1,a3,a1 6100018B +DEFINE add_a1,t0,a0 2101008B +DEFINE add_a1,t2,a1 6101018B +DEFINE add_a1,t2,a3 6101038B +DEFINE add_a1,t2,t1 61010A8B +DEFINE add_a2,a1,a3 2200038B +DEFINE add_a2,a1,t0 2200098B +DEFINE add_a2,a2,a0 4200008B +DEFINE add_a2,a2,a3 4200038B +DEFINE add_a2,a2,t0 4200098B +DEFINE add_a2,a2,t1 42000A8B +DEFINE add_a2,a3,a2 6200028B +DEFINE add_a2,t0,t1 22010A8B +DEFINE add_a2,t1,t2 42010B8B +DEFINE add_a2,t2,a0 6201008B +DEFINE add_a2,t2,a2 6201028B +DEFINE add_a3,a0,a2 0300028B +DEFINE add_a3,a1,t1 23000A8B +DEFINE add_a3,a1,t2 23000B8B +DEFINE add_a3,a3,a1 6300018B +DEFINE add_a3,a3,a2 6300028B +DEFINE add_a3,a3,t0 6300098B +DEFINE add_a3,a3,t1 63000A8B +DEFINE add_a3,a3,t2 63000B8B +DEFINE add_a3,t0,t2 23010B8B +DEFINE add_a3,t1,a2 4301028B +DEFINE add_t0,a1,t2 29000B8B +DEFINE add_t0,a3,a1 6900018B +DEFINE add_t0,t0,a0 2901008B +DEFINE add_t0,t0,a1 2901018B +DEFINE add_t0,t0,a3 2901038B +DEFINE add_t0,t0,t1 29010A8B +DEFINE add_t1,t0,t1 2A010A8B +DEFINE add_t1,t1,a0 4A01008B +DEFINE add_t1,t1,a1 4A01018B +DEFINE add_t1,t1,a2 4A01028B +DEFINE add_t1,t1,t2 4A010B8B +DEFINE add_t2,a0,t0 0B00098B +DEFINE add_t2,a0,t1 0B000A8B +DEFINE add_t2,a1,a3 2B00038B +DEFINE add_t2,a1,t2 2B000B8B +DEFINE add_t2,a2,t1 4B000A8B +DEFINE add_t2,t0,t1 2B010A8B +DEFINE add_t2,t1,t2 4B010B8B +DEFINE add_t2,t2,a0 6B01008B +DEFINE add_t2,t2,a3 6B01038B +DEFINE sub_a0,a0,t1 00000ACB +DEFINE sub_a0,a1,t2 20000BCB +DEFINE sub_a0,a3,a0 600000CB +DEFINE sub_a1,t0,a0 210100CB +DEFINE sub_a2,a1,a0 220000CB +DEFINE sub_a2,a2,a2 420002CB +DEFINE sub_a2,a2,t0 420009CB +DEFINE sub_a2,t0,t1 22010ACB +DEFINE sub_a2,t2,a3 620103CB +DEFINE sub_a3,a3,a1 630001CB +DEFINE sub_a3,a3,a2 630002CB +DEFINE sub_a3,t0,a2 230102CB +DEFINE sub_a3,t0,a3 230103CB +DEFINE sub_a3,t0,t1 23010ACB +DEFINE sub_a3,t1,a2 430102CB +DEFINE sub_a3,t1,t0 430109CB +DEFINE sub_a3,t2,t1 63010ACB +DEFINE sub_t0,a1,a2 290002CB +DEFINE sub_t0,t0,a0 290100CB +DEFINE sub_t0,t0,a1 290101CB +DEFINE sub_t0,t0,t1 29010ACB +DEFINE sub_t2,t1,t0 4B0109CB +DEFINE and_a3,a3,a2 6300028A +DEFINE or_a0,a0,a1 000001AA +DEFINE or_a0,a0,a2 000002AA +DEFINE or_a3,a3,a2 630002AA +DEFINE xor_a2,a2,a3 420003CA +DEFINE xor_a3,a3,a2 630002CA +DEFINE shl_a2,a2,a3 4220C39A +DEFINE sar_a2,a2,a3 4228C39A +DEFINE mul_a0,a0,a3 007C039B +DEFINE mul_a0,t1,t2 407D0B9B +DEFINE mul_a1,a1,a3 217C039B +DEFINE mul_a2,a2,t0 427C099B +DEFINE mul_a3,a3,a2 637C029B +DEFINE mul_t0,t0,a1 297D019B +DEFINE mul_t0,t0,a2 297D029B +DEFINE mul_t1,t1,a3 4A7D039B +DEFINE mul_t2,t0,a2 2B7D029B +DEFINE div_a0,a0,a1 000CC19A +DEFINE div_a2,a2,a3 420CC39A +DEFINE rem_a2,a0,a1 100CC19A0282019B +DEFINE rem_a2,a2,a3 500CC39A028A039B + +## ---- Immediate Arithmetic +DEFINE addi_a0,a0,neg1 000400D1 +DEFINE addi_a0,a0,1 00040091 +DEFINE addi_a0,a0,24 00600091 +DEFINE addi_a1,a1,neg48 21C000D1 +DEFINE addi_a1,a1,neg24 216000D1 +DEFINE addi_a1,a1,neg2 210800D1 +DEFINE addi_a1,a1,1 21040091 +DEFINE addi_a1,a1,2 21080091 +DEFINE addi_a1,a1,3 210C0091 +DEFINE addi_a1,t0,1 21050091 +DEFINE addi_a2,a0,1 02040091 +DEFINE addi_a2,a2,neg1 420400D1 +DEFINE addi_a2,a2,1 42040091 +DEFINE addi_a2,a2,2 42080091 +DEFINE addi_a2,a2,3 420C0091 +DEFINE addi_a2,a2,8 42200091 +DEFINE addi_a2,a2,24 42600091 +DEFINE addi_a2,a2,48 42C00091 +DEFINE addi_a2,t0,1 22050091 +DEFINE addi_a2,t2,neg48 62C100D1 +DEFINE addi_a3,a3,1 63040091 +DEFINE addi_a3,a3,24 63600091 +DEFINE addi_t0,a1,neg24 296000D1 +DEFINE addi_t0,a1,24 29600091 +DEFINE addi_t0,t0,neg1 290500D1 +DEFINE addi_t0,t0,1 29050091 +DEFINE addi_t0,t0,2 29090091 +DEFINE addi_t0,t0,24 29610091 +DEFINE addi_t0,t0,48 29C10091 +DEFINE addi_t1,t0,24 2A610091 +DEFINE addi_t1,t1,neg24 4A6100D1 +DEFINE addi_t1,t1,neg1 4A0500D1 +DEFINE addi_t1,t1,1 4A050091 +DEFINE addi_t1,t1,16 4A410091 +DEFINE addi_t1,t1,24 4A610091 +DEFINE addi_t2,a1,neg24 2B6000D1 +DEFINE addi_t2,t0,neg24 2B6100D1 +DEFINE addi_t2,t0,24 2B610091 +DEFINE addi_t2,t1,2 4B090091 +DEFINE addi_t2,t2,neg1 6B0500D1 +DEFINE addi_t2,t2,1 6B050091 +DEFINE addi_t2,t2,24 6B610091 +DEFINE andi_a2,a0,15 F00180D20200108A +DEFINE andi_a2,a1,15 F00180D22200108A +DEFINE andi_a2,a2,15 F00180D24200108A +DEFINE andi_a3,a3,15 F00180D26300108A +DEFINE andi_a3,t2,255 F01F80D26301108A +DEFINE shli_a0,a0,3 00F07DD3 +DEFINE shli_a0,a0,4 00EC7CD3 +DEFINE shli_a1,a1,1 21F87FD3 +DEFINE shli_a2,t1,3 42F17DD3 +DEFINE shli_a3,t0,1 23F97FD3 +DEFINE shli_a3,t0,4 23ED7CD3 +DEFINE shli_t1,a2,3 4AF07DD3 +DEFINE shli_t2,t0,3 2BF17DD3 +DEFINE shri_a0,a0,6 00FC46D3 +DEFINE shri_a1,a1,6 21FC46D3 +DEFINE shri_a2,a3,4 62FC44D3 +DEFINE shri_t2,t2,8 6BFD48D3 + +## ---- Memory +DEFINE ld_a0,a0,0 000040F9 +DEFINE ld_a0,a0,8 000440F9 +DEFINE ld_a0,a0,16 000840F9 +DEFINE ld_a0,a1,0 200040F9 +DEFINE ld_a0,a2,0 400040F9 +DEFINE ld_a0,a3,0 600040F9 +DEFINE ld_a0,a3,8 600440F9 +DEFINE ld_a0,a3,16 600840F9 +DEFINE ld_a0,sp,0 E00B40F9 +DEFINE ld_a0,sp,8 E00F40F9 +DEFINE ld_a0,sp,24 E01740F9 +DEFINE ld_a1,a0,0 010040F9 +DEFINE ld_a1,a0,8 010440F9 +DEFINE ld_a1,a0,24 010C40F9 +DEFINE ld_a1,a1,0 210040F9 +DEFINE ld_a1,a2,8 410440F9 +DEFINE ld_a1,a3,8 610440F9 +DEFINE ld_a1,t0,0 210140F9 +DEFINE ld_a1,t0,8 210540F9 +DEFINE ld_a1,t0,16 210940F9 +DEFINE ld_a1,t1,0 410140F9 +DEFINE ld_a1,t2,16 610940F9 +DEFINE ld_a1,sp,8 E10F40F9 +DEFINE ld_a2,a0,0 020040F9 +DEFINE ld_a2,a0,8 020440F9 +DEFINE ld_a2,a0,16 020840F9 +DEFINE ld_a2,a1,0 220040F9 +DEFINE ld_a2,a1,8 220440F9 +DEFINE ld_a2,a2,0 420040F9 +DEFINE ld_a2,t0,0 220140F9 +DEFINE ld_a2,t0,8 220540F9 +DEFINE ld_a2,t0,16 220940F9 +DEFINE ld_a2,t1,neg24 42815EF8 +DEFINE ld_a2,t2,0 620140F9 +DEFINE ld_a2,sp,16 E21340F9 +DEFINE ld_a3,a0,0 030040F9 +DEFINE ld_a3,a0,8 030440F9 +DEFINE ld_a3,a0,16 030840F9 +DEFINE ld_a3,a1,0 230040F9 +DEFINE ld_a3,a1,8 230440F9 +DEFINE ld_a3,a2,0 430040F9 +DEFINE ld_a3,a3,0 630040F9 +DEFINE ld_a3,t0,0 230140F9 +DEFINE ld_a3,t0,8 230540F9 +DEFINE ld_a3,t0,16 230940F9 +DEFINE ld_t0,a0,0 090040F9 +DEFINE ld_t0,a0,8 090440F9 +DEFINE ld_t0,a0,16 090840F9 +DEFINE ld_t0,a1,0 290040F9 +DEFINE ld_t0,a1,8 290440F9 +DEFINE ld_t0,a1,16 290840F9 +DEFINE ld_t0,a1,24 290C40F9 +DEFINE ld_t0,a1,32 291040F9 +DEFINE ld_t0,a2,0 490040F9 +DEFINE ld_t0,a3,0 690040F9 +DEFINE ld_t0,t0,0 290140F9 +DEFINE ld_t0,t1,8 490540F9 +DEFINE ld_t0,t1,16 490940F9 +DEFINE ld_t0,t2,16 690940F9 +DEFINE ld_t0,sp,0 E90B40F9 +DEFINE ld_t0,sp,8 E90F40F9 +DEFINE ld_t0,sp,16 E91340F9 +DEFINE ld_t0,sp,24 E91740F9 +DEFINE ld_t0,sp,32 E91B40F9 +DEFINE ld_t0,sp,40 E91F40F9 +DEFINE ld_t1,a0,0 0A0040F9 +DEFINE ld_t1,a0,8 0A0440F9 +DEFINE ld_t1,a0,16 0A0840F9 +DEFINE ld_t1,a1,0 2A0040F9 +DEFINE ld_t1,a1,8 2A0440F9 +DEFINE ld_t1,a1,16 2A0840F9 +DEFINE ld_t1,a2,8 4A0440F9 +DEFINE ld_t1,a2,16 4A0840F9 +DEFINE ld_t1,a3,0 6A0040F9 +DEFINE ld_t1,a3,8 6A0440F9 +DEFINE ld_t1,t0,0 2A0140F9 +DEFINE ld_t1,t0,16 2A0940F9 +DEFINE ld_t1,t1,0 4A0140F9 +DEFINE ld_t1,t1,16 4A0940F9 +DEFINE ld_t1,sp,8 EA0F40F9 +DEFINE ld_t1,sp,32 EA1B40F9 +DEFINE ld_t1,sp,48 EA2340F9 +DEFINE ld_t2,a0,0 0B0040F9 +DEFINE ld_t2,a1,0 2B0040F9 +DEFINE ld_t2,a3,16 6B0840F9 +DEFINE ld_t2,t0,0 2B0140F9 +DEFINE ld_t2,t1,0 4B0140F9 +DEFINE ld_t2,sp,16 EB1340F9 +DEFINE st_a0,a1,0 200000F9 +DEFINE st_a0,a2,0 400000F9 +DEFINE st_a0,a2,8 400400F9 +DEFINE st_a0,a2,16 400800F9 +DEFINE st_a0,a3,0 600000F9 +DEFINE st_a0,a3,8 600400F9 +DEFINE st_a0,a3,16 600800F9 +DEFINE st_a0,t0,0 200100F9 +DEFINE st_a0,t0,8 200500F9 +DEFINE st_a0,t2,0 600100F9 +DEFINE st_a0,t2,8 600500F9 +DEFINE st_a0,t2,16 600900F9 +DEFINE st_a0,sp,0 E00B00F9 +DEFINE st_a0,sp,16 E01300F9 +DEFINE st_a1,a0,0 010000F9 +DEFINE st_a1,a2,0 410000F9 +DEFINE st_a1,a2,16 410800F9 +DEFINE st_a1,a3,0 610000F9 +DEFINE st_a1,a3,8 610400F9 +DEFINE st_a1,t0,0 210100F9 +DEFINE st_a1,t0,8 210500F9 +DEFINE st_a1,t0,16 210900F9 +DEFINE st_a1,t1,0 410100F9 +DEFINE st_a1,t1,8 410500F9 +DEFINE st_a1,t1,16 410900F9 +DEFINE st_a1,t2,16 610900F9 +DEFINE st_a1,sp,8 E10F00F9 +DEFINE st_a1,sp,16 E11300F9 +DEFINE st_a2,a0,0 020000F9 +DEFINE st_a2,a1,0 220000F9 +DEFINE st_a2,a3,0 620000F9 +DEFINE st_a2,a3,16 620800F9 +DEFINE st_a2,a3,32 621000F9 +DEFINE st_a2,t0,0 220100F9 +DEFINE st_a2,t0,16 220900F9 +DEFINE st_a2,t1,0 420100F9 +DEFINE st_a2,t2,0 620100F9 +DEFINE st_a3,a0,0 030000F9 +DEFINE st_a3,a2,0 430000F9 +DEFINE st_a3,t0,0 230100F9 +DEFINE st_a3,t1,8 430500F9 +DEFINE st_a3,t2,0 630100F9 +DEFINE st_a3,t2,8 630500F9 +DEFINE st_a3,t2,16 630900F9 +DEFINE st_t0,a0,0 090000F9 +DEFINE st_t0,a0,16 090800F9 +DEFINE st_t0,a0,24 090C00F9 +DEFINE st_t0,a1,0 290000F9 +DEFINE st_t0,a2,0 490000F9 +DEFINE st_t0,a3,0 690000F9 +DEFINE st_t0,a3,8 690400F9 +DEFINE st_t0,t1,0 490100F9 +DEFINE st_t0,sp,0 E90B00F9 +DEFINE st_t0,sp,8 E90F00F9 +DEFINE st_t0,sp,16 E91300F9 +DEFINE st_t0,sp,24 E91700F9 +DEFINE st_t0,sp,32 E91B00F9 +DEFINE st_t0,sp,40 E91F00F9 +DEFINE st_t0,sp,48 E92300F9 +DEFINE st_t1,a0,0 0A0000F9 +DEFINE st_t1,a0,24 0A0C00F9 +DEFINE st_t1,a1,0 2A0000F9 +DEFINE st_t1,a3,0 6A0000F9 +DEFINE st_t1,a3,8 6A0400F9 +DEFINE st_t1,a3,16 6A0800F9 +DEFINE st_t1,a3,24 6A0C00F9 +DEFINE st_t1,t0,0 2A0100F9 +DEFINE st_t2,a0,0 0B0000F9 +DEFINE st_t2,a1,0 2B0000F9 +DEFINE st_t2,a2,0 4B0000F9 +DEFINE st_t2,a3,0 6B0000F9 +DEFINE st_t2,t0,0 2B0100F9 +DEFINE st_t2,t1,0 4B0100F9 +DEFINE lb_a0,a0,0 00004039 +DEFINE lb_a0,t0,0 20014039 +DEFINE lb_a1,a1,0 21004039 +DEFINE lb_a1,a3,0 61004039 +DEFINE lb_a1,a3,1 61044039 +DEFINE lb_a1,t0,0 21014039 +DEFINE lb_a1,t0,1 21054039 +DEFINE lb_a2,a1,0 22004039 +DEFINE lb_a2,a2,0 42004039 +DEFINE lb_a3,a1,0 23004039 +DEFINE lb_a3,a2,0 43004039 +DEFINE lb_a3,a3,0 63004039 +DEFINE lb_t0,a3,0 69004039 +DEFINE lb_t0,a3,1 69044039 +DEFINE lb_t0,a3,2 69084039 +DEFINE lb_t0,t0,0 29014039 +DEFINE lb_t2,t0,0 2B014039 +DEFINE lb_t2,t2,0 6B014039 +DEFINE sb_a0,a1,0 20000039 +DEFINE sb_a0,a2,0 40000039 +DEFINE sb_a0,t2,0 60010039 +DEFINE sb_a1,a2,0 41000039 +DEFINE sb_a2,a0,0 02000039 +DEFINE sb_a2,a1,0 22000039 +DEFINE sb_a2,a3,0 62000039 +DEFINE sb_a2,t2,0 62010039 +DEFINE sb_a3,a0,0 03000039 +DEFINE sb_a3,a1,0 23000039 +DEFINE sb_a3,a2,0 43000039 +DEFINE sb_a3,t2,0 63010039 +DEFINE sb_t1,a0,0 0A000039 +DEFINE sb_t1,a2,0 4A000039 +DEFINE sb_t2,a0,0 0B000039 +DEFINE sb_t2,a1,0 2B000039 +DEFINE sb_t2,a2,0 4B000039 + +## ---- ABI Access + +## ---- Branches +DEFINE b 20021FD6 +DEFINE beq_a0,a1 1F0001EB4100005420021FD6 +DEFINE beq_a0,t0 1F0009EB4100005420021FD6 +DEFINE beq_a0,t1 1F000AEB4100005420021FD6 +DEFINE beq_a1,a2 3F0002EB4100005420021FD6 +DEFINE beq_a2,a3 5F0003EB4100005420021FD6 +DEFINE beq_a3,a2 7F0002EB4100005420021FD6 +DEFINE beq_a3,t0 7F0009EB4100005420021FD6 +DEFINE beq_a3,t1 7F000AEB4100005420021FD6 +DEFINE beq_t0,a0 3F0100EB4100005420021FD6 +DEFINE beq_t0,a1 3F0101EB4100005420021FD6 +DEFINE beq_t0,a2 3F0102EB4100005420021FD6 +DEFINE beq_t0,t1 3F010AEB4100005420021FD6 +DEFINE beq_t0,t2 3F010BEB4100005420021FD6 +DEFINE beq_t1,a0 5F0100EB4100005420021FD6 +DEFINE beq_t1,a1 5F0101EB4100005420021FD6 +DEFINE beq_t1,a2 5F0102EB4100005420021FD6 +DEFINE beq_t1,t0 5F0109EB4100005420021FD6 +DEFINE beq_t1,t2 5F010BEB4100005420021FD6 +DEFINE beq_t2,a0 7F0100EB4100005420021FD6 +DEFINE beq_t2,a2 7F0102EB4100005420021FD6 +DEFINE beq_t2,a3 7F0103EB4100005420021FD6 +DEFINE beq_t2,t0 7F0109EB4100005420021FD6 +DEFINE beq_t2,t1 7F010AEB4100005420021FD6 +DEFINE bne_a0,t0 1F0009EB4000005420021FD6 +DEFINE bne_a1,a2 3F0002EB4000005420021FD6 +DEFINE bne_a1,t0 3F0009EB4000005420021FD6 +DEFINE bne_a2,a3 5F0003EB4000005420021FD6 +DEFINE bne_a3,a0 7F0000EB4000005420021FD6 +DEFINE bne_a3,a2 7F0002EB4000005420021FD6 +DEFINE bne_a3,t0 7F0009EB4000005420021FD6 +DEFINE bne_t0,t1 3F010AEB4000005420021FD6 +DEFINE bne_t0,t2 3F010BEB4000005420021FD6 +DEFINE bne_t1,a2 5F0102EB4000005420021FD6 +DEFINE bne_t1,a3 5F0103EB4000005420021FD6 +DEFINE bne_t1,t2 5F010BEB4000005420021FD6 +DEFINE bne_t2,a2 7F0102EB4000005420021FD6 +DEFINE bne_t2,a3 7F0103EB4000005420021FD6 +DEFINE bne_t2,t0 7F0109EB4000005420021FD6 +DEFINE blt_a0,a2 1F0002EB4A00005420021FD6 +DEFINE blt_a1,a0 3F0000EB4A00005420021FD6 +DEFINE blt_a1,a2 3F0002EB4A00005420021FD6 +DEFINE blt_a1,t2 3F000BEB4A00005420021FD6 +DEFINE blt_a2,a1 5F0001EB4A00005420021FD6 +DEFINE blt_a2,a3 5F0003EB4A00005420021FD6 +DEFINE blt_a2,t0 5F0009EB4A00005420021FD6 +DEFINE blt_a2,t1 5F000AEB4A00005420021FD6 +DEFINE blt_a2,t2 5F000BEB4A00005420021FD6 +DEFINE blt_a3,a2 7F0002EB4A00005420021FD6 +DEFINE blt_a3,t2 7F000BEB4A00005420021FD6 +DEFINE blt_t0,t1 3F010AEB4A00005420021FD6 +DEFINE blt_t0,t2 3F010BEB4A00005420021FD6 +DEFINE blt_t1,a1 5F0101EB4A00005420021FD6 +DEFINE blt_t1,t0 5F0109EB4A00005420021FD6 +DEFINE blt_t2,a3 7F0103EB4A00005420021FD6 +DEFINE blt_t2,t1 7F010AEB4A00005420021FD6 +DEFINE bltu_t0,t1 3F010AEB4200005420021FD6 +DEFINE beqz_a0 400000B520021FD6 +DEFINE beqz_a1 410000B520021FD6 +DEFINE beqz_a2 420000B520021FD6 +DEFINE beqz_a3 430000B520021FD6 +DEFINE beqz_t0 490000B520021FD6 +DEFINE beqz_t1 4A0000B520021FD6 +DEFINE beqz_t2 4B0000B520021FD6 +DEFINE bnez_a0 400000B420021FD6 +DEFINE bnez_a1 410000B420021FD6 +DEFINE bnez_a2 420000B420021FD6 +DEFINE bnez_t0 490000B420021FD6 +DEFINE bnez_t1 4A0000B420021FD6 +DEFINE bnez_t2 4B0000B420021FD6 +DEFINE bltz_a0 1F001FEB4A00005420021FD6 +DEFINE bltz_t0 3F011FEB4A00005420021FD6 + +## ---- Calls And Returns +DEFINE call 20023FD6 +DEFINE ret C0035FD6 +DEFINE eret FE0340F9E80740F91F010091C0035FD6 +DEFINE tail FE0340F9E80740F91F01009120021FD6 + +## ---- Frame Management +DEFINE enter_0 FF4300D1FE0300F9E8430091E80700F9 +DEFINE enter_8 FF8300D1FE0300F9E8830091E80700F9 +DEFINE enter_16 FF8300D1FE0300F9E8830091E80700F9 +DEFINE enter_40 FF0301D1FE0300F9E8030191E80700F9 +DEFINE enter_56 FF4301D1FE0300F9E8430191E80700F9 + +## ---- System +DEFINE syscall E80300AAF70301AAF80302AAF90303AAE00317AAE10318AAE20319AAE30309AAE40313AAE50314AA010000D4E10317AAE20318AAE30319AA +DEFINE sys_close 3900000000000000 +DEFINE sys_exit 5D00000000000000 +DEFINE sys_openat 3800000000000000 +DEFINE sys_read 3F00000000000000 +DEFINE sys_write 4000000000000000 + +## ---- Program Entry +## Backend-owned :_start stub per docs/P1.md §Program Entry. +## Calls p1_main under the one-word direct-result convention +## (a0=argc, a1=argv) and sys_exits its return value. +:_start +'E00340F9' +'E1230091' +'5100001802000014' +&p1_main +'20023FD6' +'A80B80D2' +'010000D4' diff --git a/P1/P1-amd64.M1 b/P1/P1-amd64.M1 @@ -0,0 +1,520 @@ +## amd64.M1 — GENERATED by p1/gen/p1_gen.py. Do not edit by hand. +## +## This table targets the P1 ISA described in docs/P1.md. +## Row shapes are shared; per-arch lowering lives in p1/gen/<arch>.py. + + +## ---- Materialization +DEFINE li_a0 48BF +DEFINE li_a1 48BE +DEFINE li_a2 48BA +DEFINE li_a3 48B9 +DEFINE li_t0 49BA +DEFINE li_t1 49BB +DEFINE li_t2 49B8 +DEFINE la_a0 BF +DEFINE la_a1 BE +DEFINE la_a2 BA +DEFINE la_a3 B9 +DEFINE la_t0 41BA +DEFINE la_t1 41BB +DEFINE la_t2 41B8 +DEFINE la_br 41BF + +## ---- Moves +DEFINE mov_a0,a3 4889CF +DEFINE mov_a0,t0 4C89D7 +DEFINE mov_a0,t1 4C89DF +DEFINE mov_a0,t2 4C89C7 +DEFINE mov_a1,a0 4889FE +DEFINE mov_a1,t0 4C89D6 +DEFINE mov_a1,t1 4C89DE +DEFINE mov_a1,t2 4C89C6 +DEFINE mov_a2,a1 4889F2 +DEFINE mov_a2,t0 4C89D2 +DEFINE mov_a2,t1 4C89DA +DEFINE mov_a3,t0 4C89D1 +DEFINE mov_a3,t1 4C89D9 +DEFINE mov_t0,a0 4989FA +DEFINE mov_t1,a0 4989FB +DEFINE mov_t2,a0 4989F8 +DEFINE mov_t2,t1 4D89D8 + +## ---- Register Arithmetic +DEFINE add_a0,a0,a1 4889FF4801F7 +DEFINE add_a0,a0,a2 4889FF4801D7 +DEFINE add_a0,a0,t0 4889FF4C01D7 +DEFINE add_a0,a0,t1 4889FF4C01DF +DEFINE add_a0,a0,t2 4889FF4C01C7 +DEFINE add_a0,a2,a0 4989F94889D74C01CF +DEFINE add_a0,a2,t2 4889D74C01C7 +DEFINE add_a0,t0,a3 4C89D74801CF +DEFINE add_a0,t1,a0 4989F94C89DF4C01CF +DEFINE add_a0,t1,t2 4C89DF4C01C7 +DEFINE add_a0,t2,a1 4C89C74801F7 +DEFINE add_a1,a0,a1 4989F14889FE4C01CE +DEFINE add_a1,a1,a0 4889F64801FE +DEFINE add_a1,a1,a2 4889F64801D6 +DEFINE add_a1,a1,a3 4889F64801CE +DEFINE add_a1,a1,t0 4889F64C01D6 +DEFINE add_a1,a1,t1 4889F64C01DE +DEFINE add_a1,a2,a1 4989F14889D64C01CE +DEFINE add_a1,a2,a3 4889D64801CE +DEFINE add_a1,a2,t0 4889D64C01D6 +DEFINE add_a1,a3,a1 4989F14889CE4C01CE +DEFINE add_a1,t0,a0 4C89D64801FE +DEFINE add_a1,t2,a1 4989F14C89C64C01CE +DEFINE add_a1,t2,a3 4C89C64801CE +DEFINE add_a1,t2,t1 4C89C64C01DE +DEFINE add_a2,a1,a3 4889F24801CA +DEFINE add_a2,a1,t0 4889F24C01D2 +DEFINE add_a2,a2,a0 4889D24801FA +DEFINE add_a2,a2,a3 4889D24801CA +DEFINE add_a2,a2,t0 4889D24C01D2 +DEFINE add_a2,a2,t1 4889D24C01DA +DEFINE add_a2,a3,a2 4989D14889CA4C01CA +DEFINE add_a2,t0,t1 4C89D24C01DA +DEFINE add_a2,t1,t2 4C89DA4C01C2 +DEFINE add_a2,t2,a0 4C89C24801FA +DEFINE add_a2,t2,a2 4989D14C89C24C01CA +DEFINE add_a3,a0,a2 4889F94801D1 +DEFINE add_a3,a1,t1 4889F14C01D9 +DEFINE add_a3,a1,t2 4889F14C01C1 +DEFINE add_a3,a3,a1 4889C94801F1 +DEFINE add_a3,a3,a2 4889C94801D1 +DEFINE add_a3,a3,t0 4889C94C01D1 +DEFINE add_a3,a3,t1 4889C94C01D9 +DEFINE add_a3,a3,t2 4889C94C01C1 +DEFINE add_a3,t0,t2 4C89D14C01C1 +DEFINE add_a3,t1,a2 4C89D94801D1 +DEFINE add_t0,a1,t2 4989F24D01C2 +DEFINE add_t0,a3,a1 4989CA4901F2 +DEFINE add_t0,t0,a0 4D89D24901FA +DEFINE add_t0,t0,a1 4D89D24901F2 +DEFINE add_t0,t0,a3 4D89D24901CA +DEFINE add_t0,t0,t1 4D89D24D01DA +DEFINE add_t1,t0,t1 4D89D94D89D34D01CB +DEFINE add_t1,t1,a0 4D89DB4901FB +DEFINE add_t1,t1,a1 4D89DB4901F3 +DEFINE add_t1,t1,a2 4D89DB4901D3 +DEFINE add_t1,t1,t2 4D89DB4D01C3 +DEFINE add_t2,a0,t0 4989F84D01D0 +DEFINE add_t2,a0,t1 4989F84D01D8 +DEFINE add_t2,a1,a3 4989F04901C8 +DEFINE add_t2,a1,t2 4D89C14989F04D01C8 +DEFINE add_t2,a2,t1 4989D04D01D8 +DEFINE add_t2,t0,t1 4D89D04D01D8 +DEFINE add_t2,t1,t2 4D89C14D89D84D01C8 +DEFINE add_t2,t2,a0 4D89C04901F8 +DEFINE add_t2,t2,a3 4D89C04901C8 +DEFINE sub_a0,a0,t1 4889FF4C29DF +DEFINE sub_a0,a1,t2 4889F74C29C7 +DEFINE sub_a0,a3,a0 4989F94889CF4C29CF +DEFINE sub_a1,t0,a0 4C89D64829FE +DEFINE sub_a2,a1,a0 4889F24829FA +DEFINE sub_a2,a2,a2 4989D14889D24C29CA +DEFINE sub_a2,a2,t0 4889D24C29D2 +DEFINE sub_a2,t0,t1 4C89D24C29DA +DEFINE sub_a2,t2,a3 4C89C24829CA +DEFINE sub_a3,a3,a1 4889C94829F1 +DEFINE sub_a3,a3,a2 4889C94829D1 +DEFINE sub_a3,t0,a2 4C89D14829D1 +DEFINE sub_a3,t0,a3 4989C94C89D14C29C9 +DEFINE sub_a3,t0,t1 4C89D14C29D9 +DEFINE sub_a3,t1,a2 4C89D94829D1 +DEFINE sub_a3,t1,t0 4C89D94C29D1 +DEFINE sub_a3,t2,t1 4C89C14C29D9 +DEFINE sub_t0,a1,a2 4989F24929D2 +DEFINE sub_t0,t0,a0 4D89D24929FA +DEFINE sub_t0,t0,a1 4D89D24929F2 +DEFINE sub_t0,t0,t1 4D89D24D29DA +DEFINE sub_t2,t1,t0 4D89D84D29D0 +DEFINE and_a3,a3,a2 4889C94821D1 +DEFINE or_a0,a0,a1 4889FF4809F7 +DEFINE or_a0,a0,a2 4889FF4809D7 +DEFINE or_a3,a3,a2 4889C94809D1 +DEFINE xor_a2,a2,a3 4889D24831CA +DEFINE xor_a3,a3,a2 4889C94831D1 +DEFINE shl_a2,a2,a3 4889CD4989D14889C949D3E14889E94C89CA +DEFINE sar_a2,a2,a3 4889CD4989D14889C949D3F94889E94C89CA +DEFINE mul_a0,a0,a3 4889FF480FAFF9 +DEFINE mul_a0,t1,t2 4C89DF490FAFF8 +DEFINE mul_a1,a1,a3 4889F6480FAFF1 +DEFINE mul_a2,a2,t0 4889D2490FAFD2 +DEFINE mul_a3,a3,a2 4889C9480FAFCA +DEFINE mul_t0,t0,a1 4D89D24C0FAFD6 +DEFINE mul_t0,t0,a2 4D89D24C0FAFD2 +DEFINE mul_t1,t1,a3 4D89DB4C0FAFD9 +DEFINE mul_t2,t0,a2 4D89D04C0FAFC2 +DEFINE div_a0,a0,a1 4889D54989F14889F8489949F7F94889EA4889C7 +DEFINE div_a2,a2,a3 4889D54989C94889D0489949F7F94889EA4889C2 +DEFINE rem_a2,a0,a1 4889D54989F14889F8489949F7F94889D04889EA4889C2 +DEFINE rem_a2,a2,a3 4889D54989C94889D0489949F7F94889D04889EA4889C2 + +## ---- Immediate Arithmetic +DEFINE addi_a0,a0,neg1 4889FF4883C7FF +DEFINE addi_a0,a0,1 4889FF4883C701 +DEFINE addi_a0,a0,24 4889FF4883C718 +DEFINE addi_a1,a1,neg48 4889F64883C6D0 +DEFINE addi_a1,a1,neg24 4889F64883C6E8 +DEFINE addi_a1,a1,neg2 4889F64883C6FE +DEFINE addi_a1,a1,1 4889F64883C601 +DEFINE addi_a1,a1,2 4889F64883C602 +DEFINE addi_a1,a1,3 4889F64883C603 +DEFINE addi_a1,t0,1 4C89D64883C601 +DEFINE addi_a2,a0,1 4889FA4883C201 +DEFINE addi_a2,a2,neg1 4889D24883C2FF +DEFINE addi_a2,a2,1 4889D24883C201 +DEFINE addi_a2,a2,2 4889D24883C202 +DEFINE addi_a2,a2,3 4889D24883C203 +DEFINE addi_a2,a2,8 4889D24883C208 +DEFINE addi_a2,a2,24 4889D24883C218 +DEFINE addi_a2,a2,48 4889D24883C230 +DEFINE addi_a2,t0,1 4C89D24883C201 +DEFINE addi_a2,t2,neg48 4C89C24883C2D0 +DEFINE addi_a3,a3,1 4889C94883C101 +DEFINE addi_a3,a3,24 4889C94883C118 +DEFINE addi_t0,a1,neg24 4989F24983C2E8 +DEFINE addi_t0,a1,24 4989F24983C218 +DEFINE addi_t0,t0,neg1 4D89D24983C2FF +DEFINE addi_t0,t0,1 4D89D24983C201 +DEFINE addi_t0,t0,2 4D89D24983C202 +DEFINE addi_t0,t0,24 4D89D24983C218 +DEFINE addi_t0,t0,48 4D89D24983C230 +DEFINE addi_t1,t0,24 4D89D34983C318 +DEFINE addi_t1,t1,neg24 4D89DB4983C3E8 +DEFINE addi_t1,t1,neg1 4D89DB4983C3FF +DEFINE addi_t1,t1,1 4D89DB4983C301 +DEFINE addi_t1,t1,16 4D89DB4983C310 +DEFINE addi_t1,t1,24 4D89DB4983C318 +DEFINE addi_t2,a1,neg24 4989F04983C0E8 +DEFINE addi_t2,t0,neg24 4D89D04983C0E8 +DEFINE addi_t2,t0,24 4D89D04983C018 +DEFINE addi_t2,t1,2 4D89D84983C002 +DEFINE addi_t2,t2,neg1 4D89C04983C0FF +DEFINE addi_t2,t2,1 4D89C04983C001 +DEFINE addi_t2,t2,24 4D89C04983C018 +DEFINE andi_a2,a0,15 4889FA4883E20F +DEFINE andi_a2,a1,15 4889F24883E20F +DEFINE andi_a2,a2,15 4889D24883E20F +DEFINE andi_a3,a3,15 4889C94883E10F +DEFINE andi_a3,t2,255 4C89C14881E1FF000000 +DEFINE shli_a0,a0,3 4889FF48C1E703 +DEFINE shli_a0,a0,4 4889FF48C1E704 +DEFINE shli_a1,a1,1 4889F648C1E601 +DEFINE shli_a2,t1,3 4C89DA48C1E203 +DEFINE shli_a3,t0,1 4C89D148C1E101 +DEFINE shli_a3,t0,4 4C89D148C1E104 +DEFINE shli_t1,a2,3 4989D349C1E303 +DEFINE shli_t2,t0,3 4D89D049C1E003 +DEFINE shri_a0,a0,6 4889FF48C1EF06 +DEFINE shri_a1,a1,6 4889F648C1EE06 +DEFINE shri_a2,a3,4 4889CA48C1EA04 +DEFINE shri_t2,t2,8 4D89C049C1E808 + +## ---- Memory +DEFINE ld_a0,a0,0 488B7F00 +DEFINE ld_a0,a0,8 488B7F08 +DEFINE ld_a0,a0,16 488B7F10 +DEFINE ld_a0,a1,0 488B7E00 +DEFINE ld_a0,a2,0 488B7A00 +DEFINE ld_a0,a3,0 488B7900 +DEFINE ld_a0,a3,8 488B7908 +DEFINE ld_a0,a3,16 488B7910 +DEFINE ld_a0,sp,0 488B7C2410 +DEFINE ld_a0,sp,8 488B7C2418 +DEFINE ld_a0,sp,24 488B7C2428 +DEFINE ld_a1,a0,0 488B7700 +DEFINE ld_a1,a0,8 488B7708 +DEFINE ld_a1,a0,24 488B7718 +DEFINE ld_a1,a1,0 488B7600 +DEFINE ld_a1,a2,8 488B7208 +DEFINE ld_a1,a3,8 488B7108 +DEFINE ld_a1,t0,0 498B7200 +DEFINE ld_a1,t0,8 498B7208 +DEFINE ld_a1,t0,16 498B7210 +DEFINE ld_a1,t1,0 498B7300 +DEFINE ld_a1,t2,16 498B7010 +DEFINE ld_a1,sp,8 488B742418 +DEFINE ld_a2,a0,0 488B5700 +DEFINE ld_a2,a0,8 488B5708 +DEFINE ld_a2,a0,16 488B5710 +DEFINE ld_a2,a1,0 488B5600 +DEFINE ld_a2,a1,8 488B5608 +DEFINE ld_a2,a2,0 488B5200 +DEFINE ld_a2,t0,0 498B5200 +DEFINE ld_a2,t0,8 498B5208 +DEFINE ld_a2,t0,16 498B5210 +DEFINE ld_a2,t1,neg24 498B53E8 +DEFINE ld_a2,t2,0 498B5000 +DEFINE ld_a2,sp,16 488B542420 +DEFINE ld_a3,a0,0 488B4F00 +DEFINE ld_a3,a0,8 488B4F08 +DEFINE ld_a3,a0,16 488B4F10 +DEFINE ld_a3,a1,0 488B4E00 +DEFINE ld_a3,a1,8 488B4E08 +DEFINE ld_a3,a2,0 488B4A00 +DEFINE ld_a3,a3,0 488B4900 +DEFINE ld_a3,t0,0 498B4A00 +DEFINE ld_a3,t0,8 498B4A08 +DEFINE ld_a3,t0,16 498B4A10 +DEFINE ld_t0,a0,0 4C8B5700 +DEFINE ld_t0,a0,8 4C8B5708 +DEFINE ld_t0,a0,16 4C8B5710 +DEFINE ld_t0,a1,0 4C8B5600 +DEFINE ld_t0,a1,8 4C8B5608 +DEFINE ld_t0,a1,16 4C8B5610 +DEFINE ld_t0,a1,24 4C8B5618 +DEFINE ld_t0,a1,32 4C8B5620 +DEFINE ld_t0,a2,0 4C8B5200 +DEFINE ld_t0,a3,0 4C8B5100 +DEFINE ld_t0,t0,0 4D8B5200 +DEFINE ld_t0,t1,8 4D8B5308 +DEFINE ld_t0,t1,16 4D8B5310 +DEFINE ld_t0,t2,16 4D8B5010 +DEFINE ld_t0,sp,0 4C8B542410 +DEFINE ld_t0,sp,8 4C8B542418 +DEFINE ld_t0,sp,16 4C8B542420 +DEFINE ld_t0,sp,24 4C8B542428 +DEFINE ld_t0,sp,32 4C8B542430 +DEFINE ld_t0,sp,40 4C8B542438 +DEFINE ld_t1,a0,0 4C8B5F00 +DEFINE ld_t1,a0,8 4C8B5F08 +DEFINE ld_t1,a0,16 4C8B5F10 +DEFINE ld_t1,a1,0 4C8B5E00 +DEFINE ld_t1,a1,8 4C8B5E08 +DEFINE ld_t1,a1,16 4C8B5E10 +DEFINE ld_t1,a2,8 4C8B5A08 +DEFINE ld_t1,a2,16 4C8B5A10 +DEFINE ld_t1,a3,0 4C8B5900 +DEFINE ld_t1,a3,8 4C8B5908 +DEFINE ld_t1,t0,0 4D8B5A00 +DEFINE ld_t1,t0,16 4D8B5A10 +DEFINE ld_t1,t1,0 4D8B5B00 +DEFINE ld_t1,t1,16 4D8B5B10 +DEFINE ld_t1,sp,8 4C8B5C2418 +DEFINE ld_t1,sp,32 4C8B5C2430 +DEFINE ld_t1,sp,48 4C8B5C2440 +DEFINE ld_t2,a0,0 4C8B4700 +DEFINE ld_t2,a1,0 4C8B4600 +DEFINE ld_t2,a3,16 4C8B4110 +DEFINE ld_t2,t0,0 4D8B4200 +DEFINE ld_t2,t1,0 4D8B4300 +DEFINE ld_t2,sp,16 4C8B442420 +DEFINE st_a0,a1,0 48897E00 +DEFINE st_a0,a2,0 48897A00 +DEFINE st_a0,a2,8 48897A08 +DEFINE st_a0,a2,16 48897A10 +DEFINE st_a0,a3,0 48897900 +DEFINE st_a0,a3,8 48897908 +DEFINE st_a0,a3,16 48897910 +DEFINE st_a0,t0,0 49897A00 +DEFINE st_a0,t0,8 49897A08 +DEFINE st_a0,t2,0 49897800 +DEFINE st_a0,t2,8 49897808 +DEFINE st_a0,t2,16 49897810 +DEFINE st_a0,sp,0 48897C2410 +DEFINE st_a0,sp,16 48897C2420 +DEFINE st_a1,a0,0 48897700 +DEFINE st_a1,a2,0 48897200 +DEFINE st_a1,a2,16 48897210 +DEFINE st_a1,a3,0 48897100 +DEFINE st_a1,a3,8 48897108 +DEFINE st_a1,t0,0 49897200 +DEFINE st_a1,t0,8 49897208 +DEFINE st_a1,t0,16 49897210 +DEFINE st_a1,t1,0 49897300 +DEFINE st_a1,t1,8 49897308 +DEFINE st_a1,t1,16 49897310 +DEFINE st_a1,t2,16 49897010 +DEFINE st_a1,sp,8 4889742418 +DEFINE st_a1,sp,16 4889742420 +DEFINE st_a2,a0,0 48895700 +DEFINE st_a2,a1,0 48895600 +DEFINE st_a2,a3,0 48895100 +DEFINE st_a2,a3,16 48895110 +DEFINE st_a2,a3,32 48895120 +DEFINE st_a2,t0,0 49895200 +DEFINE st_a2,t0,16 49895210 +DEFINE st_a2,t1,0 49895300 +DEFINE st_a2,t2,0 49895000 +DEFINE st_a3,a0,0 48894F00 +DEFINE st_a3,a2,0 48894A00 +DEFINE st_a3,t0,0 49894A00 +DEFINE st_a3,t1,8 49894B08 +DEFINE st_a3,t2,0 49894800 +DEFINE st_a3,t2,8 49894808 +DEFINE st_a3,t2,16 49894810 +DEFINE st_t0,a0,0 4C895700 +DEFINE st_t0,a0,16 4C895710 +DEFINE st_t0,a0,24 4C895718 +DEFINE st_t0,a1,0 4C895600 +DEFINE st_t0,a2,0 4C895200 +DEFINE st_t0,a3,0 4C895100 +DEFINE st_t0,a3,8 4C895108 +DEFINE st_t0,t1,0 4D895300 +DEFINE st_t0,sp,0 4C89542410 +DEFINE st_t0,sp,8 4C89542418 +DEFINE st_t0,sp,16 4C89542420 +DEFINE st_t0,sp,24 4C89542428 +DEFINE st_t0,sp,32 4C89542430 +DEFINE st_t0,sp,40 4C89542438 +DEFINE st_t0,sp,48 4C89542440 +DEFINE st_t1,a0,0 4C895F00 +DEFINE st_t1,a0,24 4C895F18 +DEFINE st_t1,a1,0 4C895E00 +DEFINE st_t1,a3,0 4C895900 +DEFINE st_t1,a3,8 4C895908 +DEFINE st_t1,a3,16 4C895910 +DEFINE st_t1,a3,24 4C895918 +DEFINE st_t1,t0,0 4D895A00 +DEFINE st_t2,a0,0 4C894700 +DEFINE st_t2,a1,0 4C894600 +DEFINE st_t2,a2,0 4C894200 +DEFINE st_t2,a3,0 4C894100 +DEFINE st_t2,t0,0 4D894200 +DEFINE st_t2,t1,0 4D894300 +DEFINE lb_a0,a0,0 480FB67F00 +DEFINE lb_a0,t0,0 490FB67A00 +DEFINE lb_a1,a1,0 480FB67600 +DEFINE lb_a1,a3,0 480FB67100 +DEFINE lb_a1,a3,1 480FB67101 +DEFINE lb_a1,t0,0 490FB67200 +DEFINE lb_a1,t0,1 490FB67201 +DEFINE lb_a2,a1,0 480FB65600 +DEFINE lb_a2,a2,0 480FB65200 +DEFINE lb_a3,a1,0 480FB64E00 +DEFINE lb_a3,a2,0 480FB64A00 +DEFINE lb_a3,a3,0 480FB64900 +DEFINE lb_t0,a3,0 4C0FB65100 +DEFINE lb_t0,a3,1 4C0FB65101 +DEFINE lb_t0,a3,2 4C0FB65102 +DEFINE lb_t0,t0,0 4D0FB65200 +DEFINE lb_t2,t0,0 4D0FB64200 +DEFINE lb_t2,t2,0 4D0FB64000 +DEFINE sb_a0,a1,0 48887E00 +DEFINE sb_a0,a2,0 48887A00 +DEFINE sb_a0,t2,0 49887800 +DEFINE sb_a1,a2,0 48887200 +DEFINE sb_a2,a0,0 48885700 +DEFINE sb_a2,a1,0 48885600 +DEFINE sb_a2,a3,0 48885100 +DEFINE sb_a2,t2,0 49885000 +DEFINE sb_a3,a0,0 48884F00 +DEFINE sb_a3,a1,0 48884E00 +DEFINE sb_a3,a2,0 48884A00 +DEFINE sb_a3,t2,0 49884800 +DEFINE sb_t1,a0,0 4C885F00 +DEFINE sb_t1,a2,0 4C885A00 +DEFINE sb_t2,a0,0 4C884700 +DEFINE sb_t2,a1,0 4C884600 +DEFINE sb_t2,a2,0 4C884200 + +## ---- ABI Access + +## ---- Branches +DEFINE b 41FFE7 +DEFINE beq_a0,a1 4839F7750341FFE7 +DEFINE beq_a0,t0 4C39D7750341FFE7 +DEFINE beq_a0,t1 4C39DF750341FFE7 +DEFINE beq_a1,a2 4839D6750341FFE7 +DEFINE beq_a2,a3 4839CA750341FFE7 +DEFINE beq_a3,a2 4839D1750341FFE7 +DEFINE beq_a3,t0 4C39D1750341FFE7 +DEFINE beq_a3,t1 4C39D9750341FFE7 +DEFINE beq_t0,a0 4939FA750341FFE7 +DEFINE beq_t0,a1 4939F2750341FFE7 +DEFINE beq_t0,a2 4939D2750341FFE7 +DEFINE beq_t0,t1 4D39DA750341FFE7 +DEFINE beq_t0,t2 4D39C2750341FFE7 +DEFINE beq_t1,a0 4939FB750341FFE7 +DEFINE beq_t1,a1 4939F3750341FFE7 +DEFINE beq_t1,a2 4939D3750341FFE7 +DEFINE beq_t1,t0 4D39D3750341FFE7 +DEFINE beq_t1,t2 4D39C3750341FFE7 +DEFINE beq_t2,a0 4939F8750341FFE7 +DEFINE beq_t2,a2 4939D0750341FFE7 +DEFINE beq_t2,a3 4939C8750341FFE7 +DEFINE beq_t2,t0 4D39D0750341FFE7 +DEFINE beq_t2,t1 4D39D8750341FFE7 +DEFINE bne_a0,t0 4C39D7740341FFE7 +DEFINE bne_a1,a2 4839D6740341FFE7 +DEFINE bne_a1,t0 4C39D6740341FFE7 +DEFINE bne_a2,a3 4839CA740341FFE7 +DEFINE bne_a3,a0 4839F9740341FFE7 +DEFINE bne_a3,a2 4839D1740341FFE7 +DEFINE bne_a3,t0 4C39D1740341FFE7 +DEFINE bne_t0,t1 4D39DA740341FFE7 +DEFINE bne_t0,t2 4D39C2740341FFE7 +DEFINE bne_t1,a2 4939D3740341FFE7 +DEFINE bne_t1,a3 4939CB740341FFE7 +DEFINE bne_t1,t2 4D39C3740341FFE7 +DEFINE bne_t2,a2 4939D0740341FFE7 +DEFINE bne_t2,a3 4939C8740341FFE7 +DEFINE bne_t2,t0 4D39D0740341FFE7 +DEFINE blt_a0,a2 4839D77D0341FFE7 +DEFINE blt_a1,a0 4839FE7D0341FFE7 +DEFINE blt_a1,a2 4839D67D0341FFE7 +DEFINE blt_a1,t2 4C39C67D0341FFE7 +DEFINE blt_a2,a1 4839F27D0341FFE7 +DEFINE blt_a2,a3 4839CA7D0341FFE7 +DEFINE blt_a2,t0 4C39D27D0341FFE7 +DEFINE blt_a2,t1 4C39DA7D0341FFE7 +DEFINE blt_a2,t2 4C39C27D0341FFE7 +DEFINE blt_a3,a2 4839D17D0341FFE7 +DEFINE blt_a3,t2 4C39C17D0341FFE7 +DEFINE blt_t0,t1 4D39DA7D0341FFE7 +DEFINE blt_t0,t2 4D39C27D0341FFE7 +DEFINE blt_t1,a1 4939F37D0341FFE7 +DEFINE blt_t1,t0 4D39D37D0341FFE7 +DEFINE blt_t2,a3 4939C87D0341FFE7 +DEFINE blt_t2,t1 4D39D87D0341FFE7 +DEFINE bltu_t0,t1 4D39DA730341FFE7 +DEFINE beqz_a0 4885FF750341FFE7 +DEFINE beqz_a1 4885F6750341FFE7 +DEFINE beqz_a2 4885D2750341FFE7 +DEFINE beqz_a3 4885C9750341FFE7 +DEFINE beqz_t0 4D85D2750341FFE7 +DEFINE beqz_t1 4D85DB750341FFE7 +DEFINE beqz_t2 4D85C0750341FFE7 +DEFINE bnez_a0 4885FF740341FFE7 +DEFINE bnez_a1 4885F6740341FFE7 +DEFINE bnez_a2 4885D2740341FFE7 +DEFINE bnez_t0 4D85D2740341FFE7 +DEFINE bnez_t1 4D85DB740341FFE7 +DEFINE bnez_t2 4D85C0740341FFE7 +DEFINE bltz_a0 4885FF7D0341FFE7 +DEFINE bltz_t0 4D85D27D0341FFE7 + +## ---- Calls And Returns +DEFINE call 41FFD7 +DEFINE ret C3 +DEFINE eret 4C8B4C2400488B4424084889C44151C3 +DEFINE tail 4C8B4C2400488B4424084889C4415141FFE7 + +## ---- Frame Management +DEFINE enter_0 41594889E04881EC100000004C894C24004889442408 +DEFINE enter_8 41594889E04881EC200000004C894C24004889442408 +DEFINE enter_16 41594889E04881EC200000004C894C24004889442408 +DEFINE enter_40 41594889E04881EC400000004C894C24004889442408 +DEFINE enter_56 41594889E04881EC500000004C894C24004889442408 + +## ---- System +DEFINE syscall 565251415341504889F8488B7C2420488B742418488B5424104989D84D89E10F054158415B595A5E4889C7 +DEFINE sys_close 0300000000000000 +DEFINE sys_exit 3C00000000000000 +DEFINE sys_openat 0101000000000000 +DEFINE sys_read 0000000000000000 +DEFINE sys_write 0100000000000000 + +## ---- Program Entry +## Backend-owned :_start stub per docs/P1.md §Program Entry. +## Calls p1_main under the one-word direct-result convention +## (a0=argc, a1=argv) and sys_exits its return value. +:_start +'488B7C2400' +'4889E64883C608' +'41BF' +&p1_main +'41FFD7' +'B83C0000000F05' diff --git a/P1/P1-riscv64.M1 b/P1/P1-riscv64.M1 @@ -0,0 +1,521 @@ +## riscv64.M1 — GENERATED by p1/gen/p1_gen.py. Do not edit by hand. +## +## This table targets the P1 ISA described in docs/P1.md. +## Row shapes are shared; per-arch lowering lives in p1/gen/<arch>.py. + + +## ---- Materialization +DEFINE li_a0 170500000335C5006F00C000 +DEFINE li_a1 9705000083B5C5006F00C000 +DEFINE li_a2 170600000336C6006F00C000 +DEFINE li_a3 9706000083B6C6006F00C000 +DEFINE li_t0 9702000083B2C2006F00C000 +DEFINE li_t1 170300000333C3006F00C000 +DEFINE li_t2 9703000083B3C3006F00C000 +DEFINE la_a0 170500000365C5006F008000 +DEFINE la_a1 9705000083E5C5006F008000 +DEFINE la_a2 170600000366C6006F008000 +DEFINE la_a3 9706000083E6C6006F008000 +DEFINE la_t0 9702000083E2C2006F008000 +DEFINE la_t1 170300000363C3006F008000 +DEFINE la_t2 9703000083E3C3006F008000 +DEFINE la_br 970F000083EFCF006F008000 + +## ---- Moves +DEFINE mov_a0,a3 13850600 +DEFINE mov_a0,t0 13850200 +DEFINE mov_a0,t1 13050300 +DEFINE mov_a0,t2 13850300 +DEFINE mov_a1,a0 93050500 +DEFINE mov_a1,t0 93850200 +DEFINE mov_a1,t1 93050300 +DEFINE mov_a1,t2 93850300 +DEFINE mov_a2,a1 13860500 +DEFINE mov_a2,t0 13860200 +DEFINE mov_a2,t1 13060300 +DEFINE mov_a3,t0 93860200 +DEFINE mov_a3,t1 93060300 +DEFINE mov_t0,a0 93020500 +DEFINE mov_t1,a0 13030500 +DEFINE mov_t2,a0 93030500 +DEFINE mov_t2,t1 93030300 + +## ---- Register Arithmetic +DEFINE add_a0,a0,a1 3305B500 +DEFINE add_a0,a0,a2 3305C500 +DEFINE add_a0,a0,t0 33055500 +DEFINE add_a0,a0,t1 33056500 +DEFINE add_a0,a0,t2 33057500 +DEFINE add_a0,a2,a0 3305A600 +DEFINE add_a0,a2,t2 33057600 +DEFINE add_a0,t0,a3 3385D200 +DEFINE add_a0,t1,a0 3305A300 +DEFINE add_a0,t1,t2 33057300 +DEFINE add_a0,t2,a1 3385B300 +DEFINE add_a1,a0,a1 B305B500 +DEFINE add_a1,a1,a0 B385A500 +DEFINE add_a1,a1,a2 B385C500 +DEFINE add_a1,a1,a3 B385D500 +DEFINE add_a1,a1,t0 B3855500 +DEFINE add_a1,a1,t1 B3856500 +DEFINE add_a1,a2,a1 B305B600 +DEFINE add_a1,a2,a3 B305D600 +DEFINE add_a1,a2,t0 B3055600 +DEFINE add_a1,a3,a1 B385B600 +DEFINE add_a1,t0,a0 B385A200 +DEFINE add_a1,t2,a1 B385B300 +DEFINE add_a1,t2,a3 B385D300 +DEFINE add_a1,t2,t1 B3856300 +DEFINE add_a2,a1,a3 3386D500 +DEFINE add_a2,a1,t0 33865500 +DEFINE add_a2,a2,a0 3306A600 +DEFINE add_a2,a2,a3 3306D600 +DEFINE add_a2,a2,t0 33065600 +DEFINE add_a2,a2,t1 33066600 +DEFINE add_a2,a3,a2 3386C600 +DEFINE add_a2,t0,t1 33866200 +DEFINE add_a2,t1,t2 33067300 +DEFINE add_a2,t2,a0 3386A300 +DEFINE add_a2,t2,a2 3386C300 +DEFINE add_a3,a0,a2 B306C500 +DEFINE add_a3,a1,t1 B3866500 +DEFINE add_a3,a1,t2 B3867500 +DEFINE add_a3,a3,a1 B386B600 +DEFINE add_a3,a3,a2 B386C600 +DEFINE add_a3,a3,t0 B3865600 +DEFINE add_a3,a3,t1 B3866600 +DEFINE add_a3,a3,t2 B3867600 +DEFINE add_a3,t0,t2 B3867200 +DEFINE add_a3,t1,a2 B306C300 +DEFINE add_t0,a1,t2 B3827500 +DEFINE add_t0,a3,a1 B382B600 +DEFINE add_t0,t0,a0 B382A200 +DEFINE add_t0,t0,a1 B382B200 +DEFINE add_t0,t0,a3 B382D200 +DEFINE add_t0,t0,t1 B3826200 +DEFINE add_t1,t0,t1 33836200 +DEFINE add_t1,t1,a0 3303A300 +DEFINE add_t1,t1,a1 3303B300 +DEFINE add_t1,t1,a2 3303C300 +DEFINE add_t1,t1,t2 33037300 +DEFINE add_t2,a0,t0 B3035500 +DEFINE add_t2,a0,t1 B3036500 +DEFINE add_t2,a1,a3 B383D500 +DEFINE add_t2,a1,t2 B3837500 +DEFINE add_t2,a2,t1 B3036600 +DEFINE add_t2,t0,t1 B3836200 +DEFINE add_t2,t1,t2 B3037300 +DEFINE add_t2,t2,a0 B383A300 +DEFINE add_t2,t2,a3 B383D300 +DEFINE sub_a0,a0,t1 33056540 +DEFINE sub_a0,a1,t2 33857540 +DEFINE sub_a0,a3,a0 3385A640 +DEFINE sub_a1,t0,a0 B385A240 +DEFINE sub_a2,a1,a0 3386A540 +DEFINE sub_a2,a2,a2 3306C640 +DEFINE sub_a2,a2,t0 33065640 +DEFINE sub_a2,t0,t1 33866240 +DEFINE sub_a2,t2,a3 3386D340 +DEFINE sub_a3,a3,a1 B386B640 +DEFINE sub_a3,a3,a2 B386C640 +DEFINE sub_a3,t0,a2 B386C240 +DEFINE sub_a3,t0,a3 B386D240 +DEFINE sub_a3,t0,t1 B3866240 +DEFINE sub_a3,t1,a2 B306C340 +DEFINE sub_a3,t1,t0 B3065340 +DEFINE sub_a3,t2,t1 B3866340 +DEFINE sub_t0,a1,a2 B382C540 +DEFINE sub_t0,t0,a0 B382A240 +DEFINE sub_t0,t0,a1 B382B240 +DEFINE sub_t0,t0,t1 B3826240 +DEFINE sub_t2,t1,t0 B3035340 +DEFINE and_a3,a3,a2 B3F6C600 +DEFINE or_a0,a0,a1 3365B500 +DEFINE or_a0,a0,a2 3365C500 +DEFINE or_a3,a3,a2 B3E6C600 +DEFINE xor_a2,a2,a3 3346D600 +DEFINE xor_a3,a3,a2 B3C6C600 +DEFINE shl_a2,a2,a3 3316D600 +DEFINE sar_a2,a2,a3 3356D640 +DEFINE mul_a0,a0,a3 3305D502 +DEFINE mul_a0,t1,t2 33057302 +DEFINE mul_a1,a1,a3 B385D502 +DEFINE mul_a2,a2,t0 33065602 +DEFINE mul_a3,a3,a2 B386C602 +DEFINE mul_t0,t0,a1 B382B202 +DEFINE mul_t0,t0,a2 B382C202 +DEFINE mul_t1,t1,a3 3303D302 +DEFINE mul_t2,t0,a2 B383C202 +DEFINE div_a0,a0,a1 3345B502 +DEFINE div_a2,a2,a3 3346D602 +DEFINE rem_a2,a0,a1 3366B502 +DEFINE rem_a2,a2,a3 3366D602 + +## ---- Immediate Arithmetic +DEFINE addi_a0,a0,neg1 1305F5FF +DEFINE addi_a0,a0,1 13051500 +DEFINE addi_a0,a0,24 13058501 +DEFINE addi_a1,a1,neg48 938505FD +DEFINE addi_a1,a1,neg24 938585FE +DEFINE addi_a1,a1,neg2 9385E5FF +DEFINE addi_a1,a1,1 93851500 +DEFINE addi_a1,a1,2 93852500 +DEFINE addi_a1,a1,3 93853500 +DEFINE addi_a1,t0,1 93851200 +DEFINE addi_a2,a0,1 13061500 +DEFINE addi_a2,a2,neg1 1306F6FF +DEFINE addi_a2,a2,1 13061600 +DEFINE addi_a2,a2,2 13062600 +DEFINE addi_a2,a2,3 13063600 +DEFINE addi_a2,a2,8 13068600 +DEFINE addi_a2,a2,24 13068601 +DEFINE addi_a2,a2,48 13060603 +DEFINE addi_a2,t0,1 13861200 +DEFINE addi_a2,t2,neg48 138603FD +DEFINE addi_a3,a3,1 93861600 +DEFINE addi_a3,a3,24 93868601 +DEFINE addi_t0,a1,neg24 938285FE +DEFINE addi_t0,a1,24 93828501 +DEFINE addi_t0,t0,neg1 9382F2FF +DEFINE addi_t0,t0,1 93821200 +DEFINE addi_t0,t0,2 93822200 +DEFINE addi_t0,t0,24 93828201 +DEFINE addi_t0,t0,48 93820203 +DEFINE addi_t1,t0,24 13838201 +DEFINE addi_t1,t1,neg24 130383FE +DEFINE addi_t1,t1,neg1 1303F3FF +DEFINE addi_t1,t1,1 13031300 +DEFINE addi_t1,t1,16 13030301 +DEFINE addi_t1,t1,24 13038301 +DEFINE addi_t2,a1,neg24 938385FE +DEFINE addi_t2,t0,neg24 938382FE +DEFINE addi_t2,t0,24 93838201 +DEFINE addi_t2,t1,2 93032300 +DEFINE addi_t2,t2,neg1 9383F3FF +DEFINE addi_t2,t2,1 93831300 +DEFINE addi_t2,t2,24 93838301 +DEFINE andi_a2,a0,15 1376F500 +DEFINE andi_a2,a1,15 13F6F500 +DEFINE andi_a2,a2,15 1376F600 +DEFINE andi_a3,a3,15 93F6F600 +DEFINE andi_a3,t2,255 93F6F30F +DEFINE shli_a0,a0,3 13153500 +DEFINE shli_a0,a0,4 13154500 +DEFINE shli_a1,a1,1 93951500 +DEFINE shli_a2,t1,3 13163300 +DEFINE shli_a3,t0,1 93961200 +DEFINE shli_a3,t0,4 93964200 +DEFINE shli_t1,a2,3 13133600 +DEFINE shli_t2,t0,3 93933200 +DEFINE shri_a0,a0,6 13556500 +DEFINE shri_a1,a1,6 93D56500 +DEFINE shri_a2,a3,4 13D64600 +DEFINE shri_t2,t2,8 93D38300 + +## ---- Memory +DEFINE ld_a0,a0,0 03350500 +DEFINE ld_a0,a0,8 03358500 +DEFINE ld_a0,a0,16 03350501 +DEFINE ld_a0,a1,0 03B50500 +DEFINE ld_a0,a2,0 03350600 +DEFINE ld_a0,a3,0 03B50600 +DEFINE ld_a0,a3,8 03B58600 +DEFINE ld_a0,a3,16 03B50601 +DEFINE ld_a0,sp,0 03350101 +DEFINE ld_a0,sp,8 03358101 +DEFINE ld_a0,sp,24 03358102 +DEFINE ld_a1,a0,0 83350500 +DEFINE ld_a1,a0,8 83358500 +DEFINE ld_a1,a0,24 83358501 +DEFINE ld_a1,a1,0 83B50500 +DEFINE ld_a1,a2,8 83358600 +DEFINE ld_a1,a3,8 83B58600 +DEFINE ld_a1,t0,0 83B50200 +DEFINE ld_a1,t0,8 83B58200 +DEFINE ld_a1,t0,16 83B50201 +DEFINE ld_a1,t1,0 83350300 +DEFINE ld_a1,t2,16 83B50301 +DEFINE ld_a1,sp,8 83358101 +DEFINE ld_a2,a0,0 03360500 +DEFINE ld_a2,a0,8 03368500 +DEFINE ld_a2,a0,16 03360501 +DEFINE ld_a2,a1,0 03B60500 +DEFINE ld_a2,a1,8 03B68500 +DEFINE ld_a2,a2,0 03360600 +DEFINE ld_a2,t0,0 03B60200 +DEFINE ld_a2,t0,8 03B68200 +DEFINE ld_a2,t0,16 03B60201 +DEFINE ld_a2,t1,neg24 033683FE +DEFINE ld_a2,t2,0 03B60300 +DEFINE ld_a2,sp,16 03360102 +DEFINE ld_a3,a0,0 83360500 +DEFINE ld_a3,a0,8 83368500 +DEFINE ld_a3,a0,16 83360501 +DEFINE ld_a3,a1,0 83B60500 +DEFINE ld_a3,a1,8 83B68500 +DEFINE ld_a3,a2,0 83360600 +DEFINE ld_a3,a3,0 83B60600 +DEFINE ld_a3,t0,0 83B60200 +DEFINE ld_a3,t0,8 83B68200 +DEFINE ld_a3,t0,16 83B60201 +DEFINE ld_t0,a0,0 83320500 +DEFINE ld_t0,a0,8 83328500 +DEFINE ld_t0,a0,16 83320501 +DEFINE ld_t0,a1,0 83B20500 +DEFINE ld_t0,a1,8 83B28500 +DEFINE ld_t0,a1,16 83B20501 +DEFINE ld_t0,a1,24 83B28501 +DEFINE ld_t0,a1,32 83B20502 +DEFINE ld_t0,a2,0 83320600 +DEFINE ld_t0,a3,0 83B20600 +DEFINE ld_t0,t0,0 83B20200 +DEFINE ld_t0,t1,8 83328300 +DEFINE ld_t0,t1,16 83320301 +DEFINE ld_t0,t2,16 83B20301 +DEFINE ld_t0,sp,0 83320101 +DEFINE ld_t0,sp,8 83328101 +DEFINE ld_t0,sp,16 83320102 +DEFINE ld_t0,sp,24 83328102 +DEFINE ld_t0,sp,32 83320103 +DEFINE ld_t0,sp,40 83328103 +DEFINE ld_t1,a0,0 03330500 +DEFINE ld_t1,a0,8 03338500 +DEFINE ld_t1,a0,16 03330501 +DEFINE ld_t1,a1,0 03B30500 +DEFINE ld_t1,a1,8 03B38500 +DEFINE ld_t1,a1,16 03B30501 +DEFINE ld_t1,a2,8 03338600 +DEFINE ld_t1,a2,16 03330601 +DEFINE ld_t1,a3,0 03B30600 +DEFINE ld_t1,a3,8 03B38600 +DEFINE ld_t1,t0,0 03B30200 +DEFINE ld_t1,t0,16 03B30201 +DEFINE ld_t1,t1,0 03330300 +DEFINE ld_t1,t1,16 03330301 +DEFINE ld_t1,sp,8 03338101 +DEFINE ld_t1,sp,32 03330103 +DEFINE ld_t1,sp,48 03330104 +DEFINE ld_t2,a0,0 83330500 +DEFINE ld_t2,a1,0 83B30500 +DEFINE ld_t2,a3,16 83B30601 +DEFINE ld_t2,t0,0 83B30200 +DEFINE ld_t2,t1,0 83330300 +DEFINE ld_t2,sp,16 83330102 +DEFINE st_a0,a1,0 23B0A500 +DEFINE st_a0,a2,0 2330A600 +DEFINE st_a0,a2,8 2334A600 +DEFINE st_a0,a2,16 2338A600 +DEFINE st_a0,a3,0 23B0A600 +DEFINE st_a0,a3,8 23B4A600 +DEFINE st_a0,a3,16 23B8A600 +DEFINE st_a0,t0,0 23B0A200 +DEFINE st_a0,t0,8 23B4A200 +DEFINE st_a0,t2,0 23B0A300 +DEFINE st_a0,t2,8 23B4A300 +DEFINE st_a0,t2,16 23B8A300 +DEFINE st_a0,sp,0 2338A100 +DEFINE st_a0,sp,16 2330A102 +DEFINE st_a1,a0,0 2330B500 +DEFINE st_a1,a2,0 2330B600 +DEFINE st_a1,a2,16 2338B600 +DEFINE st_a1,a3,0 23B0B600 +DEFINE st_a1,a3,8 23B4B600 +DEFINE st_a1,t0,0 23B0B200 +DEFINE st_a1,t0,8 23B4B200 +DEFINE st_a1,t0,16 23B8B200 +DEFINE st_a1,t1,0 2330B300 +DEFINE st_a1,t1,8 2334B300 +DEFINE st_a1,t1,16 2338B300 +DEFINE st_a1,t2,16 23B8B300 +DEFINE st_a1,sp,8 233CB100 +DEFINE st_a1,sp,16 2330B102 +DEFINE st_a2,a0,0 2330C500 +DEFINE st_a2,a1,0 23B0C500 +DEFINE st_a2,a3,0 23B0C600 +DEFINE st_a2,a3,16 23B8C600 +DEFINE st_a2,a3,32 23B0C602 +DEFINE st_a2,t0,0 23B0C200 +DEFINE st_a2,t0,16 23B8C200 +DEFINE st_a2,t1,0 2330C300 +DEFINE st_a2,t2,0 23B0C300 +DEFINE st_a3,a0,0 2330D500 +DEFINE st_a3,a2,0 2330D600 +DEFINE st_a3,t0,0 23B0D200 +DEFINE st_a3,t1,8 2334D300 +DEFINE st_a3,t2,0 23B0D300 +DEFINE st_a3,t2,8 23B4D300 +DEFINE st_a3,t2,16 23B8D300 +DEFINE st_t0,a0,0 23305500 +DEFINE st_t0,a0,16 23385500 +DEFINE st_t0,a0,24 233C5500 +DEFINE st_t0,a1,0 23B05500 +DEFINE st_t0,a2,0 23305600 +DEFINE st_t0,a3,0 23B05600 +DEFINE st_t0,a3,8 23B45600 +DEFINE st_t0,t1,0 23305300 +DEFINE st_t0,sp,0 23385100 +DEFINE st_t0,sp,8 233C5100 +DEFINE st_t0,sp,16 23305102 +DEFINE st_t0,sp,24 23345102 +DEFINE st_t0,sp,32 23385102 +DEFINE st_t0,sp,40 233C5102 +DEFINE st_t0,sp,48 23305104 +DEFINE st_t1,a0,0 23306500 +DEFINE st_t1,a0,24 233C6500 +DEFINE st_t1,a1,0 23B06500 +DEFINE st_t1,a3,0 23B06600 +DEFINE st_t1,a3,8 23B46600 +DEFINE st_t1,a3,16 23B86600 +DEFINE st_t1,a3,24 23BC6600 +DEFINE st_t1,t0,0 23B06200 +DEFINE st_t2,a0,0 23307500 +DEFINE st_t2,a1,0 23B07500 +DEFINE st_t2,a2,0 23307600 +DEFINE st_t2,a3,0 23B07600 +DEFINE st_t2,t0,0 23B07200 +DEFINE st_t2,t1,0 23307300 +DEFINE lb_a0,a0,0 03450500 +DEFINE lb_a0,t0,0 03C50200 +DEFINE lb_a1,a1,0 83C50500 +DEFINE lb_a1,a3,0 83C50600 +DEFINE lb_a1,a3,1 83C51600 +DEFINE lb_a1,t0,0 83C50200 +DEFINE lb_a1,t0,1 83C51200 +DEFINE lb_a2,a1,0 03C60500 +DEFINE lb_a2,a2,0 03460600 +DEFINE lb_a3,a1,0 83C60500 +DEFINE lb_a3,a2,0 83460600 +DEFINE lb_a3,a3,0 83C60600 +DEFINE lb_t0,a3,0 83C20600 +DEFINE lb_t0,a3,1 83C21600 +DEFINE lb_t0,a3,2 83C22600 +DEFINE lb_t0,t0,0 83C20200 +DEFINE lb_t2,t0,0 83C30200 +DEFINE lb_t2,t2,0 83C30300 +DEFINE sb_a0,a1,0 2380A500 +DEFINE sb_a0,a2,0 2300A600 +DEFINE sb_a0,t2,0 2380A300 +DEFINE sb_a1,a2,0 2300B600 +DEFINE sb_a2,a0,0 2300C500 +DEFINE sb_a2,a1,0 2380C500 +DEFINE sb_a2,a3,0 2380C600 +DEFINE sb_a2,t2,0 2380C300 +DEFINE sb_a3,a0,0 2300D500 +DEFINE sb_a3,a1,0 2380D500 +DEFINE sb_a3,a2,0 2300D600 +DEFINE sb_a3,t2,0 2380D300 +DEFINE sb_t1,a0,0 23006500 +DEFINE sb_t1,a2,0 23006600 +DEFINE sb_t2,a0,0 23007500 +DEFINE sb_t2,a1,0 23807500 +DEFINE sb_t2,a2,0 23007600 + +## ---- ABI Access + +## ---- Branches +DEFINE b 67800F00 +DEFINE beq_a0,a1 6314B50067800F00 +DEFINE beq_a0,t0 6314550067800F00 +DEFINE beq_a0,t1 6314650067800F00 +DEFINE beq_a1,a2 6394C50067800F00 +DEFINE beq_a2,a3 6314D60067800F00 +DEFINE beq_a3,a2 6394C60067800F00 +DEFINE beq_a3,t0 6394560067800F00 +DEFINE beq_a3,t1 6394660067800F00 +DEFINE beq_t0,a0 6394A20067800F00 +DEFINE beq_t0,a1 6394B20067800F00 +DEFINE beq_t0,a2 6394C20067800F00 +DEFINE beq_t0,t1 6394620067800F00 +DEFINE beq_t0,t2 6394720067800F00 +DEFINE beq_t1,a0 6314A30067800F00 +DEFINE beq_t1,a1 6314B30067800F00 +DEFINE beq_t1,a2 6314C30067800F00 +DEFINE beq_t1,t0 6314530067800F00 +DEFINE beq_t1,t2 6314730067800F00 +DEFINE beq_t2,a0 6394A30067800F00 +DEFINE beq_t2,a2 6394C30067800F00 +DEFINE beq_t2,a3 6394D30067800F00 +DEFINE beq_t2,t0 6394530067800F00 +DEFINE beq_t2,t1 6394630067800F00 +DEFINE bne_a0,t0 6304550067800F00 +DEFINE bne_a1,a2 6384C50067800F00 +DEFINE bne_a1,t0 6384550067800F00 +DEFINE bne_a2,a3 6304D60067800F00 +DEFINE bne_a3,a0 6384A60067800F00 +DEFINE bne_a3,a2 6384C60067800F00 +DEFINE bne_a3,t0 6384560067800F00 +DEFINE bne_t0,t1 6384620067800F00 +DEFINE bne_t0,t2 6384720067800F00 +DEFINE bne_t1,a2 6304C30067800F00 +DEFINE bne_t1,a3 6304D30067800F00 +DEFINE bne_t1,t2 6304730067800F00 +DEFINE bne_t2,a2 6384C30067800F00 +DEFINE bne_t2,a3 6384D30067800F00 +DEFINE bne_t2,t0 6384530067800F00 +DEFINE blt_a0,a2 6354C50067800F00 +DEFINE blt_a1,a0 63D4A50067800F00 +DEFINE blt_a1,a2 63D4C50067800F00 +DEFINE blt_a1,t2 63D4750067800F00 +DEFINE blt_a2,a1 6354B60067800F00 +DEFINE blt_a2,a3 6354D60067800F00 +DEFINE blt_a2,t0 6354560067800F00 +DEFINE blt_a2,t1 6354660067800F00 +DEFINE blt_a2,t2 6354760067800F00 +DEFINE blt_a3,a2 63D4C60067800F00 +DEFINE blt_a3,t2 63D4760067800F00 +DEFINE blt_t0,t1 63D4620067800F00 +DEFINE blt_t0,t2 63D4720067800F00 +DEFINE blt_t1,a1 6354B30067800F00 +DEFINE blt_t1,t0 6354530067800F00 +DEFINE blt_t2,a3 63D4D30067800F00 +DEFINE blt_t2,t1 63D4630067800F00 +DEFINE bltu_t0,t1 63F4620067800F00 +DEFINE beqz_a0 6314050067800F00 +DEFINE beqz_a1 6394050067800F00 +DEFINE beqz_a2 6314060067800F00 +DEFINE beqz_a3 6394060067800F00 +DEFINE beqz_t0 6394020067800F00 +DEFINE beqz_t1 6314030067800F00 +DEFINE beqz_t2 6394030067800F00 +DEFINE bnez_a0 6304050067800F00 +DEFINE bnez_a1 6384050067800F00 +DEFINE bnez_a2 6304060067800F00 +DEFINE bnez_t0 6384020067800F00 +DEFINE bnez_t1 6304030067800F00 +DEFINE bnez_t2 6384030067800F00 +DEFINE bltz_a0 6354050067800F00 +DEFINE bltz_t0 63D4020067800F00 + +## ---- Calls And Returns +DEFINE call E7800F00 +DEFINE ret 67800000 +DEFINE eret 83300100033481001301040067800000 +DEFINE tail 83300100033481001301040067800F00 + +## ---- Frame Management +DEFINE enter_0 130101FF233011001304010123348100 +DEFINE enter_8 130101FE233011001304010223348100 +DEFINE enter_16 130101FE233011001304010223348100 +DEFINE enter_40 130101FC233011001304010423348100 +DEFINE enter_56 130101FB233011001304010523348100 + +## ---- System +DEFINE syscall 938E0500130E0600138806009308050013850E0093050E00130608009386020013870400930709007300000093850E0013060E0093060800 +DEFINE sys_close 3900000000000000 +DEFINE sys_exit 5D00000000000000 +DEFINE sys_openat 3800000000000000 +DEFINE sys_read 3F00000000000000 +DEFINE sys_write 4000000000000000 + +## ---- Program Entry +## Backend-owned :_start stub per docs/P1.md §Program Entry. +## Calls p1_main under the one-word direct-result convention +## (a0=argc, a1=argv) and sys_exits its return value. +:_start +'03350100' +'93058100' +'970F000083EFCF006F008000' +&p1_main +'E7800F00' +'9308D005' +'73000000' diff --git a/P1/gen/p1_gen.py b/P1/gen/p1_gen.py @@ -77,7 +77,7 @@ LDARG_SLOTS = tuple(range(32)) ENTER_SIZES = tuple(range(0, 129)) -HEADER = """## p1_{arch}.M1 — GENERATED by p1/gen/p1_gen.py. Do not edit by hand. +HEADER = """## {arch}.M1 — GENERATED by p1/gen/p1_gen.py. Do not edit by hand. ## ## This table targets the P1 ISA described in docs/P1.md. ## Row shapes are shared; per-arch lowering lives in p1/gen/<arch>.py. @@ -233,8 +233,7 @@ def main(argv=None): for arch_name in archs: arch = ARCHES[arch_name] - dest_dir = os.path.join(build_root, arch.name) - path = os.path.join(dest_dir, f'p1_{arch.name}.M1') + path = os.path.join(build_root, f'{arch.name}.M1') content = emit(arch.name) if check: try: @@ -246,7 +245,7 @@ def main(argv=None): sys.stderr.write(f'DIFF: {path}\n') had_diff = True continue - os.makedirs(dest_dir, exist_ok=True) + os.makedirs(build_root, exist_ok=True) with open(path, 'w') as f: f.write(content) print(f'wrote {path} ({len(content)} bytes)') diff --git a/scripts/boot-build-p1.sh b/scripts/boot-build-p1.sh @@ -0,0 +1,44 @@ +#!/bin/sh +## boot-build-p1.sh — in-container .P1/.M1 -> ELF. +## +## Assumes a pre-pruned P1 backend table (P1/P1-<arch>.M1). No prune step +## at build time — that one-time work lives in scripts/prune-p1-table.sh +## and the result is checked in. +## +## Pipeline: +## cat <table> <src> -> /tmp/combined.M1 +## M0 /tmp/combined.M1 -> /tmp/prog.hex2 +## catm /tmp/elf.hex2 /tmp/prog.hex2 -> /tmp/linked.hex2 +## hex2-0 /tmp/linked.hex2 -> $OUT +## +## Stages through /tmp because the stage0 tools do one syscall per byte; +## virtiofs round-trips would dominate otherwise. +## +## Usage: boot-build-p1.sh <table.M1> <src> <ELF.hex2> <work-dir> +## <tools-dir> <out> + +set -eu + +[ "$#" -eq 6 ] || { echo "usage: $0 <table.M1> <src> <ELF.hex2> <work-dir> <tools-dir> <out>" >&2; exit 2; } + +TABLE=$1 +SRC=$2 +ELF_HDR=$3 +WORK=$4 +TOOLS=$5 +OUT=$6 + +mkdir -p "$WORK" "$(dirname "$OUT")" + +cat "$TABLE" "$SRC" > /tmp/combined.M1 +"$TOOLS/M0" /tmp/combined.M1 /tmp/prog.hex2 + +cp "$ELF_HDR" /tmp/elf.hex2 +"$TOOLS/catm" /tmp/linked.hex2 /tmp/elf.hex2 /tmp/prog.hex2 +"$TOOLS/hex2-0" /tmp/linked.hex2 /tmp/prog.bin + +cp /tmp/combined.M1 "$WORK/combined.M1" +cp /tmp/prog.hex2 "$WORK/prog.hex2" +cp /tmp/linked.hex2 "$WORK/linked.hex2" +cp /tmp/prog.bin "$OUT" +chmod 0700 "$OUT" diff --git a/scripts/boot-build-p1pp.sh b/scripts/boot-build-p1pp.sh @@ -0,0 +1,46 @@ +#!/bin/sh +## boot-build-p1pp.sh — in-container .P1pp -> ELF. +## +## Pipeline: +## cat <P1-arch.M1pp> <P1.M1pp> <src.P1pp> -> /tmp/combined.M1pp +## m1pp /tmp/combined.M1pp -> /tmp/expanded.M1 +## M0 /tmp/expanded.M1 -> /tmp/prog.hex2 +## catm /tmp/elf.hex2 /tmp/prog.hex2 -> /tmp/linked.hex2 +## hex2-0 /tmp/linked.hex2 -> $OUT +## +## Uses the per-arch self-hosted m1pp ELF (built by boot2.sh / +## boot-build-p1.sh against M1pp/M1pp.P1). +## +## Usage: boot-build-p1pp.sh <backend.M1pp> <frontend.M1pp> <src.P1pp> +## <ELF.hex2> <work-dir> <m1pp-bin> +## <tools-dir> <out> + +set -eu + +[ "$#" -eq 8 ] || { echo "usage: $0 <backend.M1pp> <frontend.M1pp> <src.P1pp> <ELF.hex2> <work-dir> <m1pp-bin> <tools-dir> <out>" >&2; exit 2; } + +BACKEND=$1 +FRONTEND=$2 +SRC=$3 +ELF_HDR=$4 +WORK=$5 +M1PP_BIN=$6 +TOOLS=$7 +OUT=$8 + +mkdir -p "$WORK" "$(dirname "$OUT")" + +cat "$BACKEND" "$FRONTEND" "$SRC" > /tmp/combined.M1pp +"$M1PP_BIN" /tmp/combined.M1pp /tmp/expanded.M1 +"$TOOLS/M0" /tmp/expanded.M1 /tmp/prog.hex2 + +cp "$ELF_HDR" /tmp/elf.hex2 +"$TOOLS/catm" /tmp/linked.hex2 /tmp/elf.hex2 /tmp/prog.hex2 +"$TOOLS/hex2-0" /tmp/linked.hex2 /tmp/prog.bin + +cp /tmp/combined.M1pp "$WORK/combined.M1pp" +cp /tmp/expanded.M1 "$WORK/expanded.M1" +cp /tmp/prog.hex2 "$WORK/prog.hex2" +cp /tmp/linked.hex2 "$WORK/linked.hex2" +cp /tmp/prog.bin "$OUT" +chmod 0700 "$OUT" diff --git a/scripts/boot1.sh b/scripts/boot1.sh @@ -0,0 +1,46 @@ +#!/bin/sh +## boot1.sh — stage 1 of the bootstrap chain. +## +## In-container script. Brings up M0/hex2-0/catm from the ~400-byte +## hex0-seed by chaining stage0-posix's first three phases. All produced +## binaries are target-arch Linux ELF and land in $OUT as: +## hex0, hex1, hex2-0, catm, M0 +## +## Phase map (stage0-posix mescc-tools-{seed,mini}-kaem.kaem phases 0-3): +## 0) hex0-seed + hex0.hex0 -> hex0 +## 1) hex0 + hex1.hex0 -> hex1 +## 2) hex1 + hex2.hex1 -> hex2-0 +## 2b) hex2-0 + catm.hex2 -> catm +## 3a) catm : ELF.hex2 + M0.hex2 -> M0.combined.hex2 +## 3b) hex2-0 : M0.combined.hex2 -> M0 +## +## Inputs are read from vendor/seed/<arch>/ (vendored upstream). +## +## Usage: boot1.sh <arch> <out-dir> +## arch: aarch64 | amd64 | riscv64 +## out-dir: path (relative to /work) where tool binaries should land + +set -eu + +ARCH=$1 +OUT=$2 + +case "$ARCH" in + aarch64|amd64|riscv64) ;; + *) echo "boot1.sh: unsupported arch '$ARCH'" >&2 ; exit 1 ;; +esac + +S=vendor/seed/$ARCH +mkdir -p "$OUT" + +## Build everything in /tmp (RAM tmpfs — see PODMAN macro in Makefile), +## then cp the final binaries to the bind-mounted $OUT. Stage0 tools do +## one syscall per byte; staying off virtiofs for intermediates is ~5x. +"$S/hex0-seed" "$S/hex0.hex0" /tmp/hex0 +/tmp/hex0 "$S/hex1.hex0" /tmp/hex1 +/tmp/hex1 "$S/hex2.hex1" /tmp/hex2-0 +/tmp/hex2-0 "$S/catm.hex2" /tmp/catm +/tmp/catm /tmp/M0.combined.hex2 "$S/ELF.hex2" "$S/M0.hex2" +/tmp/hex2-0 /tmp/M0.combined.hex2 /tmp/M0 + +cp /tmp/hex0 /tmp/hex1 /tmp/hex2-0 /tmp/catm /tmp/M0 "$OUT/" diff --git a/scripts/boot2.sh b/scripts/boot2.sh @@ -0,0 +1,35 @@ +#!/bin/sh +## boot2.sh — stage 2 of the bootstrap chain. +## +## In-container script. Builds the M1pp expander and pokem ELFs from the +## checked-in pre-pruned P1 backend table (P1/P1-<arch>.M1) plus their +## sources. Calls scripts/boot-build-p1.sh internally. +## +## Output (relative to repo root, /work in container): +## build/<arch>/m1pp, build/<arch>/pokem +## +## Usage: boot2.sh <arch> + +set -eu + +[ "$#" -eq 1 ] || { echo "usage: $0 <arch>" >&2; exit 2; } + +ARCH=$1 + +case "$ARCH" in + aarch64|amd64|riscv64) ;; + *) echo "boot2.sh: unsupported arch '$ARCH'" >&2; exit 1 ;; +esac + +TABLE=/work/P1/P1-$ARCH.M1 +ELF_HDR=/work/vendor/seed/$ARCH/ELF.hex2 +TOOLS=/work/build/$ARCH/tools +OUT=/work/build/$ARCH + +sh /work/scripts/boot-build-p1.sh \ + "$TABLE" /work/M1pp/M1pp.P1 "$ELF_HDR" \ + "$OUT/.work/m1pp" "$TOOLS" "$OUT/m1pp" + +sh /work/scripts/boot-build-p1.sh \ + "$TABLE" /work/pokem/pokem.P1 "$ELF_HDR" \ + "$OUT/.work/pokem" "$TOOLS" "$OUT/pokem" diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh @@ -1,39 +0,0 @@ -#!/bin/sh -## bootstrap.sh — bring up M0/hex2-0/catm from a 400-byte hex0-seed. -## -## Runs inside a target-arch busybox container. All produced binaries are -## target-arch Linux ELF and land in $OUT as: hex0 hex1 hex2-0 catm M0. -## -## Phase map (stage0-posix mescc-tools-{seed,mini}-kaem.kaem phases 0-3): -## 0) hex0-seed + hex0.hex0 -> hex0 -## 1) hex0 + hex1.hex0 -> hex1 -## 2) hex1 + hex2.hex1 -> hex2-0 -## 2b) hex2-0 + catm.hex2 -> catm -## 3a) catm : ELF.hex2 + M0.hex2 -> M0.combined.hex2 -## 3b) hex2-0 : M0.combined.hex2 -> M0 -## -## Inputs are read from vendor/seed/<arch>/ (vendored upstream). -## -## Usage: bootstrap.sh <arch> <out-dir> -## arch: aarch64 | amd64 | riscv64 -## out-dir: path (relative to /work) where tool binaries should land - -set -eu - -ARCH=$1 -OUT=$2 - -case "$ARCH" in - aarch64|amd64|riscv64) ;; - *) echo "bootstrap.sh: unsupported arch '$ARCH'" >&2 ; exit 1 ;; -esac - -S=vendor/seed/$ARCH -mkdir -p "$OUT" - -"$S/hex0-seed" "$S/hex0.hex0" "$OUT/hex0" -"$OUT/hex0" "$S/hex1.hex0" "$OUT/hex1" -"$OUT/hex1" "$S/hex2.hex1" "$OUT/hex2-0" -"$OUT/hex2-0" "$S/catm.hex2" "$OUT/catm" -"$OUT/catm" "$OUT/M0.combined.hex2" "$S/ELF.hex2" "$S/M0.hex2" -"$OUT/hex2-0" "$OUT/M0.combined.hex2" "$OUT/M0" diff --git a/scripts/build-native-tools.sh b/scripts/build-native-tools.sh @@ -1,28 +1,35 @@ #!/bin/sh -## build-native-tools.sh — host-compile mescc-tools M1 + hex2 for dev-loop -## speed. +## build-native-tools.sh — host-compile one of the dev-loop tools. ## -## These are NOT in the bootstrap chain: they're a fast substitute for the -## stage0 M0/hex2-0 produced by scripts/bootstrap.sh. Output is byte-exact -## with the bootstrap tools when invoked with the right flags (see -## scripts/build-p1.sh / scripts/build-p1pp.sh). Running them on the host -## avoids the per-byte syscall storm the stage0 tools incur under Apple's -## linux/arm64 VM (~150x faster on a typical P1 build). +## Pure transformation invoked by the Makefile per-target. Always rebuilds +## the requested tool; Make handles staleness. ## -## Source lookup (first match wins): +## Tools (NOT in the bootstrap chain — fast host substitutes): +## M1, hex2 — built from upstream mescc-tools sources +## m1pp — built from M1pp/M1pp.c (the C oracle) +## +## Source lookup for M1/hex2 (first match wins): ## 1. $MESCC_TOOLS_SRC (if set) ## 2. ../live-bootstrap/seed/stage0-posix/mescc-tools -## 3. ../mescc-tools (if M2libc is populated) +## 3. ../mescc-tools +## +## Usage: scripts/build-native-tools.sh <M1|hex2|m1pp> set -eu +[ "$#" -eq 1 ] || { echo "usage: $0 <M1|hex2|m1pp>" >&2; exit 2; } + +TOOL=$1 REPO=$(cd "$(dirname "$0")/.." && pwd) cd "$REPO" OUT=build/native-tools mkdir -p "$OUT" -find_src() { +: "${CC:=cc}" +CFLAGS="-O2 -std=c99 -D_GNU_SOURCE" + +find_mescc_src() { if [ -n "${MESCC_TOOLS_SRC:-}" ]; then if [ -f "$MESCC_TOOLS_SRC/M1-macro.c" ] && [ -f "$MESCC_TOOLS_SRC/M2libc/bootstrappable.c" ]; then echo "$MESCC_TOOLS_SRC" @@ -46,46 +53,24 @@ find_src() { return 1 } -SRC=$(find_src) - -: "${CC:=cc}" -CFLAGS="-O2 -std=c99 -D_GNU_SOURCE" - -m1_fresh() { - [ -x "$OUT/M1" ] || return 1 - for s in "$SRC/M1-macro.c" "$SRC/stringify.c" "$SRC/M2libc/bootstrappable.c"; do - [ "$OUT/M1" -nt "$s" ] || return 1 - done - return 0 -} -hex2_fresh() { - [ -x "$OUT/hex2" ] || return 1 - for s in "$SRC/hex2.c" "$SRC/hex2_linker.c" "$SRC/hex2_word.c" "$SRC/M2libc/bootstrappable.c"; do - [ "$OUT/hex2" -nt "$s" ] || return 1 - done - return 0 -} -m1pp_fresh() { - [ -x "$OUT/m1pp" ] || return 1 - [ "$OUT/m1pp" -nt "$REPO/M1pp/M1pp.c" ] || return 1 - return 0 -} - -if ! m1_fresh; then - echo " compiling $OUT/M1 from $SRC" - $CC $CFLAGS \ - "$SRC/M1-macro.c" "$SRC/stringify.c" "$SRC/M2libc/bootstrappable.c" \ - -o "$OUT/M1" -fi - -if ! hex2_fresh; then - echo " compiling $OUT/hex2 from $SRC" - $CC $CFLAGS \ - "$SRC/hex2.c" "$SRC/hex2_linker.c" "$SRC/hex2_word.c" "$SRC/M2libc/bootstrappable.c" \ - -o "$OUT/hex2" -fi - -if ! m1pp_fresh; then - echo " compiling $OUT/m1pp from M1pp/M1pp.c" - $CC -O2 -std=c99 M1pp/M1pp.c -o "$OUT/m1pp" -fi +case "$TOOL" in + M1) + SRC=$(find_mescc_src) + $CC $CFLAGS \ + "$SRC/M1-macro.c" "$SRC/stringify.c" "$SRC/M2libc/bootstrappable.c" \ + -o "$OUT/M1" + ;; + hex2) + SRC=$(find_mescc_src) + $CC $CFLAGS \ + "$SRC/hex2.c" "$SRC/hex2_linker.c" "$SRC/hex2_word.c" "$SRC/M2libc/bootstrappable.c" \ + -o "$OUT/hex2" + ;; + m1pp) + $CC -O2 -std=c99 M1pp/M1pp.c -o "$OUT/m1pp" + ;; + *) + echo "build-native-tools.sh: unknown tool '$TOOL'" >&2 + exit 2 + ;; +esac diff --git a/scripts/build-p1.sh b/scripts/build-p1.sh @@ -1,110 +0,0 @@ -#!/bin/sh -## build-p1.sh — assemble a P1 source (.P1 or .M1) into a runnable ELF. -## -## Pipeline: -## 1. lint — assert every P1 op token in <src> is defined -## 2. prune — strip DEFINEs the source doesn't reference -## 3. cat — pruned defs ++ <src> -> combined.M1 -## 4. M1 — combined.M1 -> .hex2 -## 5. cat — ELF header ++ .hex2 -> linked.hex2 -## 6. hex2 — linked.hex2 -> raw ELF -## 7. trim p_filesz, chmod 0700 -## -## Modes (selected via M1PP_BOOTSTRAP_TOOLS env): -## default host-side native mescc-tools M1/hex2 (~150x faster -## than stage0 on Apple Silicon). Built on demand by -## scripts/build-native-tools.sh. -## =1 bootstrap M0/hex2-0 inside a busybox container, with -## /tmp staging to dodge per-byte virtiofs syscall storm. -## Output is byte-identical with the native mode. -## -## Usage: scripts/build-p1.sh <arch> <source.P1|.M1> <output_binary> - -set -eu - -if [ "$#" -ne 3 ]; then - echo "usage: $0 <arch> <source> <output>" >&2 - exit 2 -fi - -ARCH=$1 -SRC=$2 -OUT=$3 - -REPO=$(cd "$(dirname "$0")/.." && pwd) -cd "$REPO" - -case "$ARCH" in - aarch64) PLATFORM=linux/arm64 ;; - amd64) PLATFORM=linux/amd64 ;; - riscv64) PLATFORM=linux/riscv64 ;; - *) echo "build-p1.sh: unsupported arch '$ARCH'" >&2; exit 1 ;; -esac - -P1_DEFS=build/p1/$ARCH/p1_$ARCH.M1 -ELF_HDR=vendor/seed/$ARCH/ELF.hex2 -BASE_ADDR=0x600000 ## must match the load address encoded in $ELF_HDR -TOOLS=build/$ARCH/tools ## bootstrap M0/hex2-0/catm (when M1PP_BOOTSTRAP_TOOLS=1) - -NAME=$(basename "$SRC" | sed 's/\.[^.]*$//') -WORK=build/p1/$ARCH/$NAME.work -mkdir -p "$WORK" "$(dirname "$OUT")" - -for f in "$P1_DEFS" "$ELF_HDR" scripts/lint.sh "$SRC"; do - if [ ! -e "$f" ]; then - echo "build-p1.sh: missing dependency: $f" >&2 - exit 1 - fi -done - -PRUNED=$WORK/p1.pruned.M1 -COMBINED=$WORK/combined.M1 -PROG_HEX2=$WORK/prog.hex2 -LINKED=$WORK/linked.hex2 -RAW=$WORK/prog.raw - -sh scripts/lint.sh "$P1_DEFS" "$SRC" - -awk 'NR==FNR{for(i=1;i<=NF;i++)u[$i]=1;next} /^DEFINE /{if($2 in u)print;next} {print}' \ - "$SRC" "$P1_DEFS" > "$PRUNED" - -cat "$PRUNED" "$SRC" > "$COMBINED" - -if [ "${M1PP_BOOTSTRAP_TOOLS:-0}" = 1 ]; then - for f in "$TOOLS/M0" "$TOOLS/hex2-0" "$TOOLS/catm"; do - [ -e "$f" ] || { echo "build-p1.sh: missing bootstrap dependency: $f" >&2; exit 1; } - done - cat "$ELF_HDR" > "$WORK/elf.hex2" - podman run --rm --pull=never --platform "$PLATFORM" \ - -v "$REPO":/work -w /work \ - "boot2-busybox:$ARCH" sh -ec " - set -eu - cp $COMBINED /tmp/combined.M1 - $TOOLS/M0 /tmp/combined.M1 /tmp/prog.hex2 - cp $WORK/elf.hex2 /tmp/elf.hex2 - $TOOLS/catm /tmp/linked.hex2 /tmp/elf.hex2 /tmp/prog.hex2 - $TOOLS/hex2-0 /tmp/linked.hex2 /tmp/prog.raw - cp /tmp/prog.hex2 $PROG_HEX2 - cp /tmp/linked.hex2 $LINKED - cp /tmp/prog.raw $RAW - " -else - NATIVE_M1=build/native-tools/M1 - NATIVE_HEX2=build/native-tools/hex2 - if [ ! -x "$NATIVE_M1" ] || [ ! -x "$NATIVE_HEX2" ]; then - sh scripts/build-native-tools.sh - fi - "$NATIVE_M1" --architecture "$ARCH" --little-endian \ - -f "$COMBINED" -o "$PROG_HEX2" - cat "$ELF_HDR" "$PROG_HEX2" > "$LINKED" - "$NATIVE_HEX2" --architecture "$ARCH" --little-endian \ - --base-address "$BASE_ADDR" \ - -f "$LINKED" -o "$RAW" -fi - -## Trim trailing zero padding past p_filesz (lives at byte offset 96 as a -## little-endian u32 in the ELF64 program header). The kernel zero-fills -## the BSS gap up to p_memsz at load time. -size=$(od -An -tu4 -N4 -j96 "$RAW" | tr -d ' ') -head -c "$size" "$RAW" > "$OUT" -chmod 0700 "$OUT" diff --git a/scripts/build-p1pp.sh b/scripts/build-p1pp.sh @@ -1,79 +0,0 @@ -#!/bin/sh -## build-p1pp.sh — assemble a P1pp source (.P1pp) into a runnable ELF. -## -## Pipeline: -## 1. cat — P1/P1-<arch>.M1pp ++ P1/P1.M1pp ++ <source.P1pp> -> combined.M1pp -## 2. m1pp — combined.M1pp -> expanded.M1 (macros -> raw hex + labels) -## 3. M1 — expanded.M1 -> prog.hex2 (stringify literals, pass hex through) -## 4. cat — vendor/seed/<arch>/ELF.hex2 ++ prog.hex2 -> linked.hex2 -## 5. hex2 — linked.hex2 -> raw ELF -## 6. trim p_filesz, chmod 0700 -## -## Uses the native-compiled m1pp + mescc-tools M1/hex2 (host binaries built -## by scripts/build-native-tools.sh). The host-compiled m1pp has 64K-token / -## 512K-text buffers, versus ~4K / 32K in the aarch64 self-hosted m1pp.P1; -## the combined backend + frontend + source easily overflows the latter. -## -## Usage: scripts/build-p1pp.sh <arch> <source.P1pp> <output_binary> - -set -eu - -if [ "$#" -ne 3 ]; then - echo "usage: $0 <arch> <source.P1pp> <output>" >&2 - exit 2 -fi - -ARCH=$1 -SRC=$2 -OUT=$3 - -REPO=$(cd "$(dirname "$0")/.." && pwd) -cd "$REPO" - -case "$ARCH" in - aarch64|amd64|riscv64) ;; - *) echo "build-p1pp.sh: unsupported arch '$ARCH'" >&2; exit 1 ;; -esac - -ELF_HDR=vendor/seed/$ARCH/ELF.hex2 -BASE_ADDR=0x600000 -FRONTEND=P1/P1.M1pp -BACKEND=P1/P1-$ARCH.M1pp - -for f in "$BACKEND" "$FRONTEND" "$ELF_HDR" "$SRC"; do - [ -e "$f" ] || { echo "build-p1pp.sh: missing input: $f" >&2; exit 1; } -done - -NATIVE_M1PP=build/native-tools/m1pp -NATIVE_M1=build/native-tools/M1 -NATIVE_HEX2=build/native-tools/hex2 -if [ ! -x "$NATIVE_M1PP" ] || [ ! -x "$NATIVE_M1" ] || [ ! -x "$NATIVE_HEX2" ]; then - sh scripts/build-native-tools.sh -fi - -NAME=$(basename "$SRC" .P1pp) -WORK=build/p1pp/$ARCH/$NAME.work -mkdir -p "$WORK" "$(dirname "$OUT")" - -COMBINED=$WORK/combined.M1pp -EXPANDED=$WORK/expanded.M1 -PROG_HEX2=$WORK/prog.hex2 -LINKED=$WORK/linked.hex2 -RAW=$WORK/prog.raw - -cat "$BACKEND" "$FRONTEND" "$SRC" > "$COMBINED" - -"$NATIVE_M1PP" "$COMBINED" "$EXPANDED" - -"$NATIVE_M1" --architecture "$ARCH" --little-endian \ - -f "$EXPANDED" -o "$PROG_HEX2" - -cat "$ELF_HDR" "$PROG_HEX2" > "$LINKED" - -"$NATIVE_HEX2" --architecture "$ARCH" --little-endian \ - --base-address "$BASE_ADDR" \ - -f "$LINKED" -o "$RAW" - -size=$(od -An -tu4 -N4 -j96 "$RAW" | tr -d ' ') -head -c "$size" "$RAW" > "$OUT" -chmod 0700 "$OUT" diff --git a/scripts/prune-p1-table.sh b/scripts/prune-p1-table.sh @@ -0,0 +1,29 @@ +#!/bin/sh +## prune-p1-table.sh — emit a pruned P1 backend table. +## +## One-time host-side helper. Reads the full per-arch P1 DEFINE table +## generated by P1/gen/p1_gen.py (~7,300 DEFINEs) and keeps only the +## DEFINEs whose names appear as whitespace-separated tokens in the given +## source files. Result is checked in as P1/P1-<arch>.M1 so routine +## builds skip the prune step. +## +## The match is conservative: any token that lexically equals a DEFINE +## name keeps that DEFINE. False positives (extra DEFINEs) are harmless; +## only false negatives would cause a SIGILL binary, and the lexical +## match cannot produce them. +## +## Usage: prune-p1-table.sh <full-table.M1> <output> <src...> + +set -eu + +[ "$#" -ge 3 ] || { echo "usage: $0 <full-table.M1> <output> <src...>" >&2; exit 2; } + +FULL=$1 +OUT=$2 +shift 2 + +cat "$@" | awk ' + NR==FNR { for (i = 1; i <= NF; i++) used[$i] = 1; next } + /^DEFINE / { if ($2 in used) print; next } + { print } +' - "$FULL" > "$OUT" diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh @@ -62,6 +62,7 @@ platform_of() { run_in_container() { arch=$1; shift podman run --rm --pull=never --platform "$(platform_of "$arch")" \ + --tmpfs /tmp:size=512M \ -v "$REPO":/work -w /work \ "boot2-busybox:$arch" "$@" } @@ -94,21 +95,11 @@ show_diff() { } ## --- m1pp suite --------------------------------------------------------- - -m1pp_build_expander() { - arch=$1 - bin=build/$arch/m1pp - src=M1pp/M1pp.P1 - defs=build/p1/$arch/p1_$arch.M1 - if [ -x "$bin" ] && [ "$bin" -nt "$src" ] && [ "$bin" -nt "$defs" ]; then - return 0 - fi - sh scripts/build-p1.sh "$arch" "$src" "$bin" >/dev/null 2>&1 || { - echo "FATAL: failed to build m1pp expander for $arch" >&2 - sh scripts/build-p1.sh "$arch" "$src" "$bin" 2>&1 | sed 's/^/ /' >&2 - exit 1 - } -} +## +## Caller (Make) ensures build/<arch>/m1pp expanders, build/<arch>/tools/M0, +## the per-arch image, and P1/P1-<arch>.M1 tables exist before this runs. +## .M1 fixtures are still built per-fixture inline via boot-build-p1.sh +## (per-fixture build is test work, not infrastructure). run_m1pp_suite() { if [ -z "$ARCH" ]; then @@ -135,7 +126,6 @@ run_m1pp_suite() { for arch in $ARCHES; do label="[$arch] $name" if [ -e "$m1pp_src" ]; then - m1pp_build_expander "$arch" outfile=build/$arch/m1pp-out/$name mkdir -p "$(dirname "$outfile")" rm -f "$outfile" @@ -144,9 +134,19 @@ run_m1pp_suite() { actual=$([ -e "$outfile" ] && cat "$outfile" || echo "") elif [ -e "$m1_src" ]; then bin=build/$arch/m1pp-tests/$name - if ! sh scripts/build-p1.sh "$arch" "$m1_src" "$bin" >/dev/null 2>&1; then + table=P1/P1-$arch.M1 + elf=vendor/seed/$arch/ELF.hex2 + work=build/$arch/.work/m1pp-tests/$name + tools=build/$arch/tools + if ! sh scripts/lint.sh "$table" "$m1_src" >/dev/null 2>&1 \ + || ! run_in_container "$arch" sh scripts/boot-build-p1.sh \ + "$table" "$m1_src" "$elf" "$work" "$tools" "$bin" \ + >/dev/null 2>&1; then report "$label" FAIL - sh scripts/build-p1.sh "$arch" "$m1_src" "$bin" 2>&1 | sed 's/^/ /' + sh scripts/lint.sh "$table" "$m1_src" 2>&1 | sed 's/^/ /' >&2 || true + run_in_container "$arch" sh scripts/boot-build-p1.sh \ + "$table" "$m1_src" "$elf" "$work" "$tools" "$bin" \ + 2>&1 | sed 's/^/ /' >&2 || true continue fi actual=$(run_in_container "$arch" "./$bin" 2>&1 || true) @@ -190,9 +190,19 @@ run_p1_suite() { for arch in $ARCHES; do label="[$arch] $name" bin=build/$arch/p1-tests/$name - if ! sh scripts/build-p1pp.sh "$arch" "$fixture" "$bin" >/dev/null 2>&1; then + backend=P1/P1-$arch.M1pp + frontend=P1/P1.M1pp + elf=vendor/seed/$arch/ELF.hex2 + work=build/$arch/.work/p1-tests/$name + m1pp_bin=build/$arch/m1pp + tools=build/$arch/tools + if ! run_in_container "$arch" sh scripts/boot-build-p1pp.sh \ + "$backend" "$frontend" "$fixture" "$elf" "$work" "$m1pp_bin" "$tools" "$bin" \ + >/dev/null 2>&1; then report "$label" FAIL - sh scripts/build-p1pp.sh "$arch" "$fixture" "$bin" 2>&1 | sed 's/^/ /' + run_in_container "$arch" sh scripts/boot-build-p1pp.sh \ + "$backend" "$frontend" "$fixture" "$elf" "$work" "$m1pp_bin" "$tools" "$bin" \ + 2>&1 | sed 's/^/ /' >&2 || true continue fi actual=$(run_in_container "$arch" "./$bin" 2>&1 || true)