public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Add untested 32-bit core file support.
@ 2018-12-27 23:27 Jim Wilson
  2019-01-12 22:29 ` Mark Wielaard
  0 siblings, 1 reply; 4+ messages in thread
From: Jim Wilson @ 2018-12-27 23:27 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Jim Wilson

This conflicts with the previoues two patches.  Adds 32-bit support exactly the
same way that the sparc backend handles 32- and 64-bit core file support.  The
64-bit core file support was tested and still works same as before.

Signed-off-by: Jim Wilson <jimw@sifive.com>
---
 backends/ChangeLog          | 11 +++++++++
 backends/Makefile.am        |  2 +-
 backends/riscv64_corenote.c |  2 ++
 backends/riscv_corenote.c   | 45 +++++++++++++++++++++++++++----------
 backends/riscv_init.c       |  7 +++++-
 5 files changed, 53 insertions(+), 14 deletions(-)
 create mode 100644 backends/riscv64_corenote.c

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 637aa8c2..58a1b775 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,5 +1,16 @@
 2018-12-27  Jim Wilson  <jimw@sifive.com>
 
+	* Makefile.am (riscv_SRCS): Add riscv64_corenote.c.
+	* riscv64_corenote.c: New file.
+	* riscv_corenote.c (BITS): New.
+	(BACKEND): Conditional on BITS.
+	(ULONG, UID_T, GID_T, ALIGN_ULONG, ALIGN_UID_T, ALIGN_GID_T): Likewise.
+	(TYPE_ULONG, TYPE_UID_T, TYPE_GID_T): Likewise.
+	(prstatus_regs): Use BITS/8 instead of 8.
+	(PRSTATUS_REGS_SIZE): Likewise.
+	* riscv_init.c (riscv64_core_note): Declare.
+	(riscv_init): If ELFCLASS64 then use riscv64_core_note hook.
+
 	* Makefile.am (riscv_SRCS): Add riscv_retval.c.
 	* riscv_init.c: Include libelfP.h.
 	(riscv_return_value_location_lp64d): Declare.
diff --git a/backends/Makefile.am b/backends/Makefile.am
index fedeb93a..2126a2ec 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -132,7 +132,7 @@ libebl_bpf_pic_a_SOURCES = $(bpf_SRCS)
 am_libebl_bpf_pic_a_OBJECTS = $(bpf_SRCS:.c=.os)
 
 riscv_SRCS = riscv_init.c riscv_symbol.c riscv_cfi.c riscv_regs.c \
-	     riscv_initreg.c riscv_corenote.c riscv_retval.c
+	     riscv_initreg.c riscv_corenote.c riscv64_corenote.c riscv_retval.c
 libebl_riscv_pic_a_SOURCES = $(riscv_SRCS)
 am_libebl_riscv_pic_a_OBJECTS = $(riscv_SRCS:.c=.os)
 
diff --git a/backends/riscv64_corenote.c b/backends/riscv64_corenote.c
new file mode 100644
index 00000000..dbcb89d9
--- /dev/null
+++ b/backends/riscv64_corenote.c
@@ -0,0 +1,2 @@
+#define BITS 64
+#include "riscv_corenote.c"
diff --git a/backends/riscv_corenote.c b/backends/riscv_corenote.c
index afb84bee..b728903f 100644
--- a/backends/riscv_corenote.c
+++ b/backends/riscv_corenote.c
@@ -35,27 +35,48 @@
 #include <stdio.h>
 #include <sys/time.h>
 
-#define BACKEND	riscv_
+#ifndef BITS
+# define BITS		32
+# define BACKEND	riscv_
+#else
+# define BITS		64
+# define BACKEND	riscv64_
+#endif
+
 #include "libebl_CPU.h"
 
-#define	ULONG			uint64_t
+#if BITS == 32
+# define ULONG			uint32_t
+# define UID_T			uint16_t
+# define GID_T			uint16_t
+# define ALIGN_ULONG		4
+# define ALIGN_UID_T		2
+# define ALIGN_GID_T		2
+# define TYPE_ULONG		ELF_T_WORD
+# define TYPE_UID_T		ELF_T_HALF
+# define TYPE_GID_T		ELF_T_HALF
+#else
+# define ULONG			uint64_t
+# define UID_T			uint32_t
+# define GID_T			uint32_t
+# define ALIGN_ULONG		8
+# define ALIGN_UID_T		4
+# define ALIGN_GID_T		4
+# define TYPE_ULONG		ELF_T_XWORD
+# define TYPE_UID_T		ELF_T_WORD
+# define TYPE_GID_T		ELF_T_WORD
+#endif
+
 #define PID_T			int32_t
-#define	UID_T			uint32_t
-#define	GID_T			uint32_t
-#define ALIGN_ULONG		8
 #define ALIGN_PID_T		4
-#define ALIGN_UID_T		4
-#define ALIGN_GID_T		4
-#define TYPE_ULONG		ELF_T_XWORD
 #define TYPE_PID_T		ELF_T_SWORD
-#define TYPE_UID_T		ELF_T_WORD
-#define TYPE_GID_T		ELF_T_WORD
+
 
 static const Ebl_Register_Location prstatus_regs[] =
   {
-    { .offset = 8, .regno = 1, .count = 31, .bits = 64 } /* x1..x31 */
+    { .offset = BITS/8, .regno = 1, .count = 31, .bits = 64 } /* x1..x31 */
   };
-#define PRSTATUS_REGS_SIZE	(32 * 8)
+#define PRSTATUS_REGS_SIZE	(32 * (BITS/8))
 
 #define PRSTATUS_REGSET_ITEMS						\
   {									\
diff --git a/backends/riscv_init.c b/backends/riscv_init.c
index ecee2910..3398c104 100644
--- a/backends/riscv_init.c
+++ b/backends/riscv_init.c
@@ -41,6 +41,8 @@
 extern __typeof (EBLHOOK (return_value_location))
   riscv_return_value_location_lp64d attribute_hidden;
 
+extern __typeof (EBLHOOK (core_note)) riscv64_core_note attribute_hidden;
+
 const char *
 riscv_init (Elf *elf,
 	    GElf_Half machine __attribute__ ((unused)),
@@ -62,7 +64,10 @@ riscv_init (Elf *elf,
   HOOK (eh, check_special_symbol);
   HOOK (eh, machine_flag_check);
   HOOK (eh, set_initial_registers_tid);
-  HOOK (eh, core_note);
+  if (eh->class == ELFCLASS64)
+    eh->core_note = riscv64_core_note;
+  else
+    HOOK (eh, core_note);
   if (eh->class == ELFCLASS64
       && ((elf->state.elf64.ehdr->e_flags & EF_RISCV_FLOAT_ABI)
 	  == EF_RISCV_FLOAT_ABI_DOUBLE))
-- 
2.19.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Add untested 32-bit core file support.
  2018-12-27 23:27 [PATCH] RISC-V: Add untested 32-bit core file support Jim Wilson
@ 2019-01-12 22:29 ` Mark Wielaard
  2019-01-13  0:38   ` Jim Wilson
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Wielaard @ 2019-01-12 22:29 UTC (permalink / raw)
  To: Jim Wilson, elfutils-devel

On Thu, 2018-12-27 at 15:27 -0800, Jim Wilson wrote:
> This conflicts with the previoues two patches.  Adds 32-bit support exactly the
> same way that the sparc backend handles 32- and 64-bit core file support.  The
> 64-bit core file support was tested and still works same as before.

I don't really like adding code that cannot be tested. But it does look
the 32-bit port isn't far off, just waiting for the next linux/glibc
release to settle the time_t ABI. And the code does look correct.
Except for...

> static const Ebl_Register_Location prstatus_regs[] =
>    {
> -    { .offset = 8, .regno = 1, .count = 31, .bits = 64 } /* x1..x31 */
> +    { .offset = BITS/8, .regno = 1, .count = 31, .bits = 64 } /* x1..x31 */
>    };

Should that be .bits = BITS ?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Add untested 32-bit core file support.
  2019-01-12 22:29 ` Mark Wielaard
@ 2019-01-13  0:38   ` Jim Wilson
  2019-01-13 10:12     ` Mark Wielaard
  0 siblings, 1 reply; 4+ messages in thread
From: Jim Wilson @ 2019-01-13  0:38 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

On Sat, Jan 12, 2019 at 2:29 PM Mark Wielaard <mark@klomp.org> wrote:
> I don't really like adding code that cannot be tested. But it does look
> the 32-bit port isn't far off, just waiting for the next linux/glibc
> release to settle the time_t ABI. And the code does look correct.
> Except for...

We don't expect 32-bit desktop linux distros, but there are folks that
want 32-bit embedded linux.  A few companies have gotten it working,
but only Andes is trying to upstream patches so far, and as you
mentioned that is waiting for the time_t ABI.  Meanwhile, it should be
possible to build a busy-box style 32-bit linux system, using an old
obsolete pre-upstream glibc port, but that isn't useful for real
development work.

> > static const Ebl_Register_Location prstatus_regs[] =
> >    {
> > -    { .offset = 8, .regno = 1, .count = 31, .bits = 64 } /* x1..x31 */
> > +    { .offset = BITS/8, .regno = 1, .count = 31, .bits = 64 } /* x1..x31 */
> >    };
>
> Should that be .bits = BITS ?

Yes, sorry, I was looking at the offset field and completely missed
the bits member at the end.  Do you want me to submit an updated
patch?

Jim

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Add untested 32-bit core file support.
  2019-01-13  0:38   ` Jim Wilson
@ 2019-01-13 10:12     ` Mark Wielaard
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Wielaard @ 2019-01-13 10:12 UTC (permalink / raw)
  To: Jim Wilson; +Cc: elfutils-devel

On Sat, Jan 12, 2019 at 04:37:51PM -0800, Jim Wilson wrote:
> On Sat, Jan 12, 2019 at 2:29 PM Mark Wielaard <mark@klomp.org> wrote:
> > > static const Ebl_Register_Location prstatus_regs[] =
> > >    {
> > > -    { .offset = 8, .regno = 1, .count = 31, .bits = 64 } /* x1..x31 */
> > > +    { .offset = BITS/8, .regno = 1, .count = 31, .bits = 64 } /* x1..x31 */
> > >    };
> >
> > Should that be .bits = BITS ?
> 
> Yes, sorry, I was looking at the offset field and completely missed
> the bits member at the end.  Do you want me to submit an updated
> patch?

I fixed it up and pushed the commit. It looks fine otherwise.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-13 10:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-27 23:27 [PATCH] RISC-V: Add untested 32-bit core file support Jim Wilson
2019-01-12 22:29 ` Mark Wielaard
2019-01-13  0:38   ` Jim Wilson
2019-01-13 10:12     ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).