2 * Main file supporting the transition to PEI Core in Normal World for Versatile Express
4 * Copyright (c) 2011, ARM Limited. All rights reserved.
6 * This program and the accompanying materials
7 * are licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/DebugAgentLib.h>
18 #include <Library/PrintLib.h>
19 #include <Library/ArmLib.h>
20 #include <Library/SerialPortLib.h>
22 #include <Ppi/ArmGlobalVariable.h>
24 #include "PrePeiCore.h"
26 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi
= { PrePeiCoreTemporaryRamSupport
};
27 ARM_GLOBAL_VARIABLE_PPI mGlobalVariablePpi
= { PrePeiCoreGetGlobalVariableMemory
};
29 EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable
[] = {
31 EFI_PEI_PPI_DESCRIPTOR_PPI
,
32 &gEfiTemporaryRamSupportPpiGuid
,
33 &mTemporaryRamSupportPpi
36 EFI_PEI_PPI_DESCRIPTOR_PPI
,
37 &gArmGlobalVariablePpiGuid
,
44 OUT UINTN
*PpiListSize
,
45 OUT EFI_PEI_PPI_DESCRIPTOR
**PpiList
48 EFI_PEI_PPI_DESCRIPTOR
*PlatformPpiList
;
49 UINTN PlatformPpiListSize
;
51 EFI_PEI_PPI_DESCRIPTOR
*LastPpi
;
53 // Get the Platform PPIs
54 PlatformPpiListSize
= 0;
55 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize
, &PlatformPpiList
);
57 // Copy the Common and Platform PPis in Temporrary Memory
58 ListBase
= PcdGet32 (PcdCPUCoresStackBase
);
59 CopyMem ((VOID
*)ListBase
, gCommonPpiTable
, sizeof(gCommonPpiTable
));
60 CopyMem ((VOID
*)(ListBase
+ sizeof(gCommonPpiTable
)), PlatformPpiList
, PlatformPpiListSize
);
62 // Set the Terminate flag on the last PPI entry
63 LastPpi
= (EFI_PEI_PPI_DESCRIPTOR
*)ListBase
+ ((sizeof(gCommonPpiTable
) + PlatformPpiListSize
) / sizeof(EFI_PEI_PPI_DESCRIPTOR
)) - 1;
64 LastPpi
->Flags
|= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
66 *PpiList
= (EFI_PEI_PPI_DESCRIPTOR
*)ListBase
;
67 *PpiListSize
= sizeof(gCommonPpiTable
) + PlatformPpiListSize
;
73 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
77 ArmCleanInvalidateDataCache();
79 //Invalidate instruction cache
80 ArmInvalidateInstructionCache();
82 // Enable Instruction & Data caches
83 ArmEnableDataCache ();
84 ArmEnableInstructionCache ();
87 // Note: Doesn't have to Enable CPU interface in non-secure world,
88 // as Non-secure interface is already enabled in Secure world.
91 // Write VBAR - The Vector table must be 32-byte aligned
92 ASSERT(((UINT32
)PeiVectorTable
& ((1 << 5)-1)) == 0);
93 ArmWriteVBar((UINT32
)PeiVectorTable
);
95 //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.
97 // If not primary Jump to Secondary Main
98 if (IS_PRIMARY_CORE(MpId
)) {
99 // Initialize the Debug Agent for Source Level Debugging
100 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
101 SaveAndSetDebugTimerInterrupt (TRUE
);
103 // Initialize the platform specific controllers
104 ArmPlatformInitialize (MpId
);
106 // Goto primary Main.
107 PrimaryMain (PeiCoreEntryPoint
);
109 SecondaryMain (MpId
);
112 // PEI Core should always load and never return
118 PrePeiCoreTemporaryRamSupport (
119 IN CONST EFI_PEI_SERVICES
**PeiServices
,
120 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
121 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
130 OldHeap
= (VOID
*)(UINTN
)TemporaryMemoryBase
;
131 NewHeap
= (VOID
*)((UINTN
)PermanentMemoryBase
+ (CopySize
>> 1));
133 OldStack
= (VOID
*)((UINTN
)TemporaryMemoryBase
+ (CopySize
>> 1));
134 NewStack
= (VOID
*)(UINTN
)PermanentMemoryBase
;
137 // Migrate the temporary memory stack to permanent memory stack.
139 CopyMem (NewStack
, OldStack
, CopySize
>> 1);
142 // Migrate the temporary memory heap to permanent memory heap.
144 CopyMem (NewHeap
, OldHeap
, CopySize
>> 1);
146 SecSwitchStack ((UINTN
)NewStack
- (UINTN
)OldStack
);
152 PrePeiCoreGetGlobalVariableMemory (
153 OUT EFI_PHYSICAL_ADDRESS
*GlobalVariableBase
156 ASSERT (GlobalVariableBase
!= NULL
);
158 *GlobalVariableBase
= (UINTN
)PcdGet32 (PcdCPUCoresStackBase
) +
159 (UINTN
)PcdGet32 (PcdCPUCorePrimaryStackSize
) -
160 (UINTN
)PcdGet32 (PcdPeiGlobalVariableSize
);
166 PeiCommonExceptionEntry (
176 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"Reset Exception at 0x%X\n\r",LR
);
179 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"Undefined Exception at 0x%X\n\r",LR
);
182 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"SWI Exception at 0x%X\n\r",LR
);
185 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"PrefetchAbort Exception at 0x%X\n\r",LR
);
188 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"DataAbort Exception at 0x%X\n\r",LR
);
191 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"Reserved Exception at 0x%X\n\r",LR
);
194 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"IRQ Exception at 0x%X\n\r",LR
);
197 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"FIQ Exception at 0x%X\n\r",LR
);
200 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"Unknown Exception at 0x%X\n\r",LR
);
203 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);