Module Name: src
Committed By: rin
Date: Sun Jul 21 16:53:17 UTC 2019
Modified Files:
src/sys/lib/libsa: Makefile loadfile_elf32.c
Log Message:
Add SA_ENABLE_BIENDIAN option, which enable us to load kernel image of
opposite byte order (for arm EFI bootloader).
XXX
Currently, it is restricted to load_elf*.c. It would be nice if we can
recognize disklabel and filesystem of opposite byte order.
To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/lib/libsa/Makefile
cvs rdiff -u -r1.54 -r1.55 src/sys/lib/libsa/loadfile_elf32.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/lib/libsa/Makefile
diff -u src/sys/lib/libsa/Makefile:1.90 src/sys/lib/libsa/Makefile:1.91
--- src/sys/lib/libsa/Makefile:1.90 Tue Apr 2 22:25:10 2019
+++ src/sys/lib/libsa/Makefile Sun Jul 21 16:53:17 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.90 2019/04/02 22:25:10 christos Exp $
+# $NetBSD: Makefile,v 1.91 2019/07/21 16:53:17 rin Exp $
LIB= sa
LIBISPRIVATE?= yes
@@ -7,6 +7,8 @@ SA_USE_CREAD?= no # Read compressed ker
SA_INCLUDE_NET?= yes # Netboot via TFTP, NFS
SA_USE_LOADFILE?= no # Generic executable loading support
SA_ENABLE_LS_OP?= no # Filesystems ls operation
+SA_ENABLE_BIENDIAN?= no # Biendian support
+ # (currently only for loadfile_elf*)
#DEBUGCPPFLAGS= -DBOOTP_DEBUG -DNETIF_DEBUG -DETHER_DEBUG -DNFS_DEBUG -DRPC_DEBUG -DRARP_DEBUG -DARP_DEBUG -DNET_DEBUG -DDEBUG -DPARANOID
CPPFLAGS= -I${SADIR} ${SACPPFLAGS} ${SAMISCCPPFLAGS} \
@@ -73,6 +75,11 @@ SRCS+= bootp.c rarp.c bootparam.c
SRCS+= nfs.c tftp.c
.endif
+.if (${SA_ENABLE_BIENDIAN} == "yes")
+CPPFLAGS+= -DLIBSA_BIENDIAN_SUPPORT
+SRCS+= byteorder.c
+.endif
+
SRCS+= ffsv1.c ffsv2.c
SRCS+= lfsv1.c lfsv2.c
SRCS+= cd9660.c
Index: src/sys/lib/libsa/loadfile_elf32.c
diff -u src/sys/lib/libsa/loadfile_elf32.c:1.54 src/sys/lib/libsa/loadfile_elf32.c:1.55
--- src/sys/lib/libsa/loadfile_elf32.c:1.54 Thu Jun 20 17:33:30 2019
+++ src/sys/lib/libsa/loadfile_elf32.c Sun Jul 21 16:53:17 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: loadfile_elf32.c,v 1.54 2019/06/20 17:33:30 maxv Exp $ */
+/* $NetBSD: loadfile_elf32.c,v 1.55 2019/07/21 16:53:17 rin Exp $ */
/*
* Copyright (c) 1997, 2008, 2017 The NetBSD Foundation, Inc.
@@ -59,12 +59,18 @@
#define ELFROUND (ELFSIZE / 8)
#ifndef _STANDALONE
-#include "byteorder.h"
-
/*
* Byte swapping may be necessary in the non-_STANDLONE case because
* we may be built with a host compiler.
*/
+#ifndef LIBSA_BIENDIAN_SUPPORT
+#define LIBSA_BIENDIAN_SUPPORT
+#endif
+#endif
+
+#ifdef LIBSA_BIENDIAN_SUPPORT
+#include "byteorder.h"
+
#define E16(f) \
f = (bo == ELFDATA2LSB) ? sa_htole16(f) : sa_htobe16(f)
#define E32(f) \
@@ -241,10 +247,10 @@ externalize_shdr(Elf_Byte bo, Elf_Shdr *
#error ELFSIZE is not 32 or 64
#endif
}
-#else /* _STANDALONE */
+#else /* LIBSA_BIENDIAN_SUPPORT */
/*
- * Byte swapping is never necessary in the _STANDALONE case because
- * we are being built with the target compiler.
+ * Byte swapping is never necessary in the !LIBSA_BIENDIAN_SUPPORT case
+ * because we are being built with the target compiler.
*/
#define internalize_ehdr(bo, ehdr) /* nothing */
#define externalize_ehdr(bo, ehdr) /* nothing */
@@ -253,7 +259,7 @@ externalize_shdr(Elf_Byte bo, Elf_Shdr *
#define internalize_shdr(bo, shdr) /* nothing */
#define externalize_shdr(bo, shdr) /* nothing */
-#endif /* _STANDALONE */
+#endif /* LIBSA_BIENDIAN_SUPPORT */
#define IS_TEXT(p) (p.p_flags & PF_X)
#define IS_DATA(p) ((p.p_flags & PF_X) == 0)
@@ -379,7 +385,7 @@ ELFNAMEEND(loadfile_dynamic)(int fd, Elf
internalize_ehdr(elf->e_ident[EI_DATA], elf);
maxp += sizeof(Elf_Ehdr);
-#ifndef _STANDALONE
+#ifdef LIBSA_BIENDIAN_SUPPORT
for (i = 0; i < elf->e_shnum; i++)
internalize_shdr(elf->e_ident[EI_DATA], &shdr[i]);
#endif
@@ -472,7 +478,7 @@ ELFNAMEEND(loadfile_dynamic)(int fd, Elf
/*
* Finally, load the SECTION HEADERS.
*/
-#ifndef _STANDALONE
+#ifdef LIBSA_BIENDIAN_SUPPORT
for (i = 0; i < elf->e_shnum; i++)
externalize_shdr(elf->e_ident[EI_DATA], &shdr[i]);
#endif
@@ -526,7 +532,7 @@ ELFNAMEEND(loadsym)(int fd, Elf_Ehdr *el
shpp = maxp;
maxp += roundup(sz, ELFROUND);
-#ifndef _STANDALONE
+#ifdef LIBSA_BIENDIAN_SUPPORT
for (i = 0; i < elf->e_shnum; i++)
internalize_shdr(elf->e_ident[EI_DATA], &shp[i]);
#endif
@@ -636,7 +642,7 @@ havesym:
}
}
if (flags & LOAD_SYM) {
-#ifndef _STANDALONE
+#ifdef LIBSA_BIENDIAN_SUPPORT
for (i = 0; i < elf->e_shnum; i++)
externalize_shdr(elf->e_ident[EI_DATA], &shp[i]);
#endif