krc.kr (3.4 MB) natively on a Redmi Note 8 Pro Cortex-A76 (vs 2.76 s on Android)
krc compiled inside ApexRift matches host FNV-1a (80c027220de82184)
It Self-Hosts — Measured on Real Silicon
ApexRift compiles the KernRift compiler (krc.kr, 3.4 MB) inside ApexRift, and the result is byte-identical to the host build. Two matching checksums are the whole claim: the compiler that ran and the compiler it produced are the same program.
apex > krc --arch=x86_64 --target=none --emit=arx /in.kr -o /out.arx 328971 tokens, 206242 nodes, 1157184 bytes -> /out.arx (5490.00 ms) apex > sum /bin/krc sum: 80c027220de82184 1161280 bytes /bin/krc apex > sum /out.arx sum: 80c027220de82184 1161280 bytes /out.arx
Self-compile on physical hardware (Redmi Note 8 Pro vs Android)
| Machine & OS | Core / Clock | Single-target arm64 ELF |
|---|---|---|
| Desktop (x86_64, Linux) | Ryzen 9 7900X | 0.55 s |
| Begonia — ApexRift | Cortex-A55 @ 1175 MHz | 8.98 s |
Begonia — ApexRift (cpufreq 1701) | Cortex-A55 @ 1701 MHz (rated) | 6.32 s |
Begonia — ApexRift (runon 600) | Cortex-A76 @ 1085 MHz (bootloader) | 4.57 s |
Begonia — ApexRift (runon 600 + cpufreq 2000 big) | Cortex-A76 @ 2000 MHz (vendor top 2050) | 2.82 s |
| Begonia — Android | scheduler's choice | 2.76 s |
Timed off the handset's 13 MHz hardware architectural counter (cntfrq_el0), reproduced within 6 ms across runs (docs/BENCHMARKS.md). On x86_64, ./run.sh provisions /bin/krc, /bin/kr, and a staged /bin/kernel.img on the virtio disk (supporting live kexec /bin/kernel.img go hot-swaps where the GOP framebuffer survives the swap).
Where It Runs
The artifact is a self-booting image that firmware, a phone bootloader, or qemu -kernel enters directly.
| Target | How It Boots | Proven By |
|---|---|---|
| x86_64 / QEMU | qemu-system-x86_64 -kernel apexrift.img (Multiboot), or --emit=uefi → BOOTX64.EFI under OVMF |
./test.sh |
| x86_64 / Real UEFI PCs | USB stick written by tools/make-usb.sh, Secure Boot off, GOP framebuffer + +diag on-screen trace |
ASUS ROG Strix G18 (G815LW) laptop |
| arm64 / QEMU virt | -kernel entered at EL1, GICv3, FDT parser, stage-1 MMU |
./test-arm64.sh |
| arm64 / Redmi Note 8 Pro (“begonia”) | Repacked Android boot image flashed with fastboot (MediaTek MT6785) |
Real handset: display, touch, UFS, USB, 5 GHz WiFi, Bluetooth 5.0, PMIC/DVFS |
Verified before silicon: Morgana_VM. Morgana_VM (morgana-x86 and morgana-a64, ~24k LOC of KernRift) boots ApexRift's full UEFI path pixel-identical to OVMF and matches QEMU transcripts byte for byte. It halts and names any unknown instruction or unmodelled device access, models the physical laptop (--machine=g815) and handset (--machine=begonia) from measured boot reports, and runs a Stage-0 --preflight check on the phone itself as an ApexRift ARX before a kernel is allowed to kexec.
Phone boot images are never distributed. A begonia boot image carries the vendor's NT36672A touch firmware and stock Android boot headers, neither of which is ours to give away. To run ApexRift on a begonia you build the image yourself from files pulled off your own handset via tools/build-begonia-boot.sh.
Proof on Real Silicon
Unedited photographs of ApexRift running bare-metal on a physical Redmi Note 8 Pro (MediaTek MT6785) — 1080×2340 panel, NT36672A touch, on-screen QWERTY & symbol keyboard, EL1, and live MT6359 PMIC telemetry.
uname, version & temp on begonia (boot seq 700, EL1): live eFuse-trimmed PMIC die and buck temperatures (42.1–43.2 °C, 0 timeouts) with the custom touch QWERTY keyboard.
vproc live voltage & PLL readout: big cluster (A76 pair, 800 mV @ 1085 MHz), little cluster (6× A55, 800 mV @ 1175 MHz), CCI interconnect (612 MHz), 0 PMIC timeouts, and the ?123 symbol keyboard layer.Verified Against Independent Oracles
Nothing in ApexRift is judged only by code written in the same tree. Every major subsystem is measured against an external reference implementation.
| Subsystem | Independent Oracle | Measured Result |
|---|---|---|
On-device self-host (krc.kr, 3.4 MB) |
Android on the same Redmi Note 8 Pro | 2.82 s vs 2.76 s (Cortex-A76 @ 2000 MHz, cntfrq_el0) |
Custom DEFLATE (std/gzip.kr) |
zlib -9 & system gzip -t |
4.5% smaller (1,616,196 B vs 1,691,927 B), round-trip verified |
RiftCrypto & TLS 1.3 (crypto/) |
openssl s_server & live kernrift.org / curl |
Byte-identical HTTPS body checksum, real P-256/P-384 X.509 chains |
Morgana_VM (morgana-x86 / a64) |
QEMU & OVMF UEFI firmware | Byte-identical serial transcripts, pixel-identical UEFI GOP frame |
Lessons paid for on silicon
- EL2 without VHE silently ignores EL1 MMU writes: Writing EL1 translation registers from EL2 without VHE configures nothing at all — a week of a handset that looked like it was running before dropping EL2→EL1 at entry.
- LK's display overlay hides pixels without alpha
0xFF: Correct physical framebuffer address, correct stride, landed stores — completely invisible panel until the alpha channel was forced opaque. - A microsecond
termioswindow makes CDC-ACM lie: Opening/dev/apexriftand callingstty raw -echoin a second process leaves ECHO live long enough to bounce the first 12 banner bytes back into the phone's bulk OUT endpoint — which is whykr-consoleopens and runsioctl(TCSETS)in one static KernRift process. - Hardware counters that report zero off-charger: Measuring across a real unplug proved the MT6360's
IBATchannel reads0 mAduring discharge while the pack is under load — sobatprints uncounted off-charger seconds rather than fabricating a percentage.
System Layers
Backends are chosen at import time, never dispatched through nullable function pointers at runtime — a missing hardware backend is a link error before silicon is ever touched.
What Works Today
Boot, kexec & Watchdog
Multiboot and full UEFI (GOP framebuffer, memory map past 4 GiB, ExitBootServices onto own page tables). Live kexec hot-swap preserves the framebuffer across kernels; kstage verifies FNV-1a + length of disk bytes and arms hardware watchdog fallback (6300ESB / SoC WDT).
Hardware Isolation & W^X
Unprivileged execution at Ring 3 (iretq, int 0x80 & SYSCALL/SYSRET, SMEP, NX) and EL0 (EL2→EL1 drop, eret, svc #0, 4 KiB page splitting). Per-segment W^X, isolated user arena, fault containment, and runaway-loop watchdog preemption on both architectures.
ArFS Storage & AES-XTS
Block-structured filesystem: 4 KiB blocks, bitmap allocator, direct + single/double-indirect inodes up to 4 GiB per file. One dispatcher drives RAM disk, virtio-blk, and handset UFS with fault injection. Includes fsck / fsck fix, opt-in redo journal, and whole-volume AES-128-XTS (x86_64, confidentiality-only).
ARX & Signed Modules
Custom executable container (7F 41 52 58) emitted by krc --emit=arx with mandatory-table validation and FNV-1a integrity. Loadable kernel modules enter via a versioned service vtable and are signature-checked before load (modsig / modkey).
Apex Sans (From-Scratch Font)
Original stroke-designed typeface (tools/fonts/apexsans.strokes) and custom ARF1 binary glyph toolchain (~6k LOC, ~410 glyphs: Latin, Latin-1, Extended-A, monotonic & polytonic Greek, symbols) at 16/24/32 px. Renders 2 bpp 4-level AA via byte-by-byte reads safe even with MMU off on Device memory; mutation-gated (font_check.kr), Apache-2.0.
Apex UI (Immediate-Mode Toolkit)
Zero-import PIC ARX GUI toolkit (std/ui.kr, Apache-2.0) running unprivileged in Ring 3 / EL0: containers, labels, buttons, text fields, scroll lists, tab focus, clipping, and Apex Sans text. Traps strictly via four wrappers (surface_info, present, event_wait, clock); mutation-gated by ui_check.kr + mutate_ui.sh.
RiftCrypto & TLS 1.3
From-zero cryptography and TLS 1.3 suite (crypto/, 27 files, ~9.4k LOC): own bignum, RSA-2048/PSS, Ed25519, ECDSA P-256/P-384, X25519, ChaCha20-Poly1305, AES, SHA-1/256/512, HKDF, 54 KB DER/X.509 parser with chain validation and curated roots, plus Ed25519-signed Roughtime — verified byte-exact against openssl s_server and kernrift.org. Runs over e1000, USB CDC-EEM, and WiFi TCP (RFC 5681, SACK).
Graphical Shell & Dual I/O
Double-buffered 1024×768x32 compositor (QEMU ramfb) with draggable windows, focus/raise, taskbar clock, ApexShell terminal, and live System Monitor, plus 80×25 VGA fallback. Output goes to screen and serial simultaneously.
5 GHz WiFi & Bluetooth 5.0
On the MT6785 handset: 5 GHz VHT80 LAN WiFi measured at 13.3 MB/s (106 Mbps) download across 100 MiB (71,912 frames, 19,230 reordered, 0 holes dropped; 13.8 MB/s host-timed) and 6.66 MB/s (53.3 Mbps) upload (0 retransmits) with full WPA2 4-way handshake, DHCP, and boot-time join. Bluetooth 5.0: MCU boot, HCI, SSP pairing, persisted link keys, L2CAP, and RFCOMM.
arsh & kr-console
arsh is a custom authenticated remote shell (X25519 + Ed25519 + ChaCha20-Poly1305) over WiFi with pinned host key and client allow-list. kr-console (tools/krconsole.kr) is a pure-KernRift raw USB CDC-ACM console replacing Python: sets raw -echo termios in-process via ioctl(TCSETS), keeps timestamped session logs, and runs an unconditional syscall-ABI witness on every build.
From-Scratch USB Stack
Descriptor tables (usb_desc.kr), Chapter 9 enumeration (usb_ch9.kr), and byte pipes (usb_cdc.kr) proven on the x86 gate before touching MediaTek's mtu3.kr controller. Exposes both a raw CDC-ACM serial console (/dev/apexrift, no ADB) and CDC-EEM Ethernet over USB.
PMIC Telemetry & DVFS
MT6359 (PWRAP) and MT6360 (I2C5) decoded live on the handset: bat (VBAT/VSYS/IBAT/IBUS + integrated charge), temp (4 PMIC sensors off eFuse trim), vproc set against MediaTek's operating-point table, cpufreq, and an opt-in DVFS governor.
8-Core SMP & Run Queue
Brings up all 8 handset cores via PSCI CPU_ON (6× Cortex-A55 + 2× Cortex-A76), runs pinned jobs on big cores (runon 600), and ships a kernel spinlock (core/spin.kr), FIFO run queue (core/sched.kr), and cross-core SHA-256 verification (smpsha).
Custom DEFLATE & Zero Python
Own LZ77 + optimal shortest-path dynamic Huffman encoder (std/gzip.kr) — 4.5% smaller than zlib -9, round-trip verified by system gzip -t. Handset boot-image repacking runs purely in KernRift, verified byte-identical to the Python it replaced.
Boot Health, Crash Records & Evidence
Cross-boot health verdicts, known-good fallback slot (good), bad-image denylist (badlst), persistent crash records across warm reboots (rec, journal), fixed-RAM overlap audit (memclaim), and non-vacuous mutation gates.
Where It Is Going
The open engineering work, stated plainly without hand-waving.
- SMP-safe kernel & preemptive scheduler: All 8 cores start and take posted jobs today, but kernel services forward to the boot core through a mailbox because console, ArFS, handle table, and arena are unlocked globals. Locking them unlocks real parallelism and preemption.
- Per-process address spaces: Separate page tables per user process so
krandarshcan execute arbitrary isolated programs rather than sharing one user arena. - TCP fast retransmit & recovery: RFC 5681 slow start, congestion avoidance, and go-back-N on timeout are done; fast retransmit / fast recovery remain open.
- Absolute battery state of charge: MT6360's IBAT channel integrates charge-in current but reads 0 mA off the charger, so discharge is not yet measured; true gauged SoC waits on reading discharge current and pack resistance.
Build, Boot & Test
Requires Linux x86_64, git, curl, make, xxd, and qemu-system-x86_64. The pinned KernRift compiler bootstraps itself until krc3 == krc4.
$ git clone https://github.com/Pantelis23/ApexRift.git && cd ApexRift $ ci/bootstrap-krc.sh # build pinned KernRift compiler into ci/.krc/ (krc3 == krc4) $ ./build.sh # compile kernel, boot 6s in QEMU, print serial log $ ./run.sh # interactive shell with krc and kr already in /bin
$ ./test.sh # x86_64 + arm64 gates against booted images $ ./tools/run-krc-in-apexrift.sh # self-host krc inside ApexRift & verify checksums $ ./tools/run-uefi-probe.sh --shot # UEFI + GOP framebuffer verification $ APEX_NO_HANDSET=1 ./hardtest.sh # flake, vacuity, stress & mutation campaigns
Engineering Records (docs/)
Over 1.4 MB of measured bring-up logs, protocol specs, and post-mortems in the repository — including the wrong turns and retracted hypotheses.
Licence
ApexRift is free software under GPL-3.0-only, with an explicit exception (LICENSE-EXCEPTION): programs using ApexRift only through its syscall or ARX service interface are not derivative works and may carry any licence their author chooses.
The app toolkit (std/ui.kr), program-side syscall shims, the Apex Sans font, and shared KernRift std/ files are Apache-2.0. Every source file carries an SPDX-License-Identifier header enforced by ./test.sh.
Bug Reports & Discussions