Base.h

Go to the documentation of this file.
00001 /** @file
00002   Root include file for Mde Package Base type modules
00003 
00004   This is the include file for any module of type base. Base modules only use
00005   types defined via this include file and can be ported easily to any
00006   environment. There are a set of base libraries in the Mde Package that can
00007   be used to implement base modules.
00008 
00009 Copyright (c) 2006 - 2008, Intel Corporation
00010 All rights reserved. This program and the accompanying materials
00011 are licensed and made available under the terms and conditions of the BSD License
00012 which accompanies this distribution.  The full text of the license may be found at
00013 http://opensource.org/licenses/bsd-license.php
00014 
00015 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
00016 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
00017 
00018 **/
00019 
00020 
00021 #ifndef __BASE_H__
00022 #define __BASE_H__
00023 
00024 //
00025 // Include processor specific binding
00026 //
00027 #include <gpxe/efi/ProcessorBind.h>
00028 
00029 typedef struct {
00030   UINT32  Data1;
00031   UINT16  Data2;
00032   UINT16  Data3;
00033   UINT8   Data4[8];
00034 } GUID;
00035 
00036 typedef UINT64 PHYSICAL_ADDRESS;
00037 
00038 ///
00039 /// LIST_ENTRY definition
00040 ///
00041 typedef struct _LIST_ENTRY LIST_ENTRY;
00042 
00043 struct _LIST_ENTRY {
00044   LIST_ENTRY  *ForwardLink;
00045   LIST_ENTRY  *BackLink;
00046 };
00047 
00048 //
00049 // Modifiers to absract standard types to aid in debug of problems
00050 //
00051 #define CONST     const
00052 #define STATIC    static
00053 #define VOID      void
00054 
00055 //
00056 // Modifiers for Data Types used to self document code.
00057 // This concept is borrowed for UEFI specification.
00058 //
00059 #define IN
00060 #define OUT
00061 #define OPTIONAL
00062 
00063 //
00064 //  UEFI specification claims 1 and 0. We are concerned about the
00065 //  complier portability so we did it this way.
00066 //
00067 #define TRUE  ((BOOLEAN)(1==1))
00068 #define FALSE ((BOOLEAN)(0==1))
00069 
00070 #define NULL  ((VOID *) 0)
00071 
00072 #define  BIT0     0x00000001
00073 #define  BIT1     0x00000002
00074 #define  BIT2     0x00000004
00075 #define  BIT3     0x00000008
00076 #define  BIT4     0x00000010
00077 #define  BIT5     0x00000020
00078 #define  BIT6     0x00000040
00079 #define  BIT7     0x00000080
00080 #define  BIT8     0x00000100
00081 #define  BIT9     0x00000200
00082 #define  BIT10    0x00000400
00083 #define  BIT11    0x00000800
00084 #define  BIT12    0x00001000
00085 #define  BIT13    0x00002000
00086 #define  BIT14    0x00004000
00087 #define  BIT15    0x00008000
00088 #define  BIT16    0x00010000
00089 #define  BIT17    0x00020000
00090 #define  BIT18    0x00040000
00091 #define  BIT19    0x00080000
00092 #define  BIT20    0x00100000
00093 #define  BIT21    0x00200000
00094 #define  BIT22    0x00400000
00095 #define  BIT23    0x00800000
00096 #define  BIT24    0x01000000
00097 #define  BIT25    0x02000000
00098 #define  BIT26    0x04000000
00099 #define  BIT27    0x08000000
00100 #define  BIT28    0x10000000
00101 #define  BIT29    0x20000000
00102 #define  BIT30    0x40000000
00103 #define  BIT31    0x80000000
00104 #define  BIT32    0x0000000100000000UL
00105 #define  BIT33    0x0000000200000000UL
00106 #define  BIT34    0x0000000400000000UL
00107 #define  BIT35    0x0000000800000000UL
00108 #define  BIT36    0x0000001000000000UL
00109 #define  BIT37    0x0000002000000000UL
00110 #define  BIT38    0x0000004000000000UL
00111 #define  BIT39    0x0000008000000000UL
00112 #define  BIT40    0x0000010000000000UL
00113 #define  BIT41    0x0000020000000000UL
00114 #define  BIT42    0x0000040000000000UL
00115 #define  BIT43    0x0000080000000000UL
00116 #define  BIT44    0x0000100000000000UL
00117 #define  BIT45    0x0000200000000000UL
00118 #define  BIT46    0x0000400000000000UL
00119 #define  BIT47    0x0000800000000000UL
00120 #define  BIT48    0x0001000000000000UL
00121 #define  BIT49    0x0002000000000000UL
00122 #define  BIT50    0x0004000000000000UL
00123 #define  BIT51    0x0008000000000000UL
00124 #define  BIT52    0x0010000000000000UL
00125 #define  BIT53    0x0020000000000000UL
00126 #define  BIT54    0x0040000000000000UL
00127 #define  BIT55    0x0080000000000000UL
00128 #define  BIT56    0x0100000000000000UL
00129 #define  BIT57    0x0200000000000000UL
00130 #define  BIT58    0x0400000000000000UL
00131 #define  BIT59    0x0800000000000000UL
00132 #define  BIT60    0x1000000000000000UL
00133 #define  BIT61    0x2000000000000000UL
00134 #define  BIT62    0x4000000000000000UL
00135 #define  BIT63    0x8000000000000000UL
00136 
00137 //
00138 //  Support for variable length argument lists using the ANSI standard.
00139 //
00140 //  Since we are using the ANSI standard we used the standard nameing and
00141 //  did not folow the coding convention
00142 //
00143 //  VA_LIST  - typedef for argument list.
00144 //  VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use.
00145 //  VA_END (VA_LIST Marker) - Clear Marker
00146 //  VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argumnet from
00147 //    the ... list. You must know the size and pass it in this macro.
00148 //
00149 //  example:
00150 //
00151 //  UINTN
00152 //  ExampleVarArg (
00153 //    IN UINTN  NumberOfArgs,
00154 //    ...
00155 //    )
00156 //  {
00157 //    VA_LIST Marker;
00158 //    UINTN   Index;
00159 //    UINTN   Result;
00160 //
00161 //    //
00162 //    // Initialize the Marker
00163 //    //
00164 //    VA_START (Marker, NumberOfArgs);
00165 //    for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) {
00166 //      //
00167 //      // The ... list is a series of UINTN values, so average them up.
00168 //      //
00169 //      Result += VA_ARG (Marker, UINTN);
00170 //    }
00171 //
00172 //    VA_END (Marker);
00173 //    return Result
00174 //  }
00175 //
00176 
00177 #define _INT_SIZE_OF(n) ((sizeof (n) + sizeof (UINTN) - 1) &~(sizeof (UINTN) - 1))
00178 
00179 //
00180 // Also support coding convention rules for var arg macros
00181 //
00182 typedef CHAR8 *VA_LIST;
00183 #define VA_START(ap, v) (ap = (VA_LIST) & (v) + _INT_SIZE_OF (v))
00184 #define VA_ARG(ap, t)   (*(t *) ((ap += _INT_SIZE_OF (t)) - _INT_SIZE_OF (t)))
00185 #define VA_END(ap)      (ap = (VA_LIST) 0)
00186 
00187 //
00188 // Macro that returns the byte offset of a field in a data structure.
00189 //
00190 #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))
00191 
00192 ///
00193 ///  CONTAINING_RECORD - returns a pointer to the structure
00194 ///      from one of it's elements.
00195 ///
00196 #define _CR(Record, TYPE, Field)  ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
00197 
00198 ///
00199 ///  ALIGN_VALUE - aligns a value up to the next boundary of the given alignment.
00200 ///
00201 #define ALIGN_VALUE(Value, Alignment) ((Value) + (((Alignment) - (Value)) & ((Alignment) - 1)))
00202 
00203 ///
00204 ///  ALIGN_POINTER - aligns a pointer to the lowest boundry
00205 ///
00206 #define ALIGN_POINTER(Pointer, Alignment) ((VOID *) (ALIGN_VALUE ((UINTN)(Pointer), (Alignment))))
00207 
00208 ///
00209 ///  ALIGN_VARIABLE - aligns a variable up to the next natural boundry for int size of a processor
00210 ///
00211 #define ALIGN_VARIABLE(Value)  ALIGN_VALUE ((Value), sizeof (UINTN))
00212 
00213 
00214 //
00215 // Return the maximum of two operands.
00216 // This macro returns the maximum of two operand specified by a and b.
00217 // Both a and b must be the same numerical types, signed or unsigned.
00218 //
00219 #define MAX(a, b)                       \
00220   (((a) > (b)) ? (a) : (b))
00221 
00222 
00223 //
00224 // Return the minimum of two operands.
00225 // This macro returns the minimal of two operand specified by a and b.
00226 // Both a and b must be the same numerical types, signed or unsigned.
00227 //
00228 #define MIN(a, b)                       \
00229   (((a) < (b)) ? (a) : (b))
00230 
00231 
00232 //
00233 // EFI Error Codes common to all execution phases
00234 //
00235 
00236 typedef INTN RETURN_STATUS;
00237 
00238 ///
00239 /// Set the upper bit to indicate EFI Error.
00240 ///
00241 #define ENCODE_ERROR(a)              (MAX_BIT | (a))
00242 
00243 #define ENCODE_WARNING(a)            (a)
00244 #define RETURN_ERROR(a)              ((INTN) (a) < 0)
00245 
00246 #define RETURN_SUCCESS               0
00247 #define RETURN_LOAD_ERROR            ENCODE_ERROR (1)
00248 #define RETURN_INVALID_PARAMETER     ENCODE_ERROR (2)
00249 #define RETURN_UNSUPPORTED           ENCODE_ERROR (3)
00250 #define RETURN_BAD_BUFFER_SIZE       ENCODE_ERROR (4)
00251 #define RETURN_BUFFER_TOO_SMALL      ENCODE_ERROR (5)
00252 #define RETURN_NOT_READY             ENCODE_ERROR (6)
00253 #define RETURN_DEVICE_ERROR          ENCODE_ERROR (7)
00254 #define RETURN_WRITE_PROTECTED       ENCODE_ERROR (8)
00255 #define RETURN_OUT_OF_RESOURCES      ENCODE_ERROR (9)
00256 #define RETURN_VOLUME_CORRUPTED      ENCODE_ERROR (10)
00257 #define RETURN_VOLUME_FULL           ENCODE_ERROR (11)
00258 #define RETURN_NO_MEDIA              ENCODE_ERROR (12)
00259 #define RETURN_MEDIA_CHANGED         ENCODE_ERROR (13)
00260 #define RETURN_NOT_FOUND             ENCODE_ERROR (14)
00261 #define RETURN_ACCESS_DENIED         ENCODE_ERROR (15)
00262 #define RETURN_NO_RESPONSE           ENCODE_ERROR (16)
00263 #define RETURN_NO_MAPPING            ENCODE_ERROR (17)
00264 #define RETURN_TIMEOUT               ENCODE_ERROR (18)
00265 #define RETURN_NOT_STARTED           ENCODE_ERROR (19)
00266 #define RETURN_ALREADY_STARTED       ENCODE_ERROR (20)
00267 #define RETURN_ABORTED               ENCODE_ERROR (21)
00268 #define RETURN_ICMP_ERROR            ENCODE_ERROR (22)
00269 #define RETURN_TFTP_ERROR            ENCODE_ERROR (23)
00270 #define RETURN_PROTOCOL_ERROR        ENCODE_ERROR (24)
00271 #define RETURN_INCOMPATIBLE_VERSION  ENCODE_ERROR (25)
00272 #define RETURN_SECURITY_VIOLATION    ENCODE_ERROR (26)
00273 #define RETURN_CRC_ERROR             ENCODE_ERROR (27)
00274 #define RETURN_END_OF_MEDIA          ENCODE_ERROR (28)
00275 #define RETURN_END_OF_FILE           ENCODE_ERROR (31)
00276 #define RETURN_INVALID_LANGUAGE      ENCODE_ERROR (32)
00277 
00278 
00279 #define RETURN_WARN_UNKNOWN_GLYPH    ENCODE_WARNING (1)
00280 #define RETURN_WARN_DELETE_FAILURE   ENCODE_WARNING (2)
00281 #define RETURN_WARN_WRITE_FAILURE    ENCODE_WARNING (3)
00282 #define RETURN_WARN_BUFFER_TOO_SMALL ENCODE_WARNING (4)
00283 
00284 /**
00285   Returns a 16-bit signature built from 2 ASCII characters.
00286 
00287   @param  A        The first ASCII character.
00288   @param  B        The second ASCII character.
00289 
00290   @return A 16-bit value built from the two ASCII characters specified by A and B.
00291 
00292 **/
00293 #define SIGNATURE_16(A, B)        ((A) | (B << 8))
00294 
00295 /**
00296   Returns a 32-bit signature built from 4 ASCII characters.
00297 
00298   @param  A        The first ASCII character.
00299   @param  B        The second ASCII character.
00300   @param  C        The third ASCII character.
00301   @param  D        The fourth ASCII character.
00302 
00303   @return A 32-bit value built from the two ASCII characters specified by A, B,
00304           C and D.
00305 
00306 **/
00307 #define SIGNATURE_32(A, B, C, D)  (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16))
00308 
00309 /**
00310   Returns a 64-bit signature built from 8 ASCII characters.
00311 
00312   @param  A        The first ASCII character.
00313   @param  B        The second ASCII character.
00314   @param  C        The third ASCII character.
00315   @param  D        The fourth ASCII character.
00316   @param  E        The fifth ASCII character.
00317   @param  F        The sixth ASCII character.
00318   @param  G        The seventh ASCII character.
00319   @param  H        The eighth ASCII character.
00320 
00321   @return A 64-bit value built from the two ASCII characters specified by A, B,
00322           C, D, E, F, G and H.
00323 
00324 **/
00325 #define SIGNATURE_64(A, B, C, D, E, F, G, H) \
00326     (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32))
00327 
00328 #endif
00329 

Generated on Tue Apr 6 20:01:06 2010 for gPXE by  doxygen 1.5.7.1