I committed your current 64-asm patch from:
git://git.infradead.org/users/dwmw2/edk2.git
as edk2 r14045.

I tested Linux x86 & x86-64 boots for OVMF X64 built on Linux/GCC and
Win8/VS2012 with the change.

Thanks for the contribution,

-Jordan

On Tue, Jan 8, 2013 at 3:52 PM, David Woodhouse <dw...@infradead.org> wrote:
> We currently just jump to offset 0x200 in the kernel image, in 64-bit
> mode. This is completely broken. If it's a 32-bit kernel, we'll be
> jumping into the compressed data payload.
>
> If it's a 64-bit kernel, it'll work... but the 0x200 offset is
> explicitly marked as 'may change in the future', has already changed
> from 0x100 to 0x200 in the past with no fanfare, and bootloaders are
> instructed that they should look at the ELF header to find the offset.
> So although it does actually work today, it's still broken in the
> "someone needs to whipped for doing it this way" sense of the word.
>
> In fact, the same bug exists in other bootloaders so the 0x200 offset
> probably *is* now set in stone. But still it's only valid to use it if
> we *know* it's a 64-bit kernel. And we don't. There *is* no ELF header
> that we can look at when we're booting a bzImage, and we can't rely on
> it having a PE/COFF header either.
>
> The 32-bit entry point is always guaranteed to work, and we need to
> support it anyway. So let's just *always* use it, in 32-bit mode, and
> then we don't have to make up some horrible heuristics for detecting
> 32-bit vs. 64-bit kernels.
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: David Woodhouse <david.woodho...@intel.com>
> ---
> Forget anything you've seen about the EFI boot stub; this part stands
> alone and is completely unrelated to that.
>
> If someone could carefully review my code for getting back into 32-bit
> mode, that would be much appreciated. I've tested that it happily boots
> both 32-bit and 64-bit kernels under qemu.
>
> It also wants converting to MS assembler form; I wasn't sure how to do
> the .code32/.code64 bits so figured it was best to leave it alone
> completely for now.
>
> diff --git a/edk2/OvmfPkg/Library/LoadLinuxLib/LinuxGdt.c 
> b/edk2/OvmfPkg/Library/LoadLinuxLib/LinuxGdt.c
> index 4e20436..58c097c 100644
> --- a/edk2/OvmfPkg/Library/LoadLinuxLib/LinuxGdt.c
> +++ b/edk2/OvmfPkg/Library/LoadLinuxLib/LinuxGdt.c
> @@ -83,7 +83,11 @@ STATIC GDT_ENTRIES GdtTemplate = {
>      0x0,            // base 0
>      0x0,
>      0x09A,          // present, ring 0, data, expand-up, writable
> +#ifdef MDE_CPU_IA32
>      0x0CF,          // page-granular, 32-bit
> +#else
> +    0x0AF,          // compatibility mode
> +#endif
>      0x0,
>    },
>    //
> diff --git a/edk2/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.S 
> b/edk2/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.S
> index 9ae755b..8a39333 100644
> --- a/edk2/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.S
> +++ b/edk2/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.S
> @@ -24,7 +24,37 @@ ASM_GLOBAL ASM_PFX(JumpToKernel)
>  
> #------------------------------------------------------------------------------
>  ASM_PFX(JumpToKernel):
>      movq    %rdx, %rsi
> -    addq    $0x200, %rcx
> -    callq   %rcx
> -    ret
> +    movq    %rcx, %rbx
> +    movq    $0x10, %rax
> +    shl     $32, %rax
> +    orq     $1f, %rax
> +    pushq   %rax
> +    retf
> +1:     // Now in compatibility mode
> +.code32
> +    movl    $0x18, %eax
> +    movl    %eax, %ds
> +    movl    %eax, %es
> +    movl    %eax, %fs
> +    movl    %eax, %gs
> +    movl    %eax, %ss
> +
> +    // Disable paging
> +    movl    %cr0, %eax
> +    btcl    $31, %eax
> +    movl    %eax, %cr0
> +
> +    // Disable long mode in EFER
> +    movl    $0x0c0000080, %ecx
> +    rdmsr
> +    btcl    $8, %eax
> +    wrmsr
> +
> +    // Disable PAE
> +    movl    %cr0, %eax
> +    btcl    $5, %eax
> +    movl    %eax, %cr0
> +
> +    jmp     %ebx
> +.code64
>
>
> --
> dwmw2
>
>
> ------------------------------------------------------------------------------
> Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
> and more. Get SQL Server skills now (including 2012) with LearnDevNow -
> 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
> SALE $99.99 this month only - learn more at:
> http://p.sf.net/sfu/learnmore_122512
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to