* We place all of the values on our mini stack so lret can
         * used to perform that far jump.
         */
-       pushl   $__KERNEL_CS
        leal    startup_64(%ebp), %eax
 #ifdef CONFIG_EFI_MIXED
        movl    efi32_boot_args(%ebp), %edi
        movl    efi32_boot_args+8(%ebp), %edx   // saved bootparams pointer
        cmpl    $0, %edx
        jnz     1f
+       /*
+        * efi_pe_entry uses MS calling convention, which requires 32 bytes of
+        * shadow space on the stack even if all arguments are passed in
+        * registers. We also need an additional 8 bytes for the space that
+        * would be occupied by the return address, and this also results in
+        * the correct stack alignment for entry.
+        */
+       subl    $40, %esp
        leal    efi_pe_entry(%ebp), %eax
        movl    %edi, %ecx                      // MS calling convention
        movl    %esi, %edx
 1:
 #endif
+       pushl   $__KERNEL_CS
        pushl   %eax
 
        /* Enter paged protected Mode, activating Long Mode */
 
 SYM_DATA_START_LOCAL(boot_stack)
        .fill BOOT_STACK_SIZE, 1, 0
+       .balign 16
 SYM_DATA_END_LABEL(boot_stack, SYM_L_LOCAL, boot_stack_end)
 
 /*