x86 boot: simplify reloc.c
PATCH 1/1 x86 boot: simplify reloc.c
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 ]
xen/arch/x86/boot/build32.mk +0 -25
@@ -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 $@
xen/arch/x86/boot/head.S +0 -3
@@ -195,9 +195,6 @@ #include "cmdline.S" -reloc: -#include "reloc.S" - .align 16 .globl trampoline_start, trampoline_end trampoline_start:
xen/arch/x86/boot/Makefile +1 -6
@@ -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
xen/arch/x86/boot/reloc.c +9 -31
@@ -9,43 +9,21 @@* Authors: * Keir Fraser <[email protected]> */ - -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)
Quoted 11 lines · Xiao Guangrong
This patch simplify
reloc.cwith:
1): no need separate make
reloc.c-> reloc.o -> reloc.lnk -> reloc.bin ->reloc.S, and static embedreloc.Sintohead.S
2): reusememcpy()in string lib
3): remove assemble code in the head ofreloc.c[ It is just a cleanup patch and not change the code's logic, and it work well on x86.
Not havex86_64machine in my hand, thanks very much if someone can test it
onx86_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
Quoted 9 lines · Keir Fraser
Quoted 7 lines · Xiao Guangrong
This patch simplify
reloc.cwith:
1): no need separate make
reloc.c-> reloc.o -> reloc.lnk -> reloc.bin ->reloc.S, and static embedreloc.Sintohead.S
2): reusememcpy()in string lib
3): remove assemble code in the head ofreloc.c
Quoted 9 lines
Quoted 4 lines
[ It is just a cleanup patch and not change the code's logic, and it work well on x86.
Not havex86_64machine in my hand, thanks very much if someone can test it
onx86_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