Skip to content

Commit

Permalink
MdeModulePkg/EbcDxe: add ARM support
Browse files Browse the repository at this point in the history
* This is a port of the AARCH64 implementation of the EBC runtime to ARM.
* Note that, on its own, this patch only allows running self contained EBC
  applications, such as ones that don't issue calls into the native
  platform, or that aren't being called from native.
* Support for EBC -> native and native -> EBC calls will be added in
  subsequent patches.
* Because EFI32 may not be defined for ARM compilation, this patch also
  alters the EBC Debugger to use MDE_CPU_### macros for address display.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Pete Batard <pete@akeo.ie>
  • Loading branch information
Ard Biesheuvel authored and pbatard committed Jan 24, 2017
1 parent 212f834 commit 2df4eaa
Show file tree
Hide file tree
Showing 10 changed files with 648 additions and 17 deletions.
6 changes: 5 additions & 1 deletion ArmVirtPkg/ArmVirt.dsc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@
#
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf

#
# EBC support
#
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf

#
# UEFI application (Shell Embedded Boot Loader)
#
Expand Down Expand Up @@ -430,4 +435,3 @@
# ACPI Support
#
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
10 changes: 5 additions & 5 deletions ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,18 @@ READ_LOCK_STATUS = TRUE
INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf

#
# EBC support
#
INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf

!if $(ARCH) == AARCH64
#
# ACPI Support
#
INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf

#
# EBC support
#
INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
!endif

#
Expand Down
10 changes: 5 additions & 5 deletions ArmVirtPkg/ArmVirtXen.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ READ_LOCK_STATUS = TRUE
#
INF ShellPkg/Application/Shell/Shell.inf

#
# EBC support
#
INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf

#
# Bds
#
Expand All @@ -186,11 +191,6 @@ READ_LOCK_STATUS = TRUE
!if $(ARCH) == AARCH64
INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
INF ArmVirtPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf

#
# EBC support
#
INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
!endif

#
Expand Down
4 changes: 3 additions & 1 deletion MdeModulePkg/MdeModulePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,10 @@
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf

[Components.IA32, Components.X64, Components.IPF, Components.AARCH64]
[Components.IA32, Components.X64, Components.IPF]
MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf

[Components.IA32, Components.X64, Components.IPF, Components.ARM, Components.AARCH64]
MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf
Expand Down
147 changes: 147 additions & 0 deletions MdeModulePkg/Universal/EbcDxe/Arm/EbcLowLevel.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
///** @file
//
// This code provides low level routines that support the Virtual Machine
// for option ROMs.
//
// Copyright (c) 2016, Linaro, Ltd. All rights reserved.<BR>
// Copyright (c) 2015, The Linux Foundation. All rights reserved.<BR>
// Copyright (c) 2007 - 2014, 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.
//
//**/

.thumb
.syntax unified

ASM_GLOBAL ASM_PFX(EbcLLCALLEXNative)
ASM_GLOBAL ASM_PFX(EbcLLEbcInterpret)
ASM_GLOBAL ASM_PFX(EbcLLExecuteEbcImageEntryPoint)

INTERWORK_FUNC(EbcLLCALLEXNative)
INTERWORK_FUNC(EbcLLEbcInterpret)
INTERWORK_FUNC(EbcLLExecuteEbcImageEntryPoint)

ASM_GLOBAL ASM_PFX(mEbcInstructionBufferTemplate)

//****************************************************************************
// EbcLLCALLEX
//
// This function is called to execute an EBC CALLEX instruction.
// This instruction requires that we thunk out to external native
// code. For ARM, we copy the VM stack into the main stack and then pop
// the first 4 arguments off according to the ARM Procedure Call Standard
// On return, we restore the stack pointer to its original location.
//
//****************************************************************************
// UINTN EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)
ASM_PFX(EbcLLCALLEXNative):
mov ip, r0 // Preserve r0

//
// If the EBC stack frame is smaller than or equal to 16 bytes, we know there
// are no stacked arguments #5 and beyond that we need to copy to the native
// stack. In this case, we can perform a tail call which is much more
// efficient, since there is no need to touch the native stack at all.
//
sub r3, r2, r1 // Length = NewStackPointer - FramePtr
cmp r3, #16
bgt 0f

ldrd r2, r3, [r1, #8]
ldrd r0, r1, [r1]

bx ip

//
// More than 16 bytes: we need to build the full native stack frame and copy
// the part of the VM stack exceeding 16 bytes (which may contain stacked
// arguments) to the native stack
//
0: push {r4, lr}
mov r4, sp

//
// Ensure that the stack pointer remains 8 byte aligned,
// even if the size of the VM stack frame is not a multiple of 8
//
add r1, r1, #16 // Skip over [potential] reg params
tst r3, #7 // Multiple of 8?
beq 1f
ldr r3, [r2, #-4]! // No? Then push one word
str r3, [sp, #-8]! // ... but use two slots
b 2f

1: ldrd r0, r3, [r2, #-8]!
strd r0, r3, [sp, #-8]!
2: cmp r2, r1
bgt 1b

ldrd r2, r3, [r1, #-8]
ldrd r0, r1, [r1, #-16]

blx ip

mov sp, r4
pop {r4, pc}

//****************************************************************************
// EbcLLEbcInterpret
//
// This function is called by the thunk code to handle an Native to EBC call
// This can handle up to 16 arguments (1-4 on in r0-r3, 5-16 are on the stack)
// ip contains the Entry point that will be the first argument when
// EBCInterpret is called.
//
//****************************************************************************
ASM_PFX(EbcLLEbcInterpret):
stmdb sp!, {r4, lr}

// push the entry point and the address of args #5 - #16 onto the stack
add r4, sp, #8
str ip, [sp, #-8]!
str r4, [sp, #4]

// call C-code
bl ASM_PFX(EbcInterpret)

add sp, sp, #8
ldmia sp!, {r4, pc}

//****************************************************************************
// EbcLLExecuteEbcImageEntryPoint
//
// This function is called by the thunk code to handle the image entry point
// ip contains the Entry point that will be the third argument when
// ExecuteEbcImageEntryPoint is called.
//
//****************************************************************************
ASM_PFX(EbcLLExecuteEbcImageEntryPoint):
ldr r2, [ip, #12]

// tail call to C code
b ASM_PFX(ExecuteEbcImageEntryPoint)

//****************************************************************************
// mEbcInstructionBufferTemplate
//****************************************************************************
.section ".rodata", "a"
.align 2
.arm
ASM_PFX(mEbcInstructionBufferTemplate):
adr ip, .
ldr pc, 0f

//
// Add a magic code here to help the VM recognize the thunk.
//
udf #0xEBC

.long 0 // EBC_ENTRYPOINT_SIGNATURE
0: .long 0 // EBC_LL_EBC_ENTRYPOINT_SIGNATURE
Loading

0 comments on commit 2df4eaa

Please sign in to comment.