diff --git a/build/platform.simulator.macos.mak b/build/platform.simulator.macos.mak index dcfeac04b..927d80636 100644 --- a/build/platform.simulator.macos.mak +++ b/build/platform.simulator.macos.mak @@ -5,7 +5,9 @@ APPLE_PLATFORM = macos APPLE_PLATFORM_MIN_VERSION = 10.10 EPSILON_TELEMETRY ?= 0 -ARCHS = x86_64 +# Build universal binary for both x86_64 and ARM64 by default +# Can be overridden with ARCHS=arm64 or ARCHS=x86_64 for single architecture builds +ARCHS ?= x86_64 arm64 ifdef ARCH BUILD_DIR := $(BUILD_DIR)/$(ARCH) diff --git a/ion/src/simulator/macos/Makefile b/ion/src/simulator/macos/Makefile index cdc8015d6..724a4b8af 100644 --- a/ion/src/simulator/macos/Makefile +++ b/ion/src/simulator/macos/Makefile @@ -11,13 +11,30 @@ ion_src += $(addprefix ion/src/simulator/shared/, \ dummy/keyboard_callback.cpp \ dummy/window_callback.cpp \ clipboard_helper.cpp \ - collect_registers_x86_64.s \ collect_registers.cpp \ haptics.cpp \ journal.cpp \ store_script.cpp \ ) +# Include architecture-specific assembly files +# When building for a specific architecture (via ARCH variable) +ifdef ARCH +ifeq ($(ARCH),arm64) +ion_src += ion/src/simulator/shared/collect_registers_arm64.s +else +ion_src += ion/src/simulator/shared/collect_registers_x86_64.s +endif +else +# When building universal binary, include both +ifneq ($(filter arm64,$(ARCHS)),) +ion_src += ion/src/simulator/shared/collect_registers_arm64.s +endif +ifneq ($(filter x86_64,$(ARCHS)),) +ion_src += ion/src/simulator/shared/collect_registers_x86_64.s +endif +endif + ifeq ($(EPSILON_TELEMETRY),1) ion_src += ion/src/simulator/shared/dummy/telemetry_init.cpp ion_src += ion/src/shared/telemetry_console.cpp diff --git a/ion/src/simulator/shared/collect_registers_arm64.s b/ion/src/simulator/shared/collect_registers_arm64.s new file mode 100644 index 000000000..67b4e5b0b --- /dev/null +++ b/ion/src/simulator/shared/collect_registers_arm64.s @@ -0,0 +1,21 @@ +.text + +.global _collect_registers + +_collect_registers: + // Save callee-saved registers to the buffer pointed by x0 + // ARM64 callee-saved registers: x19-x28, x29 (fp), x30 (lr), sp + stp x19, x20, [x0, #0] + stp x21, x22, [x0, #16] + stp x23, x24, [x0, #32] + stp x25, x26, [x0, #48] + stp x27, x28, [x0, #64] + stp x29, x30, [x0, #80] + + // Save stack pointer + mov x1, sp + str x1, [x0, #96] + + // Return current stack pointer + mov x0, sp + ret \ No newline at end of file