All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Arbuckle <programmingkidx@gmail.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: John Arbuckle <programmingkidx@gmail.com>
Subject: [PATCH] Add support for building on ARM Macs
Date: Thu, 28 Jan 2021 16:14:18 -0500	[thread overview]
Message-ID: <20210128211419.50052-1-programmingkidx@gmail.com> (raw)

Adds support for building QEMU on ARM-based Macintoshes. 
This patch has been tested on an M1 Mac running Mac OS 11.1
and on a 64-bit x86 Mac running Mac OS 10.12.

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
---
 configure | 49 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/configure b/configure
index dcc5ea7d63..f6bcd0ecac 100755
--- a/configure
+++ b/configure
@@ -622,13 +622,40 @@ fi
 # the correct CPU with the --cpu option.
 case $targetos in
 Darwin)
-  # on Leopard most of the system is 32-bit, so we have to ask the kernel if we can
-  # run 64-bit userspace code.
-  # If the user didn't specify a CPU explicitly and the kernel says this is
-  # 64 bit hw, then assume x86_64. Otherwise fall through to the usual detection code.
-  if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
-    cpu="x86_64"
-  fi
+    # user specified the target cpu with --cpu
+    if test ! -z "$cpu"; then
+        echo "Using user-specified cpu target $cpu"
+
+    # detect the host cpu
+    else
+        raw_value=`sysctl -n hw.cputype`
+        cpu_arch=$((raw_value & 0xff))
+
+        if [[ $"cpu_arch" -eq 12 ]]; then    # if ARM
+            is_64bit=$((raw_value & 0x01000000))
+            if [[ "$is_64bit" -gt 1 ]]; then # if 64-bit
+                cpu="aarch64"
+            else
+                cpu="arm"
+            fi
+
+        elif [[ $"cpu_arch" -eq 7 ]]; then   # if x86
+            is_64bit=`sysctl -n hw.cpu64bit_capable`
+            if [[ "$is_64bit" -eq 1 ]]; then # if 64-bit
+                cpu="x86_64"
+            else
+                cpu="x86"
+            fi
+
+        elif [[ $"cpu_arch" -eq 18 ]]; then  # if PowerPC
+                # Not sure know how to detect 64-bit PowerPC a.k.a. G5
+                cpu="ppc"
+
+        else
+            echo "Unknown target cpu error"
+        fi
+    fi
+
   HOST_DSOSUF=".dylib"
   ;;
 SunOS)
@@ -772,10 +799,12 @@ OpenBSD)
 Darwin)
   bsd="yes"
   darwin="yes"
-  if [ "$cpu" = "x86_64" ] ; then
-    QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
-    QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
+  cpu_arch="$cpu"
+  if [ $cpu == "aarch64" ]; then   # Apple's clang prefers arm64
+    cpu_arch="arm64"
   fi
+  QEMU_CFLAGS="-arch $cpu_arch $QEMU_CFLAGS"
+  QEMU_LDFLAGS="-arch $cpu_arch $QEMU_LDFLAGS"
   audio_drv_list="coreaudio try-sdl"
   audio_possible_drivers="coreaudio sdl"
   QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS"
-- 
2.24.3 (Apple Git-128)



             reply	other threads:[~2021-01-28 21:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 21:14 John Arbuckle [this message]
2021-01-28 22:14 ` [PATCH] Add support for building on ARM Macs Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210128211419.50052-1-programmingkidx@gmail.com \
    --to=programmingkidx@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.