2 C Entry point for the SEC. First C code after the reset vector.
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
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.
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>
26 #include <Ppi/GuidedSectionExtraction.h>
27 #include <Guid/LzmaDecompress.h>
29 #include <ArmEb/ArmEb.h>
31 #include "LzmaDecompress.h"
40 DeCygwinPathIfNeeded (
46 SerialPortInitialize (
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 ();
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
);
70 MmioOr32 (EB_SP810_CTRL_BASE
+ SP810_SYS_CTRL_REG
, SP810_SYS_CTRL_TIMER2_EN
);
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
);
75 // preload the timer count register
76 MmioWrite32 (EB_SP804_TIMER2_BASE
+ SP804_TIMER_LOAD_REG
, 1);
79 MmioOr32 (EB_SP804_TIMER2_BASE
+ SP804_TIMER_CONTROL_REG
, SP804_TIMER_CTRL_ENABLE
);
86 IN UINT32 MemoryLength
91 ExtractGuidedSectionLibConstructor (
97 LzmaDecompressLibConstructor (
112 // Build a basic HOB list
113 HobBase
= (VOID
*)(UINTN
)(FixedPcdGet32(PcdEmbeddedFdBaseAddress
) + FixedPcdGet32(PcdEmbeddedFdSize
));
114 CreateHobList (MemoryBase
, MemorySize
, HobBase
, StackBase
);
117 // Enable program flow prediction, if supported.
118 ArmEnableBranchPrediction ();
120 // Initialize CPU cache
121 InitCache ((UINT32
)MemoryBase
, (UINT32
)MemorySize
);
123 // Add memory allocation hob for relocated FD
124 BuildMemoryAllocationHob (FixedPcdGet32(PcdEmbeddedFdBaseAddress
), FixedPcdGet32(PcdEmbeddedFdSize
), EfiBootServicesData
);
126 // Add the FVs to the hob list
127 BuildFvHob (PcdGet32(PcdFlashFvMainBase
), PcdGet32(PcdFlashFvMainSize
));
132 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, NULL
);
133 SaveAndSetDebugTimerInterrupt (TRUE
);
135 DEBUG ((EFI_D_ERROR
, "UART Enabled\n"));
137 // Start up a free running timer so that the timer lib will work
140 // SEC phase needs to run library constructors by hand.
141 ExtractGuidedSectionLibConstructor ();
142 LzmaDecompressLibConstructor ();
144 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
145 BuildPeCoffLoaderHob ();
146 BuildExtractSectionHob (
147 &gLzmaCustomDecompressGuid
,
148 LzmaGuidedSectionGetInfo
,
149 LzmaGuidedSectionExtraction
152 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
153 DecompressFirstFv ();
155 // Load the DXE Core and transfer control to it
156 LoadDxeCoreFromFv (NULL
, 0);
158 // DXE Core should always load and never return