[m-rev.] diff: use global registers on aarch64

Julien Fischer jfischer at opturion.com
Wed Jan 13 14:03:51 AEDT 2021


The diff below is sufficient to allow Mercury to bootcheck in grade
reg.gc on my aarch64 Linux system.  I'll update the documentation and
NEWS after I've bootchecked in further reg.* grades.

------------------------------

Use global registers on aarch64.

runtime/machdeps/aarch64_regs.h:
runtime/mercury_regs.h:
      Define global registers for aarch64.

configure.ac:
      Compile with -fomit-frame-pointer on aarch64.  (Doing so, frees
      up register x29.)

      Compile with -fPIC instead of -fpic on aarch64-*-linux* systems
      in order to avoid size limits on the global offset table.

Julien.

diff --git a/configure.ac b/configure.ac
index c7afb1255..ea491cf41 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
  # vim: ts=4 sw=4 expandtab
  #-----------------------------------------------------------------------------#
  # Copyright (C) 1995-2012 The University of Melbourne.
-# Copyright (C) 2013-2020 The Mercury team.
+# Copyright (C) 2013-2021 The Mercury team.
  # This file may only be copied under the terms of the GNU General
  # Public Licence - see the file COPYING in the Mercury distribution.
  #-----------------------------------------------------------------------------#
@@ -2420,10 +2420,11 @@ case "$ac_cv_prog_gcc" in yes)
              mercury_cv_gcc_labels=no
              ;;
          aarch64*)
-        # The test for GCC labels goes into a loop on AArch64.
+            # The test for GCC labels goes into a loop on AArch64.
              MERCURY_MSG("gcc labels do not work on AArch64")
              mercury_cv_asm_labels=no
              mercury_cv_gcc_labels=no
+            CFLAGS_FOR_REGS="-fno-omit-frame-pointer"
              ;;
      esac
      ;;
@@ -4186,6 +4187,9 @@ if test "$mercury_cv_enable_shared_libs" = "yes"; then
              ;;
          aarch64*-linux|aarch64*-linux-gnu)
              AC_MSG_RESULT(yes)
+            # On aarch64 machines we must use -fPIC rather than -fpic in order
+            # to avoid limits on the size of the global offset table.
+            CFLAGS_FOR_PIC="-fPIC -DMR_PIC"
              EXT_FOR_SHARED_LIB=so
              ;;
          *-freebsd*)
diff --git a/runtime/machdeps/aarch64_regs.h b/runtime/machdeps/aarch64_regs.h
index e69de29bb..9b612310a 100644
--- a/runtime/machdeps/aarch64_regs.h
+++ b/runtime/machdeps/aarch64_regs.h
@@ -0,0 +1,73 @@
+/*
+** Copyright (C) 2021 The Mercury team.
+** This file is distributed under the terms specified in COPYING.LIB.
+*/
+#ifndef MR_MACHDEPS_AARCH64_REGS_H
+#define MR_MACHDEPS_AARCH64_REGS_H
+
+#define MR_NUM_REAL_REGS 4
+
+/*
+** Machine registers MR_mr0 - MR_mr36 for the ARM architecture.
+*/
+
+register        MR_Word MR_mr0 __asm__("x19");  /* sp */
+register        MR_Word MR_mr1 __asm__("x20");  /* succip */
+register        MR_Word MR_mr2 __asm__("x21");  /* r1 */
+register        MR_Word MR_mr3 __asm__("x22");  /* r2 */
+
+#define MR_save_regs_to_mem(save_area) (        \
+        save_area[0] = MR_mr0,                  \
+        save_area[1] = MR_mr1,                  \
+        save_area[2] = MR_mr2,                  \
+        save_area[3] = MR_mr3,                  \
+        (void)0                                 \
+ )
+
+#define MR_restore_regs_from_mem(save_area) (   \
+        MR_mr0 = save_area[0],                  \
+        MR_mr1 = save_area[1],                  \
+        MR_mr2 = save_area[2],                  \
+        MR_mr3 = save_area[3],                  \
+        (void)0                                 \
+)
+
+#define MR_save_transient_regs_to_mem(save_area)        ((void)0)
+#define MR_restore_transient_regs_from_mem(save_area)   ((void)0)
+ 
+#define MR_mr4  MR_fake_reg[4]
+#define MR_mr5  MR_fake_reg[5]
+#define MR_mr6  MR_fake_reg[6]
+#define MR_mr7  MR_fake_reg[7]
+#define MR_mr8  MR_fake_reg[8]
+#define MR_mr9  MR_fake_reg[9]
+#define MR_mr10 MR_fake_reg[10]
+#define MR_mr11 MR_fake_reg[11]
+#define MR_mr12 MR_fake_reg[12]
+#define MR_mr13 MR_fake_reg[13]
+#define MR_mr14 MR_fake_reg[14]
+#define MR_mr15 MR_fake_reg[15]
+#define MR_mr16 MR_fake_reg[16]
+#define MR_mr17 MR_fake_reg[17]
+#define MR_mr18 MR_fake_reg[18]
+#define MR_mr19 MR_fake_reg[19]
+#define MR_mr20 MR_fake_reg[20]
+#define MR_mr21 MR_fake_reg[21]
+#define MR_mr22 MR_fake_reg[22]
+#define MR_mr23 MR_fake_reg[23]
+#define MR_mr24 MR_fake_reg[24]
+#define MR_mr25 MR_fake_reg[25]
+#define MR_mr26 MR_fake_reg[26]
+#define MR_mr27 MR_fake_reg[27]
+#define MR_mr28 MR_fake_reg[28]
+#define MR_mr29 MR_fake_reg[29]
+#define MR_mr30 MR_fake_reg[30]
+#define MR_mr31 MR_fake_reg[31]
+#define MR_mr32 MR_fake_reg[32]
+#define MR_mr33 MR_fake_reg[33]
+#define MR_mr34 MR_fake_reg[34]
+#define MR_mr35 MR_fake_reg[35]
+#define MR_mr36 MR_fake_reg[36]
+#define MR_mr37 MR_fake_reg[37]
+
+#endif /* not MR_MACHDEPS_ARM_REGS_H */
diff --git a/runtime/mercury_regs.h b/runtime/mercury_regs.h
index daec4f9de..f7f611a82 100644
--- a/runtime/mercury_regs.h
+++ b/runtime/mercury_regs.h
@@ -95,6 +95,8 @@
      #include "machdeps/ia64_regs.h"
    #elif defined(__arm__)
      #include "machdeps/arm_regs.h"
+  #elif defined(__aarch64__)
+    #include "machdeps/aarch64_regs.h"
    #else
      #error "MR_USE_GCC_GLOBAL_REGISTERS not yet supported on this machine."
    #endif


More information about the reviews mailing list