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