From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from BLU004-OMC4S12.hotmail.com (blu004-omc4s12.hotmail.com [65.55.111.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3A72E1A1E06 for ; Sun, 31 Jul 2016 18:58:12 -0700 (PDT) Received: from EUR01-HE1-obe.outbound.protection.outlook.com ([65.55.111.135]) by BLU004-OMC4S12.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Sun, 31 Jul 2016 18:58:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=uk1YoV+EQn9t3F05w9sePC9VQy3uFJMYI4dWCe+J6Bw=; b=MQLKk965fVvHN8xhqQiWTBkQiT0rk2ntiz09dTTEWVUA0AOtnUFmrqNwsOYHtcZfFyj3/9j48sd/fwkpXR5Wi3+b0wj4elZhGgYriAyI1+Vkpd9WoUr12zeJ8tAKP9vUCVNp3zXMnHntnuaKu5ENGt78t2UK4PWytmXhq2Dpi5efssL1gCEyn2nM8ehgVueTqiScpSlm200T8oKHdh4XqtrqL/Q5rRxxtzQpQUbElHIs+XX4y8O9mKOEgKuNmiWe1u7L2UN944PG+E378OhS9NRkFVtRDhz2HzzRhLny2fsuLc5r2+zTLHt9nsbt86gc1qi5Lq2fkz8kzZRGXr1t5w== Received: from DB5EUR01FT058.eop-EUR01.prod.protection.outlook.com (10.152.4.51) by DB5EUR01HT026.eop-EUR01.prod.protection.outlook.com (10.152.5.168) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.8; Mon, 1 Aug 2016 01:58:08 +0000 Received: from AM4PR06MB1779.eurprd06.prod.outlook.com (10.152.4.52) by DB5EUR01FT058.mail.protection.outlook.com (10.152.5.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.557.8 via Frontend Transport; Mon, 1 Aug 2016 01:58:08 +0000 Received: from AM4PR06MB1779.eurprd06.prod.outlook.com ([10.165.247.142]) by AM4PR06MB1779.eurprd06.prod.outlook.com ([10.165.247.142]) with mapi id 15.01.0549.022; Mon, 1 Aug 2016 01:58:06 +0000 From: Marvin H?user To: "edk2-devel@lists.01.org" CC: "Tian, Feng" Thread-Topic: [RFC 1/2] MdeModulePkg/EbcDxe: Add AARCH64 EBC VM support Thread-Index: AQHR65b5eeIBzgUzMkSSmJu8xGeuw6AzWKVg Date: Mon, 1 Aug 2016 01:58:06 +0000 Message-ID: References: <1469808369-5344-1-git-send-email-leif.lindholm@linaro.org> <1469808369-5344-2-git-send-email-leif.lindholm@linaro.org> <7F1BAD85ADEA444D97065A60D2E97EE53881E396@SHSMSX101.ccr.corp.intel.com> In-Reply-To: <7F1BAD85ADEA444D97065A60D2E97EE53881E396@SHSMSX101.ccr.corp.intel.com> Accept-Language: de-DE, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=softfail (sender IP is 10.152.4.52) smtp.mailfrom=outlook.com; lists.01.org; dkim=none (message not signed) header.d=none;lists.01.org; dmarc=fail action=none header.from=outlook.com; received-spf: SoftFail (protection.outlook.com: domain of transitioning outlook.com discourages use of 10.152.4.52 as permitted sender) x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [OKW2Ftt6ZDSjeTTYsOHrlITlW1eOoyVPKLT3wF2gt/B3Q3spv1RKfT95J5+tXB9h] x-eopattributedmessage: 0 x-forefront-antispam-report: CIP:10.152.4.52; IPV:NLI; CTRY:; EFV:NLI; SFV:NSPM; SFS:(10019020)(98900003); DIR:OUT; SFP:1102; SCL:1; SRVR:DB5EUR01HT026; H:AM4PR06MB1779.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; x-microsoft-exchange-diagnostics: 1; DB5EUR01HT026; 6:lAYlKfZ3SZt9S1IPeORvAmDNP4hqK1U93Dg5t7647GBpWWbE3rWbBDE44muFuS2CWR0JPKxdlGgzVvxAkjRzJ4M+aq3ZQuj7s6B/MdTM8X59RI3/oIaOy6p6d8vsn1VOQsAMIxPOjuhO1v/zIBHAGR0R2EOFa8jhJIUYmiwAztHK6vsF9U3a+ojHVI6ItI5Va+NgeFQjGPvwUtUSbPuFywotbvl3ja95unPMLsyLSTeBnuPAhvC49Vra9rYEmxXSyTbnkPDxc5Ch5mWNXWTyIA5GrT6vscZMqlWP6cJbbZOc3vymJeb5bmWgzSvRgMgA; 5:FPbuR/450cYZfza2xfIg+BlQ15k64GboiidIrScCSS0DQlHroWaD1UdSGYz98nn4TFSf/k93h3HIr+uOoEDnMLnsQj1UmlQ/UNHN4bTNNyThgXoIi3gBilWCZ4lozQ8T61Y8a5/DiGqGY1DhlfYHZw==; 24:kUWz4W8Ge37iF3H/iyF+QYHYGSH4OdPoYfrkJP2uMx+2pQQop0sx0ofmCaV/8tirlnRSiygLJJlEWwbu37TQjciRHVJcaLAaeh3GCsazM48=; 7:VKxq1xoih5FZ8z5kfoWe80kGhHYDm7gTLA/3TRg1plPcg4JfQUmUE9dEZu+WSVVeuOidwBirUz3DSWj8V7QfibieyUc5PlldjTIR/DtgDKpsQvGHFiU9P3nLiFj+wT8Dnfu54zJS8qEm+2muhbKO8wZF9ChqMb1ctqLrrhuA1Yb73PSuwO0iy457hIuStP36Cls9g3yJT42FCDP/nynWDtPB5aBmeiW3dolvdiBoAW9FvSGwqjQgtt/VHqjPoujG x-ms-office365-filtering-correlation-id: a0993139-7dc0-4932-5dbd-08d3b9af47f0 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(1601125047); SRVR:DB5EUR01HT026; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(432015012)(82015046); SRVR:DB5EUR01HT026; BCL:0; PCL:0; RULEID:; SRVR:DB5EUR01HT026; x-forefront-prvs: 0021920B5A spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Aug 2016 01:58:06.4520 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5EUR01HT026 X-OriginalArrivalTime: 01 Aug 2016 01:58:10.0997 (UTC) FILETIME=[280D4650:01D1EB98] Subject: Re: [RFC 1/2] MdeModulePkg/EbcDxe: Add AARCH64 EBC VM support X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Aug 2016 01:58:12 -0000 Content-Language: de-DE Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hey Feng, According to the Contributions document, BSD 2-clause is one of the license= s that can be accepted, if the parent license cannot be used: https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Contributions.tx= t#L25 Regards, Marvin. > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Tian, Feng > Sent: Monday, August 1, 2016 3:50 AM > To: Leif Lindholm ; edk2-devel@lists.01.org > Cc: Tian, Feng ; Daniil Egranov > ; Jeff Brasen ; Zeng, > Star ; Ard Biesheuvel > Subject: Re: [edk2] [RFC 1/2] MdeModulePkg/EbcDxe: Add AARCH64 EBC > VM support >=20 > Hi, Leif >=20 > If I understand correctly, EDKII doesn't allow such BSD license. >=20 > Correct me if anybody has different opinions. >=20 > Thanks > Feng >=20 > -----Original Message----- > From: Leif Lindholm [mailto:leif.lindholm@linaro.org] > Sent: Saturday, July 30, 2016 12:06 AM > To: edk2-devel@lists.01.org > Cc: Jeff Brasen ; Ard Biesheuvel > ; Daniil Egranov ; > Tian, Feng ; Zeng, Star > Subject: [RFC 1/2] MdeModulePkg/EbcDxe: Add AARCH64 EBC VM support >=20 > From: Jeff Brasen >=20 > Adds support for the EBC VM for AARCH64 platforms >=20 > Submitted on behalf of a third-party: The Linux Foundation This contribut= ion > is licensed under the BSD license as found at > http://opensource.org/licenses/bsd-license.php >=20 > [Taken from https://source.codeaurora.org/external/server/edk2-blue/] > Signed-off-by: Leif Lindholm > --- > .../Universal/EbcDxe/AArch64/EbcLowLevel.S | 135 +++++ > MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c | 563 > +++++++++++++++++++++ > MdeModulePkg/Universal/EbcDxe/EbcDxe.inf | 6 +- > 3 files changed, 703 insertions(+), 1 deletion(-) create mode 100644 > MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S > create mode 100644 > MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c >=20 > diff --git a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S > b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S > new file mode 100644 > index 0000000..e858227 > --- /dev/null > +++ b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcLowLevel.S > @@ -0,0 +1,135 @@ > +#/** @file > +# > +# This code provides low level routines that support the Virtual Mach= ine > +# for option ROMs. > +# > +# Copyright (c) 2015, The Linux Foundation. All rights reserved. > +# Copyright (c) 2007 - 2014, Intel Corporation. All rights > +reserved.
# 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. > +# > +#**/ > + > +#---------------------------------------------------------------------- > +----- > +# Equate files needed. > +#---------------------------------------------------------------------- > +----- > + > +ASM_GLOBAL ASM_PFX(CopyMem); > +ASM_GLOBAL ASM_PFX(EbcInterpret); > +ASM_GLOBAL ASM_PFX(ExecuteEbcImageEntryPoint); > + > +#******************************************************** > ************** > +****** > +# EbcLLCALLEX > +# > +# This function is called to execute an EBC CALLEX instruction. > +# This instruction requires that we thunk out to external native # > +code. For AArch64, we copy the VM stack into the main stack and then > +pop # the first 8 arguments off according to the AArch64 Procedure Call > +Standard # On return, we restore the stack pointer to its original locat= ion. > +# > +#******************************************************** > ************** > +****** # UINTN EbcLLCALLEXNative(UINTN FuncAddr, UINTN > NewStackPointer, > +VOID *FramePtr) ASM_GLOBAL ASM_PFX(EbcLLCALLEXNative); > +ASM_PFX(EbcLLCALLEXNative): > + stp x19, x20, [sp, #-16]! > + stp x29, x30, [sp, #-16]! > + > + mov x19, x0 > + mov x20, sp > + sub x2, x2, x1 // Length =3D NewStackPointer-FramePtr > + sub sp, sp, x2 > + sub sp, sp, #64 // Make sure there is room for at least 8 args i= n the new > stack > + mov x0, sp > + > + bl CopyMem // Sp, NewStackPointer, Length > + > + ldp x0, x1, [sp], #16 > + ldp x2, x3, [sp], #16 > + ldp x4, x5, [sp], #16 > + ldp x6, x7, [sp], #16 > + > + blr x19 > + > + mov sp, x20 > + ldp x29, x30, [sp], #16 > + ldp x19, x20, [sp], #16 > + > + ret > + > +#******************************************************** > ************** > +****** > +# EbcLLEbcInterpret > +# > +# This function is called by the thunk code to handle an Native to EBC > +call # This can handle up to 16 arguments (1-8 on in x0-x7, 9-16 are on > +the stack) # x9 contains the Entry point that will be the first > +argument when # EBCInterpret is called. > +# > +#******************************************************** > ************** > +****** > +ASM_GLOBAL ASM_PFX(EbcLLEbcInterpret); > +ASM_PFX(EbcLLEbcInterpret): > + stp x29, x30, [sp, #-16]! > + > + // copy the current arguments 9-16 from old location and add arg 7 t= o > stack > + // keeping 16 byte stack alignment > + sub sp, sp, #80 > + str x7, [sp] > + ldr x11, [sp, #96] > + str x11, [sp, #8] > + ldr x11, [sp, #104] > + str x11, [sp, #16] > + ldr x11, [sp, #112] > + str x11, [sp, #24] > + ldr x11, [sp, #120] > + str x11, [sp, #32] > + ldr x11, [sp, #128] > + str x11, [sp, #40] > + ldr x11, [sp, #136] > + str x11, [sp, #48] > + ldr x11, [sp, #144] > + str x11, [sp, #56] > + ldr x11, [sp, #152] > + str x11, [sp, #64] > + > + // Shift arguments and add entry point and as argument 1 > + mov x7, x6 > + mov x6, x5 > + mov x5, x4 > + mov x4, x3 > + mov x3, x2 > + mov x2, x1 > + mov x1, x0 > + mov x0, x9 > + > + # call C-code > + bl ASM_PFX(EbcInterpret) > + add sp, sp, #80 > + > + ldp x29, x30, [sp], #16 > + > + ret > + > +#******************************************************** > ************** > +****** > +# EbcLLExecuteEbcImageEntryPoint > +# > +# This function is called by the thunk code to handle the image entry > +point # x9 contains the Entry point that will be the first argument > +when # ExecuteEbcImageEntryPoint is called. > +# > +#******************************************************** > ************** > +****** ASM_GLOBAL ASM_PFX(EbcLLExecuteEbcImageEntryPoint); > +ASM_PFX(EbcLLExecuteEbcImageEntryPoint): > + stp x29, x30, [sp, #-16]! > + # build new paramater calling convention > + mov x2, x1 > + mov x1, x0 > + mov x0, x9 > + > + # call C-code > + bl ASM_PFX(ExecuteEbcImageEntryPoint) > + ldp x29, x30, [sp], #16 > + ret > diff --git a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c > b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c > new file mode 100644 > index 0000000..23261a0 > --- /dev/null > +++ b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c > @@ -0,0 +1,563 @@ > +/** @file > + This module contains EBC support routines that are customized based > +on > + the target AArch64 processor. > + > +Copyright (c) 2015, The Linux Foundation. All rights reserved. > +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
> +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. > + > +**/ > + > +#include "EbcInt.h" > +#include "EbcExecute.h" > + > +// > +// Amount of space that is not used in the stack // #define > +STACK_REMAIN_SIZE (1024 * 4) > + > +// > +// This is instruction buffer used to create EBC thunk // > +#define EBC_MAGIC_SIGNATURE 0xCA112EBCCA112EBCull > +#define EBC_ENTRYPOINT_SIGNATURE 0xAFAFAFAFAFAFAFAFull > +#define EBC_LL_EBC_ENTRYPOINT_SIGNATURE 0xFAFAFAFAFAFAFAFAull > +UINT8 mInstructionBufferTemplate[] =3D { > + 0x03, 0x00, 0x00, 0x14, //b pc+16 > + // > + // Add a magic code here to help the VM recognize the thunk.. > + // > + (UINT8)(EBC_MAGIC_SIGNATURE & 0xFF), > + (UINT8)((EBC_MAGIC_SIGNATURE >> 8) & 0xFF), > + (UINT8)((EBC_MAGIC_SIGNATURE >> 16) & 0xFF), > + (UINT8)((EBC_MAGIC_SIGNATURE >> 24) & 0xFF), > + (UINT8)((EBC_MAGIC_SIGNATURE >> 32) & 0xFF), > + (UINT8)((EBC_MAGIC_SIGNATURE >> 40) & 0xFF), > + (UINT8)((EBC_MAGIC_SIGNATURE >> 48) & 0xFF), > + (UINT8)((EBC_MAGIC_SIGNATURE >> 56) & 0xFF), > + 0x69, 0x00, 0x00, 0x58, //ldr x9, #32 > + 0x8A, 0x00, 0x00, 0x58, //ldr x10, #40 > + 0x05, 0x00, 0x00, 0x14, //b pc+32 > + (UINT8)(EBC_ENTRYPOINT_SIGNATURE & 0xFF), > + (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 8) & 0xFF), > + (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 16) & 0xFF), > + (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 24) & 0xFF), > + (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 32) & 0xFF), > + (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 40) & 0xFF), > + (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 48) & 0xFF), > + (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 56) & 0xFF), > + (UINT8)(EBC_LL_EBC_ENTRYPOINT_SIGNATURE & 0xFF), > + (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 8) & 0xFF), > + (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 16) & 0xFF), > + (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 24) & 0xFF), > + (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 32) & 0xFF), > + (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 40) & 0xFF), > + (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 48) & 0xFF), > + (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 56) & 0xFF), > + 0x40, 0x01, 0x1F, 0xD6 //br x10 > + > +}; > + > +/** > + Begin executing an EBC image. > + This is used for Ebc Thunk call. > + > + @return The value returned by the EBC application we're going to run. > + > +**/ > +UINT64 > +EFIAPI > +EbcLLEbcInterpret ( > + VOID > + ); > + > +/** > + Begin executing an EBC image. > + This is used for Ebc image entrypoint. > + > + @return The value returned by the EBC application we're going to run. > + > +**/ > +UINT64 > +EFIAPI > +EbcLLExecuteEbcImageEntryPoint ( > + VOID > + ); > + > +/** > + Pushes a 64 bit unsigned value to the VM stack. > + > + @param VmPtr The pointer to current VM context. > + @param Arg The value to be pushed. > + > +**/ > +VOID > +PushU64 ( > + IN VM_CONTEXT *VmPtr, > + IN UINT64 Arg > + ) > +{ > + // > + // Advance the VM stack down, and then copy the argument to the stack. > + // Hope it's aligned. > + // > + VmPtr->Gpr[0] -=3D sizeof (UINT64); > + *(UINT64 *) VmPtr->Gpr[0] =3D Arg; > + return; > +} > + > + > +/** > + Begin executing an EBC image. > + > + This is a thunk function. > + > + @param EntryPoint The entrypoint of EBC code. > + @param Arg1 The 1st argument. > + @param Arg2 The 2nd argument. > + @param Arg3 The 3rd argument. > + @param Arg4 The 4th argument. > + @param Arg5 The 5th argument. > + @param Arg6 The 6th argument. > + @param Arg7 The 7th argument. > + @param Arg8 The 8th argument. > + @param Arg9 The 9th argument. > + @param Arg10 The 10th argument. > + @param Arg11 The 11th argument. > + @param Arg12 The 12th argument. > + @param Arg13 The 13th argument. > + @param Arg14 The 14th argument. > + @param Arg15 The 15th argument. > + @param Arg16 The 16th argument. > + > + @return The value returned by the EBC application we're going to run. > + > +**/ > +UINT64 > +EFIAPI > +EbcInterpret ( > + IN UINTN EntryPoint, > + IN UINTN Arg1, > + IN UINTN Arg2, > + IN UINTN Arg3, > + IN UINTN Arg4, > + IN UINTN Arg5, > + IN UINTN Arg6, > + IN UINTN Arg7, > + IN UINTN Arg8, > + IN UINTN Arg9, > + IN UINTN Arg10, > + IN UINTN Arg11, > + IN UINTN Arg12, > + IN UINTN Arg13, > + IN UINTN Arg14, > + IN UINTN Arg15, > + IN UINTN Arg16 > + ) > +{ > + // > + // Create a new VM context on the stack > + // > + VM_CONTEXT VmContext; > + UINTN Addr; > + EFI_STATUS Status; > + UINTN StackIndex; > + > + // > + // Get the EBC entry point > + // > + Addr =3D EntryPoint; > + > + // > + // Now clear out our context > + // > + ZeroMem ((VOID *) &VmContext, sizeof (VM_CONTEXT)); > + > + // > + // Set the VM instruction pointer to the correct location in memory. > + // > + VmContext.Ip =3D (VMIP) Addr; > + > + // > + // Initialize the stack pointer for the EBC. Get the current system > + stack // pointer and adjust it down by the max needed for the interpre= ter. > + // > + > + // > + // Adjust the VM's stack pointer down. > + // > + > + Status =3D GetEBCStack((EFI_HANDLE)(UINTN)-1, &VmContext.StackPool, > + &StackIndex); if (EFI_ERROR(Status)) { > + return Status; > + } > + VmContext.StackTop =3D (UINT8*)VmContext.StackPool + > + (STACK_REMAIN_SIZE); VmContext.Gpr[0] =3D (UINT64) > + ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE); > + VmContext.HighStackBottom =3D (UINTN) VmContext.Gpr[0]; > VmContext.Gpr[0] > + -=3D sizeof (UINTN); > + > + // > + // Align the stack on a natural boundary. > + // > + VmContext.Gpr[0] &=3D ~(VM_REGISTER)(sizeof (UINTN) - 1); > + > + // > + // Put a magic value in the stack gap, then adjust down again. > + // > + *(UINTN *) (UINTN) (VmContext.Gpr[0]) =3D (UINTN) > VM_STACK_KEY_VALUE; > + VmContext.StackMagicPtr =3D (UINTN *) (UINTN) VmContext.Gp= r[0]; > + > + // > + // The stack upper to LowStackTop is belong to the VM. > + // > + VmContext.LowStackTop =3D (UINTN) VmContext.Gpr[0]; > + > + // > + // For the worst case, assume there are 4 arguments passed in > + registers, store // them to VM's stack. > + // > + PushU64 (&VmContext, (UINT64) Arg16); > + PushU64 (&VmContext, (UINT64) Arg15); > + PushU64 (&VmContext, (UINT64) Arg14); > + PushU64 (&VmContext, (UINT64) Arg13); > + PushU64 (&VmContext, (UINT64) Arg12); > + PushU64 (&VmContext, (UINT64) Arg11); > + PushU64 (&VmContext, (UINT64) Arg10); > + PushU64 (&VmContext, (UINT64) Arg9); > + PushU64 (&VmContext, (UINT64) Arg8); > + PushU64 (&VmContext, (UINT64) Arg7); > + PushU64 (&VmContext, (UINT64) Arg6); > + PushU64 (&VmContext, (UINT64) Arg5); > + PushU64 (&VmContext, (UINT64) Arg4); > + PushU64 (&VmContext, (UINT64) Arg3); > + PushU64 (&VmContext, (UINT64) Arg2); > + PushU64 (&VmContext, (UINT64) Arg1); > + > + // > + // Interpreter assumes 64-bit return address is pushed on the stack. > + // AArch64 does not do this so pad the stack accordingly. > + // > + PushU64 (&VmContext, (UINT64) 0); > + PushU64 (&VmContext, (UINT64) 0x1234567887654321ULL); > + > + // > + // For AArch64, this is where we say our return address is // > + VmContext.StackRetAddr =3D (UINT64) VmContext.Gpr[0]; > + > + // > + // We need to keep track of where the EBC stack starts. This way, if > + the EBC // accesses any stack variables above its initial stack > + setting, then we know // it's accessing variables passed into it, > + which means the data is on the // VM's stack. > + // When we're called, on the stack (high to low) we have the > + parameters, the // return address, then the saved ebp. Save the pointe= r > to the return address. > + // EBC code knows that's there, so should look above it for function > parameters. > + // The offset is the size of locals (VMContext + Addr + saved ebp). > + // Note that the interpreter assumes there is a 16 bytes of return > + address on // the stack too, so adjust accordingly. > + // VmContext.HighStackBottom =3D (UINTN)(Addr + sizeof (VmContext) + > + sizeof (Addr)); // > + > + // > + // Begin executing the EBC code > + // > + EbcExecute (&VmContext); > + > + // > + // Return the value in R[7] unless there was an error > + // > + ReturnEBCStack(StackIndex); > + return (UINT64) VmContext.Gpr[7]; > +} > + > + > +/** > + Begin executing an EBC image. > + > + @param EntryPoint The entrypoint of EBC code. > + @param ImageHandle image handle for the EBC application we're > executing > + @param SystemTable standard system table passed into an driver's > entry > + point > + > + @return The value returned by the EBC application we're going to run. > + > +**/ > +UINT64 > +EFIAPI > +ExecuteEbcImageEntryPoint ( > + IN UINTN EntryPoint, > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + // > + // Create a new VM context on the stack > + // > + VM_CONTEXT VmContext; > + UINTN Addr; > + EFI_STATUS Status; > + UINTN StackIndex; > + > + // > + // Get the EBC entry point > + // > + Addr =3D EntryPoint; > + > + // > + // Now clear out our context > + // > + ZeroMem ((VOID *) &VmContext, sizeof (VM_CONTEXT)); > + > + // > + // Save the image handle so we can track the thunks created for this > + image // VmContext.ImageHandle =3D ImageHandle; > VmContext.SystemTable > + =3D SystemTable; > + > + // > + // Set the VM instruction pointer to the correct location in memory. > + // > + VmContext.Ip =3D (VMIP) Addr; > + > + // > + // Initialize the stack pointer for the EBC. Get the current system > + stack // pointer and adjust it down by the max needed for the interpre= ter. > + // > + > + Status =3D GetEBCStack(ImageHandle, &VmContext.StackPool, > &StackIndex); > + if (EFI_ERROR(Status)) { > + return Status; > + } > + VmContext.StackTop =3D (UINT8*)VmContext.StackPool + > + (STACK_REMAIN_SIZE); VmContext.Gpr[0] =3D (UINT64) > + ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE); > + VmContext.HighStackBottom =3D (UINTN) VmContext.Gpr[0]; > VmContext.Gpr[0] > + -=3D sizeof (UINTN); > + > + > + // > + // Put a magic value in the stack gap, then adjust down again // > + *(UINTN *) (UINTN) (VmContext.Gpr[0]) =3D (UINTN) > VM_STACK_KEY_VALUE; > + VmContext.StackMagicPtr =3D (UINTN *) (UINTN) VmContext.Gp= r[0]; > + > + // > + // Align the stack on a natural boundary VmContext.Gpr[0] &=3D > + ~(VM_REGISTER)(sizeof(UINTN) - 1); // > + VmContext.LowStackTop =3D (UINTN) VmContext.Gpr[0]; > + > + // > + // Simply copy the image handle and system table onto the EBC stack. > + // Greatly simplifies things by not having to spill the args. > + // > + PushU64 (&VmContext, (UINT64) SystemTable); > + PushU64 (&VmContext, (UINT64) ImageHandle); > + > + // > + // VM pushes 16-bytes for return address. Simulate that here. > + // > + PushU64 (&VmContext, (UINT64) 0); > + PushU64 (&VmContext, (UINT64) 0x1234567887654321ULL); > + > + // > + // For AArch64, this is where we say our return address is // > + VmContext.StackRetAddr =3D (UINT64) VmContext.Gpr[0]; > + > + // > + // Entry function needn't access high stack context, simply // put > + the stack pointer here. > + // > + > + // > + // Begin executing the EBC code > + // > + EbcExecute (&VmContext); > + > + // > + // Return the value in R[7] unless there was an error > + // > + ReturnEBCStack(StackIndex); > + return (UINT64) VmContext.Gpr[7]; > +} > + > + > +/** > + Create thunks for an EBC image entry point, or an EBC protocol service= . > + > + @param ImageHandle Image handle for the EBC image. If not n= ull, > then > + we're creating a thunk for an image entr= y point. > + @param EbcEntryPoint Address of the EBC code that the thunk i= s to > call > + @param Thunk Returned thunk we create here > + @param Flags Flags indicating options for creating th= e thunk > + > + @retval EFI_SUCCESS The thunk was created successfully. > + @retval EFI_INVALID_PARAMETER The parameter of EbcEntryPoint is not > 16-bit > + aligned. > + @retval EFI_OUT_OF_RESOURCES There is not enough memory to > created the EBC > + Thunk. > + @retval EFI_BUFFER_TOO_SMALL EBC_THUNK_SIZE is not larger enough. > + > +**/ > +EFI_STATUS > +EbcCreateThunks ( > + IN EFI_HANDLE ImageHandle, > + IN VOID *EbcEntryPoint, > + OUT VOID **Thunk, > + IN UINT32 Flags > + ) > +{ > + UINT8 *Ptr; > + UINT8 *ThunkBase; > + UINT32 Index; > + INT32 ThunkSize; > + > + // > + // Check alignment of pointer to EBC code // if ((UINT32) (UINTN) > + EbcEntryPoint & 0x01) { > + return EFI_INVALID_PARAMETER; > + } > + > + ThunkSize =3D sizeof(mInstructionBufferTemplate); > + > + Ptr =3D AllocatePool (sizeof(mInstructionBufferTemplate)); > + > + if (Ptr =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + // > + // Print(L"Allocate TH: 0x%X\n", (UINT32)Ptr); // // Save the > + start address so we can add a pointer to it to a list later. > + // > + ThunkBase =3D Ptr; > + > + // > + // Give them the address of our buffer we're going to fix up // > + *Thunk =3D (VOID *) Ptr; > + > + // > + // Copy whole thunk instruction buffer template // CopyMem (Ptr, > + mInstructionBufferTemplate, sizeof(mInstructionBufferTemplate)); > + > + // > + // Patch EbcEntryPoint and EbcLLEbcInterpret // for (Index =3D 0; > + Index < sizeof(mInstructionBufferTemplate) - sizeof(UINTN); Index++) { > + if (*(UINTN *)&Ptr[Index] =3D=3D EBC_ENTRYPOINT_SIGNATURE) { > + *(UINTN *)&Ptr[Index] =3D (UINTN)EbcEntryPoint; > + } > + if (*(UINTN *)&Ptr[Index] =3D=3D EBC_LL_EBC_ENTRYPOINT_SIGNATURE) { > + if ((Flags & FLAG_THUNK_ENTRY_POINT) !=3D 0) { > + *(UINTN *)&Ptr[Index] =3D (UINTN)EbcLLExecuteEbcImageEntryPoint; > + } else { > + *(UINTN *)&Ptr[Index] =3D (UINTN)EbcLLEbcInterpret; > + } > + } > + } > + > + // > + // Add the thunk to the list for this image. Do this last since the > + add // function flushes the cache for us. > + // > + EbcAddImageThunk (ImageHandle, (VOID *) ThunkBase, ThunkSize); > + > + return EFI_SUCCESS; > +} > + > + > +/** > + This function is called to execute an EBC CALLEX instruction. > + The function check the callee's content to see whether it is common > +native > + code or a thunk to another piece of EBC code. > + If the callee is common native code, use EbcLLCAllEXASM to > +manipulate, > + otherwise, set the VM->IP to target EBC code directly to avoid > +another VM > + be startup which cost time and stack space. > + > + @param VmPtr Pointer to a VM context. > + @param FuncAddr Callee's address > + @param NewStackPointer New stack pointer after the call > + @param FramePtr New frame pointer after the call > + @param Size The size of call instruction > + > +**/ > +VOID > +EbcLLCALLEX ( > + IN VM_CONTEXT *VmPtr, > + IN UINTN FuncAddr, > + IN UINTN NewStackPointer, > + IN VOID *FramePtr, > + IN UINT8 Size > + ) > +{ > + UINTN IsThunk; > + UINTN TargetEbcAddr; > + UINT8 InstructionBuffer[sizeof(mInstructionBufferTemplate)]; > + UINTN Index; > + UINTN IndexOfEbcEntrypoint; > + > + IsThunk =3D 1; > + TargetEbcAddr =3D 0; > + IndexOfEbcEntrypoint =3D 0; > + > + // > + // Processor specific code to check whether the callee is a thunk to E= BC. > + // > + CopyMem (InstructionBuffer, (VOID *)FuncAddr, > + sizeof(InstructionBuffer)); // // Fill the signature according to > + mInstructionBufferTemplate // for (Index =3D 0; Index < > + sizeof(mInstructionBufferTemplate) - sizeof(UINTN); Index++) { > + if (*(UINTN *)&mInstructionBufferTemplate[Index] =3D=3D > EBC_ENTRYPOINT_SIGNATURE) { > + *(UINTN *)&InstructionBuffer[Index] =3D EBC_ENTRYPOINT_SIGNATURE; > + IndexOfEbcEntrypoint =3D Index; > + } > + if (*(UINTN *)&mInstructionBufferTemplate[Index] =3D=3D > EBC_LL_EBC_ENTRYPOINT_SIGNATURE) { > + *(UINTN *)&InstructionBuffer[Index] =3D > EBC_LL_EBC_ENTRYPOINT_SIGNATURE; > + } > + } > + // > + // Check if we need thunk to native > + // > + if (CompareMem (InstructionBuffer, mInstructionBufferTemplate, > sizeof(mInstructionBufferTemplate)) !=3D 0) { > + IsThunk =3D 0; > + } > + > + if (IsThunk =3D=3D 1){ > + // > + // The callee is a thunk to EBC, adjust the stack pointer down 16 by= tes and > + // put our return address and frame pointer on the VM stack. > + // Then set the VM's IP to new EBC code. > + // > + VmPtr->Gpr[0] -=3D 8; > + VmWriteMemN (VmPtr, (UINTN) VmPtr->Gpr[0], (UINTN) FramePtr); > + VmPtr->FramePtr =3D (VOID *) (UINTN) VmPtr->Gpr[0]; > + VmPtr->Gpr[0] -=3D 8; > + VmWriteMem64 (VmPtr, (UINTN) VmPtr->Gpr[0], (UINT64) (UINTN) > + (VmPtr->Ip + Size)); > + > + CopyMem (&TargetEbcAddr, (UINT8 *)FuncAddr + IndexOfEbcEntrypoint, > sizeof(UINTN)); > + VmPtr->Ip =3D (VMIP) (UINTN) TargetEbcAddr; } else { > + // > + // The callee is not a thunk to EBC, call native code, > + // and get return value. > + // > + VmPtr->Gpr[7] =3D EbcLLCALLEXNative (FuncAddr, NewStackPointer, > + FramePtr); > + > + // > + // Advance the IP. > + // > + VmPtr->Ip +=3D Size; > + } > +} > + > diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf > b/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf > index 15dc01c..e9a0b28 100644 > --- a/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf > +++ b/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf > @@ -5,6 +5,7 @@ > # platform and processor-independent mechanisms for loading and > executing EFI # device drivers. > # > +# Copyright (c) 2015, The Linux Foundation. All rights reserved. > # Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. # > This program and the accompanying materials # are licensed and made > available under the terms and conditions of the BSD License @@ -28,7 +29,= 7 > @@ [Defines] # # The following information is for reference only and no= t > required by the build tools. > # > -# VALID_ARCHITECTURES =3D IA32 X64 IPF > +# VALID_ARCHITECTURES =3D IA32 X64 IPF AARCH64 > # >=20 > [Sources] > @@ -54,6 +55,9 @@ [Sources.IPF] > Ipf/EbcSupport.c > Ipf/EbcLowLevel.s >=20 > +[Sources.AARCH64] > + AArch64/EbcSupport.c > + AArch64/EbcLowLevel.S >=20 > [Packages] > MdePkg/MdePkg.dec > -- > 2.1.4 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel