WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] x86 boot: simplify reloc.c

To: Keir Fraser <keir.fraser@xxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] x86 boot: simplify reloc.c
From: Xiao Guangrong <xiaoguangrong@xxxxxxxxxxxxxx>
Date: Tue, 10 Nov 2009 11:34:53 +0800
Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, Xiao Guangrong <ericxiao.gr@xxxxxxxxx>
Delivery-date: Mon, 09 Nov 2009 19:36:39 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)
This patch simplify reloc.c with:
1): no need separate make
    reloc.c -> reloc.o -> reloc.lnk -> reloc.bin -> reloc.S,
    and static embed reloc.S into head.S
2): reuse memcpy() in string lib
3): remove assemble code in the head of reloc.c

[ It is just a cleanup patch and not change the code's logic, and it work well 
on x86.
  Not have x86_64 machine in my hand, thanks very much if someone can test it 
on x86_64 ]

Signed-off-by: Xiao Guangrong <ericxiao.gr@xxxxxxxxx>

diff -Nur a/xen/arch/x86/boot/build32.mk b/xen/arch/x86/boot/build32.mk
--- a/xen/arch/x86/boot/build32.mk      2009-08-06 21:57:27.000000000 +0800
+++ b/xen/arch/x86/boot/build32.mk      1970-01-01 08:00:00.000000000 +0800
@@ -1,25 +0,0 @@
-XEN_ROOT=../../../..
-override XEN_TARGET_ARCH=x86_32
-CFLAGS =
-include $(XEN_ROOT)/Config.mk
-
-# Disable PIE/SSP if GCC supports them. They can break us.
-$(call cc-option-add,CFLAGS,CC,-nopie)
-$(call cc-option-add,CFLAGS,CC,-fno-stack-protector)
-$(call cc-option-add,CFLAGS,CC,-fno-stack-protector-all)
-
-CFLAGS += -Werror -fno-builtin -msoft-float
-
-# NB. awk invocation is a portable alternative to 'head -n -1'
-%.S: %.bin
-       (od -v -t x $< | awk 'NR > 1 {print s} {s=$$0}' | \
-       sed 's/ /,0x/g' | sed 's/^[0-9]*,/ .long /') >$@
-
-%.bin: %.lnk
-       $(OBJCOPY) -O binary $< $@
-
-%.lnk: %.o
-       $(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x8c000 -o $@ $<
-
-%.o: %.c
-       $(CC) $(CFLAGS) -c $< -o $@
diff -Nur a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
--- a/xen/arch/x86/boot/head.S  2009-08-06 21:57:27.000000000 +0800
+++ b/xen/arch/x86/boot/head.S  2009-10-25 10:47:26.789003416 +0800
@@ -195,9 +195,6 @@
 
 #include "cmdline.S"
 
-reloc:
-#include "reloc.S"
-
         .align 16
         .globl trampoline_start, trampoline_end
 trampoline_start:
diff -Nur a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile
--- a/xen/arch/x86/boot/Makefile        2009-08-06 21:57:27.000000000 +0800
+++ b/xen/arch/x86/boot/Makefile        2009-10-25 10:49:50.029001088 +0800
@@ -1,7 +1,2 @@
 obj-y += head.o
-
-head.o: reloc.S
-
-# NB. BOOT_TRAMPOLINE == 0x8c000
-%.S: %.c
-       RELOC=0x8c000 $(MAKE) -f build32.mk $@
+obj-y += reloc.o
diff -Nur a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c
--- a/xen/arch/x86/boot/reloc.c 2009-08-06 21:57:27.000000000 +0800
+++ b/xen/arch/x86/boot/reloc.c 2009-10-25 11:22:26.233684714 +0800
@@ -9,43 +9,21 @@
  * Authors:
  *    Keir Fraser <keir.fraser@xxxxxxxxxx>
  */
-
-asm (
-    "    .text                         \n"
-    "    .globl _start                 \n"
-    "_start:                           \n"
-    "    mov  $_start,%edi             \n"
-    "    call 1f                       \n"
-    "1:  pop  %esi                     \n"
-    "    sub  $1b-_start,%esi          \n"
-    "    mov  $__bss_start-_start,%ecx \n"
-    "    rep  movsb                    \n"
-    "    xor  %eax,%eax                \n"
-    "    mov  $_end,%ecx               \n"
-    "    sub  %edi,%ecx                \n"
-    "    rep  stosb                    \n"
-    "    mov  $reloc,%eax              \n"
-    "    jmp  *%eax                    \n"
-    );
-
-typedef unsigned int u32;
+#include <asm/types.h>
+#include <xen/string.h>
+#include <asm/page.h>
 #include "../../../include/xen/multiboot.h"
 
-extern char _start[];
+#define sym_phys(sym) (unsigned long *)((unsigned long)(sym) - 
__XEN_VIRT_START)
 
-static void *memcpy(void *dest, const void *src, unsigned int n)
-{
-    char *s = (char *)src, *d = dest;
-    while ( n-- )
-        *d++ = *s++;
-    return dest;
-}
+static void *start = (void *)0x8c000;
 
 static void *reloc_mbi_struct(void *old, unsigned int bytes)
 {
-    static void *alloc = &_start;
-    alloc = (void *)(((unsigned long)alloc - bytes) & ~15ul);
-    return memcpy(alloc, old, bytes);
+    unsigned long alloc = *sym_phys(&start);
+    alloc = ((unsigned long)alloc - bytes) & ~15ul;
+    *sym_phys(&start) = alloc;
+    return memcpy((void *)alloc, old, bytes);
 }
 
 static char *reloc_mbi_string(char *old)




_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>