Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YbTyp-0000oT-0c for mharc-grub-devel@gnu.org; Fri, 27 Mar 2015 09:07:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YbTym-0000o6-ME for grub-devel@gnu.org; Fri, 27 Mar 2015 09:07:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YbTyi-0007wv-LV for grub-devel@gnu.org; Fri, 27 Mar 2015 09:07:16 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:19915) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YbTyi-0007wj-Ea for grub-devel@gnu.org; Fri, 27 Mar 2015 09:07:12 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t2RD71nG023448 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Mar 2015 13:07:01 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t2RD70Ai005056 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 27 Mar 2015 13:07:00 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t2RD6xwd003913; Fri, 27 Mar 2015 13:06:59 GMT Received: from olila.local.net-space.pl (/10.175.231.232) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 27 Mar 2015 06:06:58 -0700 Date: Fri, 27 Mar 2015 14:06:52 +0100 From: Daniel Kiper To: Jan Beulich Subject: Re: [PATCH 18/18] x86: add multiboot2 protocol support for EFI platforms Message-ID: <20150327130652.GM8294@olila.local.net-space.pl> References: <1422640462-28103-1-git-send-email-daniel.kiper@oracle.com> <1422640462-28103-19-git-send-email-daniel.kiper@oracle.com> <550810B1020000780006AA3A@mail.emea.novell.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <550810B1020000780006AA3A@mail.emea.novell.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: aserv0022.oracle.com [141.146.126.234] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 Cc: Juergen Gross , grub-devel@gnu.org, keir@xen.org, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, roy.franz@linaro.org, ning.sun@intel.com, david.vrabel@citrix.com, phcoder@gmail.com, xen-devel@lists.xenproject.org, qiaowei.ren@intel.com, richard.l.maliszewski@intel.com, gang.wei@intel.com, fu.wei@linaro.org X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Mar 2015 13:07:17 -0000 On Tue, Mar 17, 2015 at 10:32:01AM +0000, Jan Beulich wrote: > >>> On 30.01.15 at 18:54, wrote: > > @@ -94,6 +111,17 @@ ENTRY(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) > > + .long BOOT_CS32 > > + > > +efi_st: > > + .quad 0 > > + > > +efi_ih: > > + .quad 0 > > > > .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!" > > .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!" > > @@ -124,6 +152,133 @@ print_err: > > .Lhalt: hlt > > jmp .Lhalt > > > > + .code64 > > + > > +__efi64_start: > > + cld > > + > > + /* Bootloaders may set multiboot[12].mem_lower to a nonzero value */ > > + xor %edx,%edx > > + > > + /* Check for Multiboot2 bootloader */ > > + cmp $MULTIBOOT2_BOOTLOADER_MAGIC,%eax > > + je efi_multiboot2_proto > > + > > + jmp not_multiboot > > + > > +efi_multiboot2_proto: > > jne not_multiboot (and efi_multiboot2_proto dropped altogether) > > > + /* Skip Multiboot2 information fixed part */ > > + lea MB2_fixed_sizeof(%ebx),%ecx > > Let's please not add more assumptions than necessary about stuff > being below 4G. I am not sure what do you mean by that. > > + > > +0: > > + /* Get mem_lower from Multiboot2 information */ > > + cmpl $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,(%ecx) > > + jne 1f > > + > > + mov MB2_mem_lower(%ecx),%edx > > + jmp 4f > > + > > +1: > > + /* Get EFI SystemTable address from Multiboot2 information */ > > + cmpl $MULTIBOOT2_TAG_TYPE_EFI64,(%ecx) > > + jne 2f > > + > > + lea MB2_efi64_st(%ecx),%esi > > + lea efi_st(%rip),%edi > > + movsq > > A simple pair of mov-s please, assuming all of this really needs to be > done in assembly in the first place. Also please use .L labels > in this assembly coded switch statement to ease reading. > > > + > > + /* Do not go into real mode on EFI platform */ > > + movb $1,skip_realmode(%rip) > > + > > + jmp 4f > > + > > +2: > > + /* Get EFI ImageHandle address from Multiboot2 information */ > > + cmpl $MULTIBOOT2_TAG_TYPE_EFI64_IH,(%ecx) > > + jne 3f > > + > > + lea MB2_efi64_ih(%ecx),%esi > > + lea efi_ih(%rip),%edi > > + movsq > > + jmp 4f > > + > > +3: > > + /* Is it the end of Multiboot2 information? */ > > + cmpl $MULTIBOOT2_TAG_TYPE_END,(%ecx) > > + je run_bs > > + > > +4: > > Please switch the order so that 2 can fall through into 4 (and you > then won't need the run_bs label, which otherwise should also > becom .Lrun_bs). > > > + /* 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 > > + > > +run_bs: > > + push %rax > > + push %rdx > > + > > + /* Initialize BSS (no nasty surprises!) */ > > + lea __bss_start(%rip),%rdi > > + lea _end(%rip),%rcx > > + sub %rdi,%rcx > > + xor %rax,%rax > > + rep stosb > > rep stosb > > > + > > + mov efi_ih(%rip),%rdi /* EFI ImageHandle */ > > + mov efi_st(%rip),%rsi /* EFI SystemTable */ > > + call efi_multiboot2 > > With efi_multiboot2 being a C function it really looks like much of the > above doesn't need to be done in assembly. Potentially make sense. I will try to do that. Daniel