1 /**@file 2 3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> 4 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 <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 43 typedef struct { 44 EFI_PHYSICAL_ADDRESS Address; 45 UINT64 Size; 46 } NT_FD_INFO; 47 48 typedef 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 55 typedef struct { 56 CHAR8 *PdbPointer; 57 VOID *ModHandle; 58 } PDB_NAME_TO_MOD_HANDLE; 59 60 61 62 63 EFI_STATUS 64 EFIAPI 65 SecWinNtPeiLoadFile ( 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 73 Routine Description: 74 75 TODO: Add function description 76 77 Arguments: 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 84 Returns: 85 86 TODO: add return values 87 88 --*/ 89 ; 90 91 EFI_STATUS 92 EFIAPI 93 SecWinNtPeiAutoScan ( 94 IN UINTN Index, 95 OUT EFI_PHYSICAL_ADDRESS *MemoryBase, 96 OUT UINT64 *MemorySize 97 ) 98 /*++ 99 100 Routine Description: 101 102 TODO: Add function description 103 104 Arguments: 105 106 Index - TODO: add argument description 107 MemoryBase - TODO: add argument description 108 MemorySize - TODO: add argument description 109 110 Returns: 111 112 TODO: add return values 113 114 --*/ 115 ; 116 117 VOID * 118 EFIAPI 119 SecWinNtWinNtThunkAddress ( 120 VOID 121 ) 122 /*++ 123 124 Routine Description: 125 126 TODO: Add function description 127 128 Arguments: 129 130 InterfaceSize - TODO: add argument description 131 InterfaceBase - TODO: add argument description 132 133 Returns: 134 135 TODO: add return values 136 137 --*/ 138 ; 139 140 EFI_STATUS 141 EFIAPI 142 SecWinNtWinNtFwhAddress ( 143 IN OUT UINT64 *FwhSize, 144 IN OUT EFI_PHYSICAL_ADDRESS *FwhBase 145 ) 146 /*++ 147 148 Routine Description: 149 150 TODO: Add function description 151 152 Arguments: 153 154 FwhSize - TODO: add argument description 155 FwhBase - TODO: add argument description 156 157 Returns: 158 159 TODO: add return values 160 161 --*/ 162 ; 163 164 EFI_STATUS 165 EFIAPI 166 SecPeiReportStatusCode ( 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 176 Routine Description: 177 178 TODO: Add function description 179 180 Arguments: 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 189 Returns: 190 191 TODO: add return values 192 193 --*/ 194 ; 195 196 INTN 197 EFIAPI 198 main ( 199 IN INTN Argc, 200 IN CHAR8 **Argv, 201 IN CHAR8 **Envp 202 ) 203 /*++ 204 205 Routine Description: 206 207 TODO: Add function description 208 209 Arguments: 210 211 Argc - TODO: add argument description 212 Argv - TODO: add argument description 213 Envp - TODO: add argument description 214 215 Returns: 216 217 TODO: add return values 218 219 --*/ 220 ; 221 222 EFI_STATUS 223 WinNtOpenFile ( 224 CHAR16 *FileName, 225 UINT32 MapSize, 226 DWORD CreationDispostion, 227 EFI_PHYSICAL_ADDRESS *BaseAddress, 228 UINT64 *Length 229 ) 230 /*++ 231 232 Routine Description: 233 234 TODO: Add function description 235 236 Arguments: 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 244 Returns: 245 246 TODO: add return values 247 248 --*/ 249 ; 250 251 VOID 252 SecLoadFromCore ( 253 IN UINTN LargestRegion, 254 IN UINTN LargestRegionSize, 255 IN UINTN BootFirmwareVolumeBase, 256 IN VOID *PeiCoreFile 257 ) 258 /*++ 259 260 Routine Description: 261 262 TODO: Add function description 263 264 Arguments: 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 271 Returns: 272 273 TODO: add return values 274 275 --*/ 276 ; 277 278 EFI_STATUS 279 SecLoadFile ( 280 IN VOID *Pe32Data, 281 IN EFI_PHYSICAL_ADDRESS *ImageAddress, 282 IN UINT64 *ImageSize, 283 IN EFI_PHYSICAL_ADDRESS *EntryPoint 284 ) 285 /*++ 286 287 Routine Description: 288 289 TODO: Add function description 290 291 Arguments: 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 298 Returns: 299 300 TODO: add return values 301 302 --*/ 303 ; 304 305 EFI_STATUS 306 SecFfsFindPeiCore ( 307 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, 308 OUT VOID **Pe32Data 309 ) 310 /*++ 311 312 Routine Description: 313 314 TODO: Add function description 315 316 Arguments: 317 318 FwVolHeader - TODO: add argument description 319 Pe32Data - TODO: add argument description 320 321 Returns: 322 323 TODO: add return values 324 325 --*/ 326 ; 327 328 EFI_STATUS 329 SecFfsFindNextFile ( 330 IN EFI_FV_FILETYPE SearchType, 331 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, 332 IN OUT EFI_FFS_FILE_HEADER **FileHeader 333 ) 334 /*++ 335 336 Routine Description: 337 338 TODO: Add function description 339 340 Arguments: 341 342 SearchType - TODO: add argument description 343 FwVolHeader - TODO: add argument description 344 FileHeader - TODO: add argument description 345 346 Returns: 347 348 TODO: add return values 349 350 --*/ 351 ; 352 353 EFI_STATUS 354 SecFfsFindSectionData ( 355 IN EFI_SECTION_TYPE SectionType, 356 IN EFI_FFS_FILE_HEADER *FfsFileHeader, 357 IN OUT VOID **SectionData 358 ) 359 /*++ 360 361 Routine Description: 362 363 TODO: Add function description 364 365 Arguments: 366 367 SectionType - TODO: add argument description 368 FfsFileHeader - TODO: add argument description 369 SectionData - TODO: add argument description 370 371 Returns: 372 373 TODO: add return values 374 375 --*/ 376 ; 377 378 EFI_STATUS 379 EFIAPI 380 SecWinNtPeCoffLoaderLoadAsDll ( 381 IN CHAR8 *PdbFileName, 382 IN VOID **ImageEntryPoint, 383 OUT VOID **ModHandle 384 ) 385 /*++ 386 387 Routine Description: 388 389 TODO: Add function description 390 391 Arguments: 392 393 PdbFileName - TODO: add argument description 394 ImageEntryPoint - TODO: add argument description 395 ModHandle - TODO: add argument description 396 397 Returns: 398 399 TODO: add return values 400 401 --*/ 402 ; 403 404 EFI_STATUS 405 EFIAPI 406 SecWinNtPeCoffLoaderFreeLibrary ( 407 OUT VOID *ModHandle 408 ) 409 /*++ 410 411 Routine Description: 412 413 TODO: Add function description 414 415 Arguments: 416 417 ModHandle - TODO: add argument description 418 419 Returns: 420 421 TODO: add return values 422 423 --*/ 424 ; 425 426 EFI_STATUS 427 EFIAPI 428 SecWinNtFdAddress ( 429 IN UINTN Index, 430 IN OUT EFI_PHYSICAL_ADDRESS *FdBase, 431 IN OUT UINT64 *FdSize 432 ) 433 /*++ 434 435 Routine Description: 436 437 TODO: Add function description 438 439 Arguments: 440 441 Index - TODO: add argument description 442 FdBase - TODO: add argument description 443 FdSize - TODO: add argument description 444 445 Returns: 446 447 TODO: add return values 448 449 --*/ 450 ; 451 452 EFI_STATUS 453 GetImageReadFunction ( 454 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, 455 IN EFI_PHYSICAL_ADDRESS *TopOfMemory 456 ) 457 /*++ 458 459 Routine Description: 460 461 TODO: Add function description 462 463 Arguments: 464 465 ImageContext - TODO: add argument description 466 TopOfMemory - TODO: add argument description 467 468 Returns: 469 470 TODO: add return values 471 472 --*/ 473 ; 474 475 EFI_STATUS 476 EFIAPI 477 SecImageRead ( 478 IN VOID *FileHandle, 479 IN UINTN FileOffset, 480 IN OUT UINTN *ReadSize, 481 OUT VOID *Buffer 482 ) 483 /*++ 484 485 Routine Description: 486 487 TODO: Add function description 488 489 Arguments: 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 496 Returns: 497 498 TODO: add return values 499 500 --*/ 501 ; 502 503 CHAR16 * 504 AsciiToUnicode ( 505 IN CHAR8 *Ascii, 506 IN UINTN *StrLen OPTIONAL 507 ) 508 /*++ 509 510 Routine Description: 511 512 TODO: Add function description 513 514 Arguments: 515 516 Ascii - TODO: add argument description 517 StrLen - TODO: add argument description 518 519 Returns: 520 521 TODO: add return values 522 523 --*/ 524 ; 525 526 UINTN 527 CountSeperatorsInString ( 528 IN CONST CHAR16 *String, 529 IN CHAR16 Seperator 530 ) 531 /*++ 532 533 Routine Description: 534 535 TODO: Add function description 536 537 Arguments: 538 539 String - TODO: add argument description 540 Seperator - TODO: add argument description 541 542 Returns: 543 544 TODO: add return values 545 546 --*/ 547 ; 548 549 EFI_STATUS 550 EFIAPI 551 SecTemporaryRamSupport ( 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 559 extern EFI_WIN_NT_THUNK_PROTOCOL *gWinNt; 560