blob: 76522e3c655c96fd57d83de55d81420118bd33bb [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/**@file
2
3Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution. The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13Module Name:
14 SecMain.h
15
16Abstract:
17 Include file for Windows API based SEC
18
19**/
20
21#include <stdio.h>
22#include <PiPei.h>
23#include <WinNtPeim.h>
24#include <Guid/StatusCodeDataTypeDebug.h>
25#include <Library/BaseLib.h>
26#include <Library/PeCoffLib.h>
27#include <Ppi/NtPeiLoadFile.h>
28#include <Ppi/NtAutoscan.h>
29#include <Ppi/NtThunk.h>
30#include <Ppi/StatusCode.h>
31#include <Ppi/NtFwh.h>
32#include <Ppi/TemporaryRamSupport.h>
33#include <Library/PcdLib.h>
34#include <Library/DebugLib.h>
35#include <Library/PrintLib.h>
36#include <Library/BaseMemoryLib.h>
37#include <Library/ReportStatusCodeLib.h>
38
39#include <IndustryStandard/PeImage.h>
40
41#define STACK_SIZE 0x20000
42
43typedef struct {
44 EFI_PHYSICAL_ADDRESS Address;
45 UINT64 Size;
46} NT_FD_INFO;
47
48typedef struct {
49 EFI_PHYSICAL_ADDRESS Memory;
50 UINT64 Size;
51} NT_SYSTEM_MEMORY;
52
53#define MAX_PDB_NAME_TO_MOD_HANDLE_ARRAY_SIZE 0x100
54
55typedef struct {
56 CHAR8 *PdbPointer;
57 VOID *ModHandle;
58} PDB_NAME_TO_MOD_HANDLE;
59
60
61
62
63EFI_STATUS
64EFIAPI
65SecWinNtPeiLoadFile (
66 VOID *Pe32Data, // TODO: add IN/OUT modifier to Pe32Data
67 EFI_PHYSICAL_ADDRESS *ImageAddress, // TODO: add IN/OUT modifier to ImageAddress
68 UINT64 *ImageSize, // TODO: add IN/OUT modifier to ImageSize
69 EFI_PHYSICAL_ADDRESS *EntryPoint // TODO: add IN/OUT modifier to EntryPoint
70 )
71/*++
72
73Routine Description:
74
75 TODO: Add function description
76
77Arguments:
78
79 Pe32Data - TODO: add argument description
80 ImageAddress - TODO: add argument description
81 ImageSize - TODO: add argument description
82 EntryPoint - TODO: add argument description
83
84Returns:
85
86 TODO: add return values
87
88--*/
89;
90
91EFI_STATUS
92EFIAPI
93SecWinNtPeiAutoScan (
94 IN UINTN Index,
95 OUT EFI_PHYSICAL_ADDRESS *MemoryBase,
96 OUT UINT64 *MemorySize
97 )
98/*++
99
100Routine Description:
101
102 TODO: Add function description
103
104Arguments:
105
106 Index - TODO: add argument description
107 MemoryBase - TODO: add argument description
108 MemorySize - TODO: add argument description
109
110Returns:
111
112 TODO: add return values
113
114--*/
115;
116
117VOID *
118EFIAPI
119SecWinNtWinNtThunkAddress (
120 VOID
121 )
122/*++
123
124Routine Description:
125
126 TODO: Add function description
127
128Arguments:
129
130 InterfaceSize - TODO: add argument description
131 InterfaceBase - TODO: add argument description
132
133Returns:
134
135 TODO: add return values
136
137--*/
138;
139
140EFI_STATUS
141EFIAPI
142SecWinNtWinNtFwhAddress (
143 IN OUT UINT64 *FwhSize,
144 IN OUT EFI_PHYSICAL_ADDRESS *FwhBase
145 )
146/*++
147
148Routine Description:
149
150 TODO: Add function description
151
152Arguments:
153
154 FwhSize - TODO: add argument description
155 FwhBase - TODO: add argument description
156
157Returns:
158
159 TODO: add return values
160
161--*/
162;
163
164EFI_STATUS
165EFIAPI
166SecPeiReportStatusCode (
167 IN CONST EFI_PEI_SERVICES **PeiServices,
168 IN EFI_STATUS_CODE_TYPE CodeType,
169 IN EFI_STATUS_CODE_VALUE Value,
170 IN UINT32 Instance,
171 IN CONST EFI_GUID * CallerId,
172 IN CONST EFI_STATUS_CODE_DATA * Data OPTIONAL
173 )
174/*++
175
176Routine Description:
177
178 TODO: Add function description
179
180Arguments:
181
182 PeiServices - TODO: add argument description
183 CodeType - TODO: add argument description
184 Value - TODO: add argument description
185 Instance - TODO: add argument description
186 CallerId - TODO: add argument description
187 Data - TODO: add argument description
188
189Returns:
190
191 TODO: add return values
192
193--*/
194;
195
196INTN
197EFIAPI
198main (
199 IN INTN Argc,
200 IN CHAR8 **Argv,
201 IN CHAR8 **Envp
202 )
203/*++
204
205Routine Description:
206
207 TODO: Add function description
208
209Arguments:
210
211 Argc - TODO: add argument description
212 Argv - TODO: add argument description
213 Envp - TODO: add argument description
214
215Returns:
216
217 TODO: add return values
218
219--*/
220;
221
222EFI_STATUS
223WinNtOpenFile (
224 CHAR16 *FileName,
225 UINT32 MapSize,
226 DWORD CreationDispostion,
227 EFI_PHYSICAL_ADDRESS *BaseAddress,
228 UINT64 *Length
229 )
230/*++
231
232Routine Description:
233
234 TODO: Add function description
235
236Arguments:
237
238 FileName - TODO: add argument description
239 MapSize - TODO: add argument description
240 CreationDispostion - TODO: add argument description
241 BaseAddress - TODO: add argument description
242 Length - TODO: add argument description
243
244Returns:
245
246 TODO: add return values
247
248--*/
249;
250
251VOID
252SecLoadFromCore (
253 IN UINTN LargestRegion,
254 IN UINTN LargestRegionSize,
255 IN UINTN BootFirmwareVolumeBase,
256 IN VOID *PeiCoreFile
257 )
258/*++
259
260Routine Description:
261
262 TODO: Add function description
263
264Arguments:
265
266 LargestRegion - TODO: add argument description
267 LargestRegionSize - TODO: add argument description
268 BootFirmwareVolumeBase - TODO: add argument description
269 PeiCoreFile - TODO: add argument description
270
271Returns:
272
273 TODO: add return values
274
275--*/
276;
277
278EFI_STATUS
279SecLoadFile (
280 IN VOID *Pe32Data,
281 IN EFI_PHYSICAL_ADDRESS *ImageAddress,
282 IN UINT64 *ImageSize,
283 IN EFI_PHYSICAL_ADDRESS *EntryPoint
284 )
285/*++
286
287Routine Description:
288
289 TODO: Add function description
290
291Arguments:
292
293 Pe32Data - TODO: add argument description
294 ImageAddress - TODO: add argument description
295 ImageSize - TODO: add argument description
296 EntryPoint - TODO: add argument description
297
298Returns:
299
300 TODO: add return values
301
302--*/
303;
304
305EFI_STATUS
306SecFfsFindPeiCore (
307 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
308 OUT VOID **Pe32Data
309 )
310/*++
311
312Routine Description:
313
314 TODO: Add function description
315
316Arguments:
317
318 FwVolHeader - TODO: add argument description
319 Pe32Data - TODO: add argument description
320
321Returns:
322
323 TODO: add return values
324
325--*/
326;
327
328EFI_STATUS
329SecFfsFindNextFile (
330 IN EFI_FV_FILETYPE SearchType,
331 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
332 IN OUT EFI_FFS_FILE_HEADER **FileHeader
333 )
334/*++
335
336Routine Description:
337
338 TODO: Add function description
339
340Arguments:
341
342 SearchType - TODO: add argument description
343 FwVolHeader - TODO: add argument description
344 FileHeader - TODO: add argument description
345
346Returns:
347
348 TODO: add return values
349
350--*/
351;
352
353EFI_STATUS
354SecFfsFindSectionData (
355 IN EFI_SECTION_TYPE SectionType,
356 IN EFI_FFS_FILE_HEADER *FfsFileHeader,
357 IN OUT VOID **SectionData
358 )
359/*++
360
361Routine Description:
362
363 TODO: Add function description
364
365Arguments:
366
367 SectionType - TODO: add argument description
368 FfsFileHeader - TODO: add argument description
369 SectionData - TODO: add argument description
370
371Returns:
372
373 TODO: add return values
374
375--*/
376;
377
378EFI_STATUS
379EFIAPI
380SecWinNtPeCoffLoaderLoadAsDll (
381 IN CHAR8 *PdbFileName,
382 IN VOID **ImageEntryPoint,
383 OUT VOID **ModHandle
384 )
385/*++
386
387Routine Description:
388
389 TODO: Add function description
390
391Arguments:
392
393 PdbFileName - TODO: add argument description
394 ImageEntryPoint - TODO: add argument description
395 ModHandle - TODO: add argument description
396
397Returns:
398
399 TODO: add return values
400
401--*/
402;
403
404EFI_STATUS
405EFIAPI
406SecWinNtPeCoffLoaderFreeLibrary (
407 OUT VOID *ModHandle
408 )
409/*++
410
411Routine Description:
412
413 TODO: Add function description
414
415Arguments:
416
417 ModHandle - TODO: add argument description
418
419Returns:
420
421 TODO: add return values
422
423--*/
424;
425
426EFI_STATUS
427EFIAPI
428SecWinNtFdAddress (
429 IN UINTN Index,
430 IN OUT EFI_PHYSICAL_ADDRESS *FdBase,
431 IN OUT UINT64 *FdSize
432 )
433/*++
434
435Routine Description:
436
437 TODO: Add function description
438
439Arguments:
440
441 Index - TODO: add argument description
442 FdBase - TODO: add argument description
443 FdSize - TODO: add argument description
444
445Returns:
446
447 TODO: add return values
448
449--*/
450;
451
452EFI_STATUS
453GetImageReadFunction (
454 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
455 IN EFI_PHYSICAL_ADDRESS *TopOfMemory
456 )
457/*++
458
459Routine Description:
460
461 TODO: Add function description
462
463Arguments:
464
465 ImageContext - TODO: add argument description
466 TopOfMemory - TODO: add argument description
467
468Returns:
469
470 TODO: add return values
471
472--*/
473;
474
475EFI_STATUS
476EFIAPI
477SecImageRead (
478 IN VOID *FileHandle,
479 IN UINTN FileOffset,
480 IN OUT UINTN *ReadSize,
481 OUT VOID *Buffer
482 )
483/*++
484
485Routine Description:
486
487 TODO: Add function description
488
489Arguments:
490
491 FileHandle - TODO: add argument description
492 FileOffset - TODO: add argument description
493 ReadSize - TODO: add argument description
494 Buffer - TODO: add argument description
495
496Returns:
497
498 TODO: add return values
499
500--*/
501;
502
503CHAR16 *
504AsciiToUnicode (
505 IN CHAR8 *Ascii,
506 IN UINTN *StrLen OPTIONAL
507 )
508/*++
509
510Routine Description:
511
512 TODO: Add function description
513
514Arguments:
515
516 Ascii - TODO: add argument description
517 StrLen - TODO: add argument description
518
519Returns:
520
521 TODO: add return values
522
523--*/
524;
525
526UINTN
527CountSeperatorsInString (
528 IN CONST CHAR16 *String,
529 IN CHAR16 Seperator
530 )
531/*++
532
533Routine Description:
534
535 TODO: Add function description
536
537Arguments:
538
539 String - TODO: add argument description
540 Seperator - TODO: add argument description
541
542Returns:
543
544 TODO: add return values
545
546--*/
547;
548
549EFI_STATUS
550EFIAPI
551SecTemporaryRamSupport (
552 IN CONST EFI_PEI_SERVICES **PeiServices,
553 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
554 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
555 IN UINTN CopySize
556 );
557
558
559extern EFI_WIN_NT_THUNK_PROTOCOL *gWinNt;