]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePeiCore/PrePeiCore.c
ArmPlatformPkg: Introduce ArmPlatformGlobalVariableLib
[mirror_edk2.git] / ArmPlatformPkg / PrePeiCore / PrePeiCore.c
CommitLineData
1d5d0ae9 1/** @file\r
2* Main file supporting the transition to PEI Core in Normal World for Versatile Express\r
3*\r
4* Copyright (c) 2011, ARM Limited. All rights reserved.\r
5* \r
6* This program and the accompanying materials \r
7* are licensed and made available under the terms and conditions of the BSD License \r
8* which accompanies this distribution. The full text of the license may be found at \r
9* http://opensource.org/licenses/bsd-license.php \r
10*\r
11* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
12* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
13*\r
14**/\r
15\r
1d5d0ae9 16#include <Library/BaseLib.h>\r
a6caee65 17#include <Library/DebugAgentLib.h>\r
f598bf12 18#include <Library/PrintLib.h>\r
1d5d0ae9 19#include <Library/ArmLib.h>\r
f598bf12 20#include <Library/SerialPortLib.h>\r
8fc38a3f 21\r
22#include <Ppi/ArmGlobalVariable.h>\r
1d5d0ae9 23#include <Chipset/ArmV7.h>\r
24\r
f598bf12 25#include "PrePeiCore.h"\r
1d5d0ae9 26\r
80ddb68d 27EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};\r
8fc38a3f 28ARM_GLOBAL_VARIABLE_PPI mGlobalVariablePpi = { PrePeiCoreGetGlobalVariableMemory };\r
1d5d0ae9 29\r
8fc38a3f 30EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {\r
1d5d0ae9 31 {\r
8fc38a3f 32 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
1d5d0ae9 33 &gEfiTemporaryRamSupportPpiGuid,\r
34 &mSecTemporaryRamSupportPpi\r
8fc38a3f 35 },\r
36 {\r
37 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
38 &gArmGlobalVariablePpiGuid,\r
39 &mGlobalVariablePpi\r
1d5d0ae9 40 }\r
41};\r
42\r
1d5d0ae9 43VOID\r
44CEntryPoint (\r
0787bc61 45 IN UINTN MpId,\r
1d5d0ae9 46 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint\r
47 )\r
48{\r
49 //Clean Data cache\r
50 ArmCleanInvalidateDataCache();\r
51\r
52 //Invalidate instruction cache\r
53 ArmInvalidateInstructionCache();\r
54\r
55 // Enable Instruction & Data caches\r
f598bf12 56 ArmEnableDataCache ();\r
57 ArmEnableInstructionCache ();\r
1d5d0ae9 58\r
59 //\r
60 // Note: Doesn't have to Enable CPU interface in non-secure world,\r
61 // as Non-secure interface is already enabled in Secure world.\r
62 //\r
63\r
64 // Write VBAR - The Vector table must be 32-byte aligned\r
65 ASSERT(((UINT32)PeiVectorTable & ((1 << 5)-1)) == 0);\r
66 ArmWriteVBar((UINT32)PeiVectorTable);\r
67\r
68 //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.\r
69\r
70 //If not primary Jump to Secondary Main\r
0787bc61 71 if (IS_PRIMARY_CORE(MpId)) {\r
a6caee65 72 // Initialize the Debug Agent for Source Level Debugging\r
73 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
74 SaveAndSetDebugTimerInterrupt (TRUE);\r
75\r
76 // Goto primary Main.\r
f598bf12 77 PrimaryMain (PeiCoreEntryPoint);\r
1d5d0ae9 78 } else {\r
0787bc61 79 SecondaryMain (MpId);\r
1d5d0ae9 80 }\r
81\r
82 // PEI Core should always load and never return\r
83 ASSERT (FALSE);\r
84}\r
85\r
86EFI_STATUS\r
87EFIAPI\r
88SecTemporaryRamSupport (\r
89 IN CONST EFI_PEI_SERVICES **PeiServices,\r
90 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
91 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
92 IN UINTN CopySize\r
93 )\r
94{\r
95 //\r
96 // Migrate the whole temporary memory to permenent memory.\r
f598bf12 97 //\r
1d5d0ae9 98 CopyMem (\r
99 (VOID*)(UINTN)PermanentMemoryBase, \r
100 (VOID*)(UINTN)TemporaryMemoryBase, \r
101 CopySize\r
102 );\r
103\r
104 SecSwitchStack((UINTN)(PermanentMemoryBase - TemporaryMemoryBase));\r
105\r
8fc38a3f 106EFI_STATUS\r
107PrePeiCoreGetGlobalVariableMemory (\r
108 OUT EFI_PHYSICAL_ADDRESS *GlobalVariableBase\r
109 )\r
110{\r
111 ASSERT (GlobalVariableBase != NULL);\r
112\r
113 *GlobalVariableBase = (UINTN)PcdGet32 (PcdCPUCoresStackBase) +\r
114 (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) -\r
115 (UINTN)PcdGet32 (PcdPeiGlobalVariableSize);\r
116\r
1d5d0ae9 117 return EFI_SUCCESS;\r
118}\r
119\r
2637d1ef 120VOID\r
121PeiCommonExceptionEntry (\r
122 IN UINT32 Entry,\r
123 IN UINT32 LR\r
124 )\r
125{\r
126 CHAR8 Buffer[100];\r
127 UINTN CharCount;\r
128\r
1d5d0ae9 129 switch (Entry) {\r
130 case 0:\r
2637d1ef 131 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
1d5d0ae9 132 break;\r
133 case 1:\r
2637d1ef 134 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
1d5d0ae9 135 break;\r
136 case 2:\r
2637d1ef 137 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
1d5d0ae9 138 break;\r
139 case 3:\r
2637d1ef 140 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
1d5d0ae9 141 break;\r
142 case 4:\r
2637d1ef 143 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
1d5d0ae9 144 break;\r
145 case 5:\r
2637d1ef 146 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
1d5d0ae9 147 break;\r
148 case 6:\r
2637d1ef 149 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
1d5d0ae9 150 break;\r
151 case 7:\r
2637d1ef 152 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
1d5d0ae9 153 break;\r
154 default:\r
2637d1ef 155 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
1d5d0ae9 156 break;\r
157 }\r
2637d1ef 158 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
1d5d0ae9 159 while(1);\r
160}\r