Skip to contentSkip to conversation

x86: multiboot2 protocol support

PATCH Superseded Daniel Kiper 5 participants 199 messages Jul 20, 2015 – Sep 23, 2015 Page 1 of 2

v2 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v2 cover x86: multiboot2 protocol support

Hi,

I am sending, long awaited, second version of multiboot2 protocol support for legacy BIOS and EFI platforms. It fixes all major issues discovered until now. There are still some minor problems which should be fixed in one way or another. I will address them in next releases.

This series, in general, is not targeted to Xen 4.6. However, there are some fixes at the beginning of it which are worth considering, I think.

The final goal is xen.efi binary file which could be loaded by EFI loader, multiboot (v1) protocol (only on legacy BIOS platforms) and multiboot2 protocol. This way we will have:
- smaller Xen code base,
- one code base for xen.gz and xen.efi,
- one build method for xen.gz and xen.efi;
xen.efi will be extracted from xen file
using objcopy; PE header will be contained
in ELF file and will precede Xen code,
- xen.efi build will not so strongly depend
on a given GCC and binutils version.

ARM guys should check at least patches #9 - #18 and #20. In general earlier mentioned patches touches common EFI code but they are not change functionality significantly.

GRUB2 patch series will follow this patch series.

GRUB2 guys should check patches #20 and #23 but I am sending to you all Xen related patches just in case.

If you are not interested in this patch series at all please drop me a line and I will remove you from distribution list.

Daniel

 .gitignore                        |    5 +-
 xen/arch/x86/Makefile             |   21 ++--
 xen/arch/x86/Rules.mk             |    4 +
 xen/arch/x86/boot/Makefile        |   10 +-
 xen/arch/x86/boot/build32.mk      |    4 +-
 xen/arch/x86/boot/cmdline.S       |  367 ---------------------------------------------------------------
 xen/arch/x86/boot/cmdline.c       |  396 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/boot/edd.S           |    3 -
 xen/arch/x86/boot/head.S          |  474 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
 xen/arch/x86/boot/reloc.c         |  242 +++++++++++++++++++++++++++++++++++-------
 xen/arch/x86/boot/trampoline.S    |   25 ++++-
 xen/arch/x86/boot/video.S         |    6 --
 xen/arch/x86/boot/wakeup.S        |    6 +-
 xen/arch/x86/boot/x86_64.S        |   34 +++---
 xen/arch/x86/dmi_scan.c           |    4 +-
 xen/arch/x86/domain_page.c        |    2 +-
 xen/arch/x86/efi/Makefile         |   16 +--
 xen/arch/x86/efi/efi-boot.h       |   68 ++++++++++--
 xen/arch/x86/efi/stub.c           |   16 ++-
 xen/arch/x86/mm.c                 |    3 +-
 xen/arch/x86/mpparse.c            |    4 +-
 xen/arch/x86/setup.c              |   50 ++++-----
 xen/arch/x86/shutdown.c           |    2 +-
 xen/arch/x86/time.c               |    2 +-
 xen/arch/x86/x86_64/asm-offsets.c |   10 ++
 xen/arch/x86/x86_64/mm.c          |    2 +-
 xen/arch/x86/xen.lds.S            |    6 +-
 xen/common/efi/boot.c             |  461 ++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
 xen/common/efi/runtime.c          |   23 ++--
 xen/drivers/acpi/osl.c            |    2 +-
 xen/include/asm-x86/config.h      |    3 +
 xen/include/asm-x86/page.h        |    2 +-
 xen/include/xen/efi.h             |   17 ++-
 xen/include/xen/multiboot2.h      |  182 ++++++++++++++++++++++++++++++++
 34 files changed, 1709 insertions(+), 763 deletions(-)

Daniel Kiper (23):
x86/boot: remove unneeded instruction
x86/boot: copy only text section from *.lnk file to *.bin file
x86: zero BSS using stosl instead of stosb x86/boot: call reloc() using cdecl calling convention x86/boot/reloc: create generic alloc and copy functions x86/boot: use %ecx instead of %eax
x86/boot/reloc: Rename some variables and rearrange code a bit
x86: add multiboot2 protocol support
efi: create efi_enabled()
efi: build xen.gz with EFI code
efi: split out efi_init()
efi: split out efi_console_set_mode()
efi: split out efi_get_gop()
efi: split out efi_find_gop_mode()
efi: split out efi_tables()
efi: split out efi_variables()
efi: split out efi_set_gop_mode()
efi: split out efi_exit_boot()
x86/efi: create new early memory allocator
x86: add multiboot2 protocol support for EFI platforms x86/boot: implement early command line parser in C
x86: make Xen early boot code relocatable
x86: add multiboot2 protocol support for relocatable images

#1 lore raw

PATCH v2 1/23 x86/boot: remove unneeded instruction

---
 xen/arch/x86/boot/head.S |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/boot/head.S +0 -1
index cfd59dc..f63b349 100644
@@ -169,7 +169,6 @@ __start:
         /* Apply relocations to bootstrap trampoline. */
         mov     sym_phys(trampoline_phys),%edx
         mov     $sym_phys(__trampoline_rel_start),%edi
-        mov     %edx,sym_phys(trampoline_phys)
 1:
         mov     (%edi),%eax
         add     %edx,(%edi,%eax)
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH v2 01/23] x86/boot: remove unneeded instruction

Quoted 1 line · Daniel Kiper

Don't you use it in:

    /* Switch to low-memory stack.  */                                      
193         mov     sym_phys(trampoline_phys),%edi                                  
194         lea     0x10000(%edi),%esp                                              
195         lea     trampoline_boot_cpu_entry-trampoline_start(%edi),%eax   

?

Quoted 19 lines
---
 xen/arch/x86/boot/head.S |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/boot/head.S +0 -1
index cfd59dc..f63b349 100644
@@ -169,7 +169,6 @@ __start:
         /* Apply relocations to bootstrap trampoline. */
         mov     sym_phys(trampoline_phys),%edx
         mov     $sym_phys(__trampoline_rel_start),%edi
-        mov     %edx,sym_phys(trampoline_phys)
 1:
         mov     (%edi),%eax
         add     %edx,(%edi,%eax)
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH v2 01/23] x86/boot: remove unneeded instruction

In reply to Daniel Kiper
Quoted 1 line · Daniel Kiper

Don't you use it in:

    /* Switch to low-memory stack.  */                                      
193         mov     sym_phys(trampoline_phys),%edi                                  
194         lea     0x10000(%edi),%esp                                              
195         lea     trampoline_boot_cpu_entry-trampoline_start(%edi),%eax   

?

Quoted 19 lines
---
 xen/arch/x86/boot/head.S |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/boot/head.S +0 -1
index cfd59dc..f63b349 100644
@@ -169,7 +169,6 @@ __start:
         /* Apply relocations to bootstrap trampoline. */
         mov     sym_phys(trampoline_phys),%edx
         mov     $sym_phys(__trampoline_rel_start),%edi
-        mov     %edx,sym_phys(trampoline_phys)
 1:
         mov     (%edi),%eax
         add     %edx,(%edi,%eax)
Signature · 1 line
1.7.10.4
#4 lore raw

Re: [PATCH v2 01/23] x86/boot: remove unneeded instruction

Quoted 10 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Don't you use it in:

    /* Switch to low-memory stack.  */
193         mov     sym_phys(trampoline_phys),%edi
194         lea     0x10000(%edi),%esp
195         lea     trampoline_boot_cpu_entry-trampoline_start(%edi),%eax

?

Yep, but...

Quoted 11 lines

xen/arch/x86/boot/head.S __start: · line 170

Quoted 11 lines
---
 xen/arch/x86/boot/head.S |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/boot/head.S +0 -0
index cfd59dc..f63b349 100644
@@ -169,7 +169,6 @@ __start:
         /* Apply relocations to bootstrap trampoline. */
         mov     sym_phys(trampoline_phys),%edx

...relevant value is stored in sym_phys(trampoline_phys) earlier then it is read into %edx here and...

Quoted 2 lines

xen/arch/x86/boot/head.S __start: · line 172

Quoted 2 lines
xen/arch/x86/boot/head.S +0 -1
         mov     $sym_phys(__trampoline_rel_start),%edi
-        mov     %edx,sym_phys(trampoline_phys)

...it is put back to sym_phys(trampoline_phys) without any change here :-))). So, I suppose this is remnant from something which was removed once but somebody forgot to remove this instruction too... This patch fixes it.

Daniel

#5 lore raw

Re: [PATCH v2 01/23] x86/boot: remove unneeded instruction

In reply to Konrad Rzeszutek Wilk
Quoted 10 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Don't you use it in:

    /* Switch to low-memory stack.  */
193         mov     sym_phys(trampoline_phys),%edi
194         lea     0x10000(%edi),%esp
195         lea     trampoline_boot_cpu_entry-trampoline_start(%edi),%eax

?

Yep, but...

Quoted 11 lines

xen/arch/x86/boot/head.S __start: · line 170

Quoted 11 lines
---
 xen/arch/x86/boot/head.S |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/boot/head.S +0 -0
index cfd59dc..f63b349 100644
@@ -169,7 +169,6 @@ __start:
         /* Apply relocations to bootstrap trampoline. */
         mov     sym_phys(trampoline_phys),%edx

...relevant value is stored in sym_phys(trampoline_phys) earlier then it is read into %edx here and...

Quoted 2 lines

xen/arch/x86/boot/head.S __start: · line 172

Quoted 2 lines
xen/arch/x86/boot/head.S +0 -1
         mov     $sym_phys(__trampoline_rel_start),%edi
-        mov     %edx,sym_phys(trampoline_phys)

...it is put back to sym_phys(trampoline_phys) without any change here :-))). So, I suppose this is remnant from something which was removed once but somebody forgot to remove this instruction too... This patch fixes it.

Daniel

#6 lore raw

Re: [PATCH v2 01/23] x86/boot: remove unneeded instruction

Quoted 29 lines · Daniel Kiper
Quoted 10 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Don't you use it in:

    /* Switch to low-memory stack.  */
193         mov     sym_phys(trampoline_phys),%edi
194         lea     0x10000(%edi),%esp
195         lea     trampoline_boot_cpu_entry-trampoline_start(%edi),%eax

?

Yep, but...

Quoted 11 lines

xen/arch/x86/boot/head.S __start: · line 170

Quoted 11 lines
---
 xen/arch/x86/boot/head.S |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/boot/head.S +0 -0
index cfd59dc..f63b349 100644
@@ -169,7 +169,6 @@ __start:
         /* Apply relocations to bootstrap trampoline. */
         mov     sym_phys(trampoline_phys),%edx

...relevant value is stored in sym_phys(trampoline_phys) earlier then it is read into %edx here and...

Quoted 6 lines
Quoted 2 lines

xen/arch/x86/boot/head.S __start: · line 172

Quoted 2 lines
xen/arch/x86/boot/head.S +0 -1
         mov     $sym_phys(__trampoline_rel_start),%edi
-        mov     %edx,sym_phys(trampoline_phys)

...it is put back to sym_phys(trampoline_phys) without any change here :-))). So, I suppose this is remnant from something which was removed once but somebody forgot to remove this instruction too... This patch fixes it.

#7 lore raw

Re: [PATCH v2 01/23] x86/boot: remove unneeded instruction

In reply to Daniel Kiper
Quoted 29 lines · Daniel Kiper
Quoted 10 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Daniel Kiper

Don't you use it in:

    /* Switch to low-memory stack.  */
193         mov     sym_phys(trampoline_phys),%edi
194         lea     0x10000(%edi),%esp
195         lea     trampoline_boot_cpu_entry-trampoline_start(%edi),%eax

?

Yep, but...

Quoted 11 lines

xen/arch/x86/boot/head.S __start: · line 170

Quoted 11 lines
---
 xen/arch/x86/boot/head.S |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/boot/head.S +0 -0
index cfd59dc..f63b349 100644
@@ -169,7 +169,6 @@ __start:
         /* Apply relocations to bootstrap trampoline. */
         mov     sym_phys(trampoline_phys),%edx

...relevant value is stored in sym_phys(trampoline_phys) earlier then it is read into %edx here and...

Quoted 6 lines
Quoted 2 lines

xen/arch/x86/boot/head.S __start: · line 172

Quoted 2 lines
xen/arch/x86/boot/head.S +0 -1
         mov     $sym_phys(__trampoline_rel_start),%edi
-        mov     %edx,sym_phys(trampoline_phys)

...it is put back to sym_phys(trampoline_phys) without any change here :-))). So, I suppose this is remnant from something which was removed once but somebody forgot to remove this instruction too... This patch fixes it.

#8 lore raw

PATCH v2 1/23 x86/boot: remove unneeded instruction

In reply to Daniel Kiper
---
 xen/arch/x86/boot/head.S |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/boot/head.S +0 -1
index cfd59dc..f63b349 100644
@@ -169,7 +169,6 @@ __start:
         /* Apply relocations to bootstrap trampoline. */
         mov     sym_phys(trampoline_phys),%edx
         mov     $sym_phys(__trampoline_rel_start),%edi
-        mov     %edx,sym_phys(trampoline_phys)
 1:
         mov     (%edi),%eax
         add     %edx,(%edi,%eax)
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH v2 2/23 x86/boot: copy only text section from *.lnk file to *.bin file

In reply to Daniel Kiper
---
 xen/arch/x86/boot/build32.mk |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/boot/build32.mk +1 -1
index c208249..c83effe 100644
@@ -13,7 +13,7 @@ CFLAGS := $(filter-out -flto,$(CFLAGS))
 	sed 's/ /,0x/g' | sed 's/,0x$$//' | sed 's/^[0-9]*,/ .long /') >$@
 
 %.bin: %.lnk
-	$(OBJCOPY) -O binary $< $@
+	$(OBJCOPY) -O binary -j .text $< $@
 
 %.lnk: %.o
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0 -o $@ $<
Signature · 1 line
1.7.10.4
#10 lore raw

PATCH v2 2/23 x86/boot: copy only text section from *.lnk file to *.bin file

In reply to Daniel Kiper
---
 xen/arch/x86/boot/build32.mk |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/boot/build32.mk +1 -1
index c208249..c83effe 100644
@@ -13,7 +13,7 @@ CFLAGS := $(filter-out -flto,$(CFLAGS))
 	sed 's/ /,0x/g' | sed 's/,0x$$//' | sed 's/^[0-9]*,/ .long /') >$@
 
 %.bin: %.lnk
-	$(OBJCOPY) -O binary $< $@
+	$(OBJCOPY) -O binary -j .text $< $@
 
 %.lnk: %.o
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0 -o $@ $<
Signature · 1 line
1.7.10.4
#11 lore raw

Re: [PATCH v2 02/23] x86/boot: copy only text section from *.lnk file to *.bin file

Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:

Without any explanation (description) I'm inclined to say this makes things more fragile instead of improving the situation. As it looks like we indeed pointlessly copy .eh_frame, but I think this would better be avoided by suppressing its generation (i.e. add -fno-asynchronous-unwind-tables just like Rules.mk has).

Jan

Quoted 20 lines
---
 xen/arch/x86/boot/build32.mk |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/boot/build32.mk +1 -1
index c208249..c83effe 100644
@@ -13,7 +13,7 @@ CFLAGS := $(filter-out -flto,$(CFLAGS))
 	sed 's/ /,0x/g' | sed 's/,0x$$//' | sed 's/^[0-9]*,/ .long /') >$@
 
 %.bin: %.lnk
-	$(OBJCOPY) -O binary $< $@
+	$(OBJCOPY) -O binary -j .text $< $@
 
 %.lnk: %.o
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0 -o $@ $<
Signature · 1 line
1.7.10.4
#12 lore raw

Re: [PATCH v2 02/23] x86/boot: copy only text section from *.lnk file to *.bin file

Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:

Without any explanation (description) I'm inclined to say this makes things more fragile instead of improving the situation. As it looks like we indeed pointlessly copy .eh_frame, but I think this would better be avoided by suppressing its generation (i.e. add -fno-asynchronous-unwind-tables just like Rules.mk has).

Make sense, however, there is still place for two small optimizations.

First of all ld generates .got.plt section and objcopy copy it to binary file. It is not needed because we do not link our stuff here with shared libraries. So, we can use -R objcopy option to remove it (if you do not like -j .text). This way we could save 15 bytes (at least on my machines).

We could also save another 3 bytes (per one xen/arch/x86/boot C input file) in final Xen binary in worst case :-))). We just need generate output assembly files as string of .byte instead of .long.

Where should I stop?

Daniel

#13 lore raw

Re: [PATCH v2 02/23] x86/boot: copy only text section from *.lnk file to *.bin file

Quoted 10 lines
Quoted 1 line
Quoted 1 line

Daniel Kiper <[email protected]> 07/21/15 7:24 PM >>>

Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:

Without any explanation (description) I'm inclined to say this makes things more fragile instead of improving the situation. As it looks like we indeed pointlessly copy .eh_frame, but I think this would better be avoided by suppressing its generation (i.e. add -fno-asynchronous-unwind-tables just like Rules.mk has).

Quoted 6 lines

Make sense, however, there is still place for two small optimizations.

First of all ld generates .got.plt section and objcopy copy it to binary file. It is not needed because we do not link our stuff here with shared libraries. So, we can use -R objcopy option to remove it (if you do not like -j .text). This way we could save 15 bytes (at least on my machines).

.got.plt shouldn't be generated in the first place (and I don't recall having seen one here - I'll double check once in the office), i.e. perhaps another missing compiler option or a linker quirk?

Quoted 3 lines

We could also save another 3 bytes (per one xen/arch/x86/boot C input file) in final Xen binary in worst case :-))). We just need generate output assembly files as string of .byte instead of .long.

If you feel it worth your time, go ahead.

Jan

#14 lore raw

Re: [PATCH v2 02/23] x86/boot: copy only text section from *.lnk file to *.bin file

In reply to Daniel Kiper
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 21.07.15 at 19:23, <[email protected]> wrote:

First of all ld generates .got.plt section and objcopy copy it to binary file.
It is not needed because we do not link our stuff here with shared libraries.
So, we can use -R objcopy option to remove it (if you do not like -j .text). This way we could save 15 bytes (at least on my machines).

So I checked and did find no .got.plt at all on a machine using binutils 2.25 and an empty one on a machine using an older version. So I'm curious what you're seeing present in that table (without any of your patches applied).

Jan

#15 lore raw

Re: [PATCH v2 02/23] x86/boot: copy only text section from *.lnk file to *.bin file

Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 21.07.15 at 19:23, <[email protected]> wrote:

First of all ld generates .got.plt section and objcopy copy it to binary file.
It is not needed because we do not link our stuff here with shared libraries.
So, we can use -R objcopy option to remove it (if you do not like -j .text). This way we could save 15 bytes (at least on my machines).

Quoted 4 lines

So I checked and did find no .got.plt at all on a machine using binutils 2.25 and an empty one on a machine using an older version. So I'm curious what you're seeing present in that table (without any of your patches applied).

Here it is:

[...]

Section Headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00     0   0  0
  [ 1] .text             PROGBITS        00000000 000080 000705 00 WAX 0   0 16
  [ 2] .eh_frame         PROGBITS        00000708 000788 000104 00   A 0   0  4
  [ 3] .got.plt          PROGBITS        0000080c 00088c 00000c 04  WA 0   0  4
  [ 4] .comment          PROGBITS        00000000 000898 00001c 01  MS 0   0  1
  [ 5] .debug_aranges    PROGBITS        00000000 0008b4 000020 00     0   0  1
  [ 6] .debug_info       PROGBITS        00000000 0008d4 000c2c 00     0   0  1
  [ 7] .debug_abbrev     PROGBITS        00000000 001500 000303 00     0   0  1
  [ 8] .debug_line       PROGBITS        00000000 001803 000180 00     0   0  1
  [ 9] .debug_str        PROGBITS        00000000 001983 000236 01  MS 0   0  1
  [10] .debug_loc        PROGBITS        00000000 001bb9 0007b8 00     0   0  1
  [11] .debug_ranges     PROGBITS        00000000 002371 000030 00     0   0  1
  [12] .shstrtab         STRTAB          00000000 0023a1 000096 00     0   0  1
  [13] .symtab           SYMTAB          00000000 002690 000290 10    14  36  4
  [14] .strtab           STRTAB          00000000 002920 000162 00     0   0  1

[...]

It is generated using ld from binutils 2.22.

I was thinking that -static ld option would remove .got.plt but it did not.

Daniel

#16 lore raw

Re: [PATCH v2 02/23] x86/boot: copy only text section from *.lnk file to *.bin file

Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 22.07.15 at 15:31, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 21.07.15 at 19:23, <[email protected]> wrote:

First of all ld generates .got.plt section and objcopy copy it to binary file.
It is not needed because we do not link our stuff here with shared libraries.
So, we can use -R objcopy option to remove it (if you do not like -j .text). This way we could save 15 bytes (at least on my machines).

Quoted 4 lines

So I checked and did find no .got.plt at all on a machine using binutils 2.25 and an empty one on a machine using an older version. So I'm curious what you're seeing present in that table (without any of your patches applied).

Here it is:

Quoted 8 lines

[...]

Section Headers:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00     0   0  0
  [ 1] .text             PROGBITS        00000000 000080 000705 00 WAX 0   0 16
  [ 2] .eh_frame         PROGBITS        00000708 000788 000104 00   A 0   0  4
  [ 3] .got.plt          PROGBITS        0000080c 00088c 00000c 04  WA 0   0  4

But how do I know what is in there, i.e. which symbols are causing this non-zero size? Because that's what we want to deal with instead of arbitrarily dropping (or picking) sections.

Jan

#17 lore raw

PATCH v2 3/23 x86: zero BSS using stosl instead of stosb

In reply to Daniel Kiper

Additionally, align relevant comment to coding style.

---
 xen/arch/x86/boot/head.S |    5 +++--
 xen/arch/x86/xen.lds.S   |    2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/boot/head.S +3 -2
index f63b349..ed42782 100644
@@ -123,12 +123,13 @@ __start:
         call    reloc
         mov     %eax,sym_phys(multiboot_ptr)
 
-        /* Initialize BSS (no nasty surprises!) */
+        /* Initialize BSS (no nasty surprises!). */
         mov     $sym_phys(__bss_start),%edi
         mov     $sym_phys(__bss_end),%ecx
         sub     %edi,%ecx
+        shr     $2,%ecx
         xor     %eax,%eax
-        rep     stosb
+        rep     stosl
 
         /* Interrogate CPU extended features via CPUID. */
         mov     $0x80000000,%eax
xen/arch/x86/xen.lds.S +2 -0
index 6553cff..3e1f2af 100644
@@ -162,6 +162,7 @@ SECTIONS
   . = ALIGN(STACK_SIZE);
   __init_end = .;
 
+  . = ALIGN(4);
   .bss : {                     /* BSS */
        __bss_start = .;
        *(.bss.stack_aligned)
@@ -175,6 +176,7 @@ SECTIONS
        *(.bss.percpu.read_mostly)
        . = ALIGN(SMP_CACHE_BYTES);
        __per_cpu_data_end = .;
+       . = ALIGN(4);
        __bss_end = .;
   } :text
   _end = . ;
Signature · 1 line
1.7.10.4
#18 lore raw

PATCH v2 3/23 x86: zero BSS using stosl instead of stosb

In reply to Daniel Kiper

Additionally, align relevant comment to coding style.

---
 xen/arch/x86/boot/head.S |    5 +++--
 xen/arch/x86/xen.lds.S   |    2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/boot/head.S +3 -2
index f63b349..ed42782 100644
@@ -123,12 +123,13 @@ __start:
         call    reloc
         mov     %eax,sym_phys(multiboot_ptr)
 
-        /* Initialize BSS (no nasty surprises!) */
+        /* Initialize BSS (no nasty surprises!). */
         mov     $sym_phys(__bss_start),%edi
         mov     $sym_phys(__bss_end),%ecx
         sub     %edi,%ecx
+        shr     $2,%ecx
         xor     %eax,%eax
-        rep     stosb
+        rep     stosl
 
         /* Interrogate CPU extended features via CPUID. */
         mov     $0x80000000,%eax
xen/arch/x86/xen.lds.S +2 -0
index 6553cff..3e1f2af 100644
@@ -162,6 +162,7 @@ SECTIONS
   . = ALIGN(STACK_SIZE);
   __init_end = .;
 
+  . = ALIGN(4);
   .bss : {                     /* BSS */
        __bss_start = .;
        *(.bss.stack_aligned)
@@ -175,6 +176,7 @@ SECTIONS
        *(.bss.percpu.read_mostly)
        . = ALIGN(SMP_CACHE_BYTES);
        __per_cpu_data_end = .;
+       . = ALIGN(4);
        __bss_end = .;
   } :text
   _end = . ;
Signature · 1 line
1.7.10.4
#19 lore raw

Re: [PATCH v2 03/23] x86: zero BSS using stosl instead of stosb

Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:

... because of ??? Nowadays - with X86_FEATURE_ERMS - rep stosb is expected to be faster than rep stosl.

Jan

#20 lore raw

Re: [PATCH v2 03/23] x86: zero BSS using stosl instead of stosb

Quoted 4 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:

... because of ??? Nowadays - with X86_FEATURE_ERMS - rep stosb is expected to be faster than rep stosl.

OK, I did not know about that. However, as I know this feature was introduced in 2012 with Ivy Bridge. So, I suppose that there are still a lot of machines in the wild which does not support it. Anyway, because this code is not performance critical I am not going to insist on one or another solution. However, Andrew suggested that thing, so, please agree with him in which direction we should go. I will do what you agree.

Daniel

#21 lore raw

Re: [PATCH v2 03/23] x86: zero BSS using stosl instead of stosb

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Daniel Kiper <[email protected]> 07/21/15 8:23 PM >>>

Quoted 4 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:

... because of ??? Nowadays - with X86_FEATURE_ERMS - rep stosb is expected to be faster than rep stosl.

Quoted 7 lines

OK, I did not know about that. However, as I know this feature was introduced in 2012 with Ivy Bridge. So, I suppose that there are still a lot of machines in the wild which does not support it. Anyway, because this code is not performance critical I am not going to insist on one or another solution. However, Andrew suggested that thing, so, please agree with him in which direction we should go. I will do what you agree.

ISTR having seen a similar patch from him(?), maybe in another area of code, before (or was it v1 of this one?), which I responded to with the same as above.

Jan

#22 lore raw

Re: [PATCH v2 03/23] x86: zero BSS using stosl instead of stosb

Quoted 12 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Daniel Kiper <[email protected]> 07/21/15 8:23 PM >>>

Quoted 3 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:

... because of ??? Nowadays - with X86_FEATURE_ERMS - rep stosb is expected to be faster than rep stosl.

Quoted 7 lines

OK, I did not know about that. However, as I know this feature was introduced in 2012 with Ivy Bridge. So, I suppose that there are still a lot of machines in the wild which does not support it. Anyway, because this code is not performance critical I am not going to insist on one or another solution. However, Andrew suggested that thing, so, please agree with him in which direction we should go. I will do what you agree.

Quoted 3 lines

ISTR having seen a similar patch from him(?), maybe in another area of code, before (or was it v1 of this one?), which I responded to with the same as above.

Indeed you have, several in fact. I had not had chance to delve into the optimisation manuals, but have taken a peek now. (Section 3.7.6)

In the case of having aligned source and destination on a 16-byte boundary (which we can trivially arrange), then ERMSB (to give it its Intel name) and rep stosl differ only in the setup cost; they still scale at the same rate for changes in length.

Therefore, assuming we arrange for 16-byte alignment, using rep stosl would appear to be a single 60ish cycle hit over using ERMSB, but would be substantially more efficient than using rep stosb on a non-ERMSB system.

Overall, I think 16 byte alignment and rep stosl is the best compromise.

~Andrew

#23 lore raw

Re: [PATCH v2 03/23] x86: zero BSS using stosl instead of stosb

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 22.07.15 at 10:42, <[email protected]> wrote:

In the case of having aligned source and destination on a 16-byte boundary (which we can trivially arrange), then ERMSB (to give it its Intel name) and rep stosl differ only in the setup cost; they still scale at the same rate for changes in length.

Therefore, assuming we arrange for 16-byte alignment, using rep stosl would appear to be a single 60ish cycle hit over using ERMSB, but would be substantially more efficient than using rep stosb on a non-ERMSB system.

Overall, I think 16 byte alignment and rep stosl is the best compromise.

Or leaving such code alone, with the assumption that over time the setup cost (on a growing number of systems) outweighs the benefits (on a shrinking set).

Jan

#24 lore raw

Re: [PATCH v2 03/23] x86: zero BSS using stosl instead of stosb

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 22.07.15 at 10:42, <[email protected]> wrote:

In the case of having aligned source and destination on a 16-byte boundary (which we can trivially arrange), then ERMSB (to give it its Intel name) and rep stosl differ only in the setup cost; they still scale at the same rate for changes in length.

Quoted 8 lines
Quoted 5 lines

Therefore, assuming we arrange for 16-byte alignment, using rep stosl would appear to be a single 60ish cycle hit over using ERMSB, but would be substantially more efficient than using rep stosb on a non-ERMSB system.

Overall, I think 16 byte alignment and rep stosl is the best compromise.

Or leaving such code alone, with the assumption that over time the setup cost (on a growing number of systems) outweighs the benefits (on a shrinking set).

The BSS is large - 295k on the last compile I have from staging. The setup cost is lost in the nose compared to the elapsed time to write that many zeroes to memory.

Therefore, on an ERMBS-capable system, the two options will complete in the same amount of time.

However, on all AMD hardware and Intel hardware older than IvyBridge, rep stosl is 4 times faster than rep stosb.

~Andrew

#25 lore raw

Re: [PATCH v2 03/23] x86: zero BSS using stosl instead of stosb

Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 22.07.15 at 13:22, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 22.07.15 at 10:42, <[email protected]> wrote:

In the case of having aligned source and destination on a 16-byte boundary (which we can trivially arrange), then ERMSB (to give it its Intel name) and rep stosl differ only in the setup cost; they still scale at the same rate for changes in length.

Quoted 8 lines
Quoted 5 lines

Therefore, assuming we arrange for 16-byte alignment, using rep stosl would appear to be a single 60ish cycle hit over using ERMSB, but would be substantially more efficient than using rep stosb on a non-ERMSB system.

Overall, I think 16 byte alignment and rep stosl is the best compromise.

Or leaving such code alone, with the assumption that over time the setup cost (on a growing number of systems) outweighs the benefits (on a shrinking set).

The BSS is large - 295k on the last compile I have from staging. The setup cost is lost in the nose compared to the elapsed time to write that many zeroes to memory.

Quoted 5 lines

Therefore, on an ERMBS-capable system, the two options will complete in the same amount of time.

However, on all AMD hardware and Intel hardware older than IvyBridge, rep stosl is 4 times faster than rep stosb.

Well, okay then.

Jan

#26 lore raw

PATCH v2 4/23 x86/boot: call reloc() using cdecl calling convention

In reply to Daniel Kiper
---
 xen/arch/x86/boot/head.S  |    4 +++-
 xen/arch/x86/boot/reloc.c |   20 ++++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)
xen/arch/x86/boot/head.S +3 -1
index ed42782..3cbb2e6 100644
@@ -119,8 +119,10 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
-        push    %ebx
+        push    %ebx                /* Multiboot information address. */
+        push    %eax                /* Boot trampoline address. */
         call    reloc
+        add     $8,%esp             /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
 
         /* Initialize BSS (no nasty surprises!). */
xen/arch/x86/boot/reloc.c +16 -4
index 63045c0..708898f 100644
@@ -10,15 +10,27 @@
  *    Keir Fraser <[email protected]>
  */
 
-/* entered with %eax = BOOT_TRAMPOLINE */
+/*
+ * This entry point is entered from xen/arch/x86/boot/head.S with:
+ *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
+ *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS.
+ */
 asm (
     "    .text                         \n"
     "    .globl _start                 \n"
     "_start:                           \n"
+    "    push %ebp                     \n"
+    "    mov  %esp,%ebp                \n"
     "    call 1f                       \n"
-    "1:  pop  %ebx                     \n"
-    "    mov  %eax,alloc-1b(%ebx)      \n"
-    "    jmp  reloc                    \n"
+    "1:  pop  %ecx                     \n"
+    "    mov  0x8(%ebp),%eax           \n"
+    "    mov  %eax,alloc-1b(%ecx)      \n"
+    "    mov  0xc(%ebp),%eax           \n"
+    "    push %eax                     \n"
+    "    call reloc                    \n"
+    "    add  $4,%esp                  \n"
+    "    pop  %ebp                     \n"
+    "    ret                           \n"
     );
 
 /*
Signature · 1 line
1.7.10.4
#27 lore raw

PATCH v2 4/23 x86/boot: call reloc() using cdecl calling convention

In reply to Daniel Kiper
---
 xen/arch/x86/boot/head.S  |    4 +++-
 xen/arch/x86/boot/reloc.c |   20 ++++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)
xen/arch/x86/boot/head.S +3 -1
index ed42782..3cbb2e6 100644
@@ -119,8 +119,10 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
-        push    %ebx
+        push    %ebx                /* Multiboot information address. */
+        push    %eax                /* Boot trampoline address. */
         call    reloc
+        add     $8,%esp             /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
 
         /* Initialize BSS (no nasty surprises!). */
xen/arch/x86/boot/reloc.c +16 -4
index 63045c0..708898f 100644
@@ -10,15 +10,27 @@
  *    Keir Fraser <[email protected]>
  */
 
-/* entered with %eax = BOOT_TRAMPOLINE */
+/*
+ * This entry point is entered from xen/arch/x86/boot/head.S with:
+ *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
+ *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS.
+ */
 asm (
     "    .text                         \n"
     "    .globl _start                 \n"
     "_start:                           \n"
+    "    push %ebp                     \n"
+    "    mov  %esp,%ebp                \n"
     "    call 1f                       \n"
-    "1:  pop  %ebx                     \n"
-    "    mov  %eax,alloc-1b(%ebx)      \n"
-    "    jmp  reloc                    \n"
+    "1:  pop  %ecx                     \n"
+    "    mov  0x8(%ebp),%eax           \n"
+    "    mov  %eax,alloc-1b(%ecx)      \n"
+    "    mov  0xc(%ebp),%eax           \n"
+    "    push %eax                     \n"
+    "    call reloc                    \n"
+    "    add  $4,%esp                  \n"
+    "    pop  %ebp                     \n"
+    "    ret                           \n"
     );
 
 /*
Signature · 1 line
1.7.10.4
Reviewed-by on v2 4/23
#28 lore raw

Re: [Xen-devel] [PATCH v2 04/23] x86/boot: call reloc() using cdecl calling convention

Quoted 2 lines · Daniel Kiper
Quoted 65 lines
---
 xen/arch/x86/boot/head.S  |    4 +++-
 xen/arch/x86/boot/reloc.c |   20 ++++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)
xen/arch/x86/boot/head.S +3 -1
index ed42782..3cbb2e6 100644
@@ -119,8 +119,10 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
-        push    %ebx
+        push    %ebx                /* Multiboot information address. */
+        push    %eax                /* Boot trampoline address. */
         call    reloc
+        add     $8,%esp             /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
 
         /* Initialize BSS (no nasty surprises!). */
xen/arch/x86/boot/reloc.c +16 -4
index 63045c0..708898f 100644
@@ -10,15 +10,27 @@
  *    Keir Fraser <[email protected]>
  */
 
-/* entered with %eax = BOOT_TRAMPOLINE */
+/*
+ * This entry point is entered from xen/arch/x86/boot/head.S with:
+ *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
+ *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS.
+ */
 asm (
     "    .text                         \n"
     "    .globl _start                 \n"
     "_start:                           \n"
+    "    push %ebp                     \n"
+    "    mov  %esp,%ebp                \n"
     "    call 1f                       \n"
-    "1:  pop  %ebx                     \n"
-    "    mov  %eax,alloc-1b(%ebx)      \n"
-    "    jmp  reloc                    \n"
+    "1:  pop  %ecx                     \n"
+    "    mov  0x8(%ebp),%eax           \n"
+    "    mov  %eax,alloc-1b(%ecx)      \n"
+    "    mov  0xc(%ebp),%eax           \n"
+    "    push %eax                     \n"
+    "    call reloc                    \n"
+    "    add  $4,%esp                  \n"
+    "    pop  %ebp                     \n"
+    "    ret                           \n"
     );
 
 /*
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 4/23
#29 lore raw

Re: [PATCH v2 04/23] x86/boot: call reloc() using cdecl calling convention

In reply to Daniel Kiper
Quoted 2 lines · Daniel Kiper
Quoted 65 lines
---
 xen/arch/x86/boot/head.S  |    4 +++-
 xen/arch/x86/boot/reloc.c |   20 ++++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)
xen/arch/x86/boot/head.S +3 -1
index ed42782..3cbb2e6 100644
@@ -119,8 +119,10 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
-        push    %ebx
+        push    %ebx                /* Multiboot information address. */
+        push    %eax                /* Boot trampoline address. */
         call    reloc
+        add     $8,%esp             /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
 
         /* Initialize BSS (no nasty surprises!). */
xen/arch/x86/boot/reloc.c +16 -4
index 63045c0..708898f 100644
@@ -10,15 +10,27 @@
  *    Keir Fraser <[email protected]>
  */
 
-/* entered with %eax = BOOT_TRAMPOLINE */
+/*
+ * This entry point is entered from xen/arch/x86/boot/head.S with:
+ *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
+ *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS.
+ */
 asm (
     "    .text                         \n"
     "    .globl _start                 \n"
     "_start:                           \n"
+    "    push %ebp                     \n"
+    "    mov  %esp,%ebp                \n"
     "    call 1f                       \n"
-    "1:  pop  %ebx                     \n"
-    "    mov  %eax,alloc-1b(%ebx)      \n"
-    "    jmp  reloc                    \n"
+    "1:  pop  %ecx                     \n"
+    "    mov  0x8(%ebp),%eax           \n"
+    "    mov  %eax,alloc-1b(%ecx)      \n"
+    "    mov  0xc(%ebp),%eax           \n"
+    "    push %eax                     \n"
+    "    call reloc                    \n"
+    "    add  $4,%esp                  \n"
+    "    pop  %ebp                     \n"
+    "    ret                           \n"
     );
 
 /*
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#30 lore raw

Re: [PATCH v2 04/23] x86/boot: call reloc() using cdecl calling convention

In reply to Daniel Kiper
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:

An empty description leaves us guess at the "why".

Quoted 8 lines
xen/arch/x86/boot/reloc.c +1 -1
@@ -10,15 +10,27 @@
  *    Keir Fraser <[email protected]>
  */
 
-/* entered with %eax = BOOT_TRAMPOLINE */
+/*

xen/arch/x86/boot/reloc.c line 23

Quoted 10 lines
xen/arch/x86/boot/reloc.c +6 -0
+ * This entry point is entered from xen/arch/x86/boot/head.S with:
+ *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
+ *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS.
+ */
 asm (
     "    .text                         \n"
     "    .globl _start                 \n"
     "_start:                           \n"
+    "    push %ebp                     \n"
+    "    mov  %esp,%ebp                \n"

What do you need this for?

xen/arch/x86/boot/reloc.c line 29

Quoted 9 lines
xen/arch/x86/boot/reloc.c +5 -3
     "    call 1f                       \n"
-    "1:  pop  %ebx                     \n"
-    "    mov  %eax,alloc-1b(%ebx)      \n"
-    "    jmp  reloc                    \n"
+    "1:  pop  %ecx                     \n"
+    "    mov  0x8(%ebp),%eax           \n"
+    "    mov  %eax,alloc-1b(%ecx)      \n"
+    "    mov  0xc(%ebp),%eax           \n"
+    "    push %eax                     \n"
    push 12(%ebp)

xen/arch/x86/boot/reloc.c line 31

Quoted 2 lines
xen/arch/x86/boot/reloc.c +2 -0
+    "    call reloc                    \n"
+    "    add  $4,%esp                  \n"

If you already copy %esp to %ebp at the top,

mov %ebp, %esp

would be the better alternative.

xen/arch/x86/boot/reloc.c line 32

Quoted 1 line
xen/arch/x86/boot/reloc.c +1 -0
+    "    pop  %ebp                     \n"

Or even just

leave

Jan

#31 lore raw

Re: [PATCH v2 04/23] x86/boot: call reloc() using cdecl calling convention

In reply to Daniel Kiper
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:28, <[email protected]> wrote:

An empty description leaves us guess at the "why".

Quoted 8 lines
xen/arch/x86/boot/reloc.c +1 -1
@@ -10,15 +10,27 @@
  *    Keir Fraser <[email protected]>
  */
 
-/* entered with %eax = BOOT_TRAMPOLINE */
+/*

xen/arch/x86/boot/reloc.c line 23

Quoted 10 lines
xen/arch/x86/boot/reloc.c +6 -0
+ * This entry point is entered from xen/arch/x86/boot/head.S with:
+ *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
+ *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS.
+ */
 asm (
     "    .text                         \n"
     "    .globl _start                 \n"
     "_start:                           \n"
+    "    push %ebp                     \n"
+    "    mov  %esp,%ebp                \n"

What do you need this for?

xen/arch/x86/boot/reloc.c line 29

Quoted 9 lines
xen/arch/x86/boot/reloc.c +5 -3
     "    call 1f                       \n"
-    "1:  pop  %ebx                     \n"
-    "    mov  %eax,alloc-1b(%ebx)      \n"
-    "    jmp  reloc                    \n"
+    "1:  pop  %ecx                     \n"
+    "    mov  0x8(%ebp),%eax           \n"
+    "    mov  %eax,alloc-1b(%ecx)      \n"
+    "    mov  0xc(%ebp),%eax           \n"
+    "    push %eax                     \n"
    push 12(%ebp)

xen/arch/x86/boot/reloc.c line 31

Quoted 2 lines
xen/arch/x86/boot/reloc.c +2 -0
+    "    call reloc                    \n"
+    "    add  $4,%esp                  \n"

If you already copy %esp to %ebp at the top,

mov %ebp, %esp

would be the better alternative.

xen/arch/x86/boot/reloc.c line 32

Quoted 1 line
xen/arch/x86/boot/reloc.c +1 -0
+    "    pop  %ebp                     \n"

Or even just

leave

Jan

#32 lore raw

PATCH v2 5/23 x86/boot/reloc: create generic alloc and copy functions

In reply to Daniel Kiper

Create generic alloc and copy functions. We need separate tools for memory allocation and copy to provide multiboot2 protocol support.

---
v2 - suggestions/fixes:
- generalize new functions names
(suggested by Jan Beulich),
- reduce number of casts
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/reloc.c |   59 ++++++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 22 deletions(-)
xen/arch/x86/boot/reloc.c +37 -22
index 708898f..09fd540 100644
@@ -45,9 +45,10 @@ asm (
 typedef unsigned int u32;
 #include "../../../include/xen/multiboot.h"
 
-static void *reloc_mbi_struct(void *old, unsigned int bytes)
+static u32 alloc_mem(u32 bytes)
 {
-    void *new;
+    u32 s;
+
     asm(
     "    call 1f                      \n"
     "1:  pop  %%edx                   \n"
@@ -55,50 +56,64 @@ static void *reloc_mbi_struct(void *old, unsigned int bytes)
     "    sub  %1,%0                   \n"
     "    and  $~15,%0                 \n"
     "    mov  %0,alloc-1b(%%edx)      \n"
-    "    mov  %0,%%edi                \n"
-    "    rep  movsb                   \n"
-       : "=&r" (new), "+c" (bytes), "+S" (old)
-	: : "edx", "edi", "memory");
-    return new;
+       : "=&r" (s) : "r" (bytes) : "edx", "memory");
+
+    return s;
 }
 
-static char *reloc_mbi_string(char *old)
+static u32 copy_mem(u32 src, u32 bytes)
 {
-    char *p;
-    for ( p = old; *p != '\0'; p++ )
+    u32 dst, dst_asm;
+
+    dst = alloc_mem(bytes);
+    dst_asm = dst;
+
+    asm volatile("rep movsb" : "+S" (src), "+D" (dst_asm), "+c" (bytes) : : "memory");
+
+    return dst;
+}
+
+static u32 copy_string(u32 src)
+{
+    u32 p;
+
+    if ( src == 0 )
+        return 0;
+
+    for ( p = src; *(char *)p != '\0'; p++ )
         continue;
-    return reloc_mbi_struct(old, p - old + 1);
+
+    return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t *reloc(multiboot_info_t *mbi_old)
+multiboot_info_t *reloc(u32 mbi_old)
 {
-    multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi));
+    multiboot_info_t *mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi));
     int i;
 
     if ( mbi->flags & MBI_CMDLINE )
-        mbi->cmdline = (u32)reloc_mbi_string((char *)mbi->cmdline);
+        mbi->cmdline = copy_string(mbi->cmdline);
 
     if ( mbi->flags & MBI_MODULES )
     {
-        module_t *mods = reloc_mbi_struct(
-            (module_t *)mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+        module_t *mods;
 
-        mbi->mods_addr = (u32)mods;
+        mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+
+        mods = (module_t *)mbi->mods_addr;
 
         for ( i = 0; i < mbi->mods_count; i++ )
         {
             if ( mods[i].string )
-                mods[i].string = (u32)reloc_mbi_string((char *)mods[i].string);
+                mods[i].string = copy_string(mods[i].string);
         }
     }
 
     if ( mbi->flags & MBI_MEMMAP )
-        mbi->mmap_addr = (u32)reloc_mbi_struct(
-            (memory_map_t *)mbi->mmap_addr, mbi->mmap_length);
+        mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length);
 
     if ( mbi->flags & MBI_LOADERNAME )
-        mbi->boot_loader_name = (u32)reloc_mbi_string(
-            (char *)mbi->boot_loader_name);
+        mbi->boot_loader_name = copy_string(mbi->boot_loader_name);
 
     /* Mask features we don't understand or don't relocate. */
     mbi->flags &= (MBI_MEMLIMITS |
Signature · 1 line
1.7.10.4
#33 lore raw

PATCH v2 5/23 x86/boot/reloc: create generic alloc and copy functions

In reply to Daniel Kiper

Create generic alloc and copy functions. We need separate tools for memory allocation and copy to provide multiboot2 protocol support.

---
v2 - suggestions/fixes:
- generalize new functions names
(suggested by Jan Beulich),
- reduce number of casts
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/reloc.c |   59 ++++++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 22 deletions(-)
xen/arch/x86/boot/reloc.c +37 -22
index 708898f..09fd540 100644
@@ -45,9 +45,10 @@ asm (
 typedef unsigned int u32;
 #include "../../../include/xen/multiboot.h"
 
-static void *reloc_mbi_struct(void *old, unsigned int bytes)
+static u32 alloc_mem(u32 bytes)
 {
-    void *new;
+    u32 s;
+
     asm(
     "    call 1f                      \n"
     "1:  pop  %%edx                   \n"
@@ -55,50 +56,64 @@ static void *reloc_mbi_struct(void *old, unsigned int bytes)
     "    sub  %1,%0                   \n"
     "    and  $~15,%0                 \n"
     "    mov  %0,alloc-1b(%%edx)      \n"
-    "    mov  %0,%%edi                \n"
-    "    rep  movsb                   \n"
-       : "=&r" (new), "+c" (bytes), "+S" (old)
-	: : "edx", "edi", "memory");
-    return new;
+       : "=&r" (s) : "r" (bytes) : "edx", "memory");
+
+    return s;
 }
 
-static char *reloc_mbi_string(char *old)
+static u32 copy_mem(u32 src, u32 bytes)
 {
-    char *p;
-    for ( p = old; *p != '\0'; p++ )
+    u32 dst, dst_asm;
+
+    dst = alloc_mem(bytes);
+    dst_asm = dst;
+
+    asm volatile("rep movsb" : "+S" (src), "+D" (dst_asm), "+c" (bytes) : : "memory");
+
+    return dst;
+}
+
+static u32 copy_string(u32 src)
+{
+    u32 p;
+
+    if ( src == 0 )
+        return 0;
+
+    for ( p = src; *(char *)p != '\0'; p++ )
         continue;
-    return reloc_mbi_struct(old, p - old + 1);
+
+    return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t *reloc(multiboot_info_t *mbi_old)
+multiboot_info_t *reloc(u32 mbi_old)
 {
-    multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi));
+    multiboot_info_t *mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi));
     int i;
 
     if ( mbi->flags & MBI_CMDLINE )
-        mbi->cmdline = (u32)reloc_mbi_string((char *)mbi->cmdline);
+        mbi->cmdline = copy_string(mbi->cmdline);
 
     if ( mbi->flags & MBI_MODULES )
     {
-        module_t *mods = reloc_mbi_struct(
-            (module_t *)mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+        module_t *mods;
 
-        mbi->mods_addr = (u32)mods;
+        mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+
+        mods = (module_t *)mbi->mods_addr;
 
         for ( i = 0; i < mbi->mods_count; i++ )
         {
             if ( mods[i].string )
-                mods[i].string = (u32)reloc_mbi_string((char *)mods[i].string);
+                mods[i].string = copy_string(mods[i].string);
         }
     }
 
     if ( mbi->flags & MBI_MEMMAP )
-        mbi->mmap_addr = (u32)reloc_mbi_struct(
-            (memory_map_t *)mbi->mmap_addr, mbi->mmap_length);
+        mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length);
 
     if ( mbi->flags & MBI_LOADERNAME )
-        mbi->boot_loader_name = (u32)reloc_mbi_string(
-            (char *)mbi->boot_loader_name);
+        mbi->boot_loader_name = copy_string(mbi->boot_loader_name);
 
     /* Mask features we don't understand or don't relocate. */
     mbi->flags &= (MBI_MEMLIMITS |
Signature · 1 line
1.7.10.4
Acked-by on v2 5/23
#34 lore raw

Re: [PATCH v2 05/23] x86/boot/reloc: create generic alloc and copy functions

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Create generic alloc and copy functions. We need separate tools for memory allocation and copy to provide multiboot2 protocol support.

Quoted 8 lines

---
v2 - suggestions/fixes:
- generalize new functions names
(suggested by Jan Beulich),
- reduce number of casts
(suggested by Jan Beulich).

This contradicts retaining Andrew's R-b tag. Please remember to drop tags for everything you make non-trivial changes to.

xen/arch/x86/boot/reloc.c static void *reloc_mbi_struct(void *old, unsigned int bytes) · line 59

Quoted 10 lines
xen/arch/x86/boot/reloc.c +1 -5
@@ -55,50 +56,64 @@ static void *reloc_mbi_struct(void *old, unsigned int bytes)
     "    sub  %1,%0                   \n"
     "    and  $~15,%0                 \n"
     "    mov  %0,alloc-1b(%%edx)      \n"
-    "    mov  %0,%%edi                \n"
-    "    rep  movsb                   \n"
-       : "=&r" (new), "+c" (bytes), "+S" (old)
-	: : "edx", "edi", "memory");
-    return new;
+       : "=&r" (s) : "r" (bytes) : "edx", "memory");

Can't "bytes" use a simple "g" constraint now?

Preferably (i.e. if correct) this changed

Jan

Acked-by on v2 5/23
#35 lore raw

Re: [PATCH v2 05/23] x86/boot/reloc: create generic alloc and copy functions

In reply to Daniel Kiper
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Create generic alloc and copy functions. We need separate tools for memory allocation and copy to provide multiboot2 protocol support.

Quoted 8 lines

---
v2 - suggestions/fixes:
- generalize new functions names
(suggested by Jan Beulich),
- reduce number of casts
(suggested by Jan Beulich).

This contradicts retaining Andrew's R-b tag. Please remember to drop tags for everything you make non-trivial changes to.

xen/arch/x86/boot/reloc.c static void *reloc_mbi_struct(void *old, unsigned int bytes) · line 59

Quoted 10 lines
xen/arch/x86/boot/reloc.c +1 -5
@@ -55,50 +56,64 @@ static void *reloc_mbi_struct(void *old, unsigned int bytes)
     "    sub  %1,%0                   \n"
     "    and  $~15,%0                 \n"
     "    mov  %0,alloc-1b(%%edx)      \n"
-    "    mov  %0,%%edi                \n"
-    "    rep  movsb                   \n"
-       : "=&r" (new), "+c" (bytes), "+S" (old)
-	: : "edx", "edi", "memory");
-    return new;
+       : "=&r" (s) : "r" (bytes) : "edx", "memory");

Can't "bytes" use a simple "g" constraint now?

Preferably (i.e. if correct) this changed

Jan

#36 lore raw

Re: [PATCH v2 05/23] x86/boot/reloc: create generic alloc and copy functions

Quoted 14 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Create generic alloc and copy functions. We need separate tools for memory allocation and copy to provide multiboot2 protocol support.

Quoted 8 lines

---
v2 - suggestions/fixes:
- generalize new functions names
(suggested by Jan Beulich),
- reduce number of casts
(suggested by Jan Beulich).

Quoted 2 lines

This contradicts retaining Andrew's R-b tag. Please remember to drop tags for everything you make non-trivial changes to.

OK.

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/boot/reloc.c +0 -0
@@ -55,50 +56,64 @@ static void *reloc_mbi_struct(void *old, unsigned int bytes)
     "    sub  %1,%0                   \n"
     "    and  $~15,%0                 \n"
     "    mov  %0,alloc-1b(%%edx)      \n"
Quoted 8 lines

xen/arch/x86/boot/reloc.c static void *reloc_mbi_struct(void *old, unsigned int bytes) · line 59

Quoted 6 lines
xen/arch/x86/boot/reloc.c +1 -5
-    "    mov  %0,%%edi                \n"
-    "    rep  movsb                   \n"
-       : "=&r" (new), "+c" (bytes), "+S" (old)
-	: : "edx", "edi", "memory");
-    return new;
+       : "=&r" (s) : "r" (bytes) : "edx", "memory");

Can't "bytes" use a simple "g" constraint now?

Works...

Quoted 1 line

Preferably (i.e. if correct) this changed

..., so, I will change that.

Quoted 1 line

Thanks!

Daniel

#37 lore raw

PATCH v2 6/23 x86/boot: use %ecx instead of %eax

In reply to Daniel Kiper

Use %ecx instead of %eax to store low memory upper limit from EBDA. This way we do not wipe multiboot protocol identifier. It is needed in reloc() to differentiate between multiboot (v1) and multiboot2 protocol.

---
 xen/arch/x86/boot/head.S |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
xen/arch/x86/boot/head.S +12 -12
index 3cbb2e6..77e7da9 100644
@@ -87,14 +87,14 @@ __start:
         jne     not_multiboot
 
         /* Set up trampoline segment 64k below EBDA */
-        movzwl  0x40e,%eax          /* EBDA segment */
-        cmp     $0xa000,%eax        /* sanity check (high) */
+        movzwl  0x40e,%ecx          /* EBDA segment */
+        cmp     $0xa000,%ecx        /* sanity check (high) */
         jae     0f
-        cmp     $0x4000,%eax        /* sanity check (low) */
+        cmp     $0x4000,%ecx        /* sanity check (low) */
         jae     1f
 0:
-        movzwl  0x413,%eax          /* use base memory size on failure */
-        shl     $10-4,%eax
+        movzwl  0x413,%ecx          /* use base memory size on failure */
+        shl     $10-4,%ecx
 1:
         /*
          * Compare the value in the BDA with the information from the
@@ -106,21 +106,21 @@ __start:
         cmp     $0x100,%edx         /* is the multiboot value too small? */
         jb      2f                  /* if so, do not use it */
         shl     $10-4,%edx
-        cmp     %eax,%edx           /* compare with BDA value */
-        cmovb   %edx,%eax           /* and use the smaller */
+        cmp     %ecx,%edx           /* compare with BDA value */
+        cmovb   %edx,%ecx           /* and use the smaller */
 
 2:      /* Reserve 64kb for the trampoline */
-        sub     $0x1000,%eax
+        sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
-        xor     %al, %al
-        shl     $4, %eax
-        mov     %eax,sym_phys(trampoline_phys)
+        xor     %cl, %cl
+        shl     $4, %ecx
+        mov     %ecx,sym_phys(trampoline_phys)
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
         push    %ebx                /* Multiboot information address. */
-        push    %eax                /* Boot trampoline address. */
+        push    %ecx                /* Boot trampoline address. */
         call    reloc
         add     $8,%esp             /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
Signature · 1 line
1.7.10.4
#38 lore raw

PATCH v2 6/23 x86/boot: use %ecx instead of %eax

In reply to Daniel Kiper

Use %ecx instead of %eax to store low memory upper limit from EBDA. This way we do not wipe multiboot protocol identifier. It is needed in reloc() to differentiate between multiboot (v1) and multiboot2 protocol.

---
 xen/arch/x86/boot/head.S |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
xen/arch/x86/boot/head.S +12 -12
index 3cbb2e6..77e7da9 100644
@@ -87,14 +87,14 @@ __start:
         jne     not_multiboot
 
         /* Set up trampoline segment 64k below EBDA */
-        movzwl  0x40e,%eax          /* EBDA segment */
-        cmp     $0xa000,%eax        /* sanity check (high) */
+        movzwl  0x40e,%ecx          /* EBDA segment */
+        cmp     $0xa000,%ecx        /* sanity check (high) */
         jae     0f
-        cmp     $0x4000,%eax        /* sanity check (low) */
+        cmp     $0x4000,%ecx        /* sanity check (low) */
         jae     1f
 0:
-        movzwl  0x413,%eax          /* use base memory size on failure */
-        shl     $10-4,%eax
+        movzwl  0x413,%ecx          /* use base memory size on failure */
+        shl     $10-4,%ecx
 1:
         /*
          * Compare the value in the BDA with the information from the
@@ -106,21 +106,21 @@ __start:
         cmp     $0x100,%edx         /* is the multiboot value too small? */
         jb      2f                  /* if so, do not use it */
         shl     $10-4,%edx
-        cmp     %eax,%edx           /* compare with BDA value */
-        cmovb   %edx,%eax           /* and use the smaller */
+        cmp     %ecx,%edx           /* compare with BDA value */
+        cmovb   %edx,%ecx           /* and use the smaller */
 
 2:      /* Reserve 64kb for the trampoline */
-        sub     $0x1000,%eax
+        sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
-        xor     %al, %al
-        shl     $4, %eax
-        mov     %eax,sym_phys(trampoline_phys)
+        xor     %cl, %cl
+        shl     $4, %ecx
+        mov     %ecx,sym_phys(trampoline_phys)
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
         push    %ebx                /* Multiboot information address. */
-        push    %eax                /* Boot trampoline address. */
+        push    %ecx                /* Boot trampoline address. */
         call    reloc
         add     $8,%esp             /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
Signature · 1 line
1.7.10.4
Reviewed-by on v2 6/23
#39 lore raw

Re: [Xen-devel] [PATCH v2 06/23] x86/boot: use %ecx instead of %eax

Quoted 7 lines · Daniel Kiper

Use %ecx instead of %eax to store low memory upper limit from EBDA. This way we do not wipe multiboot protocol identifier. It is needed in reloc() to differentiate between multiboot (v1) and multiboot2 protocol.

Quoted 65 lines
---
 xen/arch/x86/boot/head.S |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
xen/arch/x86/boot/head.S +12 -12
index 3cbb2e6..77e7da9 100644
@@ -87,14 +87,14 @@ __start:
         jne     not_multiboot
 
         /* Set up trampoline segment 64k below EBDA */
-        movzwl  0x40e,%eax          /* EBDA segment */
-        cmp     $0xa000,%eax        /* sanity check (high) */
+        movzwl  0x40e,%ecx          /* EBDA segment */
+        cmp     $0xa000,%ecx        /* sanity check (high) */
         jae     0f
-        cmp     $0x4000,%eax        /* sanity check (low) */
+        cmp     $0x4000,%ecx        /* sanity check (low) */
         jae     1f
 0:
-        movzwl  0x413,%eax          /* use base memory size on failure */
-        shl     $10-4,%eax
+        movzwl  0x413,%ecx          /* use base memory size on failure */
+        shl     $10-4,%ecx
 1:
         /*
          * Compare the value in the BDA with the information from the
@@ -106,21 +106,21 @@ __start:
         cmp     $0x100,%edx         /* is the multiboot value too small? */
         jb      2f                  /* if so, do not use it */
         shl     $10-4,%edx
-        cmp     %eax,%edx           /* compare with BDA value */
-        cmovb   %edx,%eax           /* and use the smaller */
+        cmp     %ecx,%edx           /* compare with BDA value */
+        cmovb   %edx,%ecx           /* and use the smaller */
 
 2:      /* Reserve 64kb for the trampoline */
-        sub     $0x1000,%eax
+        sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
-        xor     %al, %al
-        shl     $4, %eax
-        mov     %eax,sym_phys(trampoline_phys)
+        xor     %cl, %cl
+        shl     $4, %ecx
+        mov     %ecx,sym_phys(trampoline_phys)
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
         push    %ebx                /* Multiboot information address. */
-        push    %eax                /* Boot trampoline address. */
+        push    %ecx                /* Boot trampoline address. */
         call    reloc
         add     $8,%esp             /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 6/23
#40 lore raw

Re: [PATCH v2 06/23] x86/boot: use %ecx instead of %eax

In reply to Daniel Kiper
Quoted 7 lines · Daniel Kiper

Use %ecx instead of %eax to store low memory upper limit from EBDA. This way we do not wipe multiboot protocol identifier. It is needed in reloc() to differentiate between multiboot (v1) and multiboot2 protocol.

Quoted 65 lines
---
 xen/arch/x86/boot/head.S |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
xen/arch/x86/boot/head.S +12 -12
index 3cbb2e6..77e7da9 100644
@@ -87,14 +87,14 @@ __start:
         jne     not_multiboot
 
         /* Set up trampoline segment 64k below EBDA */
-        movzwl  0x40e,%eax          /* EBDA segment */
-        cmp     $0xa000,%eax        /* sanity check (high) */
+        movzwl  0x40e,%ecx          /* EBDA segment */
+        cmp     $0xa000,%ecx        /* sanity check (high) */
         jae     0f
-        cmp     $0x4000,%eax        /* sanity check (low) */
+        cmp     $0x4000,%ecx        /* sanity check (low) */
         jae     1f
 0:
-        movzwl  0x413,%eax          /* use base memory size on failure */
-        shl     $10-4,%eax
+        movzwl  0x413,%ecx          /* use base memory size on failure */
+        shl     $10-4,%ecx
 1:
         /*
          * Compare the value in the BDA with the information from the
@@ -106,21 +106,21 @@ __start:
         cmp     $0x100,%edx         /* is the multiboot value too small? */
         jb      2f                  /* if so, do not use it */
         shl     $10-4,%edx
-        cmp     %eax,%edx           /* compare with BDA value */
-        cmovb   %edx,%eax           /* and use the smaller */
+        cmp     %ecx,%edx           /* compare with BDA value */
+        cmovb   %edx,%ecx           /* and use the smaller */
 
 2:      /* Reserve 64kb for the trampoline */
-        sub     $0x1000,%eax
+        sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
-        xor     %al, %al
-        shl     $4, %eax
-        mov     %eax,sym_phys(trampoline_phys)
+        xor     %cl, %cl
+        shl     $4, %ecx
+        mov     %ecx,sym_phys(trampoline_phys)
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
         push    %ebx                /* Multiboot information address. */
-        push    %eax                /* Boot trampoline address. */
+        push    %ecx                /* Boot trampoline address. */
         call    reloc
         add     $8,%esp             /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#41 lore raw

PATCH v2 7/23 x86/boot/reloc: Rename some variables and rearrange code a bit

In reply to Daniel Kiper

Rename mbi and mbi_old variables and rearrange code a bit to make it more readable. Additionally, this way multiboot (v1) protocol implementation and future multiboot2 protocol implementation will use the same variable naming convention.

---
v2 - suggestions/fixes:
- extract this change from main mutliboot2
protocol implementation
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/reloc.c |   39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
xen/arch/x86/boot/reloc.c +21 -18
index 09fd540..feb1d72 100644
@@ -86,41 +86,44 @@ static u32 copy_string(u32 src)
     return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t *reloc(u32 mbi_old)
+multiboot_info_t *reloc(u32 mbi_in)
 {
-    multiboot_info_t *mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi));
     int i;
+    multiboot_info_t *mbi_out;
 
-    if ( mbi->flags & MBI_CMDLINE )
-        mbi->cmdline = copy_string(mbi->cmdline);
+    mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));
 
-    if ( mbi->flags & MBI_MODULES )
+    if ( mbi_out->flags & MBI_CMDLINE )
+        mbi_out->cmdline = copy_string(mbi_out->cmdline);
+
+    if ( mbi_out->flags & MBI_MODULES )
     {
         module_t *mods;
 
-        mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+        mbi_out->mods_addr = copy_mem(mbi_out->mods_addr,
+                                      mbi_out->mods_count * sizeof(module_t));
 
-        mods = (module_t *)mbi->mods_addr;
+        mods = (module_t *)mbi_out->mods_addr;
 
-        for ( i = 0; i < mbi->mods_count; i++ )
+        for ( i = 0; i < mbi_out->mods_count; i++ )
         {
             if ( mods[i].string )
                 mods[i].string = copy_string(mods[i].string);
         }
     }
 
-    if ( mbi->flags & MBI_MEMMAP )
-        mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length);
+    if ( mbi_out->flags & MBI_MEMMAP )
+        mbi_out->mmap_addr = copy_mem(mbi_out->mmap_addr, mbi_out->mmap_length);
 
-    if ( mbi->flags & MBI_LOADERNAME )
-        mbi->boot_loader_name = copy_string(mbi->boot_loader_name);
+    if ( mbi_out->flags & MBI_LOADERNAME )
+        mbi_out->boot_loader_name = copy_string(mbi_out->boot_loader_name);
 
     /* Mask features we don't understand or don't relocate. */
-    mbi->flags &= (MBI_MEMLIMITS |
-                   MBI_CMDLINE |
-                   MBI_MODULES |
-                   MBI_MEMMAP |
-                   MBI_LOADERNAME);
+    mbi_out->flags &= (MBI_MEMLIMITS |
+                       MBI_CMDLINE |
+                       MBI_MODULES |
+                       MBI_MEMMAP |
+                       MBI_LOADERNAME);
 
-    return mbi;
+    return mbi_out;
 }
Signature · 1 line
1.7.10.4
#42 lore raw

PATCH v2 7/23 x86/boot/reloc: Rename some variables and rearrange code a bit

In reply to Daniel Kiper

Rename mbi and mbi_old variables and rearrange code a bit to make it more readable. Additionally, this way multiboot (v1) protocol implementation and future multiboot2 protocol implementation will use the same variable naming convention.

---
v2 - suggestions/fixes:
- extract this change from main mutliboot2
protocol implementation
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/reloc.c |   39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
xen/arch/x86/boot/reloc.c +21 -18
index 09fd540..feb1d72 100644
@@ -86,41 +86,44 @@ static u32 copy_string(u32 src)
     return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t *reloc(u32 mbi_old)
+multiboot_info_t *reloc(u32 mbi_in)
 {
-    multiboot_info_t *mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi));
     int i;
+    multiboot_info_t *mbi_out;
 
-    if ( mbi->flags & MBI_CMDLINE )
-        mbi->cmdline = copy_string(mbi->cmdline);
+    mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));
 
-    if ( mbi->flags & MBI_MODULES )
+    if ( mbi_out->flags & MBI_CMDLINE )
+        mbi_out->cmdline = copy_string(mbi_out->cmdline);
+
+    if ( mbi_out->flags & MBI_MODULES )
     {
         module_t *mods;
 
-        mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+        mbi_out->mods_addr = copy_mem(mbi_out->mods_addr,
+                                      mbi_out->mods_count * sizeof(module_t));
 
-        mods = (module_t *)mbi->mods_addr;
+        mods = (module_t *)mbi_out->mods_addr;
 
-        for ( i = 0; i < mbi->mods_count; i++ )
+        for ( i = 0; i < mbi_out->mods_count; i++ )
         {
             if ( mods[i].string )
                 mods[i].string = copy_string(mods[i].string);
         }
     }
 
-    if ( mbi->flags & MBI_MEMMAP )
-        mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length);
+    if ( mbi_out->flags & MBI_MEMMAP )
+        mbi_out->mmap_addr = copy_mem(mbi_out->mmap_addr, mbi_out->mmap_length);
 
-    if ( mbi->flags & MBI_LOADERNAME )
-        mbi->boot_loader_name = copy_string(mbi->boot_loader_name);
+    if ( mbi_out->flags & MBI_LOADERNAME )
+        mbi_out->boot_loader_name = copy_string(mbi_out->boot_loader_name);
 
     /* Mask features we don't understand or don't relocate. */
-    mbi->flags &= (MBI_MEMLIMITS |
-                   MBI_CMDLINE |
-                   MBI_MODULES |
-                   MBI_MEMMAP |
-                   MBI_LOADERNAME);
+    mbi_out->flags &= (MBI_MEMLIMITS |
+                       MBI_CMDLINE |
+                       MBI_MODULES |
+                       MBI_MEMMAP |
+                       MBI_LOADERNAME);
 
-    return mbi;
+    return mbi_out;
 }
Signature · 1 line
1.7.10.4
Reviewed-by on v2 7/23
#43 lore raw

Re: [PATCH v2 07/23] x86/boot/reloc: Rename some variables and rearrange code a bit

Quoted 1 line · Daniel Kiper

Rename mbi and mbi_old variables and rearrange code a bit to make

s/mbi_old/mbi_in/

Perhaps you want to say: rename mbi_old with mbi_in, and mbi with mbi_out

or better:

Replace mbi with mbi_out and mbi_old with mbi_in and ...

Quoted 5 lines

it more readable. Additionally, this way multiboot (v1) protocol implementation and future multiboot2 protocol implementation will use the same variable naming convention.

Quoted 84 lines

---
v2 - suggestions/fixes:
- extract this change from main mutliboot2
protocol implementation
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/reloc.c |   39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
xen/arch/x86/boot/reloc.c +21 -18
index 09fd540..feb1d72 100644
@@ -86,41 +86,44 @@ static u32 copy_string(u32 src)
     return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t *reloc(u32 mbi_old)
+multiboot_info_t *reloc(u32 mbi_in)
 {
-    multiboot_info_t *mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi));
     int i;
+    multiboot_info_t *mbi_out;
 
-    if ( mbi->flags & MBI_CMDLINE )
-        mbi->cmdline = copy_string(mbi->cmdline);
+    mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));
 
-    if ( mbi->flags & MBI_MODULES )
+    if ( mbi_out->flags & MBI_CMDLINE )
+        mbi_out->cmdline = copy_string(mbi_out->cmdline);
+
+    if ( mbi_out->flags & MBI_MODULES )
     {
         module_t *mods;
 
-        mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+        mbi_out->mods_addr = copy_mem(mbi_out->mods_addr,
+                                      mbi_out->mods_count * sizeof(module_t));
 
-        mods = (module_t *)mbi->mods_addr;
+        mods = (module_t *)mbi_out->mods_addr;
 
-        for ( i = 0; i < mbi->mods_count; i++ )
+        for ( i = 0; i < mbi_out->mods_count; i++ )
         {
             if ( mods[i].string )
                 mods[i].string = copy_string(mods[i].string);
         }
     }
 
-    if ( mbi->flags & MBI_MEMMAP )
-        mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length);
+    if ( mbi_out->flags & MBI_MEMMAP )
+        mbi_out->mmap_addr = copy_mem(mbi_out->mmap_addr, mbi_out->mmap_length);
 
-    if ( mbi->flags & MBI_LOADERNAME )
-        mbi->boot_loader_name = copy_string(mbi->boot_loader_name);
+    if ( mbi_out->flags & MBI_LOADERNAME )
+        mbi_out->boot_loader_name = copy_string(mbi_out->boot_loader_name);
 
     /* Mask features we don't understand or don't relocate. */
-    mbi->flags &= (MBI_MEMLIMITS |
-                   MBI_CMDLINE |
-                   MBI_MODULES |
-                   MBI_MEMMAP |
-                   MBI_LOADERNAME);
+    mbi_out->flags &= (MBI_MEMLIMITS |
+                       MBI_CMDLINE |
+                       MBI_MODULES |
+                       MBI_MEMMAP |
+                       MBI_LOADERNAME);
 
-    return mbi;
+    return mbi_out;
 }
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 7/23
#44 lore raw

Re: [Xen-devel] [PATCH v2 07/23] x86/boot/reloc: Rename some variables and rearrange code a bit

In reply to Daniel Kiper
Quoted 1 line · Daniel Kiper

Rename mbi and mbi_old variables and rearrange code a bit to make

s/mbi_old/mbi_in/

Perhaps you want to say: rename mbi_old with mbi_in, and mbi with mbi_out

or better:

Replace mbi with mbi_out and mbi_old with mbi_in and ...

Quoted 5 lines

it more readable. Additionally, this way multiboot (v1) protocol implementation and future multiboot2 protocol implementation will use the same variable naming convention.

Quoted 84 lines

---
v2 - suggestions/fixes:
- extract this change from main mutliboot2
protocol implementation
(suggested by Jan Beulich).

---
 xen/arch/x86/boot/reloc.c |   39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
xen/arch/x86/boot/reloc.c +21 -18
index 09fd540..feb1d72 100644
@@ -86,41 +86,44 @@ static u32 copy_string(u32 src)
     return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t *reloc(u32 mbi_old)
+multiboot_info_t *reloc(u32 mbi_in)
 {
-    multiboot_info_t *mbi = (multiboot_info_t *)copy_mem(mbi_old, sizeof(*mbi));
     int i;
+    multiboot_info_t *mbi_out;
 
-    if ( mbi->flags & MBI_CMDLINE )
-        mbi->cmdline = copy_string(mbi->cmdline);
+    mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));
 
-    if ( mbi->flags & MBI_MODULES )
+    if ( mbi_out->flags & MBI_CMDLINE )
+        mbi_out->cmdline = copy_string(mbi_out->cmdline);
+
+    if ( mbi_out->flags & MBI_MODULES )
     {
         module_t *mods;
 
-        mbi->mods_addr = copy_mem(mbi->mods_addr, mbi->mods_count * sizeof(module_t));
+        mbi_out->mods_addr = copy_mem(mbi_out->mods_addr,
+                                      mbi_out->mods_count * sizeof(module_t));
 
-        mods = (module_t *)mbi->mods_addr;
+        mods = (module_t *)mbi_out->mods_addr;
 
-        for ( i = 0; i < mbi->mods_count; i++ )
+        for ( i = 0; i < mbi_out->mods_count; i++ )
         {
             if ( mods[i].string )
                 mods[i].string = copy_string(mods[i].string);
         }
     }
 
-    if ( mbi->flags & MBI_MEMMAP )
-        mbi->mmap_addr = copy_mem(mbi->mmap_addr, mbi->mmap_length);
+    if ( mbi_out->flags & MBI_MEMMAP )
+        mbi_out->mmap_addr = copy_mem(mbi_out->mmap_addr, mbi_out->mmap_length);
 
-    if ( mbi->flags & MBI_LOADERNAME )
-        mbi->boot_loader_name = copy_string(mbi->boot_loader_name);
+    if ( mbi_out->flags & MBI_LOADERNAME )
+        mbi_out->boot_loader_name = copy_string(mbi_out->boot_loader_name);
 
     /* Mask features we don't understand or don't relocate. */
-    mbi->flags &= (MBI_MEMLIMITS |
-                   MBI_CMDLINE |
-                   MBI_MODULES |
-                   MBI_MEMMAP |
-                   MBI_LOADERNAME);
+    mbi_out->flags &= (MBI_MEMLIMITS |
+                       MBI_CMDLINE |
+                       MBI_MODULES |
+                       MBI_MEMMAP |
+                       MBI_LOADERNAME);
 
-    return mbi;
+    return mbi_out;
 }
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v2 7/23
#45 lore raw

Re: [PATCH v2 07/23] x86/boot/reloc: Rename some variables and rearrange code a bit

In reply to Daniel Kiper
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Rename mbi and mbi_old variables and rearrange code a bit to make it more readable. Additionally, this way multiboot (v1) protocol implementation and future multiboot2 protocol implementation will use the same variable naming convention.

Acked-by on v2 7/23
#46 lore raw

Re: [PATCH v2 07/23] x86/boot/reloc: Rename some variables and rearrange code a bit

In reply to Daniel Kiper
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Rename mbi and mbi_old variables and rearrange code a bit to make it more readable. Additionally, this way multiboot (v1) protocol implementation and future multiboot2 protocol implementation will use the same variable naming convention.

#47 lore raw

PATCH v2 8/23 x86: add multiboot2 protocol support

In reply to Daniel Kiper

Add multiboot2 protocol support. Alter min memory limit handling as we now may not find it from either multiboot (v1) or multiboot2.

This way we are laying the foundation for EFI + GRUB2 + Xen development.

---
v2 - suggestions/fixes:
- generate multiboot2 header using macros (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- simplify assembly in xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- do not include include/xen/compiler.h
in xen/arch/x86/boot/reloc.c
(suggested by Jan Beulich),
- do not read data beyond the end of Multiboot2 information (suggested by Jan Beulich).

v2 - not fixed yet:
- dynamic dependency generation for xen/arch/x86/boot/reloc.S; this requires more work; I am not sure that it pays because potential patch requires more changes than addition of just multiboot2.h to Makefile
(suggested by Jan Beulich),
- isolated/stray __packed attribute usage for multiboot2_memory_map_t (suggested by Jan Beulich).

---
 xen/arch/x86/boot/Makefile        |    3 +-
 xen/arch/x86/boot/head.S          |  105 +++++++++++++++++++++--
 xen/arch/x86/boot/reloc.c         |  146 +++++++++++++++++++++++++++++++-
 xen/arch/x86/x86_64/asm-offsets.c |    7 ++
 xen/include/xen/multiboot2.h      |  169 +++++++++++++++++++++++++++++++++++++
 5 files changed, 420 insertions(+), 10 deletions(-)
 create mode 100644 xen/include/xen/multiboot2.h
xen/arch/x86/boot/Makefile +2 -1
index 5fdb5ae..06893d8 100644
@@ -1,6 +1,7 @@
 obj-bin-y += head.o
 
-RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h
+RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \
+	     $(BASEDIR)/include/xen/multiboot2.h
 
 head.o: reloc.S
 
xen/arch/x86/boot/head.S +100 -5

146 lines not on this page · raw message

xen/arch/x86/boot/reloc.c +142 -4

195 lines not on this page · raw message

xen/arch/x86/x86_64/asm-offsets.c +7 -0
index 447c650..b926082 100644
@@ -13,6 +13,7 @@
 #include <asm/fixmap.h>
 #include <asm/hardirq.h>
 #include <xen/multiboot.h>
+#include <xen/multiboot2.h>
 
 #define DEFINE(_sym, _val)                                                 \
     asm volatile ("\n.ascii\"==>#define " #_sym " %0 /* " #_val " */<==\"" \
@@ -166,4 +167,10 @@ void __dummy__(void)
     OFFSET(MB_flags, multiboot_info_t, flags);
     OFFSET(MB_cmdline, multiboot_info_t, cmdline);
     OFFSET(MB_mem_lower, multiboot_info_t, mem_lower);
+    BLANK();
+
+    DEFINE(MB2_fixed_sizeof, sizeof(multiboot2_fixed_t));
+    OFFSET(MB2_tag_type, multiboot2_tag_t, type);
+    OFFSET(MB2_tag_size, multiboot2_tag_t, size);
+    OFFSET(MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);
 }
xen/include/xen/multiboot2.h new file +169 -0

169 lines not on this page · raw message

Signature · 1 line
1.7.10.4
Reviewed-by on v2 8/23
#48 lore raw

Re: [PATCH v2 08/23] x86: add multiboot2 protocol support

Quoted 21 lines · Daniel Kiper

Add multiboot2 protocol support. Alter min memory limit handling as we now may not find it from either multiboot (v1) or multiboot2.

This way we are laying the foundation for EFI + GRUB2 + Xen development.

---
v2 - suggestions/fixes:
- generate multiboot2 header using macros (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- simplify assembly in xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- do not include include/xen/compiler.h
in xen/arch/x86/boot/reloc.c
(suggested by Jan Beulich),
- do not read data beyond the end of Multiboot2 information (suggested by Jan Beulich).

Quoted 1 line

v2 - not fixed yet:

You have two 'v2'

Quoted 70 lines

- dynamic dependency generation for xen/arch/x86/boot/reloc.S; this requires more work; I am not sure that it pays because potential patch requires more changes than addition of just multiboot2.h to Makefile
(suggested by Jan Beulich),
- isolated/stray __packed attribute usage for multiboot2_memory_map_t (suggested by Jan Beulich).

---
 xen/arch/x86/boot/Makefile        |    3 +-
 xen/arch/x86/boot/head.S          |  105 +++++++++++++++++++++--
 xen/arch/x86/boot/reloc.c         |  146 +++++++++++++++++++++++++++++++-
 xen/arch/x86/x86_64/asm-offsets.c |    7 ++
 xen/include/xen/multiboot2.h      |  169 +++++++++++++++++++++++++++++++++++++
 5 files changed, 420 insertions(+), 10 deletions(-)
 create mode 100644 xen/include/xen/multiboot2.h
xen/arch/x86/boot/Makefile +2 -1
index 5fdb5ae..06893d8 100644
@@ -1,6 +1,7 @@
 obj-bin-y += head.o
 
-RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h
+RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \
+	     $(BASEDIR)/include/xen/multiboot2.h
 
 head.o: reloc.S
 
xen/arch/x86/boot/head.S +23 -0
index 77e7da9..57197db 100644
@@ -1,5 +1,6 @@
 #include <xen/config.h>
 #include <xen/multiboot.h>
+#include <xen/multiboot2.h>
 #include <public/xen.h>
 #include <asm/asm_defns.h>
 #include <asm/desc.h>
@@ -19,6 +20,28 @@
 #define BOOT_PSEUDORM_CS 0x0020
 #define BOOT_PSEUDORM_DS 0x0028
 
+#define MB2_HT(name)      (MULTIBOOT2_HEADER_TAG_##name)
+#define MB2_TT(name)      (MULTIBOOT2_TAG_TYPE_##name)
+
+        .macro mb2ht_args arg, args:vararg
+        .long \arg
+        .ifnb \args
+        mb2ht_args \args
+        .endif
+        .endm
+
+        .macro mb2ht_init type, req, args:vararg
+        .align MULTIBOOT2_TAG_ALIGN
+        0:
+        .short \type
+        .short \req
+        .long 1f - 0b
+        .ifnb \args
+        mb2ht_args \args
+        .endif
+        1:
+        .endm
+
 ENTRY(start)
         jmp     __start
 

xen/arch/x86/boot/head.S multiboot1_header_start: /*** MULTIBOOT1 HEADER ****/ · line 64

Quoted 8 lines
xen/arch/x86/boot/head.S +5 -0
@@ -34,6 +57,42 @@ multiboot1_header_start:       /*** MULTIBOOT1 HEADER ****/
         .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
 multiboot1_header_end:
 
+/*** MULTIBOOT2 HEADER ****/
+/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S file. */
+        .align  MULTIBOOT2_HEADER_ALIGN
+
+.Lmultiboot2_header:

How come you use .L? It makes this hidden while the multiboot1 headers are visible? Makes it a bit harder to see the contents of this under an debugger.

Quoted 50 lines
xen/arch/x86/boot/head.S +39 -1
+        /* Magic number indicating a Multiboot2 header. */
+        .long   MULTIBOOT2_HEADER_MAGIC
+        /* Architecture: i386. */
+        .long   MULTIBOOT2_ARCHITECTURE_I386
+        /* Multiboot2 header length. */
+        .long   .Lmultiboot2_header_end - .Lmultiboot2_header
+        /* Multiboot2 header checksum. */
+        .long   -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_ARCHITECTURE_I386 + \
+                        (.Lmultiboot2_header_end - .Lmultiboot2_header))
+
+        /* Multiboot2 information request tag. */
+        mb2ht_init MB2_HT(INFORMATION_REQUEST), MB2_HT(REQUIRED), \
+                   MB2_TT(BASIC_MEMINFO), MB2_TT(MMAP)
+
+        /* Align modules at page boundry. */
+        mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
+
+        /* Console flags tag. */
+        mb2ht_init MB2_HT(CONSOLE_FLAGS), MB2_HT(OPTIONAL), \
+                   MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED
+
+        /* Framebuffer tag. */
+        mb2ht_init MB2_HT(FRAMEBUFFER), MB2_HT(OPTIONAL), \
+                   0, /* Number of the columns - no preference. */ \
+                   0, /* Number of the lines - no preference. */ \
+                   0  /* Number of bits per pixel - no preference. */
+
+        /* Multiboot2 header end tag. */
+        mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
+.Lmultiboot2_header_end:
+
         .section .init.rodata, "a", @progbits
         .align 4
 
@@ -82,10 +141,48 @@ __start:
         mov     %ecx,%es
         mov     %ecx,%ss
 
-        /* Check for Multiboot bootloader */
+        /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value. */
+        xor     %edx,%edx
+
+        /* Check for Multiboot2 bootloader. */
+        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
+        je      multiboot2_proto
+
+        /* Check for Multiboot bootloader. */
         cmp     $MULTIBOOT_BOOTLOADER_MAGIC,%eax
         jne     not_multiboot
 

xen/arch/x86/boot/head.S __start: · line 164

Quoted 10 lines
xen/arch/x86/boot/head.S +10 -0
+        /* Get mem_lower from Multiboot information. */
+        testb   $MBI_MEMLIMITS,MB_flags(%ebx)
+
+        /* Not available? BDA value will be fine. */
+        cmovnz  MB_mem_lower(%ebx),%edx
+        jmp     trampoline_setup
+
+multiboot2_proto:
+        /* Skip Multiboot2 information fixed part. */
+        lea     MB2_fixed_sizeof(%ebx),%ecx

Is there any point of double checking the aligment? That is

        and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx

?

Looking at the grub code it requests the memory to be aligned properly so in practice this will never fail. But since somebody might for fun allocate the structure to not be aligned and the fixed part could finish on non-aligned space..

xen/arch/x86/boot/head.S __start: · line 168

Quoted 4 lines
xen/arch/x86/boot/head.S +4 -0
+
+0:
+        /* Get mem_lower from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,MB2_tag_type(%ecx)

.. which would throw this off..

Quoted 136 lines
xen/arch/x86/boot/head.S +19 -4
+        jne     1f
+
+        mov     MB2_mem_lower(%ecx),%edx
+        jmp     trampoline_setup
+
+1:
+        /* Is it the end of Multiboot2 information? */
+        cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx)
+        je      trampoline_setup
+
+        /* Go to next Multiboot2 information tag. */
+        add     MB2_tag_size(%ecx),%ecx
+        add     $(MULTIBOOT2_TAG_ALIGN-1),%ecx
+        and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
+        jmp     0b
+
+trampoline_setup:
         /* Set up trampoline segment 64k below EBDA */
         movzwl  0x40e,%ecx          /* EBDA segment */
         cmp     $0xa000,%ecx        /* sanity check (high) */
@@ -100,9 +197,6 @@ __start:
          * Compare the value in the BDA with the information from the
          * multiboot structure (if available) and use the smallest.
          */
-        testb   $MBI_MEMLIMITS,(%ebx)
-        jz      2f                  /* not available? BDA value will be fine */
-        mov     MB_mem_lower(%ebx),%edx
         cmp     $0x100,%edx         /* is the multiboot value too small? */
         jb      2f                  /* if so, do not use it */
         shl     $10-4,%edx
@@ -119,10 +213,11 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
+        push    %eax                /* Multiboot magic. */
         push    %ebx                /* Multiboot information address. */
         push    %ecx                /* Boot trampoline address. */
         call    reloc
-        add     $8,%esp             /* Remove reloc() args from stack. */
+        add     $12,%esp            /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
 
         /* Initialize BSS (no nasty surprises!). */
xen/arch/x86/boot/reloc.c +30 -4
index feb1d72..41b1cc0 100644
@@ -5,15 +5,18 @@
  * and modules. This is most easily done early with paging disabled.
  *
  * Copyright (c) 2009, Citrix Systems, Inc.
+ * Copyright (c) 2013, 2014, 2015 Oracle Co.
  *
  * Authors:
  *    Keir Fraser <[email protected]>
+ *    Daniel Kiper <[email protected]>
  */
 
 /*
  * This entry point is entered from xen/arch/x86/boot/head.S with:
  *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
- *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS.
+ *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS,
+ *   - 0xc(%esp) = MULTIBOOT_MAGIC.
  */
 asm (
     "    .text                         \n"
@@ -25,10 +28,12 @@ asm (
     "1:  pop  %ecx                     \n"
     "    mov  0x8(%ebp),%eax           \n"
     "    mov  %eax,alloc-1b(%ecx)      \n"
+    "    mov  0x10(%ebp),%eax          \n"
+    "    push %eax                     \n"
     "    mov  0xc(%ebp),%eax           \n"
     "    push %eax                     \n"
     "    call reloc                    \n"
-    "    add  $4,%esp                  \n"
+    "    add  $8,%esp                  \n"
     "    pop  %ebp                     \n"
     "    ret                           \n"
     );
@@ -43,7 +48,15 @@ asm (
     );
 
 typedef unsigned int u32;
+typedef unsigned long long u64;
+
 #include "../../../include/xen/multiboot.h"
+#include "../../../include/xen/multiboot2.h"
+
+#define ALIGN_UP(addr, align) \
+                (((addr) + (typeof(addr))(align) - 1) & ~((typeof(addr))(align) - 1))
+
+#define get_mb2_data(tag, type, member) (((type *)(tag))->member)
 
 static u32 alloc_mem(u32 bytes)
 {
@@ -61,6 +74,11 @@ static u32 alloc_mem(u32 bytes)
     return s;
 }
 
+static void zero_mem(u32 s, u32 bytes)
+{
+    asm volatile("rep stosb" : "+D" (s), "+c" (bytes) : "a" (0) : "memory");
+}
+
 static u32 copy_mem(u32 src, u32 bytes)
 {
     u32 dst, dst_asm;
@@ -86,12 +104,12 @@ static u32 copy_string(u32 src)
     return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t *reloc(u32 mbi_in)
+static multiboot_info_t *mbi_mbi(void *mbi_in)
 {
     int i;
     multiboot_info_t *mbi_out;
 
-    mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));
+    mbi_out = (multiboot_info_t *)copy_mem((u32)mbi_in, sizeof(*mbi_out));
 
     if ( mbi_out->flags & MBI_CMDLINE )
         mbi_out->cmdline = copy_string(mbi_out->cmdline);
@@ -127,3 +145,123 @@ multiboot_info_t *reloc(u32 mbi_in)
 
     return mbi_out;
 }
+
+static multiboot_info_t *mbi2_mbi(void *mbi_in)
+{
+    /* Do not complain that mbi_out_mods is not initialized. */
+    module_t *mbi_out_mods = (module_t *)0;
+    memory_map_t *mmap_dst;
+    multiboot2_memory_map_t *mmap_src;
+    multiboot2_tag_t *tag;

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 165

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+    multiboot_info_t *mbi_out;
+    u32 ptr;
+    unsigned int i, mod_idx = 0;
+
+    mbi_out = (multiboot_info_t *)alloc_mem(sizeof(*mbi_out));
+    zero_mem((u32)mbi_out, sizeof(*mbi_out));
+
+    /* Skip Multiboot2 information fixed part. */
+    tag = mbi_in + sizeof(multiboot2_fixed_t);
+

Could you add:

/* First we need to get the number of modules: */

Quoted 9 lines
xen/arch/x86/boot/reloc.c +9 -0
+    for ( ; ; )
+    {
+        if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE )
+            ++mbi_out->mods_count;
+        else if ( tag->type == MULTIBOOT2_TAG_TYPE_END )
+        {
+            mbi_out->flags = MBI_MODULES;
+            mbi_out->mods_addr = alloc_mem(mbi_out->mods_count * sizeof(module_t));
+            mbi_out_mods = (module_t *)mbi_out->mods_addr;

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 183

Quoted 10 lines
xen/arch/x86/boot/reloc.c +9 -0
 
+            break;
+        }
+
+        /* Go to next Multiboot2 information tag. */
+        tag = (multiboot2_tag_t *)(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN));
+
+        /* Check Multiboot2 information total size just in case. */
+	if ( (void *)tag - mbi_in >= ((multiboot2_fixed_t *)mbi_in)->total_size )
+            break;

This looks to be using the wrong amount of spaces.

Quoted 31 lines
xen/arch/x86/boot/reloc.c +31 -0
+    }
+
+    /* Skip Multiboot2 information fixed part. */
+    tag = mbi_in + sizeof(multiboot2_fixed_t);
+
+    for ( ; ; )
+    {
+        switch ( tag->type )
+        {
+        case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME:
+            mbi_out->flags |= MBI_LOADERNAME;
+            ptr = (u32)get_mb2_data(tag, multiboot2_tag_string_t, string);
+            mbi_out->boot_loader_name = copy_string(ptr);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_CMDLINE:
+            mbi_out->flags |= MBI_CMDLINE;
+            ptr = (u32)get_mb2_data(tag, multiboot2_tag_string_t, string);
+            mbi_out->cmdline = copy_string(ptr);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO:
+            mbi_out->flags |= MBI_MEMLIMITS;
+            mbi_out->mem_lower = get_mb2_data(tag, multiboot2_tag_basic_meminfo_t, mem_lower);
+            mbi_out->mem_upper = get_mb2_data(tag, multiboot2_tag_basic_meminfo_t, mem_upper);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, multiboot2_tag_mmap_t, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 224

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+            mbi_out->mmap_length += sizeof(((multiboot2_tag_mmap_t){0}).entries);
+            mbi_out->mmap_length /= get_mb2_data(tag, multiboot2_tag_mmap_t, entry_size);
+            mbi_out->mmap_length *= sizeof(memory_map_t);
+
+            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
+
+            mmap_src = get_mb2_data(tag, multiboot2_tag_mmap_t, entries);
+            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;
+
+            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); ++i )

The other loops use 'i++'. Could it be the same type?

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 227

Quoted 3 lines
xen/arch/x86/boot/reloc.c +3 -0
+            {
+                mmap_dst[i].size = sizeof(memory_map_t);
+                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);

Could you add a comment like this please:?

/* 'size' does not exist in MB2, but __start_xen requires it to enumerate
* properly. */

Quoted 20 lines
xen/arch/x86/boot/reloc.c +20 -0
+                mmap_dst[i].base_addr_low = (u32)mmap_src[i].addr;
+                mmap_dst[i].base_addr_high = (u32)(mmap_src[i].addr >> 32);
+                mmap_dst[i].length_low = (u32)mmap_src[i].len;
+                mmap_dst[i].length_high = (u32)(mmap_src[i].len >> 32);
+                mmap_dst[i].type = mmap_src[i].type;
+            }
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_MODULE:
+            mbi_out_mods[mod_idx].mod_start = get_mb2_data(tag, multiboot2_tag_module_t, mod_start);
+            mbi_out_mods[mod_idx].mod_end = get_mb2_data(tag, multiboot2_tag_module_t, mod_end);
+            ptr = (u32)get_mb2_data(tag, multiboot2_tag_module_t, cmdline);
+            mbi_out_mods[mod_idx].string = copy_string(ptr);
+            mbi_out_mods[mod_idx].reserved = 0;
+            ++mod_idx;
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_END:
+            return mbi_out;
+

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 257

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+        default:
+            break;
+        }
+
+        /* Go to next Multiboot2 information tag. */
+        tag = (multiboot2_tag_t *)(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN));
+
+        /* Check Multiboot2 information total size just in case. */
+	if ( (void *)tag - mbi_in >= ((multiboot2_fixed_t *)mbi_in)->total_size )
+            return mbi_out;

Not enough spaces.

Quoted 111 lines
xen/arch/x86/boot/reloc.c +10 -0
+    }
+}
+
+static multiboot_info_t __attribute__((__used__)) *reloc(void *mbi_in, u32 mb_magic)
+{
+    if ( mb_magic == MULTIBOOT2_BOOTLOADER_MAGIC )
+        return mbi2_mbi(mbi_in);
+    else
+        return mbi_mbi(mbi_in);
+}
xen/arch/x86/x86_64/asm-offsets.c +7 -0
index 447c650..b926082 100644
@@ -13,6 +13,7 @@
 #include <asm/fixmap.h>
 #include <asm/hardirq.h>
 #include <xen/multiboot.h>
+#include <xen/multiboot2.h>
 
 #define DEFINE(_sym, _val)                                                 \
     asm volatile ("\n.ascii\"==>#define " #_sym " %0 /* " #_val " */<==\"" \
@@ -166,4 +167,10 @@ void __dummy__(void)
     OFFSET(MB_flags, multiboot_info_t, flags);
     OFFSET(MB_cmdline, multiboot_info_t, cmdline);
     OFFSET(MB_mem_lower, multiboot_info_t, mem_lower);
+    BLANK();
+
+    DEFINE(MB2_fixed_sizeof, sizeof(multiboot2_fixed_t));
+    OFFSET(MB2_tag_type, multiboot2_tag_t, type);
+    OFFSET(MB2_tag_size, multiboot2_tag_t, size);
+    OFFSET(MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);
 }
xen/include/xen/multiboot2.h new file +72 -0
new file mode 100644
index 0000000..09ee64e
@@ -0,0 +1,169 @@
+/*
+ *  Copyright (C) 1999,2003,2007,2008,2009,2010  Free Software Foundation, Inc.
+ *
+ *  multiboot2.h - Multiboot 2 header file.
+ *
+ *  Based on grub-2.00/include/multiboot2.h file.
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
+ *  of this software and associated documentation files (the "Software"), to
+ *  deal in the Software without restriction, including without limitation the
+ *  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ *  sell copies of the Software, and to permit persons to whom the Software is
+ *  furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL ANY
+ *  DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ *  IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __MULTIBOOT2_H__
+#define __MULTIBOOT2_H__
+
+/* The magic field should contain this.  */
+#define MULTIBOOT2_HEADER_MAGIC			0xe85250d6
+
+/* This should be in %eax on x86 architecture.  */
+#define MULTIBOOT2_BOOTLOADER_MAGIC		0x36d76289
+
+/* How many bytes from the start of the file we search for the header.  */
+#define MULTIBOOT2_SEARCH			32768
+
+/* Multiboot 2 header alignment. */
+#define MULTIBOOT2_HEADER_ALIGN			8
+
+/* Alignment of multiboot 2 modules.  */
+#define MULTIBOOT2_MOD_ALIGN			0x00001000
+
+/* Alignment of the multiboot 2 info structure.  */
+#define MULTIBOOT2_INFO_ALIGN			0x00000008
+
+/* Multiboot 2 architectures. */
+#define MULTIBOOT2_ARCHITECTURE_I386	0
+#define MULTIBOOT2_ARCHITECTURE_MIPS32	4
+
+/* Header tag types. */
+#define MULTIBOOT2_HEADER_TAG_END			0
+#define MULTIBOOT2_HEADER_TAG_INFORMATION_REQUEST	1
+#define MULTIBOOT2_HEADER_TAG_ADDRESS			2
+#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS		3
+#define MULTIBOOT2_HEADER_TAG_CONSOLE_FLAGS		4
+#define MULTIBOOT2_HEADER_TAG_FRAMEBUFFER		5
+#define MULTIBOOT2_HEADER_TAG_MODULE_ALIGN		6
+#define MULTIBOOT2_HEADER_TAG_EFI_BS			7
+#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI32	8
+#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64	9
+
+/* Header tag flags. */
+#define MULTIBOOT2_HEADER_TAG_REQUIRED	0
+#define MULTIBOOT2_HEADER_TAG_OPTIONAL	1
+
+/* Header console tag console_flags. */
+#define MULTIBOOT2_CONSOLE_FLAGS_CONSOLE_REQUIRED	1
+#define MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED	2
+
+/* Flags set in the 'flags' member of the multiboot header.  */
+#define MULTIBOOT2_TAG_TYPE_END			0

xen/include/xen/multiboot2.h line 82

Quoted 10 lines
xen/include/xen/multiboot2.h new file +10 -0
+#define MULTIBOOT2_TAG_TYPE_CMDLINE		1
+#define MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME	2
+#define MULTIBOOT2_TAG_TYPE_MODULE		3
+#define MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO	4
+#define MULTIBOOT2_TAG_TYPE_BOOTDEV		5
+#define MULTIBOOT2_TAG_TYPE_MMAP		6
+#define MULTIBOOT2_TAG_TYPE_VBE			7
+#define MULTIBOOT2_TAG_TYPE_FRAMEBUFFER		8
+#define MULTIBOOT2_TAG_TYPE_ELF_SECTIONS	9
+#define MULTIBOOT2_TAG_TYPE_APM			10

In the grub code those all look actually in the same column.

I presume it is due to the '2'. But perhaps we can make this whole file have the values at around the same column?

Also for the MULTIBOOT2_BOOTLOADER_MAGIC, ..MOD_ALIGN, INFO_ALIGN, etc.

Quoted 15 lines
xen/include/xen/multiboot2.h new file +15 -0
+#define MULTIBOOT2_TAG_TYPE_EFI32		11
+#define MULTIBOOT2_TAG_TYPE_EFI64		12
+#define MULTIBOOT2_TAG_TYPE_SMBIOS		13
+#define MULTIBOOT2_TAG_TYPE_ACPI_OLD		14
+#define MULTIBOOT2_TAG_TYPE_ACPI_NEW		15
+#define MULTIBOOT2_TAG_TYPE_NETWORK		16
+#define MULTIBOOT2_TAG_TYPE_EFI_MMAP		17
+#define MULTIBOOT2_TAG_TYPE_EFI_BS		18
+#define MULTIBOOT2_TAG_TYPE_EFI32_IH		19
+#define MULTIBOOT2_TAG_TYPE_EFI64_IH		20
+
+/* Multiboot 2 tag alignment. */
+#define MULTIBOOT2_TAG_ALIGN			8
+
+/* Memory types. */

xen/include/xen/multiboot2.h line 107

Quoted 10 lines
xen/include/xen/multiboot2.h new file +10 -0
+#define MULTIBOOT2_MEMORY_AVAILABLE		1
+#define MULTIBOOT2_MEMORY_RESERVED		2
+#define MULTIBOOT2_MEMORY_ACPI_RECLAIMABLE	3
+#define MULTIBOOT2_MEMORY_NVS			4
+#define MULTIBOOT2_MEMORY_BADRAM		5
+
+/* Framebuffer types. */
+#define MULTIBOOT2_FRAMEBUFFER_TYPE_INDEXED	0
+#define MULTIBOOT2_FRAMEBUFFER_TYPE_RGB		1
+#define MULTIBOOT2_FRAMEBUFFER_TYPE_EGA_TEXT	2

And these.

Otherwise,

Quoted 70 lines
xen/include/xen/multiboot2.h new file +62 -0
+
+#ifndef __ASSEMBLY__
+typedef struct {
+    u32 total_size;
+    u32 reserved;
+} multiboot2_fixed_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+} multiboot2_tag_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    char string[0];
+} multiboot2_tag_string_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u32 mem_lower;
+    u32 mem_upper;
+} multiboot2_tag_basic_meminfo_t;
+
+typedef struct __packed {
+    u64 addr;
+    u64 len;
+    u32 type;
+    u32 zero;
+} multiboot2_memory_map_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u32 entry_size;
+    u32 entry_version;
+    multiboot2_memory_map_t entries[0];
+} multiboot2_tag_mmap_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u64 pointer;
+} multiboot2_tag_efi64_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u64 pointer;
+} multiboot2_tag_efi64_ih_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u32 mod_start;
+    u32 mod_end;
+    char cmdline[0];
+} multiboot2_tag_module_t;
+#endif /* __ASSEMBLY__ */
+
+#endif /* __MULTIBOOT2_H__ */
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 8/23
#49 lore raw

Re: [Xen-devel] [PATCH v2 08/23] x86: add multiboot2 protocol support

In reply to Daniel Kiper
Quoted 21 lines · Daniel Kiper

Add multiboot2 protocol support. Alter min memory limit handling as we now may not find it from either multiboot (v1) or multiboot2.

This way we are laying the foundation for EFI + GRUB2 + Xen development.

---
v2 - suggestions/fixes:
- generate multiboot2 header using macros (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- simplify assembly in xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- do not include include/xen/compiler.h
in xen/arch/x86/boot/reloc.c
(suggested by Jan Beulich),
- do not read data beyond the end of Multiboot2 information (suggested by Jan Beulich).

Quoted 1 line

v2 - not fixed yet:

You have two 'v2'

Quoted 70 lines

- dynamic dependency generation for xen/arch/x86/boot/reloc.S; this requires more work; I am not sure that it pays because potential patch requires more changes than addition of just multiboot2.h to Makefile
(suggested by Jan Beulich),
- isolated/stray __packed attribute usage for multiboot2_memory_map_t (suggested by Jan Beulich).

---
 xen/arch/x86/boot/Makefile        |    3 +-
 xen/arch/x86/boot/head.S          |  105 +++++++++++++++++++++--
 xen/arch/x86/boot/reloc.c         |  146 +++++++++++++++++++++++++++++++-
 xen/arch/x86/x86_64/asm-offsets.c |    7 ++
 xen/include/xen/multiboot2.h      |  169 +++++++++++++++++++++++++++++++++++++
 5 files changed, 420 insertions(+), 10 deletions(-)
 create mode 100644 xen/include/xen/multiboot2.h
xen/arch/x86/boot/Makefile +2 -1
index 5fdb5ae..06893d8 100644
@@ -1,6 +1,7 @@
 obj-bin-y += head.o
 
-RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h
+RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \
+	     $(BASEDIR)/include/xen/multiboot2.h
 
 head.o: reloc.S
 
xen/arch/x86/boot/head.S +23 -0
index 77e7da9..57197db 100644
@@ -1,5 +1,6 @@
 #include <xen/config.h>
 #include <xen/multiboot.h>
+#include <xen/multiboot2.h>
 #include <public/xen.h>
 #include <asm/asm_defns.h>
 #include <asm/desc.h>
@@ -19,6 +20,28 @@
 #define BOOT_PSEUDORM_CS 0x0020
 #define BOOT_PSEUDORM_DS 0x0028
 
+#define MB2_HT(name)      (MULTIBOOT2_HEADER_TAG_##name)
+#define MB2_TT(name)      (MULTIBOOT2_TAG_TYPE_##name)
+
+        .macro mb2ht_args arg, args:vararg
+        .long \arg
+        .ifnb \args
+        mb2ht_args \args
+        .endif
+        .endm
+
+        .macro mb2ht_init type, req, args:vararg
+        .align MULTIBOOT2_TAG_ALIGN
+        0:
+        .short \type
+        .short \req
+        .long 1f - 0b
+        .ifnb \args
+        mb2ht_args \args
+        .endif
+        1:
+        .endm
+
 ENTRY(start)
         jmp     __start
 

xen/arch/x86/boot/head.S multiboot1_header_start: /*** MULTIBOOT1 HEADER ****/ · line 64

Quoted 8 lines
xen/arch/x86/boot/head.S +5 -0
@@ -34,6 +57,42 @@ multiboot1_header_start:       /*** MULTIBOOT1 HEADER ****/
         .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
 multiboot1_header_end:
 
+/*** MULTIBOOT2 HEADER ****/
+/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S file. */
+        .align  MULTIBOOT2_HEADER_ALIGN
+
+.Lmultiboot2_header:

How come you use .L? It makes this hidden while the multiboot1 headers are visible? Makes it a bit harder to see the contents of this under an debugger.

Quoted 50 lines
xen/arch/x86/boot/head.S +39 -1
+        /* Magic number indicating a Multiboot2 header. */
+        .long   MULTIBOOT2_HEADER_MAGIC
+        /* Architecture: i386. */
+        .long   MULTIBOOT2_ARCHITECTURE_I386
+        /* Multiboot2 header length. */
+        .long   .Lmultiboot2_header_end - .Lmultiboot2_header
+        /* Multiboot2 header checksum. */
+        .long   -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_ARCHITECTURE_I386 + \
+                        (.Lmultiboot2_header_end - .Lmultiboot2_header))
+
+        /* Multiboot2 information request tag. */
+        mb2ht_init MB2_HT(INFORMATION_REQUEST), MB2_HT(REQUIRED), \
+                   MB2_TT(BASIC_MEMINFO), MB2_TT(MMAP)
+
+        /* Align modules at page boundry. */
+        mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
+
+        /* Console flags tag. */
+        mb2ht_init MB2_HT(CONSOLE_FLAGS), MB2_HT(OPTIONAL), \
+                   MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED
+
+        /* Framebuffer tag. */
+        mb2ht_init MB2_HT(FRAMEBUFFER), MB2_HT(OPTIONAL), \
+                   0, /* Number of the columns - no preference. */ \
+                   0, /* Number of the lines - no preference. */ \
+                   0  /* Number of bits per pixel - no preference. */
+
+        /* Multiboot2 header end tag. */
+        mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
+.Lmultiboot2_header_end:
+
         .section .init.rodata, "a", @progbits
         .align 4
 
@@ -82,10 +141,48 @@ __start:
         mov     %ecx,%es
         mov     %ecx,%ss
 
-        /* Check for Multiboot bootloader */
+        /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value. */
+        xor     %edx,%edx
+
+        /* Check for Multiboot2 bootloader. */
+        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
+        je      multiboot2_proto
+
+        /* Check for Multiboot bootloader. */
         cmp     $MULTIBOOT_BOOTLOADER_MAGIC,%eax
         jne     not_multiboot
 

xen/arch/x86/boot/head.S __start: · line 164

Quoted 10 lines
xen/arch/x86/boot/head.S +10 -0
+        /* Get mem_lower from Multiboot information. */
+        testb   $MBI_MEMLIMITS,MB_flags(%ebx)
+
+        /* Not available? BDA value will be fine. */
+        cmovnz  MB_mem_lower(%ebx),%edx
+        jmp     trampoline_setup
+
+multiboot2_proto:
+        /* Skip Multiboot2 information fixed part. */
+        lea     MB2_fixed_sizeof(%ebx),%ecx

Is there any point of double checking the aligment? That is

        and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx

?

Looking at the grub code it requests the memory to be aligned properly so in practice this will never fail. But since somebody might for fun allocate the structure to not be aligned and the fixed part could finish on non-aligned space..

xen/arch/x86/boot/head.S __start: · line 168

Quoted 4 lines
xen/arch/x86/boot/head.S +4 -0
+
+0:
+        /* Get mem_lower from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,MB2_tag_type(%ecx)

.. which would throw this off..

Quoted 136 lines
xen/arch/x86/boot/head.S +19 -4
+        jne     1f
+
+        mov     MB2_mem_lower(%ecx),%edx
+        jmp     trampoline_setup
+
+1:
+        /* Is it the end of Multiboot2 information? */
+        cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx)
+        je      trampoline_setup
+
+        /* Go to next Multiboot2 information tag. */
+        add     MB2_tag_size(%ecx),%ecx
+        add     $(MULTIBOOT2_TAG_ALIGN-1),%ecx
+        and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
+        jmp     0b
+
+trampoline_setup:
         /* Set up trampoline segment 64k below EBDA */
         movzwl  0x40e,%ecx          /* EBDA segment */
         cmp     $0xa000,%ecx        /* sanity check (high) */
@@ -100,9 +197,6 @@ __start:
          * Compare the value in the BDA with the information from the
          * multiboot structure (if available) and use the smallest.
          */
-        testb   $MBI_MEMLIMITS,(%ebx)
-        jz      2f                  /* not available? BDA value will be fine */
-        mov     MB_mem_lower(%ebx),%edx
         cmp     $0x100,%edx         /* is the multiboot value too small? */
         jb      2f                  /* if so, do not use it */
         shl     $10-4,%edx
@@ -119,10 +213,11 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
+        push    %eax                /* Multiboot magic. */
         push    %ebx                /* Multiboot information address. */
         push    %ecx                /* Boot trampoline address. */
         call    reloc
-        add     $8,%esp             /* Remove reloc() args from stack. */
+        add     $12,%esp            /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
 
         /* Initialize BSS (no nasty surprises!). */
xen/arch/x86/boot/reloc.c +30 -4
index feb1d72..41b1cc0 100644
@@ -5,15 +5,18 @@
  * and modules. This is most easily done early with paging disabled.
  *
  * Copyright (c) 2009, Citrix Systems, Inc.
+ * Copyright (c) 2013, 2014, 2015 Oracle Co.
  *
  * Authors:
  *    Keir Fraser <[email protected]>
+ *    Daniel Kiper <[email protected]>
  */
 
 /*
  * This entry point is entered from xen/arch/x86/boot/head.S with:
  *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
- *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS.
+ *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS,
+ *   - 0xc(%esp) = MULTIBOOT_MAGIC.
  */
 asm (
     "    .text                         \n"
@@ -25,10 +28,12 @@ asm (
     "1:  pop  %ecx                     \n"
     "    mov  0x8(%ebp),%eax           \n"
     "    mov  %eax,alloc-1b(%ecx)      \n"
+    "    mov  0x10(%ebp),%eax          \n"
+    "    push %eax                     \n"
     "    mov  0xc(%ebp),%eax           \n"
     "    push %eax                     \n"
     "    call reloc                    \n"
-    "    add  $4,%esp                  \n"
+    "    add  $8,%esp                  \n"
     "    pop  %ebp                     \n"
     "    ret                           \n"
     );
@@ -43,7 +48,15 @@ asm (
     );
 
 typedef unsigned int u32;
+typedef unsigned long long u64;
+
 #include "../../../include/xen/multiboot.h"
+#include "../../../include/xen/multiboot2.h"
+
+#define ALIGN_UP(addr, align) \
+                (((addr) + (typeof(addr))(align) - 1) & ~((typeof(addr))(align) - 1))
+
+#define get_mb2_data(tag, type, member) (((type *)(tag))->member)
 
 static u32 alloc_mem(u32 bytes)
 {
@@ -61,6 +74,11 @@ static u32 alloc_mem(u32 bytes)
     return s;
 }
 
+static void zero_mem(u32 s, u32 bytes)
+{
+    asm volatile("rep stosb" : "+D" (s), "+c" (bytes) : "a" (0) : "memory");
+}
+
 static u32 copy_mem(u32 src, u32 bytes)
 {
     u32 dst, dst_asm;
@@ -86,12 +104,12 @@ static u32 copy_string(u32 src)
     return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t *reloc(u32 mbi_in)
+static multiboot_info_t *mbi_mbi(void *mbi_in)
 {
     int i;
     multiboot_info_t *mbi_out;
 
-    mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));
+    mbi_out = (multiboot_info_t *)copy_mem((u32)mbi_in, sizeof(*mbi_out));
 
     if ( mbi_out->flags & MBI_CMDLINE )
         mbi_out->cmdline = copy_string(mbi_out->cmdline);
@@ -127,3 +145,123 @@ multiboot_info_t *reloc(u32 mbi_in)
 
     return mbi_out;
 }
+
+static multiboot_info_t *mbi2_mbi(void *mbi_in)
+{
+    /* Do not complain that mbi_out_mods is not initialized. */
+    module_t *mbi_out_mods = (module_t *)0;
+    memory_map_t *mmap_dst;
+    multiboot2_memory_map_t *mmap_src;
+    multiboot2_tag_t *tag;

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 165

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+    multiboot_info_t *mbi_out;
+    u32 ptr;
+    unsigned int i, mod_idx = 0;
+
+    mbi_out = (multiboot_info_t *)alloc_mem(sizeof(*mbi_out));
+    zero_mem((u32)mbi_out, sizeof(*mbi_out));
+
+    /* Skip Multiboot2 information fixed part. */
+    tag = mbi_in + sizeof(multiboot2_fixed_t);
+

Could you add:

/* First we need to get the number of modules: */

Quoted 9 lines
xen/arch/x86/boot/reloc.c +9 -0
+    for ( ; ; )
+    {
+        if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE )
+            ++mbi_out->mods_count;
+        else if ( tag->type == MULTIBOOT2_TAG_TYPE_END )
+        {
+            mbi_out->flags = MBI_MODULES;
+            mbi_out->mods_addr = alloc_mem(mbi_out->mods_count * sizeof(module_t));
+            mbi_out_mods = (module_t *)mbi_out->mods_addr;

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 183

Quoted 10 lines
xen/arch/x86/boot/reloc.c +9 -0
 
+            break;
+        }
+
+        /* Go to next Multiboot2 information tag. */
+        tag = (multiboot2_tag_t *)(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN));
+
+        /* Check Multiboot2 information total size just in case. */
+	if ( (void *)tag - mbi_in >= ((multiboot2_fixed_t *)mbi_in)->total_size )
+            break;

This looks to be using the wrong amount of spaces.

Quoted 31 lines
xen/arch/x86/boot/reloc.c +31 -0
+    }
+
+    /* Skip Multiboot2 information fixed part. */
+    tag = mbi_in + sizeof(multiboot2_fixed_t);
+
+    for ( ; ; )
+    {
+        switch ( tag->type )
+        {
+        case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME:
+            mbi_out->flags |= MBI_LOADERNAME;
+            ptr = (u32)get_mb2_data(tag, multiboot2_tag_string_t, string);
+            mbi_out->boot_loader_name = copy_string(ptr);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_CMDLINE:
+            mbi_out->flags |= MBI_CMDLINE;
+            ptr = (u32)get_mb2_data(tag, multiboot2_tag_string_t, string);
+            mbi_out->cmdline = copy_string(ptr);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO:
+            mbi_out->flags |= MBI_MEMLIMITS;
+            mbi_out->mem_lower = get_mb2_data(tag, multiboot2_tag_basic_meminfo_t, mem_lower);
+            mbi_out->mem_upper = get_mb2_data(tag, multiboot2_tag_basic_meminfo_t, mem_upper);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, multiboot2_tag_mmap_t, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 224

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+            mbi_out->mmap_length += sizeof(((multiboot2_tag_mmap_t){0}).entries);
+            mbi_out->mmap_length /= get_mb2_data(tag, multiboot2_tag_mmap_t, entry_size);
+            mbi_out->mmap_length *= sizeof(memory_map_t);
+
+            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
+
+            mmap_src = get_mb2_data(tag, multiboot2_tag_mmap_t, entries);
+            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;
+
+            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); ++i )

The other loops use 'i++'. Could it be the same type?

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 227

Quoted 3 lines
xen/arch/x86/boot/reloc.c +3 -0
+            {
+                mmap_dst[i].size = sizeof(memory_map_t);
+                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);

Could you add a comment like this please:?

/* 'size' does not exist in MB2, but __start_xen requires it to enumerate
* properly. */

Quoted 20 lines
xen/arch/x86/boot/reloc.c +20 -0
+                mmap_dst[i].base_addr_low = (u32)mmap_src[i].addr;
+                mmap_dst[i].base_addr_high = (u32)(mmap_src[i].addr >> 32);
+                mmap_dst[i].length_low = (u32)mmap_src[i].len;
+                mmap_dst[i].length_high = (u32)(mmap_src[i].len >> 32);
+                mmap_dst[i].type = mmap_src[i].type;
+            }
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_MODULE:
+            mbi_out_mods[mod_idx].mod_start = get_mb2_data(tag, multiboot2_tag_module_t, mod_start);
+            mbi_out_mods[mod_idx].mod_end = get_mb2_data(tag, multiboot2_tag_module_t, mod_end);
+            ptr = (u32)get_mb2_data(tag, multiboot2_tag_module_t, cmdline);
+            mbi_out_mods[mod_idx].string = copy_string(ptr);
+            mbi_out_mods[mod_idx].reserved = 0;
+            ++mod_idx;
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_END:
+            return mbi_out;
+

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 257

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+        default:
+            break;
+        }
+
+        /* Go to next Multiboot2 information tag. */
+        tag = (multiboot2_tag_t *)(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN));
+
+        /* Check Multiboot2 information total size just in case. */
+	if ( (void *)tag - mbi_in >= ((multiboot2_fixed_t *)mbi_in)->total_size )
+            return mbi_out;

Not enough spaces.

Quoted 111 lines
xen/arch/x86/boot/reloc.c +10 -0
+    }
+}
+
+static multiboot_info_t __attribute__((__used__)) *reloc(void *mbi_in, u32 mb_magic)
+{
+    if ( mb_magic == MULTIBOOT2_BOOTLOADER_MAGIC )
+        return mbi2_mbi(mbi_in);
+    else
+        return mbi_mbi(mbi_in);
+}
xen/arch/x86/x86_64/asm-offsets.c +7 -0
index 447c650..b926082 100644
@@ -13,6 +13,7 @@
 #include <asm/fixmap.h>
 #include <asm/hardirq.h>
 #include <xen/multiboot.h>
+#include <xen/multiboot2.h>
 
 #define DEFINE(_sym, _val)                                                 \
     asm volatile ("\n.ascii\"==>#define " #_sym " %0 /* " #_val " */<==\"" \
@@ -166,4 +167,10 @@ void __dummy__(void)
     OFFSET(MB_flags, multiboot_info_t, flags);
     OFFSET(MB_cmdline, multiboot_info_t, cmdline);
     OFFSET(MB_mem_lower, multiboot_info_t, mem_lower);
+    BLANK();
+
+    DEFINE(MB2_fixed_sizeof, sizeof(multiboot2_fixed_t));
+    OFFSET(MB2_tag_type, multiboot2_tag_t, type);
+    OFFSET(MB2_tag_size, multiboot2_tag_t, size);
+    OFFSET(MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);
 }
xen/include/xen/multiboot2.h new file +72 -0
new file mode 100644
index 0000000..09ee64e
@@ -0,0 +1,169 @@
+/*
+ *  Copyright (C) 1999,2003,2007,2008,2009,2010  Free Software Foundation, Inc.
+ *
+ *  multiboot2.h - Multiboot 2 header file.
+ *
+ *  Based on grub-2.00/include/multiboot2.h file.
+ *
+ *  Permission is hereby granted, free of charge, to any person obtaining a copy
+ *  of this software and associated documentation files (the "Software"), to
+ *  deal in the Software without restriction, including without limitation the
+ *  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ *  sell copies of the Software, and to permit persons to whom the Software is
+ *  furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice shall be included in
+ *  all copies or substantial portions of the Software.
+ *
+ *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL ANY
+ *  DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ *  IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __MULTIBOOT2_H__
+#define __MULTIBOOT2_H__
+
+/* The magic field should contain this.  */
+#define MULTIBOOT2_HEADER_MAGIC			0xe85250d6
+
+/* This should be in %eax on x86 architecture.  */
+#define MULTIBOOT2_BOOTLOADER_MAGIC		0x36d76289
+
+/* How many bytes from the start of the file we search for the header.  */
+#define MULTIBOOT2_SEARCH			32768
+
+/* Multiboot 2 header alignment. */
+#define MULTIBOOT2_HEADER_ALIGN			8
+
+/* Alignment of multiboot 2 modules.  */
+#define MULTIBOOT2_MOD_ALIGN			0x00001000
+
+/* Alignment of the multiboot 2 info structure.  */
+#define MULTIBOOT2_INFO_ALIGN			0x00000008
+
+/* Multiboot 2 architectures. */
+#define MULTIBOOT2_ARCHITECTURE_I386	0
+#define MULTIBOOT2_ARCHITECTURE_MIPS32	4
+
+/* Header tag types. */
+#define MULTIBOOT2_HEADER_TAG_END			0
+#define MULTIBOOT2_HEADER_TAG_INFORMATION_REQUEST	1
+#define MULTIBOOT2_HEADER_TAG_ADDRESS			2
+#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS		3
+#define MULTIBOOT2_HEADER_TAG_CONSOLE_FLAGS		4
+#define MULTIBOOT2_HEADER_TAG_FRAMEBUFFER		5
+#define MULTIBOOT2_HEADER_TAG_MODULE_ALIGN		6
+#define MULTIBOOT2_HEADER_TAG_EFI_BS			7
+#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI32	8
+#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64	9
+
+/* Header tag flags. */
+#define MULTIBOOT2_HEADER_TAG_REQUIRED	0
+#define MULTIBOOT2_HEADER_TAG_OPTIONAL	1
+
+/* Header console tag console_flags. */
+#define MULTIBOOT2_CONSOLE_FLAGS_CONSOLE_REQUIRED	1
+#define MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED	2
+
+/* Flags set in the 'flags' member of the multiboot header.  */
+#define MULTIBOOT2_TAG_TYPE_END			0

xen/include/xen/multiboot2.h line 82

Quoted 10 lines
xen/include/xen/multiboot2.h new file +10 -0
+#define MULTIBOOT2_TAG_TYPE_CMDLINE		1
+#define MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME	2
+#define MULTIBOOT2_TAG_TYPE_MODULE		3
+#define MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO	4
+#define MULTIBOOT2_TAG_TYPE_BOOTDEV		5
+#define MULTIBOOT2_TAG_TYPE_MMAP		6
+#define MULTIBOOT2_TAG_TYPE_VBE			7
+#define MULTIBOOT2_TAG_TYPE_FRAMEBUFFER		8
+#define MULTIBOOT2_TAG_TYPE_ELF_SECTIONS	9
+#define MULTIBOOT2_TAG_TYPE_APM			10

In the grub code those all look actually in the same column.

I presume it is due to the '2'. But perhaps we can make this whole file have the values at around the same column?

Also for the MULTIBOOT2_BOOTLOADER_MAGIC, ..MOD_ALIGN, INFO_ALIGN, etc.

Quoted 15 lines
xen/include/xen/multiboot2.h new file +15 -0
+#define MULTIBOOT2_TAG_TYPE_EFI32		11
+#define MULTIBOOT2_TAG_TYPE_EFI64		12
+#define MULTIBOOT2_TAG_TYPE_SMBIOS		13
+#define MULTIBOOT2_TAG_TYPE_ACPI_OLD		14
+#define MULTIBOOT2_TAG_TYPE_ACPI_NEW		15
+#define MULTIBOOT2_TAG_TYPE_NETWORK		16
+#define MULTIBOOT2_TAG_TYPE_EFI_MMAP		17
+#define MULTIBOOT2_TAG_TYPE_EFI_BS		18
+#define MULTIBOOT2_TAG_TYPE_EFI32_IH		19
+#define MULTIBOOT2_TAG_TYPE_EFI64_IH		20
+
+/* Multiboot 2 tag alignment. */
+#define MULTIBOOT2_TAG_ALIGN			8
+
+/* Memory types. */

xen/include/xen/multiboot2.h line 107

Quoted 10 lines
xen/include/xen/multiboot2.h new file +10 -0
+#define MULTIBOOT2_MEMORY_AVAILABLE		1
+#define MULTIBOOT2_MEMORY_RESERVED		2
+#define MULTIBOOT2_MEMORY_ACPI_RECLAIMABLE	3
+#define MULTIBOOT2_MEMORY_NVS			4
+#define MULTIBOOT2_MEMORY_BADRAM		5
+
+/* Framebuffer types. */
+#define MULTIBOOT2_FRAMEBUFFER_TYPE_INDEXED	0
+#define MULTIBOOT2_FRAMEBUFFER_TYPE_RGB		1
+#define MULTIBOOT2_FRAMEBUFFER_TYPE_EGA_TEXT	2

And these.

Otherwise,

Quoted 70 lines
xen/include/xen/multiboot2.h new file +62 -0
+
+#ifndef __ASSEMBLY__
+typedef struct {
+    u32 total_size;
+    u32 reserved;
+} multiboot2_fixed_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+} multiboot2_tag_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    char string[0];
+} multiboot2_tag_string_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u32 mem_lower;
+    u32 mem_upper;
+} multiboot2_tag_basic_meminfo_t;
+
+typedef struct __packed {
+    u64 addr;
+    u64 len;
+    u32 type;
+    u32 zero;
+} multiboot2_memory_map_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u32 entry_size;
+    u32 entry_version;
+    multiboot2_memory_map_t entries[0];
+} multiboot2_tag_mmap_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u64 pointer;
+} multiboot2_tag_efi64_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u64 pointer;
+} multiboot2_tag_efi64_ih_t;
+
+typedef struct {
+    u32 type;
+    u32 size;
+    u32 mod_start;
+    u32 mod_end;
+    char cmdline[0];
+} multiboot2_tag_module_t;
+#endif /* __ASSEMBLY__ */
+
+#endif /* __MULTIBOOT2_H__ */
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#50 lore raw

Re: [Xen-devel] [PATCH v2 08/23] x86: add multiboot2 protocol support

Quoted 22 lines · Konrad Rzeszutek Wilk
Quoted 21 lines · Daniel Kiper

Add multiboot2 protocol support. Alter min memory limit handling as we now may not find it from either multiboot (v1) or multiboot2.

This way we are laying the foundation for EFI + GRUB2 + Xen development.

---
v2 - suggestions/fixes:
- generate multiboot2 header using macros (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- simplify assembly in xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- do not include include/xen/compiler.h
in xen/arch/x86/boot/reloc.c
(suggested by Jan Beulich),
- do not read data beyond the end of Multiboot2 information (suggested by Jan Beulich).

Quoted 3 lines
Quoted 1 line

v2 - not fixed yet:

You have two 'v2'

Yep, but it says "not fixed in v2".

Quoted 73 lines
Quoted 73 lines

- dynamic dependency generation for xen/arch/x86/boot/reloc.S; this requires more work; I am not sure that it pays because potential patch requires more changes than addition of just multiboot2.h to Makefile
(suggested by Jan Beulich),
- isolated/stray __packed attribute usage for multiboot2_memory_map_t (suggested by Jan Beulich).

---
 xen/arch/x86/boot/Makefile        |    3 +-
 xen/arch/x86/boot/head.S          |  105 +++++++++++++++++++++--
 xen/arch/x86/boot/reloc.c         |  146 +++++++++++++++++++++++++++++++-
 xen/arch/x86/x86_64/asm-offsets.c |    7 ++
 xen/include/xen/multiboot2.h      |  169 +++++++++++++++++++++++++++++++++++++
 5 files changed, 420 insertions(+), 10 deletions(-)
 create mode 100644 xen/include/xen/multiboot2.h
xen/arch/x86/boot/Makefile +2 -1
index 5fdb5ae..06893d8 100644
@@ -1,6 +1,7 @@
 obj-bin-y += head.o
 
-RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h
+RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \
+	     $(BASEDIR)/include/xen/multiboot2.h
 
 head.o: reloc.S
 
xen/arch/x86/boot/head.S +23 -0
index 77e7da9..57197db 100644
@@ -1,5 +1,6 @@
 #include <xen/config.h>
 #include <xen/multiboot.h>
+#include <xen/multiboot2.h>
 #include <public/xen.h>
 #include <asm/asm_defns.h>
 #include <asm/desc.h>
@@ -19,6 +20,28 @@
 #define BOOT_PSEUDORM_CS 0x0020
 #define BOOT_PSEUDORM_DS 0x0028
 
+#define MB2_HT(name)      (MULTIBOOT2_HEADER_TAG_##name)
+#define MB2_TT(name)      (MULTIBOOT2_TAG_TYPE_##name)
+
+        .macro mb2ht_args arg, args:vararg
+        .long \arg
+        .ifnb \args
+        mb2ht_args \args
+        .endif
+        .endm
+
+        .macro mb2ht_init type, req, args:vararg
+        .align MULTIBOOT2_TAG_ALIGN
+        0:
+        .short \type
+        .short \req
+        .long 1f - 0b
+        .ifnb \args
+        mb2ht_args \args
+        .endif
+        1:
+        .endm
+
 ENTRY(start)
         jmp     __start
 
@@ -34,6 +57,42 @@ multiboot1_header_start:       /*** MULTIBOOT1 HEADER ****/
         .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
 multiboot1_header_end:
 
Quoted 9 lines

xen/arch/x86/boot/head.S multiboot1_header_start: /*** MULTIBOOT1 HEADER ****/ · line 64

Quoted 5 lines
xen/arch/x86/boot/head.S +5 -0
+/*** MULTIBOOT2 HEADER ****/
+/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S file. */
+        .align  MULTIBOOT2_HEADER_ALIGN
+
+.Lmultiboot2_header:

How come you use .L? It makes this hidden while the multiboot1 headers are visible? Makes it a bit harder to see the contents of this under an debugger.

Good point. IIRC, Jan asked about that. I will remove .L if he does not object.

Quoted 62 lines
Quoted 50 lines
xen/arch/x86/boot/head.S +39 -1
+        /* Magic number indicating a Multiboot2 header. */
+        .long   MULTIBOOT2_HEADER_MAGIC
+        /* Architecture: i386. */
+        .long   MULTIBOOT2_ARCHITECTURE_I386
+        /* Multiboot2 header length. */
+        .long   .Lmultiboot2_header_end - .Lmultiboot2_header
+        /* Multiboot2 header checksum. */
+        .long   -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_ARCHITECTURE_I386 + \
+                        (.Lmultiboot2_header_end - .Lmultiboot2_header))
+
+        /* Multiboot2 information request tag. */
+        mb2ht_init MB2_HT(INFORMATION_REQUEST), MB2_HT(REQUIRED), \
+                   MB2_TT(BASIC_MEMINFO), MB2_TT(MMAP)
+
+        /* Align modules at page boundry. */
+        mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
+
+        /* Console flags tag. */
+        mb2ht_init MB2_HT(CONSOLE_FLAGS), MB2_HT(OPTIONAL), \
+                   MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED
+
+        /* Framebuffer tag. */
+        mb2ht_init MB2_HT(FRAMEBUFFER), MB2_HT(OPTIONAL), \
+                   0, /* Number of the columns - no preference. */ \
+                   0, /* Number of the lines - no preference. */ \
+                   0  /* Number of bits per pixel - no preference. */
+
+        /* Multiboot2 header end tag. */
+        mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
+.Lmultiboot2_header_end:
+
         .section .init.rodata, "a", @progbits
         .align 4
 
@@ -82,10 +141,48 @@ __start:
         mov     %ecx,%es
         mov     %ecx,%ss
 
-        /* Check for Multiboot bootloader */
+        /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value. */
+        xor     %edx,%edx
+
+        /* Check for Multiboot2 bootloader. */
+        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
+        je      multiboot2_proto
+
+        /* Check for Multiboot bootloader. */
         cmp     $MULTIBOOT_BOOTLOADER_MAGIC,%eax
         jne     not_multiboot
 

xen/arch/x86/boot/head.S __start: · line 164

Quoted 10 lines
xen/arch/x86/boot/head.S +10 -0
+        /* Get mem_lower from Multiboot information. */
+        testb   $MBI_MEMLIMITS,MB_flags(%ebx)
+
+        /* Not available? BDA value will be fine. */
+        cmovnz  MB_mem_lower(%ebx),%edx
+        jmp     trampoline_setup
+
+multiboot2_proto:
+        /* Skip Multiboot2 information fixed part. */
+        lea     MB2_fixed_sizeof(%ebx),%ecx

Is there any point of double checking the aligment? That is

Quoted 8 lines
        and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx

?

Looking at the grub code it requests the memory to be aligned properly so in practice this will never fail. But since somebody might for fun allocate the structure to not be aligned and the fixed part could finish on non-aligned space..

You are right, we should check it. multiboot2 spec states:

3.4.2 Basic tags structure

Boot information consists of fixed part and a series of tags. Its start is 8-bytes aligned.

Daniel

#51 lore raw

Re: [PATCH v2 08/23] x86: add multiboot2 protocol support

Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 13.08.15 at 21:22, <[email protected]> wrote:
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Daniel Kiper
xen/arch/x86/boot/head.S +0 -0
@@ -34,6 +57,42 @@ multiboot1_header_start:       /*** MULTIBOOT1 HEADER ****/
         .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
 multiboot1_header_end:
 
Quoted 9 lines

xen/arch/x86/boot/head.S multiboot1_header_start: /*** MULTIBOOT1 HEADER ****/ · line 64

Quoted 5 lines
xen/arch/x86/boot/head.S +5 -0
+/*** MULTIBOOT2 HEADER ****/
+/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S file. */
+        .align  MULTIBOOT2_HEADER_ALIGN
+
+.Lmultiboot2_header:

How come you use .L? It makes this hidden while the multiboot1 headers are visible? Makes it a bit harder to see the contents of this under an debugger.

Quoted 2 lines

Good point. IIRC, Jan asked about that. I will remove .L if he does not object.

For this particular one I think it's okay to drop the .L, but generally I'd like to see .L used more widely for any auxiliary labels (i.e. only "main" labels - function entry points and data objects - should have their labels present in the final symbol table).

Jan

#52 lore raw

Re: [Xen-devel] [PATCH v2 08/23] x86: add multiboot2 protocol support

In reply to Daniel Kiper
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 13.08.15 at 21:22, <[email protected]> wrote:
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Daniel Kiper
xen/arch/x86/boot/head.S +0 -0
@@ -34,6 +57,42 @@ multiboot1_header_start:       /*** MULTIBOOT1 HEADER ****/
         .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
 multiboot1_header_end:
 
Quoted 9 lines

xen/arch/x86/boot/head.S multiboot1_header_start: /*** MULTIBOOT1 HEADER ****/ · line 64

Quoted 5 lines
xen/arch/x86/boot/head.S +5 -0
+/*** MULTIBOOT2 HEADER ****/
+/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S file. */
+        .align  MULTIBOOT2_HEADER_ALIGN
+
+.Lmultiboot2_header:

How come you use .L? It makes this hidden while the multiboot1 headers are visible? Makes it a bit harder to see the contents of this under an debugger.

Quoted 2 lines

Good point. IIRC, Jan asked about that. I will remove .L if he does not object.

For this particular one I think it's okay to drop the .L, but generally I'd like to see .L used more widely for any auxiliary labels (i.e. only "main" labels - function entry points and data objects - should have their labels present in the final symbol table).

Jan

#53 lore raw

Re: [PATCH v2 08/23] x86: add multiboot2 protocol support

Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 13.08.15 at 21:22, <[email protected]> wrote:
Quoted 13 lines · Konrad Rzeszutek Wilk

xen/arch/x86/boot/head.S multiboot1_header_start: /*** MULTIBOOT1 HEADER ****/ · line 64

Quoted 9 lines · Daniel Kiper
xen/arch/x86/boot/head.S +5 -0
@@ -34,6 +57,42 @@ multiboot1_header_start:       /*** MULTIBOOT1 HEADER ****/
          .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
  multiboot1_header_end:
 
+/*** MULTIBOOT2 HEADER ****/
+/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S file. */
+        .align  MULTIBOOT2_HEADER_ALIGN
+
+.Lmultiboot2_header:

How come you use .L? It makes this hidden while the multiboot1 headers are visible? Makes it a bit harder to see the contents of this under an debugger.

Quoted 6 lines
Quoted 2 lines

Good point. IIRC, Jan asked about that. I will remove .L if he does not object.

For this particular one I think it's okay to drop the .L, but generally I'd like to see .L used more widely for any auxiliary labels (i.e. only "main" labels - function entry points and data objects - should have their labels present in the final symbol table).

In general I would agree.

However, the multiboot 1 and 2 headers are special. They are binary data included in the .text section, so having non-local lables makes the disassembly easier to read.

~Andrew

#54 lore raw

Re: [Xen-devel] [PATCH v2 08/23] x86: add multiboot2 protocol support

In reply to Jan Beulich
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 13.08.15 at 21:22, <[email protected]> wrote:
Quoted 13 lines · Konrad Rzeszutek Wilk

xen/arch/x86/boot/head.S multiboot1_header_start: /*** MULTIBOOT1 HEADER ****/ · line 64

Quoted 9 lines · Daniel Kiper
xen/arch/x86/boot/head.S +5 -0
@@ -34,6 +57,42 @@ multiboot1_header_start:       /*** MULTIBOOT1 HEADER ****/
          .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
  multiboot1_header_end:
 
+/*** MULTIBOOT2 HEADER ****/
+/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S file. */
+        .align  MULTIBOOT2_HEADER_ALIGN
+
+.Lmultiboot2_header:

How come you use .L? It makes this hidden while the multiboot1 headers are visible? Makes it a bit harder to see the contents of this under an debugger.

Quoted 6 lines
Quoted 2 lines

Good point. IIRC, Jan asked about that. I will remove .L if he does not object.

For this particular one I think it's okay to drop the .L, but generally I'd like to see .L used more widely for any auxiliary labels (i.e. only "main" labels - function entry points and data objects - should have their labels present in the final symbol table).

In general I would agree.

However, the multiboot 1 and 2 headers are special. They are binary data included in the .text section, so having non-local lables makes the disassembly easier to read.

~Andrew

#55 lore raw

Re: [PATCH v2 08/23] x86: add multiboot2 protocol support

In reply to Konrad Rzeszutek Wilk
Quoted 22 lines · Konrad Rzeszutek Wilk
Quoted 21 lines · Daniel Kiper

Add multiboot2 protocol support. Alter min memory limit handling as we now may not find it from either multiboot (v1) or multiboot2.

This way we are laying the foundation for EFI + GRUB2 + Xen development.

---
v2 - suggestions/fixes:
- generate multiboot2 header using macros (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- simplify assembly in xen/arch/x86/boot/head.S (suggested by Jan Beulich),
- do not include include/xen/compiler.h
in xen/arch/x86/boot/reloc.c
(suggested by Jan Beulich),
- do not read data beyond the end of Multiboot2 information (suggested by Jan Beulich).

Quoted 3 lines
Quoted 1 line

v2 - not fixed yet:

You have two 'v2'

Yep, but it says "not fixed in v2".

Quoted 73 lines
Quoted 73 lines

- dynamic dependency generation for xen/arch/x86/boot/reloc.S; this requires more work; I am not sure that it pays because potential patch requires more changes than addition of just multiboot2.h to Makefile
(suggested by Jan Beulich),
- isolated/stray __packed attribute usage for multiboot2_memory_map_t (suggested by Jan Beulich).

---
 xen/arch/x86/boot/Makefile        |    3 +-
 xen/arch/x86/boot/head.S          |  105 +++++++++++++++++++++--
 xen/arch/x86/boot/reloc.c         |  146 +++++++++++++++++++++++++++++++-
 xen/arch/x86/x86_64/asm-offsets.c |    7 ++
 xen/include/xen/multiboot2.h      |  169 +++++++++++++++++++++++++++++++++++++
 5 files changed, 420 insertions(+), 10 deletions(-)
 create mode 100644 xen/include/xen/multiboot2.h
xen/arch/x86/boot/Makefile +2 -1
index 5fdb5ae..06893d8 100644
@@ -1,6 +1,7 @@
 obj-bin-y += head.o
 
-RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h
+RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \
+	     $(BASEDIR)/include/xen/multiboot2.h
 
 head.o: reloc.S
 
xen/arch/x86/boot/head.S +23 -0
index 77e7da9..57197db 100644
@@ -1,5 +1,6 @@
 #include <xen/config.h>
 #include <xen/multiboot.h>
+#include <xen/multiboot2.h>
 #include <public/xen.h>
 #include <asm/asm_defns.h>
 #include <asm/desc.h>
@@ -19,6 +20,28 @@
 #define BOOT_PSEUDORM_CS 0x0020
 #define BOOT_PSEUDORM_DS 0x0028
 
+#define MB2_HT(name)      (MULTIBOOT2_HEADER_TAG_##name)
+#define MB2_TT(name)      (MULTIBOOT2_TAG_TYPE_##name)
+
+        .macro mb2ht_args arg, args:vararg
+        .long \arg
+        .ifnb \args
+        mb2ht_args \args
+        .endif
+        .endm
+
+        .macro mb2ht_init type, req, args:vararg
+        .align MULTIBOOT2_TAG_ALIGN
+        0:
+        .short \type
+        .short \req
+        .long 1f - 0b
+        .ifnb \args
+        mb2ht_args \args
+        .endif
+        1:
+        .endm
+
 ENTRY(start)
         jmp     __start
 
@@ -34,6 +57,42 @@ multiboot1_header_start:       /*** MULTIBOOT1 HEADER ****/
         .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
 multiboot1_header_end:
 
Quoted 9 lines

xen/arch/x86/boot/head.S multiboot1_header_start: /*** MULTIBOOT1 HEADER ****/ · line 64

Quoted 5 lines
xen/arch/x86/boot/head.S +5 -0
+/*** MULTIBOOT2 HEADER ****/
+/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S file. */
+        .align  MULTIBOOT2_HEADER_ALIGN
+
+.Lmultiboot2_header:

How come you use .L? It makes this hidden while the multiboot1 headers are visible? Makes it a bit harder to see the contents of this under an debugger.

Good point. IIRC, Jan asked about that. I will remove .L if he does not object.

Quoted 62 lines
Quoted 50 lines
xen/arch/x86/boot/head.S +39 -1
+        /* Magic number indicating a Multiboot2 header. */
+        .long   MULTIBOOT2_HEADER_MAGIC
+        /* Architecture: i386. */
+        .long   MULTIBOOT2_ARCHITECTURE_I386
+        /* Multiboot2 header length. */
+        .long   .Lmultiboot2_header_end - .Lmultiboot2_header
+        /* Multiboot2 header checksum. */
+        .long   -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_ARCHITECTURE_I386 + \
+                        (.Lmultiboot2_header_end - .Lmultiboot2_header))
+
+        /* Multiboot2 information request tag. */
+        mb2ht_init MB2_HT(INFORMATION_REQUEST), MB2_HT(REQUIRED), \
+                   MB2_TT(BASIC_MEMINFO), MB2_TT(MMAP)
+
+        /* Align modules at page boundry. */
+        mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
+
+        /* Console flags tag. */
+        mb2ht_init MB2_HT(CONSOLE_FLAGS), MB2_HT(OPTIONAL), \
+                   MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED
+
+        /* Framebuffer tag. */
+        mb2ht_init MB2_HT(FRAMEBUFFER), MB2_HT(OPTIONAL), \
+                   0, /* Number of the columns - no preference. */ \
+                   0, /* Number of the lines - no preference. */ \
+                   0  /* Number of bits per pixel - no preference. */
+
+        /* Multiboot2 header end tag. */
+        mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
+.Lmultiboot2_header_end:
+
         .section .init.rodata, "a", @progbits
         .align 4
 
@@ -82,10 +141,48 @@ __start:
         mov     %ecx,%es
         mov     %ecx,%ss
 
-        /* Check for Multiboot bootloader */
+        /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value. */
+        xor     %edx,%edx
+
+        /* Check for Multiboot2 bootloader. */
+        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
+        je      multiboot2_proto
+
+        /* Check for Multiboot bootloader. */
         cmp     $MULTIBOOT_BOOTLOADER_MAGIC,%eax
         jne     not_multiboot
 

xen/arch/x86/boot/head.S __start: · line 164

Quoted 10 lines
xen/arch/x86/boot/head.S +10 -0
+        /* Get mem_lower from Multiboot information. */
+        testb   $MBI_MEMLIMITS,MB_flags(%ebx)
+
+        /* Not available? BDA value will be fine. */
+        cmovnz  MB_mem_lower(%ebx),%edx
+        jmp     trampoline_setup
+
+multiboot2_proto:
+        /* Skip Multiboot2 information fixed part. */
+        lea     MB2_fixed_sizeof(%ebx),%ecx

Is there any point of double checking the aligment? That is

Quoted 8 lines
        and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx

?

Looking at the grub code it requests the memory to be aligned properly so in practice this will never fail. But since somebody might for fun allocate the structure to not be aligned and the fixed part could finish on non-aligned space..

You are right, we should check it. multiboot2 spec states:

3.4.2 Basic tags structure

Boot information consists of fixed part and a series of tags. Its start is 8-bytes aligned.

Daniel

#56 lore raw

Re: [PATCH v2 08/23] x86: add multiboot2 protocol support

In reply to Daniel Kiper
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

v2 - not fixed yet:
- dynamic dependency generation for xen/arch/x86/boot/reloc.S; this requires more work; I am not sure that it pays because potential patch requires more changes than addition of just multiboot2.h to Makefile
(suggested by Jan Beulich),

With the compiler.h inclusion done I don't think this is as necessary anymore as it was previously.

Quoted 2 lines

- isolated/stray __packed attribute usage for multiboot2_memory_map_t (suggested by Jan Beulich).

This one I don't, however, see why you didn't address. And with un-addressed issues I think you should have tagged this RFC).

xen/arch/x86/boot/head.S line 26

Quoted 8 lines
xen/arch/x86/boot/head.S +4 -0
@@ -19,6 +20,28 @@
 #define BOOT_PSEUDORM_CS 0x0020
 #define BOOT_PSEUDORM_DS 0x0028
 
+#define MB2_HT(name)      (MULTIBOOT2_HEADER_TAG_##name)
+#define MB2_TT(name)      (MULTIBOOT2_TAG_TYPE_##name)
+
+        .macro mb2ht_args arg, args:vararg

Please make sure the oldest binutils we support allow for this (introduced in 2.17; the oldest supported SLE seems to have it, but I'm not sure about RHEL).

xen/arch/x86/boot/head.S line 35

Quoted 9 lines
xen/arch/x86/boot/head.S +9 -0
+        .long \arg
+        .ifnb \args
+        mb2ht_args \args
+        .endif
+        .endm
+
+        .macro mb2ht_init type, req, args:vararg
+        .align MULTIBOOT2_TAG_ALIGN
+        0:

Labels belong in the first column. Also I generally recommend against using numeric labels in macros (due to the risk of conflict with label uses around the macro use sites) - use \@ instead to make labels unique (again provided the oldest supported binutils handle this).

xen/arch/x86/boot/head.S __start: · line 220

Quoted 10 lines
xen/arch/x86/boot/head.S +2 -1
@@ -119,10 +213,11 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
+        push    %eax                /* Multiboot magic. */
         push    %ebx                /* Multiboot information address. */
         push    %ecx                /* Boot trampoline address. */
         call    reloc
-        add     $8,%esp             /* Remove reloc() args from stack. */
+        add     $12,%esp            /* Remove reloc() args from stack. */

The latest now it becomes clear that the arguments passed are kind of backwards: One would expect the qualifying value (i.e. the magic) to come first, then the info pointer, and last the trampoline address.

xen/arch/x86/boot/reloc.c static u32 copy_string(u32 src) · line 107

Quoted 6 lines
xen/arch/x86/boot/reloc.c +1 -1
@@ -86,12 +104,12 @@ static u32 copy_string(u32 src)
     return copy_mem(src, p - src + 1);
 }
 
-multiboot_info_t *reloc(u32 mbi_in)
+static multiboot_info_t *mbi_mbi(void *mbi_in)

I don't see why this needs to become a pointer all of the sudden, ...

xen/arch/x86/boot/reloc.c static u32 copy_string(u32 src) · line 112

Quoted 6 lines
xen/arch/x86/boot/reloc.c +1 -1
 {
     int i;
     multiboot_info_t *mbi_out;
 
-    mbi_out = (multiboot_info_t *)copy_mem(mbi_in, sizeof(*mbi_out));
+    mbi_out = (multiboot_info_t *)copy_mem((u32)mbi_in, sizeof(*mbi_out));

... adding back a cast that we'd better avoid here.

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 149

Quoted 6 lines
xen/arch/x86/boot/reloc.c +2 -0
@@ -127,3 +145,123 @@ multiboot_info_t *reloc(u32 mbi_in)
 
     return mbi_out;
 }
+
+static multiboot_info_t *mbi2_mbi(void *mbi_in)

Why not "const multiboot2_fixed_t *"?

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 154

Quoted 5 lines
xen/arch/x86/boot/reloc.c +5 -0
+{
+    /* Do not complain that mbi_out_mods is not initialized. */
+    module_t *mbi_out_mods = (module_t *)0;
+    memory_map_t *mmap_dst;
+    multiboot2_memory_map_t *mmap_src;

const

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 155

Quoted 1 line
xen/arch/x86/boot/reloc.c +1 -0
+    multiboot2_tag_t *tag;

const?

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 161

Quoted 6 lines
xen/arch/x86/boot/reloc.c +6 -0
+    multiboot_info_t *mbi_out;
+    u32 ptr;
+    unsigned int i, mod_idx = 0;
+
+    mbi_out = (multiboot_info_t *)alloc_mem(sizeof(*mbi_out));
+    zero_mem((u32)mbi_out, sizeof(*mbi_out));

Please avoid one of the two casts (e.g. by using "ptr" as intermediate storage for the alloc_mem() result.

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 174

Quoted 13 lines
xen/arch/x86/boot/reloc.c +13 -0
+
+    /* Skip Multiboot2 information fixed part. */
+    tag = mbi_in + sizeof(multiboot2_fixed_t);
+
+    for ( ; ; )
+    {
+        if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE )
+            ++mbi_out->mods_count;
+        else if ( tag->type == MULTIBOOT2_TAG_TYPE_END )
+        {
+            mbi_out->flags = MBI_MODULES;
+            mbi_out->mods_addr = alloc_mem(mbi_out->mods_count * sizeof(module_t));
+            mbi_out_mods = (module_t *)mbi_out->mods_addr;

Even if we don't expect Xen to be booted without any modules, wouldn't you better do this only when mbi_out->mods_count > 0?

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 179

Quoted 5 lines
xen/arch/x86/boot/reloc.c +5 -0
+            break;
+        }
+
+        /* Go to next Multiboot2 information tag. */
+        tag = (multiboot2_tag_t *)(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN));

Please drop the stray pair of parentheses around the invocation of ALIGN_UP(). Also - long line.

Review multiboot_info_t *reloc(u32 mbi_in) · line 181

Quoted 2 lines
(quoted diff) +2 -0
+        /* Check Multiboot2 information total size just in case. */
+	if ( (void *)tag - mbi_in >= ((multiboot2_fixed_t *)mbi_in)->total_size )

Hard tab.

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 195

Quoted 13 lines
xen/arch/x86/boot/reloc.c +13 -0
+            break;
+    }
+
+    /* Skip Multiboot2 information fixed part. */
+    tag = mbi_in + sizeof(multiboot2_fixed_t);
+
+    for ( ; ; )
+    {
+        switch ( tag->type )
+        {
+        case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME:
+            mbi_out->flags |= MBI_LOADERNAME;
+            ptr = (u32)get_mb2_data(tag, multiboot2_tag_string_t, string);

Please consider adding a get_mb2_string() wrapping get_mb2_data() but eliminating the recurring casts from all use sites.

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+            mbi_out->boot_loader_name = copy_string(ptr);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_CMDLINE:
+            mbi_out->flags |= MBI_CMDLINE;
+            ptr = (u32)get_mb2_data(tag, multiboot2_tag_string_t, string);
+            mbi_out->cmdline = copy_string(ptr);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO:

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 215

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+            mbi_out->flags |= MBI_MEMLIMITS;
+            mbi_out->mem_lower = get_mb2_data(tag, multiboot2_tag_basic_meminfo_t, mem_lower);
+            mbi_out->mem_upper = get_mb2_data(tag, multiboot2_tag_basic_meminfo_t, mem_upper);
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, multiboot2_tag_mmap_t, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
+            mbi_out->mmap_length += sizeof(((multiboot2_tag_mmap_t){0}).entries);

Afaict this sizeof() evaluates to zero. And even if it didn't I can't see what the line is good for.

Quoted 8 lines
xen/arch/x86/boot/reloc.c +8 -0
+            mbi_out->mmap_length /= get_mb2_data(tag, multiboot2_tag_mmap_t, entry_size);
+            mbi_out->mmap_length *= sizeof(memory_map_t);
+
+            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
+
+            mmap_src = get_mb2_data(tag, multiboot2_tag_mmap_t, entries);
+            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;
+

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 233

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); ++i )
+            {
+                mmap_dst[i].size = sizeof(memory_map_t);
+                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);
+                mmap_dst[i].base_addr_low = (u32)mmap_src[i].addr;
+                mmap_dst[i].base_addr_high = (u32)(mmap_src[i].addr >> 32);
+                mmap_dst[i].length_low = (u32)mmap_src[i].len;
+                mmap_dst[i].length_high = (u32)(mmap_src[i].len >> 32);
+                mmap_dst[i].type = mmap_src[i].type;
+            }

So in the calculations ahead of the loop you're careful to honor entry_size. Why do you ignore it in the loop (assuming entry_size == sizeof(multiboot2_memory_map_t))?

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 238

Quoted 5 lines
xen/arch/x86/boot/reloc.c +5 -0
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_MODULE:
+            mbi_out_mods[mod_idx].mod_start = get_mb2_data(tag, multiboot2_tag_module_t, mod_start);
+            mbi_out_mods[mod_idx].mod_end = get_mb2_data(tag, multiboot2_tag_module_t, mod_end);

Long lines. Also by now the redundancy of the multiboot2_tag_ prefix and the _t suffix in each of the invocations tells us that it would be quite nice if attaching them to the actually relevant part of the name would better be done inside the macro.

Quoted 8 lines
xen/arch/x86/boot/reloc.c +8 -0
+            ptr = (u32)get_mb2_data(tag, multiboot2_tag_module_t, cmdline);
+            mbi_out_mods[mod_idx].string = copy_string(ptr);
+            mbi_out_mods[mod_idx].reserved = 0;
+            ++mod_idx;
+            break;
+
+        case MULTIBOOT2_TAG_TYPE_END:
+            return mbi_out;

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 256

Quoted 10 lines
xen/arch/x86/boot/reloc.c +10 -0
+
+        default:
+            break;
+        }
+
+        /* Go to next Multiboot2 information tag. */
+        tag = (multiboot2_tag_t *)(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN));
+
+        /* Check Multiboot2 information total size just in case. */
+	if ( (void *)tag - mbi_in >= ((multiboot2_fixed_t *)mbi_in)->total_size )

Hard tab again.

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 261

Quoted 1 line
xen/arch/x86/boot/reloc.c +1 -0
+static multiboot_info_t __attribute__((__used__)) *reloc(void *mbi_in, u32 mb_magic)

Dropping the "static" would permit to also drop the "used" attribute. Since it was that way before, why didn't you keep it that way?

Jan

#57 lore raw

Re: [PATCH v2 08/23] x86: add multiboot2 protocol support

Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

[...]

Quoted 15 lines

xen/arch/x86/boot/head.S __start: · line 220

Quoted 10 lines
xen/arch/x86/boot/head.S +2 -1
@@ -119,10 +213,11 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
+        push    %eax                /* Multiboot magic. */
         push    %ebx                /* Multiboot information address. */
         push    %ecx                /* Boot trampoline address. */
         call    reloc
-        add     $8,%esp             /* Remove reloc() args from stack. */
+        add     $12,%esp            /* Remove reloc() args from stack. */

The latest now it becomes clear that the arguments passed are kind of backwards: One would expect the qualifying value (i.e. the magic) to come first, then the info pointer, and last the trampoline address.

Yep, you are right. However, I wanted to avoid changing order of arguments to not confuse reader. If you wish I can change that thing.

[...]

Quoted 8 lines

xen/arch/x86/boot/reloc.c multiboot_info_t *reloc(u32 mbi_in) · line 215

Quoted 5 lines
xen/arch/x86/boot/reloc.c +5 -0
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, multiboot2_tag_mmap_t, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
+            mbi_out->mmap_length += sizeof(((multiboot2_tag_mmap_t){0}).entries);

Afaict this sizeof() evaluates to zero. And even if it didn't I can't see what the line is good for.

Right, I have missed that. However, if it does not evaluate to zero then you must add back relevant number of entries which you subtracted one line above. Otherwise count of entries will be incorrect.

[...]

Quoted 2 lines

Dropping the "static" would permit to also drop the "used" attribute. Since it was that way before, why didn't you keep it that way?

Yep, but I do not like this solution. Lack of static suggests that this function is used elsewhere. I prefer to explicitly say that there are not external users of that function and silence compiler warnings with __used.

Daniel

#58 lore raw

Re: [PATCH v2 08/23] x86: add multiboot2 protocol support

Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 18.08.15 at 14:00, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich

xen/arch/x86/boot/head.S __start: · line 220

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/arch/x86/boot/head.S +2 -1
@@ -119,10 +213,11 @@ __start:
 
         /* Save the Multiboot info struct (after relocation) for later use. */
         mov     $sym_phys(cpu0_stack)+1024,%esp
+        push    %eax                /* Multiboot magic. */
         push    %ebx                /* Multiboot information address. */
         push    %ecx                /* Boot trampoline address. */
         call    reloc
-        add     $8,%esp             /* Remove reloc() args from stack. */
+        add     $12,%esp            /* Remove reloc() args from stack. */

The latest now it becomes clear that the arguments passed are kind of backwards: One would expect the qualifying value (i.e. the magic) to come first, then the info pointer, and last the trampoline address.

Quoted 2 lines

Yep, you are right. However, I wanted to avoid changing order of arguments to not confuse reader. If you wish I can change that thing.

Yes please: Between confusing the reader of the patch and the reader of the resulting code, the former is the less problematic one. Furthermore with the function having just one argument before your series you have all options to avoid confusing the reader of the patches - just insert the new arguments at the right slot in each patch adding one.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
xen/arch/x86/boot/reloc.c +5 -0
+        case MULTIBOOT2_TAG_TYPE_MMAP:
+            mbi_out->flags |= MBI_MEMMAP;
+            mbi_out->mmap_length = get_mb2_data(tag, multiboot2_tag_mmap_t, size);
+            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
+            mbi_out->mmap_length += sizeof(((multiboot2_tag_mmap_t){0}).entries);
Quoted 6 lines
Quoted 2 lines

Afaict this sizeof() evaluates to zero. And even if it didn't I can't see what the line is good for.

Right, I have missed that. However, if it does not evaluate to zero then you must add back relevant number of entries which you subtracted one line above. Otherwise count of entries will be incorrect.

There's no count being subtracted afaict - what is being subtracted is the size of the rest of the structure.

Quoted 8 lines
Quoted 2 lines

Dropping the "static" would permit to also drop the "used" attribute. Since it was that way before, why didn't you keep it that way?

Yep, but I do not like this solution. Lack of static suggests that this function
is used elsewhere. I prefer to explicitly say that there are not external users
of that function and silence compiler warnings with __used.

If you want to do this, then not in the middle of some already big patch doing something completely different, but in a separate cleanup patch explaining what you explained above (which is not to say that I'm convinced, and hence I can't promise such a change to ultimately go in).

Jan

#59 lore raw

PATCH v2 9/23 efi: create efi_enabled()

In reply to Daniel Kiper

We need more fine grained knowledge about EFI environment and check for EFI platform and EFI loader separately to properly support multiboot2 protocol. In general Xen loaded by this protocol uses memory mappings and loaded modules in similar way to Xen loaded by multiboot (v1) protocol. Hence, create efi_enabled() which checks available features in efi.flags. This patch only defines EFI_PLATFORM feature which is equal to old efi_enabled == 1. Following patch will define EFI_LOADER feature accordingly.

---
 xen/arch/x86/dmi_scan.c    |    4 ++--
 xen/arch/x86/domain_page.c |    2 +-
 xen/arch/x86/efi/stub.c    |   11 ++++++++---
 xen/arch/x86/mpparse.c     |    4 ++--
 xen/arch/x86/setup.c       |   10 +++++-----
 xen/arch/x86/shutdown.c    |    2 +-
 xen/arch/x86/time.c        |    2 +-
 xen/arch/x86/xen.lds.S     |    2 --
 xen/common/efi/boot.c      |    4 ++++
 xen/common/efi/runtime.c   |   17 +++++++----------
 xen/drivers/acpi/osl.c     |    2 +-
 xen/include/xen/efi.h      |   16 ++++++++++++++--
 12 files changed, 46 insertions(+), 30 deletions(-)
xen/arch/x86/dmi_scan.c +2 -2
index 269168c..95c5a77 100644
@@ -229,7 +229,7 @@ const char *__init dmi_get_table(paddr_t *base, u32 *len)
 {
 	static unsigned int __initdata instance;
 
-	if (efi_enabled) {
+	if (efi_enabled(EFI_PLATFORM)) {
 		if (efi_smbios3_size && !(instance & 1)) {
 			*base = efi_smbios3_address;
 			*len = efi_smbios3_size;
@@ -693,7 +693,7 @@ static void __init dmi_decode(struct dmi_header *dm)
 
 void __init dmi_scan_machine(void)
 {
-	if ((!efi_enabled ? dmi_iterate(dmi_decode) :
+	if ((!efi_enabled(EFI_PLATFORM) ? dmi_iterate(dmi_decode) :
 	                    dmi_efi_iterate(dmi_decode)) == 0)
  		dmi_check_system(dmi_blacklist);
 	else
xen/arch/x86/domain_page.c +1 -1
index d86f8fe..fdf0d8a 100644
@@ -36,7 +36,7 @@ static inline struct vcpu *mapcache_current_vcpu(void)
      * domain's page tables but current may point at another domain's VCPU.
      * Return NULL as though current is not properly set up yet.
      */
-    if ( efi_enabled && efi_rs_using_pgtables() )
+    if ( efi_enabled(EFI_PLATFORM) && efi_rs_using_pgtables() )
         return NULL;
 
     /*
xen/arch/x86/efi/stub.c +8 -3
index 07c2bd0..c5ae369 100644
@@ -4,9 +4,14 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+struct efi __read_mostly efi = {
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
+};
 
 void __init efi_init_memory(void) { }
 
xen/arch/x86/mpparse.c +2 -2
index 8609f4a..5223579 100644
@@ -557,7 +557,7 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
 
 static __init void efi_unmap_mpf(void)
 {
-	if (efi_enabled)
+	if (efi_enabled(EFI_PLATFORM))
 		clear_fixmap(FIX_EFI_MPF);
 }
 
@@ -715,7 +715,7 @@ void __init find_smp_config (void)
 {
 	unsigned int address;
 
-	if (efi_enabled) {
+	if (efi_enabled(EFI_PLATFORM)) {
 		efi_check_config();
 		return;
 	}
xen/arch/x86/setup.c +5 -5
index ff34670..bce708c 100644
@@ -444,8 +444,8 @@ static void __init parse_video_info(void)
 {
     struct boot_video_info *bvi = &bootsym(boot_vid_info);
 
-    /* The EFI loader fills vga_console_info directly. */
-    if ( efi_enabled )
+    /* vga_console_info is filled directly on EFI platform. */
+    if ( efi_enabled(EFI_PLATFORM) )
         return;
 
     if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )
@@ -695,7 +695,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
         panic("dom0 kernel not specified. Check bootloader configuration.");
 
-    if ( efi_enabled )
+    if ( efi_enabled(EFI_PLATFORM) )
     {
         set_pdx_range(xen_phys_start >> PAGE_SHIFT,
                       (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
@@ -806,7 +806,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * we can relocate the dom0 kernel and other multiboot modules. Also, on
      * x86/64, we relocate Xen to higher memory.
      */
-    for ( i = 0; !efi_enabled && i < mbi->mods_count; i++ )
+    for ( i = 0; !efi_enabled(EFI_PLATFORM) && i < mbi->mods_count; i++ )
     {
         if ( mod[i].mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request.");
@@ -994,7 +994,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen.");
-    reserve_e820_ram(&boot_e820, efi_enabled ? mbi->mem_upper : __pa(&_start),
+    reserve_e820_ram(&boot_e820, efi_enabled(EFI_PLATFORM) ? mbi->mem_upper : __pa(&_start),
                      __pa(&_end));
 
     /* Late kexec reservation (dynamic start address). */
xen/arch/x86/shutdown.c +1 -1
index 0e1499d..79dcd16 100644
@@ -116,7 +116,7 @@ void machine_halt(void)
 static void default_reboot_type(void)
 {
     if ( reboot_type == BOOT_INVALID )
-        reboot_type = efi_enabled ? BOOT_EFI
+        reboot_type = efi_enabled(EFI_PLATFORM) ? BOOT_EFI
                                   : acpi_disabled ? BOOT_KBD
                                                   : BOOT_ACPI;
 }
xen/arch/x86/time.c +1 -1
index bbb7e6c..11e7e11 100644
@@ -690,7 +690,7 @@ static unsigned long get_cmos_time(void)
     static bool_t __read_mostly cmos_rtc_probe;
     boolean_param("cmos-rtc-probe", cmos_rtc_probe);
 
-    if ( efi_enabled )
+    if ( efi_enabled(EFI_PLATFORM) )
     {
         res = efi_get_time();
         if ( res )
xen/arch/x86/xen.lds.S +0 -2
index 3e1f2af..87f3e83 100644
@@ -191,8 +191,6 @@ SECTIONS
   .pad : {
     . = ALIGN(MB(16));
   } :text
-#else
-  efi = .;
 #endif
 
   /* Sections to be discarded */
xen/common/efi/boot.c +4 -0
index 75a939f..1f188fe 100644
@@ -717,6 +717,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     char *option_str;
     bool_t use_cfg_file;
 
+#ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
+    set_bit(EFI_PLATFORM, &efi.flags);
+#endif
+
     efi_ih = ImageHandle;
     efi_bs = SystemTable->BootServices;
     efi_bs_revision = efi_bs->Hdr.Revision;
xen/common/efi/runtime.c +7 -10
index ae87557..aa064e7 100644
@@ -10,14 +10,10 @@ DEFINE_XEN_GUEST_HANDLE(CHAR16);
 
 #ifndef COMPAT
 
-#ifdef CONFIG_ARM  /* Disabled until runtime services implemented */
-const bool_t efi_enabled = 0;
-#else
+#ifndef CONFIG_ARM
 # include <asm/i387.h>
 # include <asm/xstate.h>
 # include <public/platform.h>
-
-const bool_t efi_enabled = 1;
 #endif
 
 unsigned int __read_mostly efi_num_ct;
@@ -42,11 +38,12 @@ UINT64 __read_mostly efi_boot_remain_var_store_size;
 UINT64 __read_mostly efi_boot_max_var_size;
 
 struct efi __read_mostly efi = {
-	.acpi   = EFI_INVALID_TABLE_ADDR,
-	.acpi20 = EFI_INVALID_TABLE_ADDR,
-	.mps    = EFI_INVALID_TABLE_ADDR,
-	.smbios = EFI_INVALID_TABLE_ADDR,
-	.smbios3 = EFI_INVALID_TABLE_ADDR,
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
 };
 
 const struct efi_pci_rom *__read_mostly efi_pci_roms;
xen/drivers/acpi/osl.c +1 -1
index 4c09859..f4f6628 100644
@@ -66,7 +66,7 @@ void __init acpi_os_vprintf(const char *fmt, va_list args)
 
 acpi_physical_address __init acpi_os_get_root_pointer(void)
 {
-	if (efi_enabled) {
+	if (efi_enabled(EFI_PLATFORM)) {
 		if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
 			return efi.acpi20;
 		else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
xen/include/xen/efi.h +14 -2
index e74dad1..318bbec 100644
@@ -2,15 +2,17 @@
 #define __XEN_EFI_H__
 
 #ifndef __ASSEMBLY__
+#include <xen/bitops.h>
 #include <xen/types.h>
 #endif
 
-extern const bool_t efi_enabled;
-
 #define EFI_INVALID_TABLE_ADDR (~0UL)
 
+#define EFI_PLATFORM	0
+
 /* Add fields here only if they need to be referenced from non-EFI code. */
 struct efi {
+    unsigned long flags;
     unsigned long mps;          /* MPS table */
     unsigned long acpi;         /* ACPI table (IA64 ext 0.71) */
     unsigned long acpi20;       /* ACPI table (ACPI 2.0) */
@@ -40,6 +42,16 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *);
 int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *);
 int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *);
 
+/*
+ * Test whether the above EFI_* bits are enabled.
+ *
+ * Stolen from Linux Kernel.
+ */
+static inline bool_t efi_enabled(int feature)
+{
+    return test_bit(feature, &efi.flags) != 0;
+}
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __XEN_EFI_H__ */
Signature · 1 line
1.7.10.4
Reviewed-by on v2 9/23
#60 lore raw

Re: [Xen-devel] [PATCH v2 09/23] efi: create efi_enabled()

Quoted 11 lines · Daniel Kiper

We need more fine grained knowledge about EFI environment and check for EFI platform and EFI loader separately to properly support multiboot2 protocol. In general Xen loaded by this protocol uses memory mappings and loaded modules in similar way to Xen loaded by multiboot (v1) protocol. Hence, create efi_enabled() which checks available features in efi.flags. This patch only defines EFI_PLATFORM feature which is equal to old efi_enabled == 1. Following patch will define EFI_LOADER feature accordingly.

Quoted 290 lines
---
 xen/arch/x86/dmi_scan.c    |    4 ++--
 xen/arch/x86/domain_page.c |    2 +-
 xen/arch/x86/efi/stub.c    |   11 ++++++++---
 xen/arch/x86/mpparse.c     |    4 ++--
 xen/arch/x86/setup.c       |   10 +++++-----
 xen/arch/x86/shutdown.c    |    2 +-
 xen/arch/x86/time.c        |    2 +-
 xen/arch/x86/xen.lds.S     |    2 --
 xen/common/efi/boot.c      |    4 ++++
 xen/common/efi/runtime.c   |   17 +++++++----------
 xen/drivers/acpi/osl.c     |    2 +-
 xen/include/xen/efi.h      |   16 ++++++++++++++--
 12 files changed, 46 insertions(+), 30 deletions(-)
xen/arch/x86/dmi_scan.c +2 -2
index 269168c..95c5a77 100644
@@ -229,7 +229,7 @@ const char *__init dmi_get_table(paddr_t *base, u32 *len)
 {
 	static unsigned int __initdata instance;
 
-	if (efi_enabled) {
+	if (efi_enabled(EFI_PLATFORM)) {
 		if (efi_smbios3_size && !(instance & 1)) {
 			*base = efi_smbios3_address;
 			*len = efi_smbios3_size;
@@ -693,7 +693,7 @@ static void __init dmi_decode(struct dmi_header *dm)
 
 void __init dmi_scan_machine(void)
 {
-	if ((!efi_enabled ? dmi_iterate(dmi_decode) :
+	if ((!efi_enabled(EFI_PLATFORM) ? dmi_iterate(dmi_decode) :
 	                    dmi_efi_iterate(dmi_decode)) == 0)
  		dmi_check_system(dmi_blacklist);
 	else
xen/arch/x86/domain_page.c +1 -1
index d86f8fe..fdf0d8a 100644
@@ -36,7 +36,7 @@ static inline struct vcpu *mapcache_current_vcpu(void)
      * domain's page tables but current may point at another domain's VCPU.
      * Return NULL as though current is not properly set up yet.
      */
-    if ( efi_enabled && efi_rs_using_pgtables() )
+    if ( efi_enabled(EFI_PLATFORM) && efi_rs_using_pgtables() )
         return NULL;
 
     /*
xen/arch/x86/efi/stub.c +8 -3
index 07c2bd0..c5ae369 100644
@@ -4,9 +4,14 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+struct efi __read_mostly efi = {
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
+};
 
 void __init efi_init_memory(void) { }
 
xen/arch/x86/mpparse.c +2 -2
index 8609f4a..5223579 100644
@@ -557,7 +557,7 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
 
 static __init void efi_unmap_mpf(void)
 {
-	if (efi_enabled)
+	if (efi_enabled(EFI_PLATFORM))
 		clear_fixmap(FIX_EFI_MPF);
 }
 
@@ -715,7 +715,7 @@ void __init find_smp_config (void)
 {
 	unsigned int address;
 
-	if (efi_enabled) {
+	if (efi_enabled(EFI_PLATFORM)) {
 		efi_check_config();
 		return;
 	}
xen/arch/x86/setup.c +5 -5
index ff34670..bce708c 100644
@@ -444,8 +444,8 @@ static void __init parse_video_info(void)
 {
     struct boot_video_info *bvi = &bootsym(boot_vid_info);
 
-    /* The EFI loader fills vga_console_info directly. */
-    if ( efi_enabled )
+    /* vga_console_info is filled directly on EFI platform. */
+    if ( efi_enabled(EFI_PLATFORM) )
         return;
 
     if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )
@@ -695,7 +695,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
         panic("dom0 kernel not specified. Check bootloader configuration.");
 
-    if ( efi_enabled )
+    if ( efi_enabled(EFI_PLATFORM) )
     {
         set_pdx_range(xen_phys_start >> PAGE_SHIFT,
                       (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
@@ -806,7 +806,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * we can relocate the dom0 kernel and other multiboot modules. Also, on
      * x86/64, we relocate Xen to higher memory.
      */
-    for ( i = 0; !efi_enabled && i < mbi->mods_count; i++ )
+    for ( i = 0; !efi_enabled(EFI_PLATFORM) && i < mbi->mods_count; i++ )
     {
         if ( mod[i].mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request.");
@@ -994,7 +994,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen.");
-    reserve_e820_ram(&boot_e820, efi_enabled ? mbi->mem_upper : __pa(&_start),
+    reserve_e820_ram(&boot_e820, efi_enabled(EFI_PLATFORM) ? mbi->mem_upper : __pa(&_start),
                      __pa(&_end));
 
     /* Late kexec reservation (dynamic start address). */
xen/arch/x86/shutdown.c +1 -1
index 0e1499d..79dcd16 100644
@@ -116,7 +116,7 @@ void machine_halt(void)
 static void default_reboot_type(void)
 {
     if ( reboot_type == BOOT_INVALID )
-        reboot_type = efi_enabled ? BOOT_EFI
+        reboot_type = efi_enabled(EFI_PLATFORM) ? BOOT_EFI
                                   : acpi_disabled ? BOOT_KBD
                                                   : BOOT_ACPI;
 }
xen/arch/x86/time.c +1 -1
index bbb7e6c..11e7e11 100644
@@ -690,7 +690,7 @@ static unsigned long get_cmos_time(void)
     static bool_t __read_mostly cmos_rtc_probe;
     boolean_param("cmos-rtc-probe", cmos_rtc_probe);
 
-    if ( efi_enabled )
+    if ( efi_enabled(EFI_PLATFORM) )
     {
         res = efi_get_time();
         if ( res )
xen/arch/x86/xen.lds.S +0 -2
index 3e1f2af..87f3e83 100644
@@ -191,8 +191,6 @@ SECTIONS
   .pad : {
     . = ALIGN(MB(16));
   } :text
-#else
-  efi = .;
 #endif
 
   /* Sections to be discarded */
xen/common/efi/boot.c +4 -0
index 75a939f..1f188fe 100644
@@ -717,6 +717,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     char *option_str;
     bool_t use_cfg_file;
 
+#ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
+    set_bit(EFI_PLATFORM, &efi.flags);
+#endif
+
     efi_ih = ImageHandle;
     efi_bs = SystemTable->BootServices;
     efi_bs_revision = efi_bs->Hdr.Revision;
xen/common/efi/runtime.c +7 -10
index ae87557..aa064e7 100644
@@ -10,14 +10,10 @@ DEFINE_XEN_GUEST_HANDLE(CHAR16);
 
 #ifndef COMPAT
 
-#ifdef CONFIG_ARM  /* Disabled until runtime services implemented */
-const bool_t efi_enabled = 0;
-#else
+#ifndef CONFIG_ARM
 # include <asm/i387.h>
 # include <asm/xstate.h>
 # include <public/platform.h>
-
-const bool_t efi_enabled = 1;
 #endif
 
 unsigned int __read_mostly efi_num_ct;
@@ -42,11 +38,12 @@ UINT64 __read_mostly efi_boot_remain_var_store_size;
 UINT64 __read_mostly efi_boot_max_var_size;
 
 struct efi __read_mostly efi = {
-	.acpi   = EFI_INVALID_TABLE_ADDR,
-	.acpi20 = EFI_INVALID_TABLE_ADDR,
-	.mps    = EFI_INVALID_TABLE_ADDR,
-	.smbios = EFI_INVALID_TABLE_ADDR,
-	.smbios3 = EFI_INVALID_TABLE_ADDR,
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
 };
 
 const struct efi_pci_rom *__read_mostly efi_pci_roms;
xen/drivers/acpi/osl.c +1 -1
index 4c09859..f4f6628 100644
@@ -66,7 +66,7 @@ void __init acpi_os_vprintf(const char *fmt, va_list args)
 
 acpi_physical_address __init acpi_os_get_root_pointer(void)
 {
-	if (efi_enabled) {
+	if (efi_enabled(EFI_PLATFORM)) {
 		if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
 			return efi.acpi20;
 		else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
xen/include/xen/efi.h +14 -2
index e74dad1..318bbec 100644
@@ -2,15 +2,17 @@
 #define __XEN_EFI_H__
 
 #ifndef __ASSEMBLY__
+#include <xen/bitops.h>
 #include <xen/types.h>
 #endif
 
-extern const bool_t efi_enabled;
-
 #define EFI_INVALID_TABLE_ADDR (~0UL)
 
+#define EFI_PLATFORM	0
+
 /* Add fields here only if they need to be referenced from non-EFI code. */
 struct efi {
+    unsigned long flags;
     unsigned long mps;          /* MPS table */
     unsigned long acpi;         /* ACPI table (IA64 ext 0.71) */
     unsigned long acpi20;       /* ACPI table (ACPI 2.0) */
@@ -40,6 +42,16 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *);
 int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *);
 int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *);
 
+/*
+ * Test whether the above EFI_* bits are enabled.
+ *
+ * Stolen from Linux Kernel.
+ */
+static inline bool_t efi_enabled(int feature)
+{
+    return test_bit(feature, &efi.flags) != 0;
+}
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __XEN_EFI_H__ */
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 9/23
#61 lore raw

Re: [PATCH v2 09/23] efi: create efi_enabled()

In reply to Daniel Kiper
Quoted 11 lines · Daniel Kiper

We need more fine grained knowledge about EFI environment and check for EFI platform and EFI loader separately to properly support multiboot2 protocol. In general Xen loaded by this protocol uses memory mappings and loaded modules in similar way to Xen loaded by multiboot (v1) protocol. Hence, create efi_enabled() which checks available features in efi.flags. This patch only defines EFI_PLATFORM feature which is equal to old efi_enabled == 1. Following patch will define EFI_LOADER feature accordingly.

Quoted 290 lines
---
 xen/arch/x86/dmi_scan.c    |    4 ++--
 xen/arch/x86/domain_page.c |    2 +-
 xen/arch/x86/efi/stub.c    |   11 ++++++++---
 xen/arch/x86/mpparse.c     |    4 ++--
 xen/arch/x86/setup.c       |   10 +++++-----
 xen/arch/x86/shutdown.c    |    2 +-
 xen/arch/x86/time.c        |    2 +-
 xen/arch/x86/xen.lds.S     |    2 --
 xen/common/efi/boot.c      |    4 ++++
 xen/common/efi/runtime.c   |   17 +++++++----------
 xen/drivers/acpi/osl.c     |    2 +-
 xen/include/xen/efi.h      |   16 ++++++++++++++--
 12 files changed, 46 insertions(+), 30 deletions(-)
xen/arch/x86/dmi_scan.c +2 -2
index 269168c..95c5a77 100644
@@ -229,7 +229,7 @@ const char *__init dmi_get_table(paddr_t *base, u32 *len)
 {
 	static unsigned int __initdata instance;
 
-	if (efi_enabled) {
+	if (efi_enabled(EFI_PLATFORM)) {
 		if (efi_smbios3_size && !(instance & 1)) {
 			*base = efi_smbios3_address;
 			*len = efi_smbios3_size;
@@ -693,7 +693,7 @@ static void __init dmi_decode(struct dmi_header *dm)
 
 void __init dmi_scan_machine(void)
 {
-	if ((!efi_enabled ? dmi_iterate(dmi_decode) :
+	if ((!efi_enabled(EFI_PLATFORM) ? dmi_iterate(dmi_decode) :
 	                    dmi_efi_iterate(dmi_decode)) == 0)
  		dmi_check_system(dmi_blacklist);
 	else
xen/arch/x86/domain_page.c +1 -1
index d86f8fe..fdf0d8a 100644
@@ -36,7 +36,7 @@ static inline struct vcpu *mapcache_current_vcpu(void)
      * domain's page tables but current may point at another domain's VCPU.
      * Return NULL as though current is not properly set up yet.
      */
-    if ( efi_enabled && efi_rs_using_pgtables() )
+    if ( efi_enabled(EFI_PLATFORM) && efi_rs_using_pgtables() )
         return NULL;
 
     /*
xen/arch/x86/efi/stub.c +8 -3
index 07c2bd0..c5ae369 100644
@@ -4,9 +4,14 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+struct efi __read_mostly efi = {
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
+};
 
 void __init efi_init_memory(void) { }
 
xen/arch/x86/mpparse.c +2 -2
index 8609f4a..5223579 100644
@@ -557,7 +557,7 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
 
 static __init void efi_unmap_mpf(void)
 {
-	if (efi_enabled)
+	if (efi_enabled(EFI_PLATFORM))
 		clear_fixmap(FIX_EFI_MPF);
 }
 
@@ -715,7 +715,7 @@ void __init find_smp_config (void)
 {
 	unsigned int address;
 
-	if (efi_enabled) {
+	if (efi_enabled(EFI_PLATFORM)) {
 		efi_check_config();
 		return;
 	}
xen/arch/x86/setup.c +5 -5
index ff34670..bce708c 100644
@@ -444,8 +444,8 @@ static void __init parse_video_info(void)
 {
     struct boot_video_info *bvi = &bootsym(boot_vid_info);
 
-    /* The EFI loader fills vga_console_info directly. */
-    if ( efi_enabled )
+    /* vga_console_info is filled directly on EFI platform. */
+    if ( efi_enabled(EFI_PLATFORM) )
         return;
 
     if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )
@@ -695,7 +695,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
         panic("dom0 kernel not specified. Check bootloader configuration.");
 
-    if ( efi_enabled )
+    if ( efi_enabled(EFI_PLATFORM) )
     {
         set_pdx_range(xen_phys_start >> PAGE_SHIFT,
                       (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
@@ -806,7 +806,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * we can relocate the dom0 kernel and other multiboot modules. Also, on
      * x86/64, we relocate Xen to higher memory.
      */
-    for ( i = 0; !efi_enabled && i < mbi->mods_count; i++ )
+    for ( i = 0; !efi_enabled(EFI_PLATFORM) && i < mbi->mods_count; i++ )
     {
         if ( mod[i].mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request.");
@@ -994,7 +994,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen.");
-    reserve_e820_ram(&boot_e820, efi_enabled ? mbi->mem_upper : __pa(&_start),
+    reserve_e820_ram(&boot_e820, efi_enabled(EFI_PLATFORM) ? mbi->mem_upper : __pa(&_start),
                      __pa(&_end));
 
     /* Late kexec reservation (dynamic start address). */
xen/arch/x86/shutdown.c +1 -1
index 0e1499d..79dcd16 100644
@@ -116,7 +116,7 @@ void machine_halt(void)
 static void default_reboot_type(void)
 {
     if ( reboot_type == BOOT_INVALID )
-        reboot_type = efi_enabled ? BOOT_EFI
+        reboot_type = efi_enabled(EFI_PLATFORM) ? BOOT_EFI
                                   : acpi_disabled ? BOOT_KBD
                                                   : BOOT_ACPI;
 }
xen/arch/x86/time.c +1 -1
index bbb7e6c..11e7e11 100644
@@ -690,7 +690,7 @@ static unsigned long get_cmos_time(void)
     static bool_t __read_mostly cmos_rtc_probe;
     boolean_param("cmos-rtc-probe", cmos_rtc_probe);
 
-    if ( efi_enabled )
+    if ( efi_enabled(EFI_PLATFORM) )
     {
         res = efi_get_time();
         if ( res )
xen/arch/x86/xen.lds.S +0 -2
index 3e1f2af..87f3e83 100644
@@ -191,8 +191,6 @@ SECTIONS
   .pad : {
     . = ALIGN(MB(16));
   } :text
-#else
-  efi = .;
 #endif
 
   /* Sections to be discarded */
xen/common/efi/boot.c +4 -0
index 75a939f..1f188fe 100644
@@ -717,6 +717,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     char *option_str;
     bool_t use_cfg_file;
 
+#ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
+    set_bit(EFI_PLATFORM, &efi.flags);
+#endif
+
     efi_ih = ImageHandle;
     efi_bs = SystemTable->BootServices;
     efi_bs_revision = efi_bs->Hdr.Revision;
xen/common/efi/runtime.c +7 -10
index ae87557..aa064e7 100644
@@ -10,14 +10,10 @@ DEFINE_XEN_GUEST_HANDLE(CHAR16);
 
 #ifndef COMPAT
 
-#ifdef CONFIG_ARM  /* Disabled until runtime services implemented */
-const bool_t efi_enabled = 0;
-#else
+#ifndef CONFIG_ARM
 # include <asm/i387.h>
 # include <asm/xstate.h>
 # include <public/platform.h>
-
-const bool_t efi_enabled = 1;
 #endif
 
 unsigned int __read_mostly efi_num_ct;
@@ -42,11 +38,12 @@ UINT64 __read_mostly efi_boot_remain_var_store_size;
 UINT64 __read_mostly efi_boot_max_var_size;
 
 struct efi __read_mostly efi = {
-	.acpi   = EFI_INVALID_TABLE_ADDR,
-	.acpi20 = EFI_INVALID_TABLE_ADDR,
-	.mps    = EFI_INVALID_TABLE_ADDR,
-	.smbios = EFI_INVALID_TABLE_ADDR,
-	.smbios3 = EFI_INVALID_TABLE_ADDR,
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
 };
 
 const struct efi_pci_rom *__read_mostly efi_pci_roms;
xen/drivers/acpi/osl.c +1 -1
index 4c09859..f4f6628 100644
@@ -66,7 +66,7 @@ void __init acpi_os_vprintf(const char *fmt, va_list args)
 
 acpi_physical_address __init acpi_os_get_root_pointer(void)
 {
-	if (efi_enabled) {
+	if (efi_enabled(EFI_PLATFORM)) {
 		if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
 			return efi.acpi20;
 		else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
xen/include/xen/efi.h +14 -2
index e74dad1..318bbec 100644
@@ -2,15 +2,17 @@
 #define __XEN_EFI_H__
 
 #ifndef __ASSEMBLY__
+#include <xen/bitops.h>
 #include <xen/types.h>
 #endif
 
-extern const bool_t efi_enabled;
-
 #define EFI_INVALID_TABLE_ADDR (~0UL)
 
+#define EFI_PLATFORM	0
+
 /* Add fields here only if they need to be referenced from non-EFI code. */
 struct efi {
+    unsigned long flags;
     unsigned long mps;          /* MPS table */
     unsigned long acpi;         /* ACPI table (IA64 ext 0.71) */
     unsigned long acpi20;       /* ACPI table (ACPI 2.0) */
@@ -40,6 +42,16 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *);
 int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *);
 int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *);
 
+/*
+ * Test whether the above EFI_* bits are enabled.
+ *
+ * Stolen from Linux Kernel.
+ */
+static inline bool_t efi_enabled(int feature)
+{
+    return test_bit(feature, &efi.flags) != 0;
+}
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __XEN_EFI_H__ */
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#62 lore raw

Re: [PATCH v2 09/23] efi: create efi_enabled()

In reply to Daniel Kiper
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/arch/x86/efi/stub.c +0 -1
@@ -4,9 +4,14 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
-#ifndef efi_enabled

xen/arch/x86/efi/stub.c line 14

Quoted 10 lines
xen/arch/x86/efi/stub.c +8 -2
-const bool_t efi_enabled = 0;
-#endif
+struct efi __read_mostly efi = {
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
+};

How is this change related to the subject of the patch?

xen/arch/x86/xen.lds.S SECTIONS · line 194

Quoted 9 lines
xen/arch/x86/xen.lds.S +0 -2
@@ -191,8 +191,6 @@ SECTIONS
   .pad : {
     . = ALIGN(MB(16));
   } :text
-#else
-  efi = .;
 #endif

Same here.

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE · line 723

Quoted 10 lines
xen/common/efi/boot.c +3 -0
@@ -717,6 +717,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE 
 *SystemTable)
     char *option_str;
     bool_t use_cfg_file;
 
+#ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
+    set_bit(EFI_PLATFORM, &efi.flags);
+#endif

Just for this to work? I don't see the need for all the pointers in the stub case - why can't this be a separate variable? We don't need to follow Linux with where the flags actually live...

Quoted 6 lines
xen/common/efi/runtime.c +0 -0
@@ -10,14 +10,10 @@ DEFINE_XEN_GUEST_HANDLE(CHAR16);
 
 #ifndef COMPAT
 

xen/common/efi/runtime.c DEFINE_XEN_GUEST_HANDLE(CHAR16); · line 17

Quoted 10 lines
xen/common/efi/runtime.c +1 -5
-#ifdef CONFIG_ARM  /* Disabled until runtime services implemented */
-const bool_t efi_enabled = 0;
-#else
+#ifndef CONFIG_ARM
 # include <asm/i387.h>
 # include <asm/xstate.h>
 # include <public/platform.h>
-
-const bool_t efi_enabled = 1;
 #endif

Afaict the proper replacement (at least at this point in the series) for this would be to statically initialize the flag set in this xen.efi case.

xen/common/efi/runtime.c int efi_runtime_call(struct xenpf_efi_runtime_call *); · line 48

Quoted 8 lines
xen/common/efi/runtime.c +4 -0
@@ -40,6 +42,16 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *);
 int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *);
 int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *);
 
+/*
+ * Test whether the above EFI_* bits are enabled.
+ *
+ * Stolen from Linux Kernel.

I don't think this second part of the comment makes a lot of sense for a minor piece of functionality like this.

Jan

#63 lore raw

Re: [PATCH v2 09/23] efi: create efi_enabled()

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/arch/x86/efi/stub.c +0 -0
@@ -4,9 +4,14 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
Quoted 13 lines

xen/arch/x86/efi/stub.c line 14

Quoted 11 lines
xen/arch/x86/efi/stub.c +8 -3
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+struct efi __read_mostly efi = {
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
+};

How is this change related to the subject of the patch?

I need to add this struct because...

Quoted 11 lines

xen/arch/x86/xen.lds.S SECTIONS · line 194

Quoted 9 lines
xen/arch/x86/xen.lds.S +0 -2
@@ -191,8 +191,6 @@ SECTIONS
   .pad : {
     . = ALIGN(MB(16));
   } :text
-#else
-  efi = .;
 #endif

Same here.

...this creates efi symbol to just satisfy linker and I am removing it. However, existing solution does not allocate space for this symbol and any references to acpi20, etc. does not make sense. As I saw any efi.* references are protected by relevant ifs but we should not do that because it makes code very fragile. If somebody does not know how efi symbol is created he/she may assume that it always represent valid structure and do invalid references somewhere. So, I still think that stub.c should define efi struct properly even if we assume that flags should not be there. However, I agree that this could be separate patch.

By the way why did you choose so strange way to satisfy liker needs?

Quoted 7 lines
Quoted 7 lines
xen/common/efi/boot.c +0 -0
@@ -717,6 +717,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE
 *SystemTable)
     char *option_str;
     bool_t use_cfg_file;
 
Quoted 6 lines

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 722

Quoted 3 lines
xen/common/efi/boot.c +3 -0
+#ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
+    set_bit(EFI_PLATFORM, &efi.flags);
+#endif

Just for this to work? I don't see the need for all the pointers in the stub case - why can't this be a separate variable? We don't

Could be but if we create struct with so generic name like just simple efi it suggest that this is good place to put flags there. If it is not how to call it? efi_flags? Or maybe we should rename efi to efi_tables too. Then everything will be clear.

Daniel

#64 lore raw

Re: [PATCH v2 09/23] efi: create efi_enabled()

Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 14:33, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/arch/x86/efi/stub.c +0 -0
@@ -4,9 +4,14 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
Quoted 13 lines

xen/arch/x86/efi/stub.c line 14

Quoted 11 lines
xen/arch/x86/efi/stub.c +8 -3
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+struct efi __read_mostly efi = {
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
+};

How is this change related to the subject of the patch?

I need to add this struct because...

Quoted 11 lines

xen/arch/x86/xen.lds.S SECTIONS · line 194

Quoted 9 lines
xen/arch/x86/xen.lds.S +0 -2
@@ -191,8 +191,6 @@ SECTIONS
   .pad : {
     . = ALIGN(MB(16));
   } :text
-#else
-  efi = .;
 #endif

Same here.

...this creates efi symbol to just satisfy linker and I am removing it. However, existing solution does not allocate space for this symbol and any references to acpi20, etc. does not make sense. As I saw any efi.* references are protected by relevant ifs but we should not do that because it makes code very fragile. If somebody does not know how efi symbol is created he/she may assume that it always represent valid structure and do invalid references somewhere. So, I still think that stub.c should define efi struct properly even if we assume that flags should not be there. However, I agree that this could be separate patch.

Quoted 1 line

By the way why did you choose so strange way to satisfy liker needs?

To me there's nothing strange about it: I want a symbol that occupies no space in memory.

Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
xen/common/efi/boot.c +0 -0
@@ -717,6 +717,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE
 *SystemTable)
     char *option_str;
     bool_t use_cfg_file;
 
Quoted 6 lines

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 722

Quoted 3 lines
xen/common/efi/boot.c +3 -0
+#ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
+    set_bit(EFI_PLATFORM, &efi.flags);
+#endif

Just for this to work? I don't see the need for all the pointers in the stub case - why can't this be a separate variable? We don't

Quoted 4 lines

Could be but if we create struct with so generic name like just simple efi it suggest that this is good place to put flags there. If it is not how to call it? efi_flags? Or maybe we should rename efi to efi_tables too. Then everything will be clear.

I agree that this may be matter of taste, but to me the current naming looks quite fine. And yes, efi_flags of efi_state would be a fine name. In general I wouldn't even mind it to be a field in the structure, if only that resulted in the _full_ structure to be allocated even in the no-EFI build case. I admit though that with the goal of always building EFI code (unless the tool chain doesn't support doing so) this becomes less of an issue; otoh us probably wanting some Kconfig-like mechanism sooner or later to {en,dis}able certain features would call for this to remain separable. And yes, at that point it could be done by #ifdef-ing out everything by the flags member.

So based on the above I'm withdrawing my implied objection, but please make sure you write better patch descriptions explaining what is done and _why_.

Jan

#65 lore raw

Re: [PATCH v2 09/23] efi: create efi_enabled()

In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/arch/x86/efi/stub.c +0 -0
@@ -4,9 +4,14 @@
 #include <xen/lib.h>
 #include <asm/page.h>
 
Quoted 13 lines

xen/arch/x86/efi/stub.c line 14

Quoted 11 lines
xen/arch/x86/efi/stub.c +8 -3
-#ifndef efi_enabled
-const bool_t efi_enabled = 0;
-#endif
+struct efi __read_mostly efi = {
+	.flags   = 0, /* Initialized later. */
+	.acpi    = EFI_INVALID_TABLE_ADDR,
+	.acpi20  = EFI_INVALID_TABLE_ADDR,
+	.mps     = EFI_INVALID_TABLE_ADDR,
+	.smbios  = EFI_INVALID_TABLE_ADDR,
+	.smbios3 = EFI_INVALID_TABLE_ADDR
+};

How is this change related to the subject of the patch?

I need to add this struct because...

Quoted 11 lines

xen/arch/x86/xen.lds.S SECTIONS · line 194

Quoted 9 lines
xen/arch/x86/xen.lds.S +0 -2
@@ -191,8 +191,6 @@ SECTIONS
   .pad : {
     . = ALIGN(MB(16));
   } :text
-#else
-  efi = .;
 #endif

Same here.

...this creates efi symbol to just satisfy linker and I am removing it. However, existing solution does not allocate space for this symbol and any references to acpi20, etc. does not make sense. As I saw any efi.* references are protected by relevant ifs but we should not do that because it makes code very fragile. If somebody does not know how efi symbol is created he/she may assume that it always represent valid structure and do invalid references somewhere. So, I still think that stub.c should define efi struct properly even if we assume that flags should not be there. However, I agree that this could be separate patch.

By the way why did you choose so strange way to satisfy liker needs?

Quoted 7 lines
Quoted 7 lines
xen/common/efi/boot.c +0 -0
@@ -717,6 +717,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE
 *SystemTable)
     char *option_str;
     bool_t use_cfg_file;
 
Quoted 6 lines

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 722

Quoted 3 lines
xen/common/efi/boot.c +3 -0
+#ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
+    set_bit(EFI_PLATFORM, &efi.flags);
+#endif

Just for this to work? I don't see the need for all the pointers in the stub case - why can't this be a separate variable? We don't

Could be but if we create struct with so generic name like just simple efi it suggest that this is good place to put flags there. If it is not how to call it? efi_flags? Or maybe we should rename efi to efi_tables too. Then everything will be clear.

Daniel

#66 lore raw

PATCH v2 10/23 efi: build xen.gz with EFI code

In reply to Daniel Kiper

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then it must contain "linear" (or "flat") representation of code and data. Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that xen.efi further diverge from xen ELF file (in terms of contents and build method). ELF have all needed properties. So, it means that this is good starting point for further development. Additionally, I think that this is also good starting point for further xen.efi code and build optimizations. It looks that there is a chance that finally we can generate xen.efi directly from xen ELF using just simple objcopy.

---
v2 - suggestions/fixes:
- build EFI code only if it is supported in a given build environment (suggested by Jan Beulich).

---
 xen/arch/x86/Makefile     |   13 +++++--------
 xen/arch/x86/efi/Makefile |   16 +++++++++-------
 xen/arch/x86/mm.c         |    3 ++-
 xen/common/efi/runtime.c  |    6 ++++++
 4 files changed, 22 insertions(+), 16 deletions(-)
xen/arch/x86/Makefile +5 -8
index 5f24951..0335445 100644
@@ -80,7 +80,7 @@ ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in
 
 ifeq ($(lto),y)
 # Gather all LTO objects together
-prelink_lto.o: $(ALL_OBJS)
+prelink_lto.o: $(ALL_OBJS) efi/relocs-dummy.o
 	$(LD_LTO) -r -o $@ $^
 
 prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
@@ -90,14 +90,14 @@ prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
 prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
 	$(LD) $(LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o
+prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o
 	$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
 else
-prelink.o: $(ALL_OBJS)
+prelink.o: $(ALL_OBJS) efi/relocs-dummy.o
 	$(LD) $(LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o
-	$(guard) $(LD) $(LDFLAGS) -r -o $@ $(filter-out %/efi/built_in.o,$^)
+prelink-efi.o: $(ALL_OBJS)
+	$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
 endif
 
 $(BASEDIR)/common/symbols-dummy.o:
@@ -146,9 +146,6 @@ $(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbol
 	if $(guard) false; then rm -f $@; echo 'EFI support disabled'; fi
 	rm -f $(@D)/.$(@F).[0-9]*
 
-efi/boot.init.o efi/runtime.o efi/compat.o: $(BASEDIR)/arch/x86/efi/built_in.o
-efi/boot.init.o efi/runtime.o efi/compat.o: ;
-
 asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c
 	$(CC) $(filter-out -flto,$(CFLAGS)) -S -o $@ $<
 
xen/arch/x86/efi/Makefile +9 -7
index 1daa7ac..b1e8883 100644
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o
 
-stub.o: $(extra-y)
+ifeq ($(efi),y)
+obj-y += boot.init.o
+obj-y += compat.o
+obj-y += runtime.o
+else
+obj-y += stub.o
+endif
xen/arch/x86/mm.c +2 -1
index 342414f..cef2eb6 100644
@@ -344,7 +344,8 @@ void __init arch_init_memory(void)
 
     subarch_init_memory();
 
-    efi_init_memory();
+    if ( efi_enabled(EFI_PLATFORM) )
+        efi_init_memory();
 
     mem_sharing_init();
 
xen/common/efi/runtime.c +6 -0
index aa064e7..3eb21c1 100644
@@ -167,6 +167,9 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
 {
     unsigned int i, n;
 
+    if ( !efi_enabled(EFI_PLATFORM) )
+        return -EOPNOTSUPP;
+
     switch ( idx )
     {
     case XEN_FW_EFI_VERSION:
@@ -301,6 +304,9 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
     EFI_STATUS status = EFI_NOT_STARTED;
     int rc = 0;
 
+    if ( !efi_enabled(EFI_PLATFORM) )
+        return -EOPNOTSUPP;
+
     switch ( op->function )
     {
     case XEN_EFI_get_time:
Signature · 1 line
1.7.10.4
#67 lore raw

PATCH v2 10/23 efi: build xen.gz with EFI code

In reply to Daniel Kiper

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then it must contain "linear" (or "flat") representation of code and data. Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that xen.efi further diverge from xen ELF file (in terms of contents and build method). ELF have all needed properties. So, it means that this is good starting point for further development. Additionally, I think that this is also good starting point for further xen.efi code and build optimizations. It looks that there is a chance that finally we can generate xen.efi directly from xen ELF using just simple objcopy.

---
v2 - suggestions/fixes:
- build EFI code only if it is supported in a given build environment (suggested by Jan Beulich).

---
 xen/arch/x86/Makefile     |   13 +++++--------
 xen/arch/x86/efi/Makefile |   16 +++++++++-------
 xen/arch/x86/mm.c         |    3 ++-
 xen/common/efi/runtime.c  |    6 ++++++
 4 files changed, 22 insertions(+), 16 deletions(-)
xen/arch/x86/Makefile +5 -8
index 5f24951..0335445 100644
@@ -80,7 +80,7 @@ ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in
 
 ifeq ($(lto),y)
 # Gather all LTO objects together
-prelink_lto.o: $(ALL_OBJS)
+prelink_lto.o: $(ALL_OBJS) efi/relocs-dummy.o
 	$(LD_LTO) -r -o $@ $^
 
 prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
@@ -90,14 +90,14 @@ prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
 prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
 	$(LD) $(LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o
+prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o
 	$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
 else
-prelink.o: $(ALL_OBJS)
+prelink.o: $(ALL_OBJS) efi/relocs-dummy.o
 	$(LD) $(LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o
-	$(guard) $(LD) $(LDFLAGS) -r -o $@ $(filter-out %/efi/built_in.o,$^)
+prelink-efi.o: $(ALL_OBJS)
+	$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
 endif
 
 $(BASEDIR)/common/symbols-dummy.o:
@@ -146,9 +146,6 @@ $(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbol
 	if $(guard) false; then rm -f $@; echo 'EFI support disabled'; fi
 	rm -f $(@D)/.$(@F).[0-9]*
 
-efi/boot.init.o efi/runtime.o efi/compat.o: $(BASEDIR)/arch/x86/efi/built_in.o
-efi/boot.init.o efi/runtime.o efi/compat.o: ;
-
 asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c
 	$(CC) $(filter-out -flto,$(CFLAGS)) -S -o $@ $<
 
xen/arch/x86/efi/Makefile +9 -7
index 1daa7ac..b1e8883 100644
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o
 
-stub.o: $(extra-y)
+ifeq ($(efi),y)
+obj-y += boot.init.o
+obj-y += compat.o
+obj-y += runtime.o
+else
+obj-y += stub.o
+endif
xen/arch/x86/mm.c +2 -1
index 342414f..cef2eb6 100644
@@ -344,7 +344,8 @@ void __init arch_init_memory(void)
 
     subarch_init_memory();
 
-    efi_init_memory();
+    if ( efi_enabled(EFI_PLATFORM) )
+        efi_init_memory();
 
     mem_sharing_init();
 
xen/common/efi/runtime.c +6 -0
index aa064e7..3eb21c1 100644
@@ -167,6 +167,9 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
 {
     unsigned int i, n;
 
+    if ( !efi_enabled(EFI_PLATFORM) )
+        return -EOPNOTSUPP;
+
     switch ( idx )
     {
     case XEN_FW_EFI_VERSION:
@@ -301,6 +304,9 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
     EFI_STATUS status = EFI_NOT_STARTED;
     int rc = 0;
 
+    if ( !efi_enabled(EFI_PLATFORM) )
+        return -EOPNOTSUPP;
+
     switch ( op->function )
     {
     case XEN_EFI_get_time:
Signature · 1 line
1.7.10.4
#68 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 88 lines · Daniel Kiper

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then it must contain "linear" (or "flat") representation of code and data. Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that xen.efi further diverge from xen ELF file (in terms of contents and build method). ELF have all needed properties. So, it means that this is good starting point for further development. Additionally, I think that this is also good starting point for further xen.efi code and build optimizations. It looks that there is a chance that finally we can generate xen.efi directly from xen ELF using just simple objcopy.

---
v2 - suggestions/fixes:
- build EFI code only if it is supported in a given build environment (suggested by Jan Beulich).

---
 xen/arch/x86/Makefile     |   13 +++++--------
 xen/arch/x86/efi/Makefile |   16 +++++++++-------
 xen/arch/x86/mm.c         |    3 ++-
 xen/common/efi/runtime.c  |    6 ++++++
 4 files changed, 22 insertions(+), 16 deletions(-)
xen/arch/x86/Makefile +5 -8
index 5f24951..0335445 100644
@@ -80,7 +80,7 @@ ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in
 
 ifeq ($(lto),y)
 # Gather all LTO objects together
-prelink_lto.o: $(ALL_OBJS)
+prelink_lto.o: $(ALL_OBJS) efi/relocs-dummy.o
 	$(LD_LTO) -r -o $@ $^
 
 prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
@@ -90,14 +90,14 @@ prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
 prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
 	$(LD) $(LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o
+prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o
 	$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
 else
-prelink.o: $(ALL_OBJS)
+prelink.o: $(ALL_OBJS) efi/relocs-dummy.o
 	$(LD) $(LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o
-	$(guard) $(LD) $(LDFLAGS) -r -o $@ $(filter-out %/efi/built_in.o,$^)
+prelink-efi.o: $(ALL_OBJS)
+	$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
 endif
 
 $(BASEDIR)/common/symbols-dummy.o:
@@ -146,9 +146,6 @@ $(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbol
 	if $(guard) false; then rm -f $@; echo 'EFI support disabled'; fi
 	rm -f $(@D)/.$(@F).[0-9]*
 
-efi/boot.init.o efi/runtime.o efi/compat.o: $(BASEDIR)/arch/x86/efi/built_in.o
-efi/boot.init.o efi/runtime.o efi/compat.o: ;
-
 asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c
 	$(CC) $(filter-out -flto,$(CFLAGS)) -S -o $@ $<
 
xen/arch/x86/efi/Makefile +1 -6
index 1daa7ac..b1e8883 100644
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o

xen/arch/x86/efi/Makefile line 16

Quoted 10 lines
xen/arch/x86/efi/Makefile +8 -1
+extra-y += relocs-dummy.o
 
-stub.o: $(extra-y)
+ifeq ($(efi),y)
+obj-y += boot.init.o
+obj-y += compat.o
+obj-y += runtime.o
+else
+obj-y += stub.o
+endif

That makefile magic I skipped over, but the C code below looks good, so

Quoted 46 lines
xen/arch/x86/mm.c +2 -1
index 342414f..cef2eb6 100644
@@ -344,7 +344,8 @@ void __init arch_init_memory(void)
 
     subarch_init_memory();
 
-    efi_init_memory();
+    if ( efi_enabled(EFI_PLATFORM) )
+        efi_init_memory();
 
     mem_sharing_init();
 
xen/common/efi/runtime.c +6 -0
index aa064e7..3eb21c1 100644
@@ -167,6 +167,9 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
 {
     unsigned int i, n;
 
+    if ( !efi_enabled(EFI_PLATFORM) )
+        return -EOPNOTSUPP;
+
     switch ( idx )
     {
     case XEN_FW_EFI_VERSION:
@@ -301,6 +304,9 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
     EFI_STATUS status = EFI_NOT_STARTED;
     int rc = 0;
 
+    if ( !efi_enabled(EFI_PLATFORM) )
+        return -EOPNOTSUPP;
+
     switch ( op->function )
     {
     case XEN_EFI_get_time:
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#69 lore raw

Re: [Xen-devel] [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Daniel Kiper
Quoted 88 lines · Daniel Kiper

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then it must contain "linear" (or "flat") representation of code and data. Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that xen.efi further diverge from xen ELF file (in terms of contents and build method). ELF have all needed properties. So, it means that this is good starting point for further development. Additionally, I think that this is also good starting point for further xen.efi code and build optimizations. It looks that there is a chance that finally we can generate xen.efi directly from xen ELF using just simple objcopy.

---
v2 - suggestions/fixes:
- build EFI code only if it is supported in a given build environment (suggested by Jan Beulich).

---
 xen/arch/x86/Makefile     |   13 +++++--------
 xen/arch/x86/efi/Makefile |   16 +++++++++-------
 xen/arch/x86/mm.c         |    3 ++-
 xen/common/efi/runtime.c  |    6 ++++++
 4 files changed, 22 insertions(+), 16 deletions(-)
xen/arch/x86/Makefile +5 -8
index 5f24951..0335445 100644
@@ -80,7 +80,7 @@ ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in
 
 ifeq ($(lto),y)
 # Gather all LTO objects together
-prelink_lto.o: $(ALL_OBJS)
+prelink_lto.o: $(ALL_OBJS) efi/relocs-dummy.o
 	$(LD_LTO) -r -o $@ $^
 
 prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
@@ -90,14 +90,14 @@ prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
 prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
 	$(LD) $(LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o
+prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o
 	$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
 else
-prelink.o: $(ALL_OBJS)
+prelink.o: $(ALL_OBJS) efi/relocs-dummy.o
 	$(LD) $(LDFLAGS) -r -o $@ $^
 
-prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o
-	$(guard) $(LD) $(LDFLAGS) -r -o $@ $(filter-out %/efi/built_in.o,$^)
+prelink-efi.o: $(ALL_OBJS)
+	$(guard) $(LD) $(LDFLAGS) -r -o $@ $^
 endif
 
 $(BASEDIR)/common/symbols-dummy.o:
@@ -146,9 +146,6 @@ $(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbol
 	if $(guard) false; then rm -f $@; echo 'EFI support disabled'; fi
 	rm -f $(@D)/.$(@F).[0-9]*
 
-efi/boot.init.o efi/runtime.o efi/compat.o: $(BASEDIR)/arch/x86/efi/built_in.o
-efi/boot.init.o efi/runtime.o efi/compat.o: ;
-
 asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c
 	$(CC) $(filter-out -flto,$(CFLAGS)) -S -o $@ $<
 
xen/arch/x86/efi/Makefile +1 -6
index 1daa7ac..b1e8883 100644
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o

xen/arch/x86/efi/Makefile line 16

Quoted 10 lines
xen/arch/x86/efi/Makefile +8 -1
+extra-y += relocs-dummy.o
 
-stub.o: $(extra-y)
+ifeq ($(efi),y)
+obj-y += boot.init.o
+obj-y += compat.o
+obj-y += runtime.o
+else
+obj-y += stub.o
+endif

That makefile magic I skipped over, but the C code below looks good, so

Quoted 46 lines
xen/arch/x86/mm.c +2 -1
index 342414f..cef2eb6 100644
@@ -344,7 +344,8 @@ void __init arch_init_memory(void)
 
     subarch_init_memory();
 
-    efi_init_memory();
+    if ( efi_enabled(EFI_PLATFORM) )
+        efi_init_memory();
 
     mem_sharing_init();
 
xen/common/efi/runtime.c +6 -0
index aa064e7..3eb21c1 100644
@@ -167,6 +167,9 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
 {
     unsigned int i, n;
 
+    if ( !efi_enabled(EFI_PLATFORM) )
+        return -EOPNOTSUPP;
+
     switch ( idx )
     {
     case XEN_FW_EFI_VERSION:
@@ -301,6 +304,9 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
     EFI_STATUS status = EFI_NOT_STARTED;
     int rc = 0;
 
+    if ( !efi_enabled(EFI_PLATFORM) )
+        return -EOPNOTSUPP;
+
     switch ( op->function )
     {
     case XEN_EFI_get_time:
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#70 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Daniel Kiper
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then

DYM "a non-ELF file"?

Quoted 1 line

it must contain "linear" (or "flat") representation of code and data.

Why? Please don't just put out statements, but also reasons (i.e. at least which component is unable to deal with the current [valid afaict] PE image we have).

Quoted 4 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

Quoted 7 lines
xen/arch/x86/efi/Makefile +0 -2
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-

xen/arch/x86/efi/Makefile line 8

Quoted 10 lines
xen/arch/x86/efi/Makefile +2 -4
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

xen/arch/x86/efi/Makefile line 14

Quoted 1 line
xen/arch/x86/efi/Makefile +0 -1
-stub.o: $(extra-y)

With this dependency removed (instead of perhaps replaced or extended) - what will trigger relocs-dummy.o to be (re)built?

xen/arch/x86/efi/Makefile line 16

Quoted 7 lines
xen/arch/x86/efi/Makefile +7 -0
+ifeq ($(efi),y)
+obj-y += boot.init.o
+obj-y += compat.o
+obj-y += runtime.o
+else
+obj-y += stub.o
+endif

obj-y := stub.o
obj-$(efi) := boot.init.o compat.o runtime.o

xen/arch/x86/mm.c void __init arch_init_memory(void) · line 348

Quoted 9 lines
xen/arch/x86/mm.c +2 -1
@@ -344,7 +344,8 @@ void __init arch_init_memory(void)
 
     subarch_init_memory();
 
-    efi_init_memory();
+    if ( efi_enabled(EFI_PLATFORM) )
+        efi_init_memory();

I think I'd prefer such checks to be constrained to EFI code where possible, i.e. in this case do the check inside efi_init_memory().

Jan

#71 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then

Quoted 7 lines

DYM "a non-ELF file"?

Quoted 1 line

it must contain "linear" (or "flat") representation of code and data.

Why? Please don't just put out statements, but also reasons (i.e. at least which component is unable to deal with the current [valid afaict] PE image we have).

This is a requirement of multiboot (v1) or multiboot2 protocol. They both know nothing about PE image format.

Quoted 10 lines
Quoted 4 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

From PE loader point of view everything is OK. However, current Xen PE

image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids). Potentially we can change that (probably by playing with linker script or using objcopy or just simply building proper PE file ourselves; I did some experiments once but they are not exhaustive and I am not able to tell which solution will be the best in our case), however, this is next step and it will be investigated after applying this patch series to Xen source.

Quoted 15 lines
Quoted 15 lines
xen/arch/x86/efi/Makefile +1 -5
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
Quoted 4 lines

xen/arch/x86/efi/Makefile line 8

Quoted 2 lines
xen/arch/x86/efi/Makefile +1 -1
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

Because we need proper EFI code in xen.gz to support boot via multiboot2 on EFI platforms.

Quoted 4 lines

xen/arch/x86/efi/Makefile line 14

Quoted 1 line
xen/arch/x86/efi/Makefile +0 -1
-stub.o: $(extra-y)

With this dependency removed (instead of perhaps replaced or extended) - what will trigger relocs-dummy.o to be (re)built?

It is triggered by prelink.o build rule in xen/arch/x86/Makefile. Looks that it will suffice but I am not sure right now this is good solution. Hmmm... If it is OK then we can remove "extra-y += relocs-dummy.o".

Daniel

#72 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Jan Beulich
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then

Quoted 7 lines

DYM "a non-ELF file"?

Quoted 1 line

it must contain "linear" (or "flat") representation of code and data.

Why? Please don't just put out statements, but also reasons (i.e. at least which component is unable to deal with the current [valid afaict] PE image we have).

This is a requirement of multiboot (v1) or multiboot2 protocol. They both know nothing about PE image format.

Quoted 8 lines
Quoted 4 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids). Potentially we can change that (probably by playing with linker script or using objcopy or just simply building proper PE file ourselves; I did some experiments once but they are not exhaustive and I am not able to tell which solution will be the best in our case), however, this is next step and it will be investigated after applying this patch series to Xen source.

Quoted 15 lines
Quoted 15 lines
xen/arch/x86/efi/Makefile +1 -5
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
Quoted 4 lines

xen/arch/x86/efi/Makefile line 8

Quoted 2 lines
xen/arch/x86/efi/Makefile +1 -1
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

Because we need proper EFI code in xen.gz to support boot via multiboot2 on EFI platforms.

Quoted 4 lines

xen/arch/x86/efi/Makefile line 14

Quoted 1 line
xen/arch/x86/efi/Makefile +0 -1
-stub.o: $(extra-y)

With this dependency removed (instead of perhaps replaced or extended) - what will trigger relocs-dummy.o to be (re)built?

It is triggered by prelink.o build rule in xen/arch/x86/Makefile. Looks that it will suffice but I am not sure right now this is good solution. Hmmm... If it is OK then we can remove "extra-y += relocs-dummy.o".

Daniel

#73 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 15:59, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then

DYM "a non-ELF file"?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

it must contain "linear" (or "flat") representation of code and data.

Why? Please don't just put out statements, but also reasons (i.e. at least which component is unable to deal with the current [valid afaict] PE image we have).

This is a requirement of multiboot (v1) or multiboot2 protocol. They both know nothing about PE image format.

And hence how specifically we arrange data inside the image should be benign to them, as they won't be able to load the file _anyway_.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

Quoted 8 lines
Quoted 3 lines

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
xen/arch/x86/efi/Makefile +1 -5
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o >disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
Quoted 7 lines
Quoted 4 lines

xen/arch/x86/efi/Makefile line 8

Quoted 2 lines
xen/arch/x86/efi/Makefile +1 -1
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

Because we need proper EFI code in xen.gz to support boot via multiboot2 on EFI platforms.

What would we need that for when not building an EFI-capable binary anyway?

Quoted 6 lines
Quoted 4 lines

xen/arch/x86/efi/Makefile line 14

Quoted 1 line
xen/arch/x86/efi/Makefile +0 -1
-stub.o: $(extra-y)

With this dependency removed (instead of perhaps replaced or extended) - what will trigger relocs-dummy.o to be (re)built?

It is triggered by prelink.o build rule in xen/arch/x86/Makefile.

No. Or better - if it is, then this is wrong. With the way our build logic works, unless there are exceptional circumstances things in a certain directory should be built _only_ when recursion reaches that particular directory (i.e. not from any of its parents).

Jan

#74 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 31 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 15:59, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then

DYM "a non-ELF file"?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

it must contain "linear" (or "flat") representation of code and data.

Why? Please don't just put out statements, but also reasons (i.e. at least which component is unable to deal with the current [valid afaict] PE image we have).

This is a requirement of multiboot (v1) or multiboot2 protocol. They both know nothing about PE image format.

And hence how specifically we arrange data inside the image should be benign to them, as they won't be able to load the file _anyway_.

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

Quoted 7 lines
Quoted 4 lines

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

This implies that we can e.g. build valid ELF file which is also multiboot2 protocol compatible image. And we does. However, we can go further. Potentially we can build valid PE image which is also valid multiboot2 protocol image. Although current build method does not satisfy requirement number 2 because, e.g.:

Sections:

Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         001513d0  ffff82d080200000  ffff82d080200000  00001000  2**12
                                      ^^^^^^                    ^^^^^^^^

CONTENTS, ALLOC, LOAD, CODE
1 .rodata 0004de12 ffff82d0803513e0 ffff82d0803513e0 00153000 2**5
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, READONLY, DATA

Hence, we must use special method to build PE image (I discussed that in my earlier email in that topic) to do it compatible with multiboot2 protocol. This way one file could be loaded by native PE loader, mulitboot (v1) protocol (it requires relevant header but it does not interfere with PE and multiboot2 protocol stuff) and mutliboot2 protocol compatible loaders. Additionally, if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

I hope that helps.

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
xen/arch/x86/efi/Makefile +0 -2
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-

xen/arch/x86/efi/Makefile line 8

Quoted 10 lines
xen/arch/x86/efi/Makefile +2 -4
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o >disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

Quoted 5 lines
Quoted 2 lines

Because we need proper EFI code in xen.gz to support boot via multiboot2 on EFI platforms.

What would we need that for when not building an EFI-capable binary anyway?

xen/arch/x86/efi/stub.c

Daniel

#75 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 12 lines · Daniel Kiper
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
Quoted 5 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Quoted 7 lines
Quoted 2 lines

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

What is the reasoning for the restriction in 2. ?

~Andrew

#76 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Daniel Kiper
Quoted 12 lines · Daniel Kiper
Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
Quoted 5 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Quoted 7 lines
Quoted 2 lines

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

What is the reasoning for the restriction in 2. ?

~Andrew

#77 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Daniel Kiper
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

Quoted 7 lines
Quoted 3 lines

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Quoted 7 lines
Quoted 5 lines

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

What is the reasoning for the restriction in 2. ?

You are able to describe following segments using only multiboot2 features:
1) text and data segment bundled into one thing; in general boot loader does not care a lot about its internal structure; it should be just string of bytes which is loaded as is into memory (without any conversion, mangling, etc.),
2) BSS segment which follows one mentioned above; it does not have any representation in image; boot loader just reserve and zero memory of a given size.

So, as you can see Xen text and data segment must live in one place in file to satisfy multiboot2 protocol requirements. However, it does not mean that from Xen point of view image cannot have more then one section/segment with required alignments, etc.

Daniel

#78 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Andrew Cooper
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Daniel Kiper
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

Quoted 7 lines
Quoted 3 lines

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Quoted 7 lines
Quoted 5 lines

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

What is the reasoning for the restriction in 2. ?

You are able to describe following segments using only multiboot2 features:
1) text and data segment bundled into one thing; in general boot loader does not care a lot about its internal structure; it should be just string of bytes which is loaded as is into memory (without any conversion, mangling, etc.),
2) BSS segment which follows one mentioned above; it does not have any representation in image; boot loader just reserve and zero memory of a given size.

So, as you can see Xen text and data segment must live in one place in file to satisfy multiboot2 protocol requirements. However, it does not mean that from Xen point of view image cannot have more then one section/segment with required alignments, etc.

Daniel

#79 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Daniel Kiper
Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 24.08.15 at 22:54, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 15:59, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

Quoted 7 lines
Quoted 4 lines

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

This implies that we can e.g. build valid ELF file which is also multiboot2 protocol compatible image. And we does. However, we can go further. Potentially we can build valid PE image which is also valid multiboot2 protocol image. Although current build method does not satisfy requirement number 2 because, e.g.:

Sections:
Idx Name Size VMA LMA File off
Algn
0 .text 001513d0 ffff82d080200000 ffff82d080200000 00001000
2**12
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, CODE
1 .rodata 0004de12 ffff82d0803513e0 ffff82d0803513e0 00153000
2**5
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, READONLY, DATA

Quoted 3 lines

Hence, we must use special method to build PE image (I discussed that in my earlier email in that topic) to do it compatible with multiboot2 protocol.

And you realize that we use a "special method" for building the current "flat" ELF image too?

Quoted 5 lines

This way one file could be loaded by native PE loader, mulitboot (v1) protocol
(it requires relevant header but it does not interfere with PE and multiboot2
protocol stuff) and mutliboot2 protocol compatible loaders. Additionally,

Quoted 8 lines

if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying
this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

I think whether what you do now makes sense depends on the ultimate goal: If we want a single binary usable for all three cases, then while yes, having EFI code available in the ELF image makes sense, using an ELF Image won't work. And we can't have an image being both ELF and PE. Hence the goal ought to be to have a single PE image, and with that the direction you move seems wrong.

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
xen/arch/x86/efi/Makefile +0 -2
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-

xen/arch/x86/efi/Makefile line 8

Quoted 10 lines
xen/arch/x86/efi/Makefile +2 -4
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi heck.o >disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Because we need proper EFI code in xen.gz to support boot via multiboot2 on EFI platforms.

What would we need that for when not building an EFI-capable binary anyway?

xen/arch/x86/efi/stub.c

This is still too unspecific: I can't see any reference from that file to any of the symbols relocs-dummy.S provides.

Jan

#80 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Daniel Kiper
Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 24.08.15 at 22:54, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 15:59, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

Quoted 7 lines
Quoted 4 lines

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

This implies that we can e.g. build valid ELF file which is also multiboot2 protocol compatible image. And we does. However, we can go further. Potentially we can build valid PE image which is also valid multiboot2 protocol image. Although current build method does not satisfy requirement number 2 because, e.g.:

Sections:
Idx Name Size VMA LMA File off
Algn
0 .text 001513d0 ffff82d080200000 ffff82d080200000 00001000
2**12
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, CODE
1 .rodata 0004de12 ffff82d0803513e0 ffff82d0803513e0 00153000
2**5
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, READONLY, DATA

Quoted 3 lines

Hence, we must use special method to build PE image (I discussed that in my earlier email in that topic) to do it compatible with multiboot2 protocol.

And you realize that we use a "special method" for building the current "flat" ELF image too?

Quoted 5 lines

This way one file could be loaded by native PE loader, mulitboot (v1) protocol
(it requires relevant header but it does not interfere with PE and multiboot2
protocol stuff) and mutliboot2 protocol compatible loaders. Additionally,

Quoted 8 lines

if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying
this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

I think whether what you do now makes sense depends on the ultimate goal: If we want a single binary usable for all three cases, then while yes, having EFI code available in the ELF image makes sense, using an ELF Image won't work. And we can't have an image being both ELF and PE. Hence the goal ought to be to have a single PE image, and with that the direction you move seems wrong.

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
xen/arch/x86/efi/Makefile +0 -2
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-

xen/arch/x86/efi/Makefile line 8

Quoted 10 lines
xen/arch/x86/efi/Makefile +2 -4
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi heck.o >disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Because we need proper EFI code in xen.gz to support boot via multiboot2 on EFI platforms.

What would we need that for when not building an EFI-capable binary anyway?

xen/arch/x86/efi/stub.c

This is still too unspecific: I can't see any reference from that file to any of the symbols relocs-dummy.S provides.

Jan

#81 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 47 lines · Jan Beulich
Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 24.08.15 at 22:54, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 15:59, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

Quoted 7 lines
Quoted 4 lines

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

This implies that we can e.g. build valid ELF file which is also multiboot2 protocol compatible image. And we does. However, we can go further. Potentially we can build valid PE image which is also valid multiboot2 protocol image. Although current build method does not satisfy requirement number 2 because, e.g.:

Sections:
Idx Name Size VMA LMA File off
Algn
0 .text 001513d0 ffff82d080200000 ffff82d080200000 00001000
2**12
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, CODE
1 .rodata 0004de12 ffff82d0803513e0 ffff82d0803513e0 00153000
2**5
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, READONLY, DATA

Quoted 6 lines
Quoted 3 lines

Hence, we must use special method to build PE image (I discussed that in my earlier email in that topic) to do it compatible with multiboot2 protocol.

And you realize that we use a "special method" for building the current "flat" ELF image too?

Yes, I know about that.

Quoted 14 lines
Quoted 5 lines

This way one file could be loaded by native PE loader, mulitboot (v1) protocol
(it requires relevant header but it does not interfere with PE and multiboot2
protocol stuff) and mutliboot2 protocol compatible loaders. Additionally,

Quoted 8 lines

if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying
this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

Quoted 7 lines

I think whether what you do now makes sense depends on the ultimate goal: If we want a single binary usable for all three cases, then while yes, having EFI code available in the ELF image makes sense, using an ELF Image won't work. And we can't have an image being both ELF and PE. Hence the goal ought to be to have a single PE image, and with that the direction you move seems wrong.

It depends how we want to generate proper PE file. There are two options.

We can put manually proper PE header into xen/arch/x86/boot/head.S (maybe with some additional needed stuff). Then after build we will have ELF file which is loadable by multiboot protocols and has extra PE header. Of course it is unusable directly by EFI loader. However, using simple objcopy we can extract all interesting stuff from ELF file. This way we get proper PE file which is usable by three different boot protocols. Going that way we can also remove strict dependency on exact version of binutils which must have enabled i386pep support if we wish to build PE image.

Potentially we can choose second way and build proper PE image using ld and objcopy/objdump tools with proper options. However, this require more work (maybe we will be forced to build something similar to mkelf32) and we bind Xen build machinery more tightly with exact version of binutils which is not nice.

So, I decided to choose option #1. It looks simpler because we have a lot of needed stuff in place (e.g. Xen ELF image is currently in format usable by multiboot protocols). However, I think that in first step we should add EFI code to xen.gz because we want to load Xen using GRUB2 on EFI platforms ASAP. This patch allows us to do that. Later after getting this feature into upstream we can focus on building proper PE image with multiboot protocols support embedded in it.

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 15 lines
Quoted 15 lines
xen/arch/x86/efi/Makefile +1 -5
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi heck.o >disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
Quoted 4 lines

xen/arch/x86/efi/Makefile line 8

Quoted 2 lines
xen/arch/x86/efi/Makefile +1 -1
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

Because we need proper EFI code in xen.gz to support boot via multiboot2 on EFI platforms.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

What would we need that for when not building an EFI-capable binary anyway?

xen/arch/x86/efi/stub.c

This is still too unspecific: I can't see any reference from that file to any of the symbols relocs-dummy.S provides.

Ahh... You are right, we do not need relocs-dummy.S to build Xen image without EFI support. I will fix it.

Daniel

#82 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 49 lines
Quoted 1 line
Quoted 1 line · On 25.08.15 at 18:31, <[email protected]> wrote:
Quoted 47 lines · Jan Beulich
Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 24.08.15 at 22:54, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 15:59, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

Quoted 7 lines
Quoted 4 lines

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

This implies that we can e.g. build valid ELF file which is also multiboot2 protocol compatible image. And we does. However, we can go further. Potentially we can build valid PE image which is also valid multiboot2 protocol image. Although current build method does not satisfy requirement number 2 because, e.g.:

Sections:
Idx Name Size VMA LMA File off
Algn
0 .text 001513d0 ffff82d080200000 ffff82d080200000 00001000
2**12
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, CODE
1 .rodata 0004de12 ffff82d0803513e0 ffff82d0803513e0 00153000
2**5
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, READONLY, DATA

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Hence, we must use special method to build PE image (I discussed that in my earlier email in that topic) to do it compatible with multiboot2 protocol.

And you realize that we use a "special method" for building the current "flat" ELF image too?

Yes, I know about that.

And with that I wonder ...

Quoted 33 lines
Quoted 14 lines
Quoted 5 lines

This way one file could be loaded by native PE loader, mulitboot (v1) protocol
(it requires relevant header but it does not interfere with PE and multiboot2
protocol stuff) and mutliboot2 protocol compatible loaders. Additionally,

Quoted 8 lines

if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying
this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

Quoted 7 lines

I think whether what you do now makes sense depends on the ultimate goal: If we want a single binary usable for all three cases, then while yes, having EFI code available in the ELF image makes sense, using an ELF Image won't work. And we can't have an image being both ELF and PE. Hence the goal ought to be to have a single PE image, and with that the direction you move seems wrong.

It depends how we want to generate proper PE file. There are two options.

We can put manually proper PE header into xen/arch/x86/boot/head.S (maybe with some additional needed stuff). Then after build we will have ELF file which is loadable by multiboot protocols and has extra PE header. Of course it is unusable directly by EFI loader. However, using simple objcopy we can extract all interesting stuff from ELF file. This way we get proper PE file which is usable by three different boot protocols. Going that way we can also remove strict dependency on exact version of binutils which must have enabled i386pep support if we wish to build PE image.

Quoted 7 lines

Potentially we can choose second way and build proper PE image using ld and objcopy/objdump tools with proper options. However, this require more work (maybe we will be forced to build something similar to mkelf32) and we bind Xen build machinery more tightly with exact version of binutils which is not nice.

So, I decided to choose option #1.

... why there's no option #3 here: Build a suitable PE image using a tool similar to mkelf32 _without_ involving ld/objcopy (i.e. straight from the full ELF binary that mkelf32 today uses as its input).

Quoted 9 lines

It looks simpler because we have a lot of
needed stuff in place (e.g. Xen ELF image is currently in format usable by multiboot protocols). However, I think that in first step we should add EFI code to xen.gz because we want to load Xen using GRUB2 on EFI platforms ASAP.
This patch allows us to do that. Later after getting this feature into upstream
we can focus on building proper PE image with multiboot protocols support embedded in it.

But for whatever we do now we should keep in mind what the end goal is, and at least avoid making it more cumbersome to reach that end goal. And in the end I'm not sure not going the full way at once will actually turn out to be the easier route.

Jan

#83 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Daniel Kiper
Quoted 49 lines
Quoted 1 line
Quoted 1 line · On 25.08.15 at 18:31, <[email protected]> wrote:
Quoted 47 lines · Jan Beulich
Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 24.08.15 at 22:54, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 15:59, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

Quoted 7 lines
Quoted 4 lines

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

This implies that we can e.g. build valid ELF file which is also multiboot2 protocol compatible image. And we does. However, we can go further. Potentially we can build valid PE image which is also valid multiboot2 protocol image. Although current build method does not satisfy requirement number 2 because, e.g.:

Sections:
Idx Name Size VMA LMA File off
Algn
0 .text 001513d0 ffff82d080200000 ffff82d080200000 00001000
2**12
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, CODE
1 .rodata 0004de12 ffff82d0803513e0 ffff82d0803513e0 00153000
2**5
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, READONLY, DATA

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Hence, we must use special method to build PE image (I discussed that in my earlier email in that topic) to do it compatible with multiboot2 protocol.

And you realize that we use a "special method" for building the current "flat" ELF image too?

Yes, I know about that.

And with that I wonder ...

Quoted 33 lines
Quoted 14 lines
Quoted 5 lines

This way one file could be loaded by native PE loader, mulitboot (v1) protocol
(it requires relevant header but it does not interfere with PE and multiboot2
protocol stuff) and mutliboot2 protocol compatible loaders. Additionally,

Quoted 8 lines

if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying
this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

Quoted 7 lines

I think whether what you do now makes sense depends on the ultimate goal: If we want a single binary usable for all three cases, then while yes, having EFI code available in the ELF image makes sense, using an ELF Image won't work. And we can't have an image being both ELF and PE. Hence the goal ought to be to have a single PE image, and with that the direction you move seems wrong.

It depends how we want to generate proper PE file. There are two options.

We can put manually proper PE header into xen/arch/x86/boot/head.S (maybe with some additional needed stuff). Then after build we will have ELF file which is loadable by multiboot protocols and has extra PE header. Of course it is unusable directly by EFI loader. However, using simple objcopy we can extract all interesting stuff from ELF file. This way we get proper PE file which is usable by three different boot protocols. Going that way we can also remove strict dependency on exact version of binutils which must have enabled i386pep support if we wish to build PE image.

Quoted 7 lines

Potentially we can choose second way and build proper PE image using ld and objcopy/objdump tools with proper options. However, this require more work (maybe we will be forced to build something similar to mkelf32) and we bind Xen build machinery more tightly with exact version of binutils which is not nice.

So, I decided to choose option #1.

... why there's no option #3 here: Build a suitable PE image using a tool similar to mkelf32 _without_ involving ld/objcopy (i.e. straight from the full ELF binary that mkelf32 today uses as its input).

Quoted 9 lines

It looks simpler because we have a lot of
needed stuff in place (e.g. Xen ELF image is currently in format usable by multiboot protocols). However, I think that in first step we should add EFI code to xen.gz because we want to load Xen using GRUB2 on EFI platforms ASAP.
This patch allows us to do that. Later after getting this feature into upstream
we can focus on building proper PE image with multiboot protocols support embedded in it.

But for whatever we do now we should keep in mind what the end goal is, and at least avoid making it more cumbersome to reach that end goal. And in the end I'm not sure not going the full way at once will actually turn out to be the easier route.

Jan

#84 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 25.08.15 at 18:31, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 24.08.15 at 22:54, <[email protected]> wrote:

[...]

Quoted 46 lines
Quoted 4 lines
Quoted 2 lines

And you realize that we use a "special method" for building the current "flat" ELF image too?

Yes, I know about that.

And with that I wonder ...

Quoted 39 lines
Quoted 14 lines
Quoted 5 lines

This way one file could be loaded by native PE loader, mulitboot (v1) protocol
(it requires relevant header but it does not interfere with PE and multiboot2
protocol stuff) and mutliboot2 protocol compatible loaders. Additionally,

Quoted 8 lines

if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying
this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

Quoted 7 lines

I think whether what you do now makes sense depends on the ultimate goal: If we want a single binary usable for all three cases, then while yes, having EFI code available in the ELF image makes sense, using an ELF Image won't work. And we can't have an image being both ELF and PE. Hence the goal ought to be to have a single PE image, and with that the direction you move seems wrong.

It depends how we want to generate proper PE file. There are two options.

We can put manually proper PE header into xen/arch/x86/boot/head.S (maybe with some additional needed stuff). Then after build we will have ELF file which is loadable by multiboot protocols and has extra PE header. Of course it is unusable directly by EFI loader. However, using simple objcopy we can extract all interesting stuff from ELF file. This way we get proper PE file which is usable by three different boot protocols. Going that way we can also remove strict dependency on exact version of binutils which must have enabled i386pep support if we wish to build PE image.

Potentially we can choose second way and build proper PE image using ld and objcopy/objdump tools with proper options. However, this require more work (maybe we will be forced to build something similar to mkelf32) and we bind Xen build machinery more tightly with exact version of binutils which is not nice.

Quoted 5 lines
Quoted 1 line

So, I decided to choose option #1.

... why there's no option #3 here: Build a suitable PE image using a tool similar to mkelf32 _without_ involving ld/objcopy (i.e. straight from the full ELF binary that mkelf32 today uses as its input).

This is variant of #1 and make sense too. However, this way we do not get extra PE header in ELF file which is also good.

Quoted 10 lines
Quoted 9 lines

It looks simpler because we have a lot of
needed stuff in place (e.g. Xen ELF image is currently in format usable by multiboot protocols). However, I think that in first step we should add EFI code to xen.gz because we want to load Xen using GRUB2 on EFI platforms ASAP.
This patch allows us to do that. Later after getting this feature into upstream
we can focus on building proper PE image with multiboot protocols support embedded in it.

Quoted 3 lines

But for whatever we do now we should keep in mind what the end goal is, and at least avoid making it more cumbersome to reach that end goal. And in the end I'm not sure not going the full way at once

#1 and #3 need EFI code in xen.gz. So, I do not think that we do anything wrong adding this functionality here because we need it for GRUB2 support on EFI platforms too. Hence, both things benefit from that change but one does not depend on another.

Quoted 1 line

will actually turn out to be the easier route.

Do you suggest that I should put this functionality (PE with multiboot headers) on top of this patch series? Well, it is possible but this series is big and I would like to avoid to make it bigger. I prefer to get current patches into Xen tree and then work on new features (it should not take so long because as I can see we almost agreed most of stuff in that case). Or if at least half patches of current series will be accepted (as I can see there is a chance to do that with v3) then I can work on this functionality and put it on top of second not applied part. Does it make sense?

Daniel

#85 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Jan Beulich
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 25.08.15 at 18:31, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 24.08.15 at 22:54, <[email protected]> wrote:

[...]

Quoted 46 lines
Quoted 4 lines
Quoted 2 lines

And you realize that we use a "special method" for building the current "flat" ELF image too?

Yes, I know about that.

And with that I wonder ...

Quoted 39 lines
Quoted 14 lines
Quoted 5 lines

This way one file could be loaded by native PE loader, mulitboot (v1) protocol
(it requires relevant header but it does not interfere with PE and multiboot2
protocol stuff) and mutliboot2 protocol compatible loaders. Additionally,

Quoted 8 lines

if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying
this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

Quoted 7 lines

I think whether what you do now makes sense depends on the ultimate goal: If we want a single binary usable for all three cases, then while yes, having EFI code available in the ELF image makes sense, using an ELF Image won't work. And we can't have an image being both ELF and PE. Hence the goal ought to be to have a single PE image, and with that the direction you move seems wrong.

It depends how we want to generate proper PE file. There are two options.

We can put manually proper PE header into xen/arch/x86/boot/head.S (maybe with some additional needed stuff). Then after build we will have ELF file which is loadable by multiboot protocols and has extra PE header. Of course it is unusable directly by EFI loader. However, using simple objcopy we can extract all interesting stuff from ELF file. This way we get proper PE file which is usable by three different boot protocols. Going that way we can also remove strict dependency on exact version of binutils which must have enabled i386pep support if we wish to build PE image.

Potentially we can choose second way and build proper PE image using ld and objcopy/objdump tools with proper options. However, this require more work (maybe we will be forced to build something similar to mkelf32) and we bind Xen build machinery more tightly with exact version of binutils which is not nice.

Quoted 5 lines
Quoted 1 line

So, I decided to choose option #1.

... why there's no option #3 here: Build a suitable PE image using a tool similar to mkelf32 _without_ involving ld/objcopy (i.e. straight from the full ELF binary that mkelf32 today uses as its input).

This is variant of #1 and make sense too. However, this way we do not get extra PE header in ELF file which is also good.

Quoted 10 lines
Quoted 9 lines

It looks simpler because we have a lot of
needed stuff in place (e.g. Xen ELF image is currently in format usable by multiboot protocols). However, I think that in first step we should add EFI code to xen.gz because we want to load Xen using GRUB2 on EFI platforms ASAP.
This patch allows us to do that. Later after getting this feature into upstream
we can focus on building proper PE image with multiboot protocols support embedded in it.

Quoted 3 lines

But for whatever we do now we should keep in mind what the end goal is, and at least avoid making it more cumbersome to reach that end goal. And in the end I'm not sure not going the full way at once

#1 and #3 need EFI code in xen.gz. So, I do not think that we do anything wrong adding this functionality here because we need it for GRUB2 support on EFI platforms too. Hence, both things benefit from that change but one does not depend on another.

Quoted 1 line

will actually turn out to be the easier route.

Do you suggest that I should put this functionality (PE with multiboot headers) on top of this patch series? Well, it is possible but this series is big and I would like to avoid to make it bigger. I prefer to get current patches into Xen tree and then work on new features (it should not take so long because as I can see we almost agreed most of stuff in that case). Or if at least half patches of current series will be accepted (as I can see there is a chance to do that with v3) then I can work on this functionality and put it on top of second not applied part. Does it make sense?

Daniel

#86 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.08.15 at 14:33, <[email protected]> wrote:

Do you suggest that I should put this functionality (PE with multiboot headers) on top of this patch series? Well, it is possible but this series is big and I would like to avoid to make it bigger. I prefer to get current patches into Xen tree and then work on new features (it should not take so long because as I can see we almost agreed most of stuff in that case). Or if at least half patches of current series will be accepted (as I can see there is a chance to do that with v3) then I can work on this functionality and put it on top of second not applied part. Does it make sense?

Yes. I'm not objecting to deferring that part. All I want is you to make sure not to submit any changes potentially conflicting with the end goal of having a single binary (which as I understand it can only be a PE one).

Jan

#87 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Daniel Kiper
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.08.15 at 14:33, <[email protected]> wrote:

Do you suggest that I should put this functionality (PE with multiboot headers) on top of this patch series? Well, it is possible but this series is big and I would like to avoid to make it bigger. I prefer to get current patches into Xen tree and then work on new features (it should not take so long because as I can see we almost agreed most of stuff in that case). Or if at least half patches of current series will be accepted (as I can see there is a chance to do that with v3) then I can work on this functionality and put it on top of second not applied part. Does it make sense?

Yes. I'm not objecting to deferring that part. All I want is you to make sure not to submit any changes potentially conflicting with the end goal of having a single binary (which as I understand it can only be a PE one).

Jan

#88 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

Quoted 11 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.08.15 at 14:33, <[email protected]> wrote:

Do you suggest that I should put this functionality (PE with multiboot headers) on top of this patch series? Well, it is possible but this series is big and I would like to avoid to make it bigger. I prefer to get current patches into Xen tree and then work on new features (it should not take so long because as I can see we almost agreed most of stuff in that case). Or if at least half patches of current series will be accepted (as I can see there is a chance to do that with v3) then I can work on this functionality and put it on top of second not applied part. Does it make sense?

Quoted 1 line

Yes. I'm not objecting to deferring that part. All I want is you to make

Great!

Quoted 1 line

sure not to submit any changes potentially conflicting with the end

OK.

Quoted 2 lines

goal of having a single binary (which as I understand it can only be a PE one).

This is the end goal but I think that we should have transitional phase when both formats (ELF and PE) are avaibale for users. Just in case.

Daniel

#89 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Jan Beulich
Quoted 11 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 26.08.15 at 14:33, <[email protected]> wrote:

Do you suggest that I should put this functionality (PE with multiboot headers) on top of this patch series? Well, it is possible but this series is big and I would like to avoid to make it bigger. I prefer to get current patches into Xen tree and then work on new features (it should not take so long because as I can see we almost agreed most of stuff in that case). Or if at least half patches of current series will be accepted (as I can see there is a chance to do that with v3) then I can work on this functionality and put it on top of second not applied part. Does it make sense?

Quoted 1 line

Yes. I'm not objecting to deferring that part. All I want is you to make

Great!

Quoted 1 line

sure not to submit any changes potentially conflicting with the end

OK.

Quoted 2 lines

goal of having a single binary (which as I understand it can only be a PE one).

This is the end goal but I think that we should have transitional phase when both formats (ELF and PE) are avaibale for users. Just in case.

Daniel

#90 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Jan Beulich
Quoted 47 lines · Jan Beulich
Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 24.08.15 at 22:54, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 15:59, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

Quoted 7 lines
Quoted 4 lines

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

This implies that we can e.g. build valid ELF file which is also multiboot2 protocol compatible image. And we does. However, we can go further. Potentially we can build valid PE image which is also valid multiboot2 protocol image. Although current build method does not satisfy requirement number 2 because, e.g.:

Sections:
Idx Name Size VMA LMA File off
Algn
0 .text 001513d0 ffff82d080200000 ffff82d080200000 00001000
2**12
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, CODE
1 .rodata 0004de12 ffff82d0803513e0 ffff82d0803513e0 00153000
2**5
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, READONLY, DATA

Quoted 6 lines
Quoted 3 lines

Hence, we must use special method to build PE image (I discussed that in my earlier email in that topic) to do it compatible with multiboot2 protocol.

And you realize that we use a "special method" for building the current "flat" ELF image too?

Yes, I know about that.

Quoted 14 lines
Quoted 5 lines

This way one file could be loaded by native PE loader, mulitboot (v1) protocol
(it requires relevant header but it does not interfere with PE and multiboot2
protocol stuff) and mutliboot2 protocol compatible loaders. Additionally,

Quoted 8 lines

if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying
this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

Quoted 7 lines

I think whether what you do now makes sense depends on the ultimate goal: If we want a single binary usable for all three cases, then while yes, having EFI code available in the ELF image makes sense, using an ELF Image won't work. And we can't have an image being both ELF and PE. Hence the goal ought to be to have a single PE image, and with that the direction you move seems wrong.

It depends how we want to generate proper PE file. There are two options.

We can put manually proper PE header into xen/arch/x86/boot/head.S (maybe with some additional needed stuff). Then after build we will have ELF file which is loadable by multiboot protocols and has extra PE header. Of course it is unusable directly by EFI loader. However, using simple objcopy we can extract all interesting stuff from ELF file. This way we get proper PE file which is usable by three different boot protocols. Going that way we can also remove strict dependency on exact version of binutils which must have enabled i386pep support if we wish to build PE image.

Potentially we can choose second way and build proper PE image using ld and objcopy/objdump tools with proper options. However, this require more work (maybe we will be forced to build something similar to mkelf32) and we bind Xen build machinery more tightly with exact version of binutils which is not nice.

So, I decided to choose option #1. It looks simpler because we have a lot of needed stuff in place (e.g. Xen ELF image is currently in format usable by multiboot protocols). However, I think that in first step we should add EFI code to xen.gz because we want to load Xen using GRUB2 on EFI platforms ASAP. This patch allows us to do that. Later after getting this feature into upstream we can focus on building proper PE image with multiboot protocols support embedded in it.

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 15 lines
Quoted 15 lines
xen/arch/x86/efi/Makefile +1 -5
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi heck.o >disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
Quoted 4 lines

xen/arch/x86/efi/Makefile line 8

Quoted 2 lines
xen/arch/x86/efi/Makefile +1 -1
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

Because we need proper EFI code in xen.gz to support boot via multiboot2 on EFI platforms.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

What would we need that for when not building an EFI-capable binary anyway?

xen/arch/x86/efi/stub.c

This is still too unspecific: I can't see any reference from that file to any of the symbols relocs-dummy.S provides.

Ahh... You are right, we do not need relocs-dummy.S to build Xen image without EFI support. I will fix it.

Daniel

#91 lore raw

Re: [PATCH v2 10/23] efi: build xen.gz with EFI code

In reply to Jan Beulich
Quoted 31 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 22.08.15 at 15:59, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms.

If we wish to load not ELF file using multiboot (v1) or multiboot2 then

DYM "a non-ELF file"?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

it must contain "linear" (or "flat") representation of code and data.

Why? Please don't just put out statements, but also reasons (i.e. at least which component is unable to deal with the current [valid afaict] PE image we have).

This is a requirement of multiboot (v1) or multiboot2 protocol. They both know nothing about PE image format.

And hence how specifically we arrange data inside the image should be benign to them, as they won't be able to load the file _anyway_.

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). In theory there is a chance that we could build proper PE file using current build system. However, it means that

What is "improper" about the currently built PE file? And if there is anything improper, did you inform the binutils maintainers of the problem?

Quoted 7 lines
Quoted 4 lines

From PE loader point of view everything is OK. However, current Xen PE image (at least build on my machines) is not usable by multiboot (v1) or multiboot2 protocol compatible loader because it is not linear (one section does not live immediately after another without any voids).

Again - either I'm missing something (and then your explanation is not good enough) or this is (as said above) a pointless adjustment.

Let's focus on multiboot2 protocol (multiboot (v1) is similar to multiboot2 in discussed case). In general multiboot2 is able to load any file which has:
1. proper multiboot2 header in first 32 KiB of a given file,
2. "the text and data segments must be consecutive in the OS image" (The Multiboot Specification version 1.6).

This implies that we can e.g. build valid ELF file which is also multiboot2 protocol compatible image. And we does. However, we can go further. Potentially we can build valid PE image which is also valid multiboot2 protocol image. Although current build method does not satisfy requirement number 2 because, e.g.:

Sections:

Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         001513d0  ffff82d080200000  ffff82d080200000  00001000  2**12
                                      ^^^^^^                    ^^^^^^^^

CONTENTS, ALLOC, LOAD, CODE
1 .rodata 0004de12 ffff82d0803513e0 ffff82d0803513e0 00153000 2**5
^^^^^^ ^^^^^^^^
CONTENTS, ALLOC, LOAD, READONLY, DATA

Hence, we must use special method to build PE image (I discussed that in my earlier email in that topic) to do it compatible with multiboot2 protocol. This way one file could be loaded by native PE loader, mulitboot (v1) protocol (it requires relevant header but it does not interfere with PE and multiboot2 protocol stuff) and mutliboot2 protocol compatible loaders. Additionally, if it is signed with Secure Boot signature then potentially signature could be verified by UEFI itself and e.g. GRUB2. However, as I said earlier this requires more work and this is next step which I am going to do after applying this series. Currently I am going to embed EFI support into ELF file because it is easy (less changes; currently used ELF file has required properties because multiboot (v1) which we use has similar requirements like multiboot2 protocol) to make it compatible with multiboot2 protocol.

I hope that helps.

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
xen/arch/x86/efi/Makefile +0 -2
@@ -1,14 +1,16 @@
 CFLAGS += -fshort-wchar
 
-obj-y += stub.o
-

xen/arch/x86/efi/Makefile line 8

Quoted 10 lines
xen/arch/x86/efi/Makefile +2 -4
-create = test -e $(1) || touch -t 199901010000 $(1)
-
 efi := $(filter y,$(x86_64)$(shell rm -f disabled))
 efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
 efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o >disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
+efi := $(if $(efi),$(shell rm disabled)y)
 
-extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
+extra-y += relocs-dummy.o

Why is this no longer extra-$(efi)?

Quoted 5 lines
Quoted 2 lines

Because we need proper EFI code in xen.gz to support boot via multiboot2 on EFI platforms.

What would we need that for when not building an EFI-capable binary anyway?

xen/arch/x86/efi/stub.c

Daniel

#92 lore raw

PATCH v2 11/23 efi: split out efi_init()

In reply to Daniel Kiper

..which initializes basic EFI variables. We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
xen/common/efi/boot.c +17 -11
index 1f188fe..6f327cd 100644
@@ -595,6 +595,22 @@ static char *__init get_value(const struct file *cfg, const char *section,
     return NULL;
 }
 
+static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    efi_ih = ImageHandle;
+    efi_bs = SystemTable->BootServices;
+    efi_bs_revision = efi_bs->Hdr.Revision;
+    efi_rs = SystemTable->RuntimeServices;
+    efi_ct = SystemTable->ConfigurationTable;
+    efi_num_ct = SystemTable->NumberOfTableEntries;
+    efi_version = SystemTable->Hdr.Revision;
+    efi_fw_vendor = SystemTable->FirmwareVendor;
+    efi_fw_revision = SystemTable->FirmwareRevision;
+
+    StdOut = SystemTable->ConOut;
+    StdErr = SystemTable->StdErr ?: StdOut;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -721,18 +737,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     set_bit(EFI_PLATFORM, &efi.flags);
 #endif
 
-    efi_ih = ImageHandle;
-    efi_bs = SystemTable->BootServices;
-    efi_bs_revision = efi_bs->Hdr.Revision;
-    efi_rs = SystemTable->RuntimeServices;
-    efi_ct = SystemTable->ConfigurationTable;
-    efi_num_ct = SystemTable->NumberOfTableEntries;
-    efi_version = SystemTable->Hdr.Revision;
-    efi_fw_vendor = SystemTable->FirmwareVendor;
-    efi_fw_revision = SystemTable->FirmwareRevision;
+    efi_init(ImageHandle, SystemTable);
 
-    StdOut = SystemTable->ConOut;
-    StdErr = SystemTable->StdErr ?: StdOut;
     use_cfg_file = efi_arch_use_config_file(SystemTable);
 
     status = efi_bs->HandleProtocol(ImageHandle, &loaded_image_guid,
Signature · 1 line
1.7.10.4
Reviewed-by on v2 11/23
#93 lore raw

Re: [Xen-devel] [PATCH v2 11/23] efi: split out efi_init()

Quoted 4 lines · Daniel Kiper

..which initializes basic EFI variables. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 63 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
xen/common/efi/boot.c +17 -11
index 1f188fe..6f327cd 100644
@@ -595,6 +595,22 @@ static char *__init get_value(const struct file *cfg, const char *section,
     return NULL;
 }
 
+static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    efi_ih = ImageHandle;
+    efi_bs = SystemTable->BootServices;
+    efi_bs_revision = efi_bs->Hdr.Revision;
+    efi_rs = SystemTable->RuntimeServices;
+    efi_ct = SystemTable->ConfigurationTable;
+    efi_num_ct = SystemTable->NumberOfTableEntries;
+    efi_version = SystemTable->Hdr.Revision;
+    efi_fw_vendor = SystemTable->FirmwareVendor;
+    efi_fw_revision = SystemTable->FirmwareRevision;
+
+    StdOut = SystemTable->ConOut;
+    StdErr = SystemTable->StdErr ?: StdOut;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -721,18 +737,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     set_bit(EFI_PLATFORM, &efi.flags);
 #endif
 
-    efi_ih = ImageHandle;
-    efi_bs = SystemTable->BootServices;
-    efi_bs_revision = efi_bs->Hdr.Revision;
-    efi_rs = SystemTable->RuntimeServices;
-    efi_ct = SystemTable->ConfigurationTable;
-    efi_num_ct = SystemTable->NumberOfTableEntries;
-    efi_version = SystemTable->Hdr.Revision;
-    efi_fw_vendor = SystemTable->FirmwareVendor;
-    efi_fw_revision = SystemTable->FirmwareRevision;
+    efi_init(ImageHandle, SystemTable);
 
-    StdOut = SystemTable->ConOut;
-    StdErr = SystemTable->StdErr ?: StdOut;
     use_cfg_file = efi_arch_use_config_file(SystemTable);
 
     status = efi_bs->HandleProtocol(ImageHandle, &loaded_image_guid,
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 11/23
#94 lore raw

Re: [PATCH v2 11/23] efi: split out efi_init()

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

..which initializes basic EFI variables. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 63 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
xen/common/efi/boot.c +17 -11
index 1f188fe..6f327cd 100644
@@ -595,6 +595,22 @@ static char *__init get_value(const struct file *cfg, const char *section,
     return NULL;
 }
 
+static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    efi_ih = ImageHandle;
+    efi_bs = SystemTable->BootServices;
+    efi_bs_revision = efi_bs->Hdr.Revision;
+    efi_rs = SystemTable->RuntimeServices;
+    efi_ct = SystemTable->ConfigurationTable;
+    efi_num_ct = SystemTable->NumberOfTableEntries;
+    efi_version = SystemTable->Hdr.Revision;
+    efi_fw_vendor = SystemTable->FirmwareVendor;
+    efi_fw_revision = SystemTable->FirmwareRevision;
+
+    StdOut = SystemTable->ConOut;
+    StdErr = SystemTable->StdErr ?: StdOut;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -721,18 +737,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     set_bit(EFI_PLATFORM, &efi.flags);
 #endif
 
-    efi_ih = ImageHandle;
-    efi_bs = SystemTable->BootServices;
-    efi_bs_revision = efi_bs->Hdr.Revision;
-    efi_rs = SystemTable->RuntimeServices;
-    efi_ct = SystemTable->ConfigurationTable;
-    efi_num_ct = SystemTable->NumberOfTableEntries;
-    efi_version = SystemTable->Hdr.Revision;
-    efi_fw_vendor = SystemTable->FirmwareVendor;
-    efi_fw_revision = SystemTable->FirmwareRevision;
+    efi_init(ImageHandle, SystemTable);
 
-    StdOut = SystemTable->ConOut;
-    StdErr = SystemTable->StdErr ?: StdOut;
     use_cfg_file = efi_arch_use_config_file(SystemTable);
 
     status = efi_bs->HandleProtocol(ImageHandle, &loaded_image_guid,
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#95 lore raw

PATCH v2 12/23 efi: split out efi_console_set_mode()

In reply to Daniel Kiper

..which sets console mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)
xen/common/efi/boot.c +20 -17
index 6f327cd..4614146 100644
@@ -611,6 +611,25 @@ static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTabl
     StdErr = SystemTable->StdErr ?: StdOut;
 }
 
+static void __init efi_console_set_mode(void)
+{
+    UINTN cols, rows, size;
+    unsigned int best, i;
+
+    for ( i = 0, size = 0, best = StdOut->Mode->Mode;
+          i < StdOut->Mode->MaxMode; ++i )
+    {
+        if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
+             cols * rows > size )
+        {
+            size = cols * rows;
+            best = i;
+        }
+    }
+    if ( best != StdOut->Mode->Mode )
+        StdOut->SetMode(StdOut, best);
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -799,23 +818,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         }
 
         if ( !base_video )
-        {
-            unsigned int best;
-            UINTN cols, rows, size;
-
-            for ( i = 0, size = 0, best = StdOut->Mode->Mode;
-                  i < StdOut->Mode->MaxMode; ++i )
-            {
-                if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
-                     cols * rows > size )
-                {
-                    size = cols * rows;
-                    best = i;
-                }
-            }
-            if ( best != StdOut->Mode->Mode )
-                StdOut->SetMode(StdOut, best);
-        }
+            efi_console_set_mode();
     }
 
     PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSION)
Signature · 1 line
1.7.10.4
#96 lore raw

PATCH v2 12/23 efi: split out efi_console_set_mode()

In reply to Daniel Kiper

..which sets console mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)
xen/common/efi/boot.c +20 -17
index 6f327cd..4614146 100644
@@ -611,6 +611,25 @@ static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTabl
     StdErr = SystemTable->StdErr ?: StdOut;
 }
 
+static void __init efi_console_set_mode(void)
+{
+    UINTN cols, rows, size;
+    unsigned int best, i;
+
+    for ( i = 0, size = 0, best = StdOut->Mode->Mode;
+          i < StdOut->Mode->MaxMode; ++i )
+    {
+        if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
+             cols * rows > size )
+        {
+            size = cols * rows;
+            best = i;
+        }
+    }
+    if ( best != StdOut->Mode->Mode )
+        StdOut->SetMode(StdOut, best);
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -799,23 +818,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         }
 
         if ( !base_video )
-        {
-            unsigned int best;
-            UINTN cols, rows, size;
-
-            for ( i = 0, size = 0, best = StdOut->Mode->Mode;
-                  i < StdOut->Mode->MaxMode; ++i )
-            {
-                if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
-                     cols * rows > size )
-                {
-                    size = cols * rows;
-                    best = i;
-                }
-            }
-            if ( best != StdOut->Mode->Mode )
-                StdOut->SetMode(StdOut, best);
-        }
+            efi_console_set_mode();
     }
 
     PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSION)
Signature · 1 line
1.7.10.4
Reviewed-by on v2 12/23
#97 lore raw

Re: [PATCH v2 12/23] efi: split out efi_console_set_mode()

Quoted 4 lines · Daniel Kiper

..which sets console mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 71 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)
xen/common/efi/boot.c +20 -17
index 6f327cd..4614146 100644
@@ -611,6 +611,25 @@ static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTabl
     StdErr = SystemTable->StdErr ?: StdOut;
 }
 
+static void __init efi_console_set_mode(void)
+{
+    UINTN cols, rows, size;
+    unsigned int best, i;
+
+    for ( i = 0, size = 0, best = StdOut->Mode->Mode;
+          i < StdOut->Mode->MaxMode; ++i )
+    {
+        if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
+             cols * rows > size )
+        {
+            size = cols * rows;
+            best = i;
+        }
+    }
+    if ( best != StdOut->Mode->Mode )
+        StdOut->SetMode(StdOut, best);
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -799,23 +818,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         }
 
         if ( !base_video )
-        {
-            unsigned int best;
-            UINTN cols, rows, size;
-
-            for ( i = 0, size = 0, best = StdOut->Mode->Mode;
-                  i < StdOut->Mode->MaxMode; ++i )
-            {
-                if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
-                     cols * rows > size )
-                {
-                    size = cols * rows;
-                    best = i;
-                }
-            }
-            if ( best != StdOut->Mode->Mode )
-                StdOut->SetMode(StdOut, best);
-        }
+            efi_console_set_mode();
     }
 
     PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSION)
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 12/23
#98 lore raw

Re: [Xen-devel] [PATCH v2 12/23] efi: split out efi_console_set_mode()

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

..which sets console mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 71 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)
xen/common/efi/boot.c +20 -17
index 6f327cd..4614146 100644
@@ -611,6 +611,25 @@ static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTabl
     StdErr = SystemTable->StdErr ?: StdOut;
 }
 
+static void __init efi_console_set_mode(void)
+{
+    UINTN cols, rows, size;
+    unsigned int best, i;
+
+    for ( i = 0, size = 0, best = StdOut->Mode->Mode;
+          i < StdOut->Mode->MaxMode; ++i )
+    {
+        if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
+             cols * rows > size )
+        {
+            size = cols * rows;
+            best = i;
+        }
+    }
+    if ( best != StdOut->Mode->Mode )
+        StdOut->SetMode(StdOut, best);
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -799,23 +818,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         }
 
         if ( !base_video )
-        {
-            unsigned int best;
-            UINTN cols, rows, size;
-
-            for ( i = 0, size = 0, best = StdOut->Mode->Mode;
-                  i < StdOut->Mode->MaxMode; ++i )
-            {
-                if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
-                     cols * rows > size )
-                {
-                    size = cols * rows;
-                    best = i;
-                }
-            }
-            if ( best != StdOut->Mode->Mode )
-                StdOut->SetMode(StdOut, best);
-        }
+            efi_console_set_mode();
     }
 
     PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSION)
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#99 lore raw

PATCH v2 13/23 efi: split out efi_get_gop()

In reply to Daniel Kiper

..which gets pointer to GOP device. We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   59 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 23 deletions(-)
xen/common/efi/boot.c +36 -23
index 4614146..6fad230 100644
@@ -630,6 +630,41 @@ static void __init efi_console_set_mode(void)
         StdOut->SetMode(StdOut, best);
 }
 
+static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    EFI_HANDLE *handles;
+    EFI_STATUS status;
+    UINTN info_size, size = 0;
+    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
+    unsigned int i;
+
+    status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
+    if ( status == EFI_BUFFER_TOO_SMALL )
+        status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
+    if ( !EFI_ERROR(status) )
+        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
+                                      handles);
+    if ( EFI_ERROR(status) )
+        size = 0;
+    for ( i = 0; i < size / sizeof(*handles); ++i )
+    {
+        status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
+        if ( EFI_ERROR(status) )
+            continue;
+        status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
+        if ( !EFI_ERROR(status) )
+            break;
+    }
+    if ( handles )
+        efi_bs->FreePool(handles);
+    if ( EFI_ERROR(status) )
+        gop = NULL;
+
+    return gop;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -736,14 +771,12 @@ void EFIAPI __init noreturn
 efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 {
     static EFI_GUID __initdata loaded_image_guid = LOADED_IMAGE_PROTOCOL;
-    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
     static EFI_GUID __initdata shim_lock_guid = SHIM_LOCK_PROTOCOL_GUID;
     EFI_LOADED_IMAGE *loaded_image;
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
     UINTN map_key, info_size, gop_mode = ~0;
-    EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
@@ -837,27 +870,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
                                &cols, &rows) == EFI_SUCCESS )
             efi_arch_console_init(cols, rows);
 
-        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
-        if ( status == EFI_BUFFER_TOO_SMALL )
-            status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
-        if ( !EFI_ERROR(status) )
-            status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
-                                          handles);
-        if ( EFI_ERROR(status) )
-            size = 0;
-        for ( i = 0; i < size / sizeof(*handles); ++i )
-        {
-            status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
-            if ( EFI_ERROR(status) )
-                continue;
-            status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
-            if ( !EFI_ERROR(status) )
-                break;
-        }
-        if ( handles )
-            efi_bs->FreePool(handles);
-        if ( EFI_ERROR(status) )
-            gop = NULL;
+        gop = efi_get_gop();
 
         /* Get the file system interface. */
         dir_handle = get_parent_handle(loaded_image, &file_name);
Signature · 1 line
1.7.10.4
#100 lore raw

PATCH v2 13/23 efi: split out efi_get_gop()

In reply to Daniel Kiper

..which gets pointer to GOP device. We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   59 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 23 deletions(-)
xen/common/efi/boot.c +36 -23
index 4614146..6fad230 100644
@@ -630,6 +630,41 @@ static void __init efi_console_set_mode(void)
         StdOut->SetMode(StdOut, best);
 }
 
+static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    EFI_HANDLE *handles;
+    EFI_STATUS status;
+    UINTN info_size, size = 0;
+    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
+    unsigned int i;
+
+    status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
+    if ( status == EFI_BUFFER_TOO_SMALL )
+        status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
+    if ( !EFI_ERROR(status) )
+        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
+                                      handles);
+    if ( EFI_ERROR(status) )
+        size = 0;
+    for ( i = 0; i < size / sizeof(*handles); ++i )
+    {
+        status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
+        if ( EFI_ERROR(status) )
+            continue;
+        status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
+        if ( !EFI_ERROR(status) )
+            break;
+    }
+    if ( handles )
+        efi_bs->FreePool(handles);
+    if ( EFI_ERROR(status) )
+        gop = NULL;
+
+    return gop;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -736,14 +771,12 @@ void EFIAPI __init noreturn
 efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 {
     static EFI_GUID __initdata loaded_image_guid = LOADED_IMAGE_PROTOCOL;
-    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
     static EFI_GUID __initdata shim_lock_guid = SHIM_LOCK_PROTOCOL_GUID;
     EFI_LOADED_IMAGE *loaded_image;
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
     UINTN map_key, info_size, gop_mode = ~0;
-    EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
@@ -837,27 +870,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
                                &cols, &rows) == EFI_SUCCESS )
             efi_arch_console_init(cols, rows);
 
-        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
-        if ( status == EFI_BUFFER_TOO_SMALL )
-            status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
-        if ( !EFI_ERROR(status) )
-            status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
-                                          handles);
-        if ( EFI_ERROR(status) )
-            size = 0;
-        for ( i = 0; i < size / sizeof(*handles); ++i )
-        {
-            status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
-            if ( EFI_ERROR(status) )
-                continue;
-            status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
-            if ( !EFI_ERROR(status) )
-                break;
-        }
-        if ( handles )
-            efi_bs->FreePool(handles);
-        if ( EFI_ERROR(status) )
-            gop = NULL;
+        gop = efi_get_gop();
 
         /* Get the file system interface. */
         dir_handle = get_parent_handle(loaded_image, &file_name);
Signature · 1 line
1.7.10.4
Reviewed-by on v2 13/23
#101 lore raw

Re: [Xen-devel] [PATCH v2 13/23] efi: split out efi_get_gop()

Quoted 4 lines · Daniel Kiper

..which gets pointer to GOP device. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 106 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   59 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 23 deletions(-)
xen/common/efi/boot.c +36 -23
index 4614146..6fad230 100644
@@ -630,6 +630,41 @@ static void __init efi_console_set_mode(void)
         StdOut->SetMode(StdOut, best);
 }
 
+static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    EFI_HANDLE *handles;
+    EFI_STATUS status;
+    UINTN info_size, size = 0;
+    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
+    unsigned int i;
+
+    status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
+    if ( status == EFI_BUFFER_TOO_SMALL )
+        status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
+    if ( !EFI_ERROR(status) )
+        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
+                                      handles);
+    if ( EFI_ERROR(status) )
+        size = 0;
+    for ( i = 0; i < size / sizeof(*handles); ++i )
+    {
+        status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
+        if ( EFI_ERROR(status) )
+            continue;
+        status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
+        if ( !EFI_ERROR(status) )
+            break;
+    }
+    if ( handles )
+        efi_bs->FreePool(handles);
+    if ( EFI_ERROR(status) )
+        gop = NULL;
+
+    return gop;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -736,14 +771,12 @@ void EFIAPI __init noreturn
 efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 {
     static EFI_GUID __initdata loaded_image_guid = LOADED_IMAGE_PROTOCOL;
-    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
     static EFI_GUID __initdata shim_lock_guid = SHIM_LOCK_PROTOCOL_GUID;
     EFI_LOADED_IMAGE *loaded_image;
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
     UINTN map_key, info_size, gop_mode = ~0;
-    EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
@@ -837,27 +870,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
                                &cols, &rows) == EFI_SUCCESS )
             efi_arch_console_init(cols, rows);
 
-        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
-        if ( status == EFI_BUFFER_TOO_SMALL )
-            status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
-        if ( !EFI_ERROR(status) )
-            status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
-                                          handles);
-        if ( EFI_ERROR(status) )
-            size = 0;
-        for ( i = 0; i < size / sizeof(*handles); ++i )
-        {
-            status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
-            if ( EFI_ERROR(status) )
-                continue;
-            status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
-            if ( !EFI_ERROR(status) )
-                break;
-        }
-        if ( handles )
-            efi_bs->FreePool(handles);
-        if ( EFI_ERROR(status) )
-            gop = NULL;
+        gop = efi_get_gop();
 
         /* Get the file system interface. */
         dir_handle = get_parent_handle(loaded_image, &file_name);
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 13/23
#102 lore raw

Re: [PATCH v2 13/23] efi: split out efi_get_gop()

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

..which gets pointer to GOP device. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 106 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   59 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 23 deletions(-)
xen/common/efi/boot.c +36 -23
index 4614146..6fad230 100644
@@ -630,6 +630,41 @@ static void __init efi_console_set_mode(void)
         StdOut->SetMode(StdOut, best);
 }
 
+static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    EFI_HANDLE *handles;
+    EFI_STATUS status;
+    UINTN info_size, size = 0;
+    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
+    unsigned int i;
+
+    status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
+    if ( status == EFI_BUFFER_TOO_SMALL )
+        status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
+    if ( !EFI_ERROR(status) )
+        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
+                                      handles);
+    if ( EFI_ERROR(status) )
+        size = 0;
+    for ( i = 0; i < size / sizeof(*handles); ++i )
+    {
+        status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
+        if ( EFI_ERROR(status) )
+            continue;
+        status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
+        if ( !EFI_ERROR(status) )
+            break;
+    }
+    if ( handles )
+        efi_bs->FreePool(handles);
+    if ( EFI_ERROR(status) )
+        gop = NULL;
+
+    return gop;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -736,14 +771,12 @@ void EFIAPI __init noreturn
 efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 {
     static EFI_GUID __initdata loaded_image_guid = LOADED_IMAGE_PROTOCOL;
-    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
     static EFI_GUID __initdata shim_lock_guid = SHIM_LOCK_PROTOCOL_GUID;
     EFI_LOADED_IMAGE *loaded_image;
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
     UINTN map_key, info_size, gop_mode = ~0;
-    EFI_HANDLE *handles = NULL;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
@@ -837,27 +870,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
                                &cols, &rows) == EFI_SUCCESS )
             efi_arch_console_init(cols, rows);
 
-        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
-        if ( status == EFI_BUFFER_TOO_SMALL )
-            status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
-        if ( !EFI_ERROR(status) )
-            status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
-                                          handles);
-        if ( EFI_ERROR(status) )
-            size = 0;
-        for ( i = 0; i < size / sizeof(*handles); ++i )
-        {
-            status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
-            if ( EFI_ERROR(status) )
-                continue;
-            status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
-            if ( !EFI_ERROR(status) )
-                break;
-        }
-        if ( handles )
-            efi_bs->FreePool(handles);
-        if ( EFI_ERROR(status) )
-            gop = NULL;
+        gop = efi_get_gop();
 
         /* Get the file system interface. */
         dir_handle = get_parent_handle(loaded_image, &file_name);
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#103 lore raw

PATCH v2 14/23 efi: split out efi_find_gop_mode()

In reply to Daniel Kiper

..which finds suitable GOP mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   94 ++++++++++++++++++++++++++++---------------------
 1 file changed, 54 insertions(+), 40 deletions(-)
xen/common/efi/boot.c +54 -40
index 6fad230..8d16470 100644
@@ -665,6 +665,58 @@ static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
     return gop;
 }
 
+static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
+                                      UINTN cols, UINTN rows, UINTN depth)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_STATUS status;
+    UINTN gop_mode = ~0, info_size, size;
+    unsigned int i;
+
+    if ( !gop )
+        return gop_mode;
+
+    for ( i = size = 0; i < gop->Mode->MaxMode; ++i )
+    {
+        unsigned int bpp = 0;
+
+        status = gop->QueryMode(gop, i, &info_size, &mode_info);
+        if ( EFI_ERROR(status) )
+            continue;
+        switch ( mode_info->PixelFormat )
+        {
+        case PixelBitMask:
+            bpp = hweight32(mode_info->PixelInformation.RedMask |
+                            mode_info->PixelInformation.GreenMask |
+                            mode_info->PixelInformation.BlueMask);
+            break;
+        case PixelRedGreenBlueReserved8BitPerColor:
+        case PixelBlueGreenRedReserved8BitPerColor:
+            bpp = 24;
+            break;
+        default:
+            continue;
+        }
+        if ( cols == mode_info->HorizontalResolution &&
+             rows == mode_info->VerticalResolution &&
+             (!depth || bpp == depth) )
+        {
+            gop_mode = i;
+            break;
+        }
+        if ( !cols && !rows &&
+             mode_info->HorizontalResolution *
+             mode_info->VerticalResolution > size )
+        {
+            size = mode_info->HorizontalResolution *
+                   mode_info->VerticalResolution;
+            gop_mode = i;
+        }
+    }
+
+    return gop_mode;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -978,46 +1030,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
         dir_handle->Close(dir_handle);
 
-        if ( gop && !base_video )
-        {
-            for ( i = size = 0; i < gop->Mode->MaxMode; ++i )
-            {
-                unsigned int bpp = 0;
-
-                status = gop->QueryMode(gop, i, &info_size, &mode_info);
-                if ( EFI_ERROR(status) )
-                    continue;
-                switch ( mode_info->PixelFormat )
-                {
-                case PixelBitMask:
-                    bpp = hweight32(mode_info->PixelInformation.RedMask |
-                                    mode_info->PixelInformation.GreenMask |
-                                    mode_info->PixelInformation.BlueMask);
-                    break;
-                case PixelRedGreenBlueReserved8BitPerColor:
-                case PixelBlueGreenRedReserved8BitPerColor:
-                    bpp = 24;
-                    break;
-                default:
-                    continue;
-                }
-                if ( cols == mode_info->HorizontalResolution &&
-                     rows == mode_info->VerticalResolution &&
-                     (!depth || bpp == depth) )
-                {
-                    gop_mode = i;
-                    break;
-                }
-                if ( !cols && !rows &&
-                     mode_info->HorizontalResolution *
-                     mode_info->VerticalResolution > size )
-                {
-                    size = mode_info->HorizontalResolution *
-                           mode_info->VerticalResolution;
-                    gop_mode = i;
-                }
-            }
-        }
+        if ( !base_video )
+            gop_mode = efi_find_gop_mode(gop, cols, rows, depth);
     }
 
     efi_arch_edd();
Signature · 1 line
1.7.10.4
Reviewed-by on v2 14/23
#104 lore raw

Re: [Xen-devel] [PATCH v2 14/23] efi: split out efi_find_gop_mode()

Quoted 4 lines · Daniel Kiper

..which finds suitable GOP mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 128 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   94 ++++++++++++++++++++++++++++---------------------
 1 file changed, 54 insertions(+), 40 deletions(-)
xen/common/efi/boot.c +54 -40
index 6fad230..8d16470 100644
@@ -665,6 +665,58 @@ static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
     return gop;
 }
 
+static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
+                                      UINTN cols, UINTN rows, UINTN depth)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_STATUS status;
+    UINTN gop_mode = ~0, info_size, size;
+    unsigned int i;
+
+    if ( !gop )
+        return gop_mode;
+
+    for ( i = size = 0; i < gop->Mode->MaxMode; ++i )
+    {
+        unsigned int bpp = 0;
+
+        status = gop->QueryMode(gop, i, &info_size, &mode_info);
+        if ( EFI_ERROR(status) )
+            continue;
+        switch ( mode_info->PixelFormat )
+        {
+        case PixelBitMask:
+            bpp = hweight32(mode_info->PixelInformation.RedMask |
+                            mode_info->PixelInformation.GreenMask |
+                            mode_info->PixelInformation.BlueMask);
+            break;
+        case PixelRedGreenBlueReserved8BitPerColor:
+        case PixelBlueGreenRedReserved8BitPerColor:
+            bpp = 24;
+            break;
+        default:
+            continue;
+        }
+        if ( cols == mode_info->HorizontalResolution &&
+             rows == mode_info->VerticalResolution &&
+             (!depth || bpp == depth) )
+        {
+            gop_mode = i;
+            break;
+        }
+        if ( !cols && !rows &&
+             mode_info->HorizontalResolution *
+             mode_info->VerticalResolution > size )
+        {
+            size = mode_info->HorizontalResolution *
+                   mode_info->VerticalResolution;
+            gop_mode = i;
+        }
+    }
+
+    return gop_mode;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -978,46 +1030,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
         dir_handle->Close(dir_handle);
 
-        if ( gop && !base_video )
-        {
-            for ( i = size = 0; i < gop->Mode->MaxMode; ++i )
-            {
-                unsigned int bpp = 0;
-
-                status = gop->QueryMode(gop, i, &info_size, &mode_info);
-                if ( EFI_ERROR(status) )
-                    continue;
-                switch ( mode_info->PixelFormat )
-                {
-                case PixelBitMask:
-                    bpp = hweight32(mode_info->PixelInformation.RedMask |
-                                    mode_info->PixelInformation.GreenMask |
-                                    mode_info->PixelInformation.BlueMask);
-                    break;
-                case PixelRedGreenBlueReserved8BitPerColor:
-                case PixelBlueGreenRedReserved8BitPerColor:
-                    bpp = 24;
-                    break;
-                default:
-                    continue;
-                }
-                if ( cols == mode_info->HorizontalResolution &&
-                     rows == mode_info->VerticalResolution &&
-                     (!depth || bpp == depth) )
-                {
-                    gop_mode = i;
-                    break;
-                }
-                if ( !cols && !rows &&
-                     mode_info->HorizontalResolution *
-                     mode_info->VerticalResolution > size )
-                {
-                    size = mode_info->HorizontalResolution *
-                           mode_info->VerticalResolution;
-                    gop_mode = i;
-                }
-            }
-        }
+        if ( !base_video )
+            gop_mode = efi_find_gop_mode(gop, cols, rows, depth);
     }
 
     efi_arch_edd();
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 14/23
#105 lore raw

Re: [PATCH v2 14/23] efi: split out efi_find_gop_mode()

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

..which finds suitable GOP mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 128 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   94 ++++++++++++++++++++++++++++---------------------
 1 file changed, 54 insertions(+), 40 deletions(-)
xen/common/efi/boot.c +54 -40
index 6fad230..8d16470 100644
@@ -665,6 +665,58 @@ static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
     return gop;
 }
 
+static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
+                                      UINTN cols, UINTN rows, UINTN depth)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_STATUS status;
+    UINTN gop_mode = ~0, info_size, size;
+    unsigned int i;
+
+    if ( !gop )
+        return gop_mode;
+
+    for ( i = size = 0; i < gop->Mode->MaxMode; ++i )
+    {
+        unsigned int bpp = 0;
+
+        status = gop->QueryMode(gop, i, &info_size, &mode_info);
+        if ( EFI_ERROR(status) )
+            continue;
+        switch ( mode_info->PixelFormat )
+        {
+        case PixelBitMask:
+            bpp = hweight32(mode_info->PixelInformation.RedMask |
+                            mode_info->PixelInformation.GreenMask |
+                            mode_info->PixelInformation.BlueMask);
+            break;
+        case PixelRedGreenBlueReserved8BitPerColor:
+        case PixelBlueGreenRedReserved8BitPerColor:
+            bpp = 24;
+            break;
+        default:
+            continue;
+        }
+        if ( cols == mode_info->HorizontalResolution &&
+             rows == mode_info->VerticalResolution &&
+             (!depth || bpp == depth) )
+        {
+            gop_mode = i;
+            break;
+        }
+        if ( !cols && !rows &&
+             mode_info->HorizontalResolution *
+             mode_info->VerticalResolution > size )
+        {
+            size = mode_info->HorizontalResolution *
+                   mode_info->VerticalResolution;
+            gop_mode = i;
+        }
+    }
+
+    return gop_mode;
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -978,46 +1030,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
         dir_handle->Close(dir_handle);
 
-        if ( gop && !base_video )
-        {
-            for ( i = size = 0; i < gop->Mode->MaxMode; ++i )
-            {
-                unsigned int bpp = 0;
-
-                status = gop->QueryMode(gop, i, &info_size, &mode_info);
-                if ( EFI_ERROR(status) )
-                    continue;
-                switch ( mode_info->PixelFormat )
-                {
-                case PixelBitMask:
-                    bpp = hweight32(mode_info->PixelInformation.RedMask |
-                                    mode_info->PixelInformation.GreenMask |
-                                    mode_info->PixelInformation.BlueMask);
-                    break;
-                case PixelRedGreenBlueReserved8BitPerColor:
-                case PixelBlueGreenRedReserved8BitPerColor:
-                    bpp = 24;
-                    break;
-                default:
-                    continue;
-                }
-                if ( cols == mode_info->HorizontalResolution &&
-                     rows == mode_info->VerticalResolution &&
-                     (!depth || bpp == depth) )
-                {
-                    gop_mode = i;
-                    break;
-                }
-                if ( !cols && !rows &&
-                     mode_info->HorizontalResolution *
-                     mode_info->VerticalResolution > size )
-                {
-                    size = mode_info->HorizontalResolution *
-                           mode_info->VerticalResolution;
-                    gop_mode = i;
-                }
-            }
-        }
+        if ( !base_video )
+            gop_mode = efi_find_gop_mode(gop, cols, rows, depth);
     }
 
     efi_arch_edd();
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v2 14/23
#106 lore raw

Re: [PATCH v2 14/23] efi: split out efi_find_gop_mode()

In reply to Daniel Kiper
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:
xen/common/efi/boot.c +0 -0
@@ -665,6 +665,58 @@ static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
     return gop;
 }
 

xen/common/efi/boot.c static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void) · line 677

Quoted 10 lines
xen/common/efi/boot.c +10 -0
+static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
+                                      UINTN cols, UINTN rows, UINTN depth)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_STATUS status;
+    UINTN gop_mode = ~0, info_size, size;
+    unsigned int i;
+
+    if ( !gop )
+        return gop_mode;

Please drop this in favor of ...

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 981

Quoted 5 lines
xen/common/efi/boot.c +0 -1
@@ -978,46 +1030,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
         dir_handle->Close(dir_handle);
 
-        if ( gop && !base_video )

... keeping the original check here.

Similarly in patch 17.

With these minor adjustments, all the "efi: split out efi_..." patches

Jan

#107 lore raw

PATCH v2 15/23 efi: split out efi_tables()

In reply to Daniel Kiper

..which collects system tables data. We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   61 +++++++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 27 deletions(-)
xen/common/efi/boot.c +34 -27
index 8d16470..fd62125 100644
@@ -717,6 +717,39 @@ static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
     return gop_mode;
 }
 
+static void __init efi_tables(void)
+{
+    unsigned int i;
+
+    /* Obtain basic table pointers. */
+    for ( i = 0; i < efi_num_ct; ++i )
+    {
+        static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
+        static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
+        static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
+        static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
+        static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
+
+        if ( match_guid(&acpi2_guid, &efi_ct[i].VendorGuid) )
+	       efi.acpi20 = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&acpi_guid, &efi_ct[i].VendorGuid) )
+	       efi.acpi = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&mps_guid, &efi_ct[i].VendorGuid) )
+	       efi.mps = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&smbios_guid, &efi_ct[i].VendorGuid) )
+	       efi.smbios = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&smbios3_guid, &efi_ct[i].VendorGuid) )
+	       efi.smbios3 = (long)efi_ct[i].VendorTable;
+    }
+
+#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
+    dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
+                      ? (void *)(long)efi.smbios : NULL,
+                      efi.smbios3 != EFI_INVALID_TABLE_ADDR
+                      ? (void *)(long)efi.smbios3 : NULL);
+#endif
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -1039,33 +1072,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     /* XXX Collect EDID info. */
     efi_arch_cpu();
 
-    /* Obtain basic table pointers. */
-    for ( i = 0; i < efi_num_ct; ++i )
-    {
-        static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
-        static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
-        static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
-        static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
-        static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
-
-        if ( match_guid(&acpi2_guid, &efi_ct[i].VendorGuid) )
-	       efi.acpi20 = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&acpi_guid, &efi_ct[i].VendorGuid) )
-	       efi.acpi = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&mps_guid, &efi_ct[i].VendorGuid) )
-	       efi.mps = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&smbios_guid, &efi_ct[i].VendorGuid) )
-	       efi.smbios = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&smbios3_guid, &efi_ct[i].VendorGuid) )
-	       efi.smbios3 = (long)efi_ct[i].VendorTable;
-    }
-
-#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
-    dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
-                      ? (void *)(long)efi.smbios : NULL,
-                      efi.smbios3 != EFI_INVALID_TABLE_ADDR
-                      ? (void *)(long)efi.smbios3 : NULL);
-#endif
+    efi_tables();
 
     /* Collect PCI ROM contents. */
     setup_efi_pci();
Signature · 1 line
1.7.10.4
Reviewed-by on v2 15/23
#108 lore raw

Re: [Xen-devel] [PATCH v2 15/23] efi: split out efi_tables()

Quoted 4 lines · Daniel Kiper

..which collects system tables data. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 95 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   61 +++++++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 27 deletions(-)
xen/common/efi/boot.c +34 -27
index 8d16470..fd62125 100644
@@ -717,6 +717,39 @@ static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
     return gop_mode;
 }
 
+static void __init efi_tables(void)
+{
+    unsigned int i;
+
+    /* Obtain basic table pointers. */
+    for ( i = 0; i < efi_num_ct; ++i )
+    {
+        static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
+        static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
+        static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
+        static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
+        static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
+
+        if ( match_guid(&acpi2_guid, &efi_ct[i].VendorGuid) )
+	       efi.acpi20 = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&acpi_guid, &efi_ct[i].VendorGuid) )
+	       efi.acpi = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&mps_guid, &efi_ct[i].VendorGuid) )
+	       efi.mps = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&smbios_guid, &efi_ct[i].VendorGuid) )
+	       efi.smbios = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&smbios3_guid, &efi_ct[i].VendorGuid) )
+	       efi.smbios3 = (long)efi_ct[i].VendorTable;
+    }
+
+#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
+    dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
+                      ? (void *)(long)efi.smbios : NULL,
+                      efi.smbios3 != EFI_INVALID_TABLE_ADDR
+                      ? (void *)(long)efi.smbios3 : NULL);
+#endif
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -1039,33 +1072,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     /* XXX Collect EDID info. */
     efi_arch_cpu();
 
-    /* Obtain basic table pointers. */
-    for ( i = 0; i < efi_num_ct; ++i )
-    {
-        static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
-        static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
-        static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
-        static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
-        static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
-
-        if ( match_guid(&acpi2_guid, &efi_ct[i].VendorGuid) )
-	       efi.acpi20 = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&acpi_guid, &efi_ct[i].VendorGuid) )
-	       efi.acpi = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&mps_guid, &efi_ct[i].VendorGuid) )
-	       efi.mps = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&smbios_guid, &efi_ct[i].VendorGuid) )
-	       efi.smbios = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&smbios3_guid, &efi_ct[i].VendorGuid) )
-	       efi.smbios3 = (long)efi_ct[i].VendorTable;
-    }
-
-#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
-    dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
-                      ? (void *)(long)efi.smbios : NULL,
-                      efi.smbios3 != EFI_INVALID_TABLE_ADDR
-                      ? (void *)(long)efi.smbios3 : NULL);
-#endif
+    efi_tables();
 
     /* Collect PCI ROM contents. */
     setup_efi_pci();
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 15/23
#109 lore raw

Re: [PATCH v2 15/23] efi: split out efi_tables()

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

..which collects system tables data. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 95 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   61 +++++++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 27 deletions(-)
xen/common/efi/boot.c +34 -27
index 8d16470..fd62125 100644
@@ -717,6 +717,39 @@ static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
     return gop_mode;
 }
 
+static void __init efi_tables(void)
+{
+    unsigned int i;
+
+    /* Obtain basic table pointers. */
+    for ( i = 0; i < efi_num_ct; ++i )
+    {
+        static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
+        static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
+        static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
+        static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
+        static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
+
+        if ( match_guid(&acpi2_guid, &efi_ct[i].VendorGuid) )
+	       efi.acpi20 = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&acpi_guid, &efi_ct[i].VendorGuid) )
+	       efi.acpi = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&mps_guid, &efi_ct[i].VendorGuid) )
+	       efi.mps = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&smbios_guid, &efi_ct[i].VendorGuid) )
+	       efi.smbios = (long)efi_ct[i].VendorTable;
+        if ( match_guid(&smbios3_guid, &efi_ct[i].VendorGuid) )
+	       efi.smbios3 = (long)efi_ct[i].VendorTable;
+    }
+
+#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
+    dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
+                      ? (void *)(long)efi.smbios : NULL,
+                      efi.smbios3 != EFI_INVALID_TABLE_ADDR
+                      ? (void *)(long)efi.smbios3 : NULL);
+#endif
+}
+
 static void __init setup_efi_pci(void)
 {
     EFI_STATUS status;
@@ -1039,33 +1072,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     /* XXX Collect EDID info. */
     efi_arch_cpu();
 
-    /* Obtain basic table pointers. */
-    for ( i = 0; i < efi_num_ct; ++i )
-    {
-        static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
-        static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
-        static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
-        static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
-        static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
-
-        if ( match_guid(&acpi2_guid, &efi_ct[i].VendorGuid) )
-	       efi.acpi20 = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&acpi_guid, &efi_ct[i].VendorGuid) )
-	       efi.acpi = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&mps_guid, &efi_ct[i].VendorGuid) )
-	       efi.mps = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&smbios_guid, &efi_ct[i].VendorGuid) )
-	       efi.smbios = (long)efi_ct[i].VendorTable;
-        if ( match_guid(&smbios3_guid, &efi_ct[i].VendorGuid) )
-	       efi.smbios3 = (long)efi_ct[i].VendorTable;
-    }
-
-#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
-    dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
-                      ? (void *)(long)efi.smbios : NULL,
-                      efi.smbios3 != EFI_INVALID_TABLE_ADDR
-                      ? (void *)(long)efi.smbios3 : NULL);
-#endif
+    efi_tables();
 
     /* Collect PCI ROM contents. */
     setup_efi_pci();
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#110 lore raw

PATCH v2 16/23 efi: split out efi_variables()

In reply to Daniel Kiper

..which collects variable store parameters. We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)
xen/common/efi/boot.c +24 -17
index fd62125..177697a 100644
@@ -837,6 +837,29 @@ static void __init setup_efi_pci(void)
     efi_bs->FreePool(handles);
 }
 
+static void __init efi_variables(void)
+{
+    EFI_STATUS status;
+
+    status = (efi_rs->Hdr.Revision >> 16) >= 2 ?
+             efi_rs->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
+                                       EFI_VARIABLE_BOOTSERVICE_ACCESS |
+                                       EFI_VARIABLE_RUNTIME_ACCESS,
+                                       &efi_boot_max_var_store_size,
+                                       &efi_boot_remain_var_store_size,
+                                       &efi_boot_max_var_size) :
+             EFI_INCOMPATIBLE_VERSION;
+    if ( EFI_ERROR(status) )
+    {
+        efi_boot_max_var_store_size = 0;
+        efi_boot_remain_var_store_size = 0;
+        efi_boot_max_var_size = status;
+        PrintStr(L"Warning: Could not query variable store: ");
+        DisplayUint(status, 0);
+        PrintStr(newline);
+    }
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -1078,23 +1101,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     setup_efi_pci();
 
     /* Get snapshot of variable store parameters. */
-    status = (efi_rs->Hdr.Revision >> 16) >= 2 ?
-             efi_rs->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
-                                       EFI_VARIABLE_BOOTSERVICE_ACCESS |
-                                       EFI_VARIABLE_RUNTIME_ACCESS,
-                                       &efi_boot_max_var_store_size,
-                                       &efi_boot_remain_var_store_size,
-                                       &efi_boot_max_var_size) :
-             EFI_INCOMPATIBLE_VERSION;
-    if ( EFI_ERROR(status) )
-    {
-        efi_boot_max_var_store_size = 0;
-        efi_boot_remain_var_store_size = 0;
-        efi_boot_max_var_size = status;
-        PrintStr(L"Warning: Could not query variable store: ");
-        DisplayUint(status, 0);
-        PrintStr(newline);
-    }
+    efi_variables();
 
     efi_arch_memory_setup();
 
Signature · 1 line
1.7.10.4
Reviewed-by on v2 16/23
#111 lore raw

Re: [PATCH v2 16/23] efi: split out efi_variables()

Quoted 4 lines · Daniel Kiper

..which collects variable store parameters. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 75 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)
xen/common/efi/boot.c +24 -17
index fd62125..177697a 100644
@@ -837,6 +837,29 @@ static void __init setup_efi_pci(void)
     efi_bs->FreePool(handles);
 }
 
+static void __init efi_variables(void)
+{
+    EFI_STATUS status;
+
+    status = (efi_rs->Hdr.Revision >> 16) >= 2 ?
+             efi_rs->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
+                                       EFI_VARIABLE_BOOTSERVICE_ACCESS |
+                                       EFI_VARIABLE_RUNTIME_ACCESS,
+                                       &efi_boot_max_var_store_size,
+                                       &efi_boot_remain_var_store_size,
+                                       &efi_boot_max_var_size) :
+             EFI_INCOMPATIBLE_VERSION;
+    if ( EFI_ERROR(status) )
+    {
+        efi_boot_max_var_store_size = 0;
+        efi_boot_remain_var_store_size = 0;
+        efi_boot_max_var_size = status;
+        PrintStr(L"Warning: Could not query variable store: ");
+        DisplayUint(status, 0);
+        PrintStr(newline);
+    }
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -1078,23 +1101,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     setup_efi_pci();
 
     /* Get snapshot of variable store parameters. */
-    status = (efi_rs->Hdr.Revision >> 16) >= 2 ?
-             efi_rs->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
-                                       EFI_VARIABLE_BOOTSERVICE_ACCESS |
-                                       EFI_VARIABLE_RUNTIME_ACCESS,
-                                       &efi_boot_max_var_store_size,
-                                       &efi_boot_remain_var_store_size,
-                                       &efi_boot_max_var_size) :
-             EFI_INCOMPATIBLE_VERSION;
-    if ( EFI_ERROR(status) )
-    {
-        efi_boot_max_var_store_size = 0;
-        efi_boot_remain_var_store_size = 0;
-        efi_boot_max_var_size = status;
-        PrintStr(L"Warning: Could not query variable store: ");
-        DisplayUint(status, 0);
-        PrintStr(newline);
-    }
+    efi_variables();
 
     efi_arch_memory_setup();
 
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 16/23
#112 lore raw

Re: [Xen-devel] [PATCH v2 16/23] efi: split out efi_variables()

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

..which collects variable store parameters. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 75 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)
xen/common/efi/boot.c +24 -17
index fd62125..177697a 100644
@@ -837,6 +837,29 @@ static void __init setup_efi_pci(void)
     efi_bs->FreePool(handles);
 }
 
+static void __init efi_variables(void)
+{
+    EFI_STATUS status;
+
+    status = (efi_rs->Hdr.Revision >> 16) >= 2 ?
+             efi_rs->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
+                                       EFI_VARIABLE_BOOTSERVICE_ACCESS |
+                                       EFI_VARIABLE_RUNTIME_ACCESS,
+                                       &efi_boot_max_var_store_size,
+                                       &efi_boot_remain_var_store_size,
+                                       &efi_boot_max_var_size) :
+             EFI_INCOMPATIBLE_VERSION;
+    if ( EFI_ERROR(status) )
+    {
+        efi_boot_max_var_store_size = 0;
+        efi_boot_remain_var_store_size = 0;
+        efi_boot_max_var_size = status;
+        PrintStr(L"Warning: Could not query variable store: ");
+        DisplayUint(status, 0);
+        PrintStr(newline);
+    }
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -1078,23 +1101,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     setup_efi_pci();
 
     /* Get snapshot of variable store parameters. */
-    status = (efi_rs->Hdr.Revision >> 16) >= 2 ?
-             efi_rs->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
-                                       EFI_VARIABLE_BOOTSERVICE_ACCESS |
-                                       EFI_VARIABLE_RUNTIME_ACCESS,
-                                       &efi_boot_max_var_store_size,
-                                       &efi_boot_remain_var_store_size,
-                                       &efi_boot_max_var_size) :
-             EFI_INCOMPATIBLE_VERSION;
-    if ( EFI_ERROR(status) )
-    {
-        efi_boot_max_var_store_size = 0;
-        efi_boot_remain_var_store_size = 0;
-        efi_boot_max_var_size = status;
-        PrintStr(L"Warning: Could not query variable store: ");
-        DisplayUint(status, 0);
-        PrintStr(newline);
-    }
+    efi_variables();
 
     efi_arch_memory_setup();
 
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#113 lore raw

PATCH v2 17/23 efi: split out efi_set_gop_mode()

In reply to Daniel Kiper

..which sets chosen GOP mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)
xen/common/efi/boot.c +20 -13
index 177697a..04b9c7e 100644
@@ -860,6 +860,25 @@ static void __init efi_variables(void)
     }
 }
 
+static void __init efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop_mode)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_STATUS status;
+    UINTN info_size;
+
+    if ( !gop )
+        return;
+
+    /* Set graphics mode. */
+    if ( gop_mode < gop->Mode->MaxMode && gop_mode != gop->Mode->Mode )
+        gop->SetMode(gop, gop_mode);
+
+    /* Get graphics and frame buffer info. */
+    status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
+    if ( !EFI_ERROR(status) )
+        efi_arch_video_init(gop, info_size, mode_info);
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -887,7 +906,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     UINTN map_key, info_size, gop_mode = ~0;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
-    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     union string section = { NULL }, name;
     bool_t base_video = 0, retry;
     char *option_str;
@@ -1105,18 +1123,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_arch_memory_setup();
 
-    if ( gop )
-    {
-
-        /* Set graphics mode. */
-        if ( gop_mode < gop->Mode->MaxMode && gop_mode != gop->Mode->Mode )
-            gop->SetMode(gop, gop_mode);
-
-        /* Get graphics and frame buffer info. */
-        status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
-        if ( !EFI_ERROR(status) )
-            efi_arch_video_init(gop, info_size, mode_info);
-    }
+    efi_set_gop_mode(gop, gop_mode);
 
     info_size = 0;
     efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
Signature · 1 line
1.7.10.4
Reviewed-by on v2 17/23
#114 lore raw

Re: [PATCH v2 17/23] efi: split out efi_set_gop_mode()

Quoted 4 lines · Daniel Kiper

..which sets chosen GOP mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 74 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)
xen/common/efi/boot.c +20 -13
index 177697a..04b9c7e 100644
@@ -860,6 +860,25 @@ static void __init efi_variables(void)
     }
 }
 
+static void __init efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop_mode)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_STATUS status;
+    UINTN info_size;
+
+    if ( !gop )
+        return;
+
+    /* Set graphics mode. */
+    if ( gop_mode < gop->Mode->MaxMode && gop_mode != gop->Mode->Mode )
+        gop->SetMode(gop, gop_mode);
+
+    /* Get graphics and frame buffer info. */
+    status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
+    if ( !EFI_ERROR(status) )
+        efi_arch_video_init(gop, info_size, mode_info);
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -887,7 +906,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     UINTN map_key, info_size, gop_mode = ~0;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
-    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     union string section = { NULL }, name;
     bool_t base_video = 0, retry;
     char *option_str;
@@ -1105,18 +1123,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_arch_memory_setup();
 
-    if ( gop )
-    {
-
-        /* Set graphics mode. */
-        if ( gop_mode < gop->Mode->MaxMode && gop_mode != gop->Mode->Mode )
-            gop->SetMode(gop, gop_mode);
-
-        /* Get graphics and frame buffer info. */
-        status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
-        if ( !EFI_ERROR(status) )
-            efi_arch_video_init(gop, info_size, mode_info);
-    }
+    efi_set_gop_mode(gop, gop_mode);
 
     info_size = 0;
     efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 17/23
#115 lore raw

Re: [Xen-devel] [PATCH v2 17/23] efi: split out efi_set_gop_mode()

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

..which sets chosen GOP mode. We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 74 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)
xen/common/efi/boot.c +20 -13
index 177697a..04b9c7e 100644
@@ -860,6 +860,25 @@ static void __init efi_variables(void)
     }
 }
 
+static void __init efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop_mode)
+{
+    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
+    EFI_STATUS status;
+    UINTN info_size;
+
+    if ( !gop )
+        return;
+
+    /* Set graphics mode. */
+    if ( gop_mode < gop->Mode->MaxMode && gop_mode != gop->Mode->Mode )
+        gop->SetMode(gop, gop_mode);
+
+    /* Get graphics and frame buffer info. */
+    status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
+    if ( !EFI_ERROR(status) )
+        efi_arch_video_init(gop, info_size, mode_info);
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -887,7 +906,6 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     UINTN map_key, info_size, gop_mode = ~0;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
-    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
     union string section = { NULL }, name;
     bool_t base_video = 0, retry;
     char *option_str;
@@ -1105,18 +1123,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_arch_memory_setup();
 
-    if ( gop )
-    {
-
-        /* Set graphics mode. */
-        if ( gop_mode < gop->Mode->MaxMode && gop_mode != gop->Mode->Mode )
-            gop->SetMode(gop, gop_mode);
-
-        /* Get graphics and frame buffer info. */
-        status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
-        if ( !EFI_ERROR(status) )
-            efi_arch_video_init(gop, info_size, mode_info);
-    }
+    efi_set_gop_mode(gop, gop_mode);
 
     info_size = 0;
     efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#116 lore raw

PATCH v2 18/23 efi: split out efi_exit_boot()

In reply to Daniel Kiper

..which gets memory map and calls ExitBootServices(). We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   92 +++++++++++++++++++++++++++----------------------
 1 file changed, 50 insertions(+), 42 deletions(-)
xen/common/efi/boot.c +50 -42
index 04b9c7e..bf2f198 100644
@@ -879,6 +879,53 @@ static void __init efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop
         efi_arch_video_init(gop, info_size, mode_info);
 }
 
+static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_STATUS status;
+    UINTN info_size = 0, map_key;
+    bool_t retry;
+
+    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
+                         &efi_mdesc_size, &mdesc_ver);
+    info_size += 8 * efi_mdesc_size;
+    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
+    if ( !efi_memmap )
+        blexit(L"Unable to allocate memory for EFI memory map");
+
+    for ( retry = 0; ; retry = 1 )
+    {
+        efi_memmap_size = info_size;
+        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
+                                                         efi_memmap, &map_key,
+                                                         &efi_mdesc_size,
+                                                         &mdesc_ver);
+        if ( EFI_ERROR(status) )
+            PrintErrMesg(L"Cannot obtain memory map", status);
+
+        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
+                                    efi_mdesc_size, mdesc_ver);
+
+        efi_arch_pre_exit_boot();
+
+        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
+                                                             map_key);
+        efi_bs = NULL;
+        if ( status != EFI_INVALID_PARAMETER || retry )
+            break;
+    }
+
+    if ( EFI_ERROR(status) )
+        PrintErrMesg(L"Cannot exit boot services", status);
+
+    /* Adjust pointers into EFI. */
+    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
+#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
+    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
+#endif
+    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
+    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -903,11 +950,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
-    UINTN map_key, info_size, gop_mode = ~0;
+    UINTN gop_mode = ~0;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     union string section = { NULL }, name;
-    bool_t base_video = 0, retry;
+    bool_t base_video = 0;
     char *option_str;
     bool_t use_cfg_file;
 
@@ -1125,46 +1172,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_set_gop_mode(gop, gop_mode);
 
-    info_size = 0;
-    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
-                         &efi_mdesc_size, &mdesc_ver);
-    info_size += 8 * efi_mdesc_size;
-    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
-    if ( !efi_memmap )
-        blexit(L"Unable to allocate memory for EFI memory map");
-
-    for ( retry = 0; ; retry = 1 )
-    {
-        efi_memmap_size = info_size;
-        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
-                                                         efi_memmap, &map_key,
-                                                         &efi_mdesc_size,
-                                                         &mdesc_ver);
-        if ( EFI_ERROR(status) )
-            PrintErrMesg(L"Cannot obtain memory map", status);
-
-        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
-                                    efi_mdesc_size, mdesc_ver);
-
-        efi_arch_pre_exit_boot();
-
-        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
-                                                             map_key);
-        efi_bs = NULL;
-        if ( status != EFI_INVALID_PARAMETER || retry )
-            break;
-    }
-
-    if ( EFI_ERROR(status) )
-        PrintErrMesg(L"Cannot exit boot services", status);
-
-    /* Adjust pointers into EFI. */
-    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
-#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
-    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
-#endif
-    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
-    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
+    efi_exit_boot(ImageHandle, SystemTable);
 
     efi_arch_post_exit_boot();
     for( ; ; ); /* not reached */
Signature · 1 line
1.7.10.4
#117 lore raw

PATCH v2 18/23 efi: split out efi_exit_boot()

In reply to Daniel Kiper

..which gets memory map and calls ExitBootServices(). We want to re-use this code to support multiboot2 protocol on EFI platforms.

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   92 +++++++++++++++++++++++++++----------------------
 1 file changed, 50 insertions(+), 42 deletions(-)
xen/common/efi/boot.c +50 -42
index 04b9c7e..bf2f198 100644
@@ -879,6 +879,53 @@ static void __init efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop
         efi_arch_video_init(gop, info_size, mode_info);
 }
 
+static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_STATUS status;
+    UINTN info_size = 0, map_key;
+    bool_t retry;
+
+    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
+                         &efi_mdesc_size, &mdesc_ver);
+    info_size += 8 * efi_mdesc_size;
+    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
+    if ( !efi_memmap )
+        blexit(L"Unable to allocate memory for EFI memory map");
+
+    for ( retry = 0; ; retry = 1 )
+    {
+        efi_memmap_size = info_size;
+        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
+                                                         efi_memmap, &map_key,
+                                                         &efi_mdesc_size,
+                                                         &mdesc_ver);
+        if ( EFI_ERROR(status) )
+            PrintErrMesg(L"Cannot obtain memory map", status);
+
+        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
+                                    efi_mdesc_size, mdesc_ver);
+
+        efi_arch_pre_exit_boot();
+
+        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
+                                                             map_key);
+        efi_bs = NULL;
+        if ( status != EFI_INVALID_PARAMETER || retry )
+            break;
+    }
+
+    if ( EFI_ERROR(status) )
+        PrintErrMesg(L"Cannot exit boot services", status);
+
+    /* Adjust pointers into EFI. */
+    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
+#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
+    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
+#endif
+    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
+    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -903,11 +950,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
-    UINTN map_key, info_size, gop_mode = ~0;
+    UINTN gop_mode = ~0;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     union string section = { NULL }, name;
-    bool_t base_video = 0, retry;
+    bool_t base_video = 0;
     char *option_str;
     bool_t use_cfg_file;
 
@@ -1125,46 +1172,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_set_gop_mode(gop, gop_mode);
 
-    info_size = 0;
-    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
-                         &efi_mdesc_size, &mdesc_ver);
-    info_size += 8 * efi_mdesc_size;
-    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
-    if ( !efi_memmap )
-        blexit(L"Unable to allocate memory for EFI memory map");
-
-    for ( retry = 0; ; retry = 1 )
-    {
-        efi_memmap_size = info_size;
-        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
-                                                         efi_memmap, &map_key,
-                                                         &efi_mdesc_size,
-                                                         &mdesc_ver);
-        if ( EFI_ERROR(status) )
-            PrintErrMesg(L"Cannot obtain memory map", status);
-
-        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
-                                    efi_mdesc_size, mdesc_ver);
-
-        efi_arch_pre_exit_boot();
-
-        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
-                                                             map_key);
-        efi_bs = NULL;
-        if ( status != EFI_INVALID_PARAMETER || retry )
-            break;
-    }
-
-    if ( EFI_ERROR(status) )
-        PrintErrMesg(L"Cannot exit boot services", status);
-
-    /* Adjust pointers into EFI. */
-    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
-#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
-    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
-#endif
-    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
-    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
+    efi_exit_boot(ImageHandle, SystemTable);
 
     efi_arch_post_exit_boot();
     for( ; ; ); /* not reached */
Signature · 1 line
1.7.10.4
Reviewed-by on v2 18/23
#118 lore raw

Re: [Xen-devel] [PATCH v2 18/23] efi: split out efi_exit_boot()

Quoted 4 lines · Daniel Kiper

..which gets memory map and calls ExitBootServices(). We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 136 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   92 +++++++++++++++++++++++++++----------------------
 1 file changed, 50 insertions(+), 42 deletions(-)
xen/common/efi/boot.c +50 -42
index 04b9c7e..bf2f198 100644
@@ -879,6 +879,53 @@ static void __init efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop
         efi_arch_video_init(gop, info_size, mode_info);
 }
 
+static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_STATUS status;
+    UINTN info_size = 0, map_key;
+    bool_t retry;
+
+    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
+                         &efi_mdesc_size, &mdesc_ver);
+    info_size += 8 * efi_mdesc_size;
+    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
+    if ( !efi_memmap )
+        blexit(L"Unable to allocate memory for EFI memory map");
+
+    for ( retry = 0; ; retry = 1 )
+    {
+        efi_memmap_size = info_size;
+        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
+                                                         efi_memmap, &map_key,
+                                                         &efi_mdesc_size,
+                                                         &mdesc_ver);
+        if ( EFI_ERROR(status) )
+            PrintErrMesg(L"Cannot obtain memory map", status);
+
+        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
+                                    efi_mdesc_size, mdesc_ver);
+
+        efi_arch_pre_exit_boot();
+
+        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
+                                                             map_key);
+        efi_bs = NULL;
+        if ( status != EFI_INVALID_PARAMETER || retry )
+            break;
+    }
+
+    if ( EFI_ERROR(status) )
+        PrintErrMesg(L"Cannot exit boot services", status);
+
+    /* Adjust pointers into EFI. */
+    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
+#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
+    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
+#endif
+    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
+    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -903,11 +950,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
-    UINTN map_key, info_size, gop_mode = ~0;
+    UINTN gop_mode = ~0;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     union string section = { NULL }, name;
-    bool_t base_video = 0, retry;
+    bool_t base_video = 0;
     char *option_str;
     bool_t use_cfg_file;
 
@@ -1125,46 +1172,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_set_gop_mode(gop, gop_mode);
 
-    info_size = 0;
-    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
-                         &efi_mdesc_size, &mdesc_ver);
-    info_size += 8 * efi_mdesc_size;
-    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
-    if ( !efi_memmap )
-        blexit(L"Unable to allocate memory for EFI memory map");
-
-    for ( retry = 0; ; retry = 1 )
-    {
-        efi_memmap_size = info_size;
-        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
-                                                         efi_memmap, &map_key,
-                                                         &efi_mdesc_size,
-                                                         &mdesc_ver);
-        if ( EFI_ERROR(status) )
-            PrintErrMesg(L"Cannot obtain memory map", status);
-
-        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
-                                    efi_mdesc_size, mdesc_ver);
-
-        efi_arch_pre_exit_boot();
-
-        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
-                                                             map_key);
-        efi_bs = NULL;
-        if ( status != EFI_INVALID_PARAMETER || retry )
-            break;
-    }
-
-    if ( EFI_ERROR(status) )
-        PrintErrMesg(L"Cannot exit boot services", status);
-
-    /* Adjust pointers into EFI. */
-    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
-#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
-    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
-#endif
-    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
-    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
+    efi_exit_boot(ImageHandle, SystemTable);
 
     efi_arch_post_exit_boot();
     for( ; ; ); /* not reached */
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 18/23
#119 lore raw

Re: [PATCH v2 18/23] efi: split out efi_exit_boot()

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

..which gets memory map and calls ExitBootServices(). We want to re-use this code to support multiboot2 protocol on EFI platforms.

Quoted 136 lines

---
v2 - suggestions/fixes:
- improve commit message
(suggested by Jan Beulich).

---
 xen/common/efi/boot.c |   92 +++++++++++++++++++++++++++----------------------
 1 file changed, 50 insertions(+), 42 deletions(-)
xen/common/efi/boot.c +50 -42
index 04b9c7e..bf2f198 100644
@@ -879,6 +879,53 @@ static void __init efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop
         efi_arch_video_init(gop, info_size, mode_info);
 }
 
+static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_STATUS status;
+    UINTN info_size = 0, map_key;
+    bool_t retry;
+
+    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
+                         &efi_mdesc_size, &mdesc_ver);
+    info_size += 8 * efi_mdesc_size;
+    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
+    if ( !efi_memmap )
+        blexit(L"Unable to allocate memory for EFI memory map");
+
+    for ( retry = 0; ; retry = 1 )
+    {
+        efi_memmap_size = info_size;
+        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
+                                                         efi_memmap, &map_key,
+                                                         &efi_mdesc_size,
+                                                         &mdesc_ver);
+        if ( EFI_ERROR(status) )
+            PrintErrMesg(L"Cannot obtain memory map", status);
+
+        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
+                                    efi_mdesc_size, mdesc_ver);
+
+        efi_arch_pre_exit_boot();
+
+        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
+                                                             map_key);
+        efi_bs = NULL;
+        if ( status != EFI_INVALID_PARAMETER || retry )
+            break;
+    }
+
+    if ( EFI_ERROR(status) )
+        PrintErrMesg(L"Cannot exit boot services", status);
+
+    /* Adjust pointers into EFI. */
+    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
+#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
+    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
+#endif
+    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
+    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
+}
+
 static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
 {
    if ( bpp < 0 )
@@ -903,11 +950,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     EFI_STATUS status;
     unsigned int i, argc;
     CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
-    UINTN map_key, info_size, gop_mode = ~0;
+    UINTN gop_mode = ~0;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     union string section = { NULL }, name;
-    bool_t base_video = 0, retry;
+    bool_t base_video = 0;
     char *option_str;
     bool_t use_cfg_file;
 
@@ -1125,46 +1172,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     efi_set_gop_mode(gop, gop_mode);
 
-    info_size = 0;
-    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
-                         &efi_mdesc_size, &mdesc_ver);
-    info_size += 8 * efi_mdesc_size;
-    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
-    if ( !efi_memmap )
-        blexit(L"Unable to allocate memory for EFI memory map");
-
-    for ( retry = 0; ; retry = 1 )
-    {
-        efi_memmap_size = info_size;
-        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
-                                                         efi_memmap, &map_key,
-                                                         &efi_mdesc_size,
-                                                         &mdesc_ver);
-        if ( EFI_ERROR(status) )
-            PrintErrMesg(L"Cannot obtain memory map", status);
-
-        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
-                                    efi_mdesc_size, mdesc_ver);
-
-        efi_arch_pre_exit_boot();
-
-        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
-                                                             map_key);
-        efi_bs = NULL;
-        if ( status != EFI_INVALID_PARAMETER || retry )
-            break;
-    }
-
-    if ( EFI_ERROR(status) )
-        PrintErrMesg(L"Cannot exit boot services", status);
-
-    /* Adjust pointers into EFI. */
-    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
-#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
-    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
-#endif
-    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
-    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
+    efi_exit_boot(ImageHandle, SystemTable);
 
     efi_arch_post_exit_boot();
     for( ; ; ); /* not reached */
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#120 lore raw

PATCH v2 19/23 x86/efi: create new early memory allocator

In reply to Daniel Kiper

There is a problem with place_string() which is used as early memory allocator. It gets memory chunks starting from start symbol and going down. Sadly this does not work when Xen is loaded using multiboot2 protocol because start lives on 1 MiB address. So, I tried to use mem_lower address calculated by GRUB2. However, it works only on some machines. There are machines in the wild (e.g. Dell PowerEdge R820) which uses first ~640 KiB for boot services code or data... :-(((

In case of multiboot2 protocol we need that place_string() only allocate memory chunk for EFI memory map. However, I think that it should be fixed instead of making another function used just in one case. I thought about two solutions.

1) We could use native EFI allocation functions (e.g. AllocatePool() or AllocatePages()) to get memory chunk. However, later (somewhere in __start_xen()) we must copy its contents to safe place or reserve this in e820 memory map and map it in Xen virtual address space. In later case we must also care about conflicts with e.g. crash kernel regions which could be quite difficult.

2) We may allocate memory area statically somewhere in Xen code which could be used as memory pool for early dynamic allocations. Looks quite simple. Additionally, it would not depend on EFI at all and could be used on legacy BIOS platforms if we need it. However, we must carefully choose size of this pool. We do not want increase Xen binary size too much and waste too much memory but also we must fit at least memory map on x86 EFI platforms. As I saw on small machine, e.g. IBM System x3550 M2 with 8 GiB RAM, memory map may contain more than 200 entries. Every entry on x86-64 platform is 40 bytes in size. So, it means that we need more than 8 KiB for EFI memory map only. Additionally, if we want to use this memory pool for Xen and modules command line storage (it would be used when xen.efi is executed as EFI application) then we should add, I think, about 1 KiB. In this case, to be on safe side, we should assume at least 64 KiB pool for early memory allocations, which is about 4 times of our earlier calculations. However, during discussion on Xen-devel Jan Beulich suggested that just in case we should use 1 MiB memory pool like it was in original place_string() implementation. So, let's use 1 MiB as it was proposed. If we think that we should not waste unallocated memory in the pool on running system then we can mark this region as __initdata and move all required data to dynamically allocated places somewhere in __start_xen().

Now solution #2 is implemented but maybe we should consider #1 one day.

---
 xen/arch/x86/efi/efi-boot.h |   38 ++++++++++++++++++++++++++++++--------
 xen/arch/x86/setup.c        |    3 +--
 2 files changed, 31 insertions(+), 10 deletions(-)
xen/arch/x86/efi/efi-boot.h +30 -8
index 2dd69f6..3d25c48 100644
@@ -103,9 +103,36 @@ static void __init relocate_trampoline(unsigned long phys)
         *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4;
 }
 
+#define EBMALLOC_SIZE	MB(1)
+
+static char __initdata ebmalloc_mem[EBMALLOC_SIZE];
+static char __initdata *ebmalloc_free = NULL;
+
+/* EFI boot allocator. */
+static void __init *ebmalloc(size_t size)
+{
+    void *ptr;
+
+    /*
+     * Init ebmalloc_free on runtime. Static initialization
+     * will not work because it puts virtual address there.
+     */
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;
+
+    if ( ebmalloc_free - ebmalloc_mem > sizeof(ebmalloc_mem) )
+        blexit(L"Out of static memory\r\n");
+
+    return ptr;
+}
+
 static void __init place_string(u32 *addr, const char *s)
 {
-    static char *__initdata alloc = start;
+    char *alloc = NULL;
 
     if ( s && *s )
     {
@@ -113,7 +140,7 @@ static void __init place_string(u32 *addr, const char *s)
         const char *old = (char *)(long)*addr;
         size_t len2 = *addr ? strlen(old) + 1 : 0;
 
-        alloc -= len1 + len2;
+        alloc = ebmalloc(len1 + len2);
         /*
          * Insert new string before already existing one. This is needed
          * for options passed on the command line to override options from
@@ -196,12 +223,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
 
 static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
 {
-    place_string(&mbi.mem_upper, NULL);
-    mbi.mem_upper -= map_size;
-    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
-    if ( mbi.mem_upper < xen_phys_start )
-        return NULL;
-    return (void *)(long)mbi.mem_upper;
+    return ebmalloc(map_size);
 }
 
 static void __init efi_arch_pre_exit_boot(void)
xen/arch/x86/setup.c +1 -2
index bce708c..a59fc4e 100644
@@ -994,8 +994,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen.");
-    reserve_e820_ram(&boot_e820, efi_enabled(EFI_PLATFORM) ? mbi->mem_upper : __pa(&_start),
-                     __pa(&_end));
+    reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
Signature · 1 line
1.7.10.4
#121 lore raw

PATCH v2 19/23 x86/efi: create new early memory allocator

In reply to Daniel Kiper

There is a problem with place_string() which is used as early memory allocator. It gets memory chunks starting from start symbol and going down. Sadly this does not work when Xen is loaded using multiboot2 protocol because start lives on 1 MiB address. So, I tried to use mem_lower address calculated by GRUB2. However, it works only on some machines. There are machines in the wild (e.g. Dell PowerEdge R820) which uses first ~640 KiB for boot services code or data... :-(((

In case of multiboot2 protocol we need that place_string() only allocate memory chunk for EFI memory map. However, I think that it should be fixed instead of making another function used just in one case. I thought about two solutions.

1) We could use native EFI allocation functions (e.g. AllocatePool() or AllocatePages()) to get memory chunk. However, later (somewhere in __start_xen()) we must copy its contents to safe place or reserve this in e820 memory map and map it in Xen virtual address space. In later case we must also care about conflicts with e.g. crash kernel regions which could be quite difficult.

2) We may allocate memory area statically somewhere in Xen code which could be used as memory pool for early dynamic allocations. Looks quite simple. Additionally, it would not depend on EFI at all and could be used on legacy BIOS platforms if we need it. However, we must carefully choose size of this pool. We do not want increase Xen binary size too much and waste too much memory but also we must fit at least memory map on x86 EFI platforms. As I saw on small machine, e.g. IBM System x3550 M2 with 8 GiB RAM, memory map may contain more than 200 entries. Every entry on x86-64 platform is 40 bytes in size. So, it means that we need more than 8 KiB for EFI memory map only. Additionally, if we want to use this memory pool for Xen and modules command line storage (it would be used when xen.efi is executed as EFI application) then we should add, I think, about 1 KiB. In this case, to be on safe side, we should assume at least 64 KiB pool for early memory allocations, which is about 4 times of our earlier calculations. However, during discussion on Xen-devel Jan Beulich suggested that just in case we should use 1 MiB memory pool like it was in original place_string() implementation. So, let's use 1 MiB as it was proposed. If we think that we should not waste unallocated memory in the pool on running system then we can mark this region as __initdata and move all required data to dynamically allocated places somewhere in __start_xen().

Now solution #2 is implemented but maybe we should consider #1 one day.

---
 xen/arch/x86/efi/efi-boot.h |   38 ++++++++++++++++++++++++++++++--------
 xen/arch/x86/setup.c        |    3 +--
 2 files changed, 31 insertions(+), 10 deletions(-)
xen/arch/x86/efi/efi-boot.h +30 -8
index 2dd69f6..3d25c48 100644
@@ -103,9 +103,36 @@ static void __init relocate_trampoline(unsigned long phys)
         *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4;
 }
 
+#define EBMALLOC_SIZE	MB(1)
+
+static char __initdata ebmalloc_mem[EBMALLOC_SIZE];
+static char __initdata *ebmalloc_free = NULL;
+
+/* EFI boot allocator. */
+static void __init *ebmalloc(size_t size)
+{
+    void *ptr;
+
+    /*
+     * Init ebmalloc_free on runtime. Static initialization
+     * will not work because it puts virtual address there.
+     */
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;
+
+    if ( ebmalloc_free - ebmalloc_mem > sizeof(ebmalloc_mem) )
+        blexit(L"Out of static memory\r\n");
+
+    return ptr;
+}
+
 static void __init place_string(u32 *addr, const char *s)
 {
-    static char *__initdata alloc = start;
+    char *alloc = NULL;
 
     if ( s && *s )
     {
@@ -113,7 +140,7 @@ static void __init place_string(u32 *addr, const char *s)
         const char *old = (char *)(long)*addr;
         size_t len2 = *addr ? strlen(old) + 1 : 0;
 
-        alloc -= len1 + len2;
+        alloc = ebmalloc(len1 + len2);
         /*
          * Insert new string before already existing one. This is needed
          * for options passed on the command line to override options from
@@ -196,12 +223,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
 
 static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
 {
-    place_string(&mbi.mem_upper, NULL);
-    mbi.mem_upper -= map_size;
-    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
-    if ( mbi.mem_upper < xen_phys_start )
-        return NULL;
-    return (void *)(long)mbi.mem_upper;
+    return ebmalloc(map_size);
 }
 
 static void __init efi_arch_pre_exit_boot(void)
xen/arch/x86/setup.c +1 -2
index bce708c..a59fc4e 100644
@@ -994,8 +994,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen.");
-    reserve_e820_ram(&boot_e820, efi_enabled(EFI_PLATFORM) ? mbi->mem_upper : __pa(&_start),
-                     __pa(&_end));
+    reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
Signature · 1 line
1.7.10.4
Reviewed-by on v2 19/23
#122 lore raw

Re: [Xen-devel] [PATCH v2 19/23] x86/efi: create new early memory allocator

Quoted 4 lines · Daniel Kiper

There is a problem with place_string() which is used as early memory allocator. It gets memory chunks starting from start symbol and going down. Sadly this does not work when Xen is loaded using multiboot2 protocol because start lives on 1 MiB address. So, I tried to use

s/So, I tried to use/With/

Quoted 1 line

mem_lower address calculated by GRUB2. However, it works only on some

s/GRUB2. However, //

Quoted 4 lines

machines. There are machines in the wild (e.g. Dell PowerEdge R820) which uses first ~640 KiB for boot services code or data... :-(((

In case of multiboot2 protocol we need that place_string() only allocate

s/only/to only/

Quoted 3 lines

memory chunk for EFI memory map. However, I think that it should be fixed instead of making another function used just in one case. I thought about two solutions.

s/I think ...two solutions/There are two solutions:/

Quoted 8 lines

1) We could use native EFI allocation functions (e.g. AllocatePool() or AllocatePages()) to get memory chunk. However, later (somewhere in __start_xen()) we must copy its contents to safe place or reserve this in e820 memory map and map it in Xen virtual address space. In later case we must also care about conflicts with e.g. crash kernel regions which could be quite difficult.

Quoted 6 lines

2) We may allocate memory area statically somewhere in Xen code which could be used as memory pool for early dynamic allocations. Looks quite simple. Additionally, it would not depend on EFI at all and could be used on legacy BIOS platforms if we need it. However, we must carefully choose size of this pool. We do not want increase Xen binary size too much and waste too much memory but also we must fit

Aren't we gziping the binary? In which you do not waste that much disk space.

Quoted 1 line

at least memory map on x86 EFI platforms. As I saw on small machine,

s/at least memory map on/on small memory/

s/As I saw on small machine/For example on/

Quoted 2 lines

e.g. IBM System x3550 M2 with 8 GiB RAM, memory map may contain more than 200 entries. Every entry on x86-64 platform is 40 bytes in size.

s/entries. Every entry on .. is/wherein every entry is/

Quoted 1 line

So, it means that we need more than 8 KiB for EFI memory map only.

s/So, it means that we need more than/Brings it up to/

Quoted 3 lines

Additionally, if we want to use this memory pool for Xen and modules command line storage (it would be used when xen.efi is executed as EFI application) then we should add, I think, about 1 KiB. In this case,

s/,I think, //

Quoted 5 lines

to be on safe side, we should assume at least 64 KiB pool for early memory allocations, which is about 4 times of our earlier calculations. However, during discussion on Xen-devel Jan Beulich suggested that just in case we should use 1 MiB memory pool like it was in original place_string() implementation. So, let's use 1 MiB as it was proposed.

s/If we think that we should not/To not/

Quoted 5 lines

If we think that we should not waste unallocated memory in the pool on running system then we can mark this region as __initdata and move all required data to dynamically allocated places somewhere in __start_xen().

Now solution #2 is implemented but maybe we should consider #1 one day.

s/Now ../This patch implements #2 solution./

Quoted 2 lines

adjustments mentioned.

Quoted 16 lines
---
 xen/arch/x86/efi/efi-boot.h |   38 ++++++++++++++++++++++++++++++--------
 xen/arch/x86/setup.c        |    3 +--
 2 files changed, 31 insertions(+), 10 deletions(-)
xen/arch/x86/efi/efi-boot.h +3 -0
index 2dd69f6..3d25c48 100644
@@ -103,9 +103,36 @@ static void __init relocate_trampoline(unsigned long phys)
         *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4;
 }
 
+#define EBMALLOC_SIZE	MB(1)
+
+static char __initdata ebmalloc_mem[EBMALLOC_SIZE];

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 118

Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10 -0
+static char __initdata *ebmalloc_free = NULL;
+
+/* EFI boot allocator. */
+static void __init *ebmalloc(size_t size)
+{
+    void *ptr;
+
+    /*
+     * Init ebmalloc_free on runtime. Static initialization
+     * will not work because it puts virtual address there.

And why is that bad?

Quoted 66 lines
xen/arch/x86/efi/efi-boot.h +17 -8
+     */
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;
+
+    if ( ebmalloc_free - ebmalloc_mem > sizeof(ebmalloc_mem) )
+        blexit(L"Out of static memory\r\n");
+
+    return ptr;
+}
+
 static void __init place_string(u32 *addr, const char *s)
 {
-    static char *__initdata alloc = start;
+    char *alloc = NULL;
 
     if ( s && *s )
     {
@@ -113,7 +140,7 @@ static void __init place_string(u32 *addr, const char *s)
         const char *old = (char *)(long)*addr;
         size_t len2 = *addr ? strlen(old) + 1 : 0;
 
-        alloc -= len1 + len2;
+        alloc = ebmalloc(len1 + len2);
         /*
          * Insert new string before already existing one. This is needed
          * for options passed on the command line to override options from
@@ -196,12 +223,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
 
 static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
 {
-    place_string(&mbi.mem_upper, NULL);
-    mbi.mem_upper -= map_size;
-    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
-    if ( mbi.mem_upper < xen_phys_start )
-        return NULL;
-    return (void *)(long)mbi.mem_upper;
+    return ebmalloc(map_size);
 }
 
 static void __init efi_arch_pre_exit_boot(void)
xen/arch/x86/setup.c +1 -2
index bce708c..a59fc4e 100644
@@ -994,8 +994,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen.");
-    reserve_e820_ram(&boot_e820, efi_enabled(EFI_PLATFORM) ? mbi->mem_upper : __pa(&_start),
-                     __pa(&_end));
+    reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 19/23
#123 lore raw

Re: [PATCH v2 19/23] x86/efi: create new early memory allocator

In reply to Daniel Kiper
Quoted 4 lines · Daniel Kiper

There is a problem with place_string() which is used as early memory allocator. It gets memory chunks starting from start symbol and going down. Sadly this does not work when Xen is loaded using multiboot2 protocol because start lives on 1 MiB address. So, I tried to use

s/So, I tried to use/With/

Quoted 1 line

mem_lower address calculated by GRUB2. However, it works only on some

s/GRUB2. However, //

Quoted 4 lines

machines. There are machines in the wild (e.g. Dell PowerEdge R820) which uses first ~640 KiB for boot services code or data... :-(((

In case of multiboot2 protocol we need that place_string() only allocate

s/only/to only/

Quoted 3 lines

memory chunk for EFI memory map. However, I think that it should be fixed instead of making another function used just in one case. I thought about two solutions.

s/I think ...two solutions/There are two solutions:/

Quoted 8 lines

1) We could use native EFI allocation functions (e.g. AllocatePool() or AllocatePages()) to get memory chunk. However, later (somewhere in __start_xen()) we must copy its contents to safe place or reserve this in e820 memory map and map it in Xen virtual address space. In later case we must also care about conflicts with e.g. crash kernel regions which could be quite difficult.

Quoted 6 lines

2) We may allocate memory area statically somewhere in Xen code which could be used as memory pool for early dynamic allocations. Looks quite simple. Additionally, it would not depend on EFI at all and could be used on legacy BIOS platforms if we need it. However, we must carefully choose size of this pool. We do not want increase Xen binary size too much and waste too much memory but also we must fit

Aren't we gziping the binary? In which you do not waste that much disk space.

Quoted 1 line

at least memory map on x86 EFI platforms. As I saw on small machine,

s/at least memory map on/on small memory/

s/As I saw on small machine/For example on/

Quoted 2 lines

e.g. IBM System x3550 M2 with 8 GiB RAM, memory map may contain more than 200 entries. Every entry on x86-64 platform is 40 bytes in size.

s/entries. Every entry on .. is/wherein every entry is/

Quoted 1 line

So, it means that we need more than 8 KiB for EFI memory map only.

s/So, it means that we need more than/Brings it up to/

Quoted 3 lines

Additionally, if we want to use this memory pool for Xen and modules command line storage (it would be used when xen.efi is executed as EFI application) then we should add, I think, about 1 KiB. In this case,

s/,I think, //

Quoted 5 lines

to be on safe side, we should assume at least 64 KiB pool for early memory allocations, which is about 4 times of our earlier calculations. However, during discussion on Xen-devel Jan Beulich suggested that just in case we should use 1 MiB memory pool like it was in original place_string() implementation. So, let's use 1 MiB as it was proposed.

s/If we think that we should not/To not/

Quoted 5 lines

If we think that we should not waste unallocated memory in the pool on running system then we can mark this region as __initdata and move all required data to dynamically allocated places somewhere in __start_xen().

Now solution #2 is implemented but maybe we should consider #1 one day.

s/Now ../This patch implements #2 solution./

Quoted 2 lines

adjustments mentioned.

Quoted 16 lines
---
 xen/arch/x86/efi/efi-boot.h |   38 ++++++++++++++++++++++++++++++--------
 xen/arch/x86/setup.c        |    3 +--
 2 files changed, 31 insertions(+), 10 deletions(-)
xen/arch/x86/efi/efi-boot.h +3 -0
index 2dd69f6..3d25c48 100644
@@ -103,9 +103,36 @@ static void __init relocate_trampoline(unsigned long phys)
         *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4;
 }
 
+#define EBMALLOC_SIZE	MB(1)
+
+static char __initdata ebmalloc_mem[EBMALLOC_SIZE];

xen/arch/x86/efi/efi-boot.h static void __init relocate_trampoline(unsigned long phys) · line 118

Quoted 10 lines
xen/arch/x86/efi/efi-boot.h +10 -0
+static char __initdata *ebmalloc_free = NULL;
+
+/* EFI boot allocator. */
+static void __init *ebmalloc(size_t size)
+{
+    void *ptr;
+
+    /*
+     * Init ebmalloc_free on runtime. Static initialization
+     * will not work because it puts virtual address there.

And why is that bad?

Quoted 66 lines
xen/arch/x86/efi/efi-boot.h +17 -8
+     */
+    if ( ebmalloc_free == NULL )
+        ebmalloc_free = ebmalloc_mem;
+
+    ptr = ebmalloc_free;
+
+    ebmalloc_free += size;
+
+    if ( ebmalloc_free - ebmalloc_mem > sizeof(ebmalloc_mem) )
+        blexit(L"Out of static memory\r\n");
+
+    return ptr;
+}
+
 static void __init place_string(u32 *addr, const char *s)
 {
-    static char *__initdata alloc = start;
+    char *alloc = NULL;
 
     if ( s && *s )
     {
@@ -113,7 +140,7 @@ static void __init place_string(u32 *addr, const char *s)
         const char *old = (char *)(long)*addr;
         size_t len2 = *addr ? strlen(old) + 1 : 0;
 
-        alloc -= len1 + len2;
+        alloc = ebmalloc(len1 + len2);
         /*
          * Insert new string before already existing one. This is needed
          * for options passed on the command line to override options from
@@ -196,12 +223,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,
 
 static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
 {
-    place_string(&mbi.mem_upper, NULL);
-    mbi.mem_upper -= map_size;
-    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
-    if ( mbi.mem_upper < xen_phys_start )
-        return NULL;
-    return (void *)(long)mbi.mem_upper;
+    return ebmalloc(map_size);
 }
 
 static void __init efi_arch_pre_exit_boot(void)
xen/arch/x86/setup.c +1 -2
index bce708c..a59fc4e 100644
@@ -994,8 +994,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( !xen_phys_start )
         panic("Not enough memory to relocate Xen.");
-    reserve_e820_ram(&boot_e820, efi_enabled(EFI_PLATFORM) ? mbi->mem_upper : __pa(&_start),
-                     __pa(&_end));
+    reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#124 lore raw

Re: [PATCH v2 19/23] x86/efi: create new early memory allocator

In reply to Daniel Kiper
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

There is a problem with place_string() which is used as early memory allocator. It gets memory chunks starting from start symbol and going down. Sadly this does not work when Xen is loaded using multiboot2 protocol because start lives on 1 MiB address. So, I tried to use mem_lower address calculated by GRUB2. However, it works only on some machines. There are machines in the wild (e.g. Dell PowerEdge R820) which uses first ~640 KiB for boot services code or data... :-(((

In case of multiboot2 protocol we need that place_string() only allocate memory chunk for EFI memory map. However, I think that it should be fixed instead of making another function used just in one case. I thought about two solutions.

Quoted 6 lines

1) We could use native EFI allocation functions (e.g. AllocatePool() or AllocatePages()) to get memory chunk. However, later (somewhere in __start_xen()) we must copy its contents to safe place or reserve this in e820 memory map and map it in Xen virtual address space. In later case we must also care about conflicts with e.g. crash kernel regions which could be quite difficult.

1b) Do away with efi_arch_allocate_mmap_buffer() and use AllocatePages() uniformly, perhaps with a per-arch specified memory type (by means of which you can control whether the memory contents will remain preserved until the time you want to look at it). That will eliminate the only place_string() you're concerned about, with a patch with better diffstat (largely due to the questionable arch hook gone).

Jan

#125 lore raw

Re: [PATCH v2 19/23] x86/efi: create new early memory allocator

In reply to Daniel Kiper
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 20.07.15 at 16:29, <[email protected]> wrote:

There is a problem with place_string() which is used as early memory allocator. It gets memory chunks starting from start symbol and going down. Sadly this does not work when Xen is loaded using multiboot2 protocol because start lives on 1 MiB address. So, I tried to use mem_lower address calculated by GRUB2. However, it works only on some machines. There are machines in the wild (e.g. Dell PowerEdge R820) which uses first ~640 KiB for boot services code or data... :-(((

In case of multiboot2 protocol we need that place_string() only allocate memory chunk for EFI memory map. However, I think that it should be fixed instead of making another function used just in one case. I thought about two solutions.

Quoted 6 lines

1) We could use native EFI allocation functions (e.g. AllocatePool() or AllocatePages()) to get memory chunk. However, later (somewhere in __start_xen()) we must copy its contents to safe place or reserve this in e820 memory map and map it in Xen virtual address space. In later case we must also care about conflicts with e.g. crash kernel regions which could be quite difficult.

1b) Do away with efi_arch_allocate_mmap_buffer() and use AllocatePages() uniformly, perhaps with a per-arch specified memory type (by means of which you can control whether the memory contents will remain preserved until the time you want to look at it). That will eliminate the only place_string() you're concerned about, with a patch with better diffstat (largely due to the questionable arch hook gone).

Jan

#126 lore raw

PATCH v2 20/23 x86: add multiboot2 protocol support for EFI platforms

In reply to Daniel Kiper

---
v2 - suggestions/fixes:
- generate multiboot2 header using macros
(suggested by Jan Beulich),
- switch CPU to x86_32 mode before
jumping to 32-bit code
(suggested by Andrew Cooper),
- reduce code changes to increase patch readability (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- ignore MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag on EFI platform and find on my own multiboot2.mem_lower value,
- stop execution if EFI platform is detected
in legacy BIOS path.

---
 xen/arch/x86/boot/head.S          |  157 +++++++++++++++++++++++++++++++++++--
 xen/arch/x86/efi/efi-boot.h       |   30 +++++++
 xen/arch/x86/efi/stub.c           |    5 ++
 xen/arch/x86/setup.c              |   10 ++-
 xen/arch/x86/x86_64/asm-offsets.c |    2 +
 xen/arch/x86/xen.lds.S            |    4 +-
 xen/common/efi/boot.c             |   12 +++
 xen/include/xen/efi.h             |    1 +
 8 files changed, 210 insertions(+), 11 deletions(-)
xen/arch/x86/boot/head.S +151 -6
index 57197db..056047f 100644
@@ -89,6 +89,13 @@ multiboot1_header_end:
                    0, /* Number of the lines - no preference. */ \
                    0  /* Number of bits per pixel - no preference. */
 
+        /* Do not disable EFI boot services. */
+        mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL)
+
+        /* EFI64 entry point. */
+        mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \
+                   sym_phys(__efi64_start)
+
         /* Multiboot2 header end tag. */
         mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
 .Lmultiboot2_header_end:
@@ -100,9 +107,15 @@ multiboot1_header_end:
 gdt_boot_descr:
         .word   6*8-1
         .long   sym_phys(trampoline_gdt)
+        .long   0 /* Needed for 64-bit lgdt */
+
+cs32_switch_addr:
+        .long   sym_phys(cs32_switch)
+        .word   BOOT_CS32
 
 .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"
 .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!"
+.Lbad_mb2_ldr: .asciz "ERR: Use latest Multiboot2 compatible bootloader!"
 
         .section .init.text, "ax", @progbits
 
@@ -111,6 +124,9 @@ bad_cpu:
         jmp     print_err
 not_multiboot:
         mov     $(sym_phys(.Lbad_ldr_msg)),%esi # Error message
+        jmp     print_err
+mb2_too_old:
+        mov     $(sym_phys(.Lbad_mb2_ldr)),%esi # Error message
 print_err:
         mov     $0xB8000,%edi  # VGA framebuffer
 1:      mov     (%esi),%bl
@@ -130,6 +146,119 @@ print_err:
 .Lhalt: hlt
         jmp     .Lhalt
 
+        .code64
+
+__efi64_start:
+        cld
+
+        /* Check for Multiboot2 bootloader. */
+        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
+        je      efi_multiboot2_proto
+
+        /* Jump to not_multiboot after switching CPU to x86_32 mode. */
+        lea     not_multiboot(%rip),%rdi
+        jmp     x86_32_switch
+
+efi_multiboot2_proto:
+        /*
+         * Multiboot2 information address is 32-bit,
+         * so, zero higher half of %rbx.
+         */
+        mov     %ebx,%ebx
+
+        /* Skip Multiboot2 information fixed part. */
+        lea     MB2_fixed_sizeof(%rbx),%rcx
+
+0:
+        /* Get EFI SystemTable address from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx)
+        jne     1f
+
+        mov     MB2_efi64_st(%rcx),%rsi
+
+        /* Do not go into real mode on EFI platform. */
+        movb    $1,skip_realmode(%rip)
+        jmp     3f
+
+1:
+        /* Get EFI ImageHandle address from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx)
+        jne     2f
+
+        mov     MB2_efi64_ih(%rcx),%rdi
+        jmp     3f
+
+2:
+        /* Is it the end of Multiboot2 information? */
+        cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx)
+        je      run_bs
+
+3:
+        /* Go to next Multiboot2 information tag. */
+        add     MB2_tag_size(%rcx),%ecx
+        add     $(MULTIBOOT2_TAG_ALIGN-1),%rcx
+        and     $~(MULTIBOOT2_TAG_ALIGN-1),%rcx
+        jmp     0b
+
+run_bs:
+        push    %rax
+        push    %rdi
+
+        /* Initialize BSS (no nasty surprises!). */
+        lea     __bss_start(%rip),%rdi
+        lea     __bss_end(%rip),%rcx
+        sub     %rdi,%rcx
+        shr     $3,%rcx
+        xor     %eax,%eax
+        rep     stosq
+
+        pop     %rdi
+
+        /*
+         * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable.
+         * OUT: %rax - multiboot2.mem_lower. Do not get this value from
+         * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag. It could be bogus on
+         * EFI platforms.
+         */
+        call    efi_multiboot2
+
+        /* Convert multiboot2.mem_lower to bytes/16. */
+        mov     %rax,%rcx
+        shr     $4,%rcx
+
+        pop     %rax
+
+        /* Jump to trampoline_setup after switching CPU to x86_32 mode. */
+        lea     trampoline_setup(%rip),%rdi
+
+x86_32_switch:
+        cli
+
+        /* Initialise GDT. */
+        lgdt    gdt_boot_descr(%rip)
+
+        /* Reload code selector. */
+        ljmpl   *cs32_switch_addr(%rip)
+
+        .code32
+
+cs32_switch:
+        /* Initialise basic data segments. */
+        mov     $BOOT_DS,%edx
+        mov     %edx,%ds
+        mov     %edx,%es
+        mov     %edx,%fs
+        mov     %edx,%gs
+        mov     %edx,%ss
+
+        /* Disable paging. */
+        mov     %cr0,%edx
+        and     $(~X86_CR0_PG),%edx
+        mov     %edx,%cr0
+
+        /* Jump to earlier loaded address. */
+        jmp     *%edi
+
 __start:
         cld
         cli
@@ -157,7 +286,7 @@ __start:
 
         /* Not available? BDA value will be fine. */
         cmovnz  MB_mem_lower(%ebx),%edx
-        jmp     trampoline_setup
+        jmp     trampoline_bios_setup
 
 multiboot2_proto:
         /* Skip Multiboot2 information fixed part. */
@@ -169,12 +298,19 @@ multiboot2_proto:
         jne     1f
 
         mov     MB2_mem_lower(%ecx),%edx
-        jmp     trampoline_setup
+        jmp     trampoline_bios_setup
 
 1:
+        /* EFI mode is not supported via legacy BIOS path. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx)
+        je      mb2_too_old
+
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx)
+        je      mb2_too_old
+
         /* Is it the end of Multiboot2 information? */
         cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx)
-        je      trampoline_setup
+        je      trampoline_bios_setup
 
         /* Go to next Multiboot2 information tag. */
         add     MB2_tag_size(%ecx),%ecx
@@ -182,7 +318,7 @@ multiboot2_proto:
         and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
         jmp     0b
 
-trampoline_setup:
+trampoline_bios_setup:
         /* Set up trampoline segment 64k below EBDA */
         movzwl  0x40e,%ecx          /* EBDA segment */
         cmp     $0xa000,%ecx        /* sanity check (high) */
@@ -198,12 +334,13 @@ trampoline_setup:
          * multiboot structure (if available) and use the smallest.
          */
         cmp     $0x100,%edx         /* is the multiboot value too small? */
-        jb      2f                  /* if so, do not use it */
+        jb      trampoline_setup    /* if so, do not use it */
         shl     $10-4,%edx
         cmp     %ecx,%edx           /* compare with BDA value */
         cmovb   %edx,%ecx           /* and use the smaller */
 
-2:      /* Reserve 64kb for the trampoline */
+trampoline_setup:
+        /* Reserve 64kb for the trampoline. */
         sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
@@ -220,6 +357,13 @@ trampoline_setup:
         add     $12,%esp            /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
 
+        /*
+         * Do not zero BSS on EFI platform here.
+         * It was initialized earlier.
+         */
+        cmpb    $1,sym_phys(skip_realmode)
+        je      1f
+
         /* Initialize BSS (no nasty surprises!). */
         mov     $sym_phys(__bss_start),%edi
         mov     $sym_phys(__bss_end),%ecx
@@ -228,6 +372,7 @@ trampoline_setup:
         xor     %eax,%eax
         rep     stosl
 
+1:
         /* Interrogate CPU extended features via CPUID. */
         mov     $0x80000000,%eax
         cpuid
xen/arch/x86/efi/efi-boot.h +30 -0
index 3d25c48..1b25a2d 100644
@@ -228,6 +228,9 @@ static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
 
 static void __init efi_arch_pre_exit_boot(void)
 {
+    if ( !efi_enabled(EFI_LOADER) )
+        return;
+
     if ( !trampoline_phys )
     {
         if ( !cfg.addr )
@@ -662,6 +665,33 @@ static bool_t __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
     return 1; /* x86 always uses a config file */
 }
 
+paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    UINTN cols, gop_mode = ~0, rows;
+
+    set_bit(EFI_PLATFORM, &efi.flags);
+
+    efi_init(ImageHandle, SystemTable);
+
+    efi_console_set_mode();
+
+    if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
+                           &cols, &rows) == EFI_SUCCESS )
+        efi_arch_console_init(cols, rows);
+
+    gop = efi_get_gop();
+    gop_mode = efi_find_gop_mode(gop, 0, 0, 0);
+    efi_arch_edd();
+    efi_tables();
+    setup_efi_pci();
+    efi_variables();
+    efi_set_gop_mode(gop, gop_mode);
+    efi_exit_boot(ImageHandle, SystemTable);
+
+    return cfg.addr;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/efi/stub.c +5 -0
index c5ae369..d30fe89 100644
@@ -13,6 +13,11 @@ struct efi __read_mostly efi = {
 	.smbios3 = EFI_INVALID_TABLE_ADDR
 };
 
+void __init efi_multiboot2(void)
+{
+    /* TODO: Fail if entered! */
+}
+
 void __init efi_init_memory(void) { }
 
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
xen/arch/x86/setup.c +7 -3
index a59fc4e..8bec67f 100644
@@ -695,7 +695,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
         panic("dom0 kernel not specified. Check bootloader configuration.");
 
-    if ( efi_enabled(EFI_PLATFORM) )
+    if ( efi_enabled(EFI_LOADER) )
     {
         set_pdx_range(xen_phys_start >> PAGE_SHIFT,
                       (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
@@ -708,7 +708,11 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
             l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
 
-        memmap_type = loader;
+        memmap_type = "EFI";
+    }
+    else if ( efi_enabled(EFI_PLATFORM) )
+    {
+        memmap_type = "EFI";
     }
     else if ( e820_raw_nr != 0 )
     {
@@ -806,7 +810,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * we can relocate the dom0 kernel and other multiboot modules. Also, on
      * x86/64, we relocate Xen to higher memory.
      */
-    for ( i = 0; !efi_enabled(EFI_PLATFORM) && i < mbi->mods_count; i++ )
+    for ( i = 0; !efi_enabled(EFI_LOADER) && i < mbi->mods_count; i++ )
     {
         if ( mod[i].mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request.");
xen/arch/x86/x86_64/asm-offsets.c +2 -0
index b926082..b7aed49 100644
@@ -173,4 +173,6 @@ void __dummy__(void)
     OFFSET(MB2_tag_type, multiboot2_tag_t, type);
     OFFSET(MB2_tag_size, multiboot2_tag_t, size);
     OFFSET(MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);
+    OFFSET(MB2_efi64_st, multiboot2_tag_efi64_t, pointer);
+    OFFSET(MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer);
 }
xen/arch/x86/xen.lds.S +2 -2
index 87f3e83..a399615 100644
@@ -162,7 +162,7 @@ SECTIONS
   . = ALIGN(STACK_SIZE);
   __init_end = .;
 
-  . = ALIGN(4);
+  . = ALIGN(8);
   .bss : {                     /* BSS */
        __bss_start = .;
        *(.bss.stack_aligned)
@@ -176,7 +176,7 @@ SECTIONS
        *(.bss.percpu.read_mostly)
        . = ALIGN(SMP_CACHE_BYTES);
        __per_cpu_data_end = .;
-       . = ALIGN(4);
+       . = ALIGN(8);
        __bss_end = .;
   } :text
   _end = . ;
xen/common/efi/boot.c +12 -0
index bf2f198..5a02e71 100644
@@ -79,6 +79,17 @@ static size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
 static bool_t match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2);
 
+static void efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
+static void efi_console_set_mode(void);
+static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop(void);
+static UINTN efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
+                               UINTN cols, UINTN rows, UINTN depth);
+static void efi_tables(void);
+static void setup_efi_pci(void);
+static void efi_variables(void);
+static void efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop_mode);
+static void efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
+
 static const EFI_BOOT_SERVICES *__initdata efi_bs;
 static UINT32 __initdata efi_bs_revision;
 static EFI_HANDLE __initdata efi_ih;
@@ -960,6 +971,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
 #ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
     set_bit(EFI_PLATFORM, &efi.flags);
+    set_bit(EFI_LOADER, &efi.flags);
 #endif
 
     efi_init(ImageHandle, SystemTable);
xen/include/xen/efi.h +1 -0
index 318bbec..6b952df 100644
@@ -9,6 +9,7 @@
 #define EFI_INVALID_TABLE_ADDR (~0UL)
 
 #define EFI_PLATFORM	0
+#define EFI_LOADER	1
 
 /* Add fields here only if they need to be referenced from non-EFI code. */
 struct efi {
Signature · 1 line
1.7.10.4
Reviewed-by on v2 20/23
#127 lore raw

Re: [Xen-devel] [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms

Quoted 32 lines · Daniel Kiper

---
v2 - suggestions/fixes:
- generate multiboot2 header using macros
(suggested by Jan Beulich),
- switch CPU to x86_32 mode before
jumping to 32-bit code
(suggested by Andrew Cooper),
- reduce code changes to increase patch readability (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- ignore MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag on EFI platform and find on my own multiboot2.mem_lower value,
- stop execution if EFI platform is detected
in legacy BIOS path.

---
 xen/arch/x86/boot/head.S          |  157 +++++++++++++++++++++++++++++++++++--
 xen/arch/x86/efi/efi-boot.h       |   30 +++++++
 xen/arch/x86/efi/stub.c           |    5 ++
 xen/arch/x86/setup.c              |   10 ++-
 xen/arch/x86/x86_64/asm-offsets.c |    2 +
 xen/arch/x86/xen.lds.S            |    4 +-
 xen/common/efi/boot.c             |   12 +++
 xen/include/xen/efi.h             |    1 +
 8 files changed, 210 insertions(+), 11 deletions(-)
xen/arch/x86/boot/head.S +0 -0
index 57197db..056047f 100644

xen/arch/x86/boot/head.S multiboot1_header_end: · line 92

Quoted 4 lines
xen/arch/x86/boot/head.S +1 -0
@@ -89,6 +89,13 @@ multiboot1_header_end:
                    0, /* Number of the lines - no preference. */ \
                    0  /* Number of bits per pixel - no preference. */
 
+        /* Do not disable EFI boot services. */

s/disable/exit/ ?

Or perhaps:

/* Inhibit GRUB2 from calling ExitBootServices. */

?

Quoted 12 lines
xen/arch/x86/boot/head.S +6 -0
+        mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL)
+
+        /* EFI64 entry point. */
+        mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \
+                   sym_phys(__efi64_start)
+
         /* Multiboot2 header end tag. */
         mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
 .Lmultiboot2_header_end:
@@ -100,9 +107,15 @@ multiboot1_header_end:
 gdt_boot_descr:
         .word   6*8-1

xen/arch/x86/boot/head.S multiboot1_header_end: · line 118

Quoted 10 lines
xen/arch/x86/boot/head.S +6 -0
         .long   sym_phys(trampoline_gdt)
+        .long   0 /* Needed for 64-bit lgdt */
+
+cs32_switch_addr:
+        .long   sym_phys(cs32_switch)
+        .word   BOOT_CS32
 
 .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"
 .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!"
+.Lbad_mb2_ldr: .asciz "ERR: Use latest Multiboot2 compatible bootloader!"

Multiboot2+EFI compatible..?

Quoted 29 lines
xen/arch/x86/boot/head.S +15 -0
         .section .init.text, "ax", @progbits
 
@@ -111,6 +124,9 @@ bad_cpu:
         jmp     print_err
 not_multiboot:
         mov     $(sym_phys(.Lbad_ldr_msg)),%esi # Error message
+        jmp     print_err
+mb2_too_old:
+        mov     $(sym_phys(.Lbad_mb2_ldr)),%esi # Error message
 print_err:
         mov     $0xB8000,%edi  # VGA framebuffer
 1:      mov     (%esi),%bl
@@ -130,6 +146,119 @@ print_err:
 .Lhalt: hlt
         jmp     .Lhalt
 
+        .code64
+
+__efi64_start:
+        cld
+
+        /* Check for Multiboot2 bootloader. */
+        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
+        je      efi_multiboot2_proto
+
+        /* Jump to not_multiboot after switching CPU to x86_32 mode. */
+        lea     not_multiboot(%rip),%rdi
+        jmp     x86_32_switch

xen/arch/x86/boot/head.S print_err: · line 170

Quoted 10 lines
xen/arch/x86/boot/head.S +10 -0
+
+efi_multiboot2_proto:
+        /*
+         * Multiboot2 information address is 32-bit,
+         * so, zero higher half of %rbx.
+         */
+        mov     %ebx,%ebx
+
+        /* Skip Multiboot2 information fixed part. */
+        lea     MB2_fixed_sizeof(%rbx),%rcx

Don't want to check that the address is aligned properly?

xen/arch/x86/boot/head.S print_err: · line 179

Quoted 9 lines
xen/arch/x86/boot/head.S +9 -0
+
+0:
+        /* Get EFI SystemTable address from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx)
+        jne     1f
+
+        mov     MB2_efi64_st(%rcx),%rsi
+
+        /* Do not go into real mode on EFI platform. */

Add please:

/* And also inhibit clearing of BSS later on. */

Quoted 216 lines
xen/arch/x86/boot/head.S +104 -6
+        movb    $1,skip_realmode(%rip)
+        jmp     3f
+
+1:
+        /* Get EFI ImageHandle address from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx)
+        jne     2f
+
+        mov     MB2_efi64_ih(%rcx),%rdi
+        jmp     3f
+
+2:
+        /* Is it the end of Multiboot2 information? */
+        cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx)
+        je      run_bs
+
+3:
+        /* Go to next Multiboot2 information tag. */
+        add     MB2_tag_size(%rcx),%ecx
+        add     $(MULTIBOOT2_TAG_ALIGN-1),%rcx
+        and     $~(MULTIBOOT2_TAG_ALIGN-1),%rcx
+        jmp     0b
+
+run_bs:
+        push    %rax
+        push    %rdi
+
+        /* Initialize BSS (no nasty surprises!). */
+        lea     __bss_start(%rip),%rdi
+        lea     __bss_end(%rip),%rcx
+        sub     %rdi,%rcx
+        shr     $3,%rcx
+        xor     %eax,%eax
+        rep     stosq
+
+        pop     %rdi
+
+        /*
+         * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable.
+         * OUT: %rax - multiboot2.mem_lower. Do not get this value from
+         * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag. It could be bogus on
+         * EFI platforms.
+         */
+        call    efi_multiboot2
+
+        /* Convert multiboot2.mem_lower to bytes/16. */
+        mov     %rax,%rcx
+        shr     $4,%rcx
+
+        pop     %rax
+
+        /* Jump to trampoline_setup after switching CPU to x86_32 mode. */
+        lea     trampoline_setup(%rip),%rdi
+
+x86_32_switch:
+        cli
+
+        /* Initialise GDT. */
+        lgdt    gdt_boot_descr(%rip)
+
+        /* Reload code selector. */
+        ljmpl   *cs32_switch_addr(%rip)
+
+        .code32
+
+cs32_switch:
+        /* Initialise basic data segments. */
+        mov     $BOOT_DS,%edx
+        mov     %edx,%ds
+        mov     %edx,%es
+        mov     %edx,%fs
+        mov     %edx,%gs
+        mov     %edx,%ss
+
+        /* Disable paging. */
+        mov     %cr0,%edx
+        and     $(~X86_CR0_PG),%edx
+        mov     %edx,%cr0
+
+        /* Jump to earlier loaded address. */
+        jmp     *%edi
+
 __start:
         cld
         cli
@@ -157,7 +286,7 @@ __start:
 
         /* Not available? BDA value will be fine. */
         cmovnz  MB_mem_lower(%ebx),%edx
-        jmp     trampoline_setup
+        jmp     trampoline_bios_setup
 
 multiboot2_proto:
         /* Skip Multiboot2 information fixed part. */
@@ -169,12 +298,19 @@ multiboot2_proto:
         jne     1f
 
         mov     MB2_mem_lower(%ecx),%edx
-        jmp     trampoline_setup
+        jmp     trampoline_bios_setup
 
 1:
+        /* EFI mode is not supported via legacy BIOS path. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx)
+        je      mb2_too_old
+
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx)
+        je      mb2_too_old
+
         /* Is it the end of Multiboot2 information? */
         cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx)
-        je      trampoline_setup
+        je      trampoline_bios_setup
 
         /* Go to next Multiboot2 information tag. */
         add     MB2_tag_size(%ecx),%ecx
@@ -182,7 +318,7 @@ multiboot2_proto:
         and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
         jmp     0b
 
-trampoline_setup:
+trampoline_bios_setup:
         /* Set up trampoline segment 64k below EBDA */
         movzwl  0x40e,%ecx          /* EBDA segment */
         cmp     $0xa000,%ecx        /* sanity check (high) */
@@ -198,12 +334,13 @@ trampoline_setup:
          * multiboot structure (if available) and use the smallest.
          */
         cmp     $0x100,%edx         /* is the multiboot value too small? */
-        jb      2f                  /* if so, do not use it */
+        jb      trampoline_setup    /* if so, do not use it */
         shl     $10-4,%edx
         cmp     %ecx,%edx           /* compare with BDA value */
         cmovb   %edx,%ecx           /* and use the smaller */
 
-2:      /* Reserve 64kb for the trampoline */
+trampoline_setup:
+        /* Reserve 64kb for the trampoline. */
         sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
@@ -220,6 +357,13 @@ trampoline_setup:
         add     $12,%esp            /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
 
+        /*
+         * Do not zero BSS on EFI platform here.
+         * It was initialized earlier.
+         */
+        cmpb    $1,sym_phys(skip_realmode)
+        je      1f
+
         /* Initialize BSS (no nasty surprises!). */
         mov     $sym_phys(__bss_start),%edi
         mov     $sym_phys(__bss_end),%ecx
@@ -228,6 +372,7 @@ trampoline_setup:
         xor     %eax,%eax
         rep     stosl
 
+1:
         /* Interrogate CPU extended features via CPUID. */
         mov     $0x80000000,%eax
         cpuid
xen/arch/x86/efi/efi-boot.h +30 -0
index 3d25c48..1b25a2d 100644
@@ -228,6 +228,9 @@ static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
 
 static void __init efi_arch_pre_exit_boot(void)
 {
+    if ( !efi_enabled(EFI_LOADER) )
+        return;
+
     if ( !trampoline_phys )
     {
         if ( !cfg.addr )
@@ -662,6 +665,33 @@ static bool_t __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
     return 1; /* x86 always uses a config file */
 }
 
+paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    UINTN cols, gop_mode = ~0, rows;
+
+    set_bit(EFI_PLATFORM, &efi.flags);
+
+    efi_init(ImageHandle, SystemTable);
+
+    efi_console_set_mode();
+
+    if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
+                           &cols, &rows) == EFI_SUCCESS )
+        efi_arch_console_init(cols, rows);
+
+    gop = efi_get_gop();
+    gop_mode = efi_find_gop_mode(gop, 0, 0, 0);
+    efi_arch_edd();
+    efi_tables();
+    setup_efi_pci();
+    efi_variables();
+    efi_set_gop_mode(gop, gop_mode);
+    efi_exit_boot(ImageHandle, SystemTable);
+
+    return cfg.addr;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/efi/stub.c +0 -0
index c5ae369..d30fe89 100644

xen/arch/x86/efi/stub.c struct efi __read_mostly efi = { · line 18

Quoted 6 lines
xen/arch/x86/efi/stub.c +3 -0
@@ -13,6 +13,11 @@ struct efi __read_mostly efi = {
 	.smbios3 = EFI_INVALID_TABLE_ADDR
 };
 
+void __init efi_multiboot2(void)
+{
+    /* TODO: Fail if entered! */

Heheh. Could we add the 'ud2' instruction here?

Quoted 65 lines
xen/arch/x86/efi/stub.c +2 -0
+}
+
 void __init efi_init_memory(void) { }
 
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
xen/arch/x86/setup.c +7 -3
index a59fc4e..8bec67f 100644
@@ -695,7 +695,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
         panic("dom0 kernel not specified. Check bootloader configuration.");
 
-    if ( efi_enabled(EFI_PLATFORM) )
+    if ( efi_enabled(EFI_LOADER) )
     {
         set_pdx_range(xen_phys_start >> PAGE_SHIFT,
                       (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
@@ -708,7 +708,11 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
             l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
 
-        memmap_type = loader;
+        memmap_type = "EFI";
+    }
+    else if ( efi_enabled(EFI_PLATFORM) )
+    {
+        memmap_type = "EFI";
     }
     else if ( e820_raw_nr != 0 )
     {
@@ -806,7 +810,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * we can relocate the dom0 kernel and other multiboot modules. Also, on
      * x86/64, we relocate Xen to higher memory.
      */
-    for ( i = 0; !efi_enabled(EFI_PLATFORM) && i < mbi->mods_count; i++ )
+    for ( i = 0; !efi_enabled(EFI_LOADER) && i < mbi->mods_count; i++ )
     {
         if ( mod[i].mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request.");
xen/arch/x86/x86_64/asm-offsets.c +2 -0
index b926082..b7aed49 100644
@@ -173,4 +173,6 @@ void __dummy__(void)
     OFFSET(MB2_tag_type, multiboot2_tag_t, type);
     OFFSET(MB2_tag_size, multiboot2_tag_t, size);
     OFFSET(MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);
+    OFFSET(MB2_efi64_st, multiboot2_tag_efi64_t, pointer);
+    OFFSET(MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer);
 }
xen/arch/x86/xen.lds.S +1 -1
index 87f3e83..a399615 100644
@@ -162,7 +162,7 @@ SECTIONS
   . = ALIGN(STACK_SIZE);
   __init_end = .;
 
-  . = ALIGN(4);
+  . = ALIGN(8);
   .bss : {                     /* BSS */
        __bss_start = .;
        *(.bss.stack_aligned)

xen/arch/x86/xen.lds.S SECTIONS · line 179

Quoted 5 lines
xen/arch/x86/xen.lds.S +1 -1
@@ -176,7 +176,7 @@ SECTIONS
        *(.bss.percpu.read_mostly)
        . = ALIGN(SMP_CACHE_BYTES);
        __per_cpu_data_end = .;
-       . = ALIGN(4);
+       . = ALIGN(8);

This aligment check I presume is due to 'rep stosq'?

As such could you add a comment here please?

Quoted 38 lines
xen/arch/x86/xen.lds.S +0 -0
        __bss_end = .;
   } :text
   _end = . ;
xen/common/efi/boot.c +12 -0
index bf2f198..5a02e71 100644
@@ -79,6 +79,17 @@ static size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
 static bool_t match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2);
 
+static void efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
+static void efi_console_set_mode(void);
+static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop(void);
+static UINTN efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
+                               UINTN cols, UINTN rows, UINTN depth);
+static void efi_tables(void);
+static void setup_efi_pci(void);
+static void efi_variables(void);
+static void efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop_mode);
+static void efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
+
 static const EFI_BOOT_SERVICES *__initdata efi_bs;
 static UINT32 __initdata efi_bs_revision;
 static EFI_HANDLE __initdata efi_ih;
@@ -960,6 +971,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
 #ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
     set_bit(EFI_PLATFORM, &efi.flags);
+    set_bit(EFI_LOADER, &efi.flags);
 #endif
 
     efi_init(ImageHandle, SystemTable);
xen/include/xen/efi.h +0 -0
index 318bbec..6b952df 100644

xen/include/xen/efi.h line 15

Quoted 7 lines
xen/include/xen/efi.h +1 -0
@@ -9,6 +9,7 @@
 #define EFI_INVALID_TABLE_ADDR (~0UL)
 
 #define EFI_PLATFORM	0
+#define EFI_LOADER	1
 
 /* Add fields here only if they need to be referenced from non-EFI code. */
 struct efi {

With the changes above:

Quoted 8 lines
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 20/23
#128 lore raw

Re: [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms

In reply to Daniel Kiper
Quoted 32 lines · Daniel Kiper

---
v2 - suggestions/fixes:
- generate multiboot2 header using macros
(suggested by Jan Beulich),
- switch CPU to x86_32 mode before
jumping to 32-bit code
(suggested by Andrew Cooper),
- reduce code changes to increase patch readability (suggested by Jan Beulich),
- improve comments
(suggested by Jan Beulich),
- ignore MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag on EFI platform and find on my own multiboot2.mem_lower value,
- stop execution if EFI platform is detected
in legacy BIOS path.

---
 xen/arch/x86/boot/head.S          |  157 +++++++++++++++++++++++++++++++++++--
 xen/arch/x86/efi/efi-boot.h       |   30 +++++++
 xen/arch/x86/efi/stub.c           |    5 ++
 xen/arch/x86/setup.c              |   10 ++-
 xen/arch/x86/x86_64/asm-offsets.c |    2 +
 xen/arch/x86/xen.lds.S            |    4 +-
 xen/common/efi/boot.c             |   12 +++
 xen/include/xen/efi.h             |    1 +
 8 files changed, 210 insertions(+), 11 deletions(-)
xen/arch/x86/boot/head.S +0 -0
index 57197db..056047f 100644

xen/arch/x86/boot/head.S multiboot1_header_end: · line 92

Quoted 4 lines
xen/arch/x86/boot/head.S +1 -0
@@ -89,6 +89,13 @@ multiboot1_header_end:
                    0, /* Number of the lines - no preference. */ \
                    0  /* Number of bits per pixel - no preference. */
 
+        /* Do not disable EFI boot services. */

s/disable/exit/ ?

Or perhaps:

/* Inhibit GRUB2 from calling ExitBootServices. */

?

Quoted 12 lines
xen/arch/x86/boot/head.S +6 -0
+        mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL)
+
+        /* EFI64 entry point. */
+        mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \
+                   sym_phys(__efi64_start)
+
         /* Multiboot2 header end tag. */
         mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
 .Lmultiboot2_header_end:
@@ -100,9 +107,15 @@ multiboot1_header_end:
 gdt_boot_descr:
         .word   6*8-1

xen/arch/x86/boot/head.S multiboot1_header_end: · line 118

Quoted 10 lines
xen/arch/x86/boot/head.S +6 -0
         .long   sym_phys(trampoline_gdt)
+        .long   0 /* Needed for 64-bit lgdt */
+
+cs32_switch_addr:
+        .long   sym_phys(cs32_switch)
+        .word   BOOT_CS32
 
 .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"
 .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!"
+.Lbad_mb2_ldr: .asciz "ERR: Use latest Multiboot2 compatible bootloader!"

Multiboot2+EFI compatible..?

Quoted 29 lines
xen/arch/x86/boot/head.S +15 -0
         .section .init.text, "ax", @progbits
 
@@ -111,6 +124,9 @@ bad_cpu:
         jmp     print_err
 not_multiboot:
         mov     $(sym_phys(.Lbad_ldr_msg)),%esi # Error message
+        jmp     print_err
+mb2_too_old:
+        mov     $(sym_phys(.Lbad_mb2_ldr)),%esi # Error message
 print_err:
         mov     $0xB8000,%edi  # VGA framebuffer
 1:      mov     (%esi),%bl
@@ -130,6 +146,119 @@ print_err:
 .Lhalt: hlt
         jmp     .Lhalt
 
+        .code64
+
+__efi64_start:
+        cld
+
+        /* Check for Multiboot2 bootloader. */
+        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
+        je      efi_multiboot2_proto
+
+        /* Jump to not_multiboot after switching CPU to x86_32 mode. */
+        lea     not_multiboot(%rip),%rdi
+        jmp     x86_32_switch

xen/arch/x86/boot/head.S print_err: · line 170

Quoted 10 lines
xen/arch/x86/boot/head.S +10 -0
+
+efi_multiboot2_proto:
+        /*
+         * Multiboot2 information address is 32-bit,
+         * so, zero higher half of %rbx.
+         */
+        mov     %ebx,%ebx
+
+        /* Skip Multiboot2 information fixed part. */
+        lea     MB2_fixed_sizeof(%rbx),%rcx

Don't want to check that the address is aligned properly?

xen/arch/x86/boot/head.S print_err: · line 179

Quoted 9 lines
xen/arch/x86/boot/head.S +9 -0
+
+0:
+        /* Get EFI SystemTable address from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx)
+        jne     1f
+
+        mov     MB2_efi64_st(%rcx),%rsi
+
+        /* Do not go into real mode on EFI platform. */

Add please:

/* And also inhibit clearing of BSS later on. */

Quoted 216 lines
xen/arch/x86/boot/head.S +104 -6
+        movb    $1,skip_realmode(%rip)
+        jmp     3f
+
+1:
+        /* Get EFI ImageHandle address from Multiboot2 information. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx)
+        jne     2f
+
+        mov     MB2_efi64_ih(%rcx),%rdi
+        jmp     3f
+
+2:
+        /* Is it the end of Multiboot2 information? */
+        cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx)
+        je      run_bs
+
+3:
+        /* Go to next Multiboot2 information tag. */
+        add     MB2_tag_size(%rcx),%ecx
+        add     $(MULTIBOOT2_TAG_ALIGN-1),%rcx
+        and     $~(MULTIBOOT2_TAG_ALIGN-1),%rcx
+        jmp     0b
+
+run_bs:
+        push    %rax
+        push    %rdi
+
+        /* Initialize BSS (no nasty surprises!). */
+        lea     __bss_start(%rip),%rdi
+        lea     __bss_end(%rip),%rcx
+        sub     %rdi,%rcx
+        shr     $3,%rcx
+        xor     %eax,%eax
+        rep     stosq
+
+        pop     %rdi
+
+        /*
+         * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable.
+         * OUT: %rax - multiboot2.mem_lower. Do not get this value from
+         * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag. It could be bogus on
+         * EFI platforms.
+         */
+        call    efi_multiboot2
+
+        /* Convert multiboot2.mem_lower to bytes/16. */
+        mov     %rax,%rcx
+        shr     $4,%rcx
+
+        pop     %rax
+
+        /* Jump to trampoline_setup after switching CPU to x86_32 mode. */
+        lea     trampoline_setup(%rip),%rdi
+
+x86_32_switch:
+        cli
+
+        /* Initialise GDT. */
+        lgdt    gdt_boot_descr(%rip)
+
+        /* Reload code selector. */
+        ljmpl   *cs32_switch_addr(%rip)
+
+        .code32
+
+cs32_switch:
+        /* Initialise basic data segments. */
+        mov     $BOOT_DS,%edx
+        mov     %edx,%ds
+        mov     %edx,%es
+        mov     %edx,%fs
+        mov     %edx,%gs
+        mov     %edx,%ss
+
+        /* Disable paging. */
+        mov     %cr0,%edx
+        and     $(~X86_CR0_PG),%edx
+        mov     %edx,%cr0
+
+        /* Jump to earlier loaded address. */
+        jmp     *%edi
+
 __start:
         cld
         cli
@@ -157,7 +286,7 @@ __start:
 
         /* Not available? BDA value will be fine. */
         cmovnz  MB_mem_lower(%ebx),%edx
-        jmp     trampoline_setup
+        jmp     trampoline_bios_setup
 
 multiboot2_proto:
         /* Skip Multiboot2 information fixed part. */
@@ -169,12 +298,19 @@ multiboot2_proto:
         jne     1f
 
         mov     MB2_mem_lower(%ecx),%edx
-        jmp     trampoline_setup
+        jmp     trampoline_bios_setup
 
 1:
+        /* EFI mode is not supported via legacy BIOS path. */
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx)
+        je      mb2_too_old
+
+        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx)
+        je      mb2_too_old
+
         /* Is it the end of Multiboot2 information? */
         cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx)
-        je      trampoline_setup
+        je      trampoline_bios_setup
 
         /* Go to next Multiboot2 information tag. */
         add     MB2_tag_size(%ecx),%ecx
@@ -182,7 +318,7 @@ multiboot2_proto:
         and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
         jmp     0b
 
-trampoline_setup:
+trampoline_bios_setup:
         /* Set up trampoline segment 64k below EBDA */
         movzwl  0x40e,%ecx          /* EBDA segment */
         cmp     $0xa000,%ecx        /* sanity check (high) */
@@ -198,12 +334,13 @@ trampoline_setup:
          * multiboot structure (if available) and use the smallest.
          */
         cmp     $0x100,%edx         /* is the multiboot value too small? */
-        jb      2f                  /* if so, do not use it */
+        jb      trampoline_setup    /* if so, do not use it */
         shl     $10-4,%edx
         cmp     %ecx,%edx           /* compare with BDA value */
         cmovb   %edx,%ecx           /* and use the smaller */
 
-2:      /* Reserve 64kb for the trampoline */
+trampoline_setup:
+        /* Reserve 64kb for the trampoline. */
         sub     $0x1000,%ecx
 
         /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
@@ -220,6 +357,13 @@ trampoline_setup:
         add     $12,%esp            /* Remove reloc() args from stack. */
         mov     %eax,sym_phys(multiboot_ptr)
 
+        /*
+         * Do not zero BSS on EFI platform here.
+         * It was initialized earlier.
+         */
+        cmpb    $1,sym_phys(skip_realmode)
+        je      1f
+
         /* Initialize BSS (no nasty surprises!). */
         mov     $sym_phys(__bss_start),%edi
         mov     $sym_phys(__bss_end),%ecx
@@ -228,6 +372,7 @@ trampoline_setup:
         xor     %eax,%eax
         rep     stosl
 
+1:
         /* Interrogate CPU extended features via CPUID. */
         mov     $0x80000000,%eax
         cpuid
xen/arch/x86/efi/efi-boot.h +30 -0
index 3d25c48..1b25a2d 100644
@@ -228,6 +228,9 @@ static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
 
 static void __init efi_arch_pre_exit_boot(void)
 {
+    if ( !efi_enabled(EFI_LOADER) )
+        return;
+
     if ( !trampoline_phys )
     {
         if ( !cfg.addr )
@@ -662,6 +665,33 @@ static bool_t __init efi_arch_use_config_file(EFI_SYSTEM_TABLE *SystemTable)
     return 1; /* x86 always uses a config file */
 }
 
+paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
+    UINTN cols, gop_mode = ~0, rows;
+
+    set_bit(EFI_PLATFORM, &efi.flags);
+
+    efi_init(ImageHandle, SystemTable);
+
+    efi_console_set_mode();
+
+    if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
+                           &cols, &rows) == EFI_SUCCESS )
+        efi_arch_console_init(cols, rows);
+
+    gop = efi_get_gop();
+    gop_mode = efi_find_gop_mode(gop, 0, 0, 0);
+    efi_arch_edd();
+    efi_tables();
+    setup_efi_pci();
+    efi_variables();
+    efi_set_gop_mode(gop, gop_mode);
+    efi_exit_boot(ImageHandle, SystemTable);
+
+    return cfg.addr;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/efi/stub.c +0 -0
index c5ae369..d30fe89 100644

xen/arch/x86/efi/stub.c struct efi __read_mostly efi = { · line 18

Quoted 6 lines
xen/arch/x86/efi/stub.c +3 -0
@@ -13,6 +13,11 @@ struct efi __read_mostly efi = {
 	.smbios3 = EFI_INVALID_TABLE_ADDR
 };
 
+void __init efi_multiboot2(void)
+{
+    /* TODO: Fail if entered! */

Heheh. Could we add the 'ud2' instruction here?

Quoted 65 lines
xen/arch/x86/efi/stub.c +2 -0
+}
+
 void __init efi_init_memory(void) { }
 
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
xen/arch/x86/setup.c +7 -3
index a59fc4e..8bec67f 100644
@@ -695,7 +695,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
         panic("dom0 kernel not specified. Check bootloader configuration.");
 
-    if ( efi_enabled(EFI_PLATFORM) )
+    if ( efi_enabled(EFI_LOADER) )
     {
         set_pdx_range(xen_phys_start >> PAGE_SHIFT,
                       (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
@@ -708,7 +708,11 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
             l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
 
-        memmap_type = loader;
+        memmap_type = "EFI";
+    }
+    else if ( efi_enabled(EFI_PLATFORM) )
+    {
+        memmap_type = "EFI";
     }
     else if ( e820_raw_nr != 0 )
     {
@@ -806,7 +810,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * we can relocate the dom0 kernel and other multiboot modules. Also, on
      * x86/64, we relocate Xen to higher memory.
      */
-    for ( i = 0; !efi_enabled(EFI_PLATFORM) && i < mbi->mods_count; i++ )
+    for ( i = 0; !efi_enabled(EFI_LOADER) && i < mbi->mods_count; i++ )
     {
         if ( mod[i].mod_start & (PAGE_SIZE - 1) )
             panic("Bootloader didn't honor module alignment request.");
xen/arch/x86/x86_64/asm-offsets.c +2 -0
index b926082..b7aed49 100644
@@ -173,4 +173,6 @@ void __dummy__(void)
     OFFSET(MB2_tag_type, multiboot2_tag_t, type);
     OFFSET(MB2_tag_size, multiboot2_tag_t, size);
     OFFSET(MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);
+    OFFSET(MB2_efi64_st, multiboot2_tag_efi64_t, pointer);
+    OFFSET(MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer);
 }
xen/arch/x86/xen.lds.S +1 -1
index 87f3e83..a399615 100644
@@ -162,7 +162,7 @@ SECTIONS
   . = ALIGN(STACK_SIZE);
   __init_end = .;
 
-  . = ALIGN(4);
+  . = ALIGN(8);
   .bss : {                     /* BSS */
        __bss_start = .;
        *(.bss.stack_aligned)

xen/arch/x86/xen.lds.S SECTIONS · line 179

Quoted 5 lines
xen/arch/x86/xen.lds.S +1 -1
@@ -176,7 +176,7 @@ SECTIONS
        *(.bss.percpu.read_mostly)
        . = ALIGN(SMP_CACHE_BYTES);
        __per_cpu_data_end = .;
-       . = ALIGN(4);
+       . = ALIGN(8);

This aligment check I presume is due to 'rep stosq'?

As such could you add a comment here please?

Quoted 38 lines
xen/arch/x86/xen.lds.S +0 -0
        __bss_end = .;
   } :text
   _end = . ;
xen/common/efi/boot.c +12 -0
index bf2f198..5a02e71 100644
@@ -79,6 +79,17 @@ static size_t wstrlen(const CHAR16 * s);
 static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
 static bool_t match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2);
 
+static void efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
+static void efi_console_set_mode(void);
+static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop(void);
+static UINTN efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
+                               UINTN cols, UINTN rows, UINTN depth);
+static void efi_tables(void);
+static void setup_efi_pci(void);
+static void efi_variables(void);
+static void efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop_mode);
+static void efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
+
 static const EFI_BOOT_SERVICES *__initdata efi_bs;
 static UINT32 __initdata efi_bs_revision;
 static EFI_HANDLE __initdata efi_ih;
@@ -960,6 +971,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
 #ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
     set_bit(EFI_PLATFORM, &efi.flags);
+    set_bit(EFI_LOADER, &efi.flags);
 #endif
 
     efi_init(ImageHandle, SystemTable);
xen/include/xen/efi.h +0 -0
index 318bbec..6b952df 100644

xen/include/xen/efi.h line 15

Quoted 7 lines
xen/include/xen/efi.h +1 -0
@@ -9,6 +9,7 @@
 #define EFI_INVALID_TABLE_ADDR (~0UL)
 
 #define EFI_PLATFORM	0
+#define EFI_LOADER	1
 
 /* Add fields here only if they need to be referenced from non-EFI code. */
 struct efi {

With the changes above:

Quoted 8 lines
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#129 lore raw

Re: [PATCH v2 20/23] x86: add multiboot2 protocol support for EFI platforms

In reply to Daniel Kiper

xen/arch/x86/boot/head.S print_err: · line 213

Quoted 11 lines
xen/arch/x86/boot/head.S +11 -0
+run_bs:
+        push    %rax
+        push    %rdi
+
+        /* Initialize BSS (no nasty surprises!). */
+        lea     __bss_start(%rip),%rdi
+        lea     __bss_end(%rip),%rcx
+        sub     %rdi,%rcx
+        shr     $3,%rcx
+        xor     %eax,%eax
+        rep     stosq

This means we are using the %es segment. The multiboot1 is pretty clear that it should cover up to 4GB.

Would it be worth adding a comment about that?

xen/arch/x86/boot/head.S print_err: · line 223

Quoted 10 lines
xen/arch/x86/boot/head.S +10 -0
+
+        pop     %rdi
+
+        /*
+         * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable.
+         * OUT: %rax - multiboot2.mem_lower. Do not get this value from
+         * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag. It could be bogus on
+         * EFI platforms.
+         */
+        call    efi_multiboot2

However the function prototype for efi_multiboot2 is 'void', not 'int' - so it would not return anything!

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+        /* Convert multiboot2.mem_lower to bytes/16. */

Should we check to make sure it is valid? With those weird machines you seem to have run into I am not actually sure what a valid value is :-(

.. snip..

xen/arch/x86/efi/stub.c struct efi __read_mostly efi = { · line 16

Quoted 9 lines
xen/arch/x86/efi/stub.c +1 -0
index c5ae369..d30fe89 100644
@@ -13,6 +13,11 @@ struct efi __read_mostly efi = {
 	.smbios3 = EFI_INVALID_TABLE_ADDR
 };
 
+void __init efi_multiboot2(void)

unsigned int __init ..

xen/arch/x86/efi/stub.c struct efi __read_mostly efi = { · line 18

Quoted 2 lines
xen/arch/x86/efi/stub.c +2 -0
+{
+    /* TODO: Fail if entered! */

And maybe just 'return 0'; ?

Quoted 1 line
xen/arch/x86/efi/stub.c +1 -0
+}