Beginnings of Fuchsia aarch64 port

minimal testing, very preliminary

Change-Id: I008aa10687dad7baba790949ae2f28e1104d734b
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 281ddc1..2d5672a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2017-01-04  Doug Evans  <dje@google.com>
+
+	Beginnings of Fuchsia aarch64 port.
+	* aarch64-fuchsia-tdep.c: New file.
+	* aarch64-fuchsia-tdep.h: New file.
+	* configure.tgt: Add aarch64-*-fuchsia*.
+
 2016-12-16  Doug Evans  <dje@google.com>
 
 	* objfile-flags.h (objfile_flag): Add comment.
diff --git a/gdb/aarch64-fuchsia-tdep.c b/gdb/aarch64-fuchsia-tdep.c
new file mode 100644
index 0000000..e344c37
--- /dev/null
+++ b/gdb/aarch64-fuchsia-tdep.c
@@ -0,0 +1,112 @@
+/* Target-dependent code for Fuchsia AArch64.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+
+#include <ctype.h>
+
+#include "gdbarch.h"
+#include "arch-utils.h"
+#include "fuchsia-tdep.h"
+#include "aarch64-tdep.h"
+#include "aarch64-fuchsia-tdep.h"
+#include "osabi.h"
+#include "solib-svr4.h"
+#include "symtab.h"
+#include "regcache.h"
+#include "regset.h"
+#include "cli/cli-utils.h"
+#include "parser-defs.h"
+#include "user-regs.h"
+
+/* Register maps.  */
+
+static const struct regcache_map_entry aarch64_fuchsia_gregmap[] =
+  {
+    { 31, AARCH64_X0_REGNUM, 8 }, /* x0 ... x30 */
+    { 1, AARCH64_SP_REGNUM, 8 },
+    { 1, AARCH64_PC_REGNUM, 8 },
+    { 1, AARCH64_CPSR_REGNUM, 8 },
+    { 0 }
+  };
+
+static const struct regcache_map_entry aarch64_fuchsia_fpregmap[] =
+  {
+    { 32, AARCH64_V0_REGNUM, 16 }, /* v0 ... v31 */
+    { 1, AARCH64_FPSR_REGNUM, 4 },
+    { 1, AARCH64_FPCR_REGNUM, 4 },
+    { 0 }
+  };
+
+/* Register set definitions.  */
+
+const struct regset aarch64_fuchsia_gregset =
+  {
+    aarch64_fuchsia_gregmap,
+    regcache_supply_regset, regcache_collect_regset
+  };
+
+const struct regset aarch64_fuchsia_fpregset =
+  {
+    aarch64_fuchsia_fpregmap,
+    regcache_supply_regset, regcache_collect_regset
+  };
+
+static void
+aarch64_fuchsia_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  tdep->lowest_pc = 0x8000;
+
+  fuchsia_init_abi (info, gdbarch);
+
+  set_solib_svr4_fetch_link_map_offsets (gdbarch,
+					 svr4_lp64_fetch_link_map_offsets);
+
+  /* Enable TLS support.  */
+  set_gdbarch_fetch_tls_load_module_address (gdbarch,
+                                             svr4_fetch_objfile_link_map);
+
+  /* Enable longjmp.  */
+  tdep->jb_pc = 11;
+
+  /* Displaced stepping.  */
+  set_gdbarch_max_insn_length (gdbarch, 4 * DISPLACED_MODIFIED_INSNS);
+  set_gdbarch_displaced_step_copy_insn (gdbarch,
+					aarch64_displaced_step_copy_insn);
+  set_gdbarch_displaced_step_fixup (gdbarch, aarch64_displaced_step_fixup);
+  set_gdbarch_displaced_step_free_closure (gdbarch,
+					   simple_displaced_step_free_closure);
+  set_gdbarch_displaced_step_location (gdbarch, fuchsia_displaced_step_location);
+  set_gdbarch_displaced_step_hw_singlestep (gdbarch,
+					    aarch64_displaced_step_hw_singlestep);
+}
+
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_aarch64_fuchsia_tdep;
+
+void
+_initialize_aarch64_fuchsia_tdep (void)
+{
+  gdbarch_register_osabi_sniffer (bfd_arch_aarch64, bfd_target_elf_flavour,
+				  fuchsia_osabi_sniffer);
+  gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_FUCHSIA,
+			  aarch64_fuchsia_init_abi);
+}
diff --git a/gdb/aarch64-fuchsia-tdep.h b/gdb/aarch64-fuchsia-tdep.h
new file mode 100644
index 0000000..be623d7
--- /dev/null
+++ b/gdb/aarch64-fuchsia-tdep.h
@@ -0,0 +1,25 @@
+/* Fuchsia on AArch64 target support, prototypes.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef AARCH64_FUCHSIA_TDEP_H
+#define AARCH64_FUCHSIA_TDEP_H
+
+// Work-in-progress, nothing needed, yet.
+
+#endif // AARCH64_FUCHSIA_TDEP_H
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index 502a46b..58b281c 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -42,6 +42,12 @@
 	gdb_target_obs="aarch64-tdep.o aarch64-newlib-tdep.o aarch64-insn.o"
 	;;
 
+aarch64*-*-fuchsia*)
+	# Target: AArch64 fuchsia
+	gdb_target_obs="aarch64-tdep.o aarch64-fuchsia-tdep.o aarch64-insn.o \
+			fuchsia-tdep.o solib-svr4.o symfile-mem.o"
+	;;
+
 aarch64*-*-linux*)
 	# Target: AArch64 linux
 	gdb_target_obs="aarch64-tdep.o aarch64-linux-tdep.o aarch64-insn.o \