Skip to content

AArch64-only iSH: asbestos guest gadgets, kernel consolidation - #1

Draft
CodeJoule wants to merge 8 commits into
masterfrom
cursor/aarch64-guest-backend-c0e6
Draft

AArch64-only iSH: asbestos guest gadgets, kernel consolidation#1
CodeJoule wants to merge 8 commits into
masterfrom
cursor/aarch64-guest-backend-c0e6

Conversation

@CodeJoule

@CodeJoule CodeJoule commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Enables building iSH on Apple Silicon with an AArch64 Linux guest (default guest_arch=aarch64).

Critical fixes (post-review)

  • fiber_interrupt: was reading interrupt code from w20 (_cpu) instead of w23 (gadget result) — broke Mac/asm interrupt path
  • CBZ/CBNZ: W-form used uxth (16-bit) instead of uxtw; take-branch condition corrected
  • Syscall table: rebuilt from Linux asm-generic/unistd.h NRs (previous table had many wrong slots: unlinkat/ppoll/nanosleep/prctl/socket/accept4/eventfd2/…)
  • segfault_was_write: no longer cleared by helper on faults
  • Signal SP: AArch64 frames now 16-byte aligned (was using i386 sp+4 trick)
  • VDSO sigreturn: alias uses rt_sigreturn (NR 139)

Guest execution (asbestos)

  • entry.S gret tail-call fiber model
  • control.S asm gadgets for branches, SVC, mov_wide, etc.
  • memory.S / math.S / misc.S insn gadgets → helper_a64_run_insn_word
  • Meson: asm gadgets on aarch64 host (Mac), C gadgets on x86_64 (CI)

Kernel

  • exec-aarch64.c: ELF64 + PT_INTERP
  • Expanded AArch64 syscall coverage with correct numbers

App / docs

  • ISH_GUEST_ARCH = aarch64 in app/iSH.xcconfig
  • README documents Alpine aarch64 fakefs (bundled App Store rootfs is still i386)

Mac usage

  1. Build in Xcode
  2. Prepare aarch64 rootfs:
    curl -fL -o alpine-aarch64.tar.gz \
      https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/aarch64/alpine-minirootfs-3.21.7-aarch64.tar.gz
    ./build/tools/fakefsify alpine-aarch64.tar.gz alpine-aarch64
  3. Import or run ./build/ish -f alpine-aarch64 /bin/sh

Remaining gaps

  • FP/SIMD and many ISA classes still missing in aarch64-exec.c (needed for full musl)
  • Bundled ROOTFS_URL still i386 — must fakefsify Alpine aarch64 manually
  • No e2e Alpine /bin/sh CI test yet
  • Asbestos not fully 1:1 with x86 (many gadgets still C-backed)
Open in Web Open in Cursor 

cursoragent and others added 2 commits July 6, 2026 22:52
Introduce a compile-time guest_arch meson option (i386 or aarch64) so iSH
can emulate AArch64 Linux userspace alongside the existing i386 backend.

The AArch64 engine uses a C interpreter for guest instructions, AArch64
Linux syscall dispatch, ELF64 loading, signal frames, and an aarch64 VDSO.
The default i386 asbestos gadget path is unchanged.

Includes an aarch64 hello-world test and README build instructions.

Co-authored-by: CodeJoule <CodeJoule@users.noreply.github.com>
Replace the standalone C interpreter loop with the real asbestos engine:
gen-aarch64 compiles guest basic blocks into gadget streams, fiber_enter
dispatches guest AArch64 gadgets, and asbestos.c handles block caching
and invalidation using guest pc instead of eip.

- Add emu/aarch64-exec.c for per-instruction semantics used by gadgets
- Add asbestos/gen-aarch64.c and gadgets-guest-aarch64/entry.c
- Remove aarch64-interp.c, aarch64-engine.c, and no-op asbestos stubs
- Default guest_arch to aarch64; keep i386 behind -Dguest_arch=i386

Co-authored-by: CodeJoule <CodeJoule@users.noreply.github.com>
@cursor cursor Bot changed the title Add AArch64 guest backend with dual-arch build support AArch64 guest backend: asbestos execution, aarch64 default Jul 6, 2026
@cursor cursor Bot changed the title AArch64 guest backend: asbestos execution, aarch64 default AArch64-only iSH: asbestos guest gadgets, kernel consolidation Jul 6, 2026
cursoragent and others added 6 commits July 6, 2026 23:49
- Rewrite gen-aarch64.c to emit per-instruction-type guest gadgets
- Add gadgets-guest-aarch64: C gadgets (all hosts), asm hot gadgets + fiber_enter (aarch64 host)
- Add offsets-aarch64.c, helpers-aarch64.c, logical immediate decode
- Merge AArch64 syscall dispatch into kernel/calls.c; remove calls-aarch64.c
- Default ISH_GUEST_ARCH=aarch64 in Xcode and xcode-meson.sh
- Add exit42 assembler test for mov/svc gadget coverage

Co-authored-by: CodeJoule <CodeJoule@users.noreply.github.com>
- Fix gadgets-guest-aarch64 assembly to assemble on Apple Darwin:
  runtime read_xn/write_xn macros, variable shifts, insn_gadget branches
- Split C vs asm gadget sources by host arch in meson (no duplicate symbols)
- Add PT_INTERP dynamic linker loading in exec-aarch64.c
- Expand AArch64 syscall table and wire accept4 to sys_accept
- Add memory/math/misc insn gadgets and gen-aarch64 emissions
- Document Alpine aarch64 rootfs setup; default guest_arch to aarch64

Co-authored-by: CodeJoule <CodeJoule@users.noreply.github.com>
Co-authored-by: CodeJoule <CodeJoule@users.noreply.github.com>
- fiber_interrupt: read interrupt code from w23 (gadget result), not w20 (_cpu)
- CBZ/CBNZ: use uxtw for W-form and correct take-branch condition
- Preserve segfault_was_write across helper_a64_run_insn_word
- Rebuild aarch64 syscall table from Linux asm-generic NRs
  (unlinkat/ppoll/nanosleep/prctl/socket/accept4/eventfd2/etc.)
- Align AArch64 signal frames to 16-byte SP ABI
- Point vdso __kernel_sigreturn at rt_sigreturn (NR 139)

Co-authored-by: CodeJoule <CodeJoule@users.noreply.github.com>
Co-authored-by: CodeJoule <CodeJoule@users.noreply.github.com>
Co-authored-by: CodeJoule <CodeJoule@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants