From patchwork Mon Jul 6 08:42:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 491496 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id E8613140D19 for ; Mon, 6 Jul 2015 18:42:36 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=zUgdDW3C; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 67A444B6A8; Mon, 6 Jul 2015 10:42:33 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZNusDiRJM85P; Mon, 6 Jul 2015 10:42:32 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F3F404B695; Mon, 6 Jul 2015 10:42:31 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5367D4B695 for ; Mon, 6 Jul 2015 10:42:28 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BbKHXl_ybvZl for ; Mon, 6 Jul 2015 10:42:28 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-qg0-f54.google.com (mail-qg0-f54.google.com [209.85.192.54]) by theia.denx.de (Postfix) with ESMTPS id D89DD4B693 for ; Mon, 6 Jul 2015 10:42:23 +0200 (CEST) Received: by qgii30 with SMTP id i30so65922087qgi.1 for ; Mon, 06 Jul 2015 01:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:subject:date:mime-version:content-type; bh=7B5szPT4A2p5c0NPz007A74qZn3mW6pTa0TYsbrV6Ak=; b=zUgdDW3C6vMaHLDgqbpRA1La3oC1/KLj4yJHKtZjgVsVwF/BTb2sBlnRpEGpLUKssu fB757zlP14MBZwWZRESLq/knNc4+DMVTTo/K20qxayKKlBRfG/LR1LaD74uNV4W/QCBW q730BhHGVdLcFM0bqAsF33TI7tJt6/x53cAGFvBGXqTOv5XuAYWUmjLCjkpO0+IfDkPs cIjr+mnN/UslhCsRHoln24zk2NvIUjh5UYW7hRAz8NtbotgifJE32YeJ/mDWKwaAYDUQ fMYwrm3z155gRFw/vMR+tatKRHNItP0Cer/BMWI0B6yM8tPru3EFkAkF2mn+WLzqaX3x u5lQ== X-Received: by 10.55.21.204 with SMTP id 73mr93443204qkv.27.1436172142688; Mon, 06 Jul 2015 01:42:22 -0700 (PDT) Received: from mail.hotmail.com (blu004-wss1s3.hotmail.com. [134.170.2.218]) by mx.google.com with ESMTPSA id 7sm8894871qky.29.2015.07.06.01.42.21 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Jul 2015 01:42:22 -0700 (PDT) Received: from BLU436-SMTP245 ([134.170.2.215]) by BLU004-WSS1S3.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Mon, 6 Jul 2015 01:42:21 -0700 X-TMN: [qZ4agxlTS3f+giCDhqEr2xrmj1uhOjjc] Message-ID: From: Bin Meng To: Simon Glass , U-Boot Mailing List , Jian Luo Date: Mon, 6 Jul 2015 16:42:06 +0800 X-Mailer: git-send-email 1.8.2.1 X-OriginalArrivalTime: 06 Jul 2015 08:42:20.0867 (UTC) FILETIME=[AC2BC930:01D0B7C7] MIME-Version: 1.0 Subject: [U-Boot] [RESPIN PATCH v2 02/11] x86: bios: Synchronize stack between real and protected mode X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Jian Luo PCI option rom may use different SS during its execution, so it is not safe to assume esp pointed to the same location in the protected mode. Signed-off-by: Jian Luo Signed-off-by: Bin Meng Acked-by: Simon Glass --- Changes in v2 respin: - Use *protected* mode instead of 'protect mode' - Correct typo of 'read mode' Changes in v2: - Add comments for the changes in the assembly codes arch/x86/lib/bios_asm.S | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/lib/bios_asm.S b/arch/x86/lib/bios_asm.S index 4faa70e..9dbf969 100644 --- a/arch/x86/lib/bios_asm.S +++ b/arch/x86/lib/bios_asm.S @@ -246,6 +246,9 @@ __interrupt_handler_16bit = PTR_TO_REAL_MODE(.) push %fs push %gs + /* Save real mode SS */ + movw %ss, %cs:__realmode_ss + /* Clear DF to not break ABI assumptions */ cld @@ -258,12 +261,29 @@ __interrupt_handler_16bit = PTR_TO_REAL_MODE(.) enter_protected_mode + /* + * Now we are in protected mode. We need compute the right ESP based + * on saved real mode SS otherwise interrupt_handler() won't get + * correct parameters from the stack. + */ + movzwl %cs:__realmode_ss, %ecx + shll $4, %ecx + addl %ecx, %esp + /* Call the C interrupt handler */ movl $interrupt_handler, %eax call *%eax + /* Restore real mode ESP based on saved SS */ + movzwl %cs:__realmode_ss, %ecx + shll $4, %ecx + subl %ecx, %esp + enter_real_mode + /* Restore real mode SS */ + movw %cs:__realmode_ss, %ss + /* * Restore all registers, including those manipulated by the C * handler @@ -276,6 +296,9 @@ __interrupt_handler_16bit = PTR_TO_REAL_MODE(.) popal iret +__realmode_ss = PTR_TO_REAL_MODE(.) + .word 0 + .globl asm_realmode_code_size asm_realmode_code_size: .long . - asm_realmode_code