Fix the build break in two open source packages caused by check in 10660.
[mirror_edk2.git] / ArmRealViewEbPkg / Sec / Sec.c
1 /** @file
2 C Entry point for the SEC. First C code after the reset vector.
3
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
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 <PiPei.h>
17
18 #include <Library/DebugLib.h>
19 #include <Library/PrePiLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/IoLib.h>
22 #include <Library/ArmLib.h>
23 #include <Library/PeCoffGetEntryPointLib.h>
24 #include <Library/DebugAgentLib.h>
25
26 #include <Ppi/GuidedSectionExtraction.h>
27 #include <Guid/LzmaDecompress.h>
28
29 #include <ArmEb/ArmEb.h>
30
31 #include "LzmaDecompress.h"
32
33 VOID
34 EFIAPI
35 _ModuleEntryPoint(
36 VOID
37 );
38
39 CHAR8 *
40 DeCygwinPathIfNeeded (
41 IN CHAR8 *Name
42 );
43
44 RETURN_STATUS
45 EFIAPI
46 SerialPortInitialize (
47 VOID
48 );
49
50
51 VOID
52 UartInit (
53 VOID
54 )
55 {
56 // SEC phase needs to run library constructors by hand.
57 // This assumes we are linked agains the SerialLib
58 // In non SEC modules the init call is in autogenerated code.
59 SerialPortInitialize ();
60 }
61
62 VOID
63 TimerInit (
64 VOID
65 )
66 {
67 // configure SP810 to use 1MHz clock and disable
68 MmioAndThenOr32 (EB_SP810_CTRL_BASE + SP810_SYS_CTRL_REG, ~SP810_SYS_CTRL_TIMER2_EN, SP810_SYS_CTRL_TIMER2_TIMCLK);
69 // Enable
70 MmioOr32 (EB_SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER2_EN);
71
72 // configure timer 2 for one shot operation, 32 bits, no prescaler, and interrupt disabled
73 MmioOr32 (EB_SP804_TIMER2_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ONESHOT | SP804_TIMER_CTRL_32BIT | SP804_PRESCALE_DIV_1);
74
75 // preload the timer count register
76 MmioWrite32 (EB_SP804_TIMER2_BASE + SP804_TIMER_LOAD_REG, 1);
77
78 // enable the timer
79 MmioOr32 (EB_SP804_TIMER2_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);
80 }
81
82
83 VOID
84 InitCache (
85 IN UINT32 MemoryBase,
86 IN UINT32 MemoryLength
87 );
88
89 EFI_STATUS
90 EFIAPI
91 ExtractGuidedSectionLibConstructor (
92 VOID
93 );
94
95 EFI_STATUS
96 EFIAPI
97 LzmaDecompressLibConstructor (
98 VOID
99 );
100
101
102 VOID
103 CEntryPoint (
104 IN VOID *MemoryBase,
105 IN UINTN MemorySize,
106 IN VOID *StackBase,
107 IN UINTN StackSize
108 )
109 {
110 VOID *HobBase;
111
112 // HOB list is at bottom of stack area
113 // Stack grows from top-to-bottom towards HOB list
114 HobBase = (VOID *)StackBase;
115 CreateHobList (MemoryBase, MemorySize, HobBase, StackBase);
116
117 // Turn off remapping NOR to 0. We can will now see DRAM in low memory
118 MmioOr32 (0x10001000 ,BIT8); //EB_SP810_CTRL_BASE
119
120 // Enable program flow prediction, if supported.
121 ArmEnableBranchPrediction ();
122
123 // Initialize CPU cache
124 InitCache ((UINT32)MemoryBase, (UINT32)MemorySize);
125
126 // Add memory allocation hob for relocated FD
127 BuildMemoryAllocationHob (FixedPcdGet32(PcdEmbeddedFdBaseAddress), FixedPcdGet32(PcdEmbeddedFdSize), EfiBootServicesData);
128
129 // Add the FVs to the hob list
130 BuildFvHob (PcdGet32(PcdFlashFvMainBase), PcdGet32(PcdFlashFvMainSize));
131
132 // Start talking
133 UartInit ();
134
135 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL);
136 SaveAndSetDebugTimerInterrupt (TRUE);
137
138 DEBUG ((EFI_D_ERROR, "UART Enabled\n"));
139
140 // Start up a free running timer so that the timer lib will work
141 TimerInit ();
142
143 // SEC phase needs to run library constructors by hand.
144 ExtractGuidedSectionLibConstructor ();
145 LzmaDecompressLibConstructor ();
146
147 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
148 BuildPeCoffLoaderHob ();
149 BuildExtractSectionHob (
150 &gLzmaCustomDecompressGuid,
151 LzmaGuidedSectionGetInfo,
152 LzmaGuidedSectionExtraction
153 );
154
155 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
156 DecompressFirstFv ();
157
158 // Load the DXE Core and transfer control to it
159 LoadDxeCoreFromFv (NULL, 0);
160
161 // DXE Core should always load and never return
162 ASSERT (FALSE);
163 }
164