iPXE
compiler.h
Go to the documentation of this file.
00001 #ifndef COMPILER_H
00002 #define COMPILER_H
00003 
00004 /*
00005  * Doxygen can't cope with some of the more esoteric areas of C, so we
00006  * make its life simpler.
00007  *
00008  */
00009 #ifdef DOXYGEN
00010 #define __attribute__(x)
00011 #endif
00012 
00013 /** @file
00014  *
00015  * Global compiler definitions.
00016  *
00017  * This file is implicitly included by every @c .c file in Etherboot.
00018  * It defines global macros such as DBG().
00019  *
00020  * We arrange for each object to export the symbol @c obj_OBJECT
00021  * (where @c OBJECT is the object name, e.g. @c rtl8139) as a global
00022  * symbol, so that the linker can drag in selected object files from
00023  * the library using <tt> -u obj_OBJECT </tt>.
00024  *
00025  */
00026 
00027 /* Force visibility of all symbols to "hidden", i.e. inform gcc that
00028  * all symbol references resolve strictly within our final binary.
00029  * This avoids unnecessary PLT/GOT entries on x86_64.
00030  *
00031  * This is a stronger claim than specifying "-fvisibility=hidden",
00032  * since it also affects symbols marked with "extern".
00033  */
00034 #ifndef ASSEMBLY
00035 #if __GNUC__ >= 4
00036 #pragma GCC visibility push(hidden)
00037 #endif
00038 #endif /* ASSEMBLY */
00039 
00040 #undef _S1
00041 #undef _S2
00042 #undef _C1
00043 #undef _C2
00044 
00045 /** Concatenate non-expanded arguments */
00046 #define _C1( x, y ) x ## y
00047 /** Concatenate expanded arguments */
00048 #define _C2( x, y ) _C1 ( x, y )
00049 
00050 /** Stringify non-expanded argument */
00051 #define _S1( x ) #x
00052 /** Stringify expanded argument */
00053 #define _S2( x ) _S1 ( x )
00054 
00055 /* Assembler section types */
00056 #ifdef ASSEMBLY
00057 #define PROGBITS _C2 ( ASM_TCHAR, progbits )
00058 #define NOBITS _C2 ( ASM_TCHAR, nobits )
00059 #else
00060 #define PROGBITS_OPS _S2 ( ASM_TCHAR_OPS ) "progbits"
00061 #define PROGBITS _S2 ( ASM_TCHAR ) "progbits"
00062 #define NOBITS_OPS _S2 ( ASM_TCHAR_OPS ) "nobits"
00063 #define NOBITS _S2 ( ASM_TCHAR ) "nobits"
00064 #endif
00065 
00066 /**
00067  * @defgroup symmacros Macros to provide or require explicit symbols
00068  * @{
00069  */
00070 
00071 /**
00072  * Provide a symbol within this object file
00073  *
00074  * @v symbol            Symbol name
00075  */
00076 #ifdef ASSEMBLY
00077 #define PROVIDE_SYMBOL( symbol )                                \
00078         .section ".provided", "a", NOBITS ;                     \
00079         .hidden symbol ;                                        \
00080         .globl  symbol ;                                        \
00081         symbol: ;                                               \
00082         .previous
00083 #else
00084 #define PROVIDE_SYMBOL( symbol )                                \
00085         char symbol[0]                                          \
00086           __attribute__ (( section ( ".provided" ) ))
00087 #endif
00088 
00089 /**
00090  * Request a symbol
00091  *
00092  * @v symbol            Symbol name
00093  *
00094  * Request a symbol to be included within the link.  If the symbol
00095  * cannot be found, the link will succeed anyway.
00096  */
00097 #ifdef ASSEMBLY
00098 #define REQUEST_SYMBOL( symbol )                                \
00099         .equ __request_ ## symbol, symbol
00100 #else
00101 #define REQUEST_SYMBOL( symbol )                                \
00102         __asm__ ( ".equ __request_" #symbol ", " #symbol )
00103 #endif
00104 
00105 /**
00106  * Require a symbol
00107  *
00108  * @v symbol            Symbol name
00109  *
00110  * Require a symbol to be included within the link.  If the symbol
00111  * cannot be found, the link will fail.
00112  *
00113  * To use this macro within a file, you must also specify the file's
00114  * "requiring symbol" using the REQUIRING_SYMBOL() or
00115  * PROVIDE_REQUIRING_SYMBOL() macros.
00116  */
00117 #ifdef ASSEMBLY
00118 #define REQUIRE_SYMBOL( symbol )                                \
00119         .reloc __requiring_symbol__, RELOC_TYPE_NONE, symbol
00120 #else
00121 #define REQUIRE_SYMBOL( symbol )                                \
00122         __asm__ ( ".reloc __requiring_symbol__, "               \
00123                   _S2 ( RELOC_TYPE_NONE ) ", " #symbol )
00124 #endif
00125 
00126 /**
00127  * Specify the file's requiring symbol
00128  *
00129  * @v symbol            Symbol name
00130  *
00131  * REQUIRE_SYMBOL() works by defining a dummy relocation record
00132  * against a nominated "requiring symbol".  The presence of the
00133  * nominated requiring symbol will drag in all of the symbols
00134  * specified using REQUIRE_SYMBOL().
00135  */
00136 #ifdef ASSEMBLY
00137 #define REQUIRING_SYMBOL( symbol )                              \
00138         .equ __requiring_symbol__, symbol
00139 #else
00140 #define REQUIRING_SYMBOL( symbol )                              \
00141         __asm__ ( ".equ __requiring_symbol__, " #symbol )
00142 #endif
00143 
00144 /**
00145  * Provide a file's requiring symbol
00146  *
00147  * If the file contains no symbols that can be used as the requiring
00148  * symbol, you can provide a dummy one-byte-long symbol using
00149  * PROVIDE_REQUIRING_SYMBOL().
00150  */
00151 #ifdef ASSEMBLY
00152 #define PROVIDE_REQUIRING_SYMBOL()                              \
00153         .section ".tbl.requiring_symbols", "a", PROGBITS ;      \
00154         __requiring_symbol__:   .byte 0 ;                       \
00155         .size __requiring_symbol__, . - __requiring_symbol__ ;  \
00156         .previous
00157 #else
00158 #define PROVIDE_REQUIRING_SYMBOL()                              \
00159         __asm__ ( ".section \".tbl.requiring_symbols\", "       \
00160                   "         \"a\", " PROGBITS "\n"              \
00161                   "__requiring_symbol__:\t.byte 0\n"            \
00162                   ".size __requiring_symbol__, "                \
00163                   "      . - __requiring_symbol__\n"            \
00164                   ".previous" )
00165 #endif
00166 
00167 /** @} */
00168 
00169 /**
00170  * @defgroup objmacros Macros to provide or require explicit objects
00171  * @{
00172  */
00173 
00174 #define PREFIX_OBJECT( _prefix ) _C2 ( _prefix, OBJECT )
00175 #define OBJECT_SYMBOL PREFIX_OBJECT ( obj_ )
00176 
00177 /** Always provide the symbol for the current object (defined by -DOBJECT) */
00178 PROVIDE_SYMBOL ( OBJECT_SYMBOL );
00179 
00180 /**
00181  * Request an object
00182  *
00183  * @v object            Object name
00184  *
00185  * Request an object to be included within the link.  If the object
00186  * cannot be found, the link will succeed anyway.
00187  */
00188 #define REQUEST_OBJECT( object ) REQUEST_SYMBOL ( obj_ ## object )
00189 
00190 /**
00191  * Require an object
00192  *
00193  * @v object            Object name
00194  *
00195  * Require an object to be included within the link.  If the object
00196  * cannot be found, the link will fail.
00197  *
00198  * To use this macro within a file, you must also specify the file's
00199  * "requiring symbol" using the REQUIRING_SYMBOL() or
00200  * PROVIDE_REQUIRING_SYMBOL() macros.
00201  */
00202 #define REQUIRE_OBJECT( object ) REQUIRE_SYMBOL ( obj_ ## object )
00203 
00204 /** @} */
00205 
00206 /** Select file identifier for errno.h (if used) */
00207 #define ERRFILE PREFIX_OBJECT ( ERRFILE_ )
00208 
00209 #ifndef ASSEMBLY
00210 
00211 /** Declare a function as weak (use *before* the definition)
00212  *
00213  * Due to a bug in at least GCC 4.4.4 and earlier, weak symbols may be
00214  * inlined if they have hidden visibility (see above for why hidden
00215  * visibility is used).  This results in the non-weak symbol never
00216  * being used, so explicitly mark the function as noinline to prevent
00217  * inlining.
00218  */
00219 #define __weak          __attribute__ (( weak, noinline ))
00220 
00221 #endif
00222 
00223 /** @defgroup dbg Debugging infrastructure
00224  * @{
00225  */
00226 
00227 /** @def DBG
00228  *
00229  * Print a debugging message.
00230  *
00231  * The debug level is set at build time by specifying the @c DEBUG=
00232  * parameter on the @c make command line.  For example, to enable
00233  * debugging for the PCI bus functions (in pci.c) in a @c .dsk image
00234  * for the @c rtl8139 card, you could use the command line
00235  *
00236  * @code
00237  *
00238  *   make bin/rtl8139.dsk DEBUG=pci
00239  *
00240  * @endcode
00241  *
00242  * This will enable the debugging statements (DBG()) in pci.c.  If
00243  * debugging is not enabled, DBG() statements will be ignored.
00244  *
00245  * You can enable debugging in several objects simultaneously by
00246  * separating them with commas, as in
00247  *
00248  * @code
00249  *
00250  *   make bin/rtl8139.dsk DEBUG=pci,buffer,heap
00251  *
00252  * @endcode
00253  *
00254  * You can increase the debugging level for an object by specifying it
00255  * with @c :N, where @c N is the level, as in
00256  *
00257  * @code
00258  *
00259  *   make bin/rtl8139.dsk DEBUG=pci,buffer:2,heap
00260  *
00261  * @endcode
00262  *
00263  * which would enable debugging for the PCI, buffer-handling and
00264  * heap-allocation code, with the buffer-handling code at level 2.
00265  *
00266  */
00267 
00268 #ifndef DBGLVL_MAX
00269 #define NDEBUG
00270 #define DBGLVL_MAX 0
00271 #endif
00272 
00273 #ifndef DBGLVL_DFLT
00274 #define DBGLVL_DFLT DBGLVL_MAX
00275 #endif
00276 
00277 #ifndef ASSEMBLY
00278 
00279 /** printf() for debugging */
00280 extern void __attribute__ (( format ( printf, 1, 2 ) ))
00281 dbg_printf ( const char *fmt, ... );
00282 extern void dbg_autocolourise ( unsigned long id );
00283 extern void dbg_decolourise ( void );
00284 extern void dbg_hex_dump_da ( unsigned long dispaddr,
00285                               const void *data, unsigned long len );
00286 extern void dbg_md5_da ( unsigned long dispaddr,
00287                          const void *data, unsigned long len );
00288 extern void dbg_pause ( void );
00289 extern void dbg_more ( void );
00290 
00291 /* Allow for selective disabling of enabled debug levels */
00292 #define __debug_disable( object ) _C2 ( __debug_disable_, object )
00293 char __debug_disable(OBJECT) = ( DBGLVL_MAX & ~DBGLVL_DFLT );
00294 #define DBG_DISABLE_OBJECT( object, level ) do {                \
00295         extern char __debug_disable(object);                    \
00296         __debug_disable(object) |= (level);                     \
00297         } while ( 0 )
00298 #define DBG_ENABLE_OBJECT( object, level ) do {                 \
00299         extern char __debug_disable(object);                    \
00300         __debug_disable(object) &= ~(level);                    \
00301         } while ( 0 )
00302 #if DBGLVL_MAX
00303 #define DBGLVL ( DBGLVL_MAX & ~__debug_disable(OBJECT) )
00304 #define DBG_DISABLE( level ) do {                               \
00305         __debug_disable(OBJECT) |= ( (level) & DBGLVL_MAX );    \
00306         } while ( 0 )
00307 #define DBG_ENABLE( level ) do {                                \
00308         __debug_disable(OBJECT) &= ~( (level) & DBGLVL_MAX );   \
00309         } while ( 0 )
00310 #else
00311 #define DBGLVL 0
00312 #define DBG_DISABLE( level ) do { } while ( 0 )
00313 #define DBG_ENABLE( level ) do { } while ( 0 )
00314 #endif
00315 
00316 #define DBGLVL_LOG      1
00317 #define DBG_LOG         ( DBGLVL & DBGLVL_LOG )
00318 #define DBGLVL_EXTRA    2
00319 #define DBG_EXTRA       ( DBGLVL & DBGLVL_EXTRA )
00320 #define DBGLVL_PROFILE  4
00321 #define DBG_PROFILE     ( DBGLVL & DBGLVL_PROFILE )
00322 #define DBGLVL_IO       8
00323 #define DBG_IO          ( DBGLVL & DBGLVL_IO )
00324 
00325 /**
00326  * Print debugging message if we are at a certain debug level
00327  *
00328  * @v level             Debug level
00329  * @v ...               printf() argument list
00330  */
00331 #define DBG_IF( level, ... ) do {                               \
00332                 if ( DBG_ ## level ) {                          \
00333                         dbg_printf ( __VA_ARGS__ );             \
00334                 }                                               \
00335         } while ( 0 )
00336 
00337 /**
00338  * Print a hex dump if we are at a certain debug level
00339  *
00340  * @v level             Debug level
00341  * @v dispaddr          Display address
00342  * @v data              Data to print
00343  * @v len               Length of data
00344  */
00345 #define DBG_HDA_IF( level, dispaddr, data, len )  do {          \
00346                 if ( DBG_ ## level ) {                          \
00347                         union {                                 \
00348                                 unsigned long ul;               \
00349                                 typeof ( dispaddr ) raw;        \
00350                         } da;                                   \
00351                         da.ul = 0;                              \
00352                         da.raw = dispaddr;                      \
00353                         dbg_hex_dump_da ( da.ul, data, len );   \
00354                 }                                               \
00355         } while ( 0 )
00356 
00357 /**
00358  * Print a hex dump if we are at a certain debug level
00359  *
00360  * @v level             Debug level
00361  * @v data              Data to print
00362  * @v len               Length of data
00363  */
00364 #define DBG_HD_IF( level, data, len ) do {                      \
00365                 const void *_data = data;                       \
00366                 DBG_HDA_IF ( level, _data, _data, len );        \
00367         } while ( 0 )
00368 
00369 /**
00370  * Print an MD5 checksum if we are at a certain debug level
00371  *
00372  * @v level             Debug level
00373  * @v dispaddr          Display address
00374  * @v data              Data to print
00375  * @v len               Length of data
00376  */
00377 #define DBG_MD5A_IF( level, dispaddr, data, len )  do {         \
00378                 if ( DBG_ ## level ) {                          \
00379                         union {                                 \
00380                                 unsigned long ul;               \
00381                                 typeof ( dispaddr ) raw;        \
00382                         } da;                                   \
00383                         da.ul = 0;                              \
00384                         da.raw = dispaddr;                      \
00385                         dbg_md5_da ( da.ul, data, len );        \
00386                 }                                               \
00387         } while ( 0 )
00388 
00389 /**
00390  * Print an MD5 checksum if we are at a certain debug level
00391  *
00392  * @v level             Debug level
00393  * @v data              Data to print
00394  * @v len               Length of data
00395  */
00396 #define DBG_MD5_IF( level, data, len ) do {                     \
00397                 const void *_data = data;                       \
00398                 DBG_MD5A_IF ( level, _data, _data, len );       \
00399         } while ( 0 )
00400 
00401 /**
00402  * Prompt for key press if we are at a certain debug level
00403  *
00404  * @v level             Debug level
00405  */
00406 #define DBG_PAUSE_IF( level, ... ) do {                         \
00407                 if ( DBG_ ## level ) {                          \
00408                         dbg_pause();                            \
00409                 }                                               \
00410         } while ( 0 )
00411 
00412 /**
00413  * Prompt for more output data if we are at a certain debug level
00414  *
00415  * @v level             Debug level
00416  */
00417 #define DBG_MORE_IF( level, ... ) do {                          \
00418                 if ( DBG_ ## level ) {                          \
00419                         dbg_more();                             \
00420                 }                                               \
00421         } while ( 0 )
00422 
00423 /**
00424  * Select colour for debug messages if we are at a certain debug level
00425  *
00426  * @v level             Debug level
00427  * @v id                Message stream ID
00428  */
00429 #define DBG_AC_IF( level, id ) do {                             \
00430                 if ( DBG_ ## level ) {                          \
00431                         union {                                 \
00432                                 unsigned long ul;               \
00433                                 typeof ( id ) raw;              \
00434                         } dbg_stream;                           \
00435                         dbg_stream.ul = 0;                      \
00436                         dbg_stream.raw = id;                    \
00437                         dbg_autocolourise ( dbg_stream.ul );    \
00438                 }                                               \
00439         } while ( 0 )
00440 
00441 /**
00442  * Revert colour for debug messages if we are at a certain debug level
00443  *
00444  * @v level             Debug level
00445  */
00446 #define DBG_DC_IF( level ) do {                                 \
00447                 if ( DBG_ ## level ) {                          \
00448                         dbg_decolourise();                      \
00449                 }                                               \
00450         } while ( 0 )
00451 
00452 /* Autocolourising versions of the DBGxxx_IF() macros */
00453 
00454 #define DBGC_IF( level, id, ... ) do {                          \
00455                 DBG_AC_IF ( level, id );                        \
00456                 DBG_IF ( level, __VA_ARGS__ );                  \
00457                 DBG_DC_IF ( level );                            \
00458         } while ( 0 )
00459 
00460 #define DBGC_HDA_IF( level, id, ... ) do {                      \
00461                 DBG_AC_IF ( level, id );                        \
00462                 DBG_HDA_IF ( level, __VA_ARGS__ );              \
00463                 DBG_DC_IF ( level );                            \
00464         } while ( 0 )
00465 
00466 #define DBGC_HD_IF( level, id, ... ) do {                       \
00467                 DBG_AC_IF ( level, id );                        \
00468                 DBG_HD_IF ( level, __VA_ARGS__ );               \
00469                 DBG_DC_IF ( level );                            \
00470         } while ( 0 )
00471 
00472 #define DBGC_MD5A_IF( level, id, ... ) do {                     \
00473                 DBG_AC_IF ( level, id );                        \
00474                 DBG_MD5A_IF ( level, __VA_ARGS__ );             \
00475                 DBG_DC_IF ( level );                            \
00476         } while ( 0 )
00477 
00478 #define DBGC_MD5_IF( level, id, ... ) do {                      \
00479                 DBG_AC_IF ( level, id );                        \
00480                 DBG_MD5_IF ( level, __VA_ARGS__ );              \
00481                 DBG_DC_IF ( level );                            \
00482         } while ( 0 )
00483 
00484 #define DBGC_PAUSE_IF( level, id ) do {                         \
00485                 DBG_AC_IF ( level, id );                        \
00486                 DBG_PAUSE_IF ( level );                         \
00487                 DBG_DC_IF ( level );                            \
00488         } while ( 0 )
00489 
00490 #define DBGC_MORE_IF( level, id ) do {                          \
00491                 DBG_AC_IF ( level, id );                        \
00492                 DBG_MORE_IF ( level );                          \
00493                 DBG_DC_IF ( level );                            \
00494         } while ( 0 )
00495 
00496 /* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( LOG, ... )*/
00497 
00498 #define DBG( ... )              DBG_IF          ( LOG, ##__VA_ARGS__ )
00499 #define DBG_HDA( ... )          DBG_HDA_IF      ( LOG, ##__VA_ARGS__ )
00500 #define DBG_HD( ... )           DBG_HD_IF       ( LOG, ##__VA_ARGS__ )
00501 #define DBG_MD5A( ... )         DBG_MD5A_IF     ( LOG, ##__VA_ARGS__ )
00502 #define DBG_MD5( ... )          DBG_MD5_IF      ( LOG, ##__VA_ARGS__ )
00503 #define DBG_PAUSE( ... )        DBG_PAUSE_IF    ( LOG, ##__VA_ARGS__ )
00504 #define DBG_MORE( ... )         DBG_MORE_IF     ( LOG, ##__VA_ARGS__ )
00505 #define DBGC( ... )             DBGC_IF         ( LOG, ##__VA_ARGS__ )
00506 #define DBGC_HDA( ... )         DBGC_HDA_IF     ( LOG, ##__VA_ARGS__ )
00507 #define DBGC_HD( ... )          DBGC_HD_IF      ( LOG, ##__VA_ARGS__ )
00508 #define DBGC_MD5A( ... )        DBGC_MD5A_IF    ( LOG, ##__VA_ARGS__ )
00509 #define DBGC_MD5( ... )         DBGC_MD5_IF     ( LOG, ##__VA_ARGS__ )
00510 #define DBGC_PAUSE( ... )       DBGC_PAUSE_IF   ( LOG, ##__VA_ARGS__ )
00511 #define DBGC_MORE( ... )        DBGC_MORE_IF    ( LOG, ##__VA_ARGS__ )
00512 
00513 /* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( EXTRA, ... )*/
00514 
00515 #define DBG2( ... )             DBG_IF          ( EXTRA, ##__VA_ARGS__ )
00516 #define DBG2_HDA( ... )         DBG_HDA_IF      ( EXTRA, ##__VA_ARGS__ )
00517 #define DBG2_HD( ... )          DBG_HD_IF       ( EXTRA, ##__VA_ARGS__ )
00518 #define DBG2_MD5A( ... )        DBG_MD5A_IF     ( EXTRA, ##__VA_ARGS__ )
00519 #define DBG2_MD5( ... )         DBG_MD5_IF      ( EXTRA, ##__VA_ARGS__ )
00520 #define DBG2_PAUSE( ... )       DBG_PAUSE_IF    ( EXTRA, ##__VA_ARGS__ )
00521 #define DBG2_MORE( ... )        DBG_MORE_IF     ( EXTRA, ##__VA_ARGS__ )
00522 #define DBGC2( ... )            DBGC_IF         ( EXTRA, ##__VA_ARGS__ )
00523 #define DBGC2_HDA( ... )        DBGC_HDA_IF     ( EXTRA, ##__VA_ARGS__ )
00524 #define DBGC2_HD( ... )         DBGC_HD_IF      ( EXTRA, ##__VA_ARGS__ )
00525 #define DBGC2_MD5A( ... )       DBGC_MD5A_IF    ( EXTRA, ##__VA_ARGS__ )
00526 #define DBGC2_MD5( ... )        DBGC_MD5_IF     ( EXTRA, ##__VA_ARGS__ )
00527 #define DBGC2_PAUSE( ... )      DBGC_PAUSE_IF   ( EXTRA, ##__VA_ARGS__ )
00528 #define DBGC2_MORE( ... )       DBGC_MORE_IF    ( EXTRA, ##__VA_ARGS__ )
00529 
00530 /* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( PROFILE, ... )*/
00531 
00532 #define DBGP( ... )             DBG_IF          ( PROFILE, ##__VA_ARGS__ )
00533 #define DBGP_HDA( ... )         DBG_HDA_IF      ( PROFILE, ##__VA_ARGS__ )
00534 #define DBGP_HD( ... )          DBG_HD_IF       ( PROFILE, ##__VA_ARGS__ )
00535 #define DBGP_MD5A( ... )        DBG_MD5A_IF     ( PROFILE, ##__VA_ARGS__ )
00536 #define DBGP_MD5( ... )         DBG_MD5_IF      ( PROFILE, ##__VA_ARGS__ )
00537 #define DBGP_PAUSE( ... )       DBG_PAUSE_IF    ( PROFILE, ##__VA_ARGS__ )
00538 #define DBGP_MORE( ... )        DBG_MORE_IF     ( PROFILE, ##__VA_ARGS__ )
00539 #define DBGCP( ... )            DBGC_IF         ( PROFILE, ##__VA_ARGS__ )
00540 #define DBGCP_HDA( ... )        DBGC_HDA_IF     ( PROFILE, ##__VA_ARGS__ )
00541 #define DBGCP_HD( ... )         DBGC_HD_IF      ( PROFILE, ##__VA_ARGS__ )
00542 #define DBGCP_MD5A( ... )       DBGC_MD5A_IF    ( PROFILE, ##__VA_ARGS__ )
00543 #define DBGCP_MD5( ... )        DBGC_MD5_IF     ( PROFILE, ##__VA_ARGS__ )
00544 #define DBGCP_PAUSE( ... )      DBGC_PAUSE_IF   ( PROFILE, ##__VA_ARGS__ )
00545 #define DBGCP_MORE( ... )       DBGC_MORE_IF    ( PROFILE, ##__VA_ARGS__ )
00546 
00547 /* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( IO, ... )*/
00548 
00549 #define DBGIO( ... )            DBG_IF          ( IO, ##__VA_ARGS__ )
00550 #define DBGIO_HDA( ... )        DBG_HDA_IF      ( IO, ##__VA_ARGS__ )
00551 #define DBGIO_HD( ... )         DBG_HD_IF       ( IO, ##__VA_ARGS__ )
00552 #define DBGIO_MD5A( ... )       DBG_MD5A_IF     ( IO, ##__VA_ARGS__ )
00553 #define DBGIO_MD5( ... )        DBG_MD5_IF      ( IO, ##__VA_ARGS__ )
00554 #define DBGIO_PAUSE( ... )      DBG_PAUSE_IF    ( IO, ##__VA_ARGS__ )
00555 #define DBGIO_MORE( ... )       DBG_MORE_IF     ( IO, ##__VA_ARGS__ )
00556 #define DBGCIO( ... )           DBGC_IF         ( IO, ##__VA_ARGS__ )
00557 #define DBGCIO_HDA( ... )       DBGC_HDA_IF     ( IO, ##__VA_ARGS__ )
00558 #define DBGCIO_HD( ... )        DBGC_HD_IF      ( IO, ##__VA_ARGS__ )
00559 #define DBGCIO_MD5A( ... )      DBGC_MD5A_IF    ( IO, ##__VA_ARGS__ )
00560 #define DBGCIO_MD5( ... )       DBGC_MD5_IF     ( IO, ##__VA_ARGS__ )
00561 #define DBGCIO_PAUSE( ... )     DBGC_PAUSE_IF   ( IO, ##__VA_ARGS__ )
00562 #define DBGCIO_MORE( ... )      DBGC_MORE_IF    ( IO, ##__VA_ARGS__ )
00563 
00564 #endif /* ASSEMBLY */
00565 /** @} */
00566 
00567 /** @defgroup attrs Miscellaneous attributes
00568  * @{
00569  */
00570 #ifndef ASSEMBLY
00571 
00572 /** Declare a variable or data structure as unused. */
00573 #define __unused __attribute__ (( unused ))
00574 
00575 /**
00576  * Declare a function as pure - i.e. without side effects
00577  */
00578 #define __pure __attribute__ (( pure ))
00579 
00580 /**
00581  * Declare a function as const - i.e. it does not access global memory
00582  * (including dereferencing pointers passed to it) at all.
00583  * Must also not call any non-const functions.
00584  */
00585 #define __const __attribute__ (( const ))
00586 
00587 /**
00588  * Declare a function's pointer parameters as non-null - i.e. force
00589  * compiler to check pointers at compile time and enable possible
00590  * optimizations based on that fact
00591  */
00592 #define __nonnull __attribute__ (( nonnull ))
00593 
00594 /**
00595  * Declare a pointer returned by a function as a unique memory address
00596  * as returned by malloc-type functions.
00597  */
00598 #define __malloc __attribute__ (( malloc ))
00599 
00600 /**
00601  * Declare a function as used.
00602  *
00603  * Necessary only if the function is called only from assembler code.
00604  */
00605 #define __used __attribute__ (( used ))
00606 
00607 /** Declare a data structure to be aligned with 16-byte alignment */
00608 #define __aligned __attribute__ (( aligned ( 16 ) ))
00609 
00610 /** Declare a function to be always inline */
00611 #define __always_inline __attribute__ (( always_inline ))
00612 
00613 /* Force all inline functions to not be instrumented
00614  *
00615  * This is required to cope with what seems to be a long-standing gcc
00616  * bug, in which -finstrument-functions will cause instances of
00617  * inlined functions to be reported as further calls to the
00618  * *containing* function.  This makes instrumentation very difficult
00619  * to use.
00620  *
00621  * Work around this problem by adding the no_instrument_function
00622  * attribute to all inlined functions.
00623  */
00624 #define inline inline __attribute__ (( no_instrument_function ))
00625 
00626 /**
00627  * Shared data.
00628  *
00629  * To save space in the binary when multiple-driver images are
00630  * compiled, uninitialised data areas can be shared between drivers.
00631  * This will typically be used to share statically-allocated receive
00632  * and transmit buffers between drivers.
00633  *
00634  * Use as e.g.
00635  *
00636  * @code
00637  *
00638  *   struct {
00639  *      char    rx_buf[NUM_RX_BUF][RX_BUF_SIZE];
00640  *      char    tx_buf[TX_BUF_SIZE];
00641  *   } my_static_data __shared;
00642  *
00643  * @endcode
00644  *
00645  */
00646 #define __shared __asm__ ( "_shared_bss" ) __aligned
00647 
00648 #endif /* ASSEMBLY */
00649 /** @} */
00650 
00651 /**
00652  * Optimisation barrier
00653  */
00654 #ifndef ASSEMBLY
00655 #define barrier() __asm__ __volatile__ ( "" : : : "memory" )
00656 #endif /* ASSEMBLY */
00657 
00658 /**
00659  * Array size
00660  */
00661 #ifndef ASSEMBLY
00662 #define ARRAY_SIZE(array) ( sizeof (array) / sizeof ( (array)[0] ) )
00663 #endif /* ASSEMBLY */
00664 
00665 /**
00666  * @defgroup licences Licence declarations
00667  *
00668  * For reasons that are partly historical, various different files
00669  * within the iPXE codebase have differing licences.
00670  *
00671  * @{
00672  */
00673 
00674 /** Declare a file as being in the public domain
00675  *
00676  * This licence declaration is applicable when a file states itself to
00677  * be in the public domain.
00678  */
00679 #define FILE_LICENCE_PUBLIC_DOMAIN \
00680         PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__public_domain__ ) )
00681 
00682 /** Declare a file as being under version 2 (or later) of the GNU GPL
00683  *
00684  * This licence declaration is applicable when a file states itself to
00685  * be licensed under the GNU GPL; "either version 2 of the License, or
00686  * (at your option) any later version".
00687  */
00688 #define FILE_LICENCE_GPL2_OR_LATER \
00689         PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_or_later__ ) )
00690 
00691 /** Declare a file as being under version 2 of the GNU GPL
00692  *
00693  * This licence declaration is applicable when a file states itself to
00694  * be licensed under version 2 of the GPL, and does not include the
00695  * "or, at your option, any later version" clause.
00696  */
00697 #define FILE_LICENCE_GPL2_ONLY \
00698         PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_only__ ) )
00699 
00700 /** Declare a file as being under any version of the GNU GPL
00701  *
00702  * This licence declaration is applicable when a file states itself to
00703  * be licensed under the GPL, but does not specify a version.
00704  *
00705  * According to section 9 of the GPLv2, "If the Program does not
00706  * specify a version number of this License, you may choose any
00707  * version ever published by the Free Software Foundation".
00708  */
00709 #define FILE_LICENCE_GPL_ANY \
00710         PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl_any__ ) )
00711 
00712 /** Declare a file as being under the three-clause BSD licence
00713  *
00714  * This licence declaration is applicable when a file states itself to
00715  * be licensed under terms allowing redistribution in source and
00716  * binary forms (with or without modification) provided that:
00717  *
00718  *     redistributions of source code retain the copyright notice,
00719  *     list of conditions and any attached disclaimers
00720  *
00721  *     redistributions in binary form reproduce the copyright notice,
00722  *     list of conditions and any attached disclaimers in the
00723  *     documentation and/or other materials provided with the
00724  *     distribution
00725  *
00726  *     the name of the author is not used to endorse or promote
00727  *     products derived from the software without specific prior
00728  *     written permission
00729  *
00730  * It is not necessary for the file to explicitly state that it is
00731  * under a "BSD" licence; only that the licensing terms be
00732  * functionally equivalent to the standard three-clause BSD licence.
00733  */
00734 #define FILE_LICENCE_BSD3 \
00735         PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd3__ ) )
00736 
00737 /** Declare a file as being under the two-clause BSD licence
00738  *
00739  * This licence declaration is applicable when a file states itself to
00740  * be licensed under terms allowing redistribution in source and
00741  * binary forms (with or without modification) provided that:
00742  *
00743  *     redistributions of source code retain the copyright notice,
00744  *     list of conditions and any attached disclaimers
00745  *
00746  *     redistributions in binary form reproduce the copyright notice,
00747  *     list of conditions and any attached disclaimers in the
00748  *     documentation and/or other materials provided with the
00749  *     distribution
00750  *
00751  * It is not necessary for the file to explicitly state that it is
00752  * under a "BSD" licence; only that the licensing terms be
00753  * functionally equivalent to the standard two-clause BSD licence.
00754  */
00755 #define FILE_LICENCE_BSD2 \
00756         PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd2__ ) )
00757 
00758 /** Declare a file as being under the one-clause MIT-style licence
00759  *
00760  * This licence declaration is applicable when a file states itself to
00761  * be licensed under terms allowing redistribution for any purpose
00762  * with or without fee, provided that the copyright notice and
00763  * permission notice appear in all copies.
00764  */
00765 #define FILE_LICENCE_MIT \
00766         PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__mit__ ) )
00767 
00768 /** Declare a file as being under GPLv2+ or UBDL
00769  *
00770  * This licence declaration is applicable when a file states itself to
00771  * be licensed under the GNU GPL; "either version 2 of the License, or
00772  * (at your option) any later version" and also states that it may be
00773  * distributed under the terms of the Unmodified Binary Distribution
00774  * Licence (as given in the file COPYING.UBDL).
00775  */
00776 #define FILE_LICENCE_GPL2_OR_LATER_OR_UBDL \
00777         PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_or_later_or_ubdl__ ) )
00778 
00779 /** Declare a particular licence as applying to a file */
00780 #define FILE_LICENCE( _licence ) FILE_LICENCE_ ## _licence
00781 
00782 /** @} */
00783 
00784 /* This file itself is under GPLv2+/UBDL */
00785 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00786 
00787 #include <bits/compiler.h>
00788 
00789 #endif /* COMPILER_H */