All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86 boot: simplify reloc.c
@ 2009-11-10  3:34 Xiao Guangrong
  2009-11-10  7:36 ` Keir Fraser
  0 siblings, 1 reply; 3+ messages in thread
From: Xiao Guangrong @ 2009-11-10  3:34 UTC (permalink / raw)
  To: Keir Fraser; +Cc: xen-devel, Xiao Guangrong

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@gmail.com>

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@citrix.com>
  */
-
-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)

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

* Re: [PATCH] x86 boot: simplify reloc.c
  2009-11-10  3:34 [PATCH] x86 boot: simplify reloc.c Xiao Guangrong
@ 2009-11-10  7:36 ` Keir Fraser
  2009-11-10  8:21   ` Xiao Guangrong
  0 siblings, 1 reply; 3+ messages in thread
From: Keir Fraser @ 2009-11-10  7:36 UTC (permalink / raw)
  To: Xiao Guangrong; +Cc: xen-devel, Xiao Guangrong

On 10/11/2009 03:34, "Xiao Guangrong" <xiaoguangrong@cn.fujitsu.com> wrote:

> 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 ]

The patch misses the point of reloc.c, which is that it is supposed to run
in 32-bit mode. All the stuff you stripped out is exactly what's needed to
make it work with 64-bit Xen.

 -- Keir

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

* Re: [PATCH] x86 boot: simplify reloc.c
  2009-11-10  7:36 ` Keir Fraser
@ 2009-11-10  8:21   ` Xiao Guangrong
  0 siblings, 0 replies; 3+ messages in thread
From: Xiao Guangrong @ 2009-11-10  8:21 UTC (permalink / raw)
  To: Keir Fraser; +Cc: xen-devel, Xiao Guangrong



Keir Fraser wrote:
> On 10/11/2009 03:34, "Xiao Guangrong" <xiaoguangrong@cn.fujitsu.com> wrote:
> 
>> 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 ]
> 
> The patch misses the point of reloc.c, which is that it is supposed to run
> in 32-bit mode. All the stuff you stripped out is exactly what's needed to
> make it work with 64-bit Xen.
> 

Ah, sorry for this noise, I'll do some work on x86-64 about this patch.

Thanks,
Xiao

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

end of thread, other threads:[~2009-11-10  8:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-10  3:34 [PATCH] x86 boot: simplify reloc.c Xiao Guangrong
2009-11-10  7:36 ` Keir Fraser
2009-11-10  8:21   ` Xiao Guangrong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.