merge of '92c36bfdbc6468d1711c043b530e0dfe5abb6dec'
     and 'c22c8c43f8f68b0bffd4d5ccdb2282c958268742'
diff --git a/backends/ChangeLog b/backends/ChangeLog
index 9c51f98..082f4f3 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,21 @@
+2007-10-09  Roland McGrath  <roland@redhat.com>
+
+	* sparc_auxv.c: New file.
+	* Makefile.am (sparc_SRCS): Add it.
+	* sparc_init.c (sparc_init): Initialize auxv_info hook.
+
+2007-10-08  Roland McGrath  <roland@redhat.com>
+
+	* linux-core-note.c (TIMEVAL_FIELD): New macro.
+	(prstatus_items): Use it.
+	* sparc_corenote.c: New file.
+	* sparc64_corenote.c: New file.
+	* Makefile.am (sparc_SRCS): Add them.
+	* sparc_init.c (sparc_init): Initialize core_note hook.
+
+	* sparc_symbol.c (sparc_machine_flag_check): New function.
+	* sparc_init.c (sparc_init): Use it.
+
 2007-09-27  Roland McGrath  <roland@redhat.com>
 
 	* alpha_retval.c: Use dwarf_attr_integrate and dwarf_hasattr_integrate.
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 84aa478..4174f8e 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -96,7 +96,8 @@
 libebl_arm_pic_a_SOURCES = $(arm_SRCS)
 am_libebl_arm_pic_a_OBJECTS = $(arm_SRCS:.c=.os)
 
-sparc_SRCS = sparc_init.c sparc_symbol.c sparc_regs.c sparc_retval.c
+sparc_SRCS = sparc_init.c sparc_symbol.c sparc_regs.c sparc_retval.c \
+	     sparc_corenote.c sparc64_corenote.c sparc_auxv.c
 libebl_sparc_pic_a_SOURCES = $(sparc_SRCS)
 am_libebl_sparc_pic_a_OBJECTS = $(sparc_SRCS:.c=.os)
 
diff --git a/backends/linux-core-note.c b/backends/linux-core-note.c
index 0913cc9..c4a90b7 100644
--- a/backends/linux-core-note.c
+++ b/backends/linux-core-note.c
@@ -53,6 +53,15 @@
   FIELD (ULONG, tv_usec);
 };
 
+/* On sparc64, tv_usec (suseconds_t) is actually 32 bits with 32 bits padding.
+   The 'T'|0x80 value for .format indicates this as a special kludge.  */
+#if SUSECONDS_HALF
+# define TIMEVAL_FIELD(name)	FIELD (time, ULONG, name, 'T'|0x80, .count = 2)
+#else
+# define TIMEVAL_FIELD(name)	FIELD (time, ULONG, name, 'T', .count = 2)
+#endif
+
+
 struct EBLHOOK(prstatus)
 {
   struct EBLHOOK(siginfo) pr_info;
@@ -115,10 +124,10 @@
     FIELD (identity, PID_T, ppid, 'd'),
     FIELD (identity, PID_T, pgrp, 'd'),
     FIELD (identity, PID_T, sid, 'd'),
-    FIELD (time, ULONG, utime, 'T', .count = 2),
-    FIELD (time, ULONG, stime, 'T', .count = 2),
-    FIELD (time, ULONG, cutime, 'T', .count = 2),
-    FIELD (time, ULONG, cstime, 'T', .count = 2),
+    TIMEVAL_FIELD (utime),
+    TIMEVAL_FIELD (stime),
+    TIMEVAL_FIELD (cutime),
+    TIMEVAL_FIELD (cstime),
 #ifdef PRSTATUS_REGSET_ITEMS
     PRSTATUS_REGSET_ITEMS,
 #endif
diff --git a/backends/sparc64_corenote.c b/backends/sparc64_corenote.c
new file mode 100644
index 0000000..cef6431
--- /dev/null
+++ b/backends/sparc64_corenote.c
@@ -0,0 +1,2 @@
+#define BITS 64
+#include "sparc_corenote.c"
diff --git a/backends/sparc_auxv.c b/backends/sparc_auxv.c
new file mode 100644
index 0000000..a22b3ce
--- /dev/null
+++ b/backends/sparc_auxv.c
@@ -0,0 +1,43 @@
+/* SPARC-specific auxv handling.
+   Copyright (C) 2007 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils 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; version 2 of the License.
+
+   Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#define BACKEND sparc_
+#include "libebl_CPU.h"
+
+int
+EBLHOOK(auxv_info) (GElf_Xword a_type, const char **name, const char **format)
+{
+  if (a_type != AT_HWCAP)
+    return 0;
+
+  *name = "HWCAP";
+  *format = "b"
+    "flush\0" "stbar\0" "swap\0" "muldiv\0" "v9\0" "ultra3\0" "v9v\0" "\0";
+  return 1;
+}
diff --git a/backends/sparc_corenote.c b/backends/sparc_corenote.c
new file mode 100644
index 0000000..55aed8f
--- /dev/null
+++ b/backends/sparc_corenote.c
@@ -0,0 +1,109 @@
+/* PowerPC specific core note handling.
+   Copyright (C) 2007 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils 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; version 2 of the License.
+
+   Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <elf.h>
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+#ifndef BITS
+# define BITS 		32
+# define BACKEND	sparc_
+#else
+# define BITS 		64
+# define BACKEND	sparc64_
+#endif
+#include "libebl_CPU.h"
+
+#define GR(at, n, dwreg)						\
+    { .offset = at * BITS/8, .regno = dwreg, .count = n, .bits = BITS }
+
+static const Ebl_Register_Location prstatus_regs[] =
+  {
+    GR (0, 32, 0),		/* %g0-%g7, %o0-%o7, %i0-%i7 */
+#if BITS == 32
+    GR (32, 1, 65),		/* %psr */
+    GR (33, 2, 68),		/* %pc, %npc */
+    GR (35, 1, 64),		/* %y */
+    GR (36, 1, 66),		/* %wim, %tbr */
+#else
+    GR (32, 1, 82),		/* %state */
+    GR (33, 2, 80),		/* %pc, %npc */
+    GR (35, 1, 85),		/* %y */
+#endif
+  };
+#define PRSTATUS_REGS_SIZE	(BITS / 8 * (32 + (BITS == 32 ? 6 : 4)))
+
+static const Ebl_Register_Location fpregset_regs[] =
+  {
+#if BITS == 32
+    GR (0, 32, 32),		/* %f0-%f31 */
+    /* 				   padding word */
+    GR (33, 1, 70),		/* %fsr */
+    /* 	       			   qcnt, q_entrysize, en, q, padding */
+# define FPREGSET_SIZE		(34 * 4 + 4 + 64 * 4 + 4)
+#else
+    GR (0, 32, 32),		/* %f0-%f31 */
+    GR (32, 1, 83),		/* %fsr */
+    /*  33, 1, 			   %gsr */
+    GR (34, 1, 84),		/* %fprs */
+# define FPREGSET_SIZE		(35 * 8)
+#endif
+  };
+
+#if BITS == 32
+# define ULONG			uint32_t
+# define ALIGN_ULONG		4
+# define TYPE_ULONG		ELF_T_WORD
+# define TYPE_LONG		ELF_T_SWORD
+# define UID_T			uint16_t
+# define GID_T			uint16_t
+# define ALIGN_UID_T		2
+# define ALIGN_GID_T		2
+# define TYPE_UID_T		ELF_T_HALF
+# define TYPE_GID_T		ELF_T_HALF
+#else
+# define ULONG			uint64_t
+# define ALIGN_ULONG		8
+# define TYPE_ULONG		ELF_T_XWORD
+# define TYPE_LONG		ELF_T_SXWORD
+# define UID_T			uint32_t
+# define GID_T			uint32_t
+# define ALIGN_UID_T		4
+# define ALIGN_GID_T		4
+# define TYPE_UID_T		ELF_T_WORD
+# define TYPE_GID_T		ELF_T_WORD
+# define SUSECONDS_HALF		1
+#endif
+#define PID_T			int32_t
+#define ALIGN_PID_T		4
+#define TYPE_PID_T		ELF_T_SWORD
+
+#include "linux-core-note.c"
diff --git a/backends/sparc_init.c b/backends/sparc_init.c
index ba0e08a..8da845e 100644
--- a/backends/sparc_init.c
+++ b/backends/sparc_init.c
@@ -1,5 +1,5 @@
 /* Initialization of SPARC specific backend library.
-   Copyright (C) 2002, 2005, 2006 Red Hat, Inc.
+   Copyright (C) 2002, 2005, 2006, 2007 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -34,6 +34,7 @@
 /* This defines the common reloc hooks based on sparc_reloc.def.  */
 #include "common-reloc.c"
 
+extern __typeof (EBLHOOK (core_note)) sparc64_core_note attribute_hidden;
 
 const char *
 sparc_init (elf, machine, eh, ehlen)
@@ -55,7 +56,12 @@
     eh->name = "SPARC";
   sparc_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
-  //HOOK (eh, core_note);
+  HOOK (eh, machine_flag_check);
+  if (eh->class == ELFCLASS64)
+    eh->core_note = sparc64_core_note;
+  else
+    HOOK (eh, core_note);
+  HOOK (eh, auxv_info);
   HOOK (eh, register_info);
   HOOK (eh, return_value_location);
 
diff --git a/backends/sparc_symbol.c b/backends/sparc_symbol.c
index 3a261a0..237620c 100644
--- a/backends/sparc_symbol.c
+++ b/backends/sparc_symbol.c
@@ -1,5 +1,5 @@
 /* SPARC specific symbolic name handling.
-   Copyright (C) 2002, 2003, 2005 Red Hat, Inc.
+   Copyright (C) 2002, 2003, 2005, 2007 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Jakub Jelinek <jakub@redhat.com>, 2002.
 
@@ -55,3 +55,14 @@
       return ELF_T_NUM;
     }
 }
+
+/* Check whether machine flags are valid.  */
+bool
+sparc_machine_flag_check (GElf_Word flags)
+{
+  return ((flags &~ (EF_SPARCV9_MM
+		     | EF_SPARC_LEDATA
+		     | EF_SPARC_32PLUS
+		     | EF_SPARC_SUN_US1
+		     | EF_SPARC_SUN_US3)) == 0);
+}