Skip to contentSkip to conversation

x86 boot cleanups

PATCH In review Brian Gerst 2 participants 7 messages Feb 26, 2011 – Feb 27, 2011 x86

lore
Share & tools
lore
#0 lore raw

cover x86 boot cleanups

Here are three small patches that merge 32 and 64 bit code in the boot code.

[PATCH 1/3] x86, boot: Use common ELF header defines [PATCH 2/3] x86, boot: Remove memptr
[PATCH 3/3] x86, boot: merge memcpy()

 arch/x86/boot/compressed/misc.c |   44 ++++++++------------------------------
 1 files changed, 10 insertions(+), 34 deletions(-)
#1 lore raw

PATCH 1/3 x86, boot: Use common ELF header defines

<linux/elf.h> defines elfhdr and elf_phdr appropriately for 32-bit and 64-bit.

---
 arch/x86/boot/compressed/misc.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)
arch/x86/boot/compressed/misc.c +2 -7
index 3a19d04..2d57c97 100644
@@ -275,13 +275,8 @@ static void error(char *x)
 
 static void parse_elf(void *output)
 {
-#ifdef CONFIG_X86_64
-	Elf64_Ehdr ehdr;
-	Elf64_Phdr *phdrs, *phdr;
-#else
-	Elf32_Ehdr ehdr;
-	Elf32_Phdr *phdrs, *phdr;
-#endif
+	struct elfhdr ehdr;
+	struct elf_phdr *phdrs, *phdr;
 	void *dest;
 	int i;
 
Signature · 1 line
1.7.4
#3 lore raw

PATCH 2/3 x86, boot: Remove memptr

In reply to Brian Gerst

Use unsigned long for free memory pointers for both 32-bit and 64-bit.

---
 arch/x86/boot/compressed/misc.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)
arch/x86/boot/compressed/misc.c +3 -9
index 2d57c97..c13b5e9 100644
@@ -114,14 +114,8 @@ static int debug;
 void *memset(void *s, int c, size_t n);
 void *memcpy(void *dest, const void *src, size_t n);
 
-#ifdef CONFIG_X86_64
-#define memptr long
-#else
-#define memptr unsigned
-#endif
-
-static memptr free_mem_ptr;
-static memptr free_mem_end_ptr;
+static unsigned long free_mem_ptr;
+static unsigned long free_mem_end_ptr;
 
 static char *vidmem;
 static int vidport;
@@ -318,7 +312,7 @@ static void parse_elf(void *output)
 	}
 }
 
-asmlinkage void decompress_kernel(void *rmode, memptr heap,
+asmlinkage void decompress_kernel(void *rmode, unsigned long heap,
 				  unsigned char *input_data,
 				  unsigned long input_len,
 				  unsigned char *output)
Signature · 1 line
1.7.4
#5 lore raw

PATCH 3/3 x86, boot: merge memcpy()

In reply to Brian Gerst

Merge the 32-bit and 64-bit memcpy functions.

---
 arch/x86/boot/compressed/misc.c |   23 +++++------------------
 1 files changed, 5 insertions(+), 18 deletions(-)
arch/x86/boot/compressed/misc.c +5 -18
index c13b5e9..704bec1 100644
@@ -10,6 +10,7 @@
  */
 
 #include "misc.h"
+#include <asm/asm.h>
 
 /* WARNING!!
  * This code is compiled with -fPIC and it is relocated dynamically
@@ -227,35 +228,21 @@ void *memset(void *s, int c, size_t n)
 		ss[i] = c;
 	return s;
 }
-#ifdef CONFIG_X86_32
-void *memcpy(void *dest, const void *src, size_t n)
-{
-	int d0, d1, d2;
-	asm volatile(
-		"rep ; movsl\n\t"
-		"movl %4,%%ecx\n\t"
-		"rep ; movsb\n\t"
-		: "=&c" (d0), "=&D" (d1), "=&S" (d2)
-		: "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src)
-		: "memory");
 
-	return dest;
-}
-#else
 void *memcpy(void *dest, const void *src, size_t n)
 {
 	long d0, d1, d2;
 	asm volatile(
-		"rep ; movsq\n\t"
-		"movq %4,%%rcx\n\t"
+		"rep ; " __ASM_SIZE(movs) "\n\t"
+		"mov %4,%0\n\t"
 		"rep ; movsb\n\t"
 		: "=&c" (d0), "=&D" (d1), "=&S" (d2)
-		: "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src)
+		: "0" (n / sizeof(long)), "g" (n & (sizeof(long) - 1)),
+		  "1" (dest), "2" (src)
 		: "memory");
 
 	return dest;
 }
-#endif
 
 static void error(char *x)
 {
Signature · 1 line
1.7.4