On 10/18/14 20:25, Jordan Justen wrote:
> The BaseTools/Scripts/ConvertMasmToNasm.py script was used to convert
> X64/JumpToKernel.asm to X64/JumpToKernel.nasm
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jordan Justen <[email protected]>
> ---
>  OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf      |  3 +-
>  OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.S    | 91 
> ----------------------
>  .../X64/{JumpToKernel.asm => JumpToKernel.nasm}    | 66 ++++++++--------
>  3 files changed, 33 insertions(+), 127 deletions(-)
>  delete mode 100644 OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.S
>  rename OvmfPkg/Library/LoadLinuxLib/X64/{JumpToKernel.asm => 
> JumpToKernel.nasm} (54%)
> 
> diff --git a/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf 
> b/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf
> index 0d98c26..12d2f4f 100644
> --- a/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf
> +++ b/OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf
> @@ -34,8 +34,7 @@
>    Ia32/JumpToKernel.nasm
>  
>  [Sources.X64]
> -  X64/JumpToKernel.asm
> -  X64/JumpToKernel.S
> +  X64/JumpToKernel.nasm
>  
>  [Packages]
>    MdePkg/MdePkg.dec
> diff --git a/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.S 
> b/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.S
> deleted file mode 100644
> index 056e3c0..0000000
> --- a/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.S
> +++ /dev/null
> @@ -1,91 +0,0 @@
> -#------------------------------------------------------------------------------
> -#
> -# Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
> -#
> -# This program and the accompanying materials
> -# are licensed and made available under the terms and conditions of the BSD 
> License
> -# which accompanies this distribution.  The full text of the license may be 
> found at
> -# http://opensource.org/licenses/bsd-license.php.
> -#
> -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
> IMPLIED.
> -#
> -#------------------------------------------------------------------------------
> -
> -ASM_GLOBAL ASM_PFX(JumpToKernel)
> -ASM_GLOBAL ASM_PFX(JumpToUefiKernel)
> -
> -#------------------------------------------------------------------------------
> -# VOID
> -# EFIAPI
> -# JumpToKernel (
> -#   VOID *KernelStart,         // %rcx
> -#   VOID *KernelBootParams     // %rdx
> -#   );
> -#------------------------------------------------------------------------------
> -ASM_PFX(JumpToKernel):
> -
> -    // Set up for executing kernel. BP in %esi, entry point on the stack
> -    // (64-bit when the 'ret' will use it as 32-bit, but we're little-endian)
> -    movq    %rdx, %rsi
> -    pushq   %rcx
> -
> -    // Jump into the compatibility mode CS
> -    pushq   $0x10
> -    leaq    1f(%rip), %rax
> -    pushq   %rax
> -    .byte   0x48, 0xcb                      // retfq
> -
> -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    %cr4, %eax
> -    btcl    $5, %eax
> -    movl    %eax, %cr4
> -
> -    // Zero registers and 'return' to kernel
> -    xorl    %ebp, %ebp
> -    xorl    %edi, %edi
> -    xorl    %ebx, %ebx
> -    ret
> -.code64
> -
> -#------------------------------------------------------------------------------
> -# VOID
> -# EFIAPI
> -# JumpToUefiKernel (
> -#   EFI_HANDLE ImageHandle,        // rcx
> -#   EFI_SYSTEM_TABLE *SystemTable, // rdx
> -#   VOID *KernelBootParams,        // r8
> -#   VOID *KernelStart              // r9
> -#   );
> -#------------------------------------------------------------------------------
> -ASM_PFX(JumpToUefiKernel):
> -    movq    %rcx, %rdi
> -    movq    %rdx, %rsi
> -    movq    %r8, %rdx
> -    xor     %rax, %rax
> -    movl    0x264(%r8), %eax
> -    addq    %rax, %r9
> -    addq    $0x200, %r9
> -    callq   %r9
> -    ret
> -
> diff --git a/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.asm 
> b/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.nasm
> similarity index 54%
> rename from OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.asm
> rename to OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.nasm
> index fc07eab..128dcef 100644
> --- a/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.asm
> +++ b/OvmfPkg/Library/LoadLinuxLib/X64/JumpToKernel.nasm
> @@ -12,7 +12,8 @@
>  ;
>  
> ;------------------------------------------------------------------------------
>  
> -  .code
> +  DEFAULT REL
> +  SECTION .text
>  
>  
> ;------------------------------------------------------------------------------
>  ; VOID
> @@ -22,7 +23,8 @@
>  ;   VOID *KernelBootParams     // rdx
>  ;   );
>  
> ;------------------------------------------------------------------------------
> -JumpToKernel PROC
> +global ASM_PFX(JumpToKernel)
> +ASM_PFX(JumpToKernel):
>  
>      ; Set up for executing kernel. BP in %esi, entry point on the stack
>      ; (64-bit when the 'ret' will use it as 32-bit, but we're little-endian)
> @@ -30,43 +32,41 @@ JumpToKernel PROC
>      push   rcx
>  
>      ; Jump into the compatibility mode CS
> -    push    10h
> -    lea     rax, @F
> +    push    0x10
> +    lea     rax, [.0]

Okay, I did have to look at the .S here -- "@" is a label, "ahead" (F).
And we're loading its rip-relative address into rax. I gather from the
nasm docs that "." is the local label prefix.

>      push    rax
> -    DB 048h, 0cbh                      ; retfq
> +    DB 0x48, 0xcb                      ; retfq
>  
> -@@:
> +.0:
>      ; Now in compatibility mode.
>  
> -    DB 0b8h, 018h, 000h, 000h, 000h    ; movl    $0x18, %eax
> -    DB 08eh, 0d8h                      ; movl    %eax, %ds
> -    DB 08eh, 0c0h                      ; movl    %eax, %es
> -    DB 08eh, 0e0h                      ; movl    %eax, %fs
> -    DB 08eh, 0e8h                      ; movl    %eax, %gs
> -    DB 08eh, 0d0h                      ; movl    %eax, %ss
> +    DB 0xb8, 0x18, 0x0, 0x0, 0x0    ; movl    $0x18, %eax
> +    DB 0x8e, 0xd8                      ; movl    %eax, %ds
> +    DB 0x8e, 0xc0                      ; movl    %eax, %es
> +    DB 0x8e, 0xe0                      ; movl    %eax, %fs
> +    DB 0x8e, 0xe8                      ; movl    %eax, %gs
> +    DB 0x8e, 0xd0                      ; movl    %eax, %ss

I guess this could be "simply" rewritten, as nasm supports mode switches
within the same assembly file. But the conversion looks okay too.

>  
>      ; Disable paging
> -    DB 00fh, 020h, 0c0h                ; movl    %cr0, %eax
> -    DB 00fh, 0bah, 0f8h, 01fh          ; btcl    $31, %eax
> -    DB 00fh, 022h, 0c0h                ; movl    %eax, %cr0
> +    DB 0xf, 0x20, 0xc0                ; movl    %cr0, %eax
> +    DB 0xf, 0xba, 0xf8, 0x1f          ; btcl    $31, %eax
> +    DB 0xf, 0x22, 0xc0                ; movl    %eax, %cr0
>  
>      ; Disable long mode in EFER
> -    DB 0b9h, 080h, 000h, 000h, 0c0h    ; movl    $0x0c0000080, %ecx
> -    DB 00fh, 032h                      ; rdmsr
> -    DB 00fh, 0bah, 0f8h, 008h          ; btcl    $8, %eax
> -    DB 00fh, 030h                      ; wrmsr
> +    DB 0xb9, 0x80, 0x0, 0x0, 0xc0    ; movl    $0x0c0000080, %ecx
> +    DB 0xf, 0x32                      ; rdmsr
> +    DB 0xf, 0xba, 0xf8, 0x8          ; btcl    $8, %eax
> +    DB 0xf, 0x30                      ; wrmsr
>  
>      ; Disable PAE
> -    DB 00fh, 020h, 0e0h                ; movl    %cr4, %eax
> -    DB 00fh, 0bah, 0f8h, 005h          ; btcl    $5, %eax
> -    DB 00fh, 022h, 0e0h                ; movl    %eax, %cr4
> +    DB 0xf, 0x20, 0xe0                ; movl    %cr4, %eax
> +    DB 0xf, 0xba, 0xf8, 0x5          ; btcl    $5, %eax
> +    DB 0xf, 0x22, 0xe0                ; movl    %eax, %cr4
>  
> -    DB 031h, 0edh                      ; xor     %ebp, %ebp
> -    DB 031h, 0ffh                      ; xor     %edi, %edi
> -    DB 031h, 0dbh                      ; xor     %ebx, %ebx
> -    DB 0c3h                            ; ret
> -
> -JumpToKernel ENDP
> +    DB 0x31, 0xed                      ; xor     %ebp, %ebp
> +    DB 0x31, 0xff                      ; xor     %edi, %edi
> +    DB 0x31, 0xdb                      ; xor     %ebx, %ebx
> +    DB 0xc3                            ; ret

Comparing this by way of eyeballing gets old real quick.

If it runs then the conversion is correct. :) Mode switches are not
exactly forgiving.

Also I think the conversion of DBs is a more "mechanic" part of
ConvertMasmToNasm.py (around defineDataRe), and if it broke, it would
break very loudly.

>  
>  
> ;------------------------------------------------------------------------------
>  ; VOID
> @@ -78,18 +78,16 @@ JumpToKernel ENDP
>  ;   VOID *KernelStart,             // r9
>  ;   );
>  
> ;------------------------------------------------------------------------------
> -JumpToUefiKernel PROC
> +global ASM_PFX(JumpToUefiKernel)
> +ASM_PFX(JumpToUefiKernel):
>  
>      mov     rdi, rcx
>      mov     rsi, rdx
>      mov     rdx, r8
>      xor     rax, rax
> -    mov     eax, [r8 + 264h]
> +    mov     eax, [r8 + 0x264]
>      add     r9, rax
> -    add     r9, 200h
> +    add     r9, 0x200
>      call    r9
>      ret
>  
> -JumpToUefiKernel ENDP
> -
> -END
> 

Reviewed-by: Laszlo Ersek <[email protected]>

------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to