diff --git a/mps/code/.p4ignore b/mps/code/.p4ignore index 70e69009357..682821ffd84 100644 --- a/mps/code/.p4ignore +++ b/mps/code/.p4ignore @@ -13,6 +13,7 @@ lii6gc lii6ll w3i3mv w3i6mv +xca6ll xci3gc xci3ll xci6gc diff --git a/mps/code/config.h b/mps/code/config.h index 50bd9d7ed70..aa9b70c7cce 100644 --- a/mps/code/config.h +++ b/mps/code/config.h @@ -576,7 +576,13 @@ things like thread states. These definitions fix that. */ #if defined(MPS_OS_XC) -#if defined(MPS_ARCH_I6) +#if defined(MPS_ARCH_A6) + +#define THREAD_STATE_COUNT ARM_THREAD_STATE64_COUNT +#define THREAD_STATE_FLAVOR ARM_THREAD_STATE64 +#define THREAD_STATE_S arm_thread_state64_t + +#elif defined(MPS_ARCH_I6) #define THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT #define THREAD_STATE_FLAVOR x86_THREAD_STATE64 diff --git a/mps/code/eventpy.c b/mps/code/eventpy.c index c6d9f5952ed..c8990ddc5bf 100644 --- a/mps/code/eventpy.c +++ b/mps/code/eventpy.c @@ -15,7 +15,7 @@ #include "event.h" /* See */ -#if defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6) +#if defined(MPS_ARCH_A6) || defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6) #define BYTE_ORDER "<" #else #error "Can't determine byte order for platform architecture." diff --git a/mps/code/mps.c b/mps/code/mps.c index 10cb47094a1..3fbfc579f7e 100644 --- a/mps/code/mps.c +++ b/mps/code/mps.c @@ -110,6 +110,20 @@ #include "prmcanan.c" /* generic architecture mutator context */ #include "span.c" /* generic stack probe */ +/* macOS on ARM64 built with Clang */ + +#elif defined(MPS_PF_XCA6LL) + +#include "lockix.c" /* Posix locks */ +#include "thxc.c" /* macOS Mach threading */ +#include "vmix.c" /* Posix virtual memory */ +#include "protix.c" /* Posix protection */ +#include "protxc.c" /* macOS Mach exception handling */ +#include "prmcanan.c" /* generic architecture mutator context */ +#include "prmcxc.c" /* macOS mutator context */ +#include "prmcxca6.c" /* ARM64 for macOS mutator context */ +#include "span.c" /* generic stack probe */ + /* macOS on IA-32 built with Clang or GCC */ #elif defined(MPS_PF_XCI3LL) || defined(MPS_PF_XCI3GC) diff --git a/mps/code/mpstd.h b/mps/code/mpstd.h index d3beaed6b06..df56d29f2a6 100644 --- a/mps/code/mpstd.h +++ b/mps/code/mpstd.h @@ -165,6 +165,25 @@ #define MPS_PF_ALIGN 8 +/* Apple clang version 12.0, clang -E -dM */ + +#elif defined(__APPLE__) && defined(__arm64__) && defined(__MACH__) \ + && defined(__clang__) +#if defined(CONFIG_PF_STRING) && ! defined(CONFIG_PF_XCA6LL) +#error "specified CONFIG_PF_... inconsistent with detected xca6ll" +#endif +#define MPS_PF_XCA6LL +#define MPS_PF_STRING "xca6ll" +#define MPS_OS_XC +#define MPS_ARCH_A6 +#define MPS_BUILD_LL +#define MPS_T_WORD unsigned long +#define MPS_T_ULONGEST unsigned long +#define MPS_WORD_WIDTH 64 +#define MPS_WORD_SHIFT 6 +#define MPS_PF_ALIGN 8 + + /* Apple clang version 3.1, clang -E -dM */ #elif defined(__APPLE__) && defined(__i386__) && defined(__MACH__) \ diff --git a/mps/code/prmcxc.h b/mps/code/prmcxc.h index 9af1e601e98..be2b6d0a974 100644 --- a/mps/code/prmcxc.h +++ b/mps/code/prmcxc.h @@ -12,7 +12,13 @@ #include "mpm.h" #include +#if defined(MPS_ARCH_A6) +#include +#elif defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6) #include +#else +#error "Unknown macOS architecture" +#endif typedef struct MutatorContextStruct { Sig sig; /* */ diff --git a/mps/code/prmcxca6.c b/mps/code/prmcxca6.c new file mode 100644 index 00000000000..ce1de415a32 --- /dev/null +++ b/mps/code/prmcxca6.c @@ -0,0 +1,57 @@ +/* prmcxca6.c: MUTATOR CONTEXT ARM64 (macOS) + * + * $Id$ + * Copyright (c) 2001-2021 Ravenbrook Limited. See end of file for license. + * + * .purpose: Implement the mutator context module. . + * + * + * ASSUMPTIONS + * + * .sp: The stack pointer in the context is SP. + */ + +#include "prmcxc.h" + +SRCID(prmcxca6, "$Id$"); + +#if !defined(MPS_OS_XC) || !defined(MPS_ARCH_A6) +#error "prmcxca6.c is specific to MPS_OS_XC and MPS_ARCH_A6" +#endif + + +Addr MutatorContextSP(MutatorContext context) +{ + AVERT(MutatorContext, context); + return (Addr)arm_thread_state64_get_sp(*(context->threadState)); /* .sp */ +} + + +/* C. COPYRIGHT AND LICENSE + * + * Copyright (C) 2001-2021 Ravenbrook Limited . + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff --git a/mps/code/protxc.c b/mps/code/protxc.c index 346fe6074f5..172908b5cd6 100644 --- a/mps/code/protxc.c +++ b/mps/code/protxc.c @@ -70,7 +70,6 @@ #include #include #include -#include #include #include #include /* see .trans.stdlib */ diff --git a/mps/code/testlib.h b/mps/code/testlib.h index d595cac5705..f140b0a9e1b 100644 --- a/mps/code/testlib.h +++ b/mps/code/testlib.h @@ -104,7 +104,7 @@ * tests to root out any incompatible assumptions by breaking. */ -#if defined(MPS_ARCH_I6) +#if defined(MPS_ARCH_A6) || defined(MPS_ARCH_I6) #define PRIwWORD "16" #elif defined(MPS_ARCH_I3) #define PRIwWORD "8" diff --git a/mps/code/xca6ll.gmk b/mps/code/xca6ll.gmk new file mode 100644 index 00000000000..c4834070759 --- /dev/null +++ b/mps/code/xca6ll.gmk @@ -0,0 +1,58 @@ +# -*- makefile -*- +# +# xca6ll.gmk: BUILD FOR macOS/ARM64/Clang/LLVM PLATFORM +# +# $Id$ +# Copyright (c) 2001-2021 Ravenbrook Limited. See end of file for license. +# +# .prefer.xcode: The documented and preferred way to develop the MPS +# for this platform is to use the Xcode project (mps.xcodeproj). This +# makefile provides a way to compile the MPS one source file at a +# time, rather than all at once via mps.c (which can hide errors due +# to missing headers). + +PFM = xca6ll + +MPMPF = \ + lockix.c \ + prmcanan.c \ + prmcxc.c \ + prmcxca6.c \ + protix.c \ + protxc.c \ + span.c \ + thxc.c \ + vmix.c + +include ll.gmk +include comm.gmk + + +# C. COPYRIGHT AND LICENSE +# +# Copyright (C) 2001-2021 Ravenbrook Limited . +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/mps/configure b/mps/configure index 912b78e46b3..cb018412424 100755 --- a/mps/configure +++ b/mps/configure @@ -3478,6 +3478,18 @@ $as_echo "Linux x86_64" >&6; } MPS_BUILD_NAME=ll PFMCFLAGS="$CFLAGS_LL" ;; + aarch64-*-darwin*/*) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: Mac OS X ARM64" >&5 +$as_echo "Mac OS X ARM64" >&6; } + MPS_OS_NAME=xc + MPS_ARCH_NAME=a6 + MPS_BUILD_NAME=ll + BUILD_TARGET=build-via-xcode + CLEAN_TARGET=clean-xcode-build + INSTALL_TARGET=install-xcode-build + TEST_TARGET=test-xcode-build + PFMCFLAGS="$CFLAGS_LL" + ;; i*86-*-darwin*/*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: Mac OS X x86" >&5 $as_echo "Mac OS X x86" >&6; } diff --git a/mps/configure.ac b/mps/configure.ac index c57fd0bf566..acf935b640e 100644 --- a/mps/configure.ac +++ b/mps/configure.ac @@ -66,6 +66,17 @@ case $host/$CLANG in MPS_BUILD_NAME=ll PFMCFLAGS="$CFLAGS_LL" ;; + aarch64-*-darwin*/*) + AC_MSG_RESULT([Mac OS X ARM64]) + MPS_OS_NAME=xc + MPS_ARCH_NAME=a6 + MPS_BUILD_NAME=ll + BUILD_TARGET=build-via-xcode + CLEAN_TARGET=clean-xcode-build + INSTALL_TARGET=install-xcode-build + TEST_TARGET=test-xcode-build + PFMCFLAGS="$CFLAGS_LL" + ;; i*86-*-darwin*/*) AC_MSG_RESULT([Mac OS X x86]) MPS_OS_NAME=xc diff --git a/mps/design/prmc.txt b/mps/design/prmc.txt index eb427b39f49..fb141f23a8c 100644 --- a/mps/design/prmc.txt +++ b/mps/design/prmc.txt @@ -268,13 +268,14 @@ macOS implementation _`.impl.xc`: In ``prmcix.c`` and ``prmcxc.c``, with processor-specific parts in ``prmci3.c`` and ``prmci6.c``, and other platform-specific -parts in ``prmcxci3.c`` and ``prmcxci6.c``. +parts in ``prmcxca6.c``, ``prmcxci3.c`` and ``prmcxci6.c``. _`.impl.xc.context`: The context consists of the ``__Request__mach_exception_raise_state_identity_t`` and -``x86_thread_state32_t`` or ``x86_thread_state64_t`` structures. There -doesn't seem to be any documentation for these structures, but they -are defined in the Mach headers. +``arm_thread_state_t``, ``x86_thread_state32_t`` or +``x86_thread_state64_t`` structures. There doesn't seem to be any +documentation for these structures, but they are defined in the Mach +headers. _`.impl.xc.fault.addr`: ``__Request__mach_exception_raise_state_identity_t.code[1]`` is the address that the faulting instruction was trying to access. @@ -292,9 +293,11 @@ calling |thread_get_state|_. .. _thread_get_state: https://www.gnu.org/software/hurd/gnumach-doc/Thread-Execution.html _`.impl.xc.context.scan`: The thread's registers are found in the -``x86_thread_state32_t`` or ``x86_thread_state64_t`` structure. +``arm_thread_state64_t``, ``x86_thread_state32_t`` or +``x86_thread_state64_t`` structure. -_`.impl.xc.context.sp`: The stack pointer is obtained from +_`.impl.xc.context.sp`: The stack pointer is obtained using the +``arm_thread_state64_get_sp()`` macro (on ARM64), or from ``x86_thread_state32_t.__esp`` (on IA-32) or ``x86_thread_state64_t.__rsp`` (on x86-64). diff --git a/mps/manual/build.txt b/mps/manual/build.txt index 0e4828abbf5..8a5e55c1795 100644 --- a/mps/manual/build.txt +++ b/mps/manual/build.txt @@ -144,6 +144,7 @@ Platform OS Architecture Compiler Makefile ``lii6ll`` Linux x86-64 Clang ``lii6ll.gmk`` ``w3i3mv`` Windows IA-32 Microsoft C ``w3i3mv.nmk`` ``w3i6mv`` Windows x86-64 Microsoft C ``w3i6mv.nmk`` +``xca6ll`` macOS ARM64 Clang ``mps.xcodeproj`` ``xci3ll`` macOS IA-32 Clang ``mps.xcodeproj`` ``xci6ll`` macOS x86-64 Clang ``mps.xcodeproj`` ========== ========= ============= ============ ================= diff --git a/mps/manual/source/code-index.rst b/mps/manual/source/code-index.rst index 0f172a8dd5c..f30ac3a1e59 100644 --- a/mps/manual/source/code-index.rst +++ b/mps/manual/source/code-index.rst @@ -183,6 +183,7 @@ prmcw3i3.c Mutator context implementation for Windows, IA-32. prmcw3i6.c Mutator context implementation for Windows, x86-64. prmcxc.c Mutator context implementation for macOS. prmcxc.h Mutator context interface for macOS. +prmcxca6.c Mutator context implementation for macOS, ARM64. prmcxci3.c Mutator context implementation for macOS, IA-32. prmcxci6.c Mutator context implementation for macOS, x86-64. prot.h Protection interface. See design.mps.prot_. @@ -393,6 +394,7 @@ w3i3mv.nmk NMAKE file for platform W3I3MV. w3i3pc.nmk NMAKE file for platform W3I3PC. w3i6mv.nmk NMAKE file for platform W3I6MV. w3i6pc.nmk NMAKE file for platform W3I6PC. +xca6ll.gmk GNU makefile for platform XCA6LL. xci3gc.gmk GNU makefile for platform XCI3GC. xci3ll.gmk GNU makefile for platform XCI3LL. xci6gc.gmk GNU makefile for platform XCI6GC. diff --git a/mps/manual/source/release.rst b/mps/manual/source/release.rst index b8fb7239fa9..70d5b7ccded 100644 --- a/mps/manual/source/release.rst +++ b/mps/manual/source/release.rst @@ -12,6 +12,8 @@ Release 1.118.0 New features ............ +#. New supported platform ``xca6ll`` (macOS, ARM64, Clang/LLVM). + #. The MPS no longer supports building for the xci3ll platform (macOS, IA-32, Clang/LLVM) using Xcode. This is because Xcode 10.0 no longer supports this platform. The platform is still supported via diff --git a/mps/manual/source/topic/platform.rst b/mps/manual/source/topic/platform.rst index 0538ec52f16..d72f3fb7a28 100644 --- a/mps/manual/source/topic/platform.rst +++ b/mps/manual/source/topic/platform.rst @@ -28,6 +28,7 @@ The second pair of characters names the processor architecture: ====== ====================== ====================== ``AR`` Processor architecture Constant ====== ====================== ====================== +``a6`` ARM64 :c:macro:`MPS_ARCH_A6` ``i3`` Intel/AMD IA-32 :c:macro:`MPS_ARCH_I3` ``i6`` Intel/AMD x86-64 :c:macro:`MPS_ARCH_I6` ====== ====================== ====================== @@ -66,6 +67,13 @@ Platform interface #include "mpstd.h" +.. c:macro:: MPS_ARCH_A6 + + A :term:`C` preprocessor macro that indicates, if defined, that + the target processor architecture of the compilation is a member + of the ARM64 family of 64-bit processors. + + .. c:macro:: MPS_ARCH_I3 A :term:`C` preprocessor macro that indicates, if defined, that @@ -206,6 +214,13 @@ Platform interface compiler. +.. c:macro:: MPS_PF_XCA6LL + + A :term:`C` preprocessor macro that indicates, if defined, that + the :term:`platform` consists of the macOS operating system, the + ARM64 processor architecture, and the Clang/LLVM compiler. + + .. c:macro:: MPS_PF_XCI3GC A :term:`C` preprocessor macro that indicates, if defined, that @@ -378,6 +393,7 @@ Platform Status ``w3i6mv`` Supported ``w3i6pc`` *Not supported* ``w3ppmv`` *Not supported* +``xca6ll`` Supported ``xci3gc`` *Not supported* ``xci3ll`` Supported ``xci6gc`` *Not supported* diff --git a/mps/manual/source/topic/porting.rst b/mps/manual/source/topic/porting.rst index ea497dd9776..30e039d9627 100644 --- a/mps/manual/source/topic/porting.rst +++ b/mps/manual/source/topic/porting.rst @@ -76,8 +76,8 @@ usable. stack` can be scanned. See :ref:`design-prmc` for the design, and ``prmc.h`` for the - interface. There are implementations on Unix, Windows, and macOS for - IA-32 and x86-64. + interface. There are implementations on Unix and Windows for + IA-32 and x86-64, and on macOS for IA-32, x86-64, and ARM64. There is a generic implementation in ``prmcan.c``, which can't provide these features, and so only supports a single thread.