]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePeiCore/PrePeiCore.c
0b7f973d53c94ef98f2c6c5b94b377c8f54ad94d
[mirror_edk2.git] / ArmPlatformPkg / PrePeiCore / PrePeiCore.c
1 /** @file
2 * Main file supporting the transition to PEI Core in Normal World for Versatile Express
3 *
4 * Copyright (c) 2011, ARM Limited. All rights reserved.
5 *
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
10 *
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.
13 *
14 **/
15
16 #include <Library/IoLib.h>
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugAgentLib.h>
20 #include <Library/PrintLib.h>
21 #include <Library/ArmLib.h>
22 #include <Library/SerialPortLib.h>
23 #include <Chipset/ArmV7.h>
24
25 #include "PrePeiCore.h"
26
27 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};
28
29 EFI_PEI_PPI_DESCRIPTOR gSecPpiTable[] = {
30 {
31 EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
32 &gEfiTemporaryRamSupportPpiGuid,
33 &mSecTemporaryRamSupportPpi
34 }
35 };
36
37 VOID
38 CEntryPoint (
39 IN UINTN CoreId,
40 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
41 )
42 {
43 //Clean Data cache
44 ArmCleanInvalidateDataCache();
45
46 //Invalidate instruction cache
47 ArmInvalidateInstructionCache();
48
49 // Enable Instruction & Data caches
50 ArmEnableDataCache ();
51 ArmEnableInstructionCache ();
52
53 //
54 // Note: Doesn't have to Enable CPU interface in non-secure world,
55 // as Non-secure interface is already enabled in Secure world.
56 //
57
58 // Write VBAR - The Vector table must be 32-byte aligned
59 ASSERT(((UINT32)PeiVectorTable & ((1 << 5)-1)) == 0);
60 ArmWriteVBar((UINT32)PeiVectorTable);
61
62 //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.
63
64 //If not primary Jump to Secondary Main
65 if(0 == CoreId) {
66 // Initialize the Debug Agent for Source Level Debugging
67 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
68 SaveAndSetDebugTimerInterrupt (TRUE);
69
70 // Goto primary Main.
71 PrimaryMain (PeiCoreEntryPoint);
72 } else {
73 SecondaryMain (CoreId);
74 }
75
76 // PEI Core should always load and never return
77 ASSERT (FALSE);
78 }
79
80 EFI_STATUS
81 EFIAPI
82 SecTemporaryRamSupport (
83 IN CONST EFI_PEI_SERVICES **PeiServices,
84 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
85 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
86 IN UINTN CopySize
87 )
88 {
89 //
90 // Migrate the whole temporary memory to permenent memory.
91 //
92 CopyMem (
93 (VOID*)(UINTN)PermanentMemoryBase,
94 (VOID*)(UINTN)TemporaryMemoryBase,
95 CopySize
96 );
97
98 SecSwitchStack((UINTN)(PermanentMemoryBase - TemporaryMemoryBase));
99
100 return EFI_SUCCESS;
101 }
102
103 VOID
104 PeiCommonExceptionEntry (
105 IN UINT32 Entry,
106 IN UINT32 LR
107 )
108 {
109 CHAR8 Buffer[100];
110 UINTN CharCount;
111
112 switch (Entry) {
113 case 0:
114 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);
115 break;
116 case 1:
117 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);
118 break;
119 case 2:
120 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);
121 break;
122 case 3:
123 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);
124 break;
125 case 4:
126 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);
127 break;
128 case 5:
129 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);
130 break;
131 case 6:
132 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);
133 break;
134 case 7:
135 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);
136 break;
137 default:
138 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);
139 break;
140 }
141 SerialPortWrite ((UINT8 *) Buffer, CharCount);
142 while(1);
143 }