Skip to content

darwinarm64: native Apple Silicon port — Mach kernel, W^X, AAPCS64 FFI, ObjC bridge, Cocoa IDE - #586

Closed
egao1980 wants to merge 1 commit into
Clozure:arm64from
egao1980:cursor/darwin-arm64-8969
Closed

darwinarm64: native Apple Silicon port — Mach kernel, W^X, AAPCS64 FFI, ObjC bridge, Cocoa IDE#586
egao1980 wants to merge 1 commit into
Clozure:arm64from
egao1980:cursor/darwin-arm64-8969

Conversation

@egao1980

@egao1980 egao1980 commented Aug 7, 2026

Copy link
Copy Markdown

Summary

Native Darwin/arm64 (Apple Silicon) port on top of the arm64 branch: Mach exception server, MAP_JIT-based W^X, Apple AAPCS64 FFI, ObjC bridge, and the Cocoa IDE. The stock build path works like other platforms: (rebuild-ccl :full t) self-hosts, and (require :cocoa-application) builds Clozure CL64.app.

The branch is squashed into seven commits:

  1. native kernel — Mach exception server (arm64-darwin-mach.c), MAP_JIT W^X policy (purify → AREA_READONLY RX, dynamic heap never executable), GC corrupt-header diagnostics, image/thread/syscall support, lisp-kernel/darwinarm64/ build.
  2. runtime and AAPCS64 FFI — atomic composite/HFA argument passing (AAPCS64 C.3/C.12), record returns (register and x8 indirect), Darwin variadic-on-stack, callback trampolines (index in x9 so the incoming x8 sret pointer survives), interpreted %ff-call parity, shared lib/ffi-arm64.lisp, and a fix for GC-invisible .SPffcall state (raw return PC parked on the vstack could alias an ivector header and hide older vstack slots from mark/forward; save0–save3 now spill around foreign calls).
  3. ObjC bridge and Cocoa IDE — Apple tagged pointers, no objc_msgSend*_stret on arm64, call-next-method over ObjC methods, untitled Listener at launch, Trace/Source/Inspect selection fixes.
  4. interface database tooling — scripts to regenerate darwin-arm64 .cdb databases from the current SDK with ffigen5 (databases themselves stay out of the tree).
  5. stock build path — cross xload target, rebuild-ccl integration, dumplisp MAP_JIT handling.
  6. smoke tests and CI harness — FFI/callback/Cocoa smokes, launch-layout regression reproducer, mini-app suite, tools/run-darwin-arm64-ci.sh.
  7. porting notesdoc/porting/darwin.md, doc/porting/progress.md.

Validation

  • (rebuild-ccl :full t) twice (second rebuild self-hosted from the produced image)
  • ccl-tests suite 244/244; ANSI+CCL test-ccl-and-suites 21920/21920
  • Full smoke gate (tools/run-darwin-arm64-ci.sh): purify, cocoa, interp-ff-call, clean build, (require :cocoa)/Hemlock, mini-apps 01–17
  • FFI/callback smokes: struct return, variadic, pack overflow, ffcall stack, callback sret/struct/HFA, NSRange, HFA args
  • Stock-built IDE opens its untitled Listener, evaluates, and stays healthy with no init files present

Relation to the current arm64 branch

This branch is based on an earlier arm64 state. Since then the branch gained the linuxarm64 AAPCS64 FFI rework (#572) and the consolidation of the split spentry-[B-E]*.s files into arm64-spentry.s, which overlap the FFI/spentry commits here (13 conflicting files). The two implementations agree on the ABI but differ in mechanism (ffcall/callback convention, file layout), so reconciling onto the current tip is a follow-up step — happy to coordinate on which convention should win before rebasing.

GitHub does not allow reopening this PR (the head branch was recreated after it was closed); superseded by #599, which is rebased onto the current arm64 tip with the overlap reconciled.

Apple Silicon bring-up on the arm64 branch (Linux/arm64 already boots).

- lisp-kernel/darwinarm64/Makefile builds darm64cl (ASLR; no pagezero)
- Expand platform-darwinarm64.h; stub Mach TCR hooks (Unix signals for now)
- Darwin syscall path (x16 + svc #0x80, carry → -errno)
- Assembler: bcond_ext + ADRP for lisp_nil (Darwin as/ld constraints)
- darwin_sigreturn; tools/xdarwinarm64.lisp

Verified: make -C lisp-kernel/darwinarm64 produces a Mach-O arm64
binary that runs and looks for darm64cl.image.
@egao1980 egao1980 closed this Aug 7, 2026
@egao1980

egao1980 commented Aug 7, 2026

Copy link
Copy Markdown
Author

Note: this was opened from an automated agent without the fork owner's explicit request to send upstream. Closing/keeping closed is correct; further Darwin/arm64 work stays on https://github.com/egao1980/ccl/tree/cursor/darwin-arm64-8969 until/unless an upstream PR is requested.

@xrme

xrme commented Aug 7, 2026

Copy link
Copy Markdown
Member

I have a darwinarm64 lisp kernel build Makefile and directory. You can keep working on your own if you want, but as soon as I can get the chance, I'll check in what I've been working on.

@egao1980

egao1980 commented Aug 9, 2026

Copy link
Copy Markdown
Author

UDF hunt (b4f7a9f): Historical udf #0 at 0x306… was NX→HEAP_EXEC_BIAS into a zeroed RX alias while calling heap ARM64-LAP-GENERATE-CODE (not MAP_JIT). Fix: heap tip-LAP install then MAP_JIT faslop; remap probe now requires first-word match before skip. Verified wiped (compile-ccl t) ~23s, no UDF.

@egao1980

egao1980 commented Aug 9, 2026

Copy link
Copy Markdown
Author

:full rebuild-ccl fixed (f9c85b92):

  • Dropped RX alias region-probe skip (stale bias zeros → udf #0)
  • Host MAP_JIT faslop after heap tip-LAP
  • Cold-load/purify reload via tools/save-darwinarm64-image.lisp + retries

Verified end-to-end: (rebuild-ccl :full t) → cross-xload → DM1 purify → Wrote heap image → DM0 kernel. First cold-load attempt succeeded.

egao1980 added a commit to egao1980/ccl that referenced this pull request Aug 9, 2026
@egao1980 egao1980 changed the title darwinarm64: scaffold native Apple Silicon kernel (darm64cl) darwinarm64: native Apple Silicon port — Mach kernel, W^X, AAPCS64 FFI, ObjC bridge, Cocoa IDE Aug 13, 2026
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