From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Keir Fraser <keir.fraser@eu.citrix.com>
Cc: xen-devel <xen-devel@lists.xensource.com>,
Xiao Guangrong <ericxiao.gr@gmail.com>
Subject: [PATCH] x86 boot: simplify reloc.c
Date: Tue, 10 Nov 2009 11:34:53 +0800 [thread overview]
Message-ID: <4AF8DF5D.2090306@cn.fujitsu.com> (raw)
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)
next reply other threads:[~2009-11-10 3:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-10 3:34 Xiao Guangrong [this message]
2009-11-10 7:36 ` [PATCH] x86 boot: simplify reloc.c Keir Fraser
2009-11-10 8:21 ` Xiao Guangrong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AF8DF5D.2090306@cn.fujitsu.com \
--to=xiaoguangrong@cn.fujitsu.com \
--cc=ericxiao.gr@gmail.com \
--cc=keir.fraser@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.