2006-01-11  Roland McGrath  <roland@redhat.com>

	* s390_regs.c: New file.
	* Makefile.am (s390_SRCS): Add it.
	* s390_init.c (s390_init): Install register_name hook.

diff --git a/backends/ChangeLog b/backends/ChangeLog
index c51190d..c7f82a9 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,5 +1,9 @@
 2006-01-11  Roland McGrath  <roland@redhat.com>
 
+	* s390_regs.c: New file.
+	* Makefile.am (s390_SRCS): Add it.
+	* s390_init.c (s390_init): Install register_name hook.
+
 	* s390_reloc.def: Update bits per
 	Martin Schwidefsky <schwidefsky@de.ibm.com>.
 
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 9503d9d..7719b6f 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in
 ##
-## Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Red Hat, Inc.
+## Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Red Hat, Inc.
 ##
 ## This program is Open Source software; you can redistribute it and/or
 ## modify it under the terms of the Open Software License version 1.0 as
@@ -96,7 +96,7 @@
 libebl_ppc64_pic_a_SOURCES = $(ppc64_SRCS)
 am_libebl_ppc64_pic_a_OBJECTS = $(ppc64_SRCS:.c=.os)
 
-s390_SRCS = s390_init.c s390_symbol.c
+s390_SRCS = s390_init.c s390_symbol.c s390_regs.c
 libebl_s390_pic_a_SOURCES = $(s390_SRCS)
 am_libebl_s390_pic_a_OBJECTS = $(s390_SRCS:.c=.os)
 
diff --git a/backends/s390_init.c b/backends/s390_init.c
index 64b373b..d39495c 100644
--- a/backends/s390_init.c
+++ b/backends/s390_init.c
@@ -1,5 +1,5 @@
 /* Initialization of S/390 specific backend library.
-   Copyright (C) 2005 Red Hat, Inc.
+   Copyright (C) 2005, 2006 Red Hat, Inc.
 
    This program is Open Source software; you can redistribute it and/or
    modify it under the terms of the Open Software License version 1.0 as
@@ -38,6 +38,7 @@
   eh->name = "IBM S/390";
   s390_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
+  HOOK (eh, register_name);
 
   return MODVERSION;
 }
diff --git a/backends/s390_regs.c b/backends/s390_regs.c
new file mode 100644
index 0000000..a0133e4
--- /dev/null
+++ b/backends/s390_regs.c
@@ -0,0 +1,116 @@
+/* Register names and numbers for S/390 DWARF.
+   Copyright (C) 2006 Red Hat, Inc.
+
+   This program is Open Source software; you can redistribute it and/or
+   modify it under the terms of the Open Software License version 1.0 as
+   published by the Open Source Initiative.
+
+   You should have received a copy of the Open Software License along
+   with this program; if not, you may obtain a copy of the Open Software
+   License version 1.0 from http://www.opensource.org/licenses/osl.php or
+   by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+   3001 King Ranch Road, Ukiah, CA 95482.   */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+
+#define BACKEND s390_
+#include "libebl_CPU.h"
+
+
+/*
+zseries (64)
+
+0-15	gpr0-gpr15	x
+16-19	fpr[0246]
+20-24	fpr[13578]
+25-27	fpr1[024]
+28	fpr9
+29-31	fpr1[135]
+32-47	cr0-cr15	x
+48-63	ar0-ar15	x
+64	psw_mask
+65	psw_address
+*/
+
+
+ssize_t
+s390_register_name (Ebl *ebl __attribute__ ((unused)),
+		    int regno, char *name, size_t namelen,
+		    const char **prefix, const char **setname)
+{
+  if (name == NULL)
+    return 66;
+
+  if (regno < 0 || regno > 65 || namelen < 7)
+    return -1;
+
+  *prefix = "%";
+
+  if (regno < 16)
+    *setname = "integer";
+  else if (regno < 32)
+    *setname = "FPU";
+  else if (regno < 48 || regno > 63)
+    *setname = "control";	/* XXX ? */
+  else
+    *setname = "address";	/* XXX ? */
+
+  switch (regno)
+    {
+    case 0 ... 9:
+      name[0] = 'r';
+      name[1] = regno + '0';
+      namelen = 2;
+      break;
+
+    case 10 ... 15:
+      name[0] = 'r';
+      name[1] = '1';
+      name[2] = regno - 10 + '0';
+      namelen = 3;
+      break;
+
+    case 16 ... 31:
+      name[0] = 'f';
+      regno = (regno & 8) | ((regno & 4) >> 2) | ((regno & 3) << 1);
+      namelen = 1;
+      if (regno >= 10)
+	{
+	  regno -= 10;
+	  name[namelen++] = '1';
+	}
+      name[namelen++] = regno + '0';
+      break;
+
+    case 32 + 0 ... 32 + 9:
+    case 48 + 0 ... 48 + 9:
+      name[0] = regno < 48 ? 'c' : 'a';
+      name[1] = (regno & 15) + '0';
+      namelen = 2;
+      break;
+
+    case 32 + 10 ... 32 + 15:
+    case 48 + 10 ... 48 + 15:
+      name[0] = regno < 48 ? 'c' : 'a';
+      name[1] = '1';
+      name[2] = (regno & 15) - 10 + '0';
+      namelen = 3;
+      break;
+
+    case 64:
+      return stpcpy (name, "pswm") - name;
+    case 65:
+      return stpcpy (name, "pswa") - name;
+
+    default:
+      *setname = NULL;
+      return 0;
+    }
+
+  name[namelen++] = '\0';
+  return namelen;
+}