Re: [Xen-devel] [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms
On Thu, Sep 01, 2016 at 01:40:11AM -0600, Jan Beulich wrote: > >>> On 31.08.16 at 19:07,wrote: > > On Wed, Aug 31, 2016 at 06:49:51AM -0600, Jan Beulich wrote: > >> >>> On 30.08.16 at 21:32, wrote: > >> > On Thu, Aug 25, 2016 at 06:59:54AM -0600, Jan Beulich wrote: > >> >> >>> On 20.08.16 at 00:43, wrote: > >> >> > --- a/xen/arch/x86/efi/stub.c > >> >> > +++ b/xen/arch/x86/efi/stub.c > >> >> > @@ -3,6 +3,30 @@ > >> >> > #include > >> >> > #include > >> >> > #include > >> >> > +#include > >> >> > +#include > >> >> > +#include > >> >> > +#include > >> >> > +#include > >> >> > +#include > >> >> > + > >> >> > +paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, > >> >> > EFI_SYSTEM_TABLE *SystemTable) > >> >> > +{ > >> >> > +CHAR16 *err = L"Xen does not have EFI code build in!!!\r\nSystem > >> >> > halted!!!\r\n"; > >> >> > +SIMPLE_TEXT_OUTPUT_INTERFACE *StdErr; > >> >> > + > >> >> > +StdErr = SystemTable->StdErr ? SystemTable->StdErr : > >> >> > SystemTable->ConOut; > >> >> > + > >> >> > +/* Print error message and halt the system. */ > >> >> > +asm volatile( > >> >> > +"call %2 \n" > >> >> > +"0: hlt \n" > >> >> > +"jmp 0b \n" > >> >> > + : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString) > >> >> > + : "rax", "r8", "r9", "r10", "r11", "cc", "memory"); > >> >> > >> >> There are explanations missing here: First, a warning should be added > >> >> alongside the EFI header inclusions, making clear that no services > >> >> whatsoever can be called. And then the asm() here needs to explain > >> > > >> > I am not convinced but if you wish... > >> > >> Not convinced of what? > > > > About "... a warning should be added alongside the EFI header inclusions, > > making clear that no services whatsoever can be called". AIUI, "warning" == > > "comment" here. However, I think that everybody who reads this file is > > aware that "no services whatsoever can be called". So, I am not sure > > where is the point. > > Odd - you do an EFI call here (in the asm()) and talk about reader's > awareness? I do this in quite strange way just to display clear error from file called stub.c which contains just mostly function stubs. So, I have a feeling that sane reader will be conscious here and will not expect code which does sensible stuff. However, if you still think that these are insufficient then I can add warninng/comment which assures potential reader that this is a stub file and most functions does nothing except efi_multiboot2(). > >> >> need for an explicit "cc" clobber on x86. > >> > > >> > Why? > >> > >> Because such a clobber gets added to every asm() by the compiler, > >> unless it uses the (new in gcc 6) flag output. I've actually suggested > >> to upstream a patch making it possible to avoid that automatic > >> addition, but there hadn't been a whole lot of useful feedback. > > > > So, when somebody uses this new flag then "cc" will not be add here. > > This is not big deal but I think that extra "cc" clobbers does not > > hurt too. > > It surely doesn't hurt, but it makes code bigger and hence results in > it taking longer to be read and parsed (for all of these - even if just > slightly). I'm sorry, but I'm opposed to adding unnecessary stuff. As you wish... Daniel ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms
>>> On 31.08.16 at 19:07,wrote: > On Wed, Aug 31, 2016 at 06:49:51AM -0600, Jan Beulich wrote: >> >>> On 30.08.16 at 21:32, wrote: >> > On Thu, Aug 25, 2016 at 06:59:54AM -0600, Jan Beulich wrote: >> >> >>> On 20.08.16 at 00:43, wrote: >> >> > --- a/xen/arch/x86/efi/stub.c >> >> > +++ b/xen/arch/x86/efi/stub.c >> >> > @@ -3,6 +3,30 @@ >> >> > #include >> >> > #include >> >> > #include >> >> > +#include >> >> > +#include >> >> > +#include >> >> > +#include >> >> > +#include >> >> > +#include >> >> > + >> >> > +paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, >> >> > EFI_SYSTEM_TABLE *SystemTable) >> >> > +{ >> >> > +CHAR16 *err = L"Xen does not have EFI code build in!!!\r\nSystem >> >> > halted!!!\r\n"; >> >> > +SIMPLE_TEXT_OUTPUT_INTERFACE *StdErr; >> >> > + >> >> > +StdErr = SystemTable->StdErr ? SystemTable->StdErr : >> >> > SystemTable->ConOut; >> >> > + >> >> > +/* Print error message and halt the system. */ >> >> > +asm volatile( >> >> > +"call %2 \n" >> >> > +"0: hlt \n" >> >> > +"jmp 0b \n" >> >> > + : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString) >> >> > + : "rax", "r8", "r9", "r10", "r11", "cc", "memory"); >> >> >> >> There are explanations missing here: First, a warning should be added >> >> alongside the EFI header inclusions, making clear that no services >> >> whatsoever can be called. And then the asm() here needs to explain >> > >> > I am not convinced but if you wish... >> >> Not convinced of what? > > About "... a warning should be added alongside the EFI header inclusions, > making clear that no services whatsoever can be called". AIUI, "warning" == > "comment" here. However, I think that everybody who reads this file is > aware that "no services whatsoever can be called". So, I am not sure > where is the point. Odd - you do an EFI call here (in the asm()) and talk about reader's awareness? >> >> need for an explicit "cc" clobber on x86. >> > >> > Why? >> >> Because such a clobber gets added to every asm() by the compiler, >> unless it uses the (new in gcc 6) flag output. I've actually suggested >> to upstream a patch making it possible to avoid that automatic >> addition, but there hadn't been a whole lot of useful feedback. > > So, when somebody uses this new flag then "cc" will not be add here. > This is not big deal but I think that extra "cc" clobbers does not > hurt too. It surely doesn't hurt, but it makes code bigger and hence results in it taking longer to be read and parsed (for all of these - even if just slightly). I'm sorry, but I'm opposed to adding unnecessary stuff. Jan ___ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms
On Wed, Aug 31, 2016 at 06:49:51AM -0600, Jan Beulich wrote: > >>> On 30.08.16 at 21:32,wrote: > > On Thu, Aug 25, 2016 at 06:59:54AM -0600, Jan Beulich wrote: > >> >>> On 20.08.16 at 00:43, wrote: [...] > >> > +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_BOOT, _flags); > >> > +__set_bit(EFI_RS, _flags); > >> > + > >> > +efi_init(ImageHandle, SystemTable); > >> > + > >> > +efi_console_set_mode(); > >> > + > >> > +if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode, > >> > + , ) == EFI_SUCCESS ) > >> > +efi_arch_console_init(cols, rows); > >> > + > >> > +gop = efi_get_gop(); > >> > + > >> > +if ( gop ) > >> > +gop_mode = efi_find_gop_mode(gop, 0, 0, 0); > >> > + > >> > +efi_arch_edd(); > >> > +efi_arch_cpu(); > >> > + > >> > +efi_tables(); > >> > +setup_efi_pci(); > >> > +efi_variables(); > >> > + > >> > +if ( gop ) > >> > +efi_set_gop_mode(gop, gop_mode); > >> > + > >> > +efi_exit_boot(ImageHandle, SystemTable); > >> > + > >> > +/* Return highest available memory address below 1 MiB. */ > >> > +return cfg.addr; > >> > >> Where is it being made certain that there are 64k of space available > >> right below this address, as is being assumed at trampoline_setup? > > > > You are right. This is a bug. However, the problem is more generic > > and should be fixed for all boot cases (BIOS, EFI loader and EFI with > > GRUB2). Additionally, in case of BIOS and EFI with GRUB2 we should > > check that it is possible to put all data from grub loader in low > > memory. So, it looks that there is a place for at least two (three?) > > additional patches. Do you want them at the beginning of or the end > > of this patch series. > > If you think there are bugs in pre-existing code, then for having the > option of backporting putting such patches at the beginning would > be desirable. That said, I'm not convinced there are problems really > in need of fixing here (yet the grub environment is different and > hence will need taking care of even if we leave the other code paths > as they are now). I think that we should no blindly assume that a given amount of memory is available. However, we do that in a few places including this one which you pointed out. So, it should be fixed. Though, the question is: Is it possible? Right now I am not sure that it is true in all cases mentioned above. There is a chance that in case pointed out by you it is. Anyway, I will check it. > >> > --- a/xen/arch/x86/efi/stub.c > >> > +++ b/xen/arch/x86/efi/stub.c > >> > @@ -3,6 +3,30 @@ > >> > #include > >> > #include > >> > #include > >> > +#include > >> > +#include > >> > +#include > >> > +#include > >> > +#include > >> > +#include > >> > + > >> > +paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, > >> > EFI_SYSTEM_TABLE *SystemTable) > >> > +{ > >> > +CHAR16 *err = L"Xen does not have EFI code build in!!!\r\nSystem > >> > halted!!!\r\n"; > >> > +SIMPLE_TEXT_OUTPUT_INTERFACE *StdErr; > >> > + > >> > +StdErr = SystemTable->StdErr ? SystemTable->StdErr : > >> > SystemTable->ConOut; > >> > + > >> > +/* Print error message and halt the system. */ > >> > +asm volatile( > >> > +"call %2 \n" > >> > +"0: hlt \n" > >> > +"jmp 0b \n" > >> > + : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString) > >> > + : "rax", "r8", "r9", "r10", "r11", "cc", "memory"); > >> > >> There are explanations missing here: First, a warning should be added > >> alongside the EFI header inclusions, making clear that no services > >> whatsoever can be called. And then the asm() here needs to explain > > > > I am not convinced but if you wish... > > Not convinced of what? About "... a warning should be added alongside the EFI header inclusions, making clear that no services whatsoever can be called". AIUI, "warning" == "comment" here. However, I think that everybody who reads this file is aware that "no services whatsoever can be called". So, I am not sure where is the point. [...] > >> need for an explicit "cc" clobber on x86. > > > > Why? > > Because such a clobber gets added to every asm() by the compiler, > unless it uses the (new in gcc 6) flag output. I've actually suggested > to upstream a patch making it possible to avoid that automatic > addition, but there hadn't been a whole lot of useful feedback. So, when somebody uses this new flag then "cc" will not be add here. This is not big deal but I think that extra "cc" clobbers does not hurt too. Daniel ___ Xen-devel mailing list Xen-devel@lists.xen.org
Re: [Xen-devel] [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms
>>> On 30.08.16 at 21:32,wrote: > On Thu, Aug 25, 2016 at 06:59:54AM -0600, Jan Beulich wrote: >> >>> On 20.08.16 at 00:43, wrote: >> > @@ -223,14 +425,22 @@ trampoline_setup: >> > callreloc >> > mov %eax,sym_phys(multiboot_ptr) >> > >> > -/* Initialize BSS (no nasty surprises!) */ >> > +/* >> > + * Do not zero BSS on EFI platform here. >> > + * It was initialized earlier. >> > + */ >> > +cmpb$0,sym_phys(skip_realmode) >> > +jnz 1f >> > + >> > +/* Initialize BSS (no nasty surprises!). */ >> > mov $sym_phys(__bss_start),%edi >> > mov $sym_phys(__bss_end),%ecx >> > sub %edi,%ecx >> > -xor %eax,%eax >> > shr $2,%ecx >> > +xor %eax,%eax >> > rep stosl >> >> Please avoid pointless code movement like this. > > I think that shr should be close to sub because both operations are related > to some extent. However, you are right that maybe this cleanup should be in > separate patch. Does it make sense for you? Separating dependent instructions by other unrelated ones can actually improve performance. I agree that performance isn't of much relevance here, but I think I still wouldn't agree to a change like this even if submitted separately. >> > +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_BOOT, _flags); >> > +__set_bit(EFI_RS, _flags); >> > + >> > +efi_init(ImageHandle, SystemTable); >> > + >> > +efi_console_set_mode(); >> > + >> > +if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode, >> > + , ) == EFI_SUCCESS ) >> > +efi_arch_console_init(cols, rows); >> > + >> > +gop = efi_get_gop(); >> > + >> > +if ( gop ) >> > +gop_mode = efi_find_gop_mode(gop, 0, 0, 0); >> > + >> > +efi_arch_edd(); >> > +efi_arch_cpu(); >> > + >> > +efi_tables(); >> > +setup_efi_pci(); >> > +efi_variables(); >> > + >> > +if ( gop ) >> > +efi_set_gop_mode(gop, gop_mode); >> > + >> > +efi_exit_boot(ImageHandle, SystemTable); >> > + >> > +/* Return highest available memory address below 1 MiB. */ >> > +return cfg.addr; >> >> Where is it being made certain that there are 64k of space available >> right below this address, as is being assumed at trampoline_setup? > > You are right. This is a bug. However, the problem is more generic > and should be fixed for all boot cases (BIOS, EFI loader and EFI with > GRUB2). Additionally, in case of BIOS and EFI with GRUB2 we should > check that it is possible to put all data from grub loader in low > memory. So, it looks that there is a place for at least two (three?) > additional patches. Do you want them at the beginning of or the end > of this patch series. If you think there are bugs in pre-existing code, then for having the option of backporting putting such patches at the beginning would be desirable. That said, I'm not convinced there are problems really in need of fixing here (yet the grub environment is different and hence will need taking care of even if we leave the other code paths as they are now). >> > --- a/xen/arch/x86/efi/stub.c >> > +++ b/xen/arch/x86/efi/stub.c >> > @@ -3,6 +3,30 @@ >> > #include >> > #include >> > #include >> > +#include >> > +#include >> > +#include >> > +#include >> > +#include >> > +#include >> > + >> > +paddr_t __init noreturn efi_multiboot2(EFI_HANDLE ImageHandle, >> > EFI_SYSTEM_TABLE *SystemTable) >> > +{ >> > +CHAR16 *err = L"Xen does not have EFI code build in!!!\r\nSystem >> > halted!!!\r\n"; >> > +SIMPLE_TEXT_OUTPUT_INTERFACE *StdErr; >> > + >> > +StdErr = SystemTable->StdErr ? SystemTable->StdErr : >> > SystemTable->ConOut; >> > + >> > +/* Print error message and halt the system. */ >> > +asm volatile( >> > +"call %2 \n" >> > +"0: hlt \n" >> > +"jmp 0b \n" >> > + : "+c" (StdErr), "+d" (err) : "g" (StdErr->OutputString) >> > + : "rax", "r8", "r9", "r10", "r11", "cc", "memory"); >> >> There are explanations missing here: First, a warning should be added >> alongside the EFI header inclusions, making clear that no services >> whatsoever can be called. And then the asm() here needs to explain > > I am not convinced but if you wish... Not convinced of what? >> that it open codes an MS-ABI function call. Which then makes me > > OK. > >> wonder (even if it doesn't matter much) - are the clobbers actually >> correct? I think you also need to clobber rsi and rdi. Otoh there's no > > Nope, MS-ABI says that %rsi and %rdi must be saved and restored by > function which uses them. So, we do not need list both registers >
Re: [Xen-devel] [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms
On Thu, Aug 25, 2016 at 06:59:54AM -0600, Jan Beulich wrote: > >>> On 20.08.16 at 00:43,wrote: > > @@ -100,19 +107,45 @@ multiboot2_header_start: > > 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 > > + > > +vga_text_buffer: > > +.long 0xb8000 > > This now ends up being misaligned. Not a big deal, but anyway. > > > .section .init.text, "ax", @progbits I hope that ".align 4" is sufficient here. > > bad_cpu: > > mov $(sym_phys(.Lbad_cpu_msg)),%esi # Error message > > -jmp print_err > > +jmp 0f > > not_multiboot: > > mov $(sym_phys(.Lbad_ldr_msg)),%esi # Error message > > -print_err: > > -mov $0xB8000,%edi # VGA framebuffer > > +jmp 0f > > +mb2_no_st: > > +mov $(sym_phys(.Lbad_ldr_nst)),%esi # Error message > > +jmp 0f > > +mb2_no_ih: > > +mov $(sym_phys(.Lbad_ldr_nih)),%esi # Error message > > +jmp 0f > > +mb2_no_bs: > > +mov $(sym_phys(.Lbad_ldr_nbs)),%esi # Error message > > +xor %edi,%edi # No VGA text buffer > > +jmp 1f > > +mb2_efi_ia_32: > > +mov $(sym_phys(.Lbad_efi_msg)),%esi # Error message > > +xor %edi,%edi # No VGA text buffer > > +jmp 1f > > +0: mov sym_phys(vga_text_buffer),%edi > > 1: mov (%esi),%bl > > All the labels you add should imo be .L ones. And the two numeric > labels, considering their use across other label boundaries, would > perhaps better become .L ones too. OK. > > +__efi64_start: > > +cld > > + > > +/* VGA is not available on EFI platforms. */ > > +movl $0,vga_text_buffer(%rip) > > + > > +/* Check for Multiboot2 bootloader. */ > > +cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax > > +je .Lefi_multiboot2_proto > > + > > +/* Jump to not_multiboot after switching CPU to x86_32 mode. */ > > +lea not_multiboot(%rip),%edi > > +jmp x86_32_switch > > Does the boot loader, btw, make any guarantees towards placing > the image below 4G? Yep. [...] > > +/* > > + * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable. > > + * OUT: %rax - Highest available memory address below 1 MiB. > > Please be more precise, as "available" leaves open how much space > is actually available there, and hence what this can be used for. Also > according to ... > > > + * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag is not provided > > + * on EFI platforms. Hence, it could not be used like > > + * on legacy BIOS platforms. > > + */ > > +callefi_multiboot2 > > + > > +/* Convert memory address to bytes/16 and store it in safe place. > > */ > > +shr $4,%eax > > +mov %eax,%ecx > > ... the output really is in %eax. efi_multiboot2() is called according to System V AMD64 ABI. So, according to it return value is stored in %rax. Hence, from spec point of view comment is correct. Use of %eax is a bit different thing (our need/choice) and if you wish it can be documented accordingly. > > @@ -223,14 +425,22 @@ trampoline_setup: > > callreloc > > mov %eax,sym_phys(multiboot_ptr) > > > > -/* Initialize BSS (no nasty surprises!) */ > > +/* > > + * Do not zero BSS on EFI platform here. > > + * It was initialized earlier. > > + */ > > +cmpb$0,sym_phys(skip_realmode) > > +jnz 1f > > + > > +/* Initialize BSS (no nasty surprises!). */ > > mov $sym_phys(__bss_start),%edi > > mov $sym_phys(__bss_end),%ecx > > sub %edi,%ecx > > -xor %eax,%eax > > shr $2,%ecx > > +xor %eax,%eax > > rep stosl > > Please avoid pointless code movement like this. I think that shr should be close to sub because both operations are related to some extent. However, you are right that maybe this cleanup should be in separate patch. Does it make sense for you? > > +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_BOOT, _flags); > > +__set_bit(EFI_RS, _flags); > > + > > +efi_init(ImageHandle, SystemTable); > > + > > +efi_console_set_mode(); > > + > > +if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode, > > + , ) == EFI_SUCCESS ) > > +efi_arch_console_init(cols, rows); > > + > > +gop = efi_get_gop(); > > + > > +if ( gop ) > > +gop_mode = efi_find_gop_mode(gop, 0, 0, 0); > > + > > +
Re: [Xen-devel] [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms
>>> On 20.08.16 at 00:43,wrote: > @@ -100,19 +107,45 @@ multiboot2_header_start: > 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 > + > +vga_text_buffer: > +.long 0xb8000 This now ends up being misaligned. Not a big deal, but anyway. > .section .init.text, "ax", @progbits > > bad_cpu: > mov $(sym_phys(.Lbad_cpu_msg)),%esi # Error message > -jmp print_err > +jmp 0f > not_multiboot: > mov $(sym_phys(.Lbad_ldr_msg)),%esi # Error message > -print_err: > -mov $0xB8000,%edi # VGA framebuffer > +jmp 0f > +mb2_no_st: > +mov $(sym_phys(.Lbad_ldr_nst)),%esi # Error message > +jmp 0f > +mb2_no_ih: > +mov $(sym_phys(.Lbad_ldr_nih)),%esi # Error message > +jmp 0f > +mb2_no_bs: > +mov $(sym_phys(.Lbad_ldr_nbs)),%esi # Error message > +xor %edi,%edi # No VGA text buffer > +jmp 1f > +mb2_efi_ia_32: > +mov $(sym_phys(.Lbad_efi_msg)),%esi # Error message > +xor %edi,%edi # No VGA text buffer > +jmp 1f > +0: mov sym_phys(vga_text_buffer),%edi > 1: mov (%esi),%bl All the labels you add should imo be .L ones. And the two numeric labels, considering their use across other label boundaries, would perhaps better become .L ones too. > +__efi64_start: > +cld > + > +/* VGA is not available on EFI platforms. */ > +movl $0,vga_text_buffer(%rip) > + > +/* Check for Multiboot2 bootloader. */ > +cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax > +je .Lefi_multiboot2_proto > + > +/* Jump to not_multiboot after switching CPU to x86_32 mode. */ > +lea not_multiboot(%rip),%edi > +jmp x86_32_switch Does the boot loader, btw, make any guarantees towards placing the image below 4G? > +.Lefi_multiboot2_proto: > +/* Zero EFI SystemTable and EFI ImageHandle addresses. */ > +xor %esi,%esi > +xor %edi,%edi > + > +/* Skip Multiboot2 information fixed part. */ > +lea (MB2_fixed_sizeof+MULTIBOOT2_TAG_ALIGN-1)(%ebx),%ecx As indicated before - please use %rbx here; there's no need for having a pointless address size prefix. > +and $~(MULTIBOOT2_TAG_ALIGN-1),%ecx > + > +0: > +/* Check Multiboot2 information total size. */ > +mov %ecx,%r8d > +sub %ebx,%r8d > +cmp %r8d,MB2_fixed_total_size(%rbx) > +jbe run_bs > + > +/* Are EFI boot services available? */ > +cmpl$MULTIBOOT2_TAG_TYPE_EFI_BS,MB2_tag_type(%rcx) > +jne 1f > + > +/* Yes, skip real mode and do not do other unneeded things. */ > +incbskip_realmode(%rip) > +jmp 9f I think this comment need extending: Why again is not skipping real mode fine if there's no such tag, no matter that we got called in 64-bit mode here? Actually, looking further down, wasn't it that you simply abuse that label (you jump to an error label below when it is still zero)? That needs to be said here if so, for someone reading the code in order to understand that there's no actual use of real mode anywhere on this path. > +/* > + * Initialize BSS (no nasty surprises!). > + * It must be done earlier than in BIOS case > + * because efi_multiboot2() touches it. > + */ > +lea __bss_start(%rip),%edi > +lea __bss_end(%rip),%ecx In assembly code please use .startof.(.bss) and .sizeof.(.bss), as being propose for other uses by https://lists.xenproject.org/archives/html/xen-devel/2016-08/msg02718.html > +/* > + * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable. > + * OUT: %rax - Highest available memory address below 1 MiB. Please be more precise, as "available" leaves open how much space is actually available there, and hence what this can be used for. Also according to ... > + * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag is not provided > + * on EFI platforms. Hence, it could not be used like > + * on legacy BIOS platforms. > + */ > +callefi_multiboot2 > + > +/* Convert memory address to bytes/16 and store it in safe place. */ > +shr $4,%eax > +mov %eax,%ecx ... the output really is in %eax. > @@ -223,14 +425,22 @@ trampoline_setup: > callreloc > mov %eax,sym_phys(multiboot_ptr) > > -/* Initialize BSS (no nasty surprises!) */ > +/* > + * Do not zero BSS on EFI platform here. > + * It was initialized earlier. > + */ > +cmpb
[Xen-devel] [PATCH v5 13/16] x86: add multiboot2 protocol support for EFI platforms
This way Xen can be loaded on EFI platforms using GRUB2 and other boot loaders which support multiboot2 protocol. Signed-off-by: Daniel Kiper--- v4 - suggestions/fixes: - remove redundant BSS alignment, - update BSS alignment check, - use __set_bit() instead of set_bit() if possible (suggested by Jan Beulich), - call efi_arch_cpu() from efi_multiboot2() even if the same work is done later in other place right now (suggested by Jan Beulich), - xen/arch/x86/efi/stub.c:efi_multiboot2() fail properly on EFI platforms, - do not read data beyond the end of multiboot2 information in xen/arch/x86/boot/head.S (suggested by Jan Beulich), - use 32-bit registers in x86_64 code if possible (suggested by Jan Beulich), - multiboot2 information address is 64-bit in x86_64 code, so, treat it is as is (suggested by Jan Beulich), - use cmovcc if possible, - leave only one space between rep and stosq (suggested by Jan Beulich), - improve error handling, - improve early error messages, (suggested by Jan Beulich), - improve early error messages printing code, - improve label names (suggested by Jan Beulich), - improve comments (suggested by Jan Beulich), - various minor cleanups. v3 - suggestions/fixes: - take into account alignment when skipping multiboot2 fixed part (suggested by Konrad Rzeszutek Wilk), - improve segment registers initialization (suggested by Jan Beulich), - improve comments (suggested by Jan Beulich and Konrad Rzeszutek Wilk), - improve commit message (suggested by Jan Beulich). 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 | 243 ++--- xen/arch/x86/efi/efi-boot.h | 49 +++- xen/arch/x86/efi/stub.c | 24 xen/arch/x86/x86_64/asm-offsets.c |2 + xen/arch/x86/xen.lds.S|4 +- xen/common/efi/boot.c | 11 ++ 6 files changed, 312 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index 5e61854..aca5370 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -89,6 +89,13 @@ multiboot2_header_start: 0, /* Number of the lines - no preference. */ \ 0 /* Number of bits per pixel - no preference. */ +/* Inhibit bootloader from calling ExitBootServices(). */ +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,19 +107,45 @@ multiboot2_header_start: 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 + +vga_text_buffer: +.long 0xb8000 .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!" .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!" +.Lbad_ldr_nbs: .asciz "ERR: Bootloader shutdown EFI x64 boot services!" +.Lbad_ldr_nst: .asciz "ERR: EFI SystemTable is not provided by bootloader!" +.Lbad_ldr_nih: .asciz "ERR: EFI ImageHandle is not provided by bootloader!" +.Lbad_efi_msg: .asciz "ERR: EFI IA-32 platforms are not supported!" .section .init.text, "ax", @progbits bad_cpu: mov $(sym_phys(.Lbad_cpu_msg)),%esi # Error message -jmp print_err +jmp 0f not_multiboot: mov $(sym_phys(.Lbad_ldr_msg)),%esi # Error message -print_err: -mov $0xB8000,%edi # VGA framebuffer +jmp 0f +mb2_no_st: +mov $(sym_phys(.Lbad_ldr_nst)),%esi # Error message +jmp 0f +mb2_no_ih: +mov $(sym_phys(.Lbad_ldr_nih)),%esi # Error message +jmp 0f +mb2_no_bs: +mov $(sym_phys(.Lbad_ldr_nbs)),%esi # Error message +xor %edi,%edi # No VGA text buffer +jmp 1f +mb2_efi_ia_32: +mov $(sym_phys(.Lbad_efi_msg)),%esi # Error message +xor %edi,%edi # No VGA text buffer +jmp 1f +0: mov sym_phys(vga_text_buffer),%edi 1: mov (%esi),%bl test