Index: kernel/arch/amd64/include/byteorder.h
===================================================================
--- kernel/arch/amd64/include/byteorder.h	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/arch/amd64/include/byteorder.h	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -36,14 +36,6 @@
 #define KERN_amd64_BYTEORDER_H_
 
-#include <byteorder.h>
-
 /* AMD64 is little-endian */
-#define uint16_t_le2host(n)		(n)
-#define uint32_t_le2host(n)		(n)
-#define uint64_t_le2host(n)		(n)
-
-#define uint16_t_be2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_be2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_be2host(n)		uint64_t_byteorder_swap(n)
+#define ARCH_IS_LITTLE_ENDIAN
 
 #endif
Index: kernel/arch/arm32/include/byteorder.h
===================================================================
--- kernel/arch/arm32/include/byteorder.h	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/arch/arm32/include/byteorder.h	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -37,26 +37,8 @@
 #define KERN_arm32_BYTEORDER_H_
 
-#include <byteorder.h>
-
 #ifdef BIG_ENDIAN
-
-#define uint16_t_le2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_le2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_le2host(n)		uint64_t_byteorder_swap(n)
-
-#define uint16_t_be2host(n)		(n)
-#define uint32_t_be2host(n)		(n)
-#define uint64_t_be2host(n)		(n)
-
+#define ARCH_IS_BIG_ENDIAN
 #else
-
-#define uint16_t_le2host(n)		(n)
-#define uint32_t_le2host(n)		(n)
-#define uint64_t_le2host(n)		(n)
-
-#define uint16_t_be2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_be2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_be2host(n)		uint64_t_byteorder_swap(n)
-
+#define ARCH_IS_LITTLE_ENDIAN
 #endif
 
Index: kernel/arch/ia32/include/byteorder.h
===================================================================
--- kernel/arch/ia32/include/byteorder.h	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/arch/ia32/include/byteorder.h	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -36,14 +36,6 @@
 #define KERN_ia32_BYTEORDER_H_
 
-#include <byteorder.h>
-
 /* IA-32 is little-endian */
-#define uint16_t_le2host(n)		(n)
-#define uint32_t_le2host(n)		(n)
-#define uint64_t_le2host(n)		(n)
-
-#define uint16_t_be2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_be2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_be2host(n)		uint64_t_byteorder_swap(n)
+#define ARCH_IS_LITTLE_ENDIAN
 
 #endif
Index: kernel/arch/ia64/include/byteorder.h
===================================================================
--- kernel/arch/ia64/include/byteorder.h	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/arch/ia64/include/byteorder.h	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -36,14 +36,6 @@
 #define KERN_ia64_BYTEORDER_H_
 
-#include <byteorder.h>
-
 /* IA-64 is little-endian */
-#define uint16_t_le2host(n)		(n)
-#define uint32_t_le2host(n)		(n)
-#define uint64_t_le2host(n)		(n)
-
-#define uint16_t_be2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_be2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_be2host(n)		uint64_t_byteorder_swap(n)
+#define ARCH_IS_LITTLE_ENDIAN
 
 #endif
Index: kernel/arch/mips32/include/byteorder.h
===================================================================
--- kernel/arch/mips32/include/byteorder.h	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/arch/mips32/include/byteorder.h	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -36,26 +36,8 @@
 #define KERN_mips32_BYTEORDER_H_
 
-#include <byteorder.h>
-
 #ifdef BIG_ENDIAN
-
-#define uint16_t_le2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_le2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_le2host(n)		uint64_t_byteorder_swap(n)
-
-#define uint16_t_be2host(n)		(n)
-#define uint32_t_be2host(n)		(n)
-#define uint64_t_be2host(n)		(n)
-
+#define ARCH_IS_BIG_ENDIAN
 #else
-
-#define uint16_t_le2host(n)		(n)
-#define uint32_t_le2host(n)		(n)
-#define uint64_t_le2host(n)		(n)
-
-#define uint16_t_be2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_be2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_be2host(n)		uint64_t_byteorder_swap(n)
-
+#define ARCH_IS_LITTLE_ENDIAN
 #endif
 
Index: kernel/arch/mips32/src/drivers/arc.c
===================================================================
--- kernel/arch/mips32/src/drivers/arc.c	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/arch/mips32/src/drivers/arc.c	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -37,5 +37,5 @@
 #include <print.h>
 #include <arch.h>
-#include <arch/byteorder.h>
+#include <byteorder.h>
 #include <arch/mm/frame.h>
 #include <mm/frame.h>
Index: kernel/arch/ppc32/include/byteorder.h
===================================================================
--- kernel/arch/ppc32/include/byteorder.h	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/arch/ppc32/include/byteorder.h	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -36,13 +36,5 @@
 #define KERN_ppc32_BYTEORDER_H_
 
-#include <byteorder.h>
-
-#define uint16_t_le2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_le2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_le2host(n)		uint64_t_byteorder_swap(n)
-
-#define uint16_t_be2host(n)		(n)
-#define uint32_t_be2host(n)		(n)
-#define uint64_t_be2host(n)		(n)
+#define ARCH_IS_BIG_ENDIAN
 
 #endif
Index: kernel/arch/ppc64/include/byteorder.h
===================================================================
--- kernel/arch/ppc64/include/byteorder.h	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/arch/ppc64/include/byteorder.h	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -36,13 +36,5 @@
 #define KERN_ppc64_BYTEORDER_H_
 
-#include <byteorder.h>
-
-#define uint16_t_le2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_le2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_le2host(n)		uint64_t_byteorder_swap(n)
-
-#define uint16_t_be2host(n)		(n)
-#define uint32_t_be2host(n)		(n)
-#define uint64_t_be2host(n)		(n)
+#define ARCH_IS_BIG_ENDIAN
 
 #endif
Index: kernel/arch/sparc64/include/byteorder.h
===================================================================
--- kernel/arch/sparc64/include/byteorder.h	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/arch/sparc64/include/byteorder.h	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -36,13 +36,5 @@
 #define KERN_sparc64_BYTEORDER_H_
 
-#include <byteorder.h>
-
-#define uint16_t_le2host(n)		uint16_t_byteorder_swap(n)
-#define uint32_t_le2host(n)		uint32_t_byteorder_swap(n)
-#define uint64_t_le2host(n)		uint64_t_byteorder_swap(n)
-
-#define uint16_t_be2host(n)		(n)
-#define uint32_t_be2host(n)		(n)
-#define uint64_t_be2host(n)		(n)
+#define ARCH_IS_BIG_ENDIAN
 
 #endif
Index: kernel/generic/include/byteorder.h
===================================================================
--- kernel/generic/include/byteorder.h	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/generic/include/byteorder.h	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -36,4 +36,32 @@
 #define KERN_BYTEORDER_H_
 
+#include <arch/byteorder.h>
+
+#if !(defined(ARCH_IS_BIG_ENDIAN) ^ defined(ARCH_IS_LITTLE_ENDIAN))
+#error The architecture must be either big-endian or little-endian.
+#endif
+
+#ifdef ARCH_IS_BIG_ENDIAN
+
+#define uint16_t_le2host(n)		uint16_t_byteorder_swap(n)
+#define uint32_t_le2host(n)		uint32_t_byteorder_swap(n)
+#define uint64_t_le2host(n)		uint64_t_byteorder_swap(n)
+
+#define uint16_t_be2host(n)		(n)
+#define uint32_t_be2host(n)		(n)
+#define uint64_t_be2host(n)		(n)
+
+#else
+
+#define uint16_t_le2host(n)		(n)
+#define uint32_t_le2host(n)		(n)
+#define uint64_t_le2host(n)		(n)
+
+#define uint16_t_be2host(n)		uint16_t_byteorder_swap(n)
+#define uint32_t_be2host(n)		uint32_t_byteorder_swap(n)
+#define uint64_t_be2host(n)		uint64_t_byteorder_swap(n)
+
+#endif
+
 static inline uint64_t uint64_t_byteorder_swap(uint64_t n)
 {
Index: kernel/generic/src/debug/symtab.c
===================================================================
--- kernel/generic/src/debug/symtab.c	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/generic/src/debug/symtab.c	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -37,5 +37,5 @@
 
 #include <symtab.h>
-#include <arch/byteorder.h>
+#include <byteorder.h>
 #include <func.h>
 #include <print.h>
@@ -54,10 +54,10 @@
 	count_t i;
 
-	for (i=1;symbol_table[i].address_le;++i) {
+	for (i = 1; symbol_table[i].address_le; ++i) {
 		if (addr < uint64_t_le2host(symbol_table[i].address_le))
 			break;
 	}
-	if (addr >= uint64_t_le2host(symbol_table[i-1].address_le))
-		return symbol_table[i-1].symbol_name;
+	if (addr >= uint64_t_le2host(symbol_table[i - 1].address_le))
+		return symbol_table[i - 1].symbol_name;
 	return NULL;
 }
@@ -73,8 +73,8 @@
 	unsigned int namelen = strlen(name);
 	char *curname;
-	int i,j;
+	int i, j;
 	int colonoffset = -1;
 
-	for (i=0;name[i];i++)
+	for (i = 0; name[i]; i++)
 		if (name[i] == ':') {
 			colonoffset = i;
@@ -82,8 +82,8 @@
 		}
 
-	for (i=*startpos;symbol_table[i].address_le;++i) {
+	for (i = *startpos; symbol_table[i].address_le; ++i) {
 		/* Find a ':' in name */
 		curname = symbol_table[i].symbol_name;
-		for (j=0; curname[j] && curname[j] != ':'; j++)
+		for (j = 0; curname[j] && curname[j] != ':'; j++)
 			;
 		if (!curname[j])
@@ -95,5 +95,5 @@
 		if (strncmp(curname, name, namelen) == 0) {
 			*startpos = i;
-			return curname+namelen;
+			return curname + namelen;
 		}
 	}
@@ -116,5 +116,5 @@
 
 	i = 0;
-	while ((hint=symtab_search_one(name, &i))) {
+	while ((hint = symtab_search_one(name, &i))) {
 		if (!strlen(hint)) {
 			addr =  uint64_t_le2host(symbol_table[i].address_le);
@@ -152,5 +152,5 @@
 int symtab_compl(char *input)
 {
-	char output[MAX_SYMBOL_NAME+1];
+	char output[MAX_SYMBOL_NAME + 1];
 	int startpos = 0;
 	char *foundtxt;
@@ -173,7 +173,8 @@
 		startpos++;
 		if (!found)
-			strncpy(output, foundtxt, strlen(foundtxt)+1);
+			strncpy(output, foundtxt, strlen(foundtxt) + 1);
 		else {
-			for (i=0; output[i] && foundtxt[i] && output[i]==foundtxt[i]; i++)
+			for (i = 0; output[i] && foundtxt[i] &&
+			     output[i] == foundtxt[i]; i++)
 				;
 			output[i] = '\0';
Index: kernel/generic/src/lib/rd.c
===================================================================
--- kernel/generic/src/lib/rd.c	(revision dfa7bac346297f7790a17cd7dd459c2644aba6ef)
+++ kernel/generic/src/lib/rd.c	(revision 5d494b3f7a42392f3a69ba78ee3c67c3969e5041)
@@ -39,5 +39,5 @@
 
 #include <lib/rd.h>
-#include <arch/byteorder.h>
+#include <byteorder.h>
 #include <mm/frame.h>
 #include <sysinfo/sysinfo.h>
