Initial import.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
bbahnsen
2006-04-21 22:54:32 +00:00
commit 878ddf1fc3
2651 changed files with 624620 additions and 0 deletions

View File

@@ -0,0 +1,495 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CommonLib.c
Abstract:
Common Library Functions
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "CommonLib.h"
VOID
PeiZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
/*++
Routine Description:
Set Buffer to zero for Size bytes.
Arguments:
Buffer - Memory to set.
Size - Number of bytes to set
Returns:
None
--*/
{
INT8 *Ptr;
Ptr = Buffer;
while (Size--) {
*(Ptr++) = 0;
}
}
VOID
PeiCopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
/*++
Routine Description:
Copy Length bytes from Source to Destination.
Arguments:
Destination - Target of copy
Source - Place to copy from
Length - Number of bytes to copy
Returns:
None
--*/
{
CHAR8 *Destination8;
CHAR8 *Source8;
Destination8 = Destination;
Source8 = Source;
while (Length--) {
*(Destination8++) = *(Source8++);
}
}
VOID
ZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
{
PeiZeroMem (Buffer, Size);
}
VOID
CopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
{
PeiCopyMem (Destination, Source, Length);
}
INTN
CompareGuid (
IN EFI_GUID *Guid1,
IN EFI_GUID *Guid2
)
/*++
Routine Description:
Compares to GUIDs
Arguments:
Guid1 - guid to compare
Guid2 - guid to compare
Returns:
= 0 if Guid1 == Guid2
!= 0 if Guid1 != Guid2
--*/
{
INT32 *g1;
INT32 *g2;
INT32 r;
//
// Compare 32 bits at a time
//
g1 = (INT32 *) Guid1;
g2 = (INT32 *) Guid2;
r = g1[0] - g2[0];
r |= g1[1] - g2[1];
r |= g1[2] - g2[2];
r |= g1[3] - g2[3];
return r;
}
EFI_STATUS
GetFileImage (
IN CHAR8 *InputFileName,
OUT CHAR8 **InputFileImage,
OUT UINT32 *BytesRead
)
/*++
Routine Description:
This function opens a file and reads it into a memory buffer. The function
will allocate the memory buffer and returns the size of the buffer.
Arguments:
InputFileName The name of the file to read.
InputFileImage A pointer to the memory buffer.
BytesRead The size of the memory buffer.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the input parameters was invalid.
EFI_ABORTED An error occurred.
EFI_OUT_OF_RESOURCES No resource to complete operations.
--*/
{
FILE *InputFile;
UINT32 FileSize;
//
// Verify input parameters.
//
if (InputFileName == NULL || strlen (InputFileName) == 0 || InputFileImage == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Open the file and copy contents into a memory buffer.
//
//
// Open the file
//
InputFile = fopen (InputFileName, "rb");
if (InputFile == NULL) {
printf ("ERROR: Could not open input file \"%s\".\n", InputFileName);
return EFI_ABORTED;
}
//
// Go to the end so that we can determine the file size
//
if (fseek (InputFile, 0, SEEK_END)) {
printf ("ERROR: System error reading input file \"%s\".\n", InputFileName);
fclose (InputFile);
return EFI_ABORTED;
}
//
// Get the file size
//
FileSize = ftell (InputFile);
if (FileSize == -1) {
printf ("ERROR: System error parsing input file \"%s\".\n", InputFileName);
fclose (InputFile);
return EFI_ABORTED;
}
//
// Allocate a buffer
//
*InputFileImage = malloc (FileSize);
if (*InputFileImage == NULL) {
fclose (InputFile);
return EFI_OUT_OF_RESOURCES;
}
//
// Reset to the beginning of the file
//
if (fseek (InputFile, 0, SEEK_SET)) {
printf ("ERROR: System error reading input file \"%s\".\n", InputFileName);
fclose (InputFile);
free (*InputFileImage);
*InputFileImage = NULL;
return EFI_ABORTED;
}
//
// Read all of the file contents.
//
*BytesRead = fread (*InputFileImage, sizeof (UINT8), FileSize, InputFile);
if (*BytesRead != sizeof (UINT8) * FileSize) {
printf ("ERROR: Reading file \"%s\"%i.\n", InputFileName);
fclose (InputFile);
free (*InputFileImage);
*InputFileImage = NULL;
return EFI_ABORTED;
}
//
// Close the file
//
fclose (InputFile);
return EFI_SUCCESS;
}
UINT8
CalculateChecksum8 (
IN UINT8 *Buffer,
IN UINTN Size
)
/*++
Routine Description:
This function calculates the value needed for a valid UINT8 checksum
Arguments:
Buffer Pointer to buffer containing byte data of component.
Size Size of the buffer
Returns:
The 8 bit checksum value needed.
--*/
{
return (UINT8) (0x100 - CalculateSum8 (Buffer, Size));
}
UINT8
CalculateSum8 (
IN UINT8 *Buffer,
IN UINT32 Size
)
/*++
Routine Description::
This function calculates the UINT8 sum for the requested region.
Arguments:
Buffer Pointer to buffer containing byte data of component.
Size Size of the buffer
Returns:
The 8 bit checksum value needed.
--*/
{
UINTN Index;
UINT8 Sum;
Sum = 0;
//
// Perform the byte sum for buffer
//
for (Index = 0; Index < Size; Index++) {
Sum = (UINT8) (Sum + Buffer[Index]);
}
return Sum;
}
UINT16
CalculateChecksum16 (
IN UINT16 *Buffer,
IN UINTN Size
)
/*++
Routine Description::
This function calculates the value needed for a valid UINT16 checksum
Arguments:
Buffer Pointer to buffer containing byte data of component.
Size Size of the buffer
Returns:
The 16 bit checksum value needed.
--*/
{
return (UINT16) (0x10000 - CalculateSum16 (Buffer, Size));
}
UINT16
CalculateSum16 (
IN UINT16 *Buffer,
IN UINTN Size
)
/*++
Routine Description:
This function calculates the UINT16 sum for the requested region.
Arguments:
Buffer Pointer to buffer containing byte data of component.
Size Size of the buffer
Returns:
The 16 bit checksum
--*/
{
UINTN Index;
UINT16 Sum;
Sum = 0;
//
// Perform the word sum for buffer
//
for (Index = 0; Index < Size; Index++) {
Sum = (UINT16) (Sum + Buffer[Index]);
}
return (UINT16) Sum;
}
EFI_STATUS
PrintGuid (
IN EFI_GUID *Guid
)
/*++
Routine Description:
This function prints a GUID to STDOUT.
Arguments:
Guid Pointer to a GUID to print.
Returns:
EFI_SUCCESS The GUID was printed.
EFI_INVALID_PARAMETER The input was NULL.
--*/
{
if (Guid == NULL) {
printf ("ERROR: PrintGuid called with a NULL value.\n");
return EFI_INVALID_PARAMETER;
}
printf (
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
Guid->Data1,
Guid->Data2,
Guid->Data3,
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7]
);
return EFI_SUCCESS;
}
EFI_STATUS
PrintGuidToBuffer (
IN EFI_GUID *Guid,
IN OUT UINT8 *Buffer,
IN UINT32 BufferLen,
IN BOOLEAN Uppercase
)
/*++
Routine Description:
This function prints a GUID to a buffer
Arguments:
Guid - Pointer to a GUID to print.
Buffer - Pointer to a user-provided buffer to print to
BufferLen - Size of the Buffer
Uppercase - If use upper case.
Returns:
EFI_SUCCESS The GUID was printed.
EFI_INVALID_PARAMETER The input was NULL.
EFI_BUFFER_TOO_SMALL The input buffer was not big enough
--*/
{
if (Guid == NULL) {
printf ("ERROR: PrintGuidToBuffer() called with a NULL value\n");
return EFI_INVALID_PARAMETER;
}
if (BufferLen < PRINTED_GUID_BUFFER_SIZE) {
printf ("ERORR: PrintGuidToBuffer() called with invalid buffer size\n");
return EFI_BUFFER_TOO_SMALL;
}
if (Uppercase) {
sprintf (
Buffer,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
Guid->Data1,
Guid->Data2,
Guid->Data3,
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7]
);
} else {
sprintf (
Buffer,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
Guid->Data1,
Guid->Data2,
Guid->Data3,
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7]
);
}
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,131 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CommonLib.h
Abstract:
Common library assistance routines.
--*/
#ifndef _EFI_COMMON_LIB_H
#define _EFI_COMMON_LIB_H
/*
#include "TianoCommon.h"
#include "TianoCommon.h"
#include "PeiHob.h"
*/
#include <Base.h>
#include <UefiBaseTypes.h>
#ifndef _MAX_PATH
#define _MAX_PATH 500
#endif
#define PRINTED_GUID_BUFFER_SIZE 37 // including null-termination
//
// Function declarations
//
VOID
PeiZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
;
VOID
PeiCopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
;
VOID
ZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
;
VOID
CopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
;
INTN
CompareGuid (
IN EFI_GUID *Guid1,
IN EFI_GUID *Guid2
)
;
EFI_STATUS
GetFileImage (
IN CHAR8 *InputFileName,
OUT CHAR8 **InputFileImage,
OUT UINT32 *BytesRead
)
;
UINT8
CalculateChecksum8 (
IN UINT8 *Buffer,
IN UINTN Size
)
;
UINT8
CalculateSum8 (
IN UINT8 *Buffer,
IN UINTN Size
)
;
UINT16
CalculateChecksum16 (
IN UINT16 *Buffer,
IN UINTN Size
)
;
UINT16
CalculateSum16 (
IN UINT16 *Buffer,
IN UINTN Size
)
;
EFI_STATUS
PrintGuid (
IN EFI_GUID *Guid
)
;
#define PRINTED_GUID_BUFFER_SIZE 37 // including null-termination
EFI_STATUS
PrintGuidToBuffer (
IN EFI_GUID *Guid,
IN OUT UINT8 *Buffer,
IN UINT32 BufferLen,
IN BOOLEAN Uppercase
)
;
#endif

View File

@@ -0,0 +1,326 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
crc32.c
Abstract:
CalcuateCrc32 routine.
--*/
#include <stdlib.h>
#include "Crc32.h"
UINT32 mCrcTable[256] = {
0x00000000,
0x77073096,
0xEE0E612C,
0x990951BA,
0x076DC419,
0x706AF48F,
0xE963A535,
0x9E6495A3,
0x0EDB8832,
0x79DCB8A4,
0xE0D5E91E,
0x97D2D988,
0x09B64C2B,
0x7EB17CBD,
0xE7B82D07,
0x90BF1D91,
0x1DB71064,
0x6AB020F2,
0xF3B97148,
0x84BE41DE,
0x1ADAD47D,
0x6DDDE4EB,
0xF4D4B551,
0x83D385C7,
0x136C9856,
0x646BA8C0,
0xFD62F97A,
0x8A65C9EC,
0x14015C4F,
0x63066CD9,
0xFA0F3D63,
0x8D080DF5,
0x3B6E20C8,
0x4C69105E,
0xD56041E4,
0xA2677172,
0x3C03E4D1,
0x4B04D447,
0xD20D85FD,
0xA50AB56B,
0x35B5A8FA,
0x42B2986C,
0xDBBBC9D6,
0xACBCF940,
0x32D86CE3,
0x45DF5C75,
0xDCD60DCF,
0xABD13D59,
0x26D930AC,
0x51DE003A,
0xC8D75180,
0xBFD06116,
0x21B4F4B5,
0x56B3C423,
0xCFBA9599,
0xB8BDA50F,
0x2802B89E,
0x5F058808,
0xC60CD9B2,
0xB10BE924,
0x2F6F7C87,
0x58684C11,
0xC1611DAB,
0xB6662D3D,
0x76DC4190,
0x01DB7106,
0x98D220BC,
0xEFD5102A,
0x71B18589,
0x06B6B51F,
0x9FBFE4A5,
0xE8B8D433,
0x7807C9A2,
0x0F00F934,
0x9609A88E,
0xE10E9818,
0x7F6A0DBB,
0x086D3D2D,
0x91646C97,
0xE6635C01,
0x6B6B51F4,
0x1C6C6162,
0x856530D8,
0xF262004E,
0x6C0695ED,
0x1B01A57B,
0x8208F4C1,
0xF50FC457,
0x65B0D9C6,
0x12B7E950,
0x8BBEB8EA,
0xFCB9887C,
0x62DD1DDF,
0x15DA2D49,
0x8CD37CF3,
0xFBD44C65,
0x4DB26158,
0x3AB551CE,
0xA3BC0074,
0xD4BB30E2,
0x4ADFA541,
0x3DD895D7,
0xA4D1C46D,
0xD3D6F4FB,
0x4369E96A,
0x346ED9FC,
0xAD678846,
0xDA60B8D0,
0x44042D73,
0x33031DE5,
0xAA0A4C5F,
0xDD0D7CC9,
0x5005713C,
0x270241AA,
0xBE0B1010,
0xC90C2086,
0x5768B525,
0x206F85B3,
0xB966D409,
0xCE61E49F,
0x5EDEF90E,
0x29D9C998,
0xB0D09822,
0xC7D7A8B4,
0x59B33D17,
0x2EB40D81,
0xB7BD5C3B,
0xC0BA6CAD,
0xEDB88320,
0x9ABFB3B6,
0x03B6E20C,
0x74B1D29A,
0xEAD54739,
0x9DD277AF,
0x04DB2615,
0x73DC1683,
0xE3630B12,
0x94643B84,
0x0D6D6A3E,
0x7A6A5AA8,
0xE40ECF0B,
0x9309FF9D,
0x0A00AE27,
0x7D079EB1,
0xF00F9344,
0x8708A3D2,
0x1E01F268,
0x6906C2FE,
0xF762575D,
0x806567CB,
0x196C3671,
0x6E6B06E7,
0xFED41B76,
0x89D32BE0,
0x10DA7A5A,
0x67DD4ACC,
0xF9B9DF6F,
0x8EBEEFF9,
0x17B7BE43,
0x60B08ED5,
0xD6D6A3E8,
0xA1D1937E,
0x38D8C2C4,
0x4FDFF252,
0xD1BB67F1,
0xA6BC5767,
0x3FB506DD,
0x48B2364B,
0xD80D2BDA,
0xAF0A1B4C,
0x36034AF6,
0x41047A60,
0xDF60EFC3,
0xA867DF55,
0x316E8EEF,
0x4669BE79,
0xCB61B38C,
0xBC66831A,
0x256FD2A0,
0x5268E236,
0xCC0C7795,
0xBB0B4703,
0x220216B9,
0x5505262F,
0xC5BA3BBE,
0xB2BD0B28,
0x2BB45A92,
0x5CB36A04,
0xC2D7FFA7,
0xB5D0CF31,
0x2CD99E8B,
0x5BDEAE1D,
0x9B64C2B0,
0xEC63F226,
0x756AA39C,
0x026D930A,
0x9C0906A9,
0xEB0E363F,
0x72076785,
0x05005713,
0x95BF4A82,
0xE2B87A14,
0x7BB12BAE,
0x0CB61B38,
0x92D28E9B,
0xE5D5BE0D,
0x7CDCEFB7,
0x0BDBDF21,
0x86D3D2D4,
0xF1D4E242,
0x68DDB3F8,
0x1FDA836E,
0x81BE16CD,
0xF6B9265B,
0x6FB077E1,
0x18B74777,
0x88085AE6,
0xFF0F6A70,
0x66063BCA,
0x11010B5C,
0x8F659EFF,
0xF862AE69,
0x616BFFD3,
0x166CCF45,
0xA00AE278,
0xD70DD2EE,
0x4E048354,
0x3903B3C2,
0xA7672661,
0xD06016F7,
0x4969474D,
0x3E6E77DB,
0xAED16A4A,
0xD9D65ADC,
0x40DF0B66,
0x37D83BF0,
0xA9BCAE53,
0xDEBB9EC5,
0x47B2CF7F,
0x30B5FFE9,
0xBDBDF21C,
0xCABAC28A,
0x53B39330,
0x24B4A3A6,
0xBAD03605,
0xCDD70693,
0x54DE5729,
0x23D967BF,
0xB3667A2E,
0xC4614AB8,
0x5D681B02,
0x2A6F2B94,
0xB40BBE37,
0xC30C8EA1,
0x5A05DF1B,
0x2D02EF8D
};
EFI_STATUS
CalculateCrc32 (
IN UINT8 *Data,
IN UINTN DataSize,
IN OUT UINT32 *CrcOut
)
/*++
Routine Description:
The CalculateCrc32 routine.
Arguments:
Data - The buffer contaning the data to be processed
DataSize - The size of data to be processed
CrcOut - A pointer to the caller allocated UINT32 that on
contains the CRC32 checksum of Data
Returns:
EFI_SUCCESS - Calculation is successful.
EFI_INVALID_PARAMETER - Data / CrcOut = NULL, or DataSize = 0
--*/
{
UINT32 Crc;
UINTN Index;
UINT8 *Ptr;
if ((DataSize == 0) || (Data == NULL) || (CrcOut == NULL)) {
return EFI_INVALID_PARAMETER;
}
Crc = 0xffffffff;
for (Index = 0, Ptr = Data; Index < DataSize; Index++, Ptr++) {
Crc = (Crc >> 8) ^ mCrcTable[(UINT8) Crc ^ *Ptr];
}
*CrcOut = Crc ^ 0xffffffff;
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,57 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Crc32.h
Abstract:
Header file for CalcuateCrc32 routine
--*/
/*
#include "TianoCommon.h"
*/
#include <Base.h>
#include <UefiBaseTypes.h>
#ifndef _CRC32_H
#define _CRC32_H
EFI_STATUS
CalculateCrc32 (
IN UINT8 *Data,
IN UINTN DataSize,
IN OUT UINT32 *CrcOut
)
;
/*++
Routine Description:
The CalculateCrc32 routine.
Arguments:
Data - The buffer contaning the data to be processed
DataSize - The size of data to be processed
CrcOut - A pointer to the caller allocated UINT32 that on
contains the CRC32 checksum of Data
Returns:
EFI_SUCCESS - Calculation is successful.
EFI_INVALID_PARAMETER - Data / CrcOut = NULL, or DataSize = 0
--*/
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,68 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiCompress.h
Abstract:
Header file for compression routine
--*/
#include <string.h>
#include <stdlib.h>
#include <Base.h>
#include <UefiBaseTypes.h>
#ifndef _EFICOMPRESS_H
#define _EFICOMPRESS_H
EFI_STATUS
Compress (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
)
;
/*++
Routine Description:
The compression routine.
Arguments:
SrcBuffer - The buffer storing the source data
SrcSize - The size of source data
DstBuffer - The buffer to store the compressed data
DstSize - On input, the size of DstBuffer; On output,
the size of the actual compressed data.
Returns:
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case,
DstSize contains the size needed.
EFI_SUCCESS - Compression is successful.
--*/
typedef
EFI_STATUS
(*COMPRESS_FUNCTION) (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
);
#endif

View File

@@ -0,0 +1,141 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiCustomizedCompress.h
Abstract:
Header file for Customized compression routine
--*/
#include <Base.h>
#include <UefiBaseTypes.h>
#ifndef _EFICUSTOMIZEDCOMPRESS_H
#define _EFICUSTOMIZEDCOMPRESS_H
EFI_STATUS
SetCustomizedCompressionType (
IN CHAR8 *Type
)
;
/*++
Routine Description:
The implementation of Customized SetCompressionType().
Arguments:
Type - The type if compression.
Returns:
EFI_SUCCESS - The type has been set.
EFI_UNSUPPORTED - This type is unsupported.
--*/
EFI_STATUS
CustomizedGetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
;
/*++
Routine Description:
The implementation of Customized GetInfo().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
EFI_STATUS
CustomizedDecompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
;
/*++
Routine Description:
The implementation of Customized Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
EFI_STATUS
CustomizedCompress (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
)
;
/*++
Routine Description:
The Customized compression routine.
Arguments:
SrcBuffer - The buffer storing the source data
SrcSize - The size of source data
DstBuffer - The buffer to store the compressed data
DstSize - On input, the size of DstBuffer; On output,
the size of the actual compressed data.
Returns:
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case,
DstSize contains the size needed.
EFI_SUCCESS - Compression is successful.
--*/
#endif

View File

@@ -0,0 +1,790 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiDecompress.c
Abstract:
Decompressor. Algorithm Ported from OPSD code (Decomp.asm)
--*/
#include "EfiDecompress.h"
//
// Decompression algorithm begins here
//
#define BITBUFSIZ 32
#define MAXMATCH 256
#define THRESHOLD 3
#define CODE_BIT 16
#define BAD_TABLE - 1
//
// C: Char&Len Set; P: Position Set; T: exTra Set
//
#define NC (0xff + MAXMATCH + 2 - THRESHOLD)
#define CBIT 9
#define PBIT 5
#define TBIT 5
#define MAXNP ((1U << PBIT) - 1)
#define NT (CODE_BIT + 3)
#if NT > MAXNP
#define NPT NT
#else
#define NPT MAXNP
#endif
typedef struct {
UINT8 *mSrcBase; // Starting address of compressed data
UINT8 *mDstBase; // Starting address of decompressed data
UINT32 mOutBuf;
UINT32 mInBuf;
UINT16 mBitCount;
UINT32 mBitBuf;
UINT32 mSubBitBuf;
UINT16 mBlockSize;
UINT32 mCompSize;
UINT32 mOrigSize;
UINT16 mBadTableFlag;
UINT16 mLeft[2 * NC - 1];
UINT16 mRight[2 * NC - 1];
UINT8 mCLen[NC];
UINT8 mPTLen[NPT];
UINT16 mCTable[4096];
UINT16 mPTTable[256];
} SCRATCH_DATA;
STATIC
VOID
FillBuf (
IN SCRATCH_DATA *Sd,
IN UINT16 NumOfBits
)
/*++
Routine Description:
Shift mBitBuf NumOfBits left. Read in NumOfBits of bits from source.
Arguments:
Sd - The global scratch data
NumOfBit - The number of bits to shift and read.
Returns: (VOID)
--*/
{
Sd->mBitBuf = (UINT32) (Sd->mBitBuf << NumOfBits);
while (NumOfBits > Sd->mBitCount) {
Sd->mBitBuf |= (UINT32) (Sd->mSubBitBuf << (NumOfBits = (UINT16) (NumOfBits - Sd->mBitCount)));
if (Sd->mCompSize > 0) {
//
// Get 1 byte into SubBitBuf
//
Sd->mCompSize--;
Sd->mSubBitBuf = 0;
Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];
Sd->mBitCount = 8;
} else {
//
// No more bits from the source, just pad zero bit.
//
Sd->mSubBitBuf = 0;
Sd->mBitCount = 8;
}
}
Sd->mBitCount = (UINT16) (Sd->mBitCount - NumOfBits);
Sd->mBitBuf |= Sd->mSubBitBuf >> Sd->mBitCount;
}
STATIC
UINT32
GetBits (
IN SCRATCH_DATA *Sd,
IN UINT16 NumOfBits
)
/*++
Routine Description:
Get NumOfBits of bits out from mBitBuf. Fill mBitBuf with subsequent
NumOfBits of bits from source. Returns NumOfBits of bits that are
popped out.
Arguments:
Sd - The global scratch data.
NumOfBits - The number of bits to pop and read.
Returns:
The bits that are popped out.
--*/
{
UINT32 OutBits;
OutBits = (UINT32) (Sd->mBitBuf >> (BITBUFSIZ - NumOfBits));
FillBuf (Sd, NumOfBits);
return OutBits;
}
STATIC
UINT16
MakeTable (
IN SCRATCH_DATA *Sd,
IN UINT16 NumOfChar,
IN UINT8 *BitLen,
IN UINT16 TableBits,
OUT UINT16 *Table
)
/*++
Routine Description:
Creates Huffman Code mapping table according to code length array.
Arguments:
Sd - The global scratch data
NumOfChar - Number of symbols in the symbol set
BitLen - Code length array
TableBits - The width of the mapping table
Table - The table
Returns:
0 - OK.
BAD_TABLE - The table is corrupted.
--*/
{
UINT16 Count[17];
UINT16 Weight[17];
UINT16 Start[18];
UINT16 *Pointer;
UINT16 Index3;
UINT16 Index;
UINT16 Len;
UINT16 Char;
UINT16 JuBits;
UINT16 Avail;
UINT16 NextCode;
UINT16 Mask;
for (Index = 1; Index <= 16; Index++) {
Count[Index] = 0;
}
for (Index = 0; Index < NumOfChar; Index++) {
Count[BitLen[Index]]++;
}
Start[1] = 0;
for (Index = 1; Index <= 16; Index++) {
Start[Index + 1] = (UINT16) (Start[Index] + (Count[Index] << (16 - Index)));
}
if (Start[17] != 0) {
/*(1U << 16)*/
return (UINT16) BAD_TABLE;
}
JuBits = (UINT16) (16 - TableBits);
for (Index = 1; Index <= TableBits; Index++) {
Start[Index] >>= JuBits;
Weight[Index] = (UINT16) (1U << (TableBits - Index));
}
while (Index <= 16) {
Weight[Index++] = (UINT16) (1U << (16 - Index));
}
Index = (UINT16) (Start[TableBits + 1] >> JuBits);
if (Index != 0) {
Index3 = (UINT16) (1U << TableBits);
while (Index != Index3) {
Table[Index++] = 0;
}
}
Avail = NumOfChar;
Mask = (UINT16) (1U << (15 - TableBits));
for (Char = 0; Char < NumOfChar; Char++) {
Len = BitLen[Char];
if (Len == 0) {
continue;
}
NextCode = (UINT16) (Start[Len] + Weight[Len]);
if (Len <= TableBits) {
for (Index = Start[Len]; Index < NextCode; Index++) {
Table[Index] = Char;
}
} else {
Index3 = Start[Len];
Pointer = &Table[Index3 >> JuBits];
Index = (UINT16) (Len - TableBits);
while (Index != 0) {
if (*Pointer == 0) {
Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;
*Pointer = Avail++;
}
if (Index3 & Mask) {
Pointer = &Sd->mRight[*Pointer];
} else {
Pointer = &Sd->mLeft[*Pointer];
}
Index3 <<= 1;
Index--;
}
*Pointer = Char;
}
Start[Len] = NextCode;
}
//
// Succeeds
//
return 0;
}
STATIC
UINT32
DecodeP (
IN SCRATCH_DATA *Sd
)
/*++
Routine Description:
Decodes a position value.
Arguments:
Sd - the global scratch data
Returns:
The position value decoded.
--*/
{
UINT16 Val;
UINT32 Mask;
UINT32 Pos;
Val = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
if (Val >= MAXNP) {
Mask = 1U << (BITBUFSIZ - 1 - 8);
do {
if (Sd->mBitBuf & Mask) {
Val = Sd->mRight[Val];
} else {
Val = Sd->mLeft[Val];
}
Mask >>= 1;
} while (Val >= MAXNP);
}
//
// Advance what we have read
//
FillBuf (Sd, Sd->mPTLen[Val]);
Pos = Val;
if (Val > 1) {
Pos = (UINT32) ((1U << (Val - 1)) + GetBits (Sd, (UINT16) (Val - 1)));
}
return Pos;
}
STATIC
UINT16
ReadPTLen (
IN SCRATCH_DATA *Sd,
IN UINT16 nn,
IN UINT16 nbit,
IN UINT16 Special
)
/*++
Routine Description:
Reads code lengths for the Extra Set or the Position Set
Arguments:
Sd - The global scratch data
nn - Number of symbols
nbit - Number of bits needed to represent nn
Special - The special symbol that needs to be taken care of
Returns:
0 - OK.
BAD_TABLE - Table is corrupted.
--*/
{
UINT16 Number;
UINT16 CharC;
UINT16 Index;
UINT32 Mask;
Number = (UINT16) GetBits (Sd, nbit);
if (Number == 0) {
CharC = (UINT16) GetBits (Sd, nbit);
for (Index = 0; Index < 256; Index++) {
Sd->mPTTable[Index] = CharC;
}
for (Index = 0; Index < nn; Index++) {
Sd->mPTLen[Index] = 0;
}
return 0;
}
Index = 0;
while (Index < Number) {
CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));
if (CharC == 7) {
Mask = 1U << (BITBUFSIZ - 1 - 3);
while (Mask & Sd->mBitBuf) {
Mask >>= 1;
CharC += 1;
}
}
FillBuf (Sd, (UINT16) ((CharC < 7) ? 3 : CharC - 3));
Sd->mPTLen[Index++] = (UINT8) CharC;
if (Index == Special) {
CharC = (UINT16) GetBits (Sd, 2);
CharC--;
while ((INT16) (CharC) >= 0) {
Sd->mPTLen[Index++] = 0;
CharC--;
}
}
}
while (Index < nn) {
Sd->mPTLen[Index++] = 0;
}
return MakeTable (Sd, nn, Sd->mPTLen, 8, Sd->mPTTable);
}
STATIC
VOID
ReadCLen (
SCRATCH_DATA *Sd
)
/*++
Routine Description:
Reads code lengths for Char&Len Set.
Arguments:
Sd - the global scratch data
Returns: (VOID)
--*/
{
UINT16 Number;
UINT16 CharC;
UINT16 Index;
UINT32 Mask;
Number = (UINT16) GetBits (Sd, CBIT);
if (Number == 0) {
CharC = (UINT16) GetBits (Sd, CBIT);
for (Index = 0; Index < NC; Index++) {
Sd->mCLen[Index] = 0;
}
for (Index = 0; Index < 4096; Index++) {
Sd->mCTable[Index] = CharC;
}
return ;
}
Index = 0;
while (Index < Number) {
CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
if (CharC >= NT) {
Mask = 1U << (BITBUFSIZ - 1 - 8);
do {
if (Mask & Sd->mBitBuf) {
CharC = Sd->mRight[CharC];
} else {
CharC = Sd->mLeft[CharC];
}
Mask >>= 1;
} while (CharC >= NT);
}
//
// Advance what we have read
//
FillBuf (Sd, Sd->mPTLen[CharC]);
if (CharC <= 2) {
if (CharC == 0) {
CharC = 1;
} else if (CharC == 1) {
CharC = (UINT16) (GetBits (Sd, 4) + 3);
} else if (CharC == 2) {
CharC = (UINT16) (GetBits (Sd, CBIT) + 20);
}
CharC--;
while ((INT16) (CharC) >= 0) {
Sd->mCLen[Index++] = 0;
CharC--;
}
} else {
Sd->mCLen[Index++] = (UINT8) (CharC - 2);
}
}
while (Index < NC) {
Sd->mCLen[Index++] = 0;
}
MakeTable (Sd, NC, Sd->mCLen, 12, Sd->mCTable);
return ;
}
STATIC
UINT16
DecodeC (
SCRATCH_DATA *Sd
)
/*++
Routine Description:
Decode a character/length value.
Arguments:
Sd - The global scratch data.
Returns:
The value decoded.
--*/
{
UINT16 Index2;
UINT32 Mask;
if (Sd->mBlockSize == 0) {
//
// Starting a new block
//
Sd->mBlockSize = (UINT16) GetBits (Sd, 16);
Sd->mBadTableFlag = ReadPTLen (Sd, NT, TBIT, 3);
if (Sd->mBadTableFlag != 0) {
return 0;
}
ReadCLen (Sd);
Sd->mBadTableFlag = ReadPTLen (Sd, MAXNP, PBIT, (UINT16) (-1));
if (Sd->mBadTableFlag != 0) {
return 0;
}
}
Sd->mBlockSize--;
Index2 = Sd->mCTable[Sd->mBitBuf >> (BITBUFSIZ - 12)];
if (Index2 >= NC) {
Mask = 1U << (BITBUFSIZ - 1 - 12);
do {
if (Sd->mBitBuf & Mask) {
Index2 = Sd->mRight[Index2];
} else {
Index2 = Sd->mLeft[Index2];
}
Mask >>= 1;
} while (Index2 >= NC);
}
//
// Advance what we have read
//
FillBuf (Sd, Sd->mCLen[Index2]);
return Index2;
}
STATIC
VOID
Decode (
SCRATCH_DATA *Sd
)
/*++
Routine Description:
Decode the source data and put the resulting data into the destination buffer.
Arguments:
Sd - The global scratch data
Returns: (VOID)
--*/
{
UINT16 BytesRemain;
UINT32 DataIdx;
UINT16 CharC;
BytesRemain = (UINT16) (-1);
DataIdx = 0;
for (;;) {
CharC = DecodeC (Sd);
if (Sd->mBadTableFlag != 0) {
return ;
}
if (CharC < 256) {
//
// Process an Original character
//
Sd->mDstBase[Sd->mOutBuf++] = (UINT8) CharC;
if (Sd->mOutBuf >= Sd->mOrigSize) {
return ;
}
} else {
//
// Process a Pointer
//
CharC = (UINT16) (CharC - (UINT8_MAX + 1 - THRESHOLD));
BytesRemain = CharC;
DataIdx = Sd->mOutBuf - DecodeP (Sd) - 1;
BytesRemain--;
while ((INT16) (BytesRemain) >= 0) {
Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++];
if (Sd->mOutBuf >= Sd->mOrigSize) {
return ;
}
BytesRemain--;
}
}
}
return ;
}
EFI_STATUS
GetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
/*++
Routine Description:
The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
UINT8 *Src;
*ScratchSize = sizeof (SCRATCH_DATA);
Src = Source;
if (SrcSize < 8) {
return EFI_INVALID_PARAMETER;
}
*DstSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
return EFI_SUCCESS;
}
EFI_STATUS
Decompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
/*++
Routine Description:
The implementation of EFI_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
{
UINT32 Index;
UINT32 CompSize;
UINT32 OrigSize;
EFI_STATUS Status;
SCRATCH_DATA *Sd;
UINT8 *Src;
UINT8 *Dst;
Status = EFI_SUCCESS;
Src = Source;
Dst = Destination;
if (ScratchSize < sizeof (SCRATCH_DATA)) {
return EFI_INVALID_PARAMETER;
}
Sd = (SCRATCH_DATA *) Scratch;
if (SrcSize < 8) {
return EFI_INVALID_PARAMETER;
}
CompSize = Src[0] + (Src[1] << 8) + (Src[2] << 16) + (Src[3] << 24);
OrigSize = Src[4] + (Src[5] << 8) + (Src[6] << 16) + (Src[7] << 24);
if (SrcSize < CompSize + 8) {
return EFI_INVALID_PARAMETER;
}
if (DstSize != OrigSize) {
return EFI_INVALID_PARAMETER;
}
Src = Src + 8;
for (Index = 0; Index < sizeof (SCRATCH_DATA); Index++) {
((UINT8 *) Sd)[Index] = 0;
}
Sd->mSrcBase = Src;
Sd->mDstBase = Dst;
Sd->mCompSize = CompSize;
Sd->mOrigSize = OrigSize;
//
// Fill the first BITBUFSIZ bits
//
FillBuf (Sd, BITBUFSIZ);
//
// Decompress it
//
Decode (Sd);
if (Sd->mBadTableFlag != 0) {
//
// Something wrong with the source
//
Status = EFI_INVALID_PARAMETER;
}
return Status;
}

View File

@@ -0,0 +1,105 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiDecompress.h
Abstract:
Header file for compression routine
--*/
#include <Base.h>
#include <UefiBaseTypes.h>
#ifndef _EFI_DECOMPRESS_H
#define _EFI_DECOMPRESS_H
EFI_STATUS
GetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
);
/*++
Routine Description:
The implementation of EFI_DECOMPRESS_PROTOCOL.GetInfo().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
EFI_STATUS
Decompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
;
/*++
Routine Description:
The implementation of EFI_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
typedef
EFI_STATUS
(*GETINFO_FUNCTION) (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
);
typedef
EFI_STATUS
(*DECOMPRESS_FUNCTION) (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
);
#endif

View File

@@ -0,0 +1,758 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiUtilityMsgs.c
Abstract:
EFI tools utility functions to display warning, error, and informational
messages.
--*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
/*
#include "Tiano.h"
*/
#include "EfiUtilityMsgs.h"
#define MAX_LINE_LEN 200
//
// Declare module globals for keeping track of the the utility's
// name and other settings.
//
static STATUS mStatus = STATUS_SUCCESS;
static CHAR8 mUtilityName[50] = { 0 };
static UINT32 mDebugMsgMask = 0;
static CHAR8 *mSourceFileName = NULL;
static UINT32 mSourceFileLineNum = 0;
static UINT32 mErrorCount = 0;
static UINT32 mWarningCount = 0;
static UINT32 mMaxErrors = 0;
static UINT32 mMaxWarnings = 0;
static UINT32 mMaxWarningsPlusErrors = 0;
static INT8 mPrintLimitsSet = 0;
static
void
PrintMessage (
CHAR8 *Type,
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
va_list List
);
static
void
PrintLimitExceeded (
VOID
);
void
Error (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Prints an error message.
Arguments:
All arguments are optional, though the printed message may be useless if
at least something valid is not specified.
FileName - name of the file or application. If not specified, then the
utilty name (as set by the utility calling SetUtilityName()
earlier) is used. Otherwise "Unknown utility" is used.
LineNumber - the line number of error, typically used by parsers. If the
utility is not a parser, then 0 should be specified. Otherwise
the FileName and LineNumber info can be used to cause
MS Visual Studio to jump to the error.
MessageCode - an application-specific error code that can be referenced in
other documentation.
Text - the text in question, typically used by parsers.
MsgFmt - the format string for the error message. Can contain formatting
controls for use with the varargs.
Returns:
None.
Notes:
We print the following (similar to the Warn() and Debug()
W
Typical error/warning message format:
bin\VfrCompile.cpp(330) : error C2660: 'AddVfrDataStructField' : function does not take 2 parameters
BUGBUG -- these three utility functions are almost identical, and
should be modified to share code.
Visual Studio does not find error messages with:
" error :"
" error 1:"
" error c1:"
" error 1000:"
" error c100:"
It does find:
" error c1000:"
--*/
{
va_list List;
//
// If limits have been set, then check that we have not exceeded them
//
if (mPrintLimitsSet) {
//
// See if we've exceeded our total count
//
if (mMaxWarningsPlusErrors != 0) {
if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
PrintLimitExceeded ();
return ;
}
}
//
// See if we've exceeded our error count
//
if (mMaxErrors != 0) {
if (mErrorCount > mMaxErrors) {
PrintLimitExceeded ();
return ;
}
}
}
mErrorCount++;
va_start (List, MsgFmt);
PrintMessage ("error", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_ERROR) {
mStatus = STATUS_ERROR;
}
}
void
ParserError (
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Print a parser error, using the source file name and line number
set by a previous call to SetParserPosition().
Arguments:
MessageCode - application-specific error code
Text - text to print in the error message
MsgFmt - format string to print at the end of the error message
Returns:
NA
--*/
{
va_list List;
//
// If limits have been set, then check them
//
if (mPrintLimitsSet) {
//
// See if we've exceeded our total count
//
if (mMaxWarningsPlusErrors != 0) {
if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
PrintLimitExceeded ();
return ;
}
}
//
// See if we've exceeded our error count
//
if (mMaxErrors != 0) {
if (mErrorCount > mMaxErrors) {
PrintLimitExceeded ();
return ;
}
}
}
mErrorCount++;
va_start (List, MsgFmt);
PrintMessage ("error", mSourceFileName, mSourceFileLineNum, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_ERROR) {
mStatus = STATUS_ERROR;
}
}
void
ParserWarning (
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Print a parser warning, using the source file name and line number
set by a previous call to SetParserPosition().
Arguments:
ErrorCode - application-specific error code
OffendingText - text to print in the warning message
MsgFmt - format string to print at the end of the warning message
Returns:
NA
--*/
{
va_list List;
//
// If limits have been set, then check them
//
if (mPrintLimitsSet) {
//
// See if we've exceeded our total count
//
if (mMaxWarningsPlusErrors != 0) {
if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
PrintLimitExceeded ();
return ;
}
}
//
// See if we've exceeded our warning count
//
if (mMaxWarnings != 0) {
if (mWarningCount > mMaxWarnings) {
PrintLimitExceeded ();
return ;
}
}
}
mWarningCount++;
va_start (List, MsgFmt);
PrintMessage ("warning", mSourceFileName, mSourceFileLineNum, ErrorCode, OffendingText, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_WARNING) {
mStatus = STATUS_WARNING;
}
}
void
Warning (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Print a warning message.
Arguments:
FileName - name of the file where the warning was detected, or the name
of the application that detected the warning
LineNumber - the line number where the warning was detected (parsers).
0 should be specified if the utility is not a parser.
MessageCode - an application-specific warning code that can be referenced in
other documentation.
Text - the text in question (parsers)
MsgFmt - the format string for the warning message. Can contain formatting
controls for use with varargs.
Returns:
None.
--*/
{
va_list List;
//
// If limits have been set, then check them
//
if (mPrintLimitsSet) {
//
// See if we've exceeded our total count
//
if (mMaxWarningsPlusErrors != 0) {
if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
PrintLimitExceeded ();
return ;
}
}
//
// See if we've exceeded our warning count
//
if (mMaxWarnings != 0) {
if (mWarningCount > mMaxWarnings) {
PrintLimitExceeded ();
return ;
}
}
}
mWarningCount++;
va_start (List, MsgFmt);
PrintMessage ("warning", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_WARNING) {
mStatus = STATUS_WARNING;
}
}
void
DebugMsg (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MsgMask,
CHAR8 *Text,
CHAR8 *MsgFmt,
...
)
/*++
Routine Description:
Print a warning message.
Arguments:
FileName - typically the name of the utility printing the debug message, but
can be the name of a file being parsed.
LineNumber - the line number in FileName (parsers)
MsgMask - an application-specific bitmask that, in combination with mDebugMsgMask,
determines if the debug message gets printed.
Text - the text in question (parsers)
MsgFmt - the format string for the debug message. Can contain formatting
controls for use with varargs.
Returns:
None.
--*/
{
va_list List;
//
// If the debug mask is not applicable, then do nothing.
//
if ((MsgMask != 0) && ((mDebugMsgMask & MsgMask) == 0)) {
return ;
}
va_start (List, MsgFmt);
PrintMessage ("debug", FileName, LineNumber, 0, Text, MsgFmt, List);
va_end (List);
}
static
void
PrintMessage (
CHAR8 *Type,
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
CHAR8 *Text,
CHAR8 *MsgFmt,
va_list List
)
/*++
Routine Description:
Worker routine for all the utility printing services. Prints the message in
a format that Visual Studio will find when scanning build outputs for
errors or warnings.
Arguments:
Type - "warning" or "error" string to insert into the message to be
printed. The first character of this string (converted to uppercase)
is used to preceed the MessageCode value in the output string.
FileName - name of the file where the warning was detected, or the name
of the application that detected the warning
LineNumber - the line number where the warning was detected (parsers).
0 should be specified if the utility is not a parser.
MessageCode - an application-specific warning code that can be referenced in
other documentation.
Text - part of the message to print
MsgFmt - the format string for the message. Can contain formatting
controls for use with varargs.
List - the variable list.
Returns:
None.
Notes:
If FileName == NULL then this utility will use the string passed into SetUtilityName().
LineNumber is only used if the caller is a parser, in which case FileName refers to the
file being parsed.
Text and MsgFmt are both optional, though it would be of little use calling this function with
them both NULL.
Output will typically be of the form:
<FileName>(<LineNumber>) : <Type> <Type[0]><MessageCode>: <Text> : <MsgFmt>
Parser (LineNumber != 0)
VfrCompile.cpp(330) : error E2660: AddVfrDataStructField : function does not take 2 parameters
Generic utility (LineNumber == 0)
UtilityName : error E1234 : Text string : MsgFmt string and args
--*/
{
CHAR8 Line[MAX_LINE_LEN];
CHAR8 Line2[MAX_LINE_LEN];
CHAR8 *Cptr;
//
// If given a filename, then add it (and the line number) to the string.
// If there's no filename, then use the program name if provided.
//
if (FileName != NULL) {
Cptr = FileName;
} else if (mUtilityName[0] != 0) {
Cptr = mUtilityName;
} else {
Cptr = "Unknown utility";
}
strcpy (Line, Cptr);
if (LineNumber != 0) {
sprintf (Line2, "(%d)", LineNumber);
strcat (Line, Line2);
}
//
// Have to print an error code or Visual Studio won't find the
// message for you. It has to be decimal digits too.
//
sprintf (Line2, " : %s %c%04d", Type, toupper (Type[0]), MessageCode);
strcat (Line, Line2);
fprintf (stdout, "%s", Line);
//
// If offending text was provided, then print it
//
if (Text != NULL) {
fprintf (stdout, ": %s ", Text);
}
//
// Print formatted message if provided
//
if (MsgFmt != NULL) {
vsprintf (Line2, MsgFmt, List);
fprintf (stdout, ": %s", Line2);
}
fprintf (stdout, "\n");
}
void
ParserSetPosition (
CHAR8 *SourceFileName,
UINT32 LineNum
)
/*++
Routine Description:
Set the position in a file being parsed. This can be used to
print error messages deeper down in a parser.
Arguments:
SourceFileName - name of the source file being parsed
LineNum - line number of the source file being parsed
Returns:
NA
--*/
{
mSourceFileName = SourceFileName;
mSourceFileLineNum = LineNum;
}
void
SetUtilityName (
CHAR8 *UtilityName
)
/*++
Routine Description:
All printed error/warning/debug messages follow the same format, and
typically will print a filename or utility name followed by the error
text. However if a filename is not passed to the print routines, then
they'll print the utility name if you call this function early in your
app to set the utility name.
Arguments:
UtilityName - name of the utility, which will be printed with all
error/warning/debug messags.
Returns:
NA
--*/
{
//
// Save the name of the utility in our local variable. Make sure its
// length does not exceed our buffer.
//
if (UtilityName != NULL) {
if (strlen (UtilityName) >= sizeof (mUtilityName)) {
Error (UtilityName, 0, 0, "application error", "utility name length exceeds internal buffer size");
strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);
mUtilityName[sizeof (mUtilityName) - 1] = 0;
return ;
} else {
strcpy (mUtilityName, UtilityName);
}
} else {
Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");
}
}
STATUS
GetUtilityStatus (
VOID
)
/*++
Routine Description:
When you call Error() or Warning(), this module keeps track of it and
sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility
exits, it can call this function to get the status and use it as a return
value.
Arguments:
None.
Returns:
Worst-case status reported, as defined by which print function was called.
--*/
{
return mStatus;
}
void
SetDebugMsgMask (
UINT32 DebugMask
)
/*++
Routine Description:
Set the debug printing mask. This is used by the DebugMsg() function
to determine when/if a debug message should be printed.
Arguments:
DebugMask - bitmask, specific to the calling application
Returns:
NA
--*/
{
mDebugMsgMask = DebugMask;
}
void
SetPrintLimits (
UINT32 MaxErrors,
UINT32 MaxWarnings,
UINT32 MaxWarningsPlusErrors
)
/*++
Routine Description:
Set the limits of how many errors, warnings, and errors+warnings
we will print.
Arguments:
MaxErrors - maximum number of error messages to print
MaxWarnings - maximum number of warning messages to print
MaxWarningsPlusErrors
- maximum number of errors+warnings to print
Returns:
NA
--*/
{
mMaxErrors = MaxErrors;
mMaxWarnings = MaxWarnings;
mMaxWarningsPlusErrors = MaxWarningsPlusErrors;
mPrintLimitsSet = 1;
}
static
void
PrintLimitExceeded (
VOID
)
{
static INT8 mPrintLimitExceeded = 0;
//
// If we've already printed the message, do nothing. Otherwise
// temporarily increase our print limits so we can pass one
// more message through.
//
if (mPrintLimitExceeded == 0) {
mPrintLimitExceeded++;
mMaxErrors++;
mMaxWarnings++;
mMaxWarningsPlusErrors++;
Error (NULL, 0, 0, "error/warning print limit exceeded", NULL);
mMaxErrors--;
mMaxWarnings--;
mMaxWarningsPlusErrors--;
}
}
#if 0
void
TestUtilityMessages (
VOID
)
{
char *ArgStr = "ArgString";
int ArgInt;
ArgInt = 0x12345678;
//
// Test without setting utility name
//
fprintf (stdout, "* Testing without setting utility name\n");
fprintf (stdout, "** Test debug message not printed\n");
DebugMsg (NULL, 0, 0x00000001, NULL, NULL);
fprintf (stdout, "** Test warning with two strings and two args\n");
Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
fprintf (stdout, "** Test error with two strings and two args\n");
Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
fprintf (stdout, "** Test parser warning with nothing\n");
ParserWarning (0, NULL, NULL);
fprintf (stdout, "** Test parser error with nothing\n");
ParserError (0, NULL, NULL);
//
// Test with utility name set now
//
fprintf (stdout, "** Testingin with utility name set\n");
SetUtilityName ("MyUtilityName");
//
// Test debug prints
//
SetDebugMsgMask (2);
fprintf (stdout, "** Test debug message with one string\n");
DebugMsg (NULL, 0, 0x00000002, "Text1", NULL);
fprintf (stdout, "** Test debug message with one string\n");
DebugMsg (NULL, 0, 0x00000002, NULL, "Text2");
fprintf (stdout, "** Test debug message with two strings\n");
DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2");
fprintf (stdout, "** Test debug message with two strings and two args\n");
DebugMsg (NULL, 0, 0x00000002, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
//
// Test warning prints
//
fprintf (stdout, "** Test warning with no strings\n");
Warning (NULL, 0, 1234, NULL, NULL);
fprintf (stdout, "** Test warning with one string\n");
Warning (NULL, 0, 1234, "Text1", NULL);
fprintf (stdout, "** Test warning with one string\n");
Warning (NULL, 0, 1234, NULL, "Text2");
fprintf (stdout, "** Test warning with two strings and two args\n");
Warning (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
//
// Test error prints
//
fprintf (stdout, "** Test error with no strings\n");
Error (NULL, 0, 1234, NULL, NULL);
fprintf (stdout, "** Test error with one string\n");
Error (NULL, 0, 1234, "Text1", NULL);
fprintf (stdout, "** Test error with one string\n");
Error (NULL, 0, 1234, NULL, "Text2");
fprintf (stdout, "** Test error with two strings and two args\n");
Error (NULL, 0, 1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
//
// Test parser prints
//
fprintf (stdout, "** Test parser errors\n");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, NULL, NULL);
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, "Text1", NULL);
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, NULL, "Text2");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, "Text1", "Text2");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserError (1234, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
fprintf (stdout, "** Test parser warnings\n");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, NULL, NULL);
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, "Text1", NULL);
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, NULL, "Text2");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, "Text1", "Text2");
ParserSetPosition (__FILE__, __LINE__ + 1);
ParserWarning (4321, "Text1", "Text2 %s 0x%X", ArgStr, ArgInt);
}
#endif

View File

@@ -0,0 +1,138 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiUtilityMsgs.h
Abstract:
Defines and prototypes for common EFI utility error and debug messages.
--*/
#include <Base.h>
#include <UefiBaseTypes.h>
#ifndef _EFI_UTILITY_MSGS_H_
#define _EFI_UTILITY_MSGS_H_
//
// Status codes returned by EFI utility programs and functions
//
#define STATUS_SUCCESS 0
#define STATUS_WARNING 1
#define STATUS_ERROR 2
#define VOID void
typedef int STATUS;
#ifdef __cplusplus
extern "C" {
#endif
//
// When we call Error() or Warning(), the module keeps track of the worst
// case reported. GetUtilityStatus() will get the worst-case results, which
// can be used as the return value from the app.
//
STATUS
GetUtilityStatus (
void
);
//
// If someone prints an error message and didn't specify a source file name,
// then we print the utility name instead. However they must tell us the
// utility name early on via this function.
//
void
SetUtilityName (
CHAR8 *ProgramName
)
;
void
Error (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
Warning (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
DebugMsg (
CHAR8 *FileName,
UINT32 LineNumber,
UINT32 MsgLevel,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
SetDebugMsgMask (
UINT32 MsgMask
)
;
void
ParserSetPosition (
CHAR8 *SourceFileName,
UINT32 LineNum
)
;
void
ParserError (
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
ParserWarning (
UINT32 ErrorCode,
CHAR8 *OffendingText,
CHAR8 *MsgFmt,
...
)
;
void
SetPrintLimits (
UINT32 NumErrors,
UINT32 NumWarnings,
UINT32 NumWarningsPlusErrors
)
;
#ifdef __cplusplus
}
#endif
#endif // #ifndef _EFI_UTILITY_MSGS_H_

View File

@@ -0,0 +1,788 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FvLib.c
Abstract:
These functions assist in parsing and manipulating a Firmware Volume.
--*/
//
// Include files
//
#include "FvLib.h"
#include "CommonLib.h"
#include "EfiUtilityMsgs.h"
#include "MultiPhase.h"
/*
#include <CommonBuild.h>
*/
/*
#include EFI_GUID_DEFINITION (FirmwareFileSystem)
*/
//
// Module global variables
//
EFI_FIRMWARE_VOLUME_HEADER *mFvHeader = NULL;
UINT32 mFvLength = 0;
//
// External function implementations
//
EFI_STATUS
InitializeFvLib (
IN VOID *Fv,
IN UINT32 FvLength
)
/*++
Routine Description:
This initializes the FV lib with a pointer to the FV and length. It does not
verify the FV in any way.
Arguments:
Fv Buffer containing the FV.
FvLength Length of the FV
Returns:
EFI_SUCCESS Function Completed successfully.
EFI_INVALID_PARAMETER A required parameter was NULL.
--*/
{
//
// Verify input arguments
//
if (Fv == NULL) {
return EFI_INVALID_PARAMETER;
}
mFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Fv;
mFvLength = FvLength;
return EFI_SUCCESS;
}
EFI_STATUS
GetFvHeader (
OUT EFI_FIRMWARE_VOLUME_HEADER **FvHeader,
OUT UINT32 *FvLength
)
/*++
Routine Description:
This function returns a pointer to the current FV and the size.
Arguments:
FvHeader Pointer to the FV buffer.
FvLength Length of the FV
Returns:
EFI_SUCCESS Function Completed successfully.
EFI_INVALID_PARAMETER A required parameter was NULL.
EFI_ABORTED The library needs to be initialized.
--*/
{
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify input arguments
//
if (FvHeader == NULL) {
return EFI_INVALID_PARAMETER;
}
*FvHeader = mFvHeader;
return EFI_SUCCESS;
}
EFI_STATUS
GetNextFile (
IN EFI_FFS_FILE_HEADER *CurrentFile,
OUT EFI_FFS_FILE_HEADER **NextFile
)
/*++
Routine Description:
This function returns the next file. If the current file is NULL, it returns
the first file in the FV. If the function returns EFI_SUCCESS and the file
pointer is NULL, then there are no more files in the FV.
Arguments:
CurrentFile Pointer to the current file, must be within the current FV.
NextFile Pointer to the next file in the FV.
Returns:
EFI_SUCCESS Function completed successfully.
EFI_INVALID_PARAMETER A required parameter was NULL or is out of range.
EFI_ABORTED The library needs to be initialized.
--*/
{
EFI_STATUS Status;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify input arguments
//
if (NextFile == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Get first file
//
if (CurrentFile == NULL) {
CurrentFile = (EFI_FFS_FILE_HEADER *) ((UINTN) mFvHeader + mFvHeader->HeaderLength);
//
// Verify file is valid
//
Status = VerifyFfsFile (CurrentFile);
if (EFI_ERROR (Status)) {
//
// no files in this FV
//
*NextFile = NULL;
return EFI_SUCCESS;
} else {
//
// Verify file is in this FV.
//
if ((UINTN) CurrentFile >= (UINTN) mFvHeader + mFvLength - sizeof (EFI_FFS_FILE_HEADER)) {
*NextFile = NULL;
return EFI_SUCCESS;
}
*NextFile = CurrentFile;
return EFI_SUCCESS;
}
}
//
// Verify current file is in range
//
if (((UINTN) CurrentFile < (UINTN) mFvHeader + sizeof (EFI_FIRMWARE_VOLUME_HEADER)) ||
((UINTN) CurrentFile >= (UINTN) mFvHeader + mFvLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER))
) {
return EFI_INVALID_PARAMETER;
}
//
// Get next file, compensate for 8 byte alignment if necessary.
//
*NextFile = (EFI_FFS_FILE_HEADER *) (((UINTN) CurrentFile + GetLength (CurrentFile->Size) + 0x07) & (-1 << 3));
//
// Verify file is in this FV.
//
if ((UINTN) *NextFile >= (UINTN) mFvHeader + mFvLength - sizeof (EFI_FFS_FILE_HEADER)) {
*NextFile = NULL;
return EFI_SUCCESS;
}
//
// Verify file is valid
//
Status = VerifyFfsFile (*NextFile);
if (EFI_ERROR (Status)) {
//
// no more files in this FV
//
*NextFile = NULL;
return EFI_SUCCESS;
}
return EFI_SUCCESS;
}
EFI_STATUS
GetFileByName (
IN EFI_GUID *FileName,
OUT EFI_FFS_FILE_HEADER **File
)
/*++
Routine Description:
Find a file by name. The function will return NULL if the file is not found.
Arguments:
FileName The GUID file name of the file to search for.
File Return pointer. In the case of an error, contents are undefined.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_ABORTED An error was encountered.
EFI_INVALID_PARAMETER One of the parameters was NULL.
--*/
{
EFI_FFS_FILE_HEADER *CurrentFile;
EFI_STATUS Status;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify input parameters
//
if (FileName == NULL || File == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Get the first file
//
Status = GetNextFile (NULL, &CurrentFile);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "error parsing the FV", NULL);
return EFI_ABORTED;
}
//
// Loop as long as we have a valid file
//
while (CurrentFile) {
if (!CompareGuid (&CurrentFile->Name, FileName)) {
*File = CurrentFile;
return EFI_SUCCESS;
}
Status = GetNextFile (CurrentFile, &CurrentFile);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "error parsing the FV", NULL);
return EFI_ABORTED;
}
}
//
// File not found in this FV.
//
*File = NULL;
return EFI_SUCCESS;
}
EFI_STATUS
GetFileByType (
IN EFI_FV_FILETYPE FileType,
IN UINTN Instance,
OUT EFI_FFS_FILE_HEADER **File
)
/*++
Routine Description:
Find a file by type and instance. An instance of 1 is the first instance.
The function will return NULL if a matching file cannot be found.
File type EFI_FV_FILETYPE_ALL means any file type is valid.
Arguments:
FileType Type of file to search for.
Instance Instace of the file type to return.
File Return pointer. In the case of an error, contents are undefined.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_ABORTED An error was encountered.
EFI_INVALID_PARAMETER One of the parameters was NULL.
--*/
{
EFI_FFS_FILE_HEADER *CurrentFile;
EFI_STATUS Status;
UINTN FileCount;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify input parameters
//
if (File == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Initialize the number of matching files found.
//
FileCount = 0;
//
// Get the first file
//
Status = GetNextFile (NULL, &CurrentFile);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "error parsing FV", NULL);
return EFI_ABORTED;
}
//
// Loop as long as we have a valid file
//
while (CurrentFile) {
if (FileType == EFI_FV_FILETYPE_ALL || CurrentFile->Type == FileType) {
FileCount++;
}
if (FileCount == Instance) {
*File = CurrentFile;
return EFI_SUCCESS;
}
Status = GetNextFile (CurrentFile, &CurrentFile);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "error parsing the FV", NULL);
return EFI_ABORTED;
}
}
*File = NULL;
return EFI_SUCCESS;
}
EFI_STATUS
GetSectionByType (
IN EFI_FFS_FILE_HEADER *File,
IN EFI_SECTION_TYPE SectionType,
IN UINTN Instance,
OUT EFI_FILE_SECTION_POINTER *Section
)
/*++
Routine Description:
Find a section in a file by type and instance. An instance of 1 is the first
instance. The function will return NULL if a matching section cannot be found.
The function will not handle encapsulating sections.
Arguments:
File The file to search.
SectionType Type of file to search for.
Instance Instace of the section to return.
Section Return pointer. In the case of an error, contents are undefined.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_ABORTED An error was encountered.
EFI_INVALID_PARAMETER One of the parameters was NULL.
EFI_NOT_FOUND No found.
--*/
{
EFI_FILE_SECTION_POINTER CurrentSection;
EFI_STATUS Status;
UINTN SectionCount;
//
// Verify input parameters
//
if (File == NULL || Instance == 0) {
return EFI_INVALID_PARAMETER;
}
//
// Verify FFS header
//
Status = VerifyFfsFile (File);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "invalid FFS file", NULL);
return EFI_ABORTED;
}
//
// Initialize the number of matching sections found.
//
SectionCount = 0;
//
// Get the first section
//
CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) File + sizeof (EFI_FFS_FILE_HEADER));
//
// Loop as long as we have a valid file
//
while ((UINTN) CurrentSection.CommonHeader < (UINTN) File + GetLength (File->Size)) {
if (CurrentSection.CommonHeader->Type == SectionType) {
SectionCount++;
}
if (SectionCount == Instance) {
*Section = CurrentSection;
return EFI_SUCCESS;
}
//
// Find next section (including compensating for alignment issues.
//
CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((((UINTN) CurrentSection.CommonHeader) + GetLength (CurrentSection.CommonHeader->Size) + 0x03) & (-1 << 2));
}
//
// Section not found
//
(*Section).Code16Section = NULL;
return EFI_NOT_FOUND;
}
//
// will not parse compressed sections
//
EFI_STATUS
VerifyFv (
IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
)
/*++
Routine Description:
Verify the current pointer points to a valid FV header.
Arguments:
FvHeader Pointer to an alleged FV file.
Returns:
EFI_SUCCESS The FV header is valid.
EFI_VOLUME_CORRUPTED The FV header is not valid.
EFI_INVALID_PARAMETER A required parameter was NULL.
EFI_ABORTED Operation aborted.
--*/
{
UINT16 Checksum;
//
// Verify input parameters
//
if (FvHeader == NULL) {
return EFI_INVALID_PARAMETER;
}
if (FvHeader->Signature != EFI_FVH_SIGNATURE) {
Error (NULL, 0, 0, "invalid FV header signature", NULL);
return EFI_VOLUME_CORRUPTED;
}
//
// Verify header checksum
//
Checksum = CalculateSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));
if (Checksum != 0) {
Error (NULL, 0, 0, "invalid FV header checksum", NULL);
return EFI_ABORTED;
}
return EFI_SUCCESS;
}
EFI_STATUS
VerifyFfsFile (
IN EFI_FFS_FILE_HEADER *FfsHeader
)
/*++
Routine Description:
Verify the current pointer points to a FFS file header.
Arguments:
FfsHeader Pointer to an alleged FFS file.
Returns:
EFI_SUCCESS The Ffs header is valid.
EFI_NOT_FOUND This "file" is the beginning of free space.
EFI_VOLUME_CORRUPTED The Ffs header is not valid.
EFI_ABORTED The erase polarity is not known.
--*/
{
BOOLEAN ErasePolarity;
EFI_STATUS Status;
EFI_FFS_FILE_HEADER BlankHeader;
UINT8 Checksum;
UINT32 FileLength;
UINT32 OccupiedFileLength;
EFI_FFS_FILE_TAIL *Tail;
UINT8 SavedChecksum;
UINT8 SavedState;
UINT8 FileGuidString[80];
UINT32 TailSize;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Get the erase polarity.
//
Status = GetErasePolarity (&ErasePolarity);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Check if we have free space
//
if (ErasePolarity) {
memset (&BlankHeader, -1, sizeof (EFI_FFS_FILE_HEADER));
} else {
memset (&BlankHeader, 0, sizeof (EFI_FFS_FILE_HEADER));
}
if (memcmp (&BlankHeader, FfsHeader, sizeof (EFI_FFS_FILE_HEADER)) == 0) {
return EFI_NOT_FOUND;
}
//
// Convert the GUID to a string so we can at least report which file
// if we find an error.
//
PrintGuidToBuffer (&FfsHeader->Name, FileGuidString, sizeof (FileGuidString), TRUE);
if (FfsHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) {
TailSize = sizeof (EFI_FFS_FILE_TAIL);
} else {
TailSize = 0;
}
//
// Verify file header checksum
//
SavedState = FfsHeader->State;
FfsHeader->State = 0;
SavedChecksum = FfsHeader->IntegrityCheck.Checksum.File;
FfsHeader->IntegrityCheck.Checksum.File = 0;
Checksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));
FfsHeader->State = SavedState;
FfsHeader->IntegrityCheck.Checksum.File = SavedChecksum;
if (Checksum != 0) {
Error (NULL, 0, 0, FileGuidString, "invalid FFS file header checksum");
return EFI_ABORTED;
}
//
// Verify file checksum
//
if (FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) {
//
// Verify file data checksum
//
FileLength = GetLength (FfsHeader->Size);
OccupiedFileLength = (FileLength + 0x07) & (-1 << 3);
Checksum = CalculateSum8 ((UINT8 *) FfsHeader, FileLength - TailSize);
Checksum = (UINT8) (Checksum - FfsHeader->State);
if (Checksum != 0) {
Error (NULL, 0, 0, FileGuidString, "invalid FFS file checksum");
return EFI_ABORTED;
}
} else {
//
// File does not have a checksum
// Verify contents are 0x5A as spec'd
//
if (FfsHeader->IntegrityCheck.Checksum.File != FFS_FIXED_CHECKSUM) {
Error (NULL, 0, 0, FileGuidString, "invalid fixed FFS file header checksum");
return EFI_ABORTED;
}
}
//
// Check if the tail is present and verify it if it is.
//
if (FfsHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) {
//
// Verify tail is complement of integrity check field in the header.
//
Tail = (EFI_FFS_FILE_TAIL *) ((UINTN) FfsHeader + GetLength (FfsHeader->Size) - sizeof (EFI_FFS_FILE_TAIL));
if (FfsHeader->IntegrityCheck.TailReference != (EFI_FFS_FILE_TAIL)~(*Tail)) {
Error (NULL, 0, 0, FileGuidString, "invalid FFS file tail");
return EFI_ABORTED;
}
}
return EFI_SUCCESS;
}
UINT32
GetLength (
UINT8 *ThreeByteLength
)
/*++
Routine Description:
Converts a three byte length value into a UINT32.
Arguments:
ThreeByteLength Pointer to the first of the 3 byte length.
Returns:
UINT32 Size of the section
--*/
{
UINT32 Length;
if (ThreeByteLength == NULL) {
return 0;
}
Length = *((UINT32 *) ThreeByteLength);
Length = Length & 0x00FFFFFF;
return Length;
}
EFI_STATUS
GetErasePolarity (
OUT BOOLEAN *ErasePolarity
)
/*++
Routine Description:
This function returns with the FV erase polarity. If the erase polarity
for a bit is 1, the function return TRUE.
Arguments:
ErasePolarity A pointer to the erase polarity.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the input parameters was invalid.
EFI_ABORTED Operation aborted.
--*/
{
EFI_STATUS Status;
//
// Verify library has been initialized.
//
if (mFvHeader == NULL || mFvLength == 0) {
return EFI_ABORTED;
}
//
// Verify FV header
//
Status = VerifyFv (mFvHeader);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Verify input parameters.
//
if (ErasePolarity == NULL) {
return EFI_INVALID_PARAMETER;
}
if (mFvHeader->Attributes & EFI_FVB_ERASE_POLARITY) {
*ErasePolarity = TRUE;
} else {
*ErasePolarity = FALSE;
}
return EFI_SUCCESS;
}
UINT8
GetFileState (
IN BOOLEAN ErasePolarity,
IN EFI_FFS_FILE_HEADER *FfsHeader
)
/*++
Routine Description:
This function returns a the highest state bit in the FFS that is set.
It in no way validate the FFS file.
Arguments:
ErasePolarity The erase polarity for the file state bits.
FfsHeader Pointer to a FFS file.
Returns:
UINT8 The hightest set state of the file.
--*/
{
UINT8 FileState;
UINT8 HighestBit;
FileState = FfsHeader->State;
if (ErasePolarity) {
FileState = (UINT8)~FileState;
}
HighestBit = 0x80;
while (HighestBit != 0 && (HighestBit & FileState) == 0) {
HighestBit >>= 1;
}
return HighestBit;
}

View File

@@ -0,0 +1,185 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FvLib.h
Abstract:
These functions assist in parsing and manipulating a Firmware Volume.
--*/
#ifndef _EFI_FV_LIB_H
#define _EFI_FV_LIB_H
//
// Include files
//
#include <Base.h>
#include <UefiBaseTypes.h>
#include <Common/EfiImage.h>
#include <Common/FirmwareVolumeImageFormat.h>
#include <Common/FirmwareFileSystem.h>
#include <Common/FirmwareVolumeHeader.h>
/*
#include "TianoCommon.h"
#include "EfiFirmwareVolumeHeader.h"
#include "EfiFirmwareFileSystem.h"
*/
#include <string.h>
EFI_STATUS
InitializeFvLib (
IN VOID *Fv,
IN UINT32 FvLength
)
;
EFI_STATUS
GetFvHeader (
OUT EFI_FIRMWARE_VOLUME_HEADER **FvHeader,
OUT UINT32 *FvLength
)
;
EFI_STATUS
GetNextFile (
IN EFI_FFS_FILE_HEADER *CurrentFile,
OUT EFI_FFS_FILE_HEADER **NextFile
)
;
EFI_STATUS
GetFileByName (
IN EFI_GUID *FileName,
OUT EFI_FFS_FILE_HEADER **File
)
;
EFI_STATUS
GetFileByType (
IN EFI_FV_FILETYPE FileType,
IN UINTN Instance,
OUT EFI_FFS_FILE_HEADER **File
)
;
EFI_STATUS
GetSectionByType (
IN EFI_FFS_FILE_HEADER *File,
IN EFI_SECTION_TYPE SectionType,
IN UINTN Instance,
OUT EFI_FILE_SECTION_POINTER *Section
)
;
//
// will not parse compressed sections
//
EFI_STATUS
VerifyFv (
IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader
)
;
EFI_STATUS
VerifyFfsFile (
IN EFI_FFS_FILE_HEADER *FfsHeader
)
;
/*++
Routine Description:
Verify the current pointer points to a FFS file header.
Arguments:
FfsHeader Pointer to an alleged FFS file.
Returns:
EFI_SUCCESS The Ffs header is valid.
EFI_NOT_FOUND This "file" is the beginning of free space.
EFI_VOLUME_CORRUPTED The Ffs header is not valid.
--*/
UINT32
GetLength (
UINT8 *ThreeByteLength
)
;
/*++
Routine Description:
Converts a three byte length value into a UINT32.
Arguments:
ThreeByteLength Pointer to the first of the 3 byte length.
Returns:
UINT32 Size of the section
--*/
EFI_STATUS
GetErasePolarity (
OUT BOOLEAN *ErasePolarity
)
;
/*++
Routine Description:
This function returns with the FV erase polarity. If the erase polarity
for a bit is 1, the function return TRUE.
Arguments:
ErasePolarity A pointer to the erase polarity.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the input parameters was invalid.
--*/
UINT8
GetFileState (
IN BOOLEAN ErasePolarity,
IN EFI_FFS_FILE_HEADER *FfsHeader
)
;
/*++
Routine Description:
This function returns a the highest state bit in the FFS that is set.
It in no way validate the FFS file.
Arguments:
ErasePolarity The erase polarity for the file state bits.
FfsHeader Pointer to a FFS file.
Returns:
UINT8 The hightest set state of the file.
--*/
#endif

View File

@@ -0,0 +1,516 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
MyAlloc.c
Abstract:
File for memory allocation tracking functions.
--*/
#include "MyAlloc.h"
#if USE_MYALLOC
//
// Get back to original alloc/free calls.
//
#undef malloc
#undef calloc
#undef realloc
#undef free
//
// Start of allocation list.
//
static MY_ALLOC_STRUCT *MyAllocData = NULL;
//
//
//
static UINT32 MyAllocHeadMagik = MYALLOC_HEAD_MAGIK;
static UINT32 MyAllocTailMagik = MYALLOC_TAIL_MAGIK;
//
// ////////////////////////////////////////////////////////////////////////////
//
//
VOID
MyCheck (
BOOLEAN Final,
UINT8 File[],
UINTN Line
)
// *++
// Description:
//
// Check for corruptions in the allocated memory chain. If a corruption
// is detection program operation stops w/ an exit(1) call.
//
// Parameters:
//
// Final := When FALSE, MyCheck() returns if the allocated memory chain
// has not been corrupted. When TRUE, MyCheck() returns if there
// are no un-freed allocations. If there are un-freed allocations,
// they are displayed and exit(1) is called.
//
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// n/a
//
// --*/
//
{
MY_ALLOC_STRUCT *Tmp;
//
// Check parameters.
//
if (File == NULL || Line == 0) {
printf (
"\nMyCheck(Final=%u, File=%xh, Line=%u)"
"Invalid parameter(s).\n",
Final,
File,
Line
);
exit (1);
}
if (strlen (File) == 0) {
printf (
"\nMyCheck(Final=%u, File=%s, Line=%u)"
"Invalid parameter.\n",
Final,
File,
Line
);
exit (1);
}
//
// Check structure contents.
//
for (Tmp = MyAllocData; Tmp != NULL; Tmp = Tmp->Next) {
if (memcmp(Tmp->Buffer, &MyAllocHeadMagik, sizeof MyAllocHeadMagik) ||
memcmp(&Tmp->Buffer[Tmp->Size + sizeof(UINT32)], &MyAllocTailMagik, sizeof MyAllocTailMagik)) {
break;
}
}
//
// If Tmp is not NULL, the structure is corrupt.
//
if (Tmp != NULL) {
printf (
"\nMyCheck(Final=%u, File=%s, Line=%u)""\nStructure corrupted!"
"\nFile=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
Final,
File,
Line,
Tmp->File,
Tmp->Line,
Tmp->Size,
*(UINT32 *) (Tmp->Buffer),
*(UINT32 *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)])
);
exit (1);
}
//
// If Final is TRUE, display the state of the structure chain.
//
if (Final) {
if (MyAllocData != NULL) {
printf (
"\nMyCheck(Final=%u, File=%s, Line=%u)"
"\nSome allocated items have not been freed.\n",
Final,
File,
Line
);
for (Tmp = MyAllocData; Tmp != NULL; Tmp = Tmp->Next) {
printf (
"File=%s, Line=%u, nSize=%u, Head=%xh, Tail=%xh\n",
Tmp->File,
Tmp->Line,
Tmp->Size,
*(UINT32 *) (Tmp->Buffer),
*(UINT32 *) (&Tmp->Buffer[Tmp->Size + sizeof (UINT32)])
);
}
}
}
}
//
// ////////////////////////////////////////////////////////////////////////////
//
//
VOID *
MyAlloc (
UINTN Size,
UINT8 File[],
UINTN Line
)
// *++
// Description:
//
// Allocate a new link in the allocation chain along with enough storage
// for the File[] string, requested Size and alignment overhead. If
// memory cannot be allocated or the allocation chain has been corrupted,
// exit(1) will be called.
//
// Parameters:
//
// Size := Number of bytes (UINT8) requested by the called.
// Size cannot be zero.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// Pointer to the caller's buffer.
//
// --*/
//
{
MY_ALLOC_STRUCT *Tmp;
UINTN Len;
//
// Check for invalid parameters.
//
if (Size == 0 || File == NULL || Line == 0) {
printf (
"\nMyAlloc(Size=%u, File=%xh, Line=%u)"
"\nInvalid parameter(s).\n",
Size,
File,
Line
);
exit (1);
}
Len = strlen (File);
if (Len == 0) {
printf (
"\nMyAlloc(Size=%u, File=%s, Line=%u)"
"\nInvalid parameter.\n",
Size,
File,
Line
);
exit (1);
}
//
// Check the allocation list for corruption.
//
MyCheck (0, __FILE__, __LINE__);
//
// Allocate a new entry.
//
Tmp = calloc (
1,
sizeof (MY_ALLOC_STRUCT) + Len + 1 + sizeof (UINT64) + Size + (sizeof MyAllocHeadMagik) + (sizeof MyAllocTailMagik)
);
if (Tmp == NULL) {
printf (
"\nMyAlloc(Size=%u, File=%s, Line=%u)"
"\nOut of memory.\n",
Size,
File,
Line
);
exit (1);
}
//
// Fill in the new entry.
//
Tmp->File = ((UINT8 *) Tmp) + sizeof (MY_ALLOC_STRUCT);
strcpy (Tmp->File, File);
Tmp->Line = Line;
Tmp->Size = Size;
Tmp->Buffer = (UINT8 *) (((UINTN) Tmp + Len + 9) &~7);
memcpy (Tmp->Buffer, &MyAllocHeadMagik, sizeof MyAllocHeadMagik);
memcpy (
&Tmp->Buffer[Size + sizeof (UINT32)],
&MyAllocTailMagik,
sizeof MyAllocTailMagik
);
Tmp->Next = MyAllocData;
Tmp->Cksum = (UINTN) Tmp + (UINTN) (Tmp->Next) + Tmp->Line + Tmp->Size + (UINTN) (Tmp->File) + (UINTN) (Tmp->Buffer);
MyAllocData = Tmp;
return Tmp->Buffer + sizeof (UINT32);
}
//
// ////////////////////////////////////////////////////////////////////////////
//
//
VOID *
MyRealloc (
VOID *Ptr,
UINTN Size,
UINT8 File[],
UINTN Line
)
// *++
// Description:
//
// This does a MyAlloc(), memcpy() and MyFree(). There is no optimization
// for shrinking or expanding buffers. An invalid parameter will cause
// MyRealloc() to fail with a call to exit(1).
//
// Parameters:
//
// Ptr := Pointer to the caller's buffer to be re-allocated.
//
// Size := Size of new buffer. Size cannot be zero.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// Pointer to new caller's buffer.
//
// --*/
//
{
MY_ALLOC_STRUCT *Tmp;
VOID *Buffer;
//
// Check for invalid parameter(s).
//
if (Size == 0 || File == NULL || Line == 0) {
printf (
"\nMyRealloc(Ptr=%xh, Size=%u, File=%xh, Line=%u)"
"\nInvalid parameter(s).\n",
Ptr,
Size,
File,
Line
);
exit (1);
}
if (strlen (File) == 0) {
printf (
"\nMyRealloc(Ptr=%xh, Size=%u, File=%s, Line=%u)"
"\nInvalid parameter.\n",
Ptr,
Size,
File,
Line
);
exit (1);
}
//
// Find existing buffer in allocation list.
//
if (Ptr == NULL) {
Tmp = NULL;
} else if (&MyAllocData->Buffer[sizeof (UINT32)] == Ptr) {
Tmp = MyAllocData;
} else {
for (Tmp = MyAllocData;; Tmp = Tmp->Next) {
if (Tmp->Next == NULL) {
printf (
"\nMyRealloc(Ptr=%xh, Size=%u, File=%s, Line=%u)"
"\nCould not find buffer.\n",
Ptr,
Size,
File,
Line
);
exit (1);
}
Tmp = Tmp->Next;
}
}
//
// Allocate new buffer, copy old data, free old buffer.
//
Buffer = MyAlloc (Size, File, Line);
if (Buffer != NULL && Tmp != NULL) {
memcpy (
Buffer,
&Tmp->Buffer[sizeof (UINT32)],
((Size <= Tmp->Size) ? Size : Tmp->Size)
);
MyFree (Ptr, __FILE__, __LINE__);
}
return Buffer;
}
//
// ////////////////////////////////////////////////////////////////////////////
//
//
VOID
MyFree (
VOID *Ptr,
UINT8 File[],
UINTN Line
)
// *++
// Description:
//
// Release a previously allocated buffer. Invalid parameters will cause
// MyFree() to fail with an exit(1) call.
//
// Parameters:
//
// Ptr := Pointer to the caller's buffer to be freed.
// A NULL pointer will be ignored.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// n/a
//
// --*/
//
{
MY_ALLOC_STRUCT *Tmp;
MY_ALLOC_STRUCT *Tmp2;
//
// Check for invalid parameter(s).
//
if (File == NULL || Line == 0) {
printf (
"\nMyFree(Ptr=%xh, File=%xh, Line=%u)"
"\nInvalid parameter(s).\n",
Ptr,
File,
Line
);
exit (1);
}
if (strlen (File) == 0) {
printf (
"\nMyFree(Ptr=%xh, File=%s, Line=%u)"
"\nInvalid parameter.\n",
Ptr,
File,
Line
);
exit (1);
}
//
// Freeing NULL is always valid.
//
if (Ptr == NULL) {
return ;
}
//
// Fail if nothing is allocated.
//
if (MyAllocData == NULL) {
printf (
"\nMyFree(Ptr=%xh, File=%s, Line=%u)"
"\nCalled before memory allocated.\n",
Ptr,
File,
Line
);
exit (1);
}
//
// Check for corrupted allocation list.
//
MyCheck (0, __FILE__, __LINE__);
//
// Need special check for first item in list.
//
if (&MyAllocData->Buffer[sizeof (UINT32)] == Ptr) {
//
// Unlink first item in list.
//
Tmp = MyAllocData;
MyAllocData = MyAllocData->Next;
} else {
//
// Walk list looking for matching item.
//
for (Tmp = MyAllocData;; Tmp = Tmp->Next) {
//
// Fail if end of list is reached.
//
if (Tmp->Next == NULL) {
printf (
"\nMyFree(Ptr=%xh, File=%s, Line=%u)\n"
"\nNot found.\n",
Ptr,
File,
Line
);
exit (1);
}
//
// Leave loop when match is found.
//
if (&Tmp->Next->Buffer[sizeof (UINT32)] == Ptr) {
break;
}
}
//
// Unlink item from list.
//
Tmp2 = Tmp->Next;
Tmp->Next = Tmp->Next->Next;
Tmp = Tmp2;
}
//
// Release item.
//
free (Tmp);
}
#endif /* USE_MYALLOC */
/* eof - MyAlloc.c */

View File

@@ -0,0 +1,225 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
MyAlloc.h
Abstract:
Header file for memory allocation tracking functions.
--*/
#ifndef _MYALLOC_H_
#define _MYALLOC_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Base.h>
/*
#include "Tiano.h"
*/
//
// Default operation is to use the memory allocation tracking functions.
// To over-ride add "#define USE_MYALLOC 0" to your program header and/or
// source files as needed. Or, just do not include this header file in
// your project.
//
#ifndef USE_MYALLOC
#define USE_MYALLOC 1
#endif
#if USE_MYALLOC
//
// Replace C library allocation routines with MyAlloc routines.
//
#define malloc(size) MyAlloc ((size), __FILE__, __LINE__)
#define calloc(count, size) MyAlloc ((count) * (size), __FILE__, __LINE__)
#define realloc(ptr, size) MyRealloc ((ptr), (size), __FILE__, __LINE__)
#define free(ptr) MyFree ((ptr), __FILE__, __LINE__)
#define alloc_check(final) MyCheck ((final), __FILE__, __LINE__)
//
// Structure for checking/tracking memory allocations.
//
typedef struct MyAllocStruct {
UINTN Cksum;
struct MyAllocStruct *Next;
UINTN Line;
UINTN Size;
UINT8 *File;
UINT8 *Buffer;
} MY_ALLOC_STRUCT;
//
// Cksum := (UINTN)This + (UINTN)Next + Line + Size + (UINTN)File +
// (UINTN)Buffer;
//
// Next := Pointer to next allocation structure in the list.
//
// Line := __LINE__
//
// Size := Size of allocation request.
//
// File := Pointer to __FILE__ string stored immediately following
// MY_ALLOC_STRUCT in memory.
//
// Buffer := Pointer to UINT32 aligned storage immediately following
// the NULL terminated __FILE__ string. This is UINT32
// aligned because the underflow signature is 32-bits and
// this will place the first caller address on a 64-bit
// boundary.
//
//
// Signatures used to check for buffer overflow/underflow conditions.
//
#define MYALLOC_HEAD_MAGIK 0xBADFACED
#define MYALLOC_TAIL_MAGIK 0xDEADBEEF
VOID
MyCheck (
BOOLEAN Final,
UINT8 File[],
UINTN Line
)
;
//
// *++
// Description:
//
// Check for corruptions in the allocated memory chain. If a corruption
// is detection program operation stops w/ an exit(1) call.
//
// Parameters:
//
// Final := When FALSE, MyCheck() returns if the allocated memory chain
// has not been corrupted. When TRUE, MyCheck() returns if there
// are no un-freed allocations. If there are un-freed allocations,
// they are displayed and exit(1) is called.
//
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// n/a
//
// --*/
//
VOID *
MyAlloc (
UINTN Size,
UINT8 File[],
UINTN Line
)
;
//
// *++
// Description:
//
// Allocate a new link in the allocation chain along with enough storage
// for the File[] string, requested Size and alignment overhead. If
// memory cannot be allocated or the allocation chain has been corrupted,
// exit(1) will be called.
//
// Parameters:
//
// Size := Number of bytes (UINT8) requested by the called.
// Size cannot be zero.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// Pointer to the caller's buffer.
//
// --*/
//
VOID *
MyRealloc (
VOID *Ptr,
UINTN Size,
UINT8 File[],
UINTN Line
)
;
//
// *++
// Description:
//
// This does a MyAlloc(), memcpy() and MyFree(). There is no optimization
// for shrinking or expanding buffers. An invalid parameter will cause
// MyRealloc() to fail with a call to exit(1).
//
// Parameters:
//
// Ptr := Pointer to the caller's buffer to be re-allocated.
// Ptr cannot be NULL.
//
// Size := Size of new buffer. Size cannot be zero.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// Pointer to new caller's buffer.
//
// --*/
//
VOID
MyFree (
VOID *Ptr,
UINT8 File[],
UINTN Line
)
;
//
// *++
// Description:
//
// Release a previously allocated buffer. Invalid parameters will cause
// MyFree() to fail with an exit(1) call.
//
// Parameters:
//
// Ptr := Pointer to the caller's buffer to be freed.
// A NULL pointer will be ignored.
//
// File := Set to __FILE__ by macro expansion.
//
// Line := Set to __LINE__ by macro expansion.
//
// Returns:
//
// n/a
//
// --*/
//
#else /* USE_MYALLOC */
//
// Nothing to do when USE_MYALLOC is zero.
//
#define alloc_check(final)
#endif /* USE_MYALLOC */
#endif /* _MYALLOC_H_ */
/* eof - MyAlloc.h */

View File

@@ -0,0 +1,630 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ParseInf.c
Abstract:
This contains some useful functions for parsing INF files.
--*/
#include "ParseInf.h"
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#ifndef _MAX_PATH
#define _MAX_PATH 500
#endif
CHAR8 *
ReadLine (
IN MEMORY_FILE *InputFile,
IN OUT CHAR8 *InputBuffer,
IN UINTN MaxLength
)
/*++
Routine Description:
This function reads a line, stripping any comments.
The function reads a string from the input stream argument and stores it in
the input string. ReadLine reads characters from the current file position
to and including the first newline character, to the end of the stream, or
until the number of characters read is equal to MaxLength - 1, whichever
comes first. The newline character, if read, is replaced with a \0.
Arguments:
InputFile Memory file image.
InputBuffer Buffer to read into, must be _MAX_PATH size.
MaxLength The maximum size of the input buffer.
Returns:
NULL if error or EOF
InputBuffer otherwise
--*/
{
CHAR8 *CharPtr;
CHAR8 *EndOfLine;
UINTN CharsToCopy;
//
// Verify input parameters are not null
//
assert (InputBuffer);
assert (InputFile->FileImage);
assert (InputFile->Eof);
assert (InputFile->CurrentFilePointer);
//
// Check for end of file condition
//
if (InputFile->CurrentFilePointer >= InputFile->Eof) {
return NULL;
}
//
// Find the next newline char
//
EndOfLine = strchr (InputFile->CurrentFilePointer, '\n');
//
// Determine the number of characters to copy.
//
if (EndOfLine == 0) {
//
// If no newline found, copy to the end of the file.
//
CharsToCopy = InputFile->Eof - InputFile->CurrentFilePointer;
} else if (EndOfLine >= InputFile->Eof) {
//
// If the newline found was beyond the end of file, copy to the eof.
//
CharsToCopy = InputFile->Eof - InputFile->CurrentFilePointer;
} else {
//
// Newline found in the file.
//
CharsToCopy = EndOfLine - InputFile->CurrentFilePointer;
}
//
// If the end of line is too big for the current buffer, set it to the max
// size of the buffer (leaving room for the \0.
//
if (CharsToCopy > MaxLength - 1) {
CharsToCopy = MaxLength - 1;
}
//
// Copy the line.
//
memcpy (InputBuffer, InputFile->CurrentFilePointer, CharsToCopy);
//
// Add the null termination over the 0x0D
//
InputBuffer[CharsToCopy - 1] = '\0';
//
// Increment the current file pointer (include the 0x0A)
//
InputFile->CurrentFilePointer += CharsToCopy + 1;
//
// Strip any comments
//
CharPtr = strstr (InputBuffer, "//");
if (CharPtr != 0) {
CharPtr[0] = 0;
}
//
// Return the string
//
return InputBuffer;
}
BOOLEAN
FindSection (
IN MEMORY_FILE *InputFile,
IN CHAR8 *Section
)
/*++
Routine Description:
This function parses a file from the beginning to find a section.
The section string may be anywhere within a line.
Arguments:
InputFile Memory file image.
Section Section to search for
Returns:
FALSE if error or EOF
TRUE if section found
--*/
{
CHAR8 InputBuffer[_MAX_PATH];
CHAR8 *CurrentToken;
//
// Verify input is not NULL
//
assert (InputFile->FileImage);
assert (InputFile->Eof);
assert (InputFile->CurrentFilePointer);
assert (Section);
//
// Rewind to beginning of file
//
InputFile->CurrentFilePointer = InputFile->FileImage;
//
// Read lines until the section is found
//
while (InputFile->CurrentFilePointer < InputFile->Eof) {
//
// Read a line
//
ReadLine (InputFile, InputBuffer, _MAX_PATH);
//
// Check if the section is found
//
CurrentToken = strstr (InputBuffer, Section);
if (CurrentToken != NULL) {
return TRUE;
}
}
return FALSE;
}
EFI_STATUS
FindToken (
IN MEMORY_FILE *InputFile,
IN CHAR8 *Section,
IN CHAR8 *Token,
IN UINTN Instance,
OUT CHAR8 *Value
)
/*++
Routine Description:
Finds a token value given the section and token to search for.
Arguments:
InputFile Memory file image.
Section The section to search for, a string within [].
Token The token to search for, e.g. EFI_PEIM_RECOVERY, followed by an = in the INF file.
Instance The instance of the token to search for. Zero is the first instance.
Value The string that holds the value following the =. Must be _MAX_PATH in size.
Returns:
EFI_SUCCESS Value found.
EFI_ABORTED Format error detected in INF file.
EFI_INVALID_PARAMETER Input argument was null.
EFI_LOAD_ERROR Error reading from the file.
EFI_NOT_FOUND Section/Token/Value not found.
--*/
{
CHAR8 InputBuffer[_MAX_PATH];
CHAR8 *CurrentToken;
BOOLEAN ParseError;
BOOLEAN ReadError;
UINTN Occurrance;
//
// Check input parameters
//
if (InputFile->FileImage == NULL ||
InputFile->Eof == NULL ||
InputFile->CurrentFilePointer == NULL ||
Section == NULL ||
strlen (Section) == 0 ||
Token == NULL ||
strlen (Token) == 0 ||
Value == NULL
) {
return EFI_INVALID_PARAMETER;
}
//
// Initialize error codes
//
ParseError = FALSE;
ReadError = FALSE;
//
// Initialize our instance counter for the search token
//
Occurrance = 0;
if (FindSection (InputFile, Section)) {
//
// Found the desired section, find and read the desired token
//
do {
//
// Read a line from the file
//
if (ReadLine (InputFile, InputBuffer, _MAX_PATH) == NULL) {
//
// Error reading from input file
//
ReadError = TRUE;
break;
}
//
// Get the first non-whitespace string
//
CurrentToken = strtok (InputBuffer, " \t\n");
if (CurrentToken == NULL) {
//
// Whitespace line found (or comment) so continue
//
CurrentToken = InputBuffer;
continue;
}
//
// Make sure we have not reached the end of the current section
//
if (CurrentToken[0] == '[') {
break;
}
//
// Compare the current token with the desired token
//
if (strcmp (CurrentToken, Token) == 0) {
//
// Found it
//
//
// Check if it is the correct instance
//
if (Instance == Occurrance) {
//
// Copy the contents following the =
//
CurrentToken = strtok (NULL, "= \t\n");
if (CurrentToken == NULL) {
//
// Nothing found, parsing error
//
ParseError = TRUE;
} else {
//
// Copy the current token to the output value
//
strcpy (Value, CurrentToken);
return EFI_SUCCESS;
}
} else {
//
// Increment the occurrance found
//
Occurrance++;
}
}
} while (
!ParseError &&
!ReadError &&
InputFile->CurrentFilePointer < InputFile->Eof &&
CurrentToken[0] != '[' &&
Occurrance <= Instance
);
}
//
// Distinguish between read errors and INF file format errors.
//
if (ReadError) {
return EFI_LOAD_ERROR;
}
if (ParseError) {
return EFI_ABORTED;
}
return EFI_NOT_FOUND;
}
EFI_STATUS
StringToGuid (
IN CHAR8 *AsciiGuidBuffer,
OUT EFI_GUID *GuidBuffer
)
/*++
Routine Description:
Converts a string to an EFI_GUID. The string must be in the
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.
Arguments:
AsciiGuidBuffer - pointer to ascii string
GuidBuffer - pointer to destination Guid
Returns:
EFI_ABORTED Could not convert the string
EFI_SUCCESS The string was successfully converted
EFI_INVALID_PARAMETER Input parameter is invalid.
--*/
{
INT32 Index;
UINTN Data1;
UINTN Data2;
UINTN Data3;
UINTN Data4[8];
if (AsciiGuidBuffer == NULL || GuidBuffer == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Scan the guid string into the buffer
//
Index = sscanf (
AsciiGuidBuffer,
"%08x-%04x-%04x-%02x%02x-%02hx%02hx%02hx%02hx%02hx%02hx",
&Data1,
&Data2,
&Data3,
&Data4[0],
&Data4[1],
&Data4[2],
&Data4[3],
&Data4[4],
&Data4[5],
&Data4[6],
&Data4[7]
);
//
// Verify the correct number of items were scanned.
//
if (Index != 11) {
printf ("ERROR: Malformed GUID \"%s\".\n\n", AsciiGuidBuffer);
return EFI_ABORTED;
}
//
// Copy the data into our GUID.
//
GuidBuffer->Data1 = (UINT32) Data1;
GuidBuffer->Data2 = (UINT16) Data2;
GuidBuffer->Data3 = (UINT16) Data3;
GuidBuffer->Data4[0] = (UINT8) Data4[0];
GuidBuffer->Data4[1] = (UINT8) Data4[1];
GuidBuffer->Data4[2] = (UINT8) Data4[2];
GuidBuffer->Data4[3] = (UINT8) Data4[3];
GuidBuffer->Data4[4] = (UINT8) Data4[4];
GuidBuffer->Data4[5] = (UINT8) Data4[5];
GuidBuffer->Data4[6] = (UINT8) Data4[6];
GuidBuffer->Data4[7] = (UINT8) Data4[7];
return EFI_SUCCESS;
}
EFI_STATUS
AsciiStringToUint64 (
IN CONST CHAR8 *AsciiString,
IN BOOLEAN IsHex,
OUT UINT64 *ReturnValue
)
/*++
Routine Description:
Converts a null terminated ascii string that represents a number into a
UINT64 value. A hex number may be preceeded by a 0x, but may not be
succeeded by an h. A number without 0x or 0X is considered to be base 10
unless the IsHex input is true.
Arguments:
AsciiString The string to convert.
IsHex Force the string to be treated as a hex number.
ReturnValue The return value.
Returns:
EFI_SUCCESS Number successfully converted.
EFI_ABORTED Invalid character encountered.
--*/
{
UINT8 Index;
UINT64 HexNumber;
CHAR8 CurrentChar;
//
// Initialize the result
//
HexNumber = 0;
//
// Add each character to the result
//
if (IsHex || (AsciiString[0] == '0' && (AsciiString[1] == 'x' || AsciiString[1] == 'X'))) {
//
// Verify string is a hex number
//
for (Index = 2; Index < strlen (AsciiString); Index++) {
if (isxdigit (AsciiString[Index]) == 0) {
return EFI_ABORTED;
}
}
//
// Convert the hex string.
//
for (Index = 2; AsciiString[Index] != '\0'; Index++) {
CurrentChar = AsciiString[Index];
HexNumber *= 16;
if (CurrentChar >= '0' && CurrentChar <= '9') {
HexNumber += CurrentChar - '0';
} else if (CurrentChar >= 'a' && CurrentChar <= 'f') {
HexNumber += CurrentChar - 'a' + 10;
} else if (CurrentChar >= 'A' && CurrentChar <= 'F') {
HexNumber += CurrentChar - 'A' + 10;
} else {
//
// Unrecognized character
//
return EFI_ABORTED;
}
}
*ReturnValue = HexNumber;
} else {
//
// Verify string is a number
//
for (Index = 0; Index < strlen (AsciiString); Index++) {
if (isdigit (AsciiString[Index]) == 0) {
return EFI_ABORTED;
}
}
*ReturnValue = atol (AsciiString);
}
return EFI_SUCCESS;
};
CHAR8 *
ReadLineInStream (
IN FILE *InputFile,
IN OUT CHAR8 *InputBuffer
)
/*++
Routine Description:
This function reads a line, stripping any comments.
// BUGBUG: This is obsolete once genmake goes away...
Arguments:
InputFile Stream pointer.
InputBuffer Buffer to read into, must be _MAX_PATH size.
Returns:
NULL if error or EOF
InputBuffer otherwise
--*/
{
CHAR8 *CharPtr;
//
// Verify input parameters are not null
//
assert (InputFile);
assert (InputBuffer);
//
// Read a line
//
if (fgets (InputBuffer, _MAX_PATH, InputFile) == NULL) {
return NULL;
}
//
// Strip any comments
//
CharPtr = strstr (InputBuffer, "//");
if (CharPtr != 0) {
CharPtr[0] = 0;
}
CharPtr = strstr (InputBuffer, "#");
if (CharPtr != 0) {
CharPtr[0] = 0;
}
//
// Return the string
//
return InputBuffer;
}
BOOLEAN
FindSectionInStream (
IN FILE *InputFile,
IN CHAR8 *Section
)
/*++
Routine Description:
This function parses a stream file from the beginning to find a section.
The section string may be anywhere within a line.
// BUGBUG: This is obsolete once genmake goes away...
Arguments:
InputFile Stream pointer.
Section Section to search for
Returns:
FALSE if error or EOF
TRUE if section found
--*/
{
CHAR8 InputBuffer[_MAX_PATH];
CHAR8 *CurrentToken;
//
// Verify input is not NULL
//
assert (InputFile);
assert (Section);
//
// Rewind to beginning of file
//
if (fseek (InputFile, 0, SEEK_SET) != 0) {
return FALSE;
}
//
// Read lines until the section is found
//
while (feof (InputFile) == 0) {
//
// Read a line
//
ReadLineInStream (InputFile, InputBuffer);
//
// Check if the section is found
//
CurrentToken = strstr (InputBuffer, Section);
if (CurrentToken != NULL) {
return TRUE;
}
}
return FALSE;
}

View File

@@ -0,0 +1,235 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ParseInf.h
Abstract:
Header file for helper functions useful for parsing INF files.
--*/
#ifndef _EFI_PARSE_INF_H
#define _EFI_PARSE_INF_H
/* #include "TianoCommon.h" */
#include <Base.h>
#include <stdio.h>
#include <stdlib.h>
#include <UefiBaseTypes.h>
//
// Common data structures
//
typedef struct {
CHAR8 *FileImage;
CHAR8 *Eof;
CHAR8 *CurrentFilePointer;
} MEMORY_FILE;
//
// Functions declarations
//
CHAR8 *
ReadLine (
IN MEMORY_FILE *InputFile,
IN OUT CHAR8 *InputBuffer,
IN UINT32 MaxLength
)
;
/*++
Routine Description:
This function reads a line, stripping any comments.
The function reads a string from the input stream argument and stores it in
the input string. ReadLine reads characters from the current file position
to and including the first newline character, to the end of the stream, or
until the number of characters read is equal to MaxLength - 1, whichever
comes first. The newline character, if read, is replaced with a \0.
Arguments:
InputFile Memory file image.
InputBuffer Buffer to read into, must be _MAX_PATH size.
MaxLength The maximum size of the input buffer.
Returns:
NULL if error or EOF
InputBuffer otherwise
--*/
BOOLEAN
FindSection (
IN MEMORY_FILE *InputFile,
IN CHAR8 *Section
)
;
/*++
Routine Description:
This function parses a file from the beginning to find a section.
The section string may be anywhere within a line.
Arguments:
InputFile Memory file image.
Section Section to search for
Returns:
FALSE if error or EOF
TRUE if section found
--*/
EFI_STATUS
FindToken (
IN MEMORY_FILE *InputFile,
IN CHAR8 *Section,
IN CHAR8 *Token,
IN UINTN Instance,
OUT CHAR8 *Value
)
;
/*++
Routine Description:
Finds a token value given the section and token to search for.
Arguments:
InputFile Memory file image.
Section The section to search for, a string within [].
Token The token to search for, e.g. EFI_PEIM_RECOVERY, followed by an = in the INF file.
Instance The instance of the token to search for. Zero is the first instance.
Value The string that holds the value following the =. Must be _MAX_PATH in size.
Returns:
EFI_SUCCESS Value found.
EFI_ABORTED Format error detected in INF file.
EFI_INVALID_PARAMETER Input argument was null.
EFI_LOAD_ERROR Error reading from the file.
EFI_NOT_FOUND Section/Token/Value not found.
--*/
EFI_STATUS
StringToGuid (
IN CHAR8 *AsciiGuidBuffer,
OUT EFI_GUID *GuidBuffer
)
;
/*++
Routine Description:
Converts a string to an EFI_GUID. The string must be in the
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.
Arguments:
GuidBuffer - pointer to destination Guid
AsciiGuidBuffer - pointer to ascii string
Returns:
EFI_ABORTED Could not convert the string
EFI_SUCCESS The string was successfully converted
--*/
EFI_STATUS
AsciiStringToUint64 (
IN CONST CHAR8 *AsciiString,
IN BOOLEAN IsHex,
OUT UINT64 *ReturnValue
)
;
/*++
Routine Description:
Converts a null terminated ascii string that represents a number into a
UINT64 value. A hex number may be preceeded by a 0x, but may not be
succeeded by an h. A number without 0x or 0X is considered to be base 10
unless the IsHex input is true.
Arguments:
AsciiString The string to convert.
IsHex Force the string to be treated as a hex number.
ReturnValue The return value.
Returns:
EFI_SUCCESS Number successfully converted.
EFI_ABORTED Invalid character encountered.
--*/
CHAR8 *
ReadLineInStream (
IN FILE *InputFile,
IN OUT CHAR8 *InputBuffer
)
;
/*++
Routine Description:
This function reads a line, stripping any comments.
Arguments:
InputFile Stream pointer.
InputBuffer Buffer to read into, must be _MAX_PATH size.
Returns:
NULL if error or EOF
InputBuffer otherwise
--*/
BOOLEAN
FindSectionInStream (
IN FILE *InputFile,
IN CHAR8 *Section
)
;
/*++
Routine Description:
This function parses a stream file from the beginning to find a section.
The section string may be anywhere within a line.
Arguments:
InputFile Stream pointer.
Section Section to search for
Returns:
FALSE if error or EOF
TRUE if section found
--*/
#endif

View File

@@ -0,0 +1,131 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Debug.c
Abstract:
Support for Debug primatives.
--*/
#include "Tiano.h"
#include "Pei.h"
#include "EfiPrintLib.h"
#include "EfiStatusCode.h"
#include "EfiCommonLib.h"
#include EFI_GUID_DEFINITION (StatusCodeCallerId)
#include EFI_GUID_DEFINITION (StatusCodeDataTypeId)
VOID
PeiDebugAssert (
IN EFI_PEI_SERVICES **PeiServices,
IN CHAR8 *FileName,
IN INTN LineNumber,
IN CHAR8 *Description
)
/*++
Routine Description:
Worker function for ASSERT(). If Error Logging hub is loaded log ASSERT
information. If Error Logging hub is not loaded DEADLOOP ().
Arguments:
PeiServices - The PEI core services table.
FileName - File name of failing routine.
LineNumber - Line number of failing ASSERT().
Description - Description, usually the assertion,
Returns:
None
--*/
{
UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
EfiDebugAssertWorker (FileName, LineNumber, Description, sizeof (Buffer), Buffer);
//
// We choose NOT to use PEI_REPORT_STATUS_CODE here, because when debug is enable,
// we want get enough information if assert.
//
(**PeiServices).PeiReportStatusCode (
PeiServices,
(EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),
(EFI_SOFTWARE_PEI_MODULE | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),
0,
&gEfiCallerIdGuid,
(EFI_STATUS_CODE_DATA *) Buffer
);
EFI_DEADLOOP ();
}
VOID
PeiDebugPrint (
IN EFI_PEI_SERVICES **PeiServices,
IN UINTN ErrorLevel,
IN CHAR8 *Format,
...
)
/*++
Routine Description:
Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT
information. If Error Logging hub is not loaded do nothing.
Arguments:
PeiServices - The PEI core services table.
ErrorLevel - If error level is set do the debug print.
Format - String to use for the print, followed by Print arguments.
... - Print arguments
Returns:
None
--*/
{
VA_LIST Marker;
UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
VA_START (Marker, Format);
EfiDebugVPrintWorker (ErrorLevel, Format, Marker, sizeof (Buffer), Buffer);
//
// We choose NOT to use PEI_REPORT_STATUS_CODE here, because when debug is enable,
// we want get enough information if assert.
//
(**PeiServices).PeiReportStatusCode (
PeiServices,
EFI_DEBUG_CODE,
(EFI_SOFTWARE_PEI_MODULE | EFI_DC_UNSPECIFIED),
0,
&gEfiCallerIdGuid,
(EFI_STATUS_CODE_DATA *) Buffer
);
return ;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,495 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
hob.c
Abstract:
PEI Library Functions
--*/
#include "Tiano.h"
#include "Pei.h"
#include "peilib.h"
#include EFI_GUID_DEFINITION (MemoryAllocationHob)
EFI_STATUS
PeiBuildHobModule (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_GUID *ModuleName,
IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
IN UINT64 ModuleLength,
IN EFI_PHYSICAL_ADDRESS EntryPoint
)
/*++
Routine Description:
Builds a HOB for a loaded PE32 module
Arguments:
PeiServices - The PEI core services table.
ModuleName - The GUID File Name of the module
MemoryAllocationModule - The 64 bit physical address of the module
ModuleLength - The length of the module in bytes
EntryPoint - The 64 bit physical address of the entry point
to the module
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
{
EFI_STATUS Status;
EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;
Status = (*PeiServices)->CreateHob (
PeiServices,
EFI_HOB_TYPE_GUID_EXTENSION,
sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE),
&Hob
);
if (EFI_ERROR (Status)) {
return Status;
}
Hob->MemoryAllocationHeader.Name = gEfiHobMemeryAllocModuleGuid;
Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;
Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;
Hob->ModuleName = *ModuleName;
Hob->EntryPoint = EntryPoint;
return EFI_SUCCESS;
}
EFI_STATUS
PeiBuildHobResourceDescriptor (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_RESOURCE_TYPE ResourceType,
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
IN EFI_PHYSICAL_ADDRESS PhysicalStart,
IN UINT64 NumberOfBytes
)
/*++
Routine Description:
Builds a HOB that describes a chunck of system memory
Arguments:
PeiServices - The PEI core services table.
ResourceType - The type of resource described by this HOB
ResourceAttribute - The resource attributes of the memory described by this HOB
PhysicalStart - The 64 bit physical address of memory described by this HOB
NumberOfBytes - The length of the memoty described by this HOB in bytes
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
{
EFI_STATUS Status;
EFI_HOB_RESOURCE_DESCRIPTOR *Hob;
Status = (*PeiServices)->CreateHob (
PeiServices,
EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,
sizeof (EFI_HOB_RESOURCE_DESCRIPTOR),
&Hob
);
if (EFI_ERROR (Status)) {
return Status;
}
Hob->ResourceType = ResourceType;
Hob->ResourceAttribute = ResourceAttribute;
Hob->PhysicalStart = PhysicalStart;
Hob->ResourceLength = NumberOfBytes;
return EFI_SUCCESS;
}
EFI_STATUS
PeiBuildHobGuid (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_GUID *Guid,
IN UINTN DataLength,
IN OUT VOID **Hob
)
/*++
Routine Description:
Builds a custom HOB that is tagged with a GUID for identification
Arguments:
PeiServices - The PEI core services table.
Guid - The GUID of the custome HOB type
DataLength - The size of the data payload for the GUIDed HOB
Hob - Pointer to the Hob
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
{
EFI_STATUS Status;
Status = (*PeiServices)->CreateHob (
PeiServices,
EFI_HOB_TYPE_GUID_EXTENSION,
(UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength),
Hob
);
if (EFI_ERROR (Status)) {
return Status;
}
((EFI_HOB_GUID_TYPE *)(*Hob))->Name = *Guid;
return EFI_SUCCESS;
}
EFI_STATUS
PeiBuildHobGuidData (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_GUID *Guid,
IN VOID *Data,
IN UINTN DataLength
)
/*++
Routine Description:
Builds a custom HOB that is tagged with a GUID for identification
Arguments:
PeiServices - The PEI core services table.
Guid - The GUID of the custome HOB type
Data - The data to be copied into the GUIDed HOB data field.
DataLength - The data field length.
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
{
EFI_STATUS Status;
EFI_HOB_GUID_TYPE *Hob;
Status = PeiBuildHobGuid (
PeiServices,
Guid,
DataLength,
&Hob
);
if (EFI_ERROR (Status)) {
return Status;
}
Hob++;
(*PeiServices)->CopyMem (Hob, Data, DataLength);
return EFI_SUCCESS;
}
EFI_STATUS
PeiBuildHobFv (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
/*++
Routine Description:
Builds a Firmware Volume HOB
Arguments:
PeiServices - The PEI core services table.
BaseAddress - The base address of the Firmware Volume
Length - The size of the Firmware Volume in bytes
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
{
EFI_STATUS Status;
EFI_HOB_FIRMWARE_VOLUME *Hob;
Status = (*PeiServices)->CreateHob (
PeiServices,
EFI_HOB_TYPE_FV,
sizeof (EFI_HOB_FIRMWARE_VOLUME),
&Hob
);
if (EFI_ERROR (Status)) {
return Status;
}
Hob->BaseAddress = BaseAddress;
Hob->Length = Length;
return EFI_SUCCESS;
}
EFI_STATUS
PeiBuildHobCpu (
IN EFI_PEI_SERVICES **PeiServices,
IN UINT8 SizeOfMemorySpace,
IN UINT8 SizeOfIoSpace
)
/*++
Routine Description:
Builds a HOB for the CPU
Arguments:
PeiServices - The PEI core services table.
SizeOfMemorySpace - Identifies the maximum
physical memory addressibility of the processor.
SizeOfIoSpace - Identifies the maximum physical I/O addressibility
of the processor.
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
{
EFI_STATUS Status;
EFI_HOB_CPU *Hob;
Status = (*PeiServices)->CreateHob (
PeiServices,
EFI_HOB_TYPE_CPU,
sizeof (EFI_HOB_CPU),
&Hob
);
if (EFI_ERROR (Status)) {
return Status;
}
Hob->SizeOfMemorySpace = SizeOfMemorySpace;
Hob->SizeOfIoSpace = SizeOfIoSpace;
return EFI_SUCCESS;
}
EFI_STATUS
PeiBuildHobStack (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
/*++
Routine Description:
Builds a HOB for the Stack
Arguments:
PeiServices - The PEI core services table.
BaseAddress - The 64 bit physical address of the Stack
Length - The length of the stack in bytes
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
{
EFI_STATUS Status;
EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;
Status = (*PeiServices)->CreateHob (
PeiServices,
EFI_HOB_TYPE_MEMORY_ALLOCATION,
sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK),
&Hob
);
if (EFI_ERROR (Status)) {
return Status;
}
Hob->AllocDescriptor.Name = gEfiHobMemeryAllocStackGuid;
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
Hob->AllocDescriptor.MemoryLength = Length;
Hob->AllocDescriptor.MemoryType = EfiConventionalMemory;
return EFI_SUCCESS;
}
EFI_STATUS
PeiBuildHobBspStore (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN EFI_MEMORY_TYPE MemoryType
)
/*++
Routine Description:
Builds a HOB for the bsp store
Arguments:
PeiServices - The PEI core services table.
BaseAddress - The 64 bit physical address of the bsp
Length - The length of the bsp store in bytes
MemoryType - Memory type
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
{
EFI_STATUS Status;
EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;
Status = (*PeiServices)->CreateHob (
PeiServices,
EFI_HOB_TYPE_MEMORY_ALLOCATION,
sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE),
&Hob
);
if (EFI_ERROR (Status)) {
return Status;
}
Hob->AllocDescriptor.Name = gEfiHobMemeryAllocBspStoreGuid;
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
Hob->AllocDescriptor.MemoryLength = Length;
Hob->AllocDescriptor.MemoryType = MemoryType;
return EFI_SUCCESS;
}
EFI_STATUS
PeiBuildHobMemoryAllocation (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN EFI_GUID *Name,
IN EFI_MEMORY_TYPE MemoryType
)
/*++
Routine Description:
Builds a HOB for the memory allocation.
Arguments:
PeiServices - The PEI core services table.
BaseAddress - The 64 bit physical address of the memory
Length - The length of the memory allocation in bytes
Name - Name for Hob
MemoryType - Memory type
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
{
EFI_STATUS Status;
EFI_HOB_MEMORY_ALLOCATION *Hob;
Status = (*PeiServices)->CreateHob (
PeiServices,
EFI_HOB_TYPE_MEMORY_ALLOCATION,
sizeof (EFI_HOB_MEMORY_ALLOCATION),
&Hob
);
if (EFI_ERROR (Status)) {
return Status;
}
if (Name != NULL) {
Hob->AllocDescriptor.Name = *Name;
} else {
(*PeiServices)->SetMem(&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID), 0);
}
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
Hob->AllocDescriptor.MemoryLength = Length;
Hob->AllocDescriptor.MemoryType = MemoryType;
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,244 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeCoffLoaderEx.c
Abstract:
Fixes Intel Itanium(TM) specific relocation types
Revision History
--*/
#include "TianoCommon.h"
#include "EfiImage.h"
#define EXT_IMM64(Value, Address, Size, InstPos, ValPos) \
Value |= (((UINT64)((*(Address) >> InstPos) & (((UINT64)1 << Size) - 1))) << ValPos)
#define INS_IMM64(Value, Address, Size, InstPos, ValPos) \
*(UINT32*)Address = (*(UINT32*)Address & ~(((1 << Size) - 1) << InstPos)) | \
((UINT32)((((UINT64)Value >> ValPos) & (((UINT64)1 << Size) - 1))) << InstPos)
#define IMM64_IMM7B_INST_WORD_X 3
#define IMM64_IMM7B_SIZE_X 7
#define IMM64_IMM7B_INST_WORD_POS_X 4
#define IMM64_IMM7B_VAL_POS_X 0
#define IMM64_IMM9D_INST_WORD_X 3
#define IMM64_IMM9D_SIZE_X 9
#define IMM64_IMM9D_INST_WORD_POS_X 18
#define IMM64_IMM9D_VAL_POS_X 7
#define IMM64_IMM5C_INST_WORD_X 3
#define IMM64_IMM5C_SIZE_X 5
#define IMM64_IMM5C_INST_WORD_POS_X 13
#define IMM64_IMM5C_VAL_POS_X 16
#define IMM64_IC_INST_WORD_X 3
#define IMM64_IC_SIZE_X 1
#define IMM64_IC_INST_WORD_POS_X 12
#define IMM64_IC_VAL_POS_X 21
#define IMM64_IMM41a_INST_WORD_X 1
#define IMM64_IMM41a_SIZE_X 10
#define IMM64_IMM41a_INST_WORD_POS_X 14
#define IMM64_IMM41a_VAL_POS_X 22
#define IMM64_IMM41b_INST_WORD_X 1
#define IMM64_IMM41b_SIZE_X 8
#define IMM64_IMM41b_INST_WORD_POS_X 24
#define IMM64_IMM41b_VAL_POS_X 32
#define IMM64_IMM41c_INST_WORD_X 2
#define IMM64_IMM41c_SIZE_X 23
#define IMM64_IMM41c_INST_WORD_POS_X 0
#define IMM64_IMM41c_VAL_POS_X 40
#define IMM64_SIGN_INST_WORD_X 3
#define IMM64_SIGN_SIZE_X 1
#define IMM64_SIGN_INST_WORD_POS_X 27
#define IMM64_SIGN_VAL_POS_X 63
EFI_STATUS
PeCoffLoaderRelocateImageEx (
IN UINT16 *Reloc,
IN OUT CHAR8 *Fixup,
IN OUT CHAR8 **FixupData,
IN UINT64 Adjust
)
/*++
Routine Description:
Performs an Itanium-based specific relocation fixup
Arguments:
Reloc - Pointer to the relocation record
Fixup - Pointer to the address to fix up
FixupData - Pointer to a buffer to log the fixups
Adjust - The offset to adjust the fixup
Returns:
Status code
--*/
{
UINT64 *F64;
UINT64 FixupVal;
switch ((*Reloc) >> 12) {
case EFI_IMAGE_REL_BASED_DIR64:
F64 = (UINT64 *) Fixup;
*F64 = *F64 + (UINT64) Adjust;
if (*FixupData != NULL) {
*FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));
*(UINT64 *)(*FixupData) = *F64;
*FixupData = *FixupData + sizeof(UINT64);
}
break;
case EFI_IMAGE_REL_BASED_IA64_IMM64:
//
// Align it to bundle address before fixing up the
// 64-bit immediate value of the movl instruction.
//
Fixup = (CHAR8 *)((UINTN) Fixup & (UINTN) ~(15));
FixupVal = (UINT64)0;
//
// Extract the lower 32 bits of IMM64 from bundle
//
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IMM7B_INST_WORD_X,
IMM64_IMM7B_SIZE_X,
IMM64_IMM7B_INST_WORD_POS_X,
IMM64_IMM7B_VAL_POS_X
);
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IMM9D_INST_WORD_X,
IMM64_IMM9D_SIZE_X,
IMM64_IMM9D_INST_WORD_POS_X,
IMM64_IMM9D_VAL_POS_X
);
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IMM5C_INST_WORD_X,
IMM64_IMM5C_SIZE_X,
IMM64_IMM5C_INST_WORD_POS_X,
IMM64_IMM5C_VAL_POS_X
);
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IC_INST_WORD_X,
IMM64_IC_SIZE_X,
IMM64_IC_INST_WORD_POS_X,
IMM64_IC_VAL_POS_X
);
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IMM41a_INST_WORD_X,
IMM64_IMM41a_SIZE_X,
IMM64_IMM41a_INST_WORD_POS_X,
IMM64_IMM41a_VAL_POS_X
);
//
// Update 64-bit address
//
FixupVal += Adjust;
//
// Insert IMM64 into bundle
//
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM7B_INST_WORD_X),
IMM64_IMM7B_SIZE_X,
IMM64_IMM7B_INST_WORD_POS_X,
IMM64_IMM7B_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM9D_INST_WORD_X),
IMM64_IMM9D_SIZE_X,
IMM64_IMM9D_INST_WORD_POS_X,
IMM64_IMM9D_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM5C_INST_WORD_X),
IMM64_IMM5C_SIZE_X,
IMM64_IMM5C_INST_WORD_POS_X,
IMM64_IMM5C_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IC_INST_WORD_X),
IMM64_IC_SIZE_X,
IMM64_IC_INST_WORD_POS_X,
IMM64_IC_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM41a_INST_WORD_X),
IMM64_IMM41a_SIZE_X,
IMM64_IMM41a_INST_WORD_POS_X,
IMM64_IMM41a_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM41b_INST_WORD_X),
IMM64_IMM41b_SIZE_X,
IMM64_IMM41b_INST_WORD_POS_X,
IMM64_IMM41b_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM41c_INST_WORD_X),
IMM64_IMM41c_SIZE_X,
IMM64_IMM41c_INST_WORD_POS_X,
IMM64_IMM41c_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_SIGN_INST_WORD_X),
IMM64_SIGN_SIZE_X,
IMM64_SIGN_INST_WORD_POS_X,
IMM64_SIGN_VAL_POS_X
);
F64 = (UINT64 *) Fixup;
if (*FixupData != NULL) {
*FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));
*(UINT64 *)(*FixupData) = *F64;
*FixupData = *FixupData + sizeof(UINT64);
}
break;
default:
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,67 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeCoffLoaderEx.h
Abstract:
Fixes Intel Itanium(TM) specific relocation types
Revision History
--*/
#ifndef _PE_COFF_LOADER_EX_H_
#define _PE_COFF_LOADER_EX_H_
//
// Define macro to determine if the machine type is supported.
// Returns 0 if the machine is not supported, Not 0 otherwise.
//
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \
((Machine) == EFI_IMAGE_MACHINE_IA64 || \
(Machine) == EFI_IMAGE_MACHINE_EBC)
EFI_STATUS
PeCoffLoaderRelocateImageEx (
IN UINT16 *Reloc,
IN OUT CHAR8 *Fixup,
IN OUT CHAR8 **FixupData,
IN UINT64 Adjust
)
/*++
Routine Description:
Performs an Itanium-based specific relocation fixup
Arguments:
Reloc - Pointer to the relocation record
Fixup - Pointer to the address to fix up
FixupData - Pointer to a buffer to log the fixups
Adjust - The offset to adjust the fixup
Returns:
Status code
--*/
;
#endif

View File

@@ -0,0 +1,61 @@
//++
// Copyright (c) 2004, Intel Corporation
// All rights reserved. This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
// Module Name:
//
// PerformancePrimitives.s
//
// Abstract:
//
//
// Revision History:
//
//--
.file "PerformancePrimitives.s"
#include "IpfMacro.i"
//-----------------------------------------------------------------------------
//++
// GetTimerValue
//
// Implementation of CPU-based time service
//
// On Entry :
// EFI_STATUS
// GetTimerValue (
// OUT UINT64 *TimerValue
// )
//
// Return Value:
// r8 = Status
// r9 = 0
// r10 = 0
// r11 = 0
//
// As per static calling conventions.
//
//--
//---------------------------------------------------------------------------
PROCEDURE_ENTRY (GetTimerValue)
NESTED_SETUP (1,8,0,0)
mov r8 = ar.itc;;
st8 [r32]= r8
mov r8 = r0
mov r9 = r0
mov r10 = r0
mov r11 = r0
NESTED_RETURN
PROCEDURE_EXIT (GetTimerValue)
//---------------------------------------------------------------------------

View File

@@ -0,0 +1,122 @@
//++
// Copyright (c) 2004, Intel Corporation
// All rights reserved. This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
// Module Name:
//
// SwitchStack.s
//
// Abstract:
//
// Contains an implementation of a stack switch for the Itanium-based architecture.
//
//
//
// Revision History:
//
//--
.file "SwitchStack.s"
#include <asm.h>
#include <ia_64gen.h>
// Define hardware RSE Configuration Register
//
// RS Configuration (RSC) bit field positions
#define RSC_MODE 0
#define RSC_PL 2
#define RSC_BE 4
// RSC bits 5-15 reserved
#define RSC_MBZ0 5
#define RSC_MBZ0_V 0x3ff
#define RSC_LOADRS 16
#define RSC_LOADRS_LEN 14
// RSC bits 30-63 reserved
#define RSC_MBZ1 30
#define RSC_MBZ1_V 0x3ffffffffULL
// RSC modes
// Lazy
#define RSC_MODE_LY (0x0)
// Store intensive
#define RSC_MODE_SI (0x1)
// Load intensive
#define RSC_MODE_LI (0x2)
// Eager
#define RSC_MODE_EA (0x3)
// RSC Endian bit values
#define RSC_BE_LITTLE 0
#define RSC_BE_BIG 1
// RSC while in kernel: enabled, little endian, pl = 0, eager mode
#define RSC_KERNEL ((RSC_MODE_EA<<RSC_MODE) | (RSC_BE_LITTLE<<RSC_BE))
// Lazy RSC in kernel: enabled, little endian, pl = 0, lazy mode
#define RSC_KERNEL_LAZ ((RSC_MODE_LY<<RSC_MODE) | (RSC_BE_LITTLE<<RSC_BE))
// RSE disabled: disabled, pl = 0, little endian, eager mode
#define RSC_KERNEL_DISABLED ((RSC_MODE_LY<<RSC_MODE) | (RSC_BE_LITTLE<<RSC_BE))
//VOID
//SwitchStacks (
// VOID *ContinuationFunction,
// UINTN Parameter,
// UINTN NewTopOfStack,
// UINTN NewBSPStore OPTIONAL
//)
///*++
//
//Input Arguments
//
// ContinuationFunction - This is a pointer to the PLABEL of the function that should be called once the
// new stack has been created.
// Parameter - The parameter to pass to the continuation function
// NewTopOfStack - This is the new top of the memory stack for ensuing code. This is mandatory and
// should be non-zero
// NewBSPStore - This is the new BSP store for the ensuing code. It is optional on IA-32 and mandatory on Itanium-based platform.
//
//--*/
PROCEDURE_ENTRY(SwitchStacks)
mov r16 = -0x10;;
and r16 = r34, r16;; // get new stack value in R16, 0 the last nibble.
mov r15 = r35;; // Get new BspStore into R15
mov r13 = r32;; // this is a pointer to the PLABEL of the continuation function.
mov r17 = r33;; // this is the parameter to pass to the continuation function
alloc r11=0,0,0,0 // Set 0-size frame
;;
flushrs;;
mov r21 = RSC_KERNEL_DISABLED // for rse disable
;;
mov ar.rsc = r21 // turn off RSE
add sp = r0, r16;; // transfer to the EFI stack
mov ar.bspstore = r15 // switch to EFI BSP
invala // change of ar.bspstore needs invala.
mov r18 = RSC_KERNEL_LAZ // RSC enabled, Lazy mode
;;
mov ar.rsc = r18 // turn rse on, in kernel mode
;;
alloc r11=0,0,1,0;; // alloc 0 outs going to ensuing DXE IPL service
mov out0 = r17
ld8 r16 = [r13],8;; // r16 = address of continuation function from the PLABEL
ld8 gp = [r13] // gp = gp of continuation function from the PLABEL
mov b6 = r16
;;
br.call.sptk.few b0=b6;; // Call the continuation function
;;
PROCEDURE_EXIT(SwitchStacks)

View File

@@ -0,0 +1,35 @@
//
//
// Copyright (c) 2004, Intel Corporation
// All rights reserved. This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
// Module Name:
//
// asm.h
//
// Abstract:
//
// This module contains generic macros for an assembly writer.
//
//
// Revision History
//
#ifndef _ASM_H
#define _ASM_H
#define TRUE 1
#define FALSE 0
#define PROCEDURE_ENTRY(name) .##text; \
.##type name, @function; \
.##proc name; \
name::
#define PROCEDURE_EXIT(name) .##endp name
#endif // _ASM_H

View File

@@ -0,0 +1,112 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiJump.h
Abstract:
This is the Setjump/Longjump pair for an IA32 processor.
--*/
#ifndef _EFI_JUMP_H_
#define _EFI_JUMP_H_
#include EFI_GUID_DEFINITION (PeiTransferControl)
//
// NOTE:Set/LongJump needs to have this buffer start
// at 16 byte boundary. Either fix the structure
// which call this buffer or fix inside SetJump/LongJump
// Choosing 1K buffer storage for now
//
typedef struct {
CHAR8 Buffer[1024];
} EFI_JUMP_BUFFER;
EFI_STATUS
SetJump (
IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This,
IN EFI_JUMP_BUFFER *Jump
)
/*++
Routine Description:
SetJump stores the current register set in the area pointed to
by "save". It returns zero. Subsequent calls to "LongJump" will
restore the registers and return non-zero to the same location.
On entry, r32 contains the pointer to the jmp_buffer
Arguments:
This - Calling context
Jump - Jump buffer
Returns:
Status code
--*/
;
EFI_STATUS
LongJump (
IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This,
IN EFI_JUMP_BUFFER *Jump
)
/*++
Routine Description:
LongJump initializes the register set to the values saved by a
previous 'SetJump' and jumps to the return location saved by that
'SetJump'. This has the effect of unwinding the stack and returning
for a second time to the 'SetJump'.
Arguments:
This - Calling context
Jump - Jump buffer
Returns:
Status code
--*/
;
VOID
RtPioICacheFlush (
IN VOID *StartAddress,
IN UINTN SizeInBytes
)
/*++
Routine Description:
Flushing the CPU instruction cache.
Arguments:
StartAddress - Start address to flush
SizeInBytes - Length in bytes to flush
Returns:
None
--*/
;
#endif

View File

@@ -0,0 +1,214 @@
//
//
//
// Copyright (c) 2004, Intel Corporation
// All rights reserved. This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
//Module Name: ia_64gen.h
//
//
//Abstract:
//
//
//
//
//Revision History
//
//
#ifndef _IA64GEN_H
#define _IA64GEN_H
#define TT_UNAT 0
#define C_PSR 0
#define J_UNAT 0
#define T_TYPE 0
#define T_IPSR 0x8
#define T_ISR 0x10
#define T_IIP 0x18
#define T_IFA 0x20
#define T_IIPA 0x28
#define T_IFS 0x30
#define T_IIM 0x38
#define T_RSC 0x40
#define T_BSP 0x48
#define T_BSPSTORE 0x50
#define T_RNAT 0x58
#define T_PFS 0x60
#define T_KBSPSTORE 0x68
#define T_UNAT 0x70
#define T_CCV 0x78
#define T_DCR 0x80
#define T_PREDS 0x88
#define T_NATS 0x90
#define T_R1 0x98
#define T_GP 0x98
#define T_R2 0xa0
#define T_R3 0xa8
#define T_R4 0xb0
#define T_R5 0xb8
#define T_R6 0xc0
#define T_R7 0xc8
#define T_R8 0xd0
#define T_R9 0xd8
#define T_R10 0xe0
#define T_R11 0xe8
#define T_R12 0xf0
#define T_SP 0xf0
#define T_R13 0xf8
#define T_R14 0x100
#define T_R15 0x108
#define T_R16 0x110
#define T_R17 0x118
#define T_R18 0x120
#define T_R19 0x128
#define T_R20 0x130
#define T_R21 0x138
#define T_R22 0x140
#define T_R23 0x148
#define T_R24 0x150
#define T_R25 0x158
#define T_R26 0x160
#define T_R27 0x168
#define T_R28 0x170
#define T_R29 0x178
#define T_R30 0x180
#define T_R31 0x188
#define T_F2 0x1f0
#define T_F3 0x200
#define T_F4 0x210
#define T_F5 0x220
#define T_F6 0x230
#define T_F7 0x240
#define T_F8 0x250
#define T_F9 0x260
#define T_F10 0x270
#define T_F11 0x280
#define T_F12 0x290
#define T_F13 0x2a0
#define T_F14 0x2b0
#define T_F15 0x2c0
#define T_F16 0x2d0
#define T_F17 0x2e0
#define T_F18 0x2f0
#define T_F19 0x300
#define T_F20 0x310
#define T_F21 0x320
#define T_F22 0x330
#define T_F23 0x340
#define T_F24 0x350
#define T_F25 0x360
#define T_F26 0x370
#define T_F27 0x380
#define T_F28 0x390
#define T_F29 0x3a0
#define T_F30 0x3b0
#define T_F31 0x3c0
#define T_FPSR 0x1e0
#define T_B0 0x190
#define T_B1 0x198
#define T_B2 0x1a0
#define T_B3 0x1a8
#define T_B4 0x1b0
#define T_B5 0x1b8
#define T_B6 0x1c0
#define T_B7 0x1c8
#define T_EC 0x1d0
#define T_LC 0x1d8
#define J_NATS 0x8
#define J_PFS 0x10
#define J_BSP 0x18
#define J_RNAT 0x20
#define J_PREDS 0x28
#define J_LC 0x30
#define J_R4 0x38
#define J_R5 0x40
#define J_R6 0x48
#define J_R7 0x50
#define J_SP 0x58
#define J_F2 0x60
#define J_F3 0x70
#define J_F4 0x80
#define J_F5 0x90
#define J_F16 0xa0
#define J_F17 0xb0
#define J_F18 0xc0
#define J_F19 0xd0
#define J_F20 0xe0
#define J_F21 0xf0
#define J_F22 0x100
#define J_F23 0x110
#define J_F24 0x120
#define J_F25 0x130
#define J_F26 0x140
#define J_F27 0x150
#define J_F28 0x160
#define J_F29 0x170
#define J_F30 0x180
#define J_F31 0x190
#define J_FPSR 0x1a0
#define J_B0 0x1a8
#define J_B1 0x1b0
#define J_B2 0x1b8
#define J_B3 0x1c0
#define J_B4 0x1c8
#define J_B5 0x1d0
#define TRAP_FRAME_LENGTH 0x3d0
#define C_UNAT 0x28
#define C_NATS 0x30
#define C_PFS 0x8
#define C_BSPSTORE 0x10
#define C_RNAT 0x18
#define C_RSC 0x20
#define C_PREDS 0x38
#define C_LC 0x40
#define C_DCR 0x48
#define C_R1 0x50
#define C_GP 0x50
#define C_R4 0x58
#define C_R5 0x60
#define C_R6 0x68
#define C_R7 0x70
#define C_SP 0x78
#define C_R13 0x80
#define C_F2 0x90
#define C_F3 0xa0
#define C_F4 0xb0
#define C_F5 0xc0
#define C_F16 0xd0
#define C_F17 0xe0
#define C_F18 0xf0
#define C_F19 0x100
#define C_F20 0x110
#define C_F21 0x120
#define C_F22 0x130
#define C_F23 0x140
#define C_F24 0x150
#define C_F25 0x160
#define C_F26 0x170
#define C_F27 0x180
#define C_F28 0x190
#define C_F29 0x1a0
#define C_F30 0x1b0
#define C_F31 0x1c0
#define C_FPSR 0x1d0
#define C_B0 0x1d8
#define C_B1 0x1e0
#define C_B2 0x1e8
#define C_B3 0x1f0
#define C_B4 0x1f8
#define C_B5 0x200
#define TT_R2 0x8
#define TT_R3 0x10
#define TT_R8 0x18
#define TT_R9 0x20
#define TT_R10 0x28
#define TT_R11 0x30
#define TT_R14 0x38
#endif _IA64GEN_H

View File

@@ -0,0 +1,139 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
math.c
Abstract:
64-bit Math worker functions for Intel Itanium(TM) processors.
--*/
#include "Tiano.h"
#include "Pei.h"
#include "PeiLib.h"
UINT64
LShiftU64 (
IN UINT64 Operand,
IN UINTN Count
)
/*++
Routine Description:
This routine allows a 64 bit value to be left shifted by 32 bits and
returns the shifted value.
Count is valid up 63. (Only Bits 0-5 is valid for Count)
Arguments:
Operand - Value to be shifted
Count - Number of times to shift left.
Returns:
Value shifted left identified by the Count.
--*/
{
return Operand << Count;
}
UINT64
RShiftU64 (
IN UINT64 Operand,
IN UINTN Count
)
/*++
Routine Description:
This routine allows a 64 bit value to be right shifted by 32 bits and returns the
shifted value.
Count is valid up 63. (Only Bits 0-5 is valid for Count)
Arguments:
Operand - Value to be shifted
Count - Number of times to shift right.
Returns:
Value shifted right identified by the Count.
--*/
{
return Operand >> Count;
}
UINT64
MultU64x32 (
IN UINT64 Multiplicand,
IN UINTN Multiplier
)
/*++
Routine Description:
This routine allows a 64 bit value to be multiplied with a 32 bit
value returns 64bit result.
No checking if the result is greater than 64bits
Arguments:
Multiplicand - multiplicand
Multiplier - multiplier
Returns:
Multiplicand * Multiplier
--*/
{
return Multiplicand * Multiplier;
}
UINT64
DivU64x32 (
IN UINT64 Dividend,
IN UINTN Divisor,
OUT UINTN *Remainder OPTIONAL
)
/*++
Routine Description:
This routine allows a 64 bit value to be divided with a 32 bit value returns
64bit result and the Remainder.
N.B. only works for 31bit divisors!!
Arguments:
Dividend - dividend
Divisor - divisor
Remainder - buffer for remainder
Returns:
Dividend / Divisor
Remainder = Dividend mod Divisor
--*/
{
if (Remainder) {
*Remainder = Dividend % Divisor;
}
return Dividend / Divisor;
}

View File

@@ -0,0 +1,106 @@
//++
// Copyright (c) 2004, Intel Corporation
// All rights reserved. This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
// Module Name:
//
// pioflush.s
//
// Abstract:
//
//
// Revision History:
//
//--
.file "pioflush.c"
.radix D
.section .text, "ax", "progbits"
.align 32
.section .pdata, "a", "progbits"
.align 4
.section .xdata, "a", "progbits"
.align 8
.section .data, "wa", "progbits"
.align 16
.section .rdata, "a", "progbits"
.align 16
.section .bss, "wa", "nobits"
.align 16
.section .tls$, "was", "progbits"
.align 16
.section .sdata, "was", "progbits"
.align 16
.section .sbss, "was", "nobits"
.align 16
.section .srdata, "as", "progbits"
.align 16
.section .rdata, "a", "progbits"
.align 16
.section .rtcode, "ax", "progbits"
.align 32
.type RtPioICacheFlush# ,@function
.global RtPioICacheFlush#
// Function compile flags: /Ogsy
.section .rtcode
// Begin code for function: RtPioICacheFlush:
.proc RtPioICacheFlush#
.align 32
RtPioICacheFlush:
// File e:\tmp\pioflush.c
{ .mii //R-Addr: 0X00
alloc r3=2, 0, 0, 0 //11, 00000002H
cmp4.leu p0,p6=32, r33;; //15, 00000020H
(p6) mov r33=32;; //16, 00000020H
}
{ .mii //R-Addr: 0X010
nop.m 0
zxt4 r29=r33;; //21
dep.z r30=r29, 0, 5;; //21, 00000005H
}
{ .mii //R-Addr: 0X020
cmp4.eq p0,p7=r0, r30 //21
shr.u r28=r29, 5;; //19, 00000005H
(p7) adds r28=1, r28;; //22, 00000001H
}
{ .mii //R-Addr: 0X030
nop.m 0
shl r27=r28, 5;; //25, 00000005H
zxt4 r26=r27;; //25
}
{ .mfb //R-Addr: 0X040
add r31=r26, r32 //25
nop.f 0
nop.b 0
}
$L143:
{ .mii //R-Addr: 0X050
fc r32 //27
adds r32=32, r32;; //28, 00000020H
cmp.ltu p14,p15=r32, r31 //29
}
{ .mfb //R-Addr: 0X060
nop.m 0
nop.f 0
(p14) br.cond.dptk.few $L143#;; //29, 880000/120000
}
{ .mmi
sync.i;;
srlz.i
nop.i 0;;
}
{ .mfb //R-Addr: 0X070
nop.m 0
nop.f 0
br.ret.sptk.few b0;; //31
}
// End code for function:
.endp RtPioICacheFlush#
// END

View File

@@ -0,0 +1,118 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Processor.c
Abstract:
--*/
#include "Tiano.h"
#include "EfiJump.h"
#include "PeiHob.h"
#include EFI_GUID_DEFINITION (PeiFlushInstructionCache)
#include EFI_GUID_DEFINITION (PeiTransferControl)
EFI_STATUS
WinNtFlushInstructionCacheFlush (
IN EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS Start,
IN UINT64 Length
);
EFI_PEI_TRANSFER_CONTROL_PROTOCOL mTransferControl = {
SetJump,
LongJump,
sizeof (EFI_JUMP_BUFFER)
};
EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL mFlushInstructionCache = {
WinNtFlushInstructionCacheFlush
};
EFI_STATUS
InstallEfiPeiTransferControl (
IN OUT EFI_PEI_TRANSFER_CONTROL_PROTOCOL **This
)
/*++
Routine Description:
Installs the pointer to the transfer control mechanism
Arguments:
This - Pointer to transfer control mechanism.
Returns:
EFI_SUCCESS - Successfully installed.
--*/
{
*This = &mTransferControl;
return EFI_SUCCESS;
}
EFI_STATUS
InstallEfiPeiFlushInstructionCache (
IN OUT EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL **This
)
/*++
Routine Description:
Installs the pointer to the flush instruction cache mechanism
Arguments:
This - Pointer to flush instruction cache mechanism.
Returns:
EFI_SUCCESS - Successfully installed
--*/
{
*This = &mFlushInstructionCache;
return EFI_SUCCESS;
}
EFI_STATUS
WinNtFlushInstructionCacheFlush (
IN EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS Start,
IN UINT64 Length
)
/*++
Routine Description:
This routine would provide support for flushing the CPU instruction cache.
Arguments:
This - Pointer to CPU Architectural Protocol interface
Start - Start adddress in memory to flush
Length - Length of memory to flush
Returns:
Status
EFI_SUCCESS
--*/
{
RtPioICacheFlush ((UINT8 *) Start, (UINTN) Length);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,325 @@
//++
// Copyright (c) 2004, Intel Corporation
// All rights reserved. This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
// Module Name:
//
// setjmp.s
//
// Abstract:
//
// Contains an implementation of setjmp and longjmp for the
// Itanium-based architecture.
//
//
//
// Revision History:
//
//--
.file "setjmp.s"
#include <asm.h>
#include <ia_64gen.h>
// int SetJump(struct jmp_buffer save)
//
// Setup a non-local goto.
//
// Description:
//
// SetJump stores the current register set in the area pointed to
// by "save". It returns zero. Subsequent calls to "LongJump" will
// restore the registers and return non-zero to the same location.
//
// On entry, r32 contains the pointer to the jmp_buffer
//
PROCEDURE_ENTRY(SetJump)
//
// Make sure buffer is aligned at 16byte boundary
//
mov r32 = r33
add r10 = -0x10,r0 ;; // mask the lower 4 bits
and r32 = r32, r10;;
add r32 = 0x10, r32;; // move to next 16 byte boundary
add r10 = J_PREDS, r32 // skip Unats & pfs save area
add r11 = J_BSP, r32
//
// save immediate context
//
mov r2 = ar.bsp // save backing store pointer
mov r3 = pr // save predicates
;;
//
// save user Unat register
//
mov r16 = ar.lc // save loop count register
mov r14 = ar.unat // save user Unat register
st8 [r10] = r3, J_LC-J_PREDS
st8 [r11] = r2, J_R4-J_BSP
;;
st8 [r10] = r16, J_R5-J_LC
st8 [r32] = r14, J_NATS // Note: Unat at the
// beginning of the save area
mov r15 = ar.pfs
;;
//
// save preserved general registers & NaT's
//
st8.spill [r11] = r4, J_R6-J_R4
;;
st8.spill [r10] = r5, J_R7-J_R5
;;
st8.spill [r11] = r6, J_SP-J_R6
;;
st8.spill [r10] = r7, J_F3-J_R7
;;
st8.spill [r11] = sp, J_F2-J_SP
;;
//
// save spilled Unat and pfs registers
//
mov r2 = ar.unat // save Unat register after spill
;;
st8 [r32] = r2, J_PFS-J_NATS // save unat for spilled regs
;;
st8 [r32] = r15 // save pfs
//
// save floating registers
//
stf.spill [r11] = f2, J_F4-J_F2
stf.spill [r10] = f3, J_F5-J_F3
;;
stf.spill [r11] = f4, J_F16-J_F4
stf.spill [r10] = f5, J_F17-J_F5
;;
stf.spill [r11] = f16, J_F18-J_F16
stf.spill [r10] = f17, J_F19-J_F17
;;
stf.spill [r11] = f18, J_F20-J_F18
stf.spill [r10] = f19, J_F21-J_F19
;;
stf.spill [r11] = f20, J_F22-J_F20
stf.spill [r10] = f21, J_F23-J_F21
;;
stf.spill [r11] = f22, J_F24-J_F22
stf.spill [r10] = f23, J_F25-J_F23
;;
stf.spill [r11] = f24, J_F26-J_F24
stf.spill [r10] = f25, J_F27-J_F25
;;
stf.spill [r11] = f26, J_F28-J_F26
stf.spill [r10] = f27, J_F29-J_F27
;;
stf.spill [r11] = f28, J_F30-J_F28
stf.spill [r10] = f29, J_F31-J_F29
;;
stf.spill [r11] = f30, J_FPSR-J_F30
stf.spill [r10] = f31, J_B0-J_F31 // size of f31 + fpsr
//
// save FPSR register & branch registers
//
mov r2 = ar.fpsr // save fpsr register
mov r3 = b0
;;
st8 [r11] = r2, J_B1-J_FPSR
st8 [r10] = r3, J_B2-J_B0
mov r2 = b1
mov r3 = b2
;;
st8 [r11] = r2, J_B3-J_B1
st8 [r10] = r3, J_B4-J_B2
mov r2 = b3
mov r3 = b4
;;
st8 [r11] = r2, J_B5-J_B3
st8 [r10] = r3
mov r2 = b5
;;
st8 [r11] = r2
;;
//
// return
//
mov r8 = r0 // return 0 from setjmp
mov ar.unat = r14 // restore unat
br.ret.sptk b0
PROCEDURE_EXIT(SetJump)
//
// void LongJump(struct jmp_buffer *)
//
// Perform a non-local goto.
//
// Description:
//
// LongJump initializes the register set to the values saved by a
// previous 'SetJump' and jumps to the return location saved by that
// 'SetJump'. This has the effect of unwinding the stack and returning
// for a second time to the 'SetJump'.
//
PROCEDURE_ENTRY(LongJump)
//
// Make sure buffer is aligned at 16byte boundary
//
mov r32 = r33
add r10 = -0x10,r0 ;; // mask the lower 4 bits
and r32 = r32, r10;;
add r32 = 0x10, r32;; // move to next 16 byte boundary
//
// caching the return value as we do invala in the end
//
/// mov r8 = r33 // return value
mov r8 = 1 // For now return hard coded 1
//
// get immediate context
//
mov r14 = ar.rsc // get user RSC conf
add r10 = J_PFS, r32 // get address of pfs
add r11 = J_NATS, r32
;;
ld8 r15 = [r10], J_BSP-J_PFS // get pfs
ld8 r2 = [r11], J_LC-J_NATS // get unat for spilled regs
;;
mov ar.unat = r2
;;
ld8 r16 = [r10], J_PREDS-J_BSP // get backing store pointer
mov ar.rsc = r0 // put RSE in enforced lazy
mov ar.pfs = r15
;;
//
// while returning from longjmp the BSPSTORE and BSP needs to be
// same and discard all the registers allocated after we did
// setjmp. Also, we need to generate the RNAT register since we
// did not flushed the RSE on setjmp.
//
mov r17 = ar.bspstore // get current BSPSTORE
;;
cmp.ltu p6,p7 = r17, r16 // is it less than BSP of
(p6) br.spnt.few .flush_rse
mov r19 = ar.rnat // get current RNAT
;;
loadrs // invalidate dirty regs
br.sptk.many .restore_rnat // restore RNAT
.flush_rse:
flushrs
;;
mov r19 = ar.rnat // get current RNAT
mov r17 = r16 // current BSPSTORE
;;
.restore_rnat:
//
// check if RNAT is saved between saved BSP and curr BSPSTORE
//
dep r18 = 1,r16,3,6 // get RNAT address
;;
cmp.ltu p8,p9 = r18, r17 // RNAT saved on RSE
;;
(p8) ld8 r19 = [r18] // get RNAT from RSE
;;
mov ar.bspstore = r16 // set new BSPSTORE
;;
mov ar.rnat = r19 // restore RNAT
mov ar.rsc = r14 // restore RSC conf
ld8 r3 = [r11], J_R4-J_LC // get lc register
ld8 r2 = [r10], J_R5-J_PREDS // get predicates
;;
mov pr = r2, -1
mov ar.lc = r3
//
// restore preserved general registers & NaT's
//
ld8.fill r4 = [r11], J_R6-J_R4
;;
ld8.fill r5 = [r10], J_R7-J_R5
ld8.fill r6 = [r11], J_SP-J_R6
;;
ld8.fill r7 = [r10], J_F2-J_R7
ld8.fill sp = [r11], J_F3-J_SP
;;
//
// restore floating registers
//
ldf.fill f2 = [r10], J_F4-J_F2
ldf.fill f3 = [r11], J_F5-J_F3
;;
ldf.fill f4 = [r10], J_F16-J_F4
ldf.fill f5 = [r11], J_F17-J_F5
;;
ldf.fill f16 = [r10], J_F18-J_F16
ldf.fill f17 = [r11], J_F19-J_F17
;;
ldf.fill f18 = [r10], J_F20-J_F18
ldf.fill f19 = [r11], J_F21-J_F19
;;
ldf.fill f20 = [r10], J_F22-J_F20
ldf.fill f21 = [r11], J_F23-J_F21
;;
ldf.fill f22 = [r10], J_F24-J_F22
ldf.fill f23 = [r11], J_F25-J_F23
;;
ldf.fill f24 = [r10], J_F26-J_F24
ldf.fill f25 = [r11], J_F27-J_F25
;;
ldf.fill f26 = [r10], J_F28-J_F26
ldf.fill f27 = [r11], J_F29-J_F27
;;
ldf.fill f28 = [r10], J_F30-J_F28
ldf.fill f29 = [r11], J_F31-J_F29
;;
ldf.fill f30 = [r10], J_FPSR-J_F30
ldf.fill f31 = [r11], J_B0-J_F31 ;;
//
// restore branch registers and fpsr
//
ld8 r16 = [r10], J_B1-J_FPSR // get fpsr
ld8 r17 = [r11], J_B2-J_B0 // get return pointer
;;
mov ar.fpsr = r16
mov b0 = r17
ld8 r2 = [r10], J_B3-J_B1
ld8 r3 = [r11], J_B4-J_B2
;;
mov b1 = r2
mov b2 = r3
ld8 r2 = [r10], J_B5-J_B3
ld8 r3 = [r11]
;;
mov b3 = r2
mov b4 = r3
ld8 r2 = [r10]
ld8 r21 = [r32] // get user unat
;;
mov b5 = r2
mov ar.unat = r21
//
// invalidate ALAT
//
invala ;;
br.ret.sptk b0
PROCEDURE_EXIT(LongJump)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,169 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeiLib.c
Abstract:
PEI Library Functions
--*/
#include "TianoCommon.h"
#include "PeiHob.h"
#include "Pei.h"
VOID
PeiCopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
);
VOID
ZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
/*++
Routine Description:
Set Buffer to zero for Size bytes.
Arguments:
Buffer - Memory to set.
Size - Number of bytes to set
Returns:
None
--*/
{
INT8 *Ptr;
Ptr = Buffer;
while (Size--) {
*(Ptr++) = 0;
}
}
VOID
PeiCopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
/*++
Routine Description:
Copy Length bytes from Source to Destination.
Arguments:
Destination - Target of copy
Source - Place to copy from
Length - Number of bytes to copy
Returns:
None
--*/
{
CHAR8 *Destination8;
CHAR8 *Source8;
Destination8 = Destination;
Source8 = Source;
while (Length--) {
*(Destination8++) = *(Source8++);
}
}
VOID
CopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
/*++
Routine Description:
Copy Length bytes from Source to Destination.
Arguments:
Destination - Target of copy
Source - Place to copy from
Length - Number of bytes to copy
Returns:
None
--*/
{
CHAR8 *Destination8;
CHAR8 *Source8;
Destination8 = Destination;
Source8 = Source;
while (Length--) {
*(Destination8++) = *(Source8++);
}
}
BOOLEAN
CompareGuid (
IN EFI_GUID *Guid1,
IN EFI_GUID *Guid2
)
/*++
Routine Description:
Compares two GUIDs
Arguments:
Guid1 - guid to compare
Guid2 - guid to compare
Returns:
= TRUE if Guid1 == Guid2
= FALSE if Guid1 != Guid2
--*/
{
if ((((INT32 *) Guid1)[0] - ((INT32 *) Guid2)[0]) == 0) {
if ((((INT32 *) Guid1)[1] - ((INT32 *) Guid2)[1]) == 0) {
if ((((INT32 *) Guid1)[2] - ((INT32 *) Guid2)[2]) == 0) {
if ((((INT32 *) Guid1)[3] - ((INT32 *) Guid2)[3]) == 0) {
return TRUE;
}
}
}
}
return FALSE;
}

View File

@@ -0,0 +1,798 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeiLib.h
Abstract:
PEI Library Functions
--*/
#ifndef _PEI_LIB_H_
#define _PEI_LIB_H_
#include "Tiano.h"
#include "Pei.h"
#include "peiHobLib.h"
#include EFI_PROTOCOL_DEFINITION (Decompress)
#include EFI_PROTOCOL_DEFINITION (TianoDecompress)
#include EFI_GUID_DEFINITION (PeiPeCoffLoader)
VOID
PeiCopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
/*++
Routine Description:
Copy Length bytes from Source to Destination.
Arguments:
Destination - Target of copy
Source - Place to copy from
Length - Number of bytes to copy
Returns:
None
--*/
;
VOID
ZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
/*++
Routine Description:
Set Buffer to zero for Size bytes.
Arguments:
Buffer - Memory to set.
Size - Number of bytes to set
Returns:
None
--*/
;
VOID
CopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
/*++
Routine Description:
Copy Length bytes from Source to Destination.
Arguments:
Destination - Target of copy
Source - Place to copy from
Length - Number of bytes to copy
Returns:
None
--*/
;
BOOLEAN
CompareGuid (
IN EFI_GUID *Guid1,
IN EFI_GUID *Guid2
)
/*++
Routine Description:
Compares two GUIDs
Arguments:
Guid1 - guid to compare
Guid2 - guid to compare
Returns:
= TRUE if Guid1 == Guid2
= FALSE if Guid1 != Guid2
--*/
;
EFI_STATUS
InstallEfiPeiPeCoffLoader (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_PE_COFF_LOADER_PROTOCOL **This,
IN EFI_PEI_PPI_DESCRIPTOR *ThisPpi
)
/*++
Routine Description:
Install EFI Pei PE coff loader protocol.
Arguments:
PeiServices - The PEI core services table.
This - Pointer to get Pei PE coff loader protocol as output
ThisPpi - Passed in as EFI_NT_LOAD_AS_DLL_PPI on NT_EMULATOR platform
Returns:
EFI_SUCCESS
--*/
;
EFI_STATUS
InstallEfiDecompress (
EFI_DECOMPRESS_PROTOCOL **This
)
/*++
Routine Description:
Install EFI decompress protocol.
Arguments:
This - Pointer to get decompress protocol as output
Returns:
EFI_SUCCESS - EFI decompress protocol successfully installed.
--*/
;
EFI_STATUS
InstallTianoDecompress (
EFI_TIANO_DECOMPRESS_PROTOCOL **This
)
/*++
Routine Description:
Install Tiano decompress protocol.
Arguments:
This - Pointer to get decompress protocol as output
Returns:
EFI_SUCCESS - Tiano decompress protocol successfully installed.
--*/
;
VOID
PeiPerfMeasure (
EFI_PEI_SERVICES **PeiServices,
IN UINT16 *Token,
IN EFI_FFS_FILE_HEADER *FileHeader,
IN BOOLEAN EntryExit,
IN UINT64 Value
)
/*++
Routine Description:
Log a timestamp count.
Arguments:
PeiServices - Pointer to the PEI Core Services table
Token - Pointer to Token Name
FileHeader - Pointer to the file header
EntryExit - Indicates start or stop measurement
Value - The start time or the stop time
Returns:
--*/
;
EFI_STATUS
GetTimerValue (
OUT UINT64 *TimerValue
)
/*++
Routine Description:
Get timer value.
Arguments:
TimerValue - Pointer to the returned timer value
Returns:
EFI_SUCCESS - Successfully got timer value
--*/
;
#ifdef EFI_PEI_PERFORMANCE
#define PEI_PERF_START(Ps, Token, FileHeader, Value) PeiPerfMeasure (Ps, Token, FileHeader, FALSE, Value)
#define PEI_PERF_END(Ps, Token, FileHeader, Value) PeiPerfMeasure (Ps, Token, FileHeader, TRUE, Value)
#else
#define PEI_PERF_START(Ps, Token, FileHeader, Value)
#define PEI_PERF_END(Ps, Token, FileHeader, Value)
#endif
#ifdef EFI_NT_EMULATOR
EFI_STATUS
PeCoffLoaderWinNtLoadAsDll (
IN CHAR8 *PdbFileName,
IN VOID **ImageEntryPoint,
OUT VOID **ModHandle
)
/*++
Routine Description:
Loads the .DLL file is present when a PE/COFF file is loaded. This provides source level
debugging for drivers that have cooresponding .DLL files on the local system.
Arguments:
PdbFileName - The name of the .PDB file. This was found from the PE/COFF
file's debug directory entry.
ImageEntryPoint - A pointer to the DLL entry point of the .DLL file was loaded.
ModHandle - Pointer to loaded library.
Returns:
EFI_SUCCESS - The .DLL file was loaded, and the DLL entry point is returned in ImageEntryPoint
EFI_NOT_FOUND - The .DLL file could not be found
EFI_UNSUPPORTED - The .DLL file was loaded, but the entry point to the .DLL file could not
determined.
--*/
;
#endif
//
// hob.c
//
EFI_STATUS
PeiBuildHobModule (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_GUID *ModuleName,
IN EFI_PHYSICAL_ADDRESS Module,
IN UINT64 ModuleLength,
IN EFI_PHYSICAL_ADDRESS EntryPoint
)
/*++
Routine Description:
Builds a HOB for a loaded PE32 module
Arguments:
PeiServices - The PEI core services table.
ModuleName - The GUID File Name of the module
Memory - The 64 bit physical address of the module
ModuleLength - The length of the module in bytes
EntryPoint - The 64 bit physical address of the entry point
to the module
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
;
EFI_STATUS
PeiBuildHobResourceDescriptor (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_RESOURCE_TYPE ResourceType,
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
IN EFI_PHYSICAL_ADDRESS PhysicalStart,
IN UINT64 NumberOfBytes
)
/*++
Routine Description:
Builds a HOB that describes a chunck of system memory
Arguments:
PeiServices - The PEI core services table.
ResourceType - The type of resource described by this HOB
ResourceAttribute - The resource attributes of the memory described by this HOB
PhysicalStart - The 64 bit physical address of memory described by this HOB
NumberOfBytes - The length of the memoty described by this HOB in bytes
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
;
EFI_STATUS
PeiBuildHobGuid (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_GUID *Guid,
IN UINTN DataLength,
IN OUT VOID **Hob
)
/*++
Routine Description:
Builds a custom HOB that is tagged with a GUID for identification
Arguments:
PeiServices - The PEI core services table.
Guid - The GUID of the custome HOB type
DataLength - The size of the data payload for the GUIDed HOB
Hob - Pointer to the Hob
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
;
EFI_STATUS
PeiBuildHobGuidData (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_GUID *Guid,
IN VOID *Data,
IN UINTN DataLength
)
/*++
Routine Description:
Builds a custom HOB that is tagged with a GUID for identification
Arguments:
PeiServices - The PEI core services table.
Guid - The GUID of the custome HOB type
Data - The data to be copied into the GUIDed HOB data field.
DataLength - The data field length.
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
;
EFI_STATUS
PeiBuildHobFv (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
/*++
Routine Description:
Builds a Firmware Volume HOB
Arguments:
PeiServices - The PEI core services table.
BaseAddress - The base address of the Firmware Volume
Length - The size of the Firmware Volume in bytes
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
;
EFI_STATUS
PeiBuildHobCpu (
IN EFI_PEI_SERVICES **PeiServices,
IN UINT8 SizeOfMemorySpace,
IN UINT8 SizeOfIoSpace
)
/*++
Routine Description:
Builds a HOB for the CPU
Arguments:
PeiServices - The PEI core services table.
SizeOfMemorySpace - Identifies the maximum
physical memory addressibility of the processor.
SizeOfIoSpace - Identifies the maximum physical I/O addressibility
of the processor.
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
;
EFI_STATUS
PeiBuildHobStack (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length
)
/*++
Routine Description:
Builds a HOB for the Stack
Arguments:
PeiServices - The PEI core services table.
BaseAddress - The 64 bit physical address of the Stack
Length - The length of the stack in bytes
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
;
EFI_STATUS
PeiBuildHobBspStore (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN EFI_MEMORY_TYPE MemoryType
)
/*++
Routine Description:
Builds a HOB for the bsp store
Arguments:
PeiServices - The PEI core services table.
BaseAddress - The 64 bit physical address of the bsp store
Length - The length of the bsp store in bytes
MemoryType - Memory type
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
;
EFI_STATUS
PeiBuildHobMemoryAllocation (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN UINT64 Length,
IN EFI_GUID *Name,
IN EFI_MEMORY_TYPE MemoryType
)
/*++
Routine Description:
Builds a HOB for the memory allocation
Arguments:
PeiServices - The PEI core services table.
BaseAddress - The 64 bit physical address of the memory
Length - The length of the memory allocation in bytes
Name - Name for Hob
MemoryType - Memory type
Returns:
EFI_SUCCESS - Hob is successfully built.
Others - Errors occur while creating new Hob
--*/
;
//
// print.c
//
UINTN
AvSPrint (
OUT CHAR8 *StartOfBuffer,
IN UINTN StrSize,
IN CONST CHAR8 *Format,
IN VA_LIST Marker
)
/*++
Routine Description:
AvSPrint function to process format and place the results in Buffer. Since a
VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
this is the main print working routine
Arguments:
StartOfBuffer - Ascii buffer to print the results of the parsing of Format into.
StrSize - Maximum number of characters to put into buffer. Zero means
no limit.
FormatString - Ascii format string see file header for more details.
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
UINTN
ASPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
ASPrint function to process format and place the results in Buffer.
Arguments:
Buffer - Ascii buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means no
limit.
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
//
// math.c
//
UINT64
MultU64x32 (
IN UINT64 Multiplicand,
IN UINTN Multiplier
)
/*++
Routine Description:
This routine allows a 64 bit value to be multiplied with a 32 bit
value returns 64bit result.
No checking if the result is greater than 64bits
Arguments:
Multiplicand - multiplicand
Multiplier - multiplier
Returns:
Multiplicand * Multiplier
--*/
;
UINT64
DivU64x32 (
IN UINT64 Dividend,
IN UINTN Divisor,
OUT UINTN *Remainder OPTIONAL
)
/*++
Routine Description:
This routine allows a 64 bit value to be divided with a 32 bit value returns
64bit result and the Remainder.
N.B. only works for 31bit divisors!!
Arguments:
Dividend - dividend
Divisor - divisor
Remainder - buffer for remainder
Returns:
Dividend / Divisor
Remainder = Dividend mod Divisor
--*/
;
UINT64
RShiftU64 (
IN UINT64 Operand,
IN UINTN Count
)
/*++
Routine Description:
This routine allows a 64 bit value to be right shifted by 32 bits and returns the
shifted value.
Count is valid up 63. (Only Bits 0-5 is valid for Count)
Arguments:
Operand - Value to be shifted
Count - Number of times to shift right.
Returns:
Value shifted right identified by the Count.
--*/
;
UINT64
LShiftU64 (
IN UINT64 Operand,
IN UINTN Count
)
/*++
Routine Description:
This routine allows a 64 bit value to be left shifted by 32 bits and
returns the shifted value.
Count is valid up 63. (Only Bits 0-5 is valid for Count)
Arguments:
Operand - Value to be shifted
Count - Number of times to shift left.
Returns:
Value shifted left identified by the Count.
--*/
;
VOID
RegisterNativeCpuIo (
IN EFI_PEI_SERVICES **PeiServices,
IN VOID *CpuIo
)
/*++
Routine Description:
Register a native Cpu IO
Arguments:
PeiServices - Calling context
CpuIo - CpuIo instance to register
Returns:
None
--*/
;
VOID
GetNativeCpuIo (
IN EFI_PEI_SERVICES **PeiServices,
OUT VOID **CpuIo
)
/*++
Routine Description:
Get registered Cpu IO.
Arguments:
PeiServices - Calling context
CpuIo - CpuIo instance registered before
Returns:
None
--*/
;
#endif

View File

@@ -0,0 +1,233 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Perf.c
Abstract:
Support for performance primitives.
--*/
#include "Tiano.h"
#include "Pei.h"
#include "PeiLib.h"
#include "PeiHob.h"
#include EFI_GUID_DEFINITION (PeiPerformanceHob)
//
// Perfomance HOB data definitions
//
#define MAX_PEI_PERF_LOG_ENTRIES 28
//
// Prototype functions
//
EFI_STATUS
GetTimerValue (
OUT UINT64 *TimerValue
);
VOID
PeiPerfMeasure (
EFI_PEI_SERVICES **PeiServices,
IN UINT16 *Token,
IN EFI_FFS_FILE_HEADER *FileHeader,
IN BOOLEAN EntryExit,
IN UINT64 Value
)
/*++
Routine Description:
Log a timestamp count.
Arguments:
PeiServices - Pointer to the PEI Core Services table
Token - Pointer to Token Name
FileHeader - Pointer to the file header
EntryExit - Indicates start or stop measurement
Value - The start time or the stop time
Returns:
--*/
{
EFI_STATUS Status;
EFI_HOB_GUID_TYPE *Hob;
EFI_HOB_GUID_DATA_PERFORMANCE_LOG *PerfHobData;
PEI_PERFORMANCE_MEASURE_LOG_ENTRY *Log;
EFI_PEI_PPI_DESCRIPTOR *PerfHobDescriptor;
UINT64 TimeCount;
INTN Index;
UINTN Index2;
EFI_GUID *Guid;
EFI_GUID *CheckGuid;
TimeCount = 0;
//
// Get the END time as early as possible to make it more accurate.
//
if (EntryExit) {
GetTimerValue (&TimeCount);
}
//
// Locate the Pei Performance Log Hob.
//
Status = (*PeiServices)->LocatePpi (
PeiServices,
&gEfiPeiPerformanceHobGuid,
0,
&PerfHobDescriptor,
NULL
);
//
// If the Performance Hob was not found, build and install one.
//
if (EFI_ERROR(Status)) {
Status = PeiBuildHobGuid (
PeiServices,
&gEfiPeiPerformanceHobGuid,
(sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG) +
((MAX_PEI_PERF_LOG_ENTRIES-1) *
sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY)) +
sizeof(EFI_PEI_PPI_DESCRIPTOR)
),
&Hob
);
ASSERT_PEI_ERROR(PeiServices, Status);
PerfHobData = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)(Hob+1);
PerfHobData->NumberOfEntries = 0;
PerfHobDescriptor = (EFI_PEI_PPI_DESCRIPTOR *)((UINT8 *)(PerfHobData+1) +
(sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY) *
(MAX_PEI_PERF_LOG_ENTRIES-1)
)
);
PerfHobDescriptor->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
PerfHobDescriptor->Guid = &gEfiPeiPerformanceHobGuid;
PerfHobDescriptor->Ppi = NULL;
(*PeiServices)->InstallPpi (
PeiServices,
PerfHobDescriptor
);
}
PerfHobData = (EFI_HOB_GUID_DATA_PERFORMANCE_LOG *)(((UINT8 *)(PerfHobDescriptor)) -
((sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY) *
(MAX_PEI_PERF_LOG_ENTRIES-1)
)
+ sizeof(EFI_HOB_GUID_DATA_PERFORMANCE_LOG)
)
);
if (PerfHobData->NumberOfEntries >= MAX_PEI_PERF_LOG_ENTRIES) {
return;
}
if (!EntryExit) {
Log = &(PerfHobData->Log[PerfHobData->NumberOfEntries]);
(*PeiServices)->SetMem (Log, sizeof(PEI_PERFORMANCE_MEASURE_LOG_ENTRY), 0);
//
// If not NULL pointer, copy the file name
//
if (FileHeader != NULL) {
Log->Name = FileHeader->Name;
}
//
// Copy the description string
//
(*PeiServices)->CopyMem (
&(Log->DescriptionString),
Token,
(PEI_PERF_MAX_DESC_STRING-1) * sizeof(UINT16)
);
//
// Get the start time as late as possible to make it more accurate.
//
GetTimerValue (&TimeCount);
//
// Record the time stamp.
//
if (Value != 0) {
Log->StartTimeCount = Value;
} else {
Log->StartTimeCount = TimeCount;
}
Log->StopTimeCount = 0;
//
// Increment the number of valid log entries.
//
PerfHobData->NumberOfEntries++;
} else {
for (Index = PerfHobData->NumberOfEntries-1; Index >= 0; Index--) {
Log = NULL;
for (Index2 = 0; Index2 < PEI_PERF_MAX_DESC_STRING; Index2++) {
if (PerfHobData->Log[Index].DescriptionString[Index2] == 0) {
Log = &(PerfHobData->Log[Index]);
break;
}
if (PerfHobData->Log[Index].DescriptionString[Index2] !=
Token[Index2]) {
break;
}
}
if (Log != NULL) {
if (FileHeader != NULL) {
Guid = &(Log->Name);
CheckGuid = &(FileHeader->Name);
if ((((INT32 *)Guid)[0] == ((INT32 *)CheckGuid)[0]) &&
(((INT32 *)Guid)[1] == ((INT32 *)CheckGuid)[1]) &&
(((INT32 *)Guid)[2] == ((INT32 *)CheckGuid)[2]) &&
(((INT32 *)Guid)[3] == ((INT32 *)CheckGuid)[3])) {
if (Value != 0) {
Log->StopTimeCount = Value;
} else {
Log->StopTimeCount = TimeCount;
}
break;
}
} else {
if (Value != 0) {
Log->StopTimeCount = Value;
} else {
Log->StopTimeCount = TimeCount;
}
break;
}
}
}
}
return;
}

View File

@@ -0,0 +1,736 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Print.c
Abstract:
Basic Ascii AvSPrintf() function named AvSPrint(). AvSPrint() enables very
simple implemenation of debug prints.
You can not Print more than PEI_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
AvSPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S', 's' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "Tiano.h"
#include "Pei.h"
#include "PeiLib.h"
#include "Print.h"
STATIC
CHAR8 *
GetFlagsAndWidth (
IN CHAR8 *Format,
OUT UINTN *Flags,
OUT UINTN *Width,
IN OUT VA_LIST *Marker
);
STATIC
UINTN
ValueToString (
IN OUT CHAR8 *Buffer,
IN INT64 Value,
IN UINTN Flags,
IN UINTN Width
);
STATIC
UINTN
ValueTomHexStr (
IN OUT CHAR8 *Buffer,
IN UINT64 Value,
IN UINTN Flags,
IN UINTN Width
);
STATIC
UINTN
GuidToString (
IN EFI_GUID *Guid,
IN OUT CHAR8 *Buffer,
IN UINTN BufferSize
);
STATIC
UINTN
TimeToString (
IN EFI_TIME *Time,
IN OUT CHAR8 *Buffer,
IN UINTN BufferSize
);
STATIC
UINTN
EfiStatusToString (
IN EFI_STATUS Status,
OUT CHAR8 *Buffer,
IN UINTN BufferSize
);
UINTN
ASPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
ASPrint function to process format and place the results in Buffer.
Arguments:
Buffer - Ascii buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means no
limit.
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START(Marker, Format);
Return = AvSPrint(Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
AvSPrint (
OUT CHAR8 *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR8 *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
AvSPrint function to process format and place the results in Buffer. Since a
VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
this is the main print working routine
Arguments:
StartOfBuffer - Ascii buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means
no limit.
FormatString - Ascii format string see file header for more details.
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
CHAR8 *Buffer;
CHAR8 *AsciiStr;
CHAR16 *UnicodeStr;
CHAR8 *Format;
UINTN Index;
UINTN Flags;
UINTN Width;
UINT64 Value;
//
// Process the format string. Stop if Buffer is over run.
//
Buffer = StartOfBuffer;
Format = (CHAR8 *)FormatString;
for (Index = 0; (*Format != '\0') && (Index < BufferSize); Format++) {
if (*Format != '%') {
if (*Format == '\n') {
//
// If carage return add line feed
//
Buffer[Index++] = '\r';
}
Buffer[Index++] = *Format;
} else {
//
// Now it's time to parse what follows after %
//
Format = GetFlagsAndWidth (Format, &Flags, &Width, &Marker);
switch (*Format) {
case 'X':
Flags |= PREFIX_ZERO;
Width = sizeof (UINT64) * 2;
//
// break skiped on purpose
//
case 'x':
if ((Flags & LONG_TYPE) == LONG_TYPE) {
Value = VA_ARG (Marker, UINT64);
} else {
Value = VA_ARG (Marker, UINTN);
}
Index += ValueTomHexStr (&Buffer[Index], Value, Flags, Width);
break;
case 'd':
if ((Flags & LONG_TYPE) == LONG_TYPE) {
Value = VA_ARG (Marker, UINT64);
} else {
Value = (UINTN)VA_ARG (Marker, UINTN);
}
Index += ValueToString (&Buffer[Index], Value, Flags, Width);
break;
case 's':
case 'S':
UnicodeStr = (CHAR16 *)VA_ARG (Marker, CHAR16 *);
if (UnicodeStr == NULL) {
UnicodeStr = L"<null string>";
}
for ( ;*UnicodeStr != '\0'; UnicodeStr++) {
Buffer[Index++] = (CHAR8)*UnicodeStr;
}
break;
case 'a':
AsciiStr = (CHAR8 *)VA_ARG (Marker, CHAR8 *);
if (AsciiStr == NULL) {
AsciiStr = "<null string>";
}
while (*AsciiStr != '\0') {
Buffer[Index++] = *AsciiStr++;
}
break;
case 'c':
Buffer[Index++] = (CHAR8)VA_ARG (Marker, UINTN);
break;
case 'g':
Index += GuidToString (
VA_ARG (Marker, EFI_GUID *),
&Buffer[Index],
BufferSize
);
break;
case 't':
Index += TimeToString (
VA_ARG (Marker, EFI_TIME *),
&Buffer[Index],
BufferSize
);
break;
case 'r':
Index += EfiStatusToString (
VA_ARG (Marker, EFI_STATUS),
&Buffer[Index],
BufferSize
);
break;
case '%':
Buffer[Index++] = *Format;
break;
default:
//
// if the type is unknown print it to the screen
//
Buffer[Index++] = *Format;
}
}
}
Buffer[Index++] = '\0';
return &Buffer[Index] - StartOfBuffer;
}
STATIC
CHAR8 *
GetFlagsAndWidth (
IN CHAR8 *Format,
OUT UINTN *Flags,
OUT UINTN *Width,
IN OUT VA_LIST *Marker
)
/*++
Routine Description:
AvSPrint worker function that parses flag and width information from the
Format string and returns the next index into the Format string that needs
to be parsed. See file headed for details of Flag and Width.
Arguments:
Format - Current location in the AvSPrint format string.
Flags - Returns flags
Width - Returns width of element
Marker - Vararg list that may be paritally consumed and returned.
Returns:
Pointer indexed into the Format string for all the information parsed
by this routine.
--*/
{
UINTN Count;
BOOLEAN Done;
*Flags = 0;
*Width = 0;
for (Done = FALSE; !Done; ) {
Format++;
switch (*Format) {
case '-': *Flags |= LEFT_JUSTIFY; break;
case '+': *Flags |= PREFIX_SIGN; break;
case ' ': *Flags |= PREFIX_BLANK; break;
case ',': *Flags |= COMMA_TYPE; break;
case 'L':
case 'l': *Flags |= LONG_TYPE; break;
case '*':
*Width = VA_ARG (*Marker, UINTN);
break;
case '0':
*Flags |= PREFIX_ZERO;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
Count = 0;
do {
Count = (Count * 10) + *Format - '0';
Format++;
} while ((*Format >= '0') && (*Format <= '9'));
Format--;
*Width = Count;
break;
default:
Done = TRUE;
}
}
return Format;
}
static CHAR8 mHexStr[] = { '0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F' };
STATIC
UINTN
ValueTomHexStr (
IN OUT CHAR8 *Buffer,
IN UINT64 Value,
IN UINTN Flags,
IN UINTN Width
)
/*++
Routine Description:
AvSPrint worker function that prints a Value as a hex number in Buffer
Arguments:
Buffer - Location to place ascii hex string of Value.
Value - Hex value to convert to a string in Buffer.
Flags - Flags to use in printing Hex string, see file header for details.
Width - Width of hex value.
Returns:
Number of characters printed.
--*/
{
CHAR8 TempBuffer[30];
CHAR8 *TempStr;
CHAR8 Prefix;
CHAR8 *BufferPtr;
UINTN Count;
UINTN Index;
TempStr = TempBuffer;
BufferPtr = Buffer;
//
// Count starts at one since we will null terminate. Each iteration of the
// loop picks off one nibble. Oh yea TempStr ends up backwards
//
Count = 0;
do {
*(TempStr++) = mHexStr[Value & 0x0f];
Value = RShiftU64 (Value, 4);
Count++;
} while (Value != 0);
if (Flags & PREFIX_ZERO) {
Prefix = '0';
} else if (!(Flags & LEFT_JUSTIFY)) {
Prefix = ' ';
} else {
Prefix = 0x00;
}
for (Index = Count; Index < Width; Index++) {
*(TempStr++) = Prefix;
}
//
// Reverse temp string into Buffer.
//
while (TempStr != TempBuffer) {
*(BufferPtr++) = *(--TempStr);
}
*BufferPtr = 0;
return Index;
}
STATIC
UINTN
ValueToString (
IN OUT CHAR8 *Buffer,
IN INT64 Value,
IN UINTN Flags,
IN UINTN Width
)
/*++
Routine Description:
AvSPrint worker function that prints a Value as a decimal number in Buffer
Arguments:
Buffer - Location to place ascii decimal number string of Value.
Value - Decimal value to convert to a string in Buffer.
Flags - Flags to use in printing decimal string, see file header for details.
Width - Width of hex value.
Returns:
Number of characters printed.
--*/
{
CHAR8 TempBuffer[30];
CHAR8 *TempStr;
CHAR8 *BufferPtr;
UINTN Count;
UINTN Remainder;
TempStr = TempBuffer;
BufferPtr = Buffer;
Count = 0;
if (Value < 0) {
*(BufferPtr++) = '-';
Value = -Value;
Count++;
}
do {
Value = (INT64)DivU64x32 ((UINT64)Value, 10, &Remainder);
*(TempStr++) = (CHAR8)(Remainder + '0');
Count++;
if ((Flags & COMMA_TYPE) == COMMA_TYPE) {
if (Count % 3 == 0) {
*(TempStr++) = ',';
}
}
} while (Value != 0);
//
// Reverse temp string into Buffer.
//
while (TempStr != TempBuffer) {
*(BufferPtr++) = *(--TempStr);
}
*BufferPtr = 0;
return Count;
}
STATIC
UINTN
GuidToString (
IN EFI_GUID *Guid,
IN CHAR8 *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
AvSPrint worker function that prints an EFI_GUID.
Arguments:
Guid - Pointer to GUID to print.
Buffer - Buffe to print Guid into.
BufferSize - Size of Buffer.
Returns:
Number of characters printed.
--*/
{
UINTN Size;
Size = ASPrint (
Buffer,
BufferSize,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
Guid->Data1,
Guid->Data2,
Guid->Data3,
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7]
);
//
// ASPrint will null terminate the string. The -1 skips the null
//
return Size - 1;
}
STATIC
UINTN
TimeToString (
IN EFI_TIME *Time,
OUT CHAR8 *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
AvSPrint worker function that prints EFI_TIME.
Arguments:
Time - Pointer to EFI_TIME sturcture to print.
Buffer - Buffer to print Time into.
BufferSize - Size of Buffer.
Returns:
Number of characters printed.
--*/
{
UINTN Size;
Size = ASPrint (
Buffer,
BufferSize,
"%02d/%02d/%04d %02d:%02d",
Time->Month,
Time->Day,
Time->Year,
Time->Hour,
Time->Minute
);
//
// ASPrint will null terminate the string. The -1 skips the null
//
return Size - 1;
}
STATIC
UINTN
EfiStatusToString (
IN EFI_STATUS Status,
OUT CHAR8 *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
AvSPrint worker function that prints EFI_STATUS as a string. If string is
not known a hex value will be printed.
Arguments:
Status - EFI_STATUS sturcture to print.
Buffer - Buffer to print EFI_STATUS message string into.
BufferSize - Size of Buffer.
Returns:
Number of characters printed.
--*/
{
UINTN Size;
CHAR8 *Desc;
if (Status == EFI_SUCCESS) {
Desc = "Success";
} else if (Status == EFI_LOAD_ERROR) {
Desc = "Load Error";
} else if (Status == EFI_INVALID_PARAMETER) {
Desc = "Invalid Parameter";
} else if (Status == EFI_UNSUPPORTED) {
Desc = "Unsupported";
} else if (Status == EFI_BAD_BUFFER_SIZE) {
Desc = "Bad Buffer Size";
} else if (Status == EFI_BUFFER_TOO_SMALL) {
Desc = "Buffer Too Small";
} else if (Status == EFI_NOT_READY) {
Desc = "Not Ready";
} else if (Status == EFI_DEVICE_ERROR) {
Desc = "Device Error";
} else if (Status == EFI_WRITE_PROTECTED) {
Desc = "Write Protected";
} else if (Status == EFI_OUT_OF_RESOURCES) {
Desc = "Out of Resources";
} else if (Status == EFI_VOLUME_CORRUPTED) {
Desc = "Volume Corrupt";
} else if (Status == EFI_VOLUME_FULL) {
Desc = "Volume Full";
} else if (Status == EFI_NO_MEDIA) {
Desc = "No Media";
} else if (Status == EFI_MEDIA_CHANGED) {
Desc = "Media changed";
} else if (Status == EFI_NOT_FOUND) {
Desc = "Not Found";
} else if (Status == EFI_ACCESS_DENIED) {
Desc = "Access Denied";
} else if (Status == EFI_NO_RESPONSE) {
Desc = "No Response";
} else if (Status == EFI_NO_MAPPING) {
Desc = "No mapping";
} else if (Status == EFI_TIMEOUT) {
Desc = "Time out";
} else if (Status == EFI_NOT_STARTED) {
Desc = "Not started";
} else if (Status == EFI_ALREADY_STARTED) {
Desc = "Already started";
} else if (Status == EFI_ABORTED) {
Desc = "Aborted";
} else if (Status == EFI_ICMP_ERROR) {
Desc = "ICMP Error";
} else if (Status == EFI_TFTP_ERROR) {
Desc = "TFTP Error";
} else if (Status == EFI_PROTOCOL_ERROR) {
Desc = "Protocol Error";
} else if (Status == EFI_WARN_UNKNOWN_GLYPH) {
Desc = "Warning Unknown Glyph";
} else if (Status == EFI_WARN_DELETE_FAILURE) {
Desc = "Warning Delete Failure";
} else if (Status == EFI_WARN_WRITE_FAILURE) {
Desc = "Warning Write Failure";
} else if (Status == EFI_WARN_BUFFER_TOO_SMALL) {
Desc = "Warning Buffer Too Small";
} else {
Desc = NULL;
}
//
// If we found a match, copy the message to the user's buffer. Otherwise
// sprint the hex status code to their buffer.
//
if (Desc != NULL) {
Size = ASPrint (Buffer, BufferSize, "%a", Desc);
} else {
Size = ASPrint (Buffer, BufferSize, "%X", Status);
}
return Size - 1;
}

View File

@@ -0,0 +1,37 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Print.h
Abstract:
Private data for Print.c
--*/
#ifndef _PRINT_H_
#define _PRINT_H_
#define LEFT_JUSTIFY 0x01
#define PREFIX_SIGN 0x02
#define PREFIX_BLANK 0x04
#define COMMA_TYPE 0x08
#define LONG_TYPE 0x10
#define PREFIX_ZERO 0x20
//
// Largest number of characters that can be printed out.
//
#define PEI_LIB_MAX_PRINT_BUFFER (80 * 4)
#endif

View File

@@ -0,0 +1,56 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeCoffLoaderEx.c
Abstract:
IA-32 Specific relocation fixups
Revision History
--*/
#include "TianoCommon.h"
EFI_STATUS
PeCoffLoaderRelocateImageEx (
IN UINT16 *Reloc,
IN OUT CHAR8 *Fixup,
IN OUT CHAR8 **FixupData,
IN UINT64 Adjust
)
/*++
Routine Description:
Performs an IA-32 specific relocation fixup
Arguments:
Reloc - Pointer to the relocation record
Fixup - Pointer to the address to fix up
FixupData - Pointer to a buffer to log the fixups
Adjust - The offset to adjust the fixup
Returns:
EFI_UNSUPPORTED - Unsupported now
--*/
{
return EFI_UNSUPPORTED;
}

View File

@@ -0,0 +1,65 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeCoffLoaderEx.h
Abstract:
IA-32 Specific relocation fixups
Revision History
--*/
#ifndef _PE_COFF_LOADER_EX_H_
#define _PE_COFF_LOADER_EX_H_
//
// Define macro to determine if the machine type is supported.
// Returns 0 if the machine is not supported, Not 0 otherwise.
//
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \
((Machine) == EFI_IMAGE_MACHINE_IA32 || \
(Machine) == EFI_IMAGE_MACHINE_EBC)
EFI_STATUS
PeCoffLoaderRelocateImageEx (
IN UINT16 *Reloc,
IN OUT CHAR8 *Fixup,
IN OUT CHAR8 **FixupData,
IN UINT64 Adjust
)
/*++
Routine Description:
Performs an IA-32 specific relocation fixup
Arguments:
Reloc - Pointer to the relocation record
Fixup - Pointer to the address to fix up
FixupData - Pointer to a buffer to log the fixups
Adjust - The offset to adjust the fixup
Returns:
EFI_UNSUPPORTED - Unsupported now
--*/
;
#endif

View File

@@ -0,0 +1,47 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PerformancePrimitives.c
Abstract:
Support for Performance library
--*/
#include "TianoCommon.h"
#include "CpuIA32.h"
EFI_STATUS
GetTimerValue (
OUT UINT64 *TimerValue
)
/*++
Routine Description:
Get timer value.
Arguments:
TimerValue - Pointer to the returned timer value
Returns:
EFI_SUCCESS - Successfully got timer value
--*/
{
*TimerValue = EfiReadTsc ();
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,140 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Processor.c
Abstract:
--*/
#include "Tiano.h"
#include "EfiJump.h"
#include EFI_GUID_DEFINITION (PeiFlushInstructionCache)
#include EFI_GUID_DEFINITION (PeiTransferControl)
//
// Prototypes
//
EFI_STATUS
EFIAPI
TransferControlSetJump (
IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This,
IN EFI_JUMP_BUFFER *Jump
);
EFI_STATUS
EFIAPI
TransferControlLongJump (
IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This,
IN EFI_JUMP_BUFFER *Jump
);
EFI_STATUS
EFIAPI
FlushInstructionCacheFlush (
IN EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS Start,
IN UINT64 Length
);
//
// Table declarations
//
EFI_PEI_TRANSFER_CONTROL_PROTOCOL mTransferControl = {
TransferControlSetJump,
TransferControlLongJump,
sizeof (EFI_JUMP_BUFFER)
};
EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL mFlushInstructionCache = {
FlushInstructionCacheFlush
};
EFI_STATUS
InstallEfiPeiTransferControl (
IN OUT EFI_PEI_TRANSFER_CONTROL_PROTOCOL **This
)
/*++
Routine Description:
Installs the pointer to the transfer control mechanism
Arguments:
This - Pointer to transfer control mechanism.
Returns:
EFI_SUCCESS - Successfully installed.
--*/
{
*This = &mTransferControl;
return EFI_SUCCESS;
}
EFI_STATUS
InstallEfiPeiFlushInstructionCache (
IN OUT EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL **This
)
/*++
Routine Description:
Installs the pointer to the flush instruction cache mechanism
Arguments:
This - Pointer to flush instruction cache mechanism.
Returns:
EFI_SUCCESS - Successfully installed
--*/
{
*This = &mFlushInstructionCache;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FlushInstructionCacheFlush (
IN EFI_PEI_FLUSH_INSTRUCTION_CACHE_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS Start,
IN UINT64 Length
)
/*++
Routine Description:
This routine would provide support for flushing the CPU instruction cache.
In the case of IA32, this flushing is not necessary and is thus not implemented.
Arguments:
This - Pointer to CPU Architectural Protocol interface
Start - Start adddress in memory to flush
Length - Length of memory to flush
Returns:
Status
EFI_SUCCESS
--*/
{
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,223 @@
;
; Copyright (c) 2004, Intel Corporation
; All rights reserved. This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution. The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; Module Name:
;
; ProcessorAsms.Asm
;
; Abstract:
; This is separated from processor.c to allow this functions to be built with /O1
;
; Notes:
; - Masm uses "This", "ebx", etc as a directive.
; - H2INC is still not embedded in our build process so I translated the struc manually.
; - Unreferenced variables/arguments (This, NewBsp, NewStack) were causing compile errors and
; did not know of "pragma" mechanism in MASM and I did not want to reduce the warning level.
; Instead, I did a dummy referenced.
;
.686P
.MMX
.MODEL SMALL
.CODE
EFI_SUCCESS equ 0
EFI_WARN_RETURN_FROM_LONG_JUMP equ 5
;
; Generated by h2inc run manually
;
_EFI_JUMP_BUFFER STRUCT 2t
_ebx DWORD ?
_esi DWORD ?
_edi DWORD ?
_ebp DWORD ?
_esp DWORD ?
_eip DWORD ?
_EFI_JUMP_BUFFER ENDS
EFI_JUMP_BUFFER TYPEDEF _EFI_JUMP_BUFFER
TransferControlSetJump PROTO C \
_This:PTR EFI_PEI_TRANSFER_CONTROL_PROTOCOL, \
Jump:PTR EFI_JUMP_BUFFER
TransferControlLongJump PROTO C \
_This:PTR EFI_PEI_TRANSFER_CONTROL_PROTOCOL, \
Jump:PTR EFI_JUMP_BUFFER
SwitchStacks PROTO C \
EntryPoint:PTR DWORD, \
Parameter:DWORD, \
NewStack:PTR DWORD, \
NewBsp:PTR DWORD
SwitchIplStacks PROTO C \
EntryPoint:PTR DWORD, \
Parameter1:DWORD, \
Parameter2:DWORD, \
NewStack:PTR DWORD, \
NewBsp:PTR DWORD
;
;Routine Description:
;
; This routine implements the IA32 variant of the SetJump call. Its
; responsibility is to store system state information for a possible
; subsequent LongJump.
;
;Arguments:
;
; Pointer to CPU context save buffer.
;
;Returns:
;
; EFI_SUCCESS
;
TransferControlSetJump PROC C \
_This:PTR EFI_PEI_TRANSFER_CONTROL_PROTOCOL, \
Jump:PTR EFI_JUMP_BUFFER
mov eax, _This
mov ecx, Jump
mov (EFI_JUMP_BUFFER PTR [ecx])._ebx, ebx
mov (EFI_JUMP_BUFFER PTR [ecx])._esi, esi
mov (EFI_JUMP_BUFFER PTR [ecx])._edi, edi
mov eax, [ebp]
mov (EFI_JUMP_BUFFER PTR [ecx])._ebp, eax
lea eax, [ebp+4]
mov (EFI_JUMP_BUFFER PTR [ecx])._esp, eax
mov eax, [ebp+4]
mov (EFI_JUMP_BUFFER PTR [ecx])._eip, eax
mov eax, EFI_SUCCESS
ret
TransferControlSetJump ENDP
;
; Routine Description:
;
; This routine implements the IA32 variant of the LongJump call. Its
; responsibility is restore the system state to the Context Buffer and
; pass control back.
;
; Arguments:
;
; Pointer to CPU context save buffer.
;
; Returns:
;
; EFI_WARN_RETURN_FROM_LONG_JUMP
;
TransferControlLongJump PROC C \
_This:PTR EFI_PEI_TRANSFER_CONTROL_PROTOCOL, \
Jump:PTR EFI_JUMP_BUFFER
push ebx
push esi
push edi
mov eax, _This
; set return from SetJump to EFI_WARN_RETURN_FROM_LONG_JUMP
mov eax, EFI_WARN_RETURN_FROM_LONG_JUMP
mov ecx, Jump
mov ebx, (EFI_JUMP_BUFFER PTR [ecx])._ebx
mov esi, (EFI_JUMP_BUFFER PTR [ecx])._esi
mov edi, (EFI_JUMP_BUFFER PTR [ecx])._edi
mov ebp, (EFI_JUMP_BUFFER PTR [ecx])._ebp
mov esp, (EFI_JUMP_BUFFER PTR [ecx])._esp
add esp, 4 ;pop the eip
jmp DWORD PTR (EFI_JUMP_BUFFER PTR [ecx])._eip
mov eax, EFI_WARN_RETURN_FROM_LONG_JUMP
pop edi
pop esi
pop ebx
ret
TransferControlLongJump ENDP
;
; Routine Description:
; This allows the caller to switch the stack and goes to the new entry point
;
; Arguments:
; EntryPoint - Pointer to the location to enter
; Parameter - Parameter to pass in
; NewStack - New Location of the stack
; NewBsp - New BSP
;
; Returns:
;
; Nothing. Goes to the Entry Point passing in the new parameters
;
SwitchStacks PROC C \
EntryPoint:PTR DWORD, \
Parameter:DWORD, \
NewStack:PTR DWORD, \
NewBsp:PTR DWORD
push ebx
mov eax, NewBsp
mov ebx, Parameter
mov ecx, EntryPoint
mov eax, NewStack
mov esp, eax
push ebx
push 0
jmp ecx
pop ebx
ret
SwitchStacks ENDP
;
; Routine Description:
; This allows the caller to switch the stack and goes to the new entry point
;
; Arguments:
; EntryPoint - Pointer to the location to enter
; Parameter1/Parameter2 - Parameter to pass in
; NewStack - New Location of the stack
; NewBsp - New BSP
;
; Returns:
;
; Nothing. Goes to the Entry Point passing in the new parameters
;
SwitchIplStacks PROC C \
EntryPoint:PTR DWORD, \
Parameter1:DWORD, \
Parameter2:DWORD, \
NewStack:PTR DWORD, \
NewBsp:PTR DWORD
push ebx
mov eax, NewBsp
mov ebx, Parameter1
mov edx, Parameter2
mov ecx, EntryPoint
mov eax, NewStack
mov esp, eax
push edx
push ebx
call ecx
pop ebx
ret
SwitchIplStacks ENDP
END

View File

@@ -0,0 +1,34 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiJump.h
Abstract:
This is the Setjump/Longjump pair for an IA32 processor.
--*/
#ifndef _EFI_JUMP_H_
#define _EFI_JUMP_H_
typedef struct {
UINT32 ebx;
UINT32 esi;
UINT32 edi;
UINT32 ebp;
UINT32 esp;
UINT32 eip;
} EFI_JUMP_BUFFER;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,121 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
SimpleFileParsing.h
Abstract:
Function prototypes and defines for the simple file parsing routines.
--*/
#include <Base.h>
#include <UefiBaseTypes.h>
#ifndef _SIMPLE_FILE_PARSING_H_
#define _SIMPLE_FILE_PARSING_H_
#define T_CHAR char
STATUS
SFPInit (
VOID
)
;
STATUS
SFPOpenFile (
char *FileName
)
;
BOOLEAN
SFPIsKeyword (
T_CHAR *Str
)
;
BOOLEAN
SFPIsToken (
T_CHAR *Str
)
;
BOOLEAN
SFPGetNextToken (
T_CHAR *Str,
unsigned int Len
)
;
BOOLEAN
SFPGetGuidToken (
T_CHAR *Str,
UINT32 Len
)
;
#define PARSE_GUID_STYLE_5_FIELDS 0
BOOLEAN
SFPGetGuid (
int GuidStyle,
EFI_GUID *Value
)
;
BOOLEAN
SFPSkipToToken (
T_CHAR *Str
)
;
BOOLEAN
SFPGetNumber (
unsigned int *Value
)
;
BOOLEAN
SFPGetQuotedString (
T_CHAR *Str,
int Length
)
;
BOOLEAN
SFPIsEOF (
VOID
)
;
STATUS
SFPCloseFile (
VOID
)
;
unsigned
int
SFPGetLineNumber (
VOID
)
;
T_CHAR *
SFPGetFileName (
VOID
)
;
#endif // #ifndef _SIMPLE_FILE_PARSING_H_

View File

@@ -0,0 +1,73 @@
/*--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
WinNtInclude.h
Abstract:
Include file for the WinNt Library
--*/
#ifndef __WIN_NT_INCLUDE_H__
#define __WIN_NT_INCLUDE_H__
//
// Win32 include files do not compile clean with /W4, so we use the warning
// pragma to suppress the warnings for Win32 only. This way our code can stil
// compile at /W4 (highest warning level) with /WX (warnings cause build
// errors).
//
#pragma warning(disable : 4115)
#pragma warning(disable : 4201)
#pragma warning(disable : 4214)
#pragma warning(disable : 4028)
#pragma warning(disable : 4133)
#define GUID _WINNT_DUP_GUID_____
#define _LIST_ENTRY _WINNT_DUP_LIST_ENTRY_FORWARD
#define LIST_ENTRY _WINNT_DUP_LIST_ENTRY
#define InterlockedIncrement _WINNT_DUP_InterlockedIncrement
#define InterlockedDecrement _WINNT_DUP_InterlockedDecrement
#define InterlockedCompareExchange64 _WINNT_DUP_InterlockedCompareExchange64
#undef UNALIGNED
#undef CONST
#undef VOID
#ifndef __GNUC__
#include "windows.h"
#endif
#undef GUID
#undef _LIST_ENTRY
#undef LIST_ENTRY
#undef InterlockedIncrement
#undef InterlockedDecrement
#undef InterlockedCompareExchange64
#undef InterlockedCompareExchangePointer
#define VOID void
//
// Prevent collisions with Windows API name macros that deal with Unicode/Not issues
//
#undef LoadImage
#undef CreateEvent
//
// Set the warnings back on as the EFI code must be /W4.
//
#pragma warning(default : 4115)
#pragma warning(default : 4201)
#pragma warning(default : 4214)
#endif

View File

@@ -0,0 +1,8 @@
mkdir -p ../Library-mingw
mkdir -p ../Library-cygwin
rm *.o
gcc -c -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ *.c
ar cr ../Library-cygwin/libCommon.a *.o
rm *.o
gcc -mno-cygwin -c -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ *.c
ar cr ../Library-mingw/libCommon.a *.o

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="CommonTools.lib" basedir=".">
<!--
EDK Common Tools Library
Copyright (c) 2006, Intel Corporation
-->
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="tmp" value="tmp"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/Common/tmp"/>
<target name="CommonTools.lib" depends="init, ToolsLibrary">
<echo message="Building the EDK CommonTools Library"/>
</target>
<target name="init">
<echo message="The EDK CommonTools Library"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>
Unsupported Operating System
Please Contact Intel Corporation
</echo>
</else>
</if>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
</then>
</elseif>
</if>
</target>
<target name="ToolsLibrary" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${LIB_DIR}/CommonTools"
outtype="static"
libtool="${haveLibtool}"
optimize="speed">
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<fileset dir="${basedir}/Common"
includes="*.h *.c"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
</cc>
<if>
<os family="dos"/>
<then>
<exec dir="${BUILD_DIR}" executable="lib" failonerror="false">
<arg line="/NOLOGO *.lib /OUT:${LIB_DIR}/CommonTools${ext_static}"/>
</exec>
</then>
</if>
</target>
<target name="clean" depends="init">
<echo message="Removing Intermediate Files Only from ${BUILD_DIR}"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall" depends="init">
<echo message="Removing Object Files and the Library: CommonTools${ext_static}"/>
<delete dir="${BUILD_DIR}">
<fileset dir="${LIB_DIR}" includes="CommonTools${ext_static}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,89 @@
#include "CompressDll.h"
#include "EfiCompress.h"
extern
EFI_STATUS
Compress (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
);
JNIEXPORT jbyteArray JNICALL Java_org_tianocore_framework_tasks_Compress_CallCompress
(JNIEnv *env, jobject obj, jbyteArray SourceBuffer, jint SourceSize, jstring path)
{
char* DestBuffer;
int DestSize;
int Result;
char *InputBuffer;
jbyteArray OutputBuffer;
jbyte *TempByte;
DestSize = 0;
DestBuffer = NULL;
TempByte = (*env)->GetByteArrayElements(env, SourceBuffer, 0);
InputBuffer = (char*) TempByte;
//
// First call compress function and get need buffer size
//
Result = Compress (
(char*) InputBuffer,
SourceSize,
DestBuffer,
&DestSize
);
if (Result = EFI_BUFFER_TOO_SMALL) {
DestBuffer = malloc (DestSize);
}
//
// Second call compress and get the DestBuffer value
//
Result = Compress(
(char*) InputBuffer,
SourceSize,
DestBuffer,
&DestSize
);
//
// new a MV array to store the return compressed buffer
//
OutputBuffer = (*env)->NewByteArray(env, DestSize);
(*env)->SetByteArrayRegion(env, OutputBuffer,0, DestSize, (jbyte*) DestBuffer);
//
// Free Ouputbuffer.
//
free (DestBuffer);
if (Result != 0) {
return NULL;
} else {
return OutputBuffer;
}
}
#ifdef _MSC_VER
BOOLEAN
__stdcall
DllMainCRTStartup(
unsigned int hDllHandle,
unsigned int nReason,
void* Reserved
)
{
return TRUE;
}
#else
#ifdef __GNUC__
#endif
#endif

View File

@@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_tianocore_frameworktasks_Compress */
#ifndef _Included_org_tianocore_framework_tasks_Compress
#define _Included_org_tianocore_framework_tasks_Compress
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_tianocore_frameworktasks_Compress
* Method: CallCompress
* Signature: ([BILjava/lang/String;)[B
*/
JNIEXPORT jbyteArray JNICALL Java_org_tianocore_framework_tasks_Compress_CallCompress
(JNIEnv *, jobject, jbyteArray, jint, jstring);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--EDK GenDepex Tool
Copyright (c) 2006, Intel Corporation-->
<property environment="env"/>
<property name="WORKSPACE" value="${env.WORKSPACE}"/>
<property name="ToolName" value="CompressDll"/>
<property name="LibName" value="CompressDll"/>
<property name="FileSet" value="CompressDll.c CompressDll.h"/>
<property name="LibFileSet" value="CompressDll.c DepexParser.h"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${WORKSPACE}/Tools/Source/TianoTools/${ToolName}/tmp"/>
<target name="GenTool" depends="init,Lib,Dll">
<echo message="Building the EDK Tool: ${ToolName}"/>
</target>
<target name="init">
<echo message="The EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>Unsupported Operating System
Please Contact Intel Corporation</echo>
</else>
</if>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
<property name="ext_exe" value=".exe"/>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
<property name="ext_exe" value=""/>
</then>
</elseif>
</if>
<condition property="CheckDepends">
<uptodate targetfile="${BIN_DIR}/${LibName}${ext_dynamic}">
<srcfiles dir="${BUILD_DIR}" includes="CommonTools.lib, CustomizedCompress.lib, CompressDll.obj"/>
</uptodate>
</condition>
</target>
<target name="Lib" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}" outtype="static" optimize="speed">
<fileset dir="${ToolName}" includes="${LibFileSet}" defaultexcludes="TRUE" excludes="*.xml *.inf"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<includepath path="${env.JAVA_HOME}/include"/>
<includepath path="${env.JAVA_HOME}/include/win32"/>
</cc>
</target>
<target name="Dll" unless="CheckDepends">
<if>
<os family="dos"/>
<then>
<echo message="Begin link!"/>
<exec dir="${BUILD_DIR}" executable="link" failonerror="false">
<arg line="kernel32.lib ${LIB_DIR}/CommonTools.lib ${LIB_DIR}/CustomizedCompress.lib /NOLOGO /DLL /MACHINE:I386 /OUT:${BUILD_DIR}/${LibName}${ext_dynamic} ${ToolName}"/>
</exec>
<copy todir="${BIN_DIR}" file="${BUILD_DIR}/${LibName}${ext_dynamic}"/>
</then>
</if>
</target>
<target name="clean" depends="init">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall" depends="init">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete dir="${BUILD_DIR}">
<fileset dir="${BIN_DIR}" includes="${ToolName}${ext_dynamic}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,147 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CustomizedCompress.c
Abstract:
Header file for Customized compression routine
--*/
#include <Base.h>
#include <UefiBaseTypes.h>
EFI_STATUS
SetCustomizedCompressionType (
IN CHAR8 *Type
)
/*++
Routine Description:
The implementation of Customized SetCompressionType().
Arguments:
Type - The type if compression.
Returns:
EFI_SUCCESS - The type has been set.
EFI_UNSUPPORTED - This type is unsupported.
--*/
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
CustomizedGetInfo (
IN VOID *Source,
IN UINT32 SrcSize,
OUT UINT32 *DstSize,
OUT UINT32 *ScratchSize
)
/*++
Routine Description:
The implementation of Customized GetInfo().
Arguments:
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
EFI_UNSUPPORTED - The operation is unsupported.
--*/
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
CustomizedDecompress (
IN VOID *Source,
IN UINT32 SrcSize,
IN OUT VOID *Destination,
IN UINT32 DstSize,
IN OUT VOID *Scratch,
IN UINT32 ScratchSize
)
/*++
Routine Description:
The implementation of Customized Decompress().
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_INVALID_PARAMETER - The source data is corrupted
EFI_UNSUPPORTED - The operation is unsupported.
--*/
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
CustomizedCompress (
IN UINT8 *SrcBuffer,
IN UINT32 SrcSize,
IN UINT8 *DstBuffer,
IN OUT UINT32 *DstSize
)
/*++
Routine Description:
The Customized compression routine.
Arguments:
SrcBuffer - The buffer storing the source data
SrcSize - The size of source data
DstBuffer - The buffer to store the compressed data
DstSize - On input, the size of DstBuffer; On output,
the size of the actual compressed data.
Returns:
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. In this case,
DstSize contains the size needed.
EFI_SUCCESS - Compression is successful.
EFI_UNSUPPORTED - The operation is unsupported.
--*/
{
return EFI_UNSUPPORTED;
}

View File

@@ -0,0 +1,8 @@
mkdir -p ../Library-mingw
mkdir -p ../Library-cygwin
rm *.o
gcc -c -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ *.c
ar cr ../Library-cygwin/libCustomizedCompress.a *.o
rm *.o
gcc -mno-cygwin -c -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ *.c
ar cr ../Library-mingw/libCustomizedCompress.a *.o

View File

@@ -0,0 +1,121 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="CustomizedCompress.lib" basedir=".">
<!--
EDK Customized Compress Library
Copyright (c) 2006, Intel Corporation
-->
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/CustomizedCompress/tmp"/>
<target name="CustomizedCompress.lib" depends="ToolsLibrary">
<echo message="Building the EDK CustomizedCompress Library"/>
</target>
<target name="init">
<echo message="The EDK CustomizedCompress Library"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>
Unsupported Operating System
Please Contact Intel Corporation
</echo>
</else>
</if>
<property name="HOST_ARCH" value="IA32" />
<ToolChainSetup confPath="${WORKSPACE}/Tools/Conf" />
<echo message="Compiler: ${CC}"/>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
</then>
</elseif>
</if>
</target>
<target name="ToolsLibrary" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${LIB_DIR}/CustomizedCompress"
outtype="static"
libtool="${haveLibtool}"
optimize="speed">
<fileset dir="${basedir}/CustomizedCompress"
includes="*.h *.c"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
</cc>
<if>
<os family="dos"/>
<then>
<exec dir="${BUILD_DIR}" executable="lib" failonerror="false">
<arg line="/NOLOGO *.lib /OUT:${LIB_DIR}/CustomizedCompress${ext_static}"/>
</exec>
</then>
</if>
</target>
<target name="clean">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall">
<echo message="Removing Object Files and the Library: CustomizedCompress${ext_static}"/>
<delete dir="${BUILD_DIR}">
<fileset dir="${LIB_DIR}" includes="CustomizedCompress${ext_static}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1 @@
gcc -mno-cygwin -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ *.c -o FwImage -L../Library-mingw -lCommon

View File

@@ -0,0 +1,117 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK FwImage Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="FwImage"/>
<property name="FileSet" value="fwimage.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="Building the EDK Tool: ${ToolName}"/>
</target>
<target name="init">
<echo message="The EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>
Unsupported Operating System
Please Contact Intel Corporation
</echo>
</else>
</if>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
<property name="ext_exe" value=".exe"/>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
<property name="ext_exe" value=""/>
</then>
</elseif>
</if>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools.lib"/>
</cc>
</target>
<target name="clean" depends="init">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall" depends="init">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete dir="${BUILD_DRI}">
<fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,332 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
fwimage.c
Abstract:
Converts a pe32+ image to an FW image type
--*/
#include <WinNtInclude.h>
#ifndef __GNUC__
#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <Base.h>
#include <UefiBaseTypes.h>
#include <CommonLib.h>
#include <EfiImage.h>
#include <EfiUtilityMsgs.c>
#define UTILITY_NAME "FwImage"
#ifdef __GNUC__
typedef unsigned long ULONG;
typedef unsigned char UCHAR;
typedef unsigned char *PUCHAR;
typedef unsigned short USHORT;
#endif
VOID
Usage (
VOID
)
{
printf ("Usage: " UTILITY_NAME " {-t time-date} [APPLICATION|BS_DRIVER|RT_DRIVER|SAL_RT_DRIVER|COMBINED_PEIM_DRIVER|SECURITY_CORE|PEI_CORE|PE32_PEIM|RELOCATABLE_PEIM] peimage [outimage]");
}
static
STATUS
FCopyFile (
FILE *in,
FILE *out
)
{
ULONG filesize;
ULONG offset;
ULONG length;
UCHAR Buffer[8 * 1024];
fseek (in, 0, SEEK_END);
filesize = ftell (in);
fseek (in, 0, SEEK_SET);
fseek (out, 0, SEEK_SET);
offset = 0;
while (offset < filesize) {
length = sizeof (Buffer);
if (filesize - offset < length) {
length = filesize - offset;
}
fread (Buffer, length, 1, in);
fwrite (Buffer, length, 1, out);
offset += length;
}
if ((ULONG) ftell (out) != filesize) {
Error (NULL, 0, 0, "write error", NULL);
return STATUS_ERROR;
}
return STATUS_SUCCESS;
}
int
main (
int argc,
char *argv[]
)
/*++
Routine Description:
Main function.
Arguments:
argc - Number of command line parameters.
argv - Array of pointers to command line parameter strings.
Returns:
STATUS_SUCCESS - Utility exits successfully.
STATUS_ERROR - Some error occurred during execution.
--*/
{
ULONG Type;
PUCHAR Ext;
PUCHAR p;
PUCHAR pe;
PUCHAR OutImageName;
UCHAR outname[500];
FILE *fpIn;
FILE *fpOut;
EFI_IMAGE_DOS_HEADER DosHdr;
EFI_IMAGE_NT_HEADERS PeHdr;
time_t TimeStamp;
struct tm TimeStruct;
EFI_IMAGE_DOS_HEADER BackupDosHdr;
ULONG Index;
BOOLEAN TimeStampPresent;
SetUtilityName (UTILITY_NAME);
//
// Assign to fix compile warning
//
OutImageName = NULL;
Type = 0;
Ext = 0;
TimeStamp = 0;
TimeStampPresent = FALSE;
//
// Look for -t time-date option first. If the time is "0", then
// skip it.
//
if ((argc > 2) && !strcmp (argv[1], "-t")) {
TimeStampPresent = TRUE;
if (strcmp (argv[2], "0") != 0) {
//
// Convert the string to a value
//
memset ((char *) &TimeStruct, 0, sizeof (TimeStruct));
if (sscanf(
argv[2], "%d/%d/%d,%d:%d:%d",
&TimeStruct.tm_mon, /* months since January - [0,11] */
&TimeStruct.tm_mday, /* day of the month - [1,31] */
&TimeStruct.tm_year, /* years since 1900 */
&TimeStruct.tm_hour, /* hours since midnight - [0,23] */
&TimeStruct.tm_min, /* minutes after the hour - [0,59] */
&TimeStruct.tm_sec /* seconds after the minute - [0,59] */
) != 6) {
Error (NULL, 0, 0, argv[2], "failed to convert to mm/dd/yyyy,hh:mm:ss format");
return STATUS_ERROR;
}
//
// Now fixup some of the fields
//
TimeStruct.tm_mon--;
TimeStruct.tm_year -= 1900;
//
// Sanity-check values?
// Convert
//
TimeStamp = mktime (&TimeStruct);
if (TimeStamp == (time_t) - 1) {
Error (NULL, 0, 0, argv[2], "failed to convert time");
return STATUS_ERROR;
}
}
//
// Skip over the args
//
argc -= 2;
argv += 2;
}
//
// Check for enough args
//
if (argc < 3) {
Usage ();
return STATUS_ERROR;
}
if (argc == 4) {
OutImageName = argv[3];
}
//
// Get new image type
//
p = argv[1];
if (*p == '/' || *p == '\\') {
p += 1;
}
if (stricmp (p, "app") == 0 || stricmp (p, "APPLICATION") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION;
Ext = ".efi";
} else if (stricmp (p, "bsdrv") == 0 || stricmp (p, "BS_DRIVER") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER;
Ext = ".efi";
} else if (stricmp (p, "rtdrv") == 0 || stricmp (p, "RT_DRIVER") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER;
Ext = ".efi";
} else if (stricmp (p, "rtdrv") == 0 || stricmp (p, "SAL_RT_DRIVER") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER;
Ext = ".efi";
} else if (stricmp (p, "SECURITY_CORE") == 0) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER;
Ext = ".sec";
} else if (stricmp (p, "peim") == 0 ||
stricmp (p, "PEI_CORE") == 0 ||
stricmp (p, "PE32_PEIM") == 0 ||
stricmp (p, "RELOCATABLE_PEIM") == 0 ||
stricmp (p, "combined_peim_driver") == 0
) {
Type = EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER;
Ext = ".pei";
} else {
Usage ();
return STATUS_ERROR;
}
//
// open source file
//
fpIn = fopen (argv[2], "rb");
if (!fpIn) {
Error (NULL, 0, 0, argv[2], "failed to open input file for reading");
return STATUS_ERROR;
}
//
// Read the dos & pe hdrs of the image
//
fseek (fpIn, 0, SEEK_SET);
fread (&DosHdr, sizeof (DosHdr), 1, fpIn);
if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
Error (NULL, 0, 0, argv[2], "DOS header signature not found in source image");
fclose (fpIn);
return STATUS_ERROR;
}
fseek (fpIn, DosHdr.e_lfanew, SEEK_SET);
fread (&PeHdr, sizeof (PeHdr), 1, fpIn);
if (PeHdr.Signature != EFI_IMAGE_NT_SIGNATURE) {
Error (NULL, 0, 0, argv[2], "PE header signature not found in source image");
fclose (fpIn);
return STATUS_ERROR;
}
//
// open output file
//
strcpy (outname, argv[2]);
pe = NULL;
for (p = outname; *p; p++) {
if (*p == '.') {
pe = p;
}
}
if (!pe) {
pe = p;
}
strcpy (pe, Ext);
if (!OutImageName) {
OutImageName = outname;
}
fpOut = fopen (OutImageName, "w+b");
if (!fpOut) {
Error (NULL, 0, 0, OutImageName, "could not open output file for writing");
fclose (fpIn);
return STATUS_ERROR;
}
//
// Copy the file
//
if (FCopyFile (fpIn, fpOut) != STATUS_SUCCESS) {
fclose (fpIn);
fclose (fpOut);
return STATUS_ERROR;
}
//
// Zero all unused fields of the DOS header
//
memcpy (&BackupDosHdr, &DosHdr, sizeof (DosHdr));
memset (&DosHdr, 0, sizeof (DosHdr));
DosHdr.e_magic = BackupDosHdr.e_magic;
DosHdr.e_lfanew = BackupDosHdr.e_lfanew;
fseek (fpOut, 0, SEEK_SET);
fwrite (&DosHdr, sizeof (DosHdr), 1, fpOut);
fseek (fpOut, sizeof (DosHdr), SEEK_SET);
for (Index = sizeof (DosHdr); Index < (ULONG) DosHdr.e_lfanew; Index++) {
fwrite (&DosHdr.e_cp, 1, 1, fpOut);
}
//
// Path the PE header
//
PeHdr.OptionalHeader.Subsystem = (USHORT) Type;
if (TimeStampPresent) {
PeHdr.FileHeader.TimeDateStamp = (UINT32) TimeStamp;
}
PeHdr.OptionalHeader.SizeOfStackReserve = 0;
PeHdr.OptionalHeader.SizeOfStackCommit = 0;
PeHdr.OptionalHeader.SizeOfHeapReserve = 0;
PeHdr.OptionalHeader.SizeOfHeapCommit = 0;
fseek (fpOut, DosHdr.e_lfanew, SEEK_SET);
fwrite (&PeHdr, sizeof (PeHdr), 1, fpOut);
//
// Done
//
fclose (fpIn);
fclose (fpOut);
//
// printf ("Created %s\n", OutImageName);
//
return STATUS_SUCCESS;
}

View File

@@ -0,0 +1,286 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenCRC32Section.c
Abstract:
This file contains functions required to generate a Firmware File System
file. The code is compliant with the Tiano C Coding standards.
--*/
#include "GenCRC32Section.h"
#define TOOLVERSION "0.2"
#define UTILITY_NAME "GenCrc32Section"
EFI_GUID gEfiCrc32SectionGuid = EFI_CRC32_GUIDED_SECTION_EXTRACTION_PROTOCOL_GUID;
EFI_STATUS
SignSectionWithCrc32 (
IN OUT UINT8 *FileBuffer,
IN OUT UINT32 *BufferSize,
IN UINT32 DataSize
)
/*++
Routine Description:
Signs the section with CRC32 and add GUIDed section header for the
signed data. data stays in same location (overwrites source data).
Arguments:
FileBuffer - Buffer containing data to sign
BufferSize - On input, the size of FileBuffer. On output, the size of
actual section data (including added section header).
DataSize - Length of data to Sign
Key - Key to use when signing. Currently only CRC32 is supported.
Returns:
EFI_SUCCESS - Successful
EFI_OUT_OF_RESOURCES - Not enough resource to complete the operation.
--*/
{
UINT32 Crc32Checksum;
EFI_STATUS Status;
UINT32 TotalSize;
CRC32_SECTION_HEADER Crc32Header;
UINT8 *SwapBuffer;
Crc32Checksum = 0;
SwapBuffer = NULL;
if (DataSize == 0) {
*BufferSize = 0;
return EFI_SUCCESS;
}
Status = CalculateCrc32 (FileBuffer, DataSize, &Crc32Checksum);
if (EFI_ERROR (Status)) {
return Status;
}
TotalSize = DataSize + CRC32_SECTION_HEADER_SIZE;
Crc32Header.GuidSectionHeader.CommonHeader.Type = EFI_SECTION_GUID_DEFINED;
Crc32Header.GuidSectionHeader.CommonHeader.Size[0] = (UINT8) (TotalSize & 0xff);
Crc32Header.GuidSectionHeader.CommonHeader.Size[1] = (UINT8) ((TotalSize & 0xff00) >> 8);
Crc32Header.GuidSectionHeader.CommonHeader.Size[2] = (UINT8) ((TotalSize & 0xff0000) >> 16);
memcpy (&(Crc32Header.GuidSectionHeader.SectionDefinitionGuid), &gEfiCrc32SectionGuid, sizeof (EFI_GUID));
Crc32Header.GuidSectionHeader.Attributes = EFI_GUIDED_SECTION_AUTH_STATUS_VALID;
Crc32Header.GuidSectionHeader.DataOffset = CRC32_SECTION_HEADER_SIZE;
Crc32Header.CRC32Checksum = Crc32Checksum;
SwapBuffer = (UINT8 *) malloc (DataSize);
if (SwapBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
memcpy (SwapBuffer, FileBuffer, DataSize);
memcpy (FileBuffer, &Crc32Header, CRC32_SECTION_HEADER_SIZE);
memcpy (FileBuffer + CRC32_SECTION_HEADER_SIZE, SwapBuffer, DataSize);
//
// Make sure section ends on a DWORD boundary
//
while ((TotalSize & 0x03) != 0) {
FileBuffer[TotalSize] = 0;
TotalSize++;
}
*BufferSize = TotalSize;
if (SwapBuffer != NULL) {
free (SwapBuffer);
}
return EFI_SUCCESS;
}
VOID
PrintUsage (
VOID
)
{
printf ("Usage:\n");
printf (UTILITY_NAME " -i \"inputfile1\" \"inputfile2\" -o \"outputfile\" \n");
printf (" -i \"inputfile\":\n ");
printf (" specifies the input files that would be signed to CRC32 Guided section.\n");
printf (" -o \"outputfile\":\n");
printf (" specifies the output file that is a CRC32 Guided section.\n");
}
INT32
ReadFilesContentsIntoBuffer (
IN CHAR8 *argv[],
IN INT32 Start,
IN OUT UINT8 **FileBuffer,
IN OUT UINT32 *BufferSize,
OUT UINT32 *ContentSize,
IN INT32 MaximumArguments
)
{
INT32 Index;
CHAR8 *FileName;
FILE *InputFile;
UINT8 Temp;
UINT32 Size;
FileName = NULL;
InputFile = NULL;
Size = 0;
Index = 0;
//
// read all input files into one file buffer
//
while (argv[Start + Index][0] != '-') {
FileName = argv[Start + Index];
InputFile = fopen (FileName, "rb");
if (InputFile == NULL) {
Error (NULL, 0, 0, FileName, "failed to open input binary file");
return -1;
}
fread (&Temp, sizeof (UINT8), 1, InputFile);
while (!feof (InputFile)) {
(*FileBuffer)[Size++] = Temp;
fread (&Temp, sizeof (UINT8), 1, InputFile);
}
fclose (InputFile);
InputFile = NULL;
//
// Make sure section ends on a DWORD boundary
//
while ((Size & 0x03) != 0) {
(*FileBuffer)[Size] = 0;
Size++;
}
Index++;
if (Index == MaximumArguments) {
break;
}
}
*ContentSize = Size;
return Index;
}
int
main (
INT32 argc,
CHAR8 *argv[]
)
{
FILE *OutputFile;
UINT8 *FileBuffer;
UINT32 BufferSize;
EFI_STATUS Status;
UINT32 ContentSize;
CHAR8 *OutputFileName;
INT32 ReturnValue;
INT32 Index;
OutputFile = NULL;
FileBuffer = NULL;
ContentSize = 0;
OutputFileName = NULL;
SetUtilityName (UTILITY_NAME);
if (argc == 1) {
PrintUsage ();
return -1;
}
BufferSize = 1024 * 1024 * 16;
FileBuffer = (UINT8 *) malloc (BufferSize * sizeof (UINT8));
if (FileBuffer == NULL) {
Error (NULL, 0, 0, "memory allocation failed", NULL);
return -1;
}
ZeroMem (FileBuffer, BufferSize);
for (Index = 0; Index < argc; Index++) {
if (strcmpi (argv[Index], "-i") == 0) {
ReturnValue = ReadFilesContentsIntoBuffer (
argv,
(Index + 1),
&FileBuffer,
&BufferSize,
&ContentSize,
(argc - (Index + 1))
);
if (ReturnValue == -1) {
Error (NULL, 0, 0, "failed to read file contents", NULL);
return -1;
}
Index += ReturnValue;
}
if (strcmpi (argv[Index], "-o") == 0) {
OutputFileName = argv[Index + 1];
}
}
OutputFile = fopen (OutputFileName, "wb");
if (OutputFile == NULL) {
Error (NULL, 0, 0, OutputFileName, "failed to open output binary file");
free (FileBuffer);
return -1;
}
/*
//
// make sure section ends on a DWORD boundary ??
//
while ( (Size & 0x03) != 0 ) {
FileBuffer[Size] = 0;
Size ++;
}
*/
Status = SignSectionWithCrc32 (FileBuffer, &BufferSize, ContentSize);
if (EFI_ERROR (Status)) {
Error (NULL, 0, 0, "failed to sign section", NULL);
free (FileBuffer);
fclose (OutputFile);
return -1;
}
ContentSize = fwrite (FileBuffer, sizeof (UINT8), BufferSize, OutputFile);
if (ContentSize != BufferSize) {
Error (NULL, 0, 0, "failed to write output buffer", NULL);
ReturnValue = -1;
} else {
ReturnValue = 0;
}
free (FileBuffer);
fclose (OutputFile);
return ReturnValue;
}

View File

@@ -0,0 +1,64 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenCRC32Section.h
Abstract:
Header file for GenFfsFile. Mainly defines the header of section
header for CRC32 GUID defined sections. Share with GenSection.c
--*/
//
// External Files Referenced
//
/* Standard Headers */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
/* MDE Headers */
#include <Base.h>
#include <UefiBaseTypes.h>
#include <Common/EfiImage.h>
#include <Common/FirmwareVolumeImageFormat.h>
#include <Common/FirmwareFileSystem.h>
#include <Common/FirmwareVolumeHeader.h>
#include <Protocol/GuidedSectionExtraction.h>
/* Tool Headers */
#include <CommonLib.h>
#include <Crc32.h>
#include <EfiCompress.h>
#include <EfiUtilityMsgs.h>
#include <ParseInf.h>
//
// Module Coded to Tiano Coding Conventions
//
#ifndef _EFI_GEN_CRC32_SECTION_H
#define _EFI_GEN_CRC32_SECTION_H
typedef struct {
EFI_GUID_DEFINED_SECTION GuidSectionHeader;
UINT32 CRC32Checksum;
} CRC32_SECTION_HEADER;
#define EFI_SECTION_CRC32_GUID_DEFINED 0
#define CRC32_SECTION_HEADER_SIZE (sizeof (CRC32_SECTION_HEADER))
#endif

View File

@@ -0,0 +1 @@
gcc -mno-cygwin -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ *.c -o GenCRC32Section -L../Library-mingw -lCommon

View File

@@ -0,0 +1,127 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenCRC32Section Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenCRC32Section"/>
<property name="FileSet" value="GenCRC32Section.c GenCRC32Section.h"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="Building the EDK Tool: ${ToolName}"/>
</target>
<target name="init">
<echo message="The EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>
Unsupported Operating System
Please Contact Intel Corporation
</echo>
</else>
</if>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
<property name="ext_exe" value=".exe"/>
<property name="MSVC_DIR" value="C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\Include" />
<property name="MSVC_SDK_DIR" value="C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include" />
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
<property name="ext_exe" value=""/>
</then>
</elseif>
</if>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools${ext_static}"/>
</cc>
<if>
<os family="dos"/>
<then>
<exec dir="${BUILD_DIR}" executable="lib" failonerror="false">
<arg line="/NOLOGO *.lib /OUT:${LIB_DIR}/${ToolName}${ext_exe}"/>
</exec>
</then>
</if>
</target>
<target name="clean" depends="init">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall" depends="init">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete dir="${BUILD_DIR}">
<fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,903 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
DepexParser.c
Abstract:
Validate Dependency Expression syntax
recursive descent Algorithm
The original BNF grammar(taken from "Pre EFI Initialization Core Interface Specification
draft review 0.9") is thus:
<depex> ::= BEFORE <guid> END
| AFTER <guid> END
| SOR <bool> END
| <bool> END
<bool> ::= <bool> AND <term>
| <bool> OR <term>
| <term>
<term> ::= NOT <factor>
| <factor>
<factor> ::= <bool>
| TRUE
| FALSE
| GUID
<guid> ::= '{' <hex32> ',' <hex16> ',' <hex16> ','
<hex8> ',' <hex8> ',' <hex8> ',' <hex8> ','
<hex8> ',' <hex8> ',' <hex8> ',' <hex8> '}'
<hex32> ::= <hexprefix> <hexvalue>
<hex16> ::= <hexprefix> <hexvalue>
<hex8> ::= <hexprefix> <hexvalue>
<hexprefix>::= '0' 'x'
| '0' 'X'
<hexvalue> ::= <hexdigit> <hexvalue>
| <hexdigit>
<hexdigit> ::= [0-9]
| [a-f]
| [A-F]
After cleaning left recursive and parentheses supported, the BNF grammar used in this module is thus:
<depex> ::= BEFORE <guid>
| AFTER <guid>
| SOR <bool>
| <bool>
<bool> ::= <term><rightbool>
<rightbool>::= AND <term><rightbool>
| OR <term><rightbool>
| ''
<term> ::= NOT <factor>
| <factor>
<factor> ::= '('<bool>')'<rightfactor>
| NOT <factor> <rightbool> <rightfactor>
| TRUE <rightfactor>
| FALSE <rightfactor>
| END <rightfactor>
| <guid> <rightfactor>
<rightfactor> ::=AND <term><rightbool> <rightfactor>
| OR <term><rightbool> <rightfactor>
| ''
<guid> ::= '{' <hex32> ',' <hex16> ',' <hex16> ','
<hex8> ',' <hex8> ',' <hex8> ',' <hex8> ','
<hex8> ',' <hex8> ',' <hex8> ',' <hex8> '}'
<hex32> ::= <hexprefix> <hexvalue>
<hex16> ::= <hexprefix> <hexvalue>
<hex8> ::= <hexprefix> <hexvalue>
<hexprefix>::= '0' 'x'
| '0' 'X'
<hexvalue> ::= <hexdigit> <hexvalue>
| <hexdigit>
<hexdigit> ::= [0-9]
| [a-f]
| [A-F]
Note: 1. There's no precedence in operators except parentheses;
2. For hex32, less and equal than 8 bits is valid, more than 8 bits is invalid.
Same constraint for hex16 is 4, hex8 is 2. All hex should contains at least 1 bit.
3. "<factor> ::= '('<bool>')'<rightfactor>" is added to support parentheses;
4. "<factor> ::= GUID" is changed to "<factor> ::= <guid>";
5. "DEPENDENCY_END" is the terminal of the expression. But it has been filtered by caller.
During parsing, "DEPENDENCY_END" will be treated as illegal factor;
This code should build in any environment that supports a standard C-library w/ string
operations and File I/O services.
As an example of usage, consider the following:
The input string could be something like:
NOT ({ 0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72,
0x3b } AND { 0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69,
0x72, 0x3b }) OR { 0x03c4e603, 0xac28, 0x11d3, 0x9a, 0x2d, 0x00, 0x90, 0x27,
0x3f, 0xc1, 0x4d } AND
It's invalid for an extra "AND" in the end.
Complies with Tiano C Coding Standards Document, version 0.33, 16 Aug 2001.
--*/
#include "DepexParser.h"
BOOLEAN
ParseBool (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
);
BOOLEAN
ParseTerm (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
);
BOOLEAN
ParseRightBool (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
);
BOOLEAN
ParseFactor (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
);
VOID
LeftTrim (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Left trim the space, '\n' and '\r' character in string.
The space at the end does not need trim.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
None
--*/
{
while
(
((*Pindex) < (Pbegin + length)) &&
((strncmp (*Pindex, " ", 1) == 0) || (strncmp (*Pindex, "\n", 1) == 0) || (strncmp (*Pindex, "\r", 1) == 0))
) {
(*Pindex)++;
}
}
BOOLEAN
ParseHexdigit (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse Hex bit in dependency expression.
Arguments:
Pbegin The pointer to the string
length Length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If parses a valid hex bit, return TRUE, otherwise FALSE
--*/
{
//
// <hexdigit> ::= [0-9] | [a-f] | [A-F]
//
if (((**Pindex) >= '0' && (**Pindex) <= '9') ||
((**Pindex) >= 'a' && (**Pindex) <= 'f') ||
((**Pindex) >= 'A' && (**Pindex) <= 'F')
) {
(*Pindex)++;
return TRUE;
} else {
return FALSE;
}
}
BOOLEAN
ParseHex32 (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse Hex32 in dependency expression.
Arguments:
Pbegin The pointer to the string
length Length of the string
Pindex The pointer of point to the next parse character in the string
Returns:
BOOLEAN If parses a valid hex32, return TRUE, otherwise FALSE
--*/
{
INT32 Index;
INT8 *Pin;
Index = 0;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if ((strncmp (*Pindex, "0x", 2) != 0) && (strncmp (*Pindex, "0X", 2) != 0)) {
return FALSE;
}
(*Pindex) += 2;
while (ParseHexdigit (Pbegin, length, Pindex)) {
Index++;
}
if (Index > 0 && Index <= 8) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseHex16 (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse Hex16 in dependency expression.
Arguments:
Pbegin The pointer to the string
length Length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If parses a valid hex16, return TRUE, otherwise FALSE
--*/
{
int Index;
INT8 *Pin;
Index = 0;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if ((strncmp (*Pindex, "0x", 2) != 0) && (strncmp (*Pindex, "0X", 2) != 0)) {
return FALSE;
}
(*Pindex) += 2;
while (ParseHexdigit (Pbegin, length, Pindex)) {
Index++;
}
if (Index > 0 && Index <= 4) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseHex8 (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse Hex8 in dependency expression.
Arguments:
Pbegin The pointer to the string
length Length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If parses a valid hex8, return TRUE, otherwise FALSE
--*/
{
int Index;
INT8 *Pin;
Index = 0;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if ((strncmp (*Pindex, "0x", 2) != 0) && (strncmp (*Pindex, "0X", 2) != 0)) {
return FALSE;
}
(*Pindex) += 2;
while (ParseHexdigit (Pbegin, length, Pindex)) {
Index++;
}
if (Index > 0 && Index <= 2) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseGuid (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse guid in dependency expression.
There can be any number of spaces between '{' and hexword, ',' and hexword,
hexword and ',', hexword and '}'. The hexword include hex32, hex16 and hex8.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If parses a valid guid, return TRUE, otherwise FALSE
--*/
{
INT32 Index;
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, "{", 1) != 0) {
return FALSE;
}
(*Pindex)++;
LeftTrim (Pbegin, length, Pindex);
if (!ParseHex32 (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, ",", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
for (Index = 0; Index < 2; Index++) {
LeftTrim (Pbegin, length, Pindex);
if (!ParseHex16 (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, ",", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, "{", 1) != 0) {
return FALSE;
}
(*Pindex)++;
for (Index = 0; Index < 7; Index++) {
LeftTrim (Pbegin, length, Pindex);
if (!ParseHex8 (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, ",", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
}
LeftTrim (Pbegin, length, Pindex);
if (!ParseHex8 (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, "}", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, "}", 1) != 0) {
return FALSE;
} else {
(*Pindex)++;
}
return TRUE;
}
BOOLEAN
ParseRightFactor (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse rightfactor in bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid rightfactor expression, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
//
// <rightfactor> ::=AND <term> <rightbool> <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_AND, strlen (OPERATOR_AND)) == 0) {
*Pindex += strlen (OPERATOR_AND);
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <rightfactor> ::=OR <term> <rightbool> <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_OR, strlen (OPERATOR_OR)) == 0) {
*Pindex += strlen (OPERATOR_OR);
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <rightfactor> ::= ''
//
*Pindex = Pin;
return TRUE;
}
BOOLEAN
ParseRightBool (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse rightbool in bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid rightbool expression, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
//
// <rightbool>::= AND <term><rightbool>
//
if (strncmp (*Pindex, OPERATOR_AND, strlen (OPERATOR_AND)) == 0) {
*Pindex += strlen (OPERATOR_AND);
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <rightbool>::= OR <term><rightbool>
//
if (strncmp (*Pindex, OPERATOR_OR, strlen (OPERATOR_OR)) == 0) {
*Pindex += strlen (OPERATOR_OR);
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <rightbool>::= ''
//
*Pindex = Pin;
return TRUE;
}
BOOLEAN
ParseFactor (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse factor in bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid factor, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
//
// <factor> ::= '('<bool>')'<rightfactor>
//
if (strncmp (*Pindex, OPERATOR_LEFT_PARENTHESIS, strlen (OPERATOR_LEFT_PARENTHESIS)) == 0) {
*Pindex += strlen (OPERATOR_LEFT_PARENTHESIS);
LeftTrim (Pbegin, length, Pindex);
if (!ParseBool (Pbegin, length, Pindex)) {
*Pindex = Pin;
} else {
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, OPERATOR_RIGHT_PARENTHESIS, strlen (OPERATOR_RIGHT_PARENTHESIS)) == 0) {
*Pindex += strlen (OPERATOR_RIGHT_PARENTHESIS);
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
}
}
}
//
// <factor> ::= NOT <factor> <rightbool> <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_NOT, strlen (OPERATOR_NOT)) == 0) {
*Pindex += strlen (OPERATOR_NOT);
LeftTrim (Pbegin, length, Pindex);
if (ParseFactor (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightBool (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
} else {
*Pindex = Pin;
}
}
//
// <factor> ::= TRUE <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_TRUE, strlen (OPERATOR_TRUE)) == 0) {
*Pindex += strlen (OPERATOR_TRUE);
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
}
//
// <factor> ::= FALSE <rightfactor>
//
if (strncmp (*Pindex, OPERATOR_FALSE, strlen (OPERATOR_FALSE)) == 0) {
*Pindex += strlen (OPERATOR_FALSE);
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
}
}
//
// <factor> ::= <guid> <rightfactor>
//
if (ParseGuid (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (ParseRightFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseTerm (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse term in bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid term, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
//
// <term> ::= NOT <factor>
//
if (strncmp (*Pindex, OPERATOR_NOT, strlen (OPERATOR_NOT)) == 0) {
*Pindex += strlen (OPERATOR_NOT);
LeftTrim (Pbegin, length, Pindex);
if (!ParseFactor (Pbegin, length, Pindex)) {
*Pindex = Pin;
} else {
return TRUE;
}
}
//
// <term> ::=<factor>
//
if (ParseFactor (Pbegin, length, Pindex)) {
return TRUE;
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseBool (
IN INT8 *Pbegin,
IN UINT32 length,
IN OUT INT8 **Pindex
)
/*++
Routine Description:
Parse bool expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Pindex The pointer of pointer to the next parse character in the string
Returns:
BOOLEAN If string is a valid bool expression, return TRUE, otherwise FALSE
--*/
{
INT8 *Pin;
Pin = *Pindex;
LeftTrim (Pbegin, length, Pindex);
if (ParseTerm (Pbegin, length, Pindex)) {
LeftTrim (Pbegin, length, Pindex);
if (!ParseRightBool (Pbegin, length, Pindex)) {
*Pindex = Pin;
return FALSE;
} else {
return TRUE;
}
} else {
*Pindex = Pin;
return FALSE;
}
}
BOOLEAN
ParseDepex (
IN INT8 *Pbegin,
IN UINT32 length
)
/*++
Routine Description:
Parse whole dependency expression.
Arguments:
Pbegin The pointer to the string
length length of the string
Returns:
BOOLEAN If string is a valid dependency expression, return TRUE, otherwise FALSE
--*/
{
BOOLEAN Result;
INT8 **Pindex;
INT8 *temp;
Result = FALSE;
temp = Pbegin;
Pindex = &temp;
LeftTrim (Pbegin, length, Pindex);
if (strncmp (*Pindex, OPERATOR_BEFORE, strlen (OPERATOR_BEFORE)) == 0) {
(*Pindex) += strlen (OPERATOR_BEFORE);
Result = ParseGuid (Pbegin, length, Pindex);
} else if (strncmp (*Pindex, OPERATOR_AFTER, strlen (OPERATOR_AFTER)) == 0) {
(*Pindex) += strlen (OPERATOR_AFTER);
Result = ParseGuid (Pbegin, length, Pindex);
} else if (strncmp (*Pindex, OPERATOR_SOR, strlen (OPERATOR_SOR)) == 0) {
(*Pindex) += strlen (OPERATOR_SOR);
Result = ParseBool (Pbegin, length, Pindex);
} else {
Result = ParseBool (Pbegin, length, Pindex);
}
LeftTrim (Pbegin, length, Pindex);
return (BOOLEAN) (Result && (*Pindex) >= (Pbegin + length));
}

View File

@@ -0,0 +1,26 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenDepex.h
Abstract:
This file contains the relevant declarations required
to generate a binary Dependency File
Complies with Tiano C Coding Standards Document, version 0.31, 12 Dec 2000.
--*/
// TODO: fix comment to set correct module name: DepexParser.h
#ifndef _EFI_DEPEX_PARSER_H_
#define _EFI_DEPEX_PARSER_H_
#include "GenDepex.h"
#endif

View File

@@ -0,0 +1,916 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenDepex.c
Abstract:
Generate Dependency Expression ("GenDepex")
Infix to Postfix Algorithm
This code has been scrubbed to be free of having any EFI core tree dependencies.
It should build in any environment that supports a standard C-library w/ string
operations and File I/O services.
As an example of usage, consider the following:
The input user file could be something like "Sample.DXS" whose contents are
#include "Tiano.h"
DEPENDENCY_START
NOT (DISK_IO_PROTOCOL AND SIMPLE_FILE_SYSTEM_PROTOCOL)
OR EFI_PXE_BASE_CODE_PROTOCOL
DEPENDENCY_END
This file is then washed through the C-preprocessor, viz.,
cl /EP Sample.DXS > Sample.TMP1
This yields the following file "Sample.TMP1" whose contents are
DEPENDENCY_START
NOT ({ 0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, 0x0, 0xa0, 0xc9, 0x69, 0x72,
0x3b } AND { 0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69,
0x72, 0x3b }) OR { 0x03c4e603, 0xac28, 0x11d3, 0x9a, 0x2d, 0x00, 0x90, 0x27,
0x3f, 0xc1, 0x4d }
DEPENDENCY_END
This file, in turn, will be fed into the utility, viz.,
GenDepex Sample.TMP1 Sample.TMP2
With a file that is 55 bytes long:
55 bytes for the grammar binary
PUSH opcode - 1 byte
GUID Instance - 16 bytes
PUSH opcode - 1 byte
GUID Instance - 16 bytes
AND opcode - 1 byte
NOT opcode - 1 byte
PUSH opcode - 1 byte
GUID Instance - 16 bytes
OR opcode - 1 byte
END opcode - 1 byte
The file "Sample.TMP2" could be fed via a Section-builder utility
(GenSection) that would be used for the creation of a dependency
section file (.DPX) which in turn would be used by a generate FFS
utility (GenFfsFile) to produce a DXE driver/core (.DXE) or
a DXE application (.APP) file.
Complies with Tiano C Coding Standards Document, version 0.31, 12 Dec 2000.
--*/
#include "GenDepex.h"
#define TOOL_NAME "GenDepex"
extern
ParseDepex (
IN INT8 *Pbegin,
IN UINT32 length
);
VOID
PrintGenDepexUtilityInfo (
VOID
)
/*++
Routine Description:
Displays the standard utility information to SDTOUT.
Arguments:
None
Returns:
None
--*/
{
printf (
"%s, Tiano Dependency Expression Generation Utility. Version %d.%d.\n",
UTILITY_NAME,
UTILITY_MAJOR_VERSION,
UTILITY_MINOR_VERSION
);
printf ("Copyright (C) 1996-2002 Intel Corporation. All rights reserved.\n\n");
}
VOID
PrintGenDepexUsageInfo (
VOID
)
/*++
Routine Description:
Displays the utility usage syntax to STDOUT.
Arguments:
None
Returns:
None
--*/
{
printf (
"Usage: %s -I <INFILE> -O <OUTFILE> [-P <Optional Boundary for padding up>] \n",
UTILITY_NAME
);
printf (" Where:\n");
printf (" <INFILE> is the input pre-processed dependency text files name.\n");
printf (" <OUTFILE> is the output binary dependency files name.\n");
printf (" <Optional Boundary for padding up> is the padding integer value.\n");
printf (" This is the boundary to align the output file size to.\n");
}
DEPENDENCY_OPCODE
PopOpCode (
IN OUT VOID **Stack
)
/*++
Routine Description:
Pop an element from the Opcode stack.
Arguments:
Stack Current top of the OpCode stack location
Returns:
DEPENDENCY_OPCODE OpCode at the top of the OpCode stack.
Stack New top of the OpCode stack location
--*/
{
DEPENDENCY_OPCODE *OpCodePtr;
OpCodePtr = *Stack;
OpCodePtr--;
*Stack = OpCodePtr;
return *OpCodePtr;
}
VOID
PushOpCode (
IN OUT VOID **Stack,
IN DEPENDENCY_OPCODE OpCode
)
/*++
Routine Description:
Push an element onto the Opcode Stack
Arguments:
Stack Current top of the OpCode stack location
OpCode OpCode to push onto the stack
Returns:
Stack New top of the OpCode stack location
--*/
{
DEPENDENCY_OPCODE *OpCodePtr;
OpCodePtr = *Stack;
*OpCodePtr = OpCode;
OpCodePtr++;
*Stack = OpCodePtr;
}
EFI_STATUS
GenerateDependencyExpression (
IN FILE *InFile,
IN OUT FILE *OutFile,
IN UINT8 Padding OPTIONAL
)
/*++
Routine Description:
This takes the pre-compiled dependency text file and
converts it into a binary dependency file.
The BNF for the dependency expression is as follows
(from the DXE 1.0 Draft specification).
The inputted BNF grammar is thus:
<depex> ::= sor <dep> |
before GUID <dep> |
after GUID <dep> |
<bool>
<dep> ::= <bool> |
<bool> ::= <bool> and <term> |
<bool> or <term> |
<term>
<term> ::= not <factor> |
<factor>
<factor> ::= ( <bool> ) |
<term> <term> |
GUID |
<boolval>
<boolval> ::= true |
false
The outputed binary grammer is thus:
<depex> ::= sor <dep> |
before <depinst> <dep> |
after <depinst> <dep> |
<bool>
<dep> ::= <bool> |
<bool> ::= <bool> and <term> |
<bool> or <term> | <term>
<term> ::= not <factor> |
<factor>
<factor> ::= ( <bool> ) |
<term> <term> |
<boolval> |
<depinst> |
<termval>
<boolval> ::= true |
false
<depinst> ::= push GUID
<termval> ::= end
BugBug: A correct grammer is parsed correctly. A file that violates the
grammer may parse when it should generate an error. There is some
error checking and it covers most of the case when it's an include
of definition issue. An ill formed expresion may not be detected.
Arguments:
InFile - Input pre-compiled text file of the dependency expression.
This needs to be in ASCII.
The file pointer can not be NULL.
OutFile - Binary dependency file.
The file pointer can not be NULL.
Padding - OPTIONAL integer value to pad the output file to.
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the parameters in the text file was invalid.
EFI_OUT_OF_RESOURCES Unable to allocate memory.
EFI_ABORTED An misc error occurred.
--*/
{
INT8 *Ptrx;
INT8 *Pend;
INT8 *EvaluationStack;
INT8 *StackPtr;
INT8 *Buffer;
INT8 Line[LINESIZE];
UINTN Index;
UINTN OutFileSize;
UINTN FileSize;
UINTN Results;
BOOLEAN NotDone;
BOOLEAN Before_Flag;
BOOLEAN After_Flag;
BOOLEAN Dep_Flag;
BOOLEAN SOR_Flag;
EFI_GUID Guid;
UINTN ArgCountParsed;
DEPENDENCY_OPCODE Opcode;
Before_Flag = FALSE;
After_Flag = FALSE;
Dep_Flag = FALSE;
SOR_Flag = FALSE;
memset (Line, 0, LINESIZE);
OutFileSize = 0;
EvaluationStack = (INT8 *) malloc (EVAL_STACK_SIZE);
if (EvaluationStack != NULL) {
StackPtr = EvaluationStack;
} else {
printf ("Unable to allocate memory to EvaluationStack - Out of resources\n");
return EFI_OUT_OF_RESOURCES;
}
Results = (UINTN) fseek (InFile, 0, SEEK_END);
if (Results != 0) {
printf ("FSEEK failed - Aborted\n");
return EFI_ABORTED;
}
FileSize = ftell (InFile);
if (FileSize == -1L) {
printf ("FTELL failed - Aborted\n");
return EFI_ABORTED;
}
Buffer = (INT8 *) malloc (FileSize + BUFFER_SIZE);
if (Buffer == NULL) {
printf ("Unable to allocate memory to Buffer - Out of resources\n");
free (EvaluationStack);
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
return EFI_OUT_OF_RESOURCES;
}
Results = (UINTN) fseek (InFile, 0, SEEK_SET);
if (Results != 0) {
printf ("FSEEK failed - Aborted\n");
return EFI_ABORTED;
}
fread (Buffer, FileSize, 1, InFile);
Ptrx = Buffer;
Pend = Ptrx + FileSize - strlen (DEPENDENCY_END);
Index = FileSize;
NotDone = TRUE;
while ((Index--) && NotDone) {
if (strncmp (Pend, DEPENDENCY_END, strlen (DEPENDENCY_END)) == 0) {
NotDone = FALSE;
} else {
Pend--;
}
}
if (NotDone) {
printf ("Couldn't find end string %s\n", DEPENDENCY_END);
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
free (Buffer);
free (EvaluationStack);
return EFI_INVALID_PARAMETER;
}
Index = FileSize;
NotDone = TRUE;
while ((Index--) && NotDone) {
if (strncmp (Ptrx, DEPENDENCY_START, strlen (DEPENDENCY_START)) == 0) {
Ptrx += sizeof (DEPENDENCY_START);
NotDone = FALSE;
//
// BUGBUG -- should Index be decremented by sizeof(DEPENDENCY_START)?
//
} else {
Ptrx++;
}
}
if (NotDone) {
printf ("Couldn't find start string %s\n", DEPENDENCY_START);
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
free (Buffer);
free (EvaluationStack);
return EFI_INVALID_PARAMETER;
}
//
// validate the syntax of expression
//
if (!ParseDepex (Ptrx, Pend - Ptrx - 1)) {
printf ("The syntax of expression is wrong\n");
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
free (Buffer);
free (EvaluationStack);
return EFI_INVALID_PARAMETER;
}
NotDone = TRUE;
while ((Index--) && NotDone) {
if (*Ptrx == ' ') {
Ptrx++;
} else if (*Ptrx == '\n' || *Ptrx == '\r') {
Ptrx++;
} else if (strncmp (Ptrx, OPERATOR_SOR, strlen (OPERATOR_SOR)) == 0) {
//
// Checks for some invalid dependencies
//
if (Before_Flag) {
printf ("A BEFORE operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (After_Flag) {
printf ("An AFTER operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (SOR_Flag) {
printf ("Another SOR operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (Dep_Flag) {
printf ("The Schedule On Request - SOR operator must be the first operator following DEPENDENCY_START\n");
return EFI_INVALID_PARAMETER;
} else {
//
// BUGBUG - This was not in the spec but is in the CORE code
// An OPERATOR_SOR has to be first - following the DEPENDENCY_START
//
fputc (EFI_DEP_SOR, OutFile);
OutFileSize++;
Ptrx += sizeof (OPERATOR_SOR);
SOR_Flag = TRUE;
}
} else if (strncmp (Ptrx, OPERATOR_BEFORE, strlen (OPERATOR_BEFORE)) == 0) {
//
// Checks for some invalid dependencies
//
if (Before_Flag) {
printf ("Another BEFORE operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (After_Flag) {
printf ("An AFTER operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (SOR_Flag) {
printf ("A SOR operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (Dep_Flag) {
printf ("The BEFORE operator must be the first operator following DEPENDENCY_START\n");
return EFI_INVALID_PARAMETER;
} else {
fputc (EFI_DEP_BEFORE, OutFile);
OutFileSize++;
Ptrx += sizeof (OPERATOR_BEFORE);
Before_Flag = TRUE;
}
} else if (strncmp (Ptrx, OPERATOR_AFTER, strlen (OPERATOR_AFTER)) == 0) {
//
// Checks for some invalid dependencies
//
if (Before_Flag) {
printf ("A BEFORE operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (After_Flag) {
printf ("Another AFTER operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (SOR_Flag) {
printf ("A SOR operator was detected.\n");
printf ("There can only be one SOR or one AFTER or one BEFORE operator\n");
return EFI_INVALID_PARAMETER;
} else if (Dep_Flag) {
printf ("The AFTER operator must be the first operator following DEPENDENCY_START\n");
return EFI_INVALID_PARAMETER;
} else {
fputc (EFI_DEP_AFTER, OutFile);
OutFileSize++;
Ptrx += sizeof (OPERATOR_AFTER);
Dep_Flag = TRUE;
After_Flag = TRUE;
}
} else if (strncmp (Ptrx, OPERATOR_AND, strlen (OPERATOR_AND)) == 0) {
while (StackPtr != EvaluationStack) {
Opcode = PopOpCode ((VOID **) &StackPtr);
if (Opcode != DXE_DEP_LEFT_PARENTHESIS) {
fputc (Opcode, OutFile);
OutFileSize++;
} else {
PushOpCode ((VOID **) &StackPtr, DXE_DEP_LEFT_PARENTHESIS);
break;
}
}
PushOpCode ((VOID **) &StackPtr, EFI_DEP_AND);
Ptrx += sizeof (OPERATOR_AND);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, OPERATOR_OR, strlen (OPERATOR_OR)) == 0) {
while (StackPtr != EvaluationStack) {
Opcode = PopOpCode ((VOID **) &StackPtr);
if (Opcode != DXE_DEP_LEFT_PARENTHESIS) {
fputc (Opcode, OutFile);
OutFileSize++;
} else {
PushOpCode ((VOID **) &StackPtr, DXE_DEP_LEFT_PARENTHESIS);
break;
}
}
PushOpCode ((VOID **) &StackPtr, EFI_DEP_OR);
Ptrx += sizeof (OPERATOR_OR);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, OPERATOR_NOT, strlen (OPERATOR_NOT)) == 0) {
while (StackPtr != EvaluationStack) {
Opcode = PopOpCode ((VOID **) &StackPtr);
if (Opcode != DXE_DEP_LEFT_PARENTHESIS) {
fputc (Opcode, OutFile);
OutFileSize++;
} else {
PushOpCode ((VOID **) &StackPtr, DXE_DEP_LEFT_PARENTHESIS);
break;
}
}
PushOpCode ((VOID **) &StackPtr, EFI_DEP_NOT);
Ptrx += sizeof (OPERATOR_NOT);
Dep_Flag = TRUE;
} else if (*Ptrx == '\t') {
printf ("File contains tabs. This violates the coding standard\n");
return EFI_INVALID_PARAMETER;
} else if (*Ptrx == '\n') {
//
// Skip the newline character in the file
//
Ptrx++;
} else if (strncmp (Ptrx, OPERATOR_LEFT_PARENTHESIS, strlen (OPERATOR_LEFT_PARENTHESIS)) == 0) {
PushOpCode ((VOID **) &StackPtr, DXE_DEP_LEFT_PARENTHESIS);
Ptrx += strlen (OPERATOR_LEFT_PARENTHESIS);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, OPERATOR_RIGHT_PARENTHESIS, strlen (OPERATOR_RIGHT_PARENTHESIS)) == 0) {
while (StackPtr != EvaluationStack) {
Opcode = PopOpCode ((VOID **) &StackPtr);
if (Opcode != DXE_DEP_LEFT_PARENTHESIS) {
fputc (Opcode, OutFile);
OutFileSize++;
} else {
break;
}
}
Ptrx += strlen (OPERATOR_RIGHT_PARENTHESIS);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, OPERATOR_TRUE, strlen (OPERATOR_TRUE)) == 0) {
fputc (EFI_DEP_TRUE, OutFile);
OutFileSize++;
//
// OutFileSize += sizeof (EFI_DEP_TRUE);
//
Dep_Flag = TRUE;
Ptrx += strlen (OPERATOR_TRUE);
} else if (strncmp (Ptrx, OPERATOR_FALSE, strlen (OPERATOR_FALSE)) == 0) {
fputc (EFI_DEP_FALSE, OutFile);
OutFileSize++;
//
// OutFileSize += sizeof (EFI_DEP_FALSE);
//
Dep_Flag = TRUE;
Ptrx += strlen (OPERATOR_FALSE);
} else if (*Ptrx == '{') {
Ptrx++;
if (*Ptrx == ' ') {
Ptrx++;
}
ArgCountParsed = sscanf (
Ptrx,
"%x, %x, %x, { %x, %x, %x, %x, %x, %x, %x, %x }",
&Guid.Data1,
&Guid.Data2,
&Guid.Data3,
&Guid.Data4[0],
&Guid.Data4[1],
&Guid.Data4[2],
&Guid.Data4[3],
&Guid.Data4[4],
&Guid.Data4[5],
&Guid.Data4[6],
&Guid.Data4[7]
);
if (ArgCountParsed != 11) {
printf ("We have found an illegal GUID\n");
printf ("Fix your depex\n");
exit (-1);
}
while (*Ptrx != '}') {
Ptrx++;
}
Ptrx++;
while (*Ptrx != '}') {
Ptrx++;
}
//
// Absorb the closing }
//
Ptrx++;
//
// Don't provide a PUSH Opcode for the Before and After case
//
if ((!Before_Flag) && (!After_Flag)) {
fputc (EFI_DEP_PUSH, OutFile);
OutFileSize++;
}
fwrite (&Guid, sizeof (EFI_GUID), 1, OutFile);
OutFileSize += sizeof (EFI_GUID);
Dep_Flag = TRUE;
} else if (strncmp (Ptrx, DEPENDENCY_END, strlen (DEPENDENCY_END)) == 0) {
NotDone = FALSE;
} else {
//
// Not a valid construct. Null terminate somewhere out there and
// print an error message.
//
*(Ptrx + 20) = 0;
printf (TOOL_NAME " ERROR: Unrecognized input at: \"%s\"...\n", Ptrx);
return EFI_INVALID_PARAMETER;
}
}
//
// DRAIN();
//
while (StackPtr != EvaluationStack) {
fputc (PopOpCode ((VOID **) &StackPtr), OutFile);
OutFileSize++;
}
if (OutFileSize == 0) {
printf ("Grammer contains no operators or constants\n");
return EFI_INVALID_PARAMETER;
}
fputc (EFI_DEP_END, OutFile);
OutFileSize++;
//
// Checks for invalid padding values
//
if (Padding < 0) {
printf ("The inputted padding value was %d\n", Padding);
printf ("The optional padding value can not be less than ZERO\n");
return EFI_INVALID_PARAMETER;
} else if (Padding > 0) {
while ((OutFileSize % Padding) != 0) {
fputc (' ', OutFile);
OutFileSize++;
}
}
Results = (UINTN) fclose (InFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
Results = (UINTN) fclose (OutFile);
if (Results != 0) {
printf ("FCLOSE failed\n");
}
free (Buffer);
free (EvaluationStack);
return EFI_SUCCESS;
} // End GenerateDependencyExpression function
int
main (
IN UINTN argc,
IN CHAR8 *argv[]
)
/*++
Routine Description:
Parse user entries. Print some rudimentary help
Arguments:
argc The count of input arguments
argv The input arguments string array
Returns:
EFI_SUCCESS The function completed successfully.
EFI_INVALID_PARAMETER One of the input parameters was invalid or one of the parameters in the text file was invalid.
EFI_OUT_OF_RESOURCES Unable to allocate memory.
EFI_ABORTED Unable to open/create a file or a misc error.
--*/
// TODO: ] - add argument and description to function comment
{
FILE *OutFile;
FILE *InFile;
UINT8 Padding;
UINTN Index;
BOOLEAN Input_Flag;
BOOLEAN Output_Flag;
BOOLEAN Pad_Flag;
InFile = NULL;
OutFile = NULL;
Padding = 0;
Input_Flag = FALSE;
Output_Flag = FALSE;
Pad_Flag = FALSE;
//
// Output the calling arguments
//
printf ("\n\n");
for (Index = 0; Index < argc; Index++) {
printf ("%s ", argv[Index]);
}
printf ("\n\n");
if (argc < 5) {
printf ("Not enough arguments\n");
PrintGenDepexUsageInfo ();
return EFI_INVALID_PARAMETER;
}
for (Index = 1; Index < argc - 1; Index++) {
if ((strcmp (argv[Index], "-I") == 0) || (strcmp (argv[Index], "-i") == 0)) {
if (!Input_Flag) {
InFile = fopen (argv[Index + 1], "rb");
Input_Flag = TRUE;
} else {
printf ("GenDepex only allows one INPUT (-I) argument\n");
return EFI_INVALID_PARAMETER;
}
} else if ((strcmp (argv[Index], "-O") == 0) || (strcmp (argv[Index], "-o") == 0)) {
if (!Output_Flag) {
OutFile = fopen (argv[Index + 1], "wb");
Output_Flag = TRUE;
} else {
printf ("GenDepex only allows one OUTPUT (-O) argument\n");
return EFI_INVALID_PARAMETER;
}
} else if ((strcmp (argv[Index], "-P") == 0) || (strcmp (argv[Index], "-p") == 0)) {
if (!Pad_Flag) {
Padding = (UINT8) atoi (argv[Index + 1]);
Pad_Flag = TRUE;
} else {
printf ("GenDepex only allows one PADDING (-P) argument\n");
return EFI_INVALID_PARAMETER;
}
}
}
PrintGenDepexUtilityInfo ();
if (InFile == NULL) {
printf ("Can not open <INFILE> for reading.\n");
PrintGenDepexUsageInfo ();
return EFI_ABORTED;
}
if (OutFile == NULL) {
printf ("Can not open <OUTFILE> for writting.\n");
PrintGenDepexUsageInfo ();
return EFI_ABORTED;
}
return GenerateDependencyExpression (InFile, OutFile, Padding);
}

View File

@@ -0,0 +1,71 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenDepex.h
Abstract:
This file contains the relevant declarations required
to generate a binary Dependency File
Complies with Tiano C Coding Standards Document, version 0.31, 12 Dec 2000.
--*/
#ifndef _EFI_GEN_DEPEX_H
#define _EFI_GEN_DEPEX_H
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#ifndef __GNUC__
#include <malloc.h>
#endif
#include <Base.h>
#include <UefiBaseTypes.h>
#include <Dependency.h>
#define DEPENDENCY_START "DEPENDENCY_START"
#define OPERATOR_BEFORE "BEFORE"
#define OPERATOR_AFTER "AFTER"
#define OPERATOR_AND "AND"
#define OPERATOR_OR "OR"
#define OPERATOR_NOT "NOT"
#define OPERATOR_TRUE "TRUE"
#define OPERATOR_FALSE "FALSE"
#define OPERATOR_SOR "SOR"
#define OPERATOR_END "END"
#define OPERATOR_LEFT_PARENTHESIS "("
#define OPERATOR_RIGHT_PARENTHESIS ")"
#define DEPENDENCY_END "DEPENDENCY_END"
#define DXE_DEP_LEFT_PARENTHESIS 0x0a
#define DXE_DEP_RIGHT_PARENTHESIS 0x0b
#define LINESIZE 320
#define SIZE_A_SYMBOL 60
#define DEPENDENCY_OPCODE UINT8
#define EVAL_STACK_SIZE 0x1024
#define BUFFER_SIZE 0x100
//
// Utility Name
//
#define UTILITY_NAME "GenDepex"
//
// Utility version information
//
#define UTILITY_MAJOR_VERSION 0
#define UTILITY_MINOR_VERSION 5
#endif

View File

@@ -0,0 +1 @@
gcc -mno-cygwin -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ *.c -o GenDepex -L../Library-mingw -lCommon

View File

@@ -0,0 +1,146 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenDepex Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenDepex"/>
<property name="LibName" value="DepexParser"/>
<property name="FileSet" value="GenDepex.c GenDepex.h"/>
<property name="LibFileSet" value="DepexParser.c DepexParser.h" />
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Lib, Tool">
<echo message="Building the EDK Tool: ${ToolName}"/>
</target>
<target name="init">
<echo message="The EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>
Unsupported Operating System
Please Contact Intel Corporation
</echo>
</else>
</if>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
<property name="ext_exe" value=".exe"/>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
<property name="ext_exe" value=""/>
</then>
</elseif>
</if>
</target>
<target name="Tool" depends="init, Lib">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools${ext_static}"/>
<linkerarg value="${LIB_DIR}/${LibName}${ext_static}"/>
</cc>
</target>
<target name="Lib" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${LIB_DIR}/${LibName}"
outtype="static"
libtool="${haveLibtool}"
optimize="speed">
<fileset dir="${basedir}/${ToolName}"
includes="${LibFileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${PACKAGE_DIR}/Common"/>
</cc>
<if>
<os family="dos"/>
<then>
<exec dir="${BUILD_DIR}" executable="lib" failonerror="false">
<arg line="/NOLOGO *.lib /OUT:${LIB_DIR}/${LibName}${ext_static}"/>
</exec>
</then>
</if>
</target>
<target name="clean" depends="init">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall" depends="init">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete dir="${BUILD_DIR}">
<fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFfsFile.h
Abstract:
Header file for GenFfsFile.
--*/
//
// Module Coded to Tiano Coding Conventions
//
#ifndef _EFI_GEN_FFSFILE_H
#define _EFI_GEN_FFSFILE_H
//
// External Files Referenced
//
#include "Base.h"
#include "UefiBaseTypes.h"
#include "FirmwareVolumeImageFormat.h"
#include "MyAlloc.h"
#endif

View File

@@ -0,0 +1,969 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
SimpleFileParsing.c
Abstract:
Generic but simple file parsing routines.
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "Base.h"
#include "UefiBaseTypes.h"
#include "EfiUtilityMsgs.h"
#include "SimpleFileParsing.h"
#define MAX_PATH 255
#define MAX_NEST_DEPTH 20 // just in case we get in an endless loop.
#define MAX_STRING_IDENTIFIER_NAME 100 // number of wchars
#define MAX_LINE_LEN 400
#define T_CHAR_SPACE ' '
#define T_CHAR_NULL 0
#define T_CHAR_CR '\r'
#define T_CHAR_TAB '\t'
#define T_CHAR_LF '\n'
#define T_CHAR_SLASH '/'
#define T_CHAR_BACKSLASH '\\'
#define T_CHAR_DOUBLE_QUOTE '"'
#define T_CHAR_LC_X 'x'
#define T_CHAR_0 '0'
//
// We keep a linked list of these for the source files we process
//
typedef struct _SOURCE_FILE {
FILE *Fptr;
T_CHAR *FileBuffer;
T_CHAR *FileBufferPtr;
UINT32 FileSize;
INT8 FileName[MAX_PATH];
UINT32 LineNum;
BOOLEAN EndOfFile;
BOOLEAN SkipToHash;
struct _SOURCE_FILE *Previous;
struct _SOURCE_FILE *Next;
T_CHAR ControlCharacter;
} SOURCE_FILE;
//
// Here's all our module globals.
//
static struct {
SOURCE_FILE SourceFile;
BOOLEAN Verbose;
} mGlobals;
static
UINT32
t_strcmp (
T_CHAR *Buffer,
T_CHAR *Str
);
static
UINT32
t_strncmp (
T_CHAR *Str1,
T_CHAR *Str2,
UINT32 Len
);
static
UINT32
t_strlen (
T_CHAR *Str
);
static
void
RewindFile (
SOURCE_FILE *SourceFile
);
static
BOOLEAN
SkipTo (
SOURCE_FILE *SourceFile,
T_CHAR TChar,
BOOLEAN StopAfterNewline
);
static
BOOLEAN
IsWhiteSpace (
SOURCE_FILE *SourceFile
);
static
UINT32
SkipWhiteSpace (
SOURCE_FILE *SourceFile
);
static
BOOLEAN
EndOfFile (
SOURCE_FILE *SourceFile
);
static
void
PreprocessFile (
SOURCE_FILE *SourceFile
);
//
// static
// T_CHAR *
// GetQuotedString (
// SOURCE_FILE *SourceFile,
// BOOLEAN Optional
// );
//
static
T_CHAR *
t_strcpy (
T_CHAR *Dest,
T_CHAR *Src
);
static
STATUS
ProcessIncludeFile (
SOURCE_FILE *SourceFile,
SOURCE_FILE *ParentSourceFile
);
static
STATUS
ParseFile (
SOURCE_FILE *SourceFile
);
static
FILE *
FindFile (
IN INT8 *FileName,
OUT INT8 *FoundFileName,
IN UINT32 FoundFileNameLen
);
static
STATUS
ProcessFile (
SOURCE_FILE *SourceFile
);
STATUS
SFPInit (
VOID
)
{
memset ((void *) &mGlobals, 0, sizeof (mGlobals));
return STATUS_SUCCESS;
}
UINT32
SFPGetLineNumber (
VOID
)
{
return mGlobals.SourceFile.LineNum;
}
/*++
Routine Description:
Return the line number of the file we're parsing. Used
for error reporting purposes.
Arguments:
None.
Returns:
The line number, or 0 if no file is being processed
--*/
T_CHAR *
SFPGetFileName (
VOID
)
/*++
Routine Description:
Return the name of the file we're parsing. Used
for error reporting purposes.
Arguments:
None.
Returns:
A pointer to the file name. Null if no file is being
processed.
--*/
{
if (mGlobals.SourceFile.FileName[0]) {
return mGlobals.SourceFile.FileName;
}
return NULL;
}
STATUS
SFPOpenFile (
IN INT8 *FileName
)
/*++
Routine Description:
Open a file for parsing.
Arguments:
FileName - name of the file to parse
Returns:
--*/
{
STATUS Status;
t_strcpy (mGlobals.SourceFile.FileName, FileName);
Status = ProcessIncludeFile (&mGlobals.SourceFile, NULL);
return Status;
}
BOOLEAN
SFPIsToken (
T_CHAR *Str
)
/*++
Routine Description:
Check to see if the specified token is found at
the current position in the input file.
Arguments:
Str - the token to look for
Returns:
TRUE - the token is next
FALSE - the token is not next
Notes:
We do a simple string comparison on this function. It is
the responsibility of the caller to ensure that the token
is not a subset of some other token.
The file pointer is advanced past the token in the input file.
--*/
{
UINT32 Len;
SkipWhiteSpace (&mGlobals.SourceFile);
if ((Len = t_strcmp (mGlobals.SourceFile.FileBufferPtr, Str)) > 0) {
mGlobals.SourceFile.FileBufferPtr += Len;
return TRUE;
}
return FALSE;
}
BOOLEAN
SFPGetNextToken (
T_CHAR *Str,
UINT32 Len
)
{
UINT32 Index;
SkipWhiteSpace (&mGlobals.SourceFile);
Index = 0;
while (!EndOfFile (&mGlobals.SourceFile) && (Index < Len)) {
if (IsWhiteSpace (&mGlobals.SourceFile)) {
if (Index > 0) {
Str[Index] = 0;
return TRUE;
}
return FALSE;
} else {
Str[Index] = mGlobals.SourceFile.FileBufferPtr[0];
mGlobals.SourceFile.FileBufferPtr++;
Index++;
}
}
return FALSE;
}
BOOLEAN
SFPSkipToToken (
T_CHAR *Str
)
{
UINT32 Len;
T_CHAR *SavePos;
Len = t_strlen (Str);
SavePos = mGlobals.SourceFile.FileBufferPtr;
SkipWhiteSpace (&mGlobals.SourceFile);
while (!EndOfFile (&mGlobals.SourceFile)) {
if (t_strncmp (Str, mGlobals.SourceFile.FileBufferPtr, Len) == 0) {
mGlobals.SourceFile.FileBufferPtr += Len;
return TRUE;
}
mGlobals.SourceFile.FileBufferPtr++;
SkipWhiteSpace (&mGlobals.SourceFile);
}
mGlobals.SourceFile.FileBufferPtr = SavePos;
return FALSE;
}
BOOLEAN
SFPGetNumber (
UINT32 *Value
)
/*++
Routine Description:
Check the token at the current file position for a numeric value.
May be either decimal or hex.
Arguments:
Value - pointer where to store the value
Returns:
FALSE - current token is not a number
TRUE - current token is a number
--*/
{
//
// UINT32 Len;
//
SkipWhiteSpace (&mGlobals.SourceFile);
if (EndOfFile (&mGlobals.SourceFile)) {
return FALSE;
}
if (isdigit (mGlobals.SourceFile.FileBufferPtr[0])) {
//
// Check for hex value
//
if ((mGlobals.SourceFile.FileBufferPtr[0] == T_CHAR_0) && (mGlobals.SourceFile.FileBufferPtr[1] == T_CHAR_LC_X)) {
if (!isxdigit (mGlobals.SourceFile.FileBufferPtr[2])) {
return FALSE;
}
mGlobals.SourceFile.FileBufferPtr += 2;
sscanf (mGlobals.SourceFile.FileBufferPtr, "%x", Value);
while (isxdigit (mGlobals.SourceFile.FileBufferPtr[0])) {
mGlobals.SourceFile.FileBufferPtr++;
}
return TRUE;
} else {
*Value = atoi (mGlobals.SourceFile.FileBufferPtr);
while (isdigit (mGlobals.SourceFile.FileBufferPtr[0])) {
mGlobals.SourceFile.FileBufferPtr++;
}
return TRUE;
}
} else {
return FALSE;
}
}
STATUS
SFPCloseFile (
VOID
)
/*++
Routine Description:
Close the file being parsed.
Arguments:
None.
Returns:
STATUS_SUCCESS - the file was closed
STATUS_ERROR - no file is currently open
--*/
{
if (mGlobals.SourceFile.FileBuffer != NULL) {
free (mGlobals.SourceFile.FileBuffer);
memset (&mGlobals.SourceFile, 0, sizeof (mGlobals.SourceFile));
return STATUS_SUCCESS;
}
return STATUS_ERROR;
}
static
STATUS
ProcessIncludeFile (
SOURCE_FILE *SourceFile,
SOURCE_FILE *ParentSourceFile
)
/*++
Routine Description:
Given a source file, open the file and parse it
Arguments:
SourceFile - name of file to parse
ParentSourceFile - for error reporting purposes, the file that #included SourceFile.
Returns:
Standard status.
--*/
{
static UINT32 NestDepth = 0;
INT8 FoundFileName[MAX_PATH];
STATUS Status;
Status = STATUS_SUCCESS;
NestDepth++;
//
// Print the file being processed. Indent so you can tell the include nesting
// depth.
//
if (mGlobals.Verbose) {
fprintf (stdout, "%*cProcessing file '%s'\n", NestDepth * 2, ' ', SourceFile->FileName);
}
//
// Make sure we didn't exceed our maximum nesting depth
//
if (NestDepth > MAX_NEST_DEPTH) {
Error (NULL, 0, 0, SourceFile->FileName, "max nesting depth (%d) exceeded", NestDepth);
Status = STATUS_ERROR;
goto Finish;
}
//
// Try to open the file locally, and if that fails try along our include paths.
//
strcpy (FoundFileName, SourceFile->FileName);
if ((SourceFile->Fptr = fopen (FoundFileName, "r")) == NULL) {
//
// Try to find it among the paths if it has a parent (that is, it is included
// by someone else).
//
Error (NULL, 0, 0, SourceFile->FileName, "file not found");
return STATUS_ERROR;
}
//
// Process the file found
//
ProcessFile (SourceFile);
Finish:
//
// Close open files and return status
//
if (SourceFile->Fptr != NULL) {
fclose (SourceFile->Fptr);
SourceFile->Fptr = NULL;
}
return Status;
}
static
STATUS
ProcessFile (
SOURCE_FILE *SourceFile
)
{
//
// Get the file size, and then read the entire thing into memory.
// Allocate space for a terminator character.
//
fseek (SourceFile->Fptr, 0, SEEK_END);
SourceFile->FileSize = ftell (SourceFile->Fptr);
fseek (SourceFile->Fptr, 0, SEEK_SET);
SourceFile->FileBuffer = (T_CHAR *) malloc (SourceFile->FileSize + sizeof (T_CHAR));
if (SourceFile->FileBuffer == NULL) {
Error (NULL, 0, 0, "memory allocation failure", NULL);
return STATUS_ERROR;
}
fread ((VOID *) SourceFile->FileBuffer, SourceFile->FileSize, 1, SourceFile->Fptr);
SourceFile->FileBuffer[(SourceFile->FileSize / sizeof (T_CHAR))] = T_CHAR_NULL;
//
// Pre-process the file to replace comments with spaces
//
PreprocessFile (SourceFile);
SourceFile->LineNum = 1;
return STATUS_SUCCESS;
}
static
void
PreprocessFile (
SOURCE_FILE *SourceFile
)
/*++
Routine Description:
Preprocess a file to replace all carriage returns with NULLs so
we can print lines from the file to the screen.
Arguments:
SourceFile - structure that we use to keep track of an input file.
Returns:
Nothing.
--*/
{
BOOLEAN InComment;
RewindFile (SourceFile);
InComment = FALSE;
while (!EndOfFile (SourceFile)) {
//
// If a line-feed, then no longer in a comment
//
if (SourceFile->FileBufferPtr[0] == T_CHAR_LF) {
SourceFile->FileBufferPtr++;
SourceFile->LineNum++;
InComment = 0;
} else if (SourceFile->FileBufferPtr[0] == T_CHAR_CR) {
//
// Replace all carriage returns with a NULL so we can print stuff
//
SourceFile->FileBufferPtr[0] = 0;
SourceFile->FileBufferPtr++;
} else if (InComment) {
SourceFile->FileBufferPtr[0] = T_CHAR_SPACE;
SourceFile->FileBufferPtr++;
} else if ((SourceFile->FileBufferPtr[0] == T_CHAR_SLASH) && (SourceFile->FileBufferPtr[1] == T_CHAR_SLASH)) {
SourceFile->FileBufferPtr += 2;
InComment = TRUE;
} else {
SourceFile->FileBufferPtr++;
}
}
//
// Could check for end-of-file and still in a comment, but
// should not be necessary. So just restore the file pointers.
//
RewindFile (SourceFile);
}
#if 0
static
T_CHAR *
GetQuotedString (
SOURCE_FILE *SourceFile,
BOOLEAN Optional
)
{
T_CHAR *String;
T_CHAR *Start;
T_CHAR *Ptr;
UINT32 Len;
BOOLEAN PreviousBackslash;
if (SourceFile->FileBufferPtr[0] != T_CHAR_DOUBLE_QUOTE) {
if (!Optional) {
Error (SourceFile->FileName, SourceFile->LineNum, 0, "expected quoted string", "%S", SourceFile->FileBufferPtr);
}
return NULL;
}
Len = 0;
SourceFile->FileBufferPtr++;
Start = Ptr = SourceFile->FileBufferPtr;
PreviousBackslash = FALSE;
while (!EndOfFile (SourceFile)) {
if ((SourceFile->FileBufferPtr[0] == T_CHAR_DOUBLE_QUOTE) && (!PreviousBackslash)) {
break;
} else if (SourceFile->FileBufferPtr[0] == T_CHAR_CR) {
Warning (SourceFile->FileName, SourceFile->LineNum, 0, "carriage return found in quoted string", "%S", Start);
PreviousBackslash = FALSE;
} else if (SourceFile->FileBufferPtr[0] == T_CHAR_BACKSLASH) {
PreviousBackslash = TRUE;
} else {
PreviousBackslash = FALSE;
}
SourceFile->FileBufferPtr++;
Len++;
}
if (SourceFile->FileBufferPtr[0] != T_CHAR_DOUBLE_QUOTE) {
Warning (SourceFile->FileName, SourceFile->LineNum, 0, "missing closing quote on string", "%S", Start);
} else {
SourceFile->FileBufferPtr++;
}
//
// Now allocate memory for the string and save it off
//
String = (T_CHAR *) malloc ((Len + 1) * sizeof (T_CHAR));
if (String == NULL) {
Error (NULL, 0, 0, "memory allocation failed", NULL);
return NULL;
}
//
// Copy the string from the file buffer to the local copy.
// We do no reformatting of it whatsoever at this point.
//
Ptr = String;
while (Len > 0) {
*Ptr = *Start;
Start++;
Ptr++;
Len--;
}
*Ptr = 0;
return String;
}
#endif
static
BOOLEAN
EndOfFile (
SOURCE_FILE *SourceFile
)
{
//
// The file buffer pointer will typically get updated before the End-of-file flag in the
// source file structure, so check it first.
//
if (SourceFile->FileBufferPtr >= SourceFile->FileBuffer + SourceFile->FileSize / sizeof (T_CHAR)) {
SourceFile->EndOfFile = TRUE;
return TRUE;
}
if (SourceFile->EndOfFile) {
return TRUE;
}
return FALSE;
}
#if 0
static
void
ProcessTokenInclude (
SOURCE_FILE *SourceFile
)
{
INT8 IncludeFileName[MAX_PATH];
INT8 *To;
UINT32 Len;
BOOLEAN ReportedError;
SOURCE_FILE IncludedSourceFile;
ReportedError = FALSE;
if (SkipWhiteSpace (SourceFile) == 0) {
Warning (SourceFile->FileName, SourceFile->LineNum, 0, "expected whitespace following #include keyword", NULL);
}
//
// Should be quoted file name
//
if (SourceFile->FileBufferPtr[0] != T_CHAR_DOUBLE_QUOTE) {
Error (SourceFile->FileName, SourceFile->LineNum, 0, "expected quoted include file name", NULL);
goto FailDone;
}
SourceFile->FileBufferPtr++;
//
// Copy the filename as ascii to our local string
//
To = IncludeFileName;
Len = 0;
while (!EndOfFile (SourceFile)) {
if ((SourceFile->FileBufferPtr[0] == T_CHAR_CR) || (SourceFile->FileBufferPtr[0] == T_CHAR_LF)) {
Error (SourceFile->FileName, SourceFile->LineNum, 0, "end-of-line found in quoted include file name", NULL);
goto FailDone;
}
if (SourceFile->FileBufferPtr[0] == T_CHAR_DOUBLE_QUOTE) {
SourceFile->FileBufferPtr++;
break;
}
//
// If too long, then report the error once and process until the closing quote
//
Len++;
if (!ReportedError && (Len >= sizeof (IncludeFileName))) {
Error (SourceFile->FileName, SourceFile->LineNum, 0, "length of include file name exceeds limit", NULL);
ReportedError = TRUE;
}
if (!ReportedError) {
//
// *To = UNICODE_TO_ASCII(SourceFile->FileBufferPtr[0]);
//
*To = (T_CHAR) SourceFile->FileBufferPtr[0];
To++;
}
SourceFile->FileBufferPtr++;
}
if (!ReportedError) {
*To = 0;
memset ((char *) &IncludedSourceFile, 0, sizeof (SOURCE_FILE));
strcpy (IncludedSourceFile.FileName, IncludeFileName);
//
// IncludedSourceFile.ControlCharacter = DEFAULT_CONTROL_CHARACTER;
//
ProcessIncludeFile (&IncludedSourceFile, SourceFile);
//
// printf ("including file '%s'\n", IncludeFileName);
//
}
return ;
FailDone:
//
// Error recovery -- skip to next #
//
SourceFile->SkipToHash = TRUE;
}
#endif
static
BOOLEAN
IsWhiteSpace (
SOURCE_FILE *SourceFile
)
{
switch (*SourceFile->FileBufferPtr) {
case T_CHAR_NULL:
case T_CHAR_CR:
case T_CHAR_SPACE:
case T_CHAR_TAB:
case T_CHAR_LF:
return TRUE;
default:
return FALSE;
}
}
UINT32
SkipWhiteSpace (
SOURCE_FILE *SourceFile
)
{
UINT32 Count;
Count = 0;
while (!EndOfFile (SourceFile)) {
Count++;
switch (*SourceFile->FileBufferPtr) {
case T_CHAR_NULL:
case T_CHAR_CR:
case T_CHAR_SPACE:
case T_CHAR_TAB:
SourceFile->FileBufferPtr++;
break;
case T_CHAR_LF:
SourceFile->FileBufferPtr++;
SourceFile->LineNum++;
if (mGlobals.Verbose) {
printf ("%d: %S\n", SourceFile->LineNum, SourceFile->FileBufferPtr);
}
break;
default:
return Count - 1;
}
}
//
// Some tokens require trailing whitespace. If we're at the end of the
// file, then we count that as well.
//
if ((Count == 0) && (EndOfFile (SourceFile))) {
Count++;
}
return Count;
}
static
UINT32
t_strcmp (
T_CHAR *Buffer,
T_CHAR *Str
)
{
UINT32 Len;
Len = 0;
while (*Str == *Buffer) {
Buffer++;
Str++;
Len++;
}
if (*Str) {
return 0;
}
return Len;
}
static
UINT32
t_strlen (
T_CHAR *Str
)
{
UINT32 Len;
Len = 0;
while (*Str) {
Len++;
Str++;
}
return Len;
}
static
UINT32
t_strncmp (
T_CHAR *Str1,
T_CHAR *Str2,
UINT32 Len
)
{
while (Len > 0) {
if (*Str1 != *Str2) {
return Len;
}
Len--;
Str1++;
Str2++;
}
return 0;
}
static
T_CHAR *
t_strcpy (
T_CHAR *Dest,
T_CHAR *Src
)
{
T_CHAR *SaveDest;
SaveDest = Dest;
while (*Src) {
*Dest = *Src;
Dest++;
Src++;
}
*Dest = 0;
return SaveDest;
}
#if 0
static
BOOLEAN
IsValidIdentifierChar (
INT8 Char,
BOOLEAN FirstChar
)
{
//
// If it's the first character of an identifier, then
// it must be one of [A-Za-z_].
//
if (FirstChar) {
if (isalpha (Char) || (Char == '_')) {
return TRUE;
}
} else {
//
// If it's not the first character, then it can
// be one of [A-Za-z_0-9]
//
if (isalnum (Char) || (Char == '_')) {
return TRUE;
}
}
return FALSE;
}
#endif
static
void
RewindFile (
SOURCE_FILE *SourceFile
)
{
SourceFile->LineNum = 1;
SourceFile->FileBufferPtr = SourceFile->FileBuffer;
SourceFile->EndOfFile = 0;
}
#if 0
static
BOOLEAN
SkipTo (
SOURCE_FILE *SourceFile,
T_CHAR TChar,
BOOLEAN StopAfterNewline
)
{
while (!EndOfFile (SourceFile)) {
//
// Check for the character of interest
//
if (SourceFile->FileBufferPtr[0] == TChar) {
return TRUE;
} else {
if (SourceFile->FileBufferPtr[0] == T_CHAR_LF) {
SourceFile->LineNum++;
if (StopAfterNewline) {
SourceFile->FileBufferPtr++;
if (SourceFile->FileBufferPtr[0] == 0) {
SourceFile->FileBufferPtr++;
}
return FALSE;
}
}
SourceFile->FileBufferPtr++;
}
}
return FALSE;
}
#endif

View File

@@ -0,0 +1 @@
gcc -mno-cygwin -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ -I../Common -I$WORKSPACE/MdePkg/Include/ -I$WORKSPACE/MdePkg/Include/Ia32 -I. GenFfsFile.c -L../Library-mingw -lCommon -lCustomizedCompress -o GenFfsFile

View File

@@ -0,0 +1,119 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenFfsFile Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenFfsFile"/>
<property name="FileSet" value="GenFfsFile.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="Building the EDK Tool: ${ToolName}"/>
</target>
<target name="init">
<echo message="The EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>
Unsupported Operating System
Please Contact Intel Corporation
</echo>
</else>
</if>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
<property name="ext_exe" value=".exe"/>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
<property name="ext_exe" value=""/>
</then>
</elseif>
</if>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools.lib"/>
<linkerarg value="${LIB_DIR}/CustomizedCompress.lib"/>
</cc>
</target>
<target name="clean" depends="init">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall" depends="init">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete dir="${BUILD_DIR}">
<fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,701 @@
/** @file
EFI image format for PE32+. Please note some data structures are different
for IA-32 and Itanium-based images, look for UINTN and the #ifdef EFI_IA64
@bug Fix text - doc as defined in MSFT EFI specification.
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: EfiImage.h
**/
#ifndef __EFI_IMAGE_H__
#define __EFI_IMAGE_H__
//
// PE32+ Subsystem type for EFI images
//
#define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION 10
#define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
//
// BugBug: Need to get a real answer for this problem. This is not in the
// PE specification.
//
// A SAL runtime driver does not get fixed up when a transition to
// virtual mode is made. In all other cases it should be treated
// like a EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER image
//
#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
//
// PE32+ Machine type for EFI images
//
#define IMAGE_FILE_MACHINE_I386 0x014c
#define IMAGE_FILE_MACHINE_IA64 0x0200
#define IMAGE_FILE_MACHINE_EBC 0x0EBC
#define IMAGE_FILE_MACHINE_X64 0x8664
//
// Support old names for backward compatible
//
#define EFI_IMAGE_MACHINE_IA32 IMAGE_FILE_MACHINE_I386
#define EFI_IMAGE_MACHINE_IA64 IMAGE_FILE_MACHINE_IA64
#define EFI_IMAGE_MACHINE_IPF IMAGE_FILE_MACHINE_IA64
#define EFI_IMAGE_MACHINE_EBC IMAGE_FILE_MACHINE_EBC
#define EFI_IMAGE_MACHINE_X64 IMAGE_FILE_MACHINE_X64
#define EFI_IMAGE_DOS_SIGNATURE 0x5A4D // MZ
#define EFI_IMAGE_OS2_SIGNATURE 0x454E // NE
#define EFI_IMAGE_OS2_SIGNATURE_LE 0x454C // LE
#define EFI_IMAGE_NT_SIGNATURE 0x00004550 // PE00
#define EFI_IMAGE_EDOS_SIGNATURE 0x44454550 // PEED
///
/// PE images can start with an optional DOS header, so if an image is run
/// under DOS it can print an error message.
///
typedef struct {
UINT16 e_magic; // Magic number
UINT16 e_cblp; // Bytes on last page of file
UINT16 e_cp; // Pages in file
UINT16 e_crlc; // Relocations
UINT16 e_cparhdr; // Size of header in paragraphs
UINT16 e_minalloc; // Minimum extra paragraphs needed
UINT16 e_maxalloc; // Maximum extra paragraphs needed
UINT16 e_ss; // Initial (relative) SS value
UINT16 e_sp; // Initial SP value
UINT16 e_csum; // Checksum
UINT16 e_ip; // Initial IP value
UINT16 e_cs; // Initial (relative) CS value
UINT16 e_lfarlc; // File address of relocation table
UINT16 e_ovno; // Overlay number
UINT16 e_res[4]; // Reserved words
UINT16 e_oemid; // OEM identifier (for e_oeminfo)
UINT16 e_oeminfo; // OEM information; e_oemid specific
UINT16 e_res2[10]; // Reserved words
UINT32 e_lfanew; // File address of new exe header
} EFI_IMAGE_DOS_HEADER;
///
/// File header format.
///
typedef struct {
UINT16 Machine;
UINT16 NumberOfSections;
UINT32 TimeDateStamp;
UINT32 PointerToSymbolTable;
UINT32 NumberOfSymbols;
UINT16 SizeOfOptionalHeader;
UINT16 Characteristics;
} EFI_IMAGE_FILE_HEADER;
#define EFI_IMAGE_SIZEOF_FILE_HEADER 20
#define EFI_IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file.
#define EFI_IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references).
#define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file.
#define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file.
#define EFI_IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed.
#define EFI_IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine.
#define EFI_IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file
#define EFI_IMAGE_FILE_SYSTEM 0x1000 // System File.
#define EFI_IMAGE_FILE_DLL 0x2000 // File is a DLL.
#define EFI_IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed.
#define EFI_IMAGE_FILE_MACHINE_UNKNOWN 0
#define EFI_IMAGE_FILE_MACHINE_I386 0x14c // Intel 386.
#define EFI_IMAGE_FILE_MACHINE_R3000 0x162 // MIPS* little-endian, 0540 big-endian
#define EFI_IMAGE_FILE_MACHINE_R4000 0x166 // MIPS* little-endian
#define EFI_IMAGE_FILE_MACHINE_ALPHA 0x184 // Alpha_AXP*
#define EFI_IMAGE_FILE_MACHINE_POWERPC 0x1F0 // IBM* PowerPC Little-Endian
#define EFI_IMAGE_FILE_MACHINE_TAHOE 0x7cc // Intel EM machine
//
// * Other names and brands may be claimed as the property of others.
//
///
/// Directory format.
///
typedef struct {
UINT32 VirtualAddress;
UINT32 Size;
} EFI_IMAGE_DATA_DIRECTORY;
#define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16
typedef struct {
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
UINT32 BaseOfData;
UINT32 BaseOfBss;
UINT32 GprMask;
UINT32 CprMask[4];
UINT32 GpValue;
} EFI_IMAGE_ROM_OPTIONAL_HEADER;
#define EFI_IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
#define EFI_IMAGE_SIZEOF_ROM_OPTIONAL_HEADER sizeof (EFI_IMAGE_ROM_OPTIONAL_HEADER)
typedef struct {
EFI_IMAGE_FILE_HEADER FileHeader;
EFI_IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
} EFI_IMAGE_ROM_HEADERS;
///
/// @attention
/// EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64
/// are for use ONLY by tools. All proper EFI code MUST use
/// EFI_IMAGE_OPTIONAL_HEADER ONLY!!!
///
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
typedef struct {
//
// Standard fields.
//
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
UINT32 BaseOfData;
//
// NT additional fields.
//
UINT32 ImageBase;
UINT32 SectionAlignment;
UINT32 FileAlignment;
UINT16 MajorOperatingSystemVersion;
UINT16 MinorOperatingSystemVersion;
UINT16 MajorImageVersion;
UINT16 MinorImageVersion;
UINT16 MajorSubsystemVersion;
UINT16 MinorSubsystemVersion;
UINT32 Win32VersionValue;
UINT32 SizeOfImage;
UINT32 SizeOfHeaders;
UINT32 CheckSum;
UINT16 Subsystem;
UINT16 DllCharacteristics;
UINT32 SizeOfStackReserve;
UINT32 SizeOfStackCommit;
UINT32 SizeOfHeapReserve;
UINT32 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
} EFI_IMAGE_OPTIONAL_HEADER32;
///
/// @attention
/// EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64
/// are for use ONLY by tools. All proper EFI code MUST use
/// EFI_IMAGE_OPTIONAL_HEADER ONLY!!!
///
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
typedef struct {
//
// Standard fields.
//
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
//
// NT additional fields.
//
UINT64 ImageBase;
UINT32 SectionAlignment;
UINT32 FileAlignment;
UINT16 MajorOperatingSystemVersion;
UINT16 MinorOperatingSystemVersion;
UINT16 MajorImageVersion;
UINT16 MinorImageVersion;
UINT16 MajorSubsystemVersion;
UINT16 MinorSubsystemVersion;
UINT32 Win32VersionValue;
UINT32 SizeOfImage;
UINT32 SizeOfHeaders;
UINT32 CheckSum;
UINT16 Subsystem;
UINT16 DllCharacteristics;
UINT64 SizeOfStackReserve;
UINT64 SizeOfStackCommit;
UINT64 SizeOfHeapReserve;
UINT64 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
} EFI_IMAGE_OPTIONAL_HEADER64;
///
/// @attention
/// EFI_IMAGE_NT_HEADERS32 and EFI_IMAGE_HEADERS64 are for use ONLY
/// by tools. All proper EFI code MUST use EFI_IMAGE_NT_HEADERS ONLY!!!
///
typedef struct {
UINT32 Signature;
EFI_IMAGE_FILE_HEADER FileHeader;
EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader;
} EFI_IMAGE_NT_HEADERS32;
#define EFI_IMAGE_SIZEOF_NT_OPTIONAL32_HEADER sizeof (EFI_IMAGE_NT_HEADERS32)
typedef struct {
UINT32 Signature;
EFI_IMAGE_FILE_HEADER FileHeader;
EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader;
} EFI_IMAGE_NT_HEADERS64;
#define EFI_IMAGE_SIZEOF_NT_OPTIONAL64_HEADER sizeof (EFI_IMAGE_NT_HEADERS64)
//
// Processor specific definition of EFI_IMAGE_OPTIONAL_HEADER so the
// type name EFI_IMAGE_OPTIONAL_HEADER is appropriate to the build. Same for
// EFI_IMAGE_NT_HEADERS. These definitions MUST be used by ALL EFI code.
//
#if defined (MDE_CPU_IA32) && !defined (BUILDING_TOOLS) || \
defined (BUILDING_TOOLS) && defined (TOOL_BUILD_IA32_TARGET)
// typedef EFI_IMAGE_OPTIONAL_HEADER32 EFI_IMAGE_OPTIONAL_HEADER;
typedef EFI_IMAGE_NT_HEADERS32 EFI_IMAGE_NT_HEADERS;
#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \
(((Machine) == EFI_IMAGE_MACHINE_IA32) || ((Machine) == EFI_IMAGE_MACHINE_EBC))
#elif defined (MDE_CPU_IPF) && !defined (BUILDING_TOOLS) || \
defined (BUILDING_TOOLS) && defined (TOOL_BUILD_IPF_TARGET)
typedef EFI_IMAGE_OPTIONAL_HEADER64 EFI_IMAGE_OPTIONAL_HEADER;
typedef EFI_IMAGE_NT_HEADERS64 EFI_IMAGE_NT_HEADERS;
#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \
(((Machine) == EFI_IMAGE_MACHINE_IPF) || ((Machine) == EFI_IMAGE_MACHINE_EBC))
#elif defined (MDE_CPU_X64) && !defined (BUILDING_TOOLS) || \
defined (BUILDING_TOOLS) && defined (TOOL_BUILD_X64_TARGET)
typedef EFI_IMAGE_OPTIONAL_HEADER64 EFI_IMAGE_OPTIONAL_HEADER;
typedef EFI_IMAGE_NT_HEADERS64 EFI_IMAGE_NT_HEADERS;
#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \
(((Machine) == EFI_IMAGE_MACHINE_X64) || ((Machine) == EFI_IMAGE_MACHINE_EBC))
#elif defined (MDE_CPU_EBC)
//
// This is just to make sure you can cross compile with the EBC compiiler.
// It does not make sense to have a PE loader coded in EBC. You need to
// understand the basic
//
typedef EFI_IMAGE_OPTIONAL_HEADER64 EFI_IMAGE_OPTIONAL_HEADER;
typedef EFI_IMAGE_NT_HEADERS64 EFI_IMAGE_NT_HEADERS;
#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) ((Machine) == EFI_IMAGE_MACHINE_EBC)
#else
#error Unknown Processor Type
#endif
#define EFI_IMAGE_FIRST_SECTION(ntheader) \
( \
(EFI_IMAGE_SECTION_HEADER *) \
( \
(UINT32) ntheader + \
FIELD_OFFSET (EFI_IMAGE_NT_HEADERS, OptionalHeader) + \
((EFI_IMAGE_NT_HEADERS *) (ntheader))->FileHeader.SizeOfOptionalHeader \
) \
)
//
// Subsystem Values
//
#define EFI_IMAGE_SUBSYSTEM_UNKNOWN 0
#define EFI_IMAGE_SUBSYSTEM_NATIVE 1
#define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2
#define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3.
#define EFI_IMAGE_SUBSYSTEM_OS2_CUI 5
#define EFI_IMAGE_SUBSYSTEM_POSIX_CUI 7
//
// Directory Entries
//
#define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0
#define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1
#define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2
#define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
#define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4
#define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5
#define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6
#define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
#define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8
#define EFI_IMAGE_DIRECTORY_ENTRY_TLS 9
#define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10
//
// Section header format.
//
#define EFI_IMAGE_SIZEOF_SHORT_NAME 8
typedef struct {
UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME];
union {
UINT32 PhysicalAddress;
UINT32 VirtualSize;
} Misc;
UINT32 VirtualAddress;
UINT32 SizeOfRawData;
UINT32 PointerToRawData;
UINT32 PointerToRelocations;
UINT32 PointerToLinenumbers;
UINT16 NumberOfRelocations;
UINT16 NumberOfLinenumbers;
UINT32 Characteristics;
} EFI_IMAGE_SECTION_HEADER;
#define EFI_IMAGE_SIZEOF_SECTION_HEADER 40
#define EFI_IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved.
#define EFI_IMAGE_SCN_CNT_CODE 0x00000020
#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
#define EFI_IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved.
#define EFI_IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information.
#define EFI_IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image.
#define EFI_IMAGE_SCN_LNK_COMDAT 0x00001000
#define EFI_IMAGE_SCN_ALIGN_1BYTES 0x00100000
#define EFI_IMAGE_SCN_ALIGN_2BYTES 0x00200000
#define EFI_IMAGE_SCN_ALIGN_4BYTES 0x00300000
#define EFI_IMAGE_SCN_ALIGN_8BYTES 0x00400000
#define EFI_IMAGE_SCN_ALIGN_16BYTES 0x00500000
#define EFI_IMAGE_SCN_ALIGN_32BYTES 0x00600000
#define EFI_IMAGE_SCN_ALIGN_64BYTES 0x00700000
#define EFI_IMAGE_SCN_MEM_DISCARDABLE 0x02000000
#define EFI_IMAGE_SCN_MEM_NOT_CACHED 0x04000000
#define EFI_IMAGE_SCN_MEM_NOT_PAGED 0x08000000
#define EFI_IMAGE_SCN_MEM_SHARED 0x10000000
#define EFI_IMAGE_SCN_MEM_EXECUTE 0x20000000
#define EFI_IMAGE_SCN_MEM_READ 0x40000000
#define EFI_IMAGE_SCN_MEM_WRITE 0x80000000
///
/// Symbol format.
///
#define EFI_IMAGE_SIZEOF_SYMBOL 18
//
// Section values.
//
// Symbols have a section number of the section in which they are
// defined. Otherwise, section numbers have the following meanings:
//
#define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0 // Symbol is undefined or is common.
#define EFI_IMAGE_SYM_ABSOLUTE (UINT16) -1 // Symbol is an absolute value.
#define EFI_IMAGE_SYM_DEBUG (UINT16) -2 // Symbol is a special debug item.
//
// Type (fundamental) values.
//
#define EFI_IMAGE_SYM_TYPE_NULL 0 // no type.
#define EFI_IMAGE_SYM_TYPE_VOID 1 //
#define EFI_IMAGE_SYM_TYPE_CHAR 2 // type character.
#define EFI_IMAGE_SYM_TYPE_SHORT 3 // type short integer.
#define EFI_IMAGE_SYM_TYPE_INT 4
#define EFI_IMAGE_SYM_TYPE_LONG 5
#define EFI_IMAGE_SYM_TYPE_FLOAT 6
#define EFI_IMAGE_SYM_TYPE_DOUBLE 7
#define EFI_IMAGE_SYM_TYPE_STRUCT 8
#define EFI_IMAGE_SYM_TYPE_UNION 9
#define EFI_IMAGE_SYM_TYPE_ENUM 10 // enumeration.
#define EFI_IMAGE_SYM_TYPE_MOE 11 // member of enumeration.
#define EFI_IMAGE_SYM_TYPE_BYTE 12
#define EFI_IMAGE_SYM_TYPE_WORD 13
#define EFI_IMAGE_SYM_TYPE_UINT 14
#define EFI_IMAGE_SYM_TYPE_DWORD 15
//
// Type (derived) values.
//
#define EFI_IMAGE_SYM_DTYPE_NULL 0 // no derived type.
#define EFI_IMAGE_SYM_DTYPE_POINTER 1
#define EFI_IMAGE_SYM_DTYPE_FUNCTION 2
#define EFI_IMAGE_SYM_DTYPE_ARRAY 3
//
// Storage classes.
//
#define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION (UINT8) -1
#define EFI_IMAGE_SYM_CLASS_NULL 0
#define EFI_IMAGE_SYM_CLASS_AUTOMATIC 1
#define EFI_IMAGE_SYM_CLASS_EXTERNAL 2
#define EFI_IMAGE_SYM_CLASS_STATIC 3
#define EFI_IMAGE_SYM_CLASS_REGISTER 4
#define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF 5
#define EFI_IMAGE_SYM_CLASS_LABEL 6
#define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
#define EFI_IMAGE_SYM_CLASS_ARGUMENT 9
#define EFI_IMAGE_SYM_CLASS_STRUCT_TAG 10
#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
#define EFI_IMAGE_SYM_CLASS_UNION_TAG 12
#define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION 13
#define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
#define EFI_IMAGE_SYM_CLASS_ENUM_TAG 15
#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
#define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM 17
#define EFI_IMAGE_SYM_CLASS_BIT_FIELD 18
#define EFI_IMAGE_SYM_CLASS_BLOCK 100
#define EFI_IMAGE_SYM_CLASS_FUNCTION 101
#define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT 102
#define EFI_IMAGE_SYM_CLASS_FILE 103
#define EFI_IMAGE_SYM_CLASS_SECTION 104
#define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
//
// type packing constants
//
#define EFI_IMAGE_N_BTMASK 017
#define EFI_IMAGE_N_TMASK 060
#define EFI_IMAGE_N_TMASK1 0300
#define EFI_IMAGE_N_TMASK2 0360
#define EFI_IMAGE_N_BTSHFT 4
#define EFI_IMAGE_N_TSHIFT 2
//
// Communal selection types.
//
#define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES 1
#define EFI_IMAGE_COMDAT_SELECT_ANY 2
#define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3
#define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4
#define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
#define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
#define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
#define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
///
/// Relocation format.
///
typedef struct {
UINT32 VirtualAddress;
UINT32 SymbolTableIndex;
UINT16 Type;
} EFI_IMAGE_RELOCATION;
#define EFI_IMAGE_SIZEOF_RELOCATION 10
//
// I386 relocation types.
//
#define EFI_IMAGE_REL_I386_ABSOLUTE 0 // Reference is absolute, no relocation is necessary
#define EFI_IMAGE_REL_I386_DIR16 01 // Direct 16-bit reference to the symbols virtual address
#define EFI_IMAGE_REL_I386_REL16 02 // PC-relative 16-bit reference to the symbols virtual address
#define EFI_IMAGE_REL_I386_DIR32 06 // Direct 32-bit reference to the symbols virtual address
#define EFI_IMAGE_REL_I386_DIR32NB 07 // Direct 32-bit reference to the symbols virtual address, base not included
#define EFI_IMAGE_REL_I386_SEG12 011 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
#define EFI_IMAGE_REL_I386_SECTION 012
#define EFI_IMAGE_REL_I386_SECREL 013
#define EFI_IMAGE_REL_I386_REL32 024 // PC-relative 32-bit reference to the symbols virtual address
///
/// Based relocation format.
///
typedef struct {
UINT32 VirtualAddress;
UINT32 SizeOfBlock;
} EFI_IMAGE_BASE_RELOCATION;
#define EFI_IMAGE_SIZEOF_BASE_RELOCATION 8
//
// Based relocation types.
//
#define EFI_IMAGE_REL_BASED_ABSOLUTE 0
#define EFI_IMAGE_REL_BASED_HIGH 1
#define EFI_IMAGE_REL_BASED_LOW 2
#define EFI_IMAGE_REL_BASED_HIGHLOW 3
#define EFI_IMAGE_REL_BASED_HIGHADJ 4
#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
#define EFI_IMAGE_REL_BASED_IA64_IMM64 9
#define EFI_IMAGE_REL_BASED_DIR64 10
///
/// Line number format.
///
typedef struct {
union {
UINT32 SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.
UINT32 VirtualAddress; // Virtual address of line number.
} Type;
UINT16 Linenumber; // Line number.
} EFI_IMAGE_LINENUMBER;
#define EFI_IMAGE_SIZEOF_LINENUMBER 6
//
// Archive format.
//
#define EFI_IMAGE_ARCHIVE_START_SIZE 8
#define EFI_IMAGE_ARCHIVE_START "!<arch>\n"
#define EFI_IMAGE_ARCHIVE_END "`\n"
#define EFI_IMAGE_ARCHIVE_PAD "\n"
#define EFI_IMAGE_ARCHIVE_LINKER_MEMBER "/ "
#define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
typedef struct {
UINT8 Name[16]; // File member name - `/' terminated.
UINT8 Date[12]; // File member date - decimal.
UINT8 UserID[6]; // File member user id - decimal.
UINT8 GroupID[6]; // File member group id - decimal.
UINT8 Mode[8]; // File member mode - octal.
UINT8 Size[10]; // File member size - decimal.
UINT8 EndHeader[2]; // String to end header.
} EFI_IMAGE_ARCHIVE_MEMBER_HEADER;
#define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
//
// DLL support.
//
///
/// DLL Export Format
///
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT32 Name;
UINT32 Base;
UINT32 NumberOfFunctions;
UINT32 NumberOfNames;
UINT32 AddressOfFunctions;
UINT32 AddressOfNames;
UINT32 AddressOfNameOrdinals;
} EFI_IMAGE_EXPORT_DIRECTORY;
///
/// DLL support.
/// Import Format
///
typedef struct {
UINT16 Hint;
UINT8 Name[1];
} EFI_IMAGE_IMPORT_BY_NAME;
typedef struct {
union {
UINT32 Function;
UINT32 Ordinal;
EFI_IMAGE_IMPORT_BY_NAME *AddressOfData;
} u1;
} EFI_IMAGE_THUNK_DATA;
#define EFI_IMAGE_ORDINAL_FLAG 0x80000000
#define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0)
#define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT32 ForwarderChain;
UINT32 Name;
EFI_IMAGE_THUNK_DATA *FirstThunk;
} EFI_IMAGE_IMPORT_DESCRIPTOR;
///
/// Debug Format
///
#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT32 Type;
UINT32 SizeOfData;
UINT32 RVA;
UINT32 FileOffset;
} EFI_IMAGE_DEBUG_DIRECTORY_ENTRY;
#define CODEVIEW_SIGNATURE_NB10 0x3031424E // "NB10"
typedef struct {
UINT32 Signature; // "NB10"
UINT32 Unknown;
UINT32 Unknown2;
UINT32 Unknown3;
//
// Filename of .PDB goes here
//
} EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY;
#define CODEVIEW_SIGNATURE_RSDS 0x53445352 // "RSDS"
typedef struct {
UINT32 Signature; // "RSDS"
UINT32 Unknown;
UINT32 Unknown2;
UINT32 Unknown3;
UINT32 Unknown4;
UINT32 Unknown5;
//
// Filename of .PDB goes here
//
} EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;
///
/// Header format for TE images
///
typedef struct {
UINT16 Signature; // signature for TE format = "VZ"
UINT16 Machine; // from the original file header
UINT8 NumberOfSections; // from the original file header
UINT8 Subsystem; // from original optional header
UINT16 StrippedSize; // how many bytes we removed from the header
UINT32 AddressOfEntryPoint; // offset to entry point -- from original optional header
UINT32 BaseOfCode; // from original image -- required for ITP debug
UINT64 ImageBase; // from original file header
EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; // only base relocation and debug directory
} EFI_TE_IMAGE_HEADER;
#define EFI_TE_IMAGE_HEADER_SIGNATURE 0x5A56 // "VZ"
//
// Data directory indexes in our TE image header
//
#define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC 0
#define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG 1
#endif

View File

@@ -0,0 +1,57 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeCoffLoaderEx.c
Abstract:
EBC Specific relocation fixups
Revision History
--*/
RETURN_STATUS
PeCoffLoaderRelocateImageEx (
IN UINT16 *Reloc,
IN OUT CHAR8 *Fixup,
IN OUT CHAR8 **FixupData,
IN UINT64 Adjust
)
/*++
Routine Description:
Performs an IA-32 specific relocation fixup
Arguments:
Reloc - Pointer to the relocation record
Fixup - Pointer to the address to fix up
FixupData - Pointer to a buffer to log the fixups
Adjust - The offset to adjust the fixup
Returns:
EFI_UNSUPPORTED - Unsupported now
--*/
{
return RETURN_UNSUPPORTED;
}

View File

@@ -0,0 +1,299 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFvImageExe.c
Abstract:
This contains all code necessary to build the GenFvImage.exe utility.
This utility relies heavily on the GenFvImage Lib. Definitions for both
can be found in the Tiano Firmware Volume Generation Utility
Specification, review draft.
--*/
//
// File included in build
//
#include "GenFvImageExe.h"
#include "CommonLib.h"
#include "EfiUtilityMsgs.h"
VOID
PrintUtilityInfo (
VOID
)
/*++
Routine Description:
Displays the standard utility information to SDTOUT
Arguments:
None
Returns:
None
--*/
{
printf (
"%s - Tiano Firmware Volume Generation Utility."" Version %i.%i\n\n",
UTILITY_NAME,
UTILITY_MAJOR_VERSION,
UTILITY_MINOR_VERSION
);
}
VOID
PrintUsage (
VOID
)
/*++
Routine Description:
Displays the utility usage syntax to STDOUT
Arguments:
None
Returns:
None
--*/
{
printf ("Usage: %s -I FvInfFileName\n", UTILITY_NAME);
printf (" Where:\n");
printf ("\tFvInfFileName is the name of the image description file.\n\n");
}
int
main (
IN INTN argc,
IN CHAR8 **argv
)
/*++
Routine Description:
This utility uses GenFvImage.Lib to build a firmware volume image.
Arguments:
FvInfFileName The name of an FV image description file.
Arguments come in pair in any order.
-I FvInfFileName
Returns:
EFI_SUCCESS No error conditions detected.
EFI_INVALID_PARAMETER One or more of the input parameters is invalid.
EFI_OUT_OF_RESOURCES A resource required by the utility was unavailable.
Most commonly this will be memory allocation
or file creation.
EFI_LOAD_ERROR GenFvImage.lib could not be loaded.
EFI_ABORTED Error executing the GenFvImage lib.
--*/
{
EFI_STATUS Status;
CHAR8 InfFileName[_MAX_PATH];
CHAR8 *InfFileImage;
UINTN InfFileSize;
UINT8 *FvImage;
UINTN FvImageSize;
UINT8 Index;
CHAR8 FvFileNameBuffer[_MAX_PATH];
CHAR8 *FvFileName;
FILE *FvFile;
FILE *SymFile;
CHAR8 SymFileNameBuffer[_MAX_PATH];
CHAR8 *SymFileName;
UINT8 *SymImage;
UINTN SymImageSize;
CHAR8 *CurrentSymString;
FvFileName = FvFileNameBuffer;
SymFileName = SymFileNameBuffer;
SetUtilityName (UTILITY_NAME);
//
// Display utility information
//
PrintUtilityInfo ();
//
// Verify the correct number of arguments
//
if (argc != MAX_ARGS) {
Error (NULL, 0, 0, "invalid number of input parameters specified", NULL);
PrintUsage ();
return GetUtilityStatus ();
}
//
// Initialize variables
//
strcpy (InfFileName, "");
//
// Parse the command line arguments
//
for (Index = 1; Index < MAX_ARGS; Index += 2) {
//
// Make sure argument pair begin with - or /
//
if (argv[Index][0] != '-' && argv[Index][0] != '/') {
Error (NULL, 0, 0, argv[Index], "argument pair must begin with \"-\" or \"/\"");
PrintUsage ();
return GetUtilityStatus ();
}
//
// Make sure argument specifier is only one letter
//
if (argv[Index][2] != 0) {
Error (NULL, 0, 0, argv[Index], "unrecognized argument");
PrintUsage ();
return GetUtilityStatus ();
}
//
// Determine argument to read
//
switch (argv[Index][1]) {
case 'I':
case 'i':
if (strlen (InfFileName) == 0) {
strcpy (InfFileName, argv[Index + 1]);
} else {
Error (NULL, 0, 0, argv[Index + 1], "FvInfFileName may only be specified once");
PrintUsage ();
return GetUtilityStatus ();
}
break;
default:
Error (NULL, 0, 0, argv[Index], "unrecognized argument");
PrintUsage ();
return GetUtilityStatus ();
break;
}
}
//
// Read the INF file image
//
Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);
if (EFI_ERROR (Status)) {
return STATUS_ERROR;
}
//
// Call the GenFvImage lib
//
Status = GenerateFvImage (
InfFileImage,
InfFileSize,
&FvImage,
&FvImageSize,
&FvFileName,
&SymImage,
&SymImageSize,
&SymFileName
);
if (EFI_ERROR (Status)) {
switch (Status) {
case EFI_INVALID_PARAMETER:
Error (NULL, 0, 0, "invalid parameter passed to GenFvImage Lib", NULL);
return GetUtilityStatus ();
break;
case EFI_ABORTED:
Error (NULL, 0, 0, "error detected while creating the file image", NULL);
return GetUtilityStatus ();
break;
case EFI_OUT_OF_RESOURCES:
Error (NULL, 0, 0, "GenFvImage Lib could not allocate required resources", NULL);
return GetUtilityStatus ();
break;
case EFI_VOLUME_CORRUPTED:
Error (NULL, 0, 0, "no base address was specified, but the FV.INF included a PEI or BSF file", NULL);
return GetUtilityStatus ();
break;
case EFI_LOAD_ERROR:
Error (NULL, 0, 0, "could not load FV image generation library", NULL);
return GetUtilityStatus ();
break;
default:
Error (NULL, 0, 0, "GenFvImage Lib returned unknown status", "status returned = 0x%X", Status);
return GetUtilityStatus ();
break;
}
}
//
// Write file
//
FvFile = fopen (FvFileName, "wb");
if (FvFile == NULL) {
Error (NULL, 0, 0, FvFileName, "could not open output file");
free (FvImage);
free (SymImage);
return GetUtilityStatus ();
}
if (fwrite (FvImage, 1, FvImageSize, FvFile) != FvImageSize) {
Error (NULL, 0, 0, FvFileName, "failed to write to output file");
free (FvImage);
free (SymImage);
fclose (FvFile);
return GetUtilityStatus ();
}
fclose (FvFile);
free (FvImage);
//
// Write symbol file
//
if (strcmp (SymFileName, "")) {
SymFile = fopen (SymFileName, "wt");
if (SymFile == NULL) {
Error (NULL, 0, 0, SymFileName, "could not open output symbol file");
free (SymImage);
return GetUtilityStatus ();
}
fprintf (SymFile, "TEXTSYM format | V1.0\n");
CurrentSymString = SymImage;
while (((UINTN) CurrentSymString - (UINTN) SymImage) < SymImageSize) {
fprintf (SymFile, "%s", CurrentSymString);
CurrentSymString = (CHAR8 *) (((UINTN) CurrentSymString) + strlen (CurrentSymString) + 1);
}
fclose (SymFile);
}
free (SymImage);
return GetUtilityStatus ();
}

View File

@@ -0,0 +1,98 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFvImageExe.h
Abstract:
Definitions for the PeimFixup exe utility.
--*/
//
// Coded to Tiano Coding Standards
//
#ifndef _EFI_GEN_FV_IMAGE_EXE_H
#define _EFI_GEN_FV_IMAGE_EXE_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "GenFvImageLib.h"
//
// Utility Name
//
#define UTILITY_NAME "GenFvImage"
//
// Utility version information
//
#define UTILITY_MAJOR_VERSION 0
#define UTILITY_MINOR_VERSION 1
#define UTILITY_DATE __DATE__
//
// The maximum number of arguments accepted from the command line.
//
#define MAX_ARGS 3
//
// The function that displays general utility information
//
VOID
PrintUtilityInfo (
VOID
)
/*++
Routine Description:
TODO: Add function description
Arguments:
None
Returns:
TODO: add return values
--*/
;
//
// The function that displays the utility usage message.
//
VOID
PrintUsage (
VOID
)
/*++
Routine Description:
TODO: Add function description
Arguments:
None
Returns:
TODO: add return values
--*/
;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,140 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFvImageLib.h
Abstract:
This file contains describes the public interfaces to the GenFvImage Library.
The basic purpose of the library is to create Firmware Volume images.
--*/
#ifndef _EFI_GEN_FV_IMAGE_LIB_H
#define _EFI_GEN_FV_IMAGE_LIB_H
//
// Include files
//
// #include "Efi2WinNT.h"
#include "ParseInf.h"
//
// Following definition is used for FIT in IPF
//
#define COMP_TYPE_FIT_PEICORE 0x10
#define COMP_TYPE_FIT_UNUSED 0x7F
#define FIT_TYPE_MASK 0x7F
#define CHECKSUM_BIT_MASK 0x80
#pragma pack(1)
typedef struct {
UINT64 CompAddress;
UINT32 CompSize;
UINT16 CompVersion;
UINT8 CvAndType;
UINT8 CheckSum;
} FIT_TABLE;
#pragma pack()
//
// Exported function prototypes
//
EFI_STATUS
GenerateFvImage (
IN CHAR8 *InfFileImage,
IN UINTN InfFileSize,
OUT UINT8 **FvImage,
OUT UINTN *FvImageSize,
OUT CHAR8 **FvFileName,
OUT UINT8 **SymImage,
OUT UINTN *SymImageSize,
OUT CHAR8 **SymFileName
)
;
/*++
Routine Description:
This is the main function which will be called from application.
Arguments:
InfFileImage Buffer containing the INF file contents.
InfFileSize Size of the contents of the InfFileImage buffer.
FvImage Pointer to the FV image created.
FvImageSize Size of the FV image created and pointed to by FvImage.
FvFileName Requested name for the FV file.
SymImage Pointer to the Sym image created.
SymImageSize Size of the Sym image created and pointed to by SymImage.
SymFileName Requested name for the Sym file.
Returns:
EFI_SUCCESS Function completed successfully.
EFI_OUT_OF_RESOURCES Could not allocate required resources.
EFI_ABORTED Error encountered.
EFI_INVALID_PARAMETER A required parameter was NULL.
--*/
EFI_STATUS
UpdatePeiCoreEntryInFit (
IN FIT_TABLE *FitTablePtr,
IN UINT64 PeiCorePhysicalAddress
)
;
/*++
Routine Description:
This function is used to update the Pei Core address in FIT, this can be used by Sec core to pass control from
Sec to Pei Core
Arguments:
FitTablePtr - The pointer of FIT_TABLE.
PeiCorePhysicalAddress - The address of Pei Core entry.
Returns:
EFI_SUCCESS - The PEI_CORE FIT entry was updated successfully.
EFI_NOT_FOUND - Not found the PEI_CORE FIT entry.
--*/
VOID
UpdateFitCheckSum (
IN FIT_TABLE *FitTablePtr
)
;
/*++
Routine Description:
This function is used to update the checksum for FIT.
Arguments:
FitTablePtr - The pointer of FIT_TABLE.
Returns:
None.
--*/
#endif

View File

@@ -0,0 +1,170 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenFvImageLibInternal.h
Abstract:
This file contains describes the private declarations for the GenFvImage Library.
The basic purpose of the library is to create Firmware Volume images.
--*/
#ifndef _EFI_GEN_FV_IMAGE_LIB_INTERNAL_H
#define _EFI_GEN_FV_IMAGE_LIB_INTERNAL_H
//
// Include files
//
#include "GenFvImageLib.h"
#include <stdlib.h>
#include <CommonLib.h>
#include "FirmwareVolumeHeader.h"
//
// Private data declarations
//
//
// The maximum number of block map entries supported by the library
//
#define MAX_NUMBER_OF_FV_BLOCKS 100
//
// The maximum number of files in the FV supported by the library
//
#define MAX_NUMBER_OF_FILES_IN_FV 1000
#define MAX_NUMBER_OF_COMPONENTS_IN_FV 10
//
// INF file strings
//
#define OPTIONS_SECTION_STRING "[options]"
#define ATTRIBUTES_SECTION_STRING "[attributes]"
#define FILES_SECTION_STRING "[files]"
#define COMPONENT_SECTION_STRING "[components]"
#define EFI_FV_BASE_ADDRESS_STRING "EFI_BASE_ADDRESS"
#define EFI_FV_FILE_NAME_STRING "EFI_FILE_NAME"
#define EFI_SYM_FILE_NAME_STRING "EFI_SYM_FILE_NAME"
#define EFI_NUM_BLOCKS_STRING "EFI_NUM_BLOCKS"
#define EFI_BLOCK_SIZE_STRING "EFI_BLOCK_SIZE"
#define EFI_FV_GUID_STRING "EFI_FV_GUID"
#define EFI_FVB_READ_DISABLED_CAP_STRING "EFI_READ_DISABLED_CAP"
#define EFI_FVB_READ_ENABLED_CAP_STRING "EFI_READ_ENABLED_CAP"
#define EFI_FVB_READ_STATUS_STRING "EFI_READ_STATUS"
#define EFI_FVB_WRITE_DISABLED_CAP_STRING "EFI_WRITE_DISABLED_CAP"
#define EFI_FVB_WRITE_ENABLED_CAP_STRING "EFI_WRITE_ENABLED_CAP"
#define EFI_FVB_WRITE_STATUS_STRING "EFI_WRITE_STATUS"
#define EFI_FVB_LOCK_CAP_STRING "EFI_LOCK_CAP"
#define EFI_FVB_LOCK_STATUS_STRING "EFI_LOCK_STATUS"
#define EFI_FVB_STICKY_WRITE_STRING "EFI_STICKY_WRITE"
#define EFI_FVB_MEMORY_MAPPED_STRING "EFI_MEMORY_MAPPED"
#define EFI_FVB_ERASE_POLARITY_STRING "EFI_ERASE_POLARITY"
#define EFI_FVB_ALIGNMENT_CAP_STRING "EFI_ALIGNMENT_CAP"
#define EFI_FVB_ALIGNMENT_2_STRING "EFI_ALIGNMENT_2"
#define EFI_FVB_ALIGNMENT_4_STRING "EFI_ALIGNMENT_4"
#define EFI_FVB_ALIGNMENT_8_STRING "EFI_ALIGNMENT_8"
#define EFI_FVB_ALIGNMENT_16_STRING "EFI_ALIGNMENT_16"
#define EFI_FVB_ALIGNMENT_32_STRING "EFI_ALIGNMENT_32"
#define EFI_FVB_ALIGNMENT_64_STRING "EFI_ALIGNMENT_64"
#define EFI_FVB_ALIGNMENT_128_STRING "EFI_ALIGNMENT_128"
#define EFI_FVB_ALIGNMENT_256_STRING "EFI_ALIGNMENT_256"
#define EFI_FVB_ALIGNMENT_512_STRING "EFI_ALIGNMENT_512"
#define EFI_FVB_ALIGNMENT_1K_STRING "EFI_ALIGNMENT_1K"
#define EFI_FVB_ALIGNMENT_2K_STRING "EFI_ALIGNMENT_2K"
#define EFI_FVB_ALIGNMENT_4K_STRING "EFI_ALIGNMENT_4K"
#define EFI_FVB_ALIGNMENT_8K_STRING "EFI_ALIGNMENT_8K"
#define EFI_FVB_ALIGNMENT_16K_STRING "EFI_ALIGNMENT_16K"
#define EFI_FVB_ALIGNMENT_32K_STRING "EFI_ALIGNMENT_32K"
#define EFI_FVB_ALIGNMENT_64K_STRING "EFI_ALIGNMENT_64K"
//
// Component sections
//
#define EFI_NV_VARIABLE_STRING "EFI_NV_VARIABLE"
#define EFI_NV_EVENT_LOG_STRING "EFI_NV_EVENT_LOG"
#define EFI_NV_FTW_WORKING_STRING "EFI_NV_FTW_WORKING"
#define EFI_NV_FTW_SPARE_STRING "EFI_NV_FTW_SPARE"
#define EFI_FILE_NAME_STRING "EFI_FILE_NAME"
#define ONE_STRING "1"
#define ZERO_STRING "0"
#define TRUE_STRING "TRUE"
#define FALSE_STRING "FALSE"
#define NULL_STRING "NULL"
//
// Defines to calculate the offset for PEI CORE entry points
//
#define IA32_PEI_CORE_ENTRY_OFFSET 0x20
//
// Defines to calculate the FIT table
//
#define IPF_FIT_ADDRESS_OFFSET 0x20
//
// Defines to calculate the offset for SALE_ENTRY
//
#define IPF_SALE_ENTRY_ADDRESS_OFFSET 0x18
//
// Symbol file definitions, current max size if 512K
//
#define SYMBOL_FILE_SIZE 0x80000
#define FV_IMAGES_TOP_ADDRESS 0x100000000ULL
//
// Private data types
//
//
// Component information
//
typedef struct {
UINTN Size;
CHAR8 ComponentName[_MAX_PATH];
} COMPONENT_INFO;
//
// FV information holder
//
typedef struct {
EFI_PHYSICAL_ADDRESS BaseAddress;
EFI_GUID FvGuid;
UINTN Size;
CHAR8 FvName[_MAX_PATH];
CHAR8 SymName[_MAX_PATH];
EFI_FV_BLOCK_MAP_ENTRY FvBlocks[MAX_NUMBER_OF_FV_BLOCKS];
EFI_FVB_ATTRIBUTES FvAttributes;
CHAR8 FvFiles[MAX_NUMBER_OF_FILES_IN_FV][_MAX_PATH];
COMPONENT_INFO FvComponents[MAX_NUMBER_OF_COMPONENTS_IN_FV];
} FV_INFO;
//
// Private function prototypes
//
EFI_STATUS
ParseFvInf (
IN MEMORY_FILE *InfFile,
IN FV_INFO *FvInfo
)
;
#endif

View File

@@ -0,0 +1,64 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeCoffLoaderEx.c
Abstract:
IA-32 Specific relocation fixups
Revision History
--*/
#define EFI_SPECIFICATION_VERSION 0x00000000
#define EDK_RELEASE_VERSION 0x00020000
#include <Base.h>
#include <Library/PeCoffLib.h>
#include <Library/BaseMemoryLib.h>
RETURN_STATUS
PeCoffLoaderRelocateImageEx (
IN UINT16 *Reloc,
IN OUT CHAR8 *Fixup,
IN OUT CHAR8 **FixupData,
IN UINT64 Adjust
)
/*++
Routine Description:
Performs an IA-32 specific relocation fixup
Arguments:
Reloc - Pointer to the relocation record
Fixup - Pointer to the address to fix up
FixupData - Pointer to a buffer to log the fixups
Adjust - The offset to adjust the fixup
Returns:
EFI_UNSUPPORTED - Unsupported now
--*/
{
return RETURN_UNSUPPORTED;
}

View File

@@ -0,0 +1,251 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeCoffLoaderEx.c
Abstract:
Fixes Intel Itanium(TM) specific relocation types
Revision History
--*/
#define EFI_SPECIFICATION_VERSION 0x00000000
#define EDK_RELEASE_VERSION 0x00020000
#include <Base.h>
#include <Library/PeCoffLib.h>
#include <Library/BaseMemoryLib.h>
#define EXT_IMM64(Value, Address, Size, InstPos, ValPos) \
Value |= (((UINT64)((*(Address) >> InstPos) & (((UINT64)1 << Size) - 1))) << ValPos)
#define INS_IMM64(Value, Address, Size, InstPos, ValPos) \
*(UINT32*)Address = (*(UINT32*)Address & ~(((1 << Size) - 1) << InstPos)) | \
((UINT32)((((UINT64)Value >> ValPos) & (((UINT64)1 << Size) - 1))) << InstPos)
#define IMM64_IMM7B_INST_WORD_X 3
#define IMM64_IMM7B_SIZE_X 7
#define IMM64_IMM7B_INST_WORD_POS_X 4
#define IMM64_IMM7B_VAL_POS_X 0
#define IMM64_IMM9D_INST_WORD_X 3
#define IMM64_IMM9D_SIZE_X 9
#define IMM64_IMM9D_INST_WORD_POS_X 18
#define IMM64_IMM9D_VAL_POS_X 7
#define IMM64_IMM5C_INST_WORD_X 3
#define IMM64_IMM5C_SIZE_X 5
#define IMM64_IMM5C_INST_WORD_POS_X 13
#define IMM64_IMM5C_VAL_POS_X 16
#define IMM64_IC_INST_WORD_X 3
#define IMM64_IC_SIZE_X 1
#define IMM64_IC_INST_WORD_POS_X 12
#define IMM64_IC_VAL_POS_X 21
#define IMM64_IMM41a_INST_WORD_X 1
#define IMM64_IMM41a_SIZE_X 10
#define IMM64_IMM41a_INST_WORD_POS_X 14
#define IMM64_IMM41a_VAL_POS_X 22
#define IMM64_IMM41b_INST_WORD_X 1
#define IMM64_IMM41b_SIZE_X 8
#define IMM64_IMM41b_INST_WORD_POS_X 24
#define IMM64_IMM41b_VAL_POS_X 32
#define IMM64_IMM41c_INST_WORD_X 2
#define IMM64_IMM41c_SIZE_X 23
#define IMM64_IMM41c_INST_WORD_POS_X 0
#define IMM64_IMM41c_VAL_POS_X 40
#define IMM64_SIGN_INST_WORD_X 3
#define IMM64_SIGN_SIZE_X 1
#define IMM64_SIGN_INST_WORD_POS_X 27
#define IMM64_SIGN_VAL_POS_X 63
RETURN_STATUS
PeCoffLoaderRelocateImageEx (
IN UINT16 *Reloc,
IN OUT CHAR8 *Fixup,
IN OUT CHAR8 **FixupData,
IN UINT64 Adjust
)
/*++
Routine Description:
Performs an Itanium-based specific relocation fixup
Arguments:
Reloc - Pointer to the relocation record
Fixup - Pointer to the address to fix up
FixupData - Pointer to a buffer to log the fixups
Adjust - The offset to adjust the fixup
Returns:
Status code
--*/
{
UINT64 *F64;
UINT64 FixupVal;
switch ((*Reloc) >> 12) {
case EFI_IMAGE_REL_BASED_DIR64:
F64 = (UINT64 *) Fixup;
*F64 = *F64 + (UINT64) Adjust;
if (*FixupData != NULL) {
*FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));
*(UINT64 *)(*FixupData) = *F64;
*FixupData = *FixupData + sizeof(UINT64);
}
break;
case EFI_IMAGE_REL_BASED_IA64_IMM64:
//
// Align it to bundle address before fixing up the
// 64-bit immediate value of the movl instruction.
//
Fixup = (CHAR8 *)((UINTN) Fixup & (UINTN) ~(15));
FixupVal = (UINT64)0;
//
// Extract the lower 32 bits of IMM64 from bundle
//
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IMM7B_INST_WORD_X,
IMM64_IMM7B_SIZE_X,
IMM64_IMM7B_INST_WORD_POS_X,
IMM64_IMM7B_VAL_POS_X
);
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IMM9D_INST_WORD_X,
IMM64_IMM9D_SIZE_X,
IMM64_IMM9D_INST_WORD_POS_X,
IMM64_IMM9D_VAL_POS_X
);
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IMM5C_INST_WORD_X,
IMM64_IMM5C_SIZE_X,
IMM64_IMM5C_INST_WORD_POS_X,
IMM64_IMM5C_VAL_POS_X
);
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IC_INST_WORD_X,
IMM64_IC_SIZE_X,
IMM64_IC_INST_WORD_POS_X,
IMM64_IC_VAL_POS_X
);
EXT_IMM64(FixupVal,
(UINT32 *)Fixup + IMM64_IMM41a_INST_WORD_X,
IMM64_IMM41a_SIZE_X,
IMM64_IMM41a_INST_WORD_POS_X,
IMM64_IMM41a_VAL_POS_X
);
//
// Update 64-bit address
//
FixupVal += Adjust;
//
// Insert IMM64 into bundle
//
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM7B_INST_WORD_X),
IMM64_IMM7B_SIZE_X,
IMM64_IMM7B_INST_WORD_POS_X,
IMM64_IMM7B_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM9D_INST_WORD_X),
IMM64_IMM9D_SIZE_X,
IMM64_IMM9D_INST_WORD_POS_X,
IMM64_IMM9D_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM5C_INST_WORD_X),
IMM64_IMM5C_SIZE_X,
IMM64_IMM5C_INST_WORD_POS_X,
IMM64_IMM5C_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IC_INST_WORD_X),
IMM64_IC_SIZE_X,
IMM64_IC_INST_WORD_POS_X,
IMM64_IC_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM41a_INST_WORD_X),
IMM64_IMM41a_SIZE_X,
IMM64_IMM41a_INST_WORD_POS_X,
IMM64_IMM41a_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM41b_INST_WORD_X),
IMM64_IMM41b_SIZE_X,
IMM64_IMM41b_INST_WORD_POS_X,
IMM64_IMM41b_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_IMM41c_INST_WORD_X),
IMM64_IMM41c_SIZE_X,
IMM64_IMM41c_INST_WORD_POS_X,
IMM64_IMM41c_VAL_POS_X
);
INS_IMM64(FixupVal,
((UINT32 *)Fixup + IMM64_SIGN_INST_WORD_X),
IMM64_SIGN_SIZE_X,
IMM64_SIGN_INST_WORD_POS_X,
IMM64_SIGN_VAL_POS_X
);
F64 = (UINT64 *) Fixup;
if (*FixupData != NULL) {
*FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));
*(UINT64 *)(*FixupData) = *F64;
*FixupData = *FixupData + sizeof(UINT64);
}
break;
default:
return RETURN_UNSUPPORTED;
}
return RETURN_SUCCESS;
}

View File

@@ -0,0 +1,3 @@
gcc -I $WORKSPACE/MdePkg/Include/ToBeRemoved -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ Ia32/*.c *.c -o GenFvImage_IA32 -L../Library-cygwin -lCommon -L/usr/lib/e2fsprogs -luuid
gcc -I $WORKSPACE/MdePkg/Include/ToBeRemoved -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ x64/*.c *.c -o GenFvImage_X64 -L../Library-cygwin -lCommon -L/usr/lib/e2fsprogs -luuid
gcc -I $WORKSPACE/MdePkg/Include/ToBeRemoved -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ Ipf/*.c *.c -o GenFvImage_IPF -L../Library-cygwin -lCommon -L/usr/lib/e2fsprogs -luuid

View File

@@ -0,0 +1,246 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenFvImage Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenFvImage"/>
<property name="FileSet" value="BasePeCoff.c GenFvImageLib.c GenFvImageExe.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR_IA32" value="${PACKAGE_DIR}/${ToolName}/tmp/Ia32"/>
<property name="BUILD_DIR_X64" value="${PACKAGE_DIR}/${ToolName}/tmp/X64"/>
<property name="BUILD_DIR_IPF" value="${PACKAGE_DIR}/${ToolName}/tmp/Ipf"/>
<target name="GenTool" depends="init, Tool">
<echo message="Building the EDK Tool: ${ToolName}"/>
</target>
<target name="init">
<echo message="The EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR_IA32}"/>
<mkdir dir="${BUILD_DIR_X64}"/>
<mkdir dir="${BUILD_DIR_IPF}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>
Unsupported Operating System
Please Contact Intel Corporation
</echo>
</else>
</if>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
<property name="ext_exe" value=".exe"/>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
<property name="ext_exe" value=""/>
</then>
</elseif>
</if>
</target>
<target name="Tool" depends="init, GenFvImage, GenFvImage_IA32, GenFvImage_X64, GenFvImage_IPF"/>
<target name="GenFvImage">
<cc name="${ToolChain}" objdir="${BUILD_DIR_IA32}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<defineset>
<define name="BUILDING_TOOLS"/>
<define name="TOOL_BUILD_IA32_TARGET"/>
</defineset>
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet} Ia32/PeCoffLoaderEx.c"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/${ToolName}"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/ToBeRemoved"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools.lib"/>
<linkerarg value="${LIB_DIR}/CustomizedCompress.lib"/>
<linkerarg value="/nodefaultlib:libc.lib"/>
<linkerarg value="RpcRT4.Lib"/>
</cc>
</target>
<target name="GenFvImage_IA32">
<cc name="${ToolChain}" objdir="${BUILD_DIR_IA32}"
outfile="${BIN_DIR}/${ToolName}_IA32"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<defineset>
<define name="BUILDING_TOOLS"/>
<define name="TOOL_BUILD_IA32_TARGET"/>
</defineset>
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet} Ia32/PeCoffLoaderEx.c"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/${ToolName}"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/ToBeRemoved"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools.lib"/>
<linkerarg value="${LIB_DIR}/CustomizedCompress.lib"/>
<linkerarg value="/nodefaultlib:libc.lib"/>
<linkerarg value="RpcRT4.Lib"/>
</cc>
</target>
<target name="GenFvImage_X64">
<cc name="${ToolChain}" objdir="${BUILD_DIR_X64}"
outfile="${BIN_DIR}/${ToolName}_X64"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<defineset>
<define name="BUILDING_TOOLS"/>
<define name="TOOL_BUILD_X64_TARGET"/>
</defineset>
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet} x64/PeCoffLoaderEx.c"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/${ToolName}"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/ToBeRemoved"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools.lib"/>
<linkerarg value="${LIB_DIR}/CustomizedCompress.lib"/>
<linkerarg value="/nodefaultlib:libc.lib"/>
<linkerarg value="RpcRT4.Lib"/>
</cc>
</target>
<target name="GenFvImage_IPF">
<cc name="${ToolChain}" objdir="${BUILD_DIR_IPF}"
outfile="${BIN_DIR}/${ToolName}_IPF"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<defineset>
<define name="BUILDING_TOOLS"/>
<define name="TOOL_BUILD_IPF_TARGET"/>
</defineset>
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet} Ipf/PeCoffLoaderEx.c"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${PACKAGE_DIR}/${ToolName}"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/ToBeRemoved"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools.lib"/>
<linkerarg value="${LIB_DIR}/CustomizedCompress.lib"/>
<linkerarg value="/nodefaultlib:libc.lib"/>
<linkerarg value="RpcRT4.Lib"/>
</cc>
</target>
<target name="clean" depends="init">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR_IA32}" includes="*.obj"/>
<fileset dir="${BUILD_DIR_X64}" includes="*.obj"/>
<fileset dir="${BUILD_DIR_IPF}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall" depends="init">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete dir="${PACKAGE_DIR}/${ToolName}/tmp">
<fileset dir="${BIN_DIR}" includes="${ToolName}_IA32${ext_exe}"/>
<fileset dir="${BIN_DIR}" includes="${ToolName}_X64${ext_exe}"/>
<fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>
<fileset dir="${BIN_DIR}" includes="${ToolName}_IPF${ext_exe}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,76 @@
/*++
Copyright 2005, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PeCoffLoaderEx.c
Abstract:
x64 Specific relocation fixups
Revision History
--*/
#define EFI_SPECIFICATION_VERSION 0x00000000
#define EDK_RELEASE_VERSION 0x00020000
#include <Base.h>
#include <Library/PeCoffLib.h>
#include <Library/BaseMemoryLib.h>
RETURN_STATUS
PeCoffLoaderRelocateImageEx (
IN UINT16 *Reloc,
IN OUT CHAR8 *Fixup,
IN OUT CHAR8 **FixupData,
IN UINT64 Adjust
)
/*++
Routine Description:
Performs an x64 specific relocation fixup
Arguments:
Reloc - Pointer to the relocation record
Fixup - Pointer to the address to fix up
FixupData - Pointer to a buffer to log the fixups
Adjust - The offset to adjust the fixup
Returns:
None
--*/
{
UINT64 *F64;
switch ((*Reloc) >> 12) {
case EFI_IMAGE_REL_BASED_DIR64:
F64 = (UINT64 *) Fixup;
*F64 = *F64 + (UINT64) Adjust;
if (*FixupData != NULL) {
*FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));
*(UINT64 *)(*FixupData) = *F64;
*FixupData = *FixupData + sizeof(UINT64);
}
break;
default:
return RETURN_UNSUPPORTED;
}
return RETURN_SUCCESS;
}

View File

@@ -0,0 +1,939 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenSection.c
Abstract:
Creates output file that is a properly formed section per the FV spec.
--*/
#include <Base.h>
#include <UefiBaseTypes.h>
#include "FirmwareVolumeImageFormat.h"
#include "CommonLib.h"
#include "EfiCompress.h"
#include "EfiCustomizedCompress.h"
#include "Crc32.h"
#include "EfiUtilityMsgs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "GenSection.h"
#include <GuidedSectionExtraction.h>
#define UTILITY_NAME "GenSection"
#define PARAMETER_NOT_SPECIFIED "Parameter not specified"
#define MAXIMUM_INPUT_FILE_NUM 10
char *SectionTypeName[] = {
NULL, // 0x00 - reserved
"EFI_SECTION_COMPRESSION", // 0x01
"EFI_SECTION_GUID_DEFINED", // 0x02
NULL, // 0x03 - reserved
NULL, // 0x04 - reserved
NULL, // 0x05 - reserved
NULL, // 0x06 - reserved
NULL, // 0x07 - reserved
NULL, // 0x08 - reserved
NULL, // 0x09 - reserved
NULL, // 0x0A - reserved
NULL, // 0x0B - reserved
NULL, // 0x0C - reserved
NULL, // 0x0D - reserved
NULL, // 0x0E - reserved
NULL, // 0x0F - reserved
"EFI_SECTION_PE32", // 0x10
"EFI_SECTION_PIC", // 0x11
"EFI_SECTION_TE", // 0x12
"EFI_SECTION_DXE_DEPEX", // 0x13
"EFI_SECTION_VERSION", // 0x14
"EFI_SECTION_USER_INTERFACE", // 0x15
"EFI_SECTION_COMPATIBILITY16", // 0x16
"EFI_SECTION_FIRMWARE_VOLUME_IMAGE", // 0x17
"EFI_SECTION_FREEFORM_SUBTYPE_GUID", // 0x18
"EFI_SECTION_RAW", // 0x19
NULL, // 0x1A
"EFI_SECTION_PEI_DEPEX" // 0x1B
};
char *CompressionTypeName[] = { "NONE", "STANDARD" };
char *GUIDedSectionTypeName[] = { "CRC32" };
EFI_GUID gEfiCrc32SectionGuid = EFI_CRC32_GUIDED_SECTION_EXTRACTION_PROTOCOL_GUID;
static
VOID
PrintUsageMessage (
VOID
)
{
UINTN SectionType;
UINTN DisplayCount;
printf ("Usage: "UTILITY_NAME " -i InputFile -o OutputFile -s SectionType [SectionType params]\n\n");
printf (" Where SectionType is one of the following section types:\n\n");
DisplayCount = 0;
for (SectionType = 0; SectionType <= EFI_SECTION_LAST_SECTION_TYPE; SectionType++) {
if (SectionTypeName[SectionType] != NULL) {
printf (" %s\n", SectionTypeName[SectionType]);
}
}
printf ("\n and SectionType dependent parameters are as follows:\n\n");
printf (
" %s: -t < %s | %s >\n",
SectionTypeName[EFI_SECTION_COMPRESSION],
CompressionTypeName[EFI_NOT_COMPRESSED],
CompressionTypeName[EFI_STANDARD_COMPRESSION]
);
printf (
" %s: -t < %s >\n"" // Currently only CRC32 is supported\n\n",
SectionTypeName[EFI_SECTION_GUID_DEFINED],
GUIDedSectionTypeName[EFI_SECTION_CRC32_GUID_DEFINED]
);
printf (
" %s: -v VersionNumber\n"" [-a \"Version string\"]\n\n",
SectionTypeName[EFI_SECTION_VERSION]
);
printf (
" %s: -a \"Human readable name\"\n\n",
SectionTypeName[EFI_SECTION_USER_INTERFACE]
);
}
VOID
Ascii2UnicodeWriteString (
char *String,
FILE *OutFile,
BOOLEAN WriteLangCode
)
{
UINTN Index;
UINT8 AsciiNull;
//
// BUGBUG need to get correct language code...
//
char *EnglishLangCode = "eng";
AsciiNull = 0;
//
// first write the language code (english only)
//
if (WriteLangCode) {
fwrite (EnglishLangCode, 1, 4, OutFile);
}
//
// Next, write out the string... Convert ASCII to Unicode in the process.
//
Index = 0;
do {
fwrite (&String[Index], 1, 1, OutFile);
fwrite (&AsciiNull, 1, 1, OutFile);
} while (String[Index++] != 0);
}
STATUS
GenSectionCommonLeafSection (
char **InputFileName,
int InputFileNum,
UINTN SectionType,
FILE *OutFile
)
/*++
Routine Description:
Generate a leaf section of type other than EFI_SECTION_VERSION
and EFI_SECTION_USER_INTERFACE. Input file must be well formed.
The function won't validate the input file's contents. For
common leaf sections, the input file may be a binary file.
The utility will add section header to the file.
Arguments:
InputFileName - Name of the input file.
InputFileNum - Number of input files. Should be 1 for leaf section.
SectionType - A valid section type string
OutFile - Output file handle
Returns:
STATUS_ERROR - can't continue
STATUS_SUCCESS - successful return
--*/
{
UINT64 InputFileLength;
FILE *InFile;
UINT8 *Buffer;
INTN TotalLength;
EFI_COMMON_SECTION_HEADER CommonSect;
STATUS Status;
if (InputFileNum > 1) {
Error (NULL, 0, 0, "invalid parameter", "more than one input file specified");
return STATUS_ERROR;
} else if (InputFileNum < 1) {
Error (NULL, 0, 0, "no input file specified", NULL);
return STATUS_ERROR;
}
//
// Open the input file
//
InFile = fopen (InputFileName[0], "rb");
if (InFile == NULL) {
Error (NULL, 0, 0, InputFileName[0], "failed to open input file");
return STATUS_ERROR;
}
Status = STATUS_ERROR;
Buffer = NULL;
//
// Seek to the end of the input file so we can determine its size
//
fseek (InFile, 0, SEEK_END);
fgetpos (InFile, &InputFileLength);
fseek (InFile, 0, SEEK_SET);
//
// Fill in the fields in the local section header structure
//
CommonSect.Type = (EFI_SECTION_TYPE) SectionType;
TotalLength = sizeof (CommonSect) + (INTN) InputFileLength;
//
// Size must fit in 3 bytes
//
if (TotalLength >= 0x1000000) {
Error (NULL, 0, 0, InputFileName[0], "file size (0x%X) exceeds section size limit", TotalLength);
goto Done;
}
//
// Now copy the size into the section header and write out the section header
//
memcpy (&CommonSect.Size, &TotalLength, 3);
fwrite (&CommonSect, sizeof (CommonSect), 1, OutFile);
//
// Allocate a buffer to read in the contents of the input file. Then
// read it in as one block and write it to the output file.
//
if (InputFileLength != 0) {
Buffer = (UINT8 *) malloc ((size_t) InputFileLength);
if (Buffer == NULL) {
Error (__FILE__, __LINE__, 0, "memory allocation failure", NULL);
goto Done;
}
if (fread (Buffer, (size_t) InputFileLength, 1, InFile) != 1) {
Error (NULL, 0, 0, InputFileName[0], "failed to read contents of file");
goto Done;
}
if (fwrite (Buffer, (size_t) InputFileLength, 1, OutFile) != 1) {
Error (NULL, 0, 0, "failed to write to output file", NULL);
goto Done;
}
}
Status = STATUS_SUCCESS;
Done:
fclose (InFile);
if (Buffer != NULL) {
free (Buffer);
}
return Status;
}
EFI_STATUS
GetSectionContents (
char **InputFileName,
int InputFileNum,
UINT8 *FileBuffer,
UINTN *BufferLength
)
/*++
Routine Description:
Get the contents of all section files specified in InputFileName
into FileBuffer.
Arguments:
InputFileName - Name of the input file.
InputFileNum - Number of input files. Should be at least 1.
FileBuffer - Output buffer to contain data
BufferLength - Actual length of the data
Returns:
EFI_SUCCESS on successful return
EFI_INVALID_PARAMETER if InputFileNum is less than 1
EFI_ABORTED if unable to open input file.
--*/
{
UINTN Size;
UINTN FileSize;
INTN Index;
FILE *InFile;
if (InputFileNum < 1) {
Error (NULL, 0, 0, "must specify at least one input file", NULL);
return EFI_INVALID_PARAMETER;
}
Size = 0;
//
// Go through our array of file names and copy their contents
// to the output buffer.
//
for (Index = 0; Index < InputFileNum; Index++) {
InFile = fopen (InputFileName[Index], "rb");
if (InFile == NULL) {
Error (NULL, 0, 0, InputFileName[Index], "failed to open input file");
return EFI_ABORTED;
}
fseek (InFile, 0, SEEK_END);
FileSize = ftell (InFile);
fseek (InFile, 0, SEEK_SET);
//
// Now read the contents of the file into the buffer
//
if (FileSize > 0) {
if (fread (FileBuffer + Size, (size_t) FileSize, 1, InFile) != 1) {
Error (NULL, 0, 0, InputFileName[Index], "failed to read contents of input file");
fclose (InFile);
return EFI_ABORTED;
}
}
fclose (InFile);
Size += (UINTN) FileSize;
//
// make sure section ends on a DWORD boundary
//
while ((Size & 0x03) != 0) {
FileBuffer[Size] = 0;
Size++;
}
}
*BufferLength = Size;
return EFI_SUCCESS;
}
EFI_STATUS
GenSectionCompressionSection (
char **InputFileName,
int InputFileNum,
UINTN SectionType,
UINTN SectionSubType,
FILE *OutFile
)
/*++
Routine Description:
Generate an encapsulating section of type EFI_SECTION_COMPRESSION
Input file must be already sectioned. The function won't validate
the input files' contents. Caller should hand in files already
with section header.
Arguments:
InputFileName - Name of the input file.
InputFileNum - Number of input files. Should be at least 1.
SectionType - Section type to generate. Should be
EFI_SECTION_COMPRESSION
SectionSubType - Specify the compression algorithm requested.
OutFile - Output file handle
Returns:
EFI_SUCCESS on successful return
EFI_INVALID_PARAMETER if InputFileNum is less than 1
EFI_ABORTED if unable to open input file.
EFI_OUT_OF_RESOURCES No resource to complete the operation.
--*/
{
UINTN TotalLength;
UINTN InputLength;
UINTN CompressedLength;
UINT8 *FileBuffer;
UINT8 *OutputBuffer;
EFI_STATUS Status;
EFI_COMPRESSION_SECTION CompressionSect;
COMPRESS_FUNCTION CompressFunction;
if (SectionType != EFI_SECTION_COMPRESSION) {
Error (NULL, 0, 0, "parameter must be EFI_SECTION_COMPRESSION", NULL);
return EFI_INVALID_PARAMETER;
}
InputLength = 0;
FileBuffer = NULL;
OutputBuffer = NULL;
CompressedLength = 0;
FileBuffer = (UINT8 *) malloc ((1024 * 1024 * 4) * sizeof (UINT8));
if (FileBuffer == NULL) {
Error (__FILE__, __LINE__, 0, "application error", "failed to allocate memory");
return EFI_OUT_OF_RESOURCES;
}
//
// read all input file contents into a buffer
//
Status = GetSectionContents (
InputFileName,
InputFileNum,
FileBuffer,
&InputLength
);
if (EFI_ERROR (Status)) {
free (FileBuffer);
return Status;
}
CompressFunction = NULL;
//
// Now data is in FileBuffer, compress the data
//
switch (SectionSubType) {
case EFI_NOT_COMPRESSED:
CompressedLength = InputLength;
break;
case EFI_STANDARD_COMPRESSION:
CompressFunction = (COMPRESS_FUNCTION) Compress;
break;
case EFI_CUSTOMIZED_COMPRESSION:
CompressFunction = (COMPRESS_FUNCTION) CustomizedCompress;
break;
default:
Error (NULL, 0, 0, "unknown compression type", NULL);
free (FileBuffer);
return EFI_ABORTED;
}
if (CompressFunction != NULL) {
Status = CompressFunction (FileBuffer, InputLength, OutputBuffer, &CompressedLength);
if (Status == EFI_BUFFER_TOO_SMALL) {
OutputBuffer = malloc (CompressedLength);
if (!OutputBuffer) {
free (FileBuffer);
return EFI_OUT_OF_RESOURCES;
}
Status = CompressFunction (FileBuffer, InputLength, OutputBuffer, &CompressedLength);
}
free (FileBuffer);
FileBuffer = OutputBuffer;
if (EFI_ERROR (Status)) {
if (FileBuffer != NULL) {
free (FileBuffer);
}
return Status;
}
}
TotalLength = CompressedLength + sizeof (EFI_COMPRESSION_SECTION);
//
// Add the section header for the compressed data
//
CompressionSect.CommonHeader.Type = (EFI_SECTION_TYPE) SectionType;
CompressionSect.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);
CompressionSect.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);
CompressionSect.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);
CompressionSect.CompressionType = (UINT8) SectionSubType;
CompressionSect.UncompressedLength = InputLength;
fwrite (&CompressionSect, sizeof (CompressionSect), 1, OutFile);
fwrite (FileBuffer, CompressedLength, 1, OutFile);
free (FileBuffer);
return EFI_SUCCESS;
}
EFI_STATUS
GenSectionGuidDefinedSection (
char **InputFileName,
int InputFileNum,
UINTN SectionType,
UINTN SectionSubType,
FILE *OutFile
)
/*++
Routine Description:
Generate an encapsulating section of type EFI_SECTION_GUID_DEFINED
Input file must be already sectioned. The function won't validate
the input files' contents. Caller should hand in files already
with section header.
Arguments:
InputFileName - Name of the input file.
InputFileNum - Number of input files. Should be at least 1.
SectionType - Section type to generate. Should be
EFI_SECTION_GUID_DEFINED
SectionSubType - Specify the authentication algorithm requested.
OutFile - Output file handle
Returns:
EFI_SUCCESS on successful return
EFI_INVALID_PARAMETER if InputFileNum is less than 1
EFI_ABORTED if unable to open input file.
EFI_OUT_OF_RESOURCES No resource to complete the operation.
--*/
{
INTN TotalLength;
INTN InputLength;
UINT8 *FileBuffer;
UINT32 Crc32Checksum;
EFI_STATUS Status;
CRC32_SECTION_HEADER Crc32GuidSect;
if (SectionType != EFI_SECTION_GUID_DEFINED) {
Error (NULL, 0, 0, "parameter must be EFI_SECTION_GUID_DEFINED", NULL);
return EFI_INVALID_PARAMETER;
}
InputLength = 0;
FileBuffer = NULL;
FileBuffer = (UINT8 *) malloc ((1024 * 1024 * 4) * sizeof (UINT8));
if (FileBuffer == NULL) {
Error (__FILE__, __LINE__, 0, "application error", "failed to allocate memory");
return EFI_OUT_OF_RESOURCES;
}
//
// read all input file contents into a buffer
//
Status = GetSectionContents (
InputFileName,
InputFileNum,
FileBuffer,
&InputLength
);
if (EFI_ERROR (Status)) {
free (FileBuffer);
return Status;
}
//
// Now data is in FileBuffer, compress the data
//
switch (SectionSubType) {
case EFI_SECTION_CRC32_GUID_DEFINED:
Crc32Checksum = 0;
CalculateCrc32 (FileBuffer, InputLength, &Crc32Checksum);
if (EFI_ERROR (Status)) {
free (FileBuffer);
return Status;
}
TotalLength = InputLength + CRC32_SECTION_HEADER_SIZE;
Crc32GuidSect.GuidSectionHeader.CommonHeader.Type = (EFI_SECTION_TYPE) SectionType;
Crc32GuidSect.GuidSectionHeader.CommonHeader.Size[0] = (UINT8) (TotalLength & 0xff);
Crc32GuidSect.GuidSectionHeader.CommonHeader.Size[1] = (UINT8) ((TotalLength & 0xff00) >> 8);
Crc32GuidSect.GuidSectionHeader.CommonHeader.Size[2] = (UINT8) ((TotalLength & 0xff0000) >> 16);
memcpy (&(Crc32GuidSect.GuidSectionHeader.SectionDefinitionGuid), &gEfiCrc32SectionGuid, sizeof (EFI_GUID));
Crc32GuidSect.GuidSectionHeader.Attributes = EFI_GUIDED_SECTION_AUTH_STATUS_VALID;
Crc32GuidSect.GuidSectionHeader.DataOffset = CRC32_SECTION_HEADER_SIZE;
Crc32GuidSect.CRC32Checksum = Crc32Checksum;
break;
default:
Error (NULL, 0, 0, "invalid parameter", "unknown GUID defined type");
free (FileBuffer);
return EFI_ABORTED;
}
fwrite (&Crc32GuidSect, sizeof (Crc32GuidSect), 1, OutFile);
fwrite (FileBuffer, InputLength, 1, OutFile);
free (FileBuffer);
return EFI_SUCCESS;
}
int
main (
int argc,
char *argv[]
)
/*++
Routine Description:
Main
Arguments:
command line parameters
Returns:
EFI_SUCCESS Section header successfully generated and section concatenated.
EFI_ABORTED Could not generate the section
EFI_OUT_OF_RESOURCES No resource to complete the operation.
--*/
{
INTN Index;
INTN VersionNumber;
UINTN SectionType;
UINTN SectionSubType;
BOOLEAN InputFileRequired;
BOOLEAN SubTypeRequired;
FILE *InFile;
FILE *OutFile;
INTN InputFileNum;
char **InputFileName;
char *OutputFileName;
char AuxString[500] = { 0 };
char *ParamSectionType;
char *ParamSectionSubType;
char *ParamLength;
char *ParamVersion;
char *ParamDigitalSignature;
EFI_STATUS Status;
EFI_COMMON_SECTION_HEADER CommonSect;
InputFileName = NULL;
OutputFileName = PARAMETER_NOT_SPECIFIED;
ParamSectionType = PARAMETER_NOT_SPECIFIED;
ParamSectionSubType = PARAMETER_NOT_SPECIFIED;
ParamLength = PARAMETER_NOT_SPECIFIED;
ParamVersion = PARAMETER_NOT_SPECIFIED;
ParamDigitalSignature = PARAMETER_NOT_SPECIFIED;
Status = EFI_SUCCESS;
VersionNumber = 0;
SectionType = 0;
SectionSubType = 0;
InputFileRequired = TRUE;
SubTypeRequired = FALSE;
InFile = NULL;
OutFile = NULL;
InputFileNum = 0;
Status = EFI_SUCCESS;
SetUtilityName (UTILITY_NAME);
if (argc == 1) {
PrintUsageMessage ();
return STATUS_ERROR;
}
//
// Parse command line
//
Index = 1;
while (Index < argc) {
if (strcmpi (argv[Index], "-i") == 0) {
//
// Input File found
//
Index++;
InputFileName = (char **) malloc (MAXIMUM_INPUT_FILE_NUM * sizeof (char *));
if (InputFileName == NULL) {
Error (__FILE__, __LINE__, 0, "application error", "failed to allocate memory");
return EFI_OUT_OF_RESOURCES;
}
memset (InputFileName, 0, (MAXIMUM_INPUT_FILE_NUM * sizeof (char *)));
InputFileName[InputFileNum] = argv[Index];
InputFileNum++;
Index++;
//
// Parse subsequent parameters until another switch is encountered
//
while ((Index < argc) && (argv[Index][0] != '-')) {
if ((InputFileNum % MAXIMUM_INPUT_FILE_NUM) == 0) {
//
// InputFileName buffer too small, need to realloc
//
InputFileName = (char **) realloc (
InputFileName,
(InputFileNum + MAXIMUM_INPUT_FILE_NUM) * sizeof (char *)
);
if (InputFileName == NULL) {
Error (__FILE__, __LINE__, 0, "application error", "failed to allocate memory");
return EFI_OUT_OF_RESOURCES;
}
memset (&(InputFileName[InputFileNum]), 0, (MAXIMUM_INPUT_FILE_NUM * sizeof (char *)));
}
InputFileName[InputFileNum] = argv[Index];
InputFileNum++;
Index++;
}
}
if (strcmpi (argv[Index], "-o") == 0) {
//
// Output file found
//
Index++;
OutputFileName = argv[Index];
} else if (strcmpi (argv[Index], "-s") == 0) {
//
// Section Type found
//
Index++;
ParamSectionType = argv[Index];
} else if (strcmpi (argv[Index], "-t") == 0) {
//
// Compression or Authentication type
//
Index++;
ParamSectionSubType = argv[Index];
} else if (strcmpi (argv[Index], "-l") == 0) {
//
// Length
//
Index++;
ParamLength = argv[Index];
} else if (strcmpi (argv[Index], "-v") == 0) {
//
// VersionNumber
//
Index++;
ParamVersion = argv[Index];
} else if (strcmpi (argv[Index], "-a") == 0) {
//
// Aux string
//
Index++;
//
// Note, the MSVC C-Start parses out and consolidates quoted strings from the command
// line. Quote characters are stripped. If this tool is ported to other environments
// this will need to be taken into account
//
strncpy (AuxString, argv[Index], 499);
} else if (strcmpi (argv[Index], "-d") == 0) {
//
// Digital signature for EFI_TEST_AUTHENTICAION (must be 0 or 1)
//
Index++;
ParamDigitalSignature = argv[Index];
} else if (strcmpi (argv[Index], "-?") == 0) {
PrintUsageMessage ();
return STATUS_ERROR;
} else {
Error (NULL, 0, 0, argv[Index], "unknown option");
return GetUtilityStatus ();
}
Index++;
}
//
// At this point, all command line parameters are verified as not being totally
// bogus. Next verify the command line parameters are complete and make
// sense...
//
if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_COMPRESSION]) == 0) {
SectionType = EFI_SECTION_COMPRESSION;
SubTypeRequired = TRUE;
if (stricmp (ParamSectionSubType, CompressionTypeName[EFI_NOT_COMPRESSED]) == 0) {
SectionSubType = EFI_NOT_COMPRESSED;
} else if (stricmp (ParamSectionSubType, CompressionTypeName[EFI_STANDARD_COMPRESSION]) == 0) {
SectionSubType = EFI_STANDARD_COMPRESSION;
} else {
Error (NULL, 0, 0, ParamSectionSubType, "unknown compression type");
PrintUsageMessage ();
return GetUtilityStatus ();
}
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_GUID_DEFINED]) == 0) {
SectionType = EFI_SECTION_GUID_DEFINED;
SubTypeRequired = TRUE;
if (stricmp (ParamSectionSubType, GUIDedSectionTypeName[EFI_SECTION_CRC32_GUID_DEFINED]) == 0) {
SectionSubType = EFI_SECTION_CRC32_GUID_DEFINED;
} else {
Error (NULL, 0, 0, ParamSectionSubType, "unknown GUID defined section type", ParamSectionSubType);
PrintUsageMessage ();
return GetUtilityStatus ();
}
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_PE32]) == 0) {
SectionType = EFI_SECTION_PE32;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_PIC]) == 0) {
SectionType = EFI_SECTION_PIC;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_TE]) == 0) {
SectionType = EFI_SECTION_TE;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_DXE_DEPEX]) == 0) {
SectionType = EFI_SECTION_DXE_DEPEX;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_VERSION]) == 0) {
SectionType = EFI_SECTION_VERSION;
InputFileRequired = FALSE;
Index = sscanf (ParamVersion, "%d", &VersionNumber);
if (Index != 1 || VersionNumber < 0 || VersionNumber > 65565) {
Error (NULL, 0, 0, ParamVersion, "illegal version number");
PrintUsageMessage ();
return GetUtilityStatus ();
}
if (strcmp (AuxString, PARAMETER_NOT_SPECIFIED) == 0) {
AuxString[0] = 0;
}
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_USER_INTERFACE]) == 0) {
SectionType = EFI_SECTION_USER_INTERFACE;
InputFileRequired = FALSE;
if (strcmp (AuxString, PARAMETER_NOT_SPECIFIED) == 0) {
Error (NULL, 0, 0, "user interface string not specified", NULL);
PrintUsageMessage ();
return GetUtilityStatus ();
}
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_COMPATIBILITY16]) == 0) {
SectionType = EFI_SECTION_COMPATIBILITY16;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_FIRMWARE_VOLUME_IMAGE]) == 0) {
SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_FREEFORM_SUBTYPE_GUID]) == 0) {
SectionType = EFI_SECTION_FREEFORM_SUBTYPE_GUID;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_RAW]) == 0) {
SectionType = EFI_SECTION_RAW;
} else if (stricmp (ParamSectionType, SectionTypeName[EFI_SECTION_PEI_DEPEX]) == 0) {
SectionType = EFI_SECTION_PEI_DEPEX;
} else {
Error (NULL, 0, 0, ParamSectionType, "unknown section type");
PrintUsageMessage ();
return GetUtilityStatus ();
}
//
// Open output file
//
OutFile = fopen (OutputFileName, "wb");
if (OutFile == NULL) {
Error (NULL, 0, 0, OutputFileName, "failed to open output file for writing");
if (InFile != NULL) {
fclose (InFile);
}
return GetUtilityStatus ();
}
//
// At this point, we've fully validated the command line, and opened appropriate
// files, so let's go and do what we've been asked to do...
//
//
// Within this switch, build and write out the section header including any
// section type specific pieces. If there's an input file, it's tacked on later
//
switch (SectionType) {
case EFI_SECTION_COMPRESSION:
Status = GenSectionCompressionSection (
InputFileName,
InputFileNum,
SectionType,
SectionSubType,
OutFile
);
break;
case EFI_SECTION_GUID_DEFINED:
Status = GenSectionGuidDefinedSection (
InputFileName,
InputFileNum,
SectionType,
SectionSubType,
OutFile
);
break;
case EFI_SECTION_VERSION:
CommonSect.Type = (EFI_SECTION_TYPE) SectionType;
Index = sizeof (CommonSect);
//
// 2 characters for the build number
//
Index += 2;
//
// Aux string is ascii.. unicode is 2X + 2 bytes for terminating unicode null.
//
Index += (strlen (AuxString) * 2) + 2;
memcpy (&CommonSect.Size, &Index, 3);
fwrite (&CommonSect, sizeof (CommonSect), 1, OutFile);
fwrite (&VersionNumber, 2, 1, OutFile);
Ascii2UnicodeWriteString (AuxString, OutFile, FALSE);
break;
case EFI_SECTION_USER_INTERFACE:
CommonSect.Type = (EFI_SECTION_TYPE) SectionType;
Index = sizeof (CommonSect);
//
// Aux string is ascii.. unicode is 2X + 2 bytes for terminating unicode null.
//
Index += (strlen (AuxString) * 2) + 2;
memcpy (&CommonSect.Size, &Index, 3);
fwrite (&CommonSect, sizeof (CommonSect), 1, OutFile);
Ascii2UnicodeWriteString (AuxString, OutFile, FALSE);
break;
default:
//
// All other section types are caught by default (they're all the same)
//
Status = GenSectionCommonLeafSection (
InputFileName,
InputFileNum,
SectionType,
OutFile
);
break;
}
if (InputFileName != NULL) {
free (InputFileName);
}
fclose (OutFile);
//
// If we had errors, then delete the output file
//
if (GetUtilityStatus () == STATUS_ERROR) {
remove (OutputFileName);
}
return GetUtilityStatus ();
}

View File

@@ -0,0 +1,43 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GenSection.h
Abstract:
Header file for GenSection.
--*/
//
// Module Coded to Tiano Coding Conventions
//
#ifndef _EFI_GEN_SECTION_H
#define _EFI_GEN_SECTION_H
//
// External Files Referenced
//
#include <Base.h>
#include <UefiBaseTypes.h>
#include "FirmwareVolumeImageFormat.h"
typedef struct {
EFI_GUID_DEFINED_SECTION GuidSectionHeader;
UINT32 CRC32Checksum;
} CRC32_SECTION_HEADER;
#define EFI_SECTION_CRC32_GUID_DEFINED 0
#define CRC32_SECTION_HEADER_SIZE (sizeof (CRC32_SECTION_HEADER))
#endif

View File

@@ -0,0 +1 @@
gcc -mno-cygwin -I "$WORKSPACE/MdePkg/Include/" -I"$WORKSPACE/MdePkg/Include/Ia32/" -I"../Common/" -I$WORKSPACE/MdePkg/Include/Protocol/ -I$WORKSPACE/MdePkg/Include/Common/ *.c -o GenSection -L../Library-mingw -lCommon -lCustomizedCompress

View File

@@ -0,0 +1,119 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GenSection Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GenSection"/>
<property name="FileSet" value="GenSection.c"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="Building the EDK Tool: ${ToolName}"/>
</target>
<target name="init">
<echo message="The EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>
Unsupported Operating System
Please Contact Intel Corporation
</echo>
</else>
</if>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
<property name="ext_exe" value=".exe"/>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
<property name="ext_exe" value=""/>
</then>
</elseif>
</if>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools.lib"/>
<linkerarg value="${LIB_DIR}/CustomizedCompress.lib"/>
</cc>
</target>
<target name="clean" depends="init">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall" depends="init">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete dir="${BUILD_DIR}">
<fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,57 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CommonUtils.h
Abstract:
Common utility defines and structure definitions.
--*/
#ifndef _COMMON_UTILS_H_
#define _COMMON_UTILS_H_
//
// Basic types
//
typedef unsigned char UINT8;
typedef char INT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
typedef UINT8 BOOLEAN;
typedef UINT32 STATUS;
#define TRUE 1
#define FALSE 0
#define STATUS_SUCCESS 0
#define STATUS_WARNING 1
#define STATUS_ERROR 2
//
// Linked list of strings
//
typedef struct _STRING_LIST {
struct _STRING_LIST *Next;
char *Str;
} STRING_LIST;
int
CreateGuidList (
INT8 *OutFileName
)
;
#endif // #ifndef _COMMON_UTILS_H_

View File

@@ -0,0 +1,285 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FileSearch.c
Abstract:
Module used to support file searches on the system.
--*/
#include <stdio.h>
#include "CommonUtils.h"
#include "FileSearch.h"
#include "UtilsMsgs.h"
//
// Internal file search flag for sanity checks
//
#define FILE_SEARCH_STARTED 0x8000
#define FILE_SEARCH_INITED 0x4000
static
BOOLEAN
FileSearchMeetsCriteria (
FILE_SEARCH_DATA *FSData
);
/*****************************************************************************/
STATUS
FileSearchInit (
FILE_SEARCH_DATA *FSData
)
{
memset ((char *) FSData, 0, sizeof (FILE_SEARCH_DATA));
FSData->Handle = INVALID_HANDLE_VALUE;
FSData->FileSearchFlags = FILE_SEARCH_INITED;
FSData->FileName[0] = 0;
return STATUS_SUCCESS;
}
STATUS
FileSearchStart (
FILE_SEARCH_DATA *FSData,
char *FileMask,
UINT32 SearchFlags
)
{
BOOLEAN Done;
//
// Save their flags, and set a flag to indicate that they called this
// start function so we can perform extended checking in the other
// routines we have in this module.
//
FSData->FileSearchFlags |= (SearchFlags | FILE_SEARCH_STARTED);
FSData->FileName[0] = 0;
//
// Begin the search
//
FSData->Handle = FindFirstFile (FileMask, &(FSData->FindData));
if (FSData->Handle == INVALID_HANDLE_VALUE) {
return STATUS_ERROR;
}
//
// Keep looping through until we find a file meeting the caller's
// criteria per the search flags
//
Done = FALSE;
while (!Done) {
//
// If we're done (we found a match) copy the file name found and return
//
Done = FileSearchMeetsCriteria (FSData);
if (Done) {
return STATUS_SUCCESS;
}
//
// Go on to next file
//
if (!FindNextFile (FSData->Handle, &(FSData->FindData))) {
return STATUS_NOT_FOUND;
}
}
//
// Not reached
//
return STATUS_NOT_FOUND;
}
//
// Find the next file meeting their criteria and return it.
//
STATUS
FileSearchFindNext (
FILE_SEARCH_DATA *FSData
)
{
BOOLEAN Done;
Done = FALSE;
while (!Done) {
if (!FindNextFile (FSData->Handle, &(FSData->FindData))) {
return STATUS_NOT_FOUND;
}
//
// See if it matches their criteria
//
Done = FileSearchMeetsCriteria (FSData);
if (Done) {
return STATUS_SUCCESS;
}
}
//
// Not reached
//
return STATUS_NOT_FOUND;
}
//
// Perform any cleanup necessary to close down a search
//
STATUS
FileSearchDestroy (
FILE_SEARCH_DATA *FSData
)
{
if (FSData->Handle != INVALID_HANDLE_VALUE) {
FindClose (FSData->Handle);
FSData->Handle = INVALID_HANDLE_VALUE;
}
FSData->FileName[0] = 0;
FSData->FileSearchFlags = 0;
return STATUS_SUCCESS;
}
static
BOOLEAN
FileSearchMeetsCriteria (
FILE_SEARCH_DATA *FSData
)
{
BOOLEAN Status;
STRING_LIST *StrList;
UINT32 ExtLen;
UINT32 FileNameLen;
Status = FALSE;
//
// First clear the flag indicating this is neither a file or a
// directory.
//
FSData->FileFlags &= ~(FILE_SEARCH_DIR | FILE_SEARCH_FILE);
//
// We found a file. See if it matches the user's search criteria. First
// check for this being a directory, and they want directories, and
// it's not "." and it's not ".."
//
if ((FSData->FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
(FSData->FileSearchFlags & FILE_SEARCH_DIR) &&
(strcmp (FSData->FindData.cFileName, ".")) &&
(strcmp (FSData->FindData.cFileName, ".."))
) {
//
// Assume we'll make it past this check
//
Status = TRUE;
//
// If they have a list of exclude directories, then check for those
//
StrList = FSData->ExcludeDirs;
while (StrList != NULL) {
if (stricmp (FSData->FindData.cFileName, StrList->Str) == 0) {
Status = FALSE;
break;
}
StrList = StrList->Next;
}
//
// If we didn't fail due to excluded directories, then set the dir flag
//
if (Status) {
FSData->FileFlags |= FILE_SEARCH_DIR;
}
//
// Else check for a file, and they want files....
//
} else if (((FSData->FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) &&
(FSData->FileSearchFlags & FILE_SEARCH_FILE)
) {
//
// See if it's in our list of excluded files
//
Status = TRUE;
StrList = FSData->ExcludeFiles;
while (StrList != NULL) {
if (stricmp (FSData->FindData.cFileName, StrList->Str) == 0) {
Status = FALSE;
break;
}
StrList = StrList->Next;
}
if (Status) {
//
// See if it's in our list of excluded file extensions
//
FileNameLen = strlen (FSData->FindData.cFileName);
StrList = FSData->ExcludeExtensions;
while (StrList != NULL) {
ExtLen = strlen (StrList->Str);
if (stricmp (
FSData->FindData.cFileName + FileNameLen - ExtLen,
StrList->Str
) == 0) {
Status = FALSE;
break;
}
StrList = StrList->Next;
}
}
if (Status) {
FSData->FileFlags |= FILE_SEARCH_FILE;
}
}
//
// If it's a match, copy the filename into another field of the structure
// for portability.
//
if (Status) {
strcpy (FSData->FileName, FSData->FindData.cFileName);
}
return Status;
}
//
// Exclude a list of subdirectories.
//
STATUS
FileSearchExcludeDirs (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
{
FSData->ExcludeDirs = StrList;
return STATUS_SUCCESS;
}
STATUS
FileSearchExcludeFiles (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
{
FSData->ExcludeFiles = StrList;
return STATUS_SUCCESS;
}
STATUS
FileSearchExcludeExtensions (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
{
FSData->ExcludeExtensions = StrList;
return STATUS_SUCCESS;
}

View File

@@ -0,0 +1,108 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FileSearch.h
Abstract:
Header file to support file searching.
--*/
#ifndef _FILE_SEARCH_H_
#define _FILE_SEARCH_H_
//
// Since the file searching routines are OS dependent, put the
// necessary include paths in this header file so that the non-OS-dependent
// files don't need to include these windows-specific header files.
//
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <direct.h>
#include <windows.h>
//
// Return codes of some of the file search routines
//
#define STATUS_NOT_FOUND 0x1000
//
// Flags for what to search for. Also used in the FileFlags return field.
//
#define FILE_SEARCH_DIR 0x0001
#define FILE_SEARCH_FILE 0x0002
//
// Here's our class definition
//
typedef struct {
HANDLE Handle;
WIN32_FIND_DATA FindData;
UINT32 FileSearchFlags; // DIRS, FILES, etc
UINT32 FileFlags;
INT8 FileName[MAX_PATH]; // for portability
STRING_LIST *ExcludeDirs;
STRING_LIST *ExcludeFiles;
STRING_LIST *ExcludeExtensions;
} FILE_SEARCH_DATA;
//
// Here's our member functions
//
STATUS
FileSearchInit (
FILE_SEARCH_DATA *FSData
)
;
STATUS
FileSearchDestroy (
FILE_SEARCH_DATA *FSData
)
;
STATUS
FileSearchStart (
FILE_SEARCH_DATA *FSData,
char *FileMask,
UINT32 SearchFlags
)
;
STATUS
FileSearchFindNext (
FILE_SEARCH_DATA *FSData
)
;
STATUS
FileSearchExcludeDirs (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
;
STATUS
FileSearchExcludeExtensions (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
;
STATUS
FileSearchExcludeFiles (
FILE_SEARCH_DATA *FSData,
STRING_LIST *StrList
)
;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,188 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GuidList.c
Abstract:
Utility to create a GUID-to-name listing file that can
be used by other utilities. Basic operation is to take the
table of name+GUIDs that we have compiled into this utility,
and create a text file that can be parsed by other utilities
to do replacement of "name" with "GUID".
Notes:
To add a new GUID to this database:
1. Add a "#include EFI_GUID_DEFINITION(name)" statement below
2. Modify the mGuidList[] array below to add the new GUID name
The only issue that may come up is that, if the source GUID file
is not in the standard GUID directory, then this utility won't
compile because the #include fails. In this case you'd need
to define a new macro (if it's in a standard place) or modify
this utility's makefile to add the path to your new .h file.
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <Base.h>
#include <UefiBaseTypes.h>
#include <UgaDraw.h>
#include "EfiUtilityMsgs.h"
#include <Apriori.h>
#include <AcpiTableStorage.h>
// #include <Bmp.h>
#define GUID_XREF(varname, guid) { \
#varname, #guid, guid \
}
#define NULL_GUID \
{ \
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 \
}
typedef struct {
INT8 *VariableName;
INT8 *DefineName;
EFI_GUID Guid;
} GUID_LIST;
//
// This is our table of all GUIDs we want to print out to create
// a GUID-to-name cross reference.
// Use the #defined name from the GUID definition's source .h file.
//
static GUID_LIST mGuidList[] = {
GUID_XREF(gAprioriGuid, EFI_APRIORI_GUID),
GUID_XREF(gEfiAcpiTableStorageGuid, EFI_ACPI_TABLE_STORAGE_GUID),
// FIXME The next line was removed in the port to R9.
// GUID_XREF(gEfiDefaultBmpLogoGuid, EFI_DEFAULT_BMP_LOGO_GUID),
GUID_XREF(gEfiAcpiTableStorageGuid, EFI_ACPI_TABLE_STORAGE_GUID),
//
// Terminator
//
{
NULL,
NULL,
NULL_GUID
}
};
void
PrintGuidText (
FILE *OutFptr,
INT8 *VariableName,
INT8 *DefineName,
EFI_GUID *Guid
);
int
CreateGuidList (
INT8 *OutFileName
)
/*++
Routine Description:
Print our GUID/name list to the specified output file.
Arguments:
OutFileName - name of the output file to write our results to.
Returns:
0 if successful
nonzero otherwise
--*/
{
FILE *OutFptr;
int Index;
//
// Open output file for writing. If the name is NULL, then write to stdout
//
if (OutFileName != NULL) {
OutFptr = fopen (OutFileName, "w");
if (OutFptr == NULL) {
Error (NULL, 0, 0, OutFileName, "failed to open output file for writing");
return STATUS_ERROR;
}
} else {
OutFptr = stdout;
}
for (Index = 0; mGuidList[Index].VariableName != NULL; Index++) {
PrintGuidText (OutFptr, mGuidList[Index].VariableName, mGuidList[Index].DefineName, &mGuidList[Index].Guid);
}
//
// Close the output file if they specified one.
//
if (OutFileName != NULL) {
fclose (OutFptr);
}
return STATUS_SUCCESS;
}
void
PrintGuidText (
FILE *OutFptr,
INT8 *VariableName,
INT8 *DefineName,
EFI_GUID *Guid
)
/*++
Routine Description:
Print a GUID/name combo in INF-style format
guid-guid-guid-guid DEFINE_NAME gName
Arguments:
OutFptr - file pointer to which to write the output
VariableName - the GUID variable's name
DefineName - the name used in the #define
Guid - pointer to the GUID value
Returns:
NA
--*/
{
if (OutFptr == NULL) {
OutFptr = stdout;
}
fprintf (
OutFptr,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X %s %s\n",
Guid->Data1,
Guid->Data2,
Guid->Data3,
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7],
DefineName,
VariableName
);
}

View File

@@ -0,0 +1,490 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
UtilsMsgs.c
Abstract:
EFI tools utility functions to display warning, error, and informational
messages.
--*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <Base.h>
#include <UefiBaseTypes.h>
#include "EfiUtilityMsgs.h"
#define MAX_LINE_LEN 200
//
// Declare module globals for keeping track of the the utility's
// name and other settings.
//
static STATUS mStatus = STATUS_SUCCESS;
static INT8 mUtilityName[50] = { 0 };
static INT8 *mSourceFileName = NULL;
static UINT32 mSourceFileLineNum = 0;
static UINT32 mErrorCount = 0;
static UINT32 mWarningCount = 0;
static UINT32 mDebugMsgMask = 0;
static
void
PrintMessage (
INT8 *Type,
INT8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
va_list List
);
void
Error (
INT8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Prints an error message.
Arguments:
All arguments are optional, though the printed message may be useless if
at least something valid is not specified.
FileName - name of the file or application. If not specified, then the
utilty name (as set by the utility calling SetUtilityName()
earlier) is used. Otherwise "Unknown utility" is used.
LineNumber - the line number of error, typically used by parsers. If the
utility is not a parser, then 0 should be specified. Otherwise
the FileName and LineNumber info can be used to cause
MS Visual Studio to jump to the error.
MessageCode - an application-specific error code that can be referenced in
other documentation.
Text - the text in question, typically used by parsers.
MsgFmt - the format string for the error message. Can contain formatting
controls for use with the varargs.
Returns:
None.
Notes:
We print the following (similar to the Warn() and Debug()
W
Typical error/warning message format:
bin\VfrCompile.cpp(330) : error C2660: 'AddVfrDataStructField' : function does not take 2 parameters
BUGBUG -- these three utility functions are almost identical, and
should be modified to share code.
Visual Studio does not find error messages with:
" error :"
" error 1:"
" error c1:"
" error 1000:"
" error c100:"
It does find:
" error c1000:"
--*/
{
va_list List;
mErrorCount++;
va_start (List, MsgFmt);
PrintMessage ("error", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_ERROR) {
mStatus = STATUS_ERROR;
}
}
void
ParserError (
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Print a parser error, using the source file name and line number
set by a previous call to SetParserPosition().
Arguments:
MessageCode - application-specific error code
Text - text to print in the error message
MsgFmt - format string to print at the end of the error message
...
Returns:
NA
--*/
{
va_list List;
mErrorCount++;
va_start (List, MsgFmt);
PrintMessage ("error", mSourceFileName, mSourceFileLineNum, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_ERROR) {
mStatus = STATUS_ERROR;
}
}
void
ParserWarning (
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Print a parser warning, using the source file name and line number
set by a previous call to SetParserPosition().
Arguments:
ErrorCode - application-specific error code
OffendingText - text to print in the warning message
MsgFmt - format string to print at the end of the warning message
...
Returns:
NA
--*/
{
va_list List;
mWarningCount++;
va_start (List, MsgFmt);
PrintMessage ("warning", mSourceFileName, mSourceFileLineNum, ErrorCode, OffendingText, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_WARNING) {
mStatus = STATUS_WARNING;
}
}
void
Warning (
INT8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Print a warning message.
Arguments:
FileName - name of the file where the warning was detected, or the name
of the application that detected the warning
LineNumber - the line number where the warning was detected (parsers).
0 should be specified if the utility is not a parser.
MessageCode - an application-specific warning code that can be referenced in
other documentation.
Text - the text in question (parsers)
MsgFmt - the format string for the warning message. Can contain formatting
controls for use with varargs.
...
Returns:
None.
--*/
{
va_list List;
mWarningCount++;
va_start (List, MsgFmt);
PrintMessage ("warning", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
va_end (List);
//
// Set status accordingly
//
if (mStatus < STATUS_WARNING) {
mStatus = STATUS_WARNING;
}
}
void
DebugMsg (
INT8 *FileName,
UINT32 LineNumber,
UINT32 MsgMask,
INT8 *Text,
INT8 *MsgFmt,
...
)
/*++
Routine Description:
Print a warning message.
Arguments:
FileName - typically the name of the utility printing the debug message, but
can be the name of a file being parsed.
LineNumber - the line number in FileName (parsers)
MsgMask - an application-specific bitmask that, in combination with mDebugMsgMask,
determines if the debug message gets printed.
Text - the text in question (parsers)
MsgFmt - the format string for the debug message. Can contain formatting
controls for use with varargs.
...
Returns:
None.
--*/
{
va_list List;
//
// If the debug mask is not applicable, then do nothing.
//
if ((MsgMask != 0) && ((mDebugMsgMask & MsgMask) == 0)) {
return ;
}
va_start (List, MsgFmt);
PrintMessage ("debug", FileName, LineNumber, 0, Text, MsgFmt, List);
va_end (List);
}
static
void
PrintMessage (
INT8 *Type,
INT8 *FileName,
UINT32 LineNumber,
UINT32 MessageCode,
INT8 *Text,
INT8 *MsgFmt,
va_list List
)
/*++
Routine Description:
Worker routine for all the utility printing services. Prints the message in
a format that Visual Studio will find when scanning build outputs for
errors or warnings.
Arguments:
Type - "warning" or "error" string to insert into the message to be
printed. The first character of this string (converted to uppercase)
is used to preceed the MessageCode value in the output string.
FileName - name of the file where the warning was detected, or the name
of the application that detected the warning
LineNumber - the line number where the warning was detected (parsers).
0 should be specified if the utility is not a parser.
MessageCode - an application-specific warning code that can be referenced in
other documentation.
Text - part of the message to print
MsgFmt - the format string for the message. Can contain formatting
controls for use with varargs.
List - Variable function parameter list.
Returns:
None.
Notes:
If FileName == NULL then this utility will use the string passed into SetUtilityName().
LineNumber is only used if the caller is a parser, in which case FileName refers to the
file being parsed.
Text and MsgFmt are both optional, though it would be of little use calling this function with
them both NULL.
Output will typically be of the form:
<FileName>(<LineNumber>) : <Type> <Type[0]><MessageCode>: <Text> : <MsgFmt>
Parser (LineNumber != 0)
VfrCompile.cpp(330) : error E2660: AddVfrDataStructField : function does not take 2 parameters
Generic utility (LineNumber == 0)
UtilityName : error E1234 : Text string : MsgFmt string and args
--*/
{
INT8 Line[MAX_LINE_LEN];
INT8 Line2[MAX_LINE_LEN];
INT8 *Cptr;
//
// If given a filename, then add it (and the line number) to the string.
// If there's no filename, then use the program name if provided.
//
if (FileName != NULL) {
Cptr = FileName;
} else if (mUtilityName[0] != 0) {
Cptr = mUtilityName;
} else {
Cptr = "Unknown utility";
}
strcpy (Line, Cptr);
if (LineNumber != 0) {
sprintf (Line2, "(%d)", LineNumber);
strcat (Line, Line2);
}
//
// Have to print an error code or Visual Studio won't find the
// message for you. It has to be decimal digits too.
//
sprintf (Line2, " : %s %c%04d", Type, toupper (Type[0]), MessageCode);
strcat (Line, Line2);
fprintf (stdout, "%s", Line);
//
// If offending text was provided, then print it
//
if (Text != NULL) {
fprintf (stdout, ": %s ", Text);
}
//
// Print formatted message if provided
//
if (MsgFmt != NULL) {
vsprintf (Line2, MsgFmt, List);
fprintf (stdout, ": %s", Line2);
}
fprintf (stdout, "\n");
}
void
ParserSetPosition (
INT8 *SourceFileName,
UINT32 LineNum
)
/*++
Routine Description:
Set the position in a file being parsed. This can be used to
print error messages deeper down in a parser.
Arguments:
SourceFileName - name of the source file being parsed
LineNum - line number of the source file being parsed
Returns:
NA
--*/
{
mSourceFileName = SourceFileName;
mSourceFileLineNum = LineNum;
}
void
SetUtilityName (
INT8 *UtilityName
)
/*++
Routine Description:
All printed error/warning/debug messages follow the same format, and
typically will print a filename or utility name followed by the error
text. However if a filename is not passed to the print routines, then
they'll print the utility name if you call this function early in your
app to set the utility name.
Arguments:
UtilityName - name of the utility, which will be printed with all
error/warning/debug messags.
Returns:
NA
--*/
{
//
// Save the name of the utility in our local variable. Make sure its
// length does not exceed our buffer.
//
if (UtilityName != NULL) {
if (strlen (UtilityName) >= sizeof (mUtilityName)) {
Error (UtilityName, 0, 0, "application error", "utility name length exceeds internal buffer size");
strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1);
mUtilityName[sizeof (mUtilityName) - 1] = 0;
return ;
} else {
strcpy (mUtilityName, UtilityName);
}
} else {
Error (NULL, 0, 0, "application error", "SetUtilityName() called with NULL utility name");
}
}
STATUS
GetUtilityStatus (
VOID
)
/*++
Routine Description:
When you call Error() or Warning(), this module keeps track of it and
sets a local mStatus to STATUS_ERROR or STATUS_WARNING. When the utility
exits, it can call this function to get the status and use it as a return
value.
Arguments:
None.
Returns:
Worst-case status reported, as defined by which print function was called.
--*/
{
return mStatus;
}

View File

@@ -0,0 +1,106 @@
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
UtilsMsgs.h
Abstract:
Prototypes for the EFI tools utility functions.
--*/
#ifndef _UTILS_MESSAGES_H_
#define _UTILS_MESSAGES_H_
STATUS
GetUtilityStatus (
VOID
)
;
//
// If someone prints an error message and didn't specify a source file name,
// then we print the utility name instead. However they must tell us the
// utility name early on via this function.
//
VOID
SetUtilityName (
INT8 *ProgramName
)
;
void
Error (
INT8 *FileName,
UINT32 LineNumber,
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
void
Warning (
INT8 *FileName,
UINT32 LineNumber,
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
void
DebugMsg (
INT8 *FileName,
UINT32 LineNumber,
UINT32 MsgLevel,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
void
SetDebugMsgMask (
UINT32 MsgMask
)
;
void
ParserSetPosition (
INT8 *SourceFileName,
UINT32 LineNum
)
;
void
ParserError (
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
void
ParserWarning (
UINT32 ErrorCode,
INT8 *OffendingText,
INT8 *MsgFmt,
...
)
;
#endif

View File

@@ -0,0 +1 @@
gcc -mno-cygwin -I../Common/ -I/workspace/mdk/MdePkg/Include/Guid -I/workspace/mdk/MdePkg/Include/Protocol/ -I/workspace/mdk/MdePkg/Include/Common/ -I/workspace/mdk/MdePkg/Include/ -I/workspace/mdk/MdePkg/Include/Ia32 -I. GuidChk.c GuidList.c UtilsMsgs.c -o GuidChk.exe

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" ?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<project default="GenTool" basedir=".">
<!--
EDK GuidChk Tool
Copyright (c) 2006, Intel Corporation
-->
<property name="ToolName" value="GuidChk"/>
<property name="FileSet" value="*.c *.h"/>
<taskdef resource="cpptasks.tasks"/>
<typedef resource="cpptasks.types"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="LINK_OUTPUT_TYPE" value="static"/>
<property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
<target name="GenTool" depends="init, Tool">
<echo message="Building the EDK Tool: ${ToolName}"/>
</target>
<target name="init">
<echo message="The EDK Tool: ${ToolName}"/>
<mkdir dir="${BUILD_DIR}"/>
<if>
<equals arg1="${GCC}" arg2="cygwin"/>
<then>
<echo message="Cygwin Family"/>
<property name="ToolChain" value="gcc"/>
</then>
<elseif>
<os family="dos"/>
<then>
<echo message="Windows Family"/>
<property name="ToolChain" value="msvc"/>
</then>
</elseif>
<elseif>
<os family="unix"/>
<then>
<echo message="UNIX Family"/>
<property name="ToolChain" value="gcc"/>
</then>
</elseif>
<else>
<echo>
Unsupported Operating System
Please Contact Intel Corporation
</echo>
</else>
</if>
<if>
<equals arg1="${ToolChain}" arg2="msvc"/>
<then>
<property name="ext_static" value=".lib"/>
<property name="ext_dynamic" value=".dll"/>
<property name="ext_exe" value=".exe"/>
</then>
<elseif>
<equals arg1="${ToolChain}" arg2="gcc"/>
<then>
<property name="ext_static" value=".a"/>
<property name="ext_dynamic" value=".so"/>
<property name="ext_exe" value=""/>
</then>
</elseif>
</if>
</target>
<target name="Tool" depends="init">
<cc name="${ToolChain}" objdir="${BUILD_DIR}"
outfile="${BIN_DIR}/${ToolName}"
outtype="executable"
libtool="${haveLibtool}"
optimize="speed">
<fileset dir="${basedir}/${ToolName}"
includes="${FileSet}"
defaultexcludes="TRUE"
excludes="*.xml *.inf"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Guid"/>
<includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>
<includepath path="${PACKAGE_DIR}/Common"/>
<linkerarg value="${LIB_DIR}/CommonTools.lib"/>
<linkerarg value="${LIB_DIR}/CustomizedCompress.lib"/>
</cc>
</target>
<target name="clean" depends="init">
<echo message="Removing Intermediate Files Only"/>
<delete>
<fileset dir="${BUILD_DIR}" includes="*.obj"/>
</delete>
</target>
<target name="cleanall" depends="init">
<echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
<delete dir="${BUILD_DIR}">
<fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,522 @@
CHANGES FROM 1.31
This file contains the migration of PCCTS from 1.31 in the order that
changes were made. 1.32b7 is the last beta before full 1.32.
Terence Parr, Parr Research Corporation 1995.
======================================================================
1.32b1
Added Russell Quong to banner, changed banner for output slightly
Fixed it so that you have before / after actions for C++ in class def
Fixed bug in optimizer that made it sometimes forget to set internal
token pointers. Only showed up when a {...} was in the "wrong spot".
======================================================================
1.32b2
Added fixes by Dave Seidel for PC compilers in 32 bit mode (config.h
and set.h).
======================================================================
1.32b3
Fixed hideous bug in code generator for wildcard and for ~token op.
from Dave Seidel
Added pcnames.bat
1. in antlr/main.c: change strcasecmp() to stricmp()
2. in dlg/output.c: use DLEXER_C instead on "DLexer.C"
3. in h/PBlackBox.h: use <iostream.h> instead of <stream.h>
======================================================================
1.32b4
When the -ft option was used, any path prefix screwed up
the gate on the .h files
Fixed yet another bug due to the optimizer.
The exception handling thing was a bit wacko:
a : ( A B )? A B
| A C
;
exception ...
caused an exception if "A C" was the input. In other words,
it found that A C didn't match the (A B)? pred and caused
an exception rather than trying the next alt. All I did
was to change the zzmatch_wsig() macros.
Fixed some problems in gen.c relating to the name of token
class bit sets in the output.
Added the tremendously cool generalized predicate. For the
moment, I'll give this bried description.
a : <<predicate>>? blah
| foo
;
This implies that (assuming blah and foo are syntactically
ambiguous) "predicate" indicates the semantic validity of
applying "blah". If "predicate" is false, "foo" is attempted.
Previously, you had to say:
a : <<LA(1)==ID ? predicate : 1>>? ID
| ID
;
Now, you can simply use "predicate" without the ?: operator
if you turn on ANTLR command line option: "-prc on". This
tells ANTLR to compute that all by itself. It computes n
tokens of lookahead where LT(n) or LATEXT(n) is the farthest
ahead you look.
If you give a predicate using "-prc on" that is followed
by a construct that can recognize more than one n-sequence,
you will get a warning from ANTLR. For example,
a : <<isTypeName(LT(1)->getText())>>? (ID|INT)
;
This is wrong because the predicate will be applied to INTs
as well as ID's. You should use this syntax to make
the predicate more specific:
a : (ID)? => <<isTypeName(LT(1)->getText())>>? (ID|INT)
;
which says "don't apply the predicate unless ID is the
current lookahead context".
You cannot currently have anything in the "(context)? =>"
except sequences such as:
( LPAREN ID | LPAREN SCOPE )? => <<pred>>?
I haven't tested this THAT much, but it does work for the
C++ grammar.
======================================================================
1.32b5
Added getLine() to the ANTLRTokenBase and DLGBasedToken classes
left line() for backward compatibility.
----
Removed SORCERER_TRANSFORM from the ast.h stuff.
-------
Fixed bug in code gen of ANTLR such that nested syn preds work more
efficiently now. The ANTLRTokenBuffer was getting very large
with nested predicates.
------
Memory leak is now gone from ANTLRTokenBuf; all tokens are deleted.
For backward compatibility reasons, you have to say parser->deleteTokens()
or mytokenbuffer->deleteTokens() but later it will be the default mode.
Say this after the parser is constructed. E.g.,
ParserBlackBox<DLGLexer, MyParser, ANTLRToken> p(stdin);
p.parser()->deleteTokens();
p.parser()->start_symbol();
==============================
1.32b6
Changed so that deleteTokens() will do a delete ((ANTLRTokenBase *))
on the ptr. This gets the virtual destructor.
Fixed some weird things in the C++ header files (a few return types).
Made the AST routines correspond to the book and SORCERER stuff.
New token stuff: See testcpp/14/test.g
ANTLR accepts a #pragma gc_tokens which says
[1] Generate label = copy(LT(1)) instead of label=LT(1) for
all labeled token references.
[2] User now has to define ANTLRTokenPtr (as a class or a typedef
to just a pointer) as well as the ANTLRToken class itself.
See the example.
To delete tokens in token buffer, use deleteTokens() message on parser.
All tokens that fall off the ANTLRTokenBuffer get deleted
which is what currently happens when deleteTokens() message
has been sent to token buffer.
We always generate ANTLRTokenPtr instead of 'ANTLRToken *' now.
Then if no pragma set, ANTLR generates a
class ANTLRToken;
typedef ANTLRToken *ANTLRTokenPtr;
in each file.
Made a warning for x:rule_ref <<$x>>; still no warning for $i's, however.
class BB {
a : x:b y:A <<$x
$y>>
;
b : B;
}
generates
Antlr parser generator Version 1.32b6 1989-1995
test.g, line 3: error: There are no token ptrs for rule references: '$x'
===================
1.32b7:
[With respect to token object garbage collection (GC), 1.32b7
backtracks from 1.32b6, but results in better and less intrusive GC.
This is the last beta version before full 1.32.]
BIGGEST CHANGES:
o The "#pragma gc_tokens" is no longer used.
o .C files are now .cpp files (hence, makefiles will have to
be changed; or you can rerun genmk). This is a good move,
but causes some backward incompatibility problems. You can
avoid this by changing CPP_FILE_SUFFIX to ".C" in pccts/h/config.h.
o The token object class hierarchy has been flattened to include
only three classes: ANTLRAbstractToken, ANTLRCommonToken, and
ANTLRCommonNoRefCountToken. The common token now does garbage
collection via ref counting.
o "Smart" pointers are now used for garbage collection. That is,
ANTLRTokenPtr is used instead of "ANTLRToken *".
o The antlr.1 man page has been cleaned up slightly.
o The SUN C++ compiler now complains less about C++ support code.
o Grammars which subclass ANTLRCommonToken must wrap all token
pointer references in mytoken(token_ptr). This is the only
serious backward incompatibility. See below.
MINOR CHANGES:
--------------------------------------------------------
1 deleteTokens()
The deleteTokens() message to the parser or token buffer has been changed
to one of:
void noGarbageCollectTokens() { inputTokens->noGarbageCollectTokens(); }
void garbageCollectTokens() { inputTokens->garbageCollectTokens(); }
The token buffer deletes all non-referenced tokens by default now.
--------------------------------------------------------
2 makeToken()
The makeToken() message returns a new type. The function should look
like:
virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,
ANTLRChar *txt,
int line)
{
ANTLRAbstractToken *t = new ANTLRCommonToken(tt,txt);
t->setLine(line);
return t;
}
--------------------------------------------------------
3 TokenType
Changed TokenType-> ANTLRTokenType (often forces changes in AST defs due
to #[] constructor called to AST(tokentype, string)).
--------------------------------------------------------
4 AST()
You must define AST(ANTLRTokenPtr t) now in your AST class definition.
You might also have to include ATokPtr.h above the definition; e.g.,
if AST is defined in a separate file, such as AST.h, it's a good idea
to include ATOKPTR_H (ATokPtr.h). For example,
#include ATOKPTR_H
class AST : public ASTBase {
protected:
ANTLRTokenPtr token;
public:
AST(ANTLRTokenPtr t) { token = t; }
void preorder_action() {
char *s = token->getText();
printf(" %s", s);
}
};
Note the use of smart pointers rather than "ANTLRToken *".
--------------------------------------------------------
5 SUN C++
From robertb oakhill.sps.mot.com Bob Bailey. Changed ANTLR C++ output
to avoid an error in Sun C++ 3.0.1. Made "public" return value
structs created to hold multiple return values public.
--------------------------------------------------------
6 genmk
Fixed genmk so that target List.* is not included anymore. It's
called SList.* anyway.
--------------------------------------------------------
7 \r vs \n
Scott Vorthmann <vorth cmu.edu> fixed antlr.g in ANTLR so that \r
is allowed as the return character as well as \n.
--------------------------------------------------------
8 Exceptions
Bug in exceptions attached to labeled token/tokclass references. Didn't gen
code for exceptions. This didn't work:
a : "help" x:ID
;
exception[x]
catch MismatchedToken : <<printf("eh?\n");>>
Now ANTLR generates (which is kinda big, but necessary):
if ( !_match_wsig(ID) ) {
if ( guessing ) goto fail;
_signal=MismatchedToken;
switch ( _signal ) {
case MismatchedToken :
printf("eh?\n");
_signal = NoSignal;
break;
default :
goto _handler;
}
}
which implies that you can recover and continue parsing after a missing/bad
token reference.
--------------------------------------------------------
9 genmk
genmk now correctly uses config file for CPP_FILE_SUFFIX stuff.
--------------------------------------------------------
10 general cleanup / PURIFY
Anthony Green <green vizbiz.com> suggested a bunch of good general
clean up things for the code; he also suggested a few things to
help out the "PURIFY" memory allocation checker.
--------------------------------------------------------
11 $-variable references.
Manuel ORNATO indicated that a $-variable outside of a rule caused
ANTLR to crash. I fixed this.
12 Tom Moog suggestion
Fail action of semantic predicate needs "{}" envelope. FIXED.
13 references to LT(1).
I have enclosed all assignments such as:
_t22 = (ANTLRTokenPtr)LT(1);
in "if ( !guessing )" so that during backtracking the reference count
for token objects is not increased.
TOKEN OBJECT GARBAGE COLLECTION
1 INTRODUCTION
The class ANTLRCommonToken is now garbaged collected through a "smart"
pointer called ANTLRTokenPtr using reference counting. Any token
object not referenced by your grammar actions is destroyed by the
ANTLRTokenBuffer when it must make room for more token objects.
Referenced tokens are then destroyed in your parser when local
ANTLRTokenPtr objects are deleted. For example,
a : label:ID ;
would be converted to something like:
void yourclass::a(void)
{
zzRULE;
ANTLRTokenPtr label=NULL; // used to be ANTLRToken *label;
zzmatch(ID);
label = (ANTLRTokenPtr)LT(1);
consume();
...
}
When the "label" object is destroyed (it's just a pointer to your
input token object LT(1)), it decrements the reference count on the
object created for the ID. If the count goes to zero, the object
pointed by label is deleted.
To correctly manage the garbage collection, you should use
ANTLRTokenPtr instead of "ANTLRToken *". Most ANTLR support code
(visible to the user) has been modified to use the smart pointers.
***************************************************************
Remember that any local objects that you create are not deleted when a
lonjmp() is executed. Unfortunately, the syntactic predicates (...)?
use setjmp()/longjmp(). There are some situations when a few tokens
will "leak".
***************************************************************
2 DETAILS
o The default is to perform token object garbage collection.
You may use parser->noGarbageCollectTokens() to turn off
garbage collection.
o The type ANTLRTokenPtr is always defined now (automatically).
If you do not wish to use smart pointers, you will have to
redefined ANTLRTokenPtr by subclassing, changing the header
file or changing ANTLR's code generation (easy enough to
do in gen.c).
o If you don't use ParserBlackBox, the new initialization sequence is:
ANTLRTokenPtr aToken = new ANTLRToken;
scan.setToken(mytoken(aToken));
where mytoken(aToken) gets an ANTLRToken * from the smart pointer.
o Define C++ preprocessor symbol DBG_REFCOUNTTOKEN to see a bunch of
debugging stuff for reference counting if you suspect something.
3 WHY DO I HAVE TO TYPECAST ALL MY TOKEN POINTERS NOW??????
If you subclass ANTLRCommonToken and then attempt to refer to one of
your token members via a token pointer in your grammar actions, the
C++ compiler will complain that your token object does not have that
member. For example, if you used to do this
<<
class ANTLRToken : public ANTLRCommonToken {
int muck;
...
};
>>
class Foo {
a : t:ID << t->muck = ...; >> ;
}
Now, you must do change the t->muck reference to:
a : t:ID << mytoken(t)->muck = ...; >> ;
in order to downcast 't' to be an "ANTLRToken *" not the
"ANTLRAbstractToken *" resulting from ANTLRTokenPtr::operator->().
The macro is defined as:
/*
* Since you cannot redefine operator->() to return one of the user's
* token object types, we must down cast. This is a drag. Here's
* a macro that helps. template: "mytoken(a-smart-ptr)->myfield".
*/
#define mytoken(tp) ((ANTLRToken *)(tp.operator->()))
You have to use macro mytoken(grammar-label) now because smart
pointers are not specific to a parser's token objects. In other
words, the ANTLRTokenPtr class has a pointer to a generic
ANTLRAbstractToken not your ANTLRToken; the ANTLR support code must
use smart pointers too, but be able to work with any kind of
ANTLRToken. Sorry about this, but it's C++'s fault not mine. Some
nebulous future version of the C++ compilers should obviate the need
to downcast smart pointers with runtime type checking (and by allowing
different return type of overridden functions).
A way to have backward compatible code is to shut off the token object
garbage collection; i.e., use parser->noGarbageCollectTokens() and
change the definition of ANTLRTokenPtr (that's why you get source code
<wink>).
PARSER EXCEPTION HANDLING
I've noticed some weird stuff with the exception handling. I intend
to give this top priority for the "book release" of ANTLR.
==========
1.32 Full Release
o Changed Token class hierarchy to be (Thanks to Tom Moog):
ANTLRAbstractToken
ANTLRRefCountToken
ANTLRCommonToken
ANTLRNoRefCountCommonToken
o Added virtual panic() to ANTLRAbstractToken. Made ANTLRParser::panic()
virtual also.
o Cleaned up the dup() stuff in AST hierarchy to use shallowCopy() to
make node copies. John Farr at Medtronic suggested this. I.e.,
if you want to use dup() with either ANTLR or SORCERER or -transform
mode with SORCERER, you must defined shallowCopy() as:
virtual PCCTS_AST *shallowCopy()
{
return new AST;
p->setDown(NULL);
p->setRight(NULL);
return p;
}
or
virtual PCCTS_AST *shallowCopy()
{
return new AST(*this);
}
if you have defined a copy constructor such as
AST(const AST &t) // shallow copy constructor
{
token = t.token;
iconst = t.iconst;
setDown(NULL);
setRight(NULL);
}
o Added a warning with -CC and -gk are used together. This is broken,
hence a warning is appropriate.
o Added warning when #-stuff is used w/o -gt option.
o Updated MPW installation.
o "Miller, Philip W." <MILLERPW f1groups.fsd.jhuapl.edu> suggested
that genmk be use RENAME_OBJ_FLAG RENAME_EXE_FLAG instead of
hardcoding "-o" in genmk.c.
o made all exit() calls use EXIT_SUCCESS or EXIT_FAILURE.
===========================================================================
1.33
EXIT_FAILURE and EXIT_SUCCESS were not always defined. I had to modify
a bunch of files to use PCCTS_EXIT_XXX, which forces a new version. Sorry
about that.

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More