From: "Jan Beulich" Subject: [PATCH] x86: get rid of BOOT_TRAMPOLINE Date: Mon, 11 Jun 2012 09:41:46 +0100 Message-ID: <4FD5CB6A02000078000892D0@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part0729905A.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Paolo Bonzini List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part0729905A.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline We recently saw a machine that has the EBDA extending as low as 0x7c000, so that Xen fails to boot after relocating the trampoline. To fix this, I removed BOOT_TRAMPOLINE and bootsym_phys completely. Here are the parts: 1) the trampoline segment is set to 64k below the EBDA. head.S grows the ability to relocate the trampoline segment 2) reloc.c is made position-independent. It allocates data below the trampoline, whose address is passed in _eax. 3) cmdline.S is called before relocating, so all bootsym_phys there become sym_phys. Signed-off-by: Paolo Bonzini jb: - fall back to low memory size (instead of segment 0x7c00) if EBDA value is out of range - also add upper limit check on EBDA value - fix and simplify inline assembly operands in reloc_mbi_struct() - use lret instead of retf - renamed early_stack to wakeup_stack, defined and used now only in wakeup.S - aligned reloc.bin's end of .text to 16 bytes, so that checking __bss_start =3D=3D end works reliably Signed-off-by: Jan Beulich --- a/xen/arch/x86/boot/Makefile +++ b/xen/arch/x86/boot/Makefile @@ -2,8 +2,7 @@ obj-bin-y +=3D head.o =20 head.o: reloc.S =20 -BOOT_TRAMPOLINE :=3D $(shell sed -n 's,^\#define[[:space:]]\{1\,\}BOOT_TRA= MPOLINE[[:space:]]\{1\,\},,p' head.S) %.S: %.c - RELOC=3D$(BOOT_TRAMPOLINE) $(MAKE) -f build32.mk $@ + $(MAKE) -f build32.mk $@ =20 reloc.S: head.S --- a/xen/arch/x86/boot/build32.mk +++ b/xen/arch/x86/boot/build32.mk @@ -16,9 +16,10 @@ CFLAGS :=3D $(filter-out -flto,$(CFLAGS))=20 $(OBJCOPY) -O binary $< $@ =20 %.lnk: %.o - $(LD) $(LDFLAGS_DIRECT) -N -Ttext $(RELOC) -o $@ $< + $(LD) $(LDFLAGS_DIRECT) -N -Ttext 0 -o $@ $< =20 %.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) -c -fpic $< -o $@ =20 reloc.o: $(BASEDIR)/include/asm-x86/config.h +.PRECIOUS: %.bin %.lnk --- a/xen/arch/x86/boot/cmdline.S +++ b/xen/arch/x86/boot/cmdline.S @@ -164,13 +164,13 @@ cmdline_parse_early: pushl MB_cmdline(%ebx) call .Lfind_option test %eax,%eax - setnz bootsym_phys(skip_realmode) + setnz sym_phys(skip_realmode) =20 /* Check for 'tboot=3D' command-line option. */ movl $sym_phys(.Ltboot_opt),4(%esp) call .Lfind_option test %eax,%eax - setnz bootsym_phys(skip_realmode) /* tboot=3D implies no-real-mo= de */ + setnz sym_phys(skip_realmode) /* tboot=3D implies no-real-mode = */ =20 .Lparse_edd: /* Check for 'edd=3D' command-line option. */ @@ -181,13 +181,13 @@ cmdline_parse_early: cmpb $'=3D',3(%eax) jne .Lparse_edid add $4,%eax - movb $2,bootsym_phys(opt_edd) /* opt_edd=3D2: edd=3Doff */ + movb $2,sym_phys(opt_edd) /* opt_edd=3D2: edd=3Doff */ cmpw $0x666f,(%eax) /* 0x666f =3D=3D "of" */ je .Lparse_edid - decb bootsym_phys(opt_edd) /* opt_edd=3D1: edd=3Dskipmbr = */ + decb sym_phys(opt_edd) /* opt_edd=3D1: edd=3Dskipmbr */ cmpw $0x6b73,(%eax) /* 0x6b73 =3D=3D "sk" */ je .Lparse_edid - decb bootsym_phys(opt_edd) /* opt_edd=3D0: edd=3Don = (default) */ + decb sym_phys(opt_edd) /* opt_edd=3D0: edd=3Don (default) = */ =20 .Lparse_edid: /* Check for 'edid=3D' command-line option. */ @@ -203,17 +203,17 @@ cmdline_parse_early: pushl $sym_phys(.Ledid_force) call .Lstr_prefix add $8,%esp - movb $2,bootsym_phys(opt_edid) /* opt_edid=3D2: edid=3Dforce = */ + movb $2,sym_phys(opt_edid) /* opt_edid=3D2: edid=3Dforce */ test %eax,%eax jz .Lparse_vga push %ebx pushl $sym_phys(.Ledid_no) call .Lstr_prefix add $8,%esp - decb bootsym_phys(opt_edid) /* opt_edid=3D1: edid=3Dno */ + decb sym_phys(opt_edid) /* opt_edid=3D1: edid=3Dno */ test %eax,%eax jz .Lparse_vga - decb bootsym_phys(opt_edid) /* opt_edid=3D0: default */ + decb sym_phys(opt_edid) /* opt_edid=3D0: default */ =20 .Lparse_vga: /* Check for 'vga=3D' command-line option. */ @@ -227,7 +227,7 @@ cmdline_parse_early: add $4,%eax =20 /* Found the 'vga=3D' option. Default option is to display vga = menu. */ - movw $ASK_VGA,bootsym_phys(boot_vid_mode) + movw $ASK_VGA,sym_phys(boot_vid_mode) =20 /* Check for 'vga=3Dtext-80x. */ mov %eax,%ebx @@ -251,7 +251,7 @@ cmdline_parse_early: cmp %ax,%bx lodsw jne 1b - mov %ax,bootsym_phys(boot_vid_mode) + mov %ax,sym_phys(boot_vid_mode) jmp .Lcmdline_exit =20 .Lparse_vga_gfx: @@ -270,7 +270,7 @@ cmdline_parse_early: push %ebx call .Latoi pop %esi - mov %ax,bootsym_phys(vesa_size)+0 + mov %ax,sym_phys(vesa_size)+0 /* skip 'x' */ lodsb cmpb $'x',%al @@ -279,7 +279,7 @@ cmdline_parse_early: push %esi call .Latoi pop %esi - mov %ax,bootsym_phys(vesa_size)+2 + mov %ax,sym_phys(vesa_size)+2 /* skip 'x' */ lodsb cmpb $'x',%al @@ -288,9 +288,9 @@ cmdline_parse_early: push %esi call .Latoi pop %esi - mov %ax,bootsym_phys(vesa_size)+4 + mov %ax,sym_phys(vesa_size)+4 /* commit to vesa mode */ - movw $VIDEO_VESA_BY_SIZE,bootsym_phys(boot_vid_mode) + movw $VIDEO_VESA_BY_SIZE,sym_phys(boot_vid_mode) jmp .Lcmdline_exit =20 .Lparse_vga_mode: @@ -307,7 +307,7 @@ cmdline_parse_early: push %ebx call .Latoi add $4,%esp - mov %ax,bootsym_phys(boot_vid_mode) + mov %ax,sym_phys(boot_vid_mode) jmp .Lcmdline_exit =20 .Lparse_vga_current: @@ -320,7 +320,7 @@ cmdline_parse_early: jnz .Lcmdline_exit =20 /* We have 'vga=3Dcurrent'. */ - movw $VIDEO_CURRENT_MODE,bootsym_phys(boot_vid_mode) + movw $VIDEO_CURRENT_MODE,sym_phys(boot_vid_mode) =20 .Lcmdline_exit: popa --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -9,9 +9,7 @@ .text .code32 =20 -#define BOOT_TRAMPOLINE 0x7c000 #define sym_phys(sym) ((sym) - __XEN_VIRT_START) -#define bootsym_phys(sym) ((sym) - trampoline_start + BOOT_TRAMPOLINE) =20 #define BOOT_CS32 0x0008 #define BOOT_CS64 0x0010 @@ -79,6 +77,23 @@ __start: cmp $0x2BADB002,%eax jne not_multiboot =20 + /* Set up trampoline segment 64k below EBDA */ + movzwl 0x40e,%eax /* EBDA segment */ + cmp $0xa000,%eax /* sanity check (high) */ + jae 0f + cmp $0x4000,%eax /* sanity check (low) */ + jae 1f +0: + movzwl 0x413,%eax /* use base memory size on failure */ + shl $10-4,%eax +1: + sub $0x1000,%eax + + /* From arch/x86/smpboot.c: start_eip had better be page-aligned! = */ + xor %al, %al + shl $4, %eax + mov %eax,sym_phys(trampoline_phys) + /* Save the Multiboot info struct (after relocation) for later = use. */ mov $sym_phys(cpu0_stack)+1024,%esp push %ebx @@ -190,7 +205,7 @@ __start: #endif =20 /* Apply relocations to bootstrap trampoline. */ - mov $BOOT_TRAMPOLINE,%edx + mov sym_phys(trampoline_phys),%edx mov $sym_phys(__trampoline_rel_start),%edi mov %edx,sym_phys(trampoline_phys) 1: @@ -200,22 +215,35 @@ __start: cmp $sym_phys(__trampoline_rel_stop),%edi jb 1b =20 + /* Patch in the trampoline segment. */ + shr $4,%edx + mov $sym_phys(__trampoline_seg_start),%edi +1: + mov (%edi),%eax + mov %dx,(%edi,%eax) + add $4,%edi + cmp $sym_phys(__trampoline_seg_stop),%edi + jb 1b + + call cmdline_parse_early + + /* Switch to low-memory stack. */ + mov sym_phys(trampoline_phys),%edi + lea 0x10000(%edi),%esp + lea trampoline_boot_cpu_entry-trampoline_start(%edi),%eax + pushl $BOOT_CS32 + push %eax + /* Copy bootstrap trampoline to low memory, below 1MB. */ mov $sym_phys(trampoline_start),%esi - mov %edx,%edi mov $trampoline_end - trampoline_start,%ecx rep movsb =20 - lea early_stack-trampoline_start(%edx),%esp - call cmdline_parse_early - /* Jump into the relocated trampoline. */ - jmp $BOOT_CS32,$bootsym_phys(trampoline_boot_cpu_entry) + lret =20 #include "cmdline.S" =20 -#undef bootsym_phys - reloc: #include "reloc.S" =20 --- a/xen/arch/x86/boot/reloc.c +++ b/xen/arch/x86/boot/reloc.c @@ -10,42 +10,49 @@ * Keir Fraser */ =20 +/* entered with %eax =3D BOOT_TRAMPOLINE */ 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" + "1: pop %ebx \n" + " mov %eax,alloc-1b(%ebx) \n" + " mov $_end,%ecx \n" /* check that BSS is empty! = */ + " sub $__bss_start,%ecx \n" + " jz reloc \n" + "1: jmp 1b \n" + ); + +/* This is our data. Because the code must be relocatable, no BSS is + * allowed. All data is accessed PC-relative with inline assembly. + */ +asm ( + "alloc: \n" + " .long 0 \n" + " .subsection 1 \n" + " .p2align 4, 0xcc \n" + " .subsection 0 \n" ); =20 typedef unsigned int u32; #include "../../../include/xen/multiboot.h" =20 -extern char _start[]; - -static void *memcpy(void *dest, const void *src, unsigned int n) -{ - char *s =3D (char *)src, *d =3D dest; - while ( n-- ) - *d++ =3D *s++; - return dest; -} - static void *reloc_mbi_struct(void *old, unsigned int bytes) { - static void *alloc =3D &_start; - alloc =3D (void *)(((unsigned long)alloc - bytes) & ~15ul); - return memcpy(alloc, old, bytes); + void *new; + asm( + " call 1f \n" + "1: pop %%edx \n" + " mov alloc-1b(%%edx),%0 \n" + " sub %1,%0 \n" + " and $~15,%0 \n" + " mov %0,alloc-1b(%%edx) \n" + " mov %0,%%edi \n" + " rep movsb \n" + : "=3D&r" (new), "+c" (bytes), "+S" (old) + : : "edx", "edi"); + return new; } =20 static char *reloc_mbi_string(char *old) --- a/xen/arch/x86/boot/trampoline.S +++ b/xen/arch/x86/boot/trampoline.S @@ -11,6 +11,13 @@ .long 111b - (off) - .; \ .popsection =20 +#define bootsym_segrel(sym, off) \ + $0,$bootsym(sym); \ +111:; \ + .pushsection .trampoline_seg, "a"; \ + .long 111b - (off) - .; \ + .popsection + .globl trampoline_realmode_entry trampoline_realmode_entry: mov %cs,%ax @@ -151,14 +158,14 @@ trampoline_boot_cpu_entry: 1: mov %eax,%cr0 # CR0.PE =3D 0 (leave protected = mode) =20 /* Load proper real-mode values into %cs, %ds, %es and %ss. */ - ljmp $(BOOT_TRAMPOLINE>>4),$bootsym(1f) + ljmp bootsym_segrel(1f,2) 1: mov %cs,%ax mov %ax,%ds mov %ax,%es mov %ax,%ss =20 /* Initialise stack pointer and IDT, and enable irqs. */ - mov $bootsym(early_stack),%sp + xor %sp,%sp lidt bootsym(rm_idt) sti =20 @@ -220,7 +227,3 @@ rm_idt: .word 256*4-1, 0, 0 #include "edd.S" #include "video.S" #include "wakeup.S" - - .align 16 - .fill PAGE_SIZE,1,0 -early_stack: --- a/xen/arch/x86/boot/wakeup.S +++ b/xen/arch/x86/boot/wakeup.S @@ -11,7 +11,7 @@ ENTRY(wakeup_start) movw %cs, %ax movw %ax, %ds movw %ax, %ss # A stack required for BIOS call - movw $wakesym(early_stack), %sp + movw $wakesym(wakeup_stack), %sp =20 pushl $0 # Kill dangerous flag early popfl @@ -101,7 +101,7 @@ real_magic: .long 0x12345678 .globl video_mode, video_flags video_mode: .long 0 video_flags: .long 0 -trampoline_seg: .word BOOT_TRAMPOLINE >> 4 +trampoline_seg: .word 0 .pushsection .trampoline_seg, "a" .long trampoline_seg - . .popsection @@ -116,7 +116,7 @@ wakeup_32: mov $BOOT_DS, %eax mov %eax, %ds mov %eax, %ss - mov $bootsym_rel(early_stack, 4, %esp) + mov $bootsym_rel(wakeup_stack, 4, %esp) =20 # check saved magic again mov $sym_phys(saved_magic), %eax @@ -188,3 +188,7 @@ ret_point: bogus_saved_magic: movw $0x0e00 + 'S', 0xb8014 jmp bogus_saved_magic + + .align 16 + .fill PAGE_SIZE,1,0 +wakeup_stack: --=__Part0729905A.0__= Content-Type: text/plain; name="x86-boot-trampoline-remove.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-boot-trampoline-remove.patch" x86: get rid of BOOT_TRAMPOLINE=0A=0AWe recently saw a machine that has = the EBDA extending as low as 0x7c000,=0Aso that Xen fails to boot after = relocating the trampoline. To fix this,=0AI removed BOOT_TRAMPOLINE and = bootsym_phys completely.=0A=0AHere are the parts:=0A=0A1) the trampoline = segment is set to 64k below the EBDA. head.S grows=0Athe ability to = relocate the trampoline segment=0A=0A2) reloc.c is made position-independen= t. It allocates data below the=0Atrampoline, whose address is passed in = _eax.=0A=0A3) cmdline.S is called before relocating, so all bootsym_phys = there=0Abecome sym_phys.=0A=0ASigned-off-by: Paolo Bonzini =0A=0Ajb: - fall back to low memory size (instead of segment 0x7c00) = if EBDA=0A value is out of range=0A - also add upper limit check = on EBDA value=0A - fix and simplify inline assembly operands in = reloc_mbi_struct()=0A - use lret instead of retf=0A - renamed = early_stack to wakeup_stack, defined and used now only=0A in = wakeup.S=0A - aligned reloc.bin's end of .text to 16 bytes, so that = checking=0A __bss_start =3D=3D end works reliably=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- a/xen/arch/x86/boot/Makefile=0A+++= b/xen/arch/x86/boot/Makefile=0A@@ -2,8 +2,7 @@ obj-bin-y +=3D head.o=0A = =0A head.o: reloc.S=0A =0A-BOOT_TRAMPOLINE :=3D $(shell sed -n 's,^\#define= [[:space:]]\{1\,\}BOOT_TRAMPOLINE[[:space:]]\{1\,\},,p' head.S)=0A %.S: = %.c=0A- RELOC=3D$(BOOT_TRAMPOLINE) $(MAKE) -f build32.mk $@=0A+ $(MAKE) -f = build32.mk $@=0A =0A reloc.S: head.S=0A--- a/xen/arch/x86/boot/build32.mk= =0A+++ b/xen/arch/x86/boot/build32.mk=0A@@ -16,9 +16,10 @@ CFLAGS :=3D = $(filter-out -flto,$(CFLAGS)) =0A $(OBJCOPY) -O binary $< $@=0A =0A = %.lnk: %.o=0A- $(LD) $(LDFLAGS_DIRECT) -N -Ttext $(RELOC) -o $@ $<=0A+ = $(LD) $(LDFLAGS_DIRECT) -N -Ttext 0 -o $@ $<=0A =0A %.o: %.c=0A- = $(CC) $(CFLAGS) -c $< -o $@=0A+ $(CC) $(CFLAGS) -c -fpic $< -o $@=0A =0A = reloc.o: $(BASEDIR)/include/asm-x86/config.h=0A+.PRECIOUS: %.bin %.lnk=0A--= - a/xen/arch/x86/boot/cmdline.S=0A+++ b/xen/arch/x86/boot/cmdline.S=0A@@ = -164,13 +164,13 @@ cmdline_parse_early:=0A pushl MB_cmdline(%ebx)= =0A call .Lfind_option=0A test %eax,%eax=0A- = setnz bootsym_phys(skip_realmode)=0A+ setnz sym_phys(skip_realmo= de)=0A =0A /* Check for 'tboot=3D' command-line option. */=0A = movl $sym_phys(.Ltboot_opt),4(%esp)=0A call .Lfind_option= =0A test %eax,%eax=0A- setnz bootsym_phys(skip_realmode= ) /* tboot=3D implies no-real-mode */=0A+ setnz sym_phys(skip_real= mode) /* tboot=3D implies no-real-mode */=0A =0A .Lparse_edd:=0A = /* Check for 'edd=3D' command-line option. */=0A@@ -181,13 +181,13 @@ = cmdline_parse_early:=0A cmpb $'=3D',3(%eax)=0A jne = .Lparse_edid=0A add $4,%eax=0A- movb $2,bootsym_phys(= opt_edd) /* opt_edd=3D2: edd=3Doff */=0A+ movb $2,sym_phys(opt_e= dd) /* opt_edd=3D2: edd=3Doff */=0A cmpw $0x666f,(%eax) = /* 0x666f =3D=3D "of" */=0A je .Lparse_edid=0A- = decb bootsym_phys(opt_edd) /* opt_edd=3D1: edd=3Dskipmbr */=0A+ = decb sym_phys(opt_edd) /* opt_edd=3D1: edd=3Dskipmbr */=0A = cmpw $0x6b73,(%eax) /* 0x6b73 =3D=3D "sk" */=0A je = .Lparse_edid=0A- decb bootsym_phys(opt_edd) /* = opt_edd=3D0: edd=3Don (default) */=0A+ decb sym_phys(opt_edd) = /* opt_edd=3D0: edd=3Don (default) */=0A =0A .Lparse_edid:=0A /* = Check for 'edid=3D' command-line option. */=0A@@ -203,17 +203,17 @@ = cmdline_parse_early:=0A pushl $sym_phys(.Ledid_force)=0A = call .Lstr_prefix=0A add $8,%esp=0A- movb = $2,bootsym_phys(opt_edid) /* opt_edid=3D2: edid=3Dforce */=0A+ movb = $2,sym_phys(opt_edid) /* opt_edid=3D2: edid=3Dforce */=0A test = %eax,%eax=0A jz .Lparse_vga=0A push %ebx=0A = pushl $sym_phys(.Ledid_no)=0A call .Lstr_prefix=0A = add $8,%esp=0A- decb bootsym_phys(opt_edid) /* opt_edid=3D= 1: edid=3Dno */=0A+ decb sym_phys(opt_edid) /* opt_edid=3D1: = edid=3Dno */=0A test %eax,%eax=0A jz .Lparse_vga=0A= - decb bootsym_phys(opt_edid) /* opt_edid=3D0: default */=0A+ = decb sym_phys(opt_edid) /* opt_edid=3D0: default */=0A =0A = .Lparse_vga:=0A /* Check for 'vga=3D' command-line option. */=0A@@ = -227,7 +227,7 @@ cmdline_parse_early:=0A add $4,%eax=0A =0A = /* Found the 'vga=3D' option. Default option is to display vga menu. = */=0A- movw $ASK_VGA,bootsym_phys(boot_vid_mode)=0A+ movw = $ASK_VGA,sym_phys(boot_vid_mode)=0A =0A /* Check for 'vga=3Dtext= -80x. */=0A mov %eax,%ebx=0A@@ -251,7 +251,7 @@ = cmdline_parse_early:=0A cmp %ax,%bx=0A lodsw=0A = jne 1b=0A- mov %ax,bootsym_phys(boot_vid_mode)=0A+ = mov %ax,sym_phys(boot_vid_mode)=0A jmp .Lcmdline_exit=0A = =0A .Lparse_vga_gfx:=0A@@ -270,7 +270,7 @@ cmdline_parse_early:=0A = push %ebx=0A call .Latoi=0A pop %esi=0A- = mov %ax,bootsym_phys(vesa_size)+0=0A+ mov %ax,sym_phys(vesa_= size)+0=0A /* skip 'x' */=0A lodsb=0A cmpb = $'x',%al=0A@@ -279,7 +279,7 @@ cmdline_parse_early:=0A push = %esi=0A call .Latoi=0A pop %esi=0A- mov = %ax,bootsym_phys(vesa_size)+2=0A+ mov %ax,sym_phys(vesa_size)+2= =0A /* skip 'x' */=0A lodsb=0A cmpb $'x',%al=0A@= @ -288,9 +288,9 @@ cmdline_parse_early:=0A push %esi=0A = call .Latoi=0A pop %esi=0A- mov %ax,bootsym_phys(= vesa_size)+4=0A+ mov %ax,sym_phys(vesa_size)+4=0A /* = commit to vesa mode */=0A- movw $VIDEO_VESA_BY_SIZE,bootsym_phys(= boot_vid_mode)=0A+ movw $VIDEO_VESA_BY_SIZE,sym_phys(boot_vid_mod= e)=0A jmp .Lcmdline_exit=0A =0A .Lparse_vga_mode:=0A@@ -307,7 = +307,7 @@ cmdline_parse_early:=0A push %ebx=0A call = .Latoi=0A add $4,%esp=0A- mov %ax,bootsym_phys(boot_= vid_mode)=0A+ mov %ax,sym_phys(boot_vid_mode)=0A jmp = .Lcmdline_exit=0A =0A .Lparse_vga_current:=0A@@ -320,7 +320,7 @@ = cmdline_parse_early:=0A jnz .Lcmdline_exit=0A =0A /* = We have 'vga=3Dcurrent'. */=0A- movw $VIDEO_CURRENT_MODE,bootsym_= phys(boot_vid_mode)=0A+ movw $VIDEO_CURRENT_MODE,sym_phys(boot_vi= d_mode)=0A =0A .Lcmdline_exit:=0A popa=0A--- a/xen/arch/x86/boot/he= ad.S=0A+++ b/xen/arch/x86/boot/head.S=0A@@ -9,9 +9,7 @@=0A = .text=0A .code32=0A =0A-#define BOOT_TRAMPOLINE 0x7c000=0A = #define sym_phys(sym) ((sym) - __XEN_VIRT_START)=0A-#define bootsym_phy= s(sym) ((sym) - trampoline_start + BOOT_TRAMPOLINE)=0A =0A #define = BOOT_CS32 0x0008=0A #define BOOT_CS64 0x0010=0A@@ -79,6 = +77,23 @@ __start:=0A cmp $0x2BADB002,%eax=0A jne = not_multiboot=0A =0A+ /* Set up trampoline segment 64k below EBDA = */=0A+ movzwl 0x40e,%eax /* EBDA segment */=0A+ = cmp $0xa000,%eax /* sanity check (high) */=0A+ jae = 0f=0A+ cmp $0x4000,%eax /* sanity check (low) */=0A+ = jae 1f=0A+0:=0A+ movzwl 0x413,%eax /* use base = memory size on failure */=0A+ shl $10-4,%eax=0A+1:=0A+ = sub $0x1000,%eax=0A+=0A+ /* From arch/x86/smpboot.c: start_eip = had better be page-aligned! */=0A+ xor %al, %al=0A+ shl = $4, %eax=0A+ mov %eax,sym_phys(trampoline_phys)=0A+=0A = /* Save the Multiboot info struct (after relocation) for later use. = */=0A mov $sym_phys(cpu0_stack)+1024,%esp=0A push = %ebx=0A@@ -190,7 +205,7 @@ __start:=0A #endif=0A =0A /* Apply = relocations to bootstrap trampoline. */=0A- mov $BOOT_TRAMPOLINE= ,%edx=0A+ mov sym_phys(trampoline_phys),%edx=0A mov = $sym_phys(__trampoline_rel_start),%edi=0A mov %edx,sym_phys(tra= mpoline_phys)=0A 1:=0A@@ -200,22 +215,35 @@ __start:=0A cmp = $sym_phys(__trampoline_rel_stop),%edi=0A jb 1b=0A =0A+ = /* Patch in the trampoline segment. */=0A+ shr $4,%edx=0A+ = mov $sym_phys(__trampoline_seg_start),%edi=0A+1:=0A+ mov = (%edi),%eax=0A+ mov %dx,(%edi,%eax)=0A+ add = $4,%edi=0A+ cmp $sym_phys(__trampoline_seg_stop),%edi=0A+ = jb 1b=0A+=0A+ call cmdline_parse_early=0A+=0A+ /* = Switch to low-memory stack. */=0A+ mov sym_phys(trampoline_phys= ),%edi=0A+ lea 0x10000(%edi),%esp=0A+ lea trampoline_= boot_cpu_entry-trampoline_start(%edi),%eax=0A+ pushl $BOOT_CS32=0A= + push %eax=0A+=0A /* Copy bootstrap trampoline to low = memory, below 1MB. */=0A mov $sym_phys(trampoline_start),%esi= =0A- mov %edx,%edi=0A mov $trampoline_end - = trampoline_start,%ecx=0A rep movsb=0A =0A- lea = early_stack-trampoline_start(%edx),%esp=0A- call cmdline_parse_ea= rly=0A-=0A /* Jump into the relocated trampoline. */=0A- = jmp $BOOT_CS32,$bootsym_phys(trampoline_boot_cpu_entry)=0A+ = lret=0A =0A #include "cmdline.S"=0A =0A-#undef bootsym_phys=0A-=0A = reloc:=0A #include "reloc.S"=0A =0A--- a/xen/arch/x86/boot/reloc.c=0A+++ = b/xen/arch/x86/boot/reloc.c=0A@@ -10,42 +10,49 @@=0A * Keir Fraser = =0A */=0A =0A+/* entered with %eax =3D BOOT_TRAMPOLINE = */=0A asm (=0A " .text \n"=0A " = .globl _start \n"=0A "_start: = \n"=0A- " mov $_start,%edi \n"=0A " call 1f = \n"=0A- "1: pop %esi \n"=0A- = " sub $1b-_start,%esi \n"=0A- " mov $__bss_start-_start= ,%ecx \n"=0A- " rep movsb \n"=0A- " xor = %eax,%eax \n"=0A- " mov $_end,%ecx = \n"=0A- " sub %edi,%ecx \n"=0A- " rep stosb = \n"=0A- " mov $reloc,%eax \n"=0A- = " jmp *%eax \n"=0A+ "1: pop %ebx = \n"=0A+ " mov %eax,alloc-1b(%ebx) \n"=0A+ " mov = $_end,%ecx \n" /* check that BSS is empty! */=0A+ " = sub $__bss_start,%ecx \n"=0A+ " jz reloc = \n"=0A+ "1: jmp 1b \n"=0A+ );=0A+=0A+/* = This is our data. Because the code must be relocatable, no BSS is=0A+ * = allowed. All data is accessed PC-relative with inline assembly.=0A+ = */=0A+asm (=0A+ "alloc: \n"=0A+ " = .long 0 \n"=0A+ " .subsection 1 = \n"=0A+ " .p2align 4, 0xcc \n"=0A+ " .subsection = 0 \n"=0A );=0A =0A typedef unsigned int u32;=0A = #include "../../../include/xen/multiboot.h"=0A =0A-extern char _start[];=0A= -=0A-static void *memcpy(void *dest, const void *src, unsigned int = n)=0A-{=0A- char *s =3D (char *)src, *d =3D dest;=0A- while ( n-- = )=0A- *d++ =3D *s++;=0A- return dest;=0A-}=0A-=0A static void = *reloc_mbi_struct(void *old, unsigned int bytes)=0A {=0A- static void = *alloc =3D &_start;=0A- alloc =3D (void *)(((unsigned long)alloc - = bytes) & ~15ul);=0A- return memcpy(alloc, old, bytes);=0A+ void = *new;=0A+ asm(=0A+ " call 1f \n"=0A+ "1: = pop %%edx \n"=0A+ " mov alloc-1b(%%edx),%0 = \n"=0A+ " sub %1,%0 \n"=0A+ " and $~15,%0 = \n"=0A+ " mov %0,alloc-1b(%%edx) \n"=0A+ " = mov %0,%%edi \n"=0A+ " rep movsb = \n"=0A+ : "=3D&r" (new), "+c" (bytes), "+S" (old)=0A+ : : "edx", = "edi");=0A+ return new;=0A }=0A =0A static char *reloc_mbi_string(char = *old)=0A--- a/xen/arch/x86/boot/trampoline.S=0A+++ b/xen/arch/x86/boot/tram= poline.S=0A@@ -11,6 +11,13 @@=0A .long 111b - (off) - .; = \=0A .popsection=0A =0A+#define bootsym_segrel(sym, off) = \=0A+ $0,$bootsym(sym); \=0A+111:; = \=0A+ .pushsection .trampoline_seg, "a"; = \=0A+ .long 111b - (off) - .; \=0A+ .popsection=0A= +=0A .globl trampoline_realmode_entry=0A trampoline_realmode_entry:= =0A mov %cs,%ax=0A@@ -151,14 +158,14 @@ trampoline_boot_cpu_ent= ry:=0A 1: mov %eax,%cr0 # CR0.PE =3D 0 (leave = protected mode)=0A =0A /* Load proper real-mode values into %cs, = %ds, %es and %ss. */=0A- ljmp $(BOOT_TRAMPOLINE>>4),$bootsym(1f)= =0A+ ljmp bootsym_segrel(1f,2)=0A 1: mov %cs,%ax=0A = mov %ax,%ds=0A mov %ax,%es=0A mov = %ax,%ss=0A =0A /* Initialise stack pointer and IDT, and enable = irqs. */=0A- mov $bootsym(early_stack),%sp=0A+ xor = %sp,%sp=0A lidt bootsym(rm_idt)=0A sti=0A =0A@@ -220,7 = +227,3 @@ rm_idt: .word 256*4-1, 0, 0=0A #include "edd.S"=0A #include = "video.S"=0A #include "wakeup.S"=0A-=0A- .align 16=0A- = .fill PAGE_SIZE,1,0=0A-early_stack:=0A--- a/xen/arch/x86/boot/wakeup.S=0A= +++ b/xen/arch/x86/boot/wakeup.S=0A@@ -11,7 +11,7 @@ ENTRY(wakeup_start)=0A= movw %cs, %ax=0A movw %ax, %ds=0A movw = %ax, %ss # A stack required for BIOS call=0A- movw = $wakesym(early_stack), %sp=0A+ movw $wakesym(wakeup_stack), = %sp=0A =0A pushl $0 # Kill dangerous flag early=0A = popfl=0A@@ -101,7 +101,7 @@ real_magic: .long 0x12345678=0A = .globl video_mode, video_flags=0A video_mode: .long 0=0A = video_flags: .long 0=0A-trampoline_seg: .word BOOT_TRAMPOLINE >> = 4=0A+trampoline_seg: .word 0=0A .pushsection .trampoline_seg, = "a"=0A .long trampoline_seg - .=0A .popsection=0A@@ = -116,7 +116,7 @@ wakeup_32:=0A mov $BOOT_DS, %eax=0A = mov %eax, %ds=0A mov %eax, %ss=0A- mov = $bootsym_rel(early_stack, 4, %esp)=0A+ mov $bootsym_rel(wakeup_s= tack, 4, %esp)=0A =0A # check saved magic again=0A mov = $sym_phys(saved_magic), %eax=0A@@ -188,3 +188,7 @@ ret_point:=0A bogus_save= d_magic:=0A movw $0x0e00 + 'S', 0xb8014=0A jmp = bogus_saved_magic=0A+=0A+ .align 16=0A+ .fill PAGE_SIZE,1,= 0=0A+wakeup_stack:=0A --=__Part0729905A.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part0729905A.0__=--