ArmPlatformPkg/PrePi: switch to ASM_FUNC() asm macro

Annotate functions with ASM_FUNC() so that they are emitted into
separate sections.

While we're at it, replace some inefficient uses of LoadConstantToReg()

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
This commit is contained in:
Ard Biesheuvel 2016-08-10 16:04:27 +02:00
parent a0f56915a0
commit d2fa09a134
2 changed files with 28 additions and 69 deletions

View File

@ -12,24 +12,10 @@
// //
#include <AsmMacroIoLibV8.h> #include <AsmMacroIoLibV8.h>
#include <Base.h>
#include <Library/PcdLib.h>
#include <AutoGen.h>
.text
.align 3
GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)
GCC_ASM_IMPORT(ArmReadMpidr)
GCC_ASM_IMPORT(ArmPlatformPeiBootAction)
GCC_ASM_IMPORT(ArmPlatformStackSet)
GCC_ASM_EXPORT(_ModuleEntryPoint)
ASM_GLOBAL ASM_PFX(mSystemMemoryEnd) ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)
StartupAddr: .8byte ASM_PFX(CEntryPoint) ASM_FUNC(_ModuleEntryPoint)
ASM_PFX(mSystemMemoryEnd): .8byte 0
ASM_PFX(_ModuleEntryPoint):
// Do early platform specific actions // Do early platform specific actions
bl ASM_PFX(ArmPlatformPeiBootAction) bl ASM_PFX(ArmPlatformPeiBootAction)
@ -49,10 +35,8 @@ _SystemMemoryEndInit:
cmp x1, #0 cmp x1, #0
bne _SetupStackPosition bne _SetupStackPosition
LoadConstantToReg (FixedPcdGet64(PcdSystemMemoryBase), x1) MOV64 (x1, FixedPcdGet64(PcdSystemMemoryBase) + FixedPcdGet64(PcdSystemMemorySize) - 1)
LoadConstantToReg (FixedPcdGet64(PcdSystemMemorySize), x2)
sub x2, x2, #1
add x1, x1, x2
// Update the global variable // Update the global variable
adr x2, mSystemMemoryEnd adr x2, mSystemMemoryEnd
str x1, [x2] str x1, [x2]
@ -61,13 +45,13 @@ _SetupStackPosition:
// r1 = SystemMemoryTop // r1 = SystemMemoryTop
// Calculate Top of the Firmware Device // Calculate Top of the Firmware Device
LoadConstantToReg (FixedPcdGet64(PcdFdBaseAddress), x2) MOV64 (x2, FixedPcdGet64(PcdFdBaseAddress))
LoadConstantToReg (FixedPcdGet32(PcdFdSize), x3) MOV32 (x3, FixedPcdGet32(PcdFdSize) - 1)
sub x3, x3, #1 sub x3, x3, #1
add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
// UEFI Memory Size (stacks are allocated in this region) // UEFI Memory Size (stacks are allocated in this region)
LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), x4) MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
// //
// Reserve the memory for the UEFI region (contain stacks on its top) // Reserve the memory for the UEFI region (contain stacks on its top)
@ -98,9 +82,7 @@ _SetupAlignedStack:
_SetupOverflowStack: _SetupOverflowStack:
// Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
// aligned (4KB) // aligned (4KB)
LoadConstantToReg (EFI_PAGE_MASK, x11) and x1, x1, ~EFI_PAGE_MASK
and x11, x11, x1
sub x1, x1, x11
_GetBaseUefiMemory: _GetBaseUefiMemory:
// Calculate the Base of the UEFI Memory // Calculate the Base of the UEFI Memory
@ -109,22 +91,19 @@ _GetBaseUefiMemory:
_GetStackBase: _GetStackBase:
// r1 = The top of the Mpcore Stacks // r1 = The top of the Mpcore Stacks
// Stack for the primary core = PrimaryCoreStack // Stack for the primary core = PrimaryCoreStack
LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2) MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
sub x12, x1, x2 sub x12, x1, x2
// Stack for the secondary core = Number of Cores - 1 // Stack for the secondary core = Number of Cores - 1
LoadConstantToReg (FixedPcdGet32(PcdCoreCount), x0) MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
sub x0, x0, #1
LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x1)
mul x1, x1, x0
sub x12, x12, x1 sub x12, x12, x1
// x12 = The base of the MpCore Stacks (primary stack & secondary stacks) // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)
mov x0, x12 mov x0, x12
mov x1, x10 mov x1, x10
//ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize) //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2) MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x3) MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
bl ASM_PFX(ArmPlatformStackSet) bl ASM_PFX(ArmPlatformStackSet)
// Is it the Primary Core ? // Is it the Primary Core ?
@ -140,7 +119,7 @@ _PrepareArguments:
// Move sec startup address into a data register // Move sec startup address into a data register
// Ensure we're jumping to FV version of the code (not boot remapped alias) // Ensure we're jumping to FV version of the code (not boot remapped alias)
ldr x4, StartupAddr ldr x4, =ASM_PFX(CEntryPoint)
// Jump to PrePiCore C code // Jump to PrePiCore C code
// x0 = MpId // x0 = MpId
@ -150,3 +129,5 @@ _PrepareArguments:
_NeverReturn: _NeverReturn:
b _NeverReturn b _NeverReturn
ASM_PFX(mSystemMemoryEnd): .8byte 0

View File

@ -12,28 +12,12 @@
// //
#include <AsmMacroIoLib.h> #include <AsmMacroIoLib.h>
#include <Base.h>
#include <Library/PcdLib.h>
#include <AutoGen.h>
#include <Chipset/ArmV7.h> #include <Chipset/ArmV7.h>
.text
.align 3
GCC_ASM_IMPORT(CEntryPoint)
GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)
GCC_ASM_IMPORT(ArmReadMpidr)
GCC_ASM_IMPORT(ArmPlatformPeiBootAction)
GCC_ASM_IMPORT(ArmPlatformStackSet)
GCC_ASM_EXPORT(_ModuleEntryPoint)
GCC_ASM_EXPORT(mSystemMemoryEnd) GCC_ASM_EXPORT(mSystemMemoryEnd)
StartupAddr: .word CEntryPoint ASM_FUNC(_ModuleEntryPoint)
mSystemMemoryEnd: .8byte 0
ASM_PFX(_ModuleEntryPoint):
// Do early platform specific actions // Do early platform specific actions
bl ASM_PFX(ArmPlatformPeiBootAction) bl ASM_PFX(ArmPlatformPeiBootAction)
@ -57,10 +41,8 @@ _SystemMemoryEndInit:
cmp r1, #0 cmp r1, #0
bne _SetupStackPosition bne _SetupStackPosition
LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1) MOV32 (r1, FixedPcdGet32(PcdSystemMemoryBase) + FixedPcdGet32(PcdSystemMemorySize) - 1)
LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
sub r2, r2, #1
add r1, r1, r2
// Update the global variable // Update the global variable
adr r2, mSystemMemoryEnd adr r2, mSystemMemoryEnd
str r1, [r2] str r1, [r2]
@ -69,13 +51,12 @@ _SetupStackPosition:
// r1 = SystemMemoryTop // r1 = SystemMemoryTop
// Calculate Top of the Firmware Device // Calculate Top of the Firmware Device
LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2) MOV32 (r2, FixedPcdGet32(PcdFdBaseAddress))
LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3) MOV32 (r3, FixedPcdGet32(PcdFdSize) - 1)
sub r3, r3, #1
add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
// UEFI Memory Size (stacks are allocated in this region) // UEFI Memory Size (stacks are allocated in this region)
LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4) MOV32 (r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
// //
// Reserve the memory for the UEFI region (contain stacks on its top) // Reserve the memory for the UEFI region (contain stacks on its top)
@ -106,9 +87,8 @@ _SetupAlignedStack:
_SetupOverflowStack: _SetupOverflowStack:
// Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
// aligned (4KB) // aligned (4KB)
LoadConstantToReg (EFI_PAGE_MASK, r9) MOV32 (r9, ~EFI_PAGE_MASK & 0xFFFFFFFF)
and r9, r9, r1 and r1, r1, r9
sub r1, r1, r9
_GetBaseUefiMemory: _GetBaseUefiMemory:
// Calculate the Base of the UEFI Memory // Calculate the Base of the UEFI Memory
@ -117,22 +97,19 @@ _GetBaseUefiMemory:
_GetStackBase: _GetStackBase:
// r1 = The top of the Mpcore Stacks // r1 = The top of the Mpcore Stacks
// Stack for the primary core = PrimaryCoreStack // Stack for the primary core = PrimaryCoreStack
LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2) MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
sub r10, r1, r2 sub r10, r1, r2
// Stack for the secondary core = Number of Cores - 1 // Stack for the secondary core = Number of Cores - 1
LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0) MOV32 (r0, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
sub r0, r0, #1
LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)
mul r1, r1, r0
sub r10, r10, r1 sub r10, r10, r1
// r10 = The base of the MpCore Stacks (primary stack & secondary stacks) // r10 = The base of the MpCore Stacks (primary stack & secondary stacks)
mov r0, r10 mov r0, r10
mov r1, r8 mov r1, r8
//ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize) //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2) MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3) MOV32 (r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
bl ASM_PFX(ArmPlatformStackSet) bl ASM_PFX(ArmPlatformStackSet)
// Is it the Primary Core ? // Is it the Primary Core ?
@ -149,7 +126,7 @@ _PrepareArguments:
// Move sec startup address into a data register // Move sec startup address into a data register
// Ensure we're jumping to FV version of the code (not boot remapped alias) // Ensure we're jumping to FV version of the code (not boot remapped alias)
ldr r4, StartupAddr ldr r4, =ASM_PFX(CEntryPoint)
// Jump to PrePiCore C code // Jump to PrePiCore C code
// r0 = MpId // r0 = MpId
@ -160,3 +137,4 @@ _PrepareArguments:
_NeverReturn: _NeverReturn:
b _NeverReturn b _NeverReturn
ASM_PFX(mSystemMemoryEnd): .8byte 0