|
|
1.1 ! root 1: #ifndef COMPILER_H ! 2: #define COMPILER_H ! 3: ! 4: /* ! 5: * Doxygen can't cope with some of the more esoteric areas of C, so we ! 6: * make its life simpler. ! 7: * ! 8: */ ! 9: #ifdef DOXYGEN ! 10: #define __attribute__(x) ! 11: #endif ! 12: ! 13: /** @file ! 14: * ! 15: * Global compiler definitions. ! 16: * ! 17: * This file is implicitly included by every @c .c file in Etherboot. ! 18: * It defines global macros such as DBG(). ! 19: * ! 20: * We arrange for each object to export the symbol @c obj_OBJECT ! 21: * (where @c OBJECT is the object name, e.g. @c rtl8139) as a global ! 22: * symbol, so that the linker can drag in selected object files from ! 23: * the library using <tt> -u obj_OBJECT </tt>. ! 24: * ! 25: */ ! 26: ! 27: /* Force visibility of all symbols to "hidden", i.e. inform gcc that ! 28: * all symbol references resolve strictly within our final binary. ! 29: * This avoids unnecessary PLT/GOT entries on x86_64. ! 30: * ! 31: * This is a stronger claim than specifying "-fvisibility=hidden", ! 32: * since it also affects symbols marked with "extern". ! 33: */ ! 34: #ifndef ASSEMBLY ! 35: #if __GNUC__ >= 4 ! 36: #pragma GCC visibility push(hidden) ! 37: #endif ! 38: #endif /* ASSEMBLY */ ! 39: ! 40: #undef _S1 ! 41: #undef _S2 ! 42: #undef _C1 ! 43: #undef _C2 ! 44: ! 45: /** Concatenate non-expanded arguments */ ! 46: #define _C1( x, y ) x ## y ! 47: /** Concatenate expanded arguments */ ! 48: #define _C2( x, y ) _C1 ( x, y ) ! 49: ! 50: /** Stringify non-expanded argument */ ! 51: #define _S1( x ) #x ! 52: /** Stringify expanded argument */ ! 53: #define _S2( x ) _S1 ( x ) ! 54: ! 55: /** ! 56: * @defgroup symmacros Macros to provide or require explicit symbols ! 57: * @{ ! 58: */ ! 59: ! 60: /** Provide a symbol within this object file */ ! 61: #ifdef ASSEMBLY ! 62: #define PROVIDE_SYMBOL( _sym ) \ ! 63: .globl _sym ; \ ! 64: .comm _sym, 0 ! 65: #else /* ASSEMBLY */ ! 66: #define PROVIDE_SYMBOL( _sym ) \ ! 67: char _sym[0] ! 68: #endif /* ASSEMBLY */ ! 69: ! 70: /** Require a symbol within this object file ! 71: * ! 72: * The symbol is referenced by a relocation in a discarded section, so ! 73: * if it is not available at link time the link will fail. ! 74: */ ! 75: #ifdef ASSEMBLY ! 76: #define REQUIRE_SYMBOL( _sym ) \ ! 77: .section ".discard", "a", @progbits ; \ ! 78: .extern _sym ; \ ! 79: .long _sym ; \ ! 80: .previous ! 81: #else /* ASSEMBLY */ ! 82: #define REQUIRE_SYMBOL( _sym ) \ ! 83: extern char _sym; \ ! 84: static char * _C2 ( _C2 ( __require_, _sym ), _C2 ( _, __LINE__ ) ) \ ! 85: __attribute__ (( section ( ".discard" ), used )) \ ! 86: = &_sym ! 87: #endif ! 88: ! 89: /** Request that a symbol be available at runtime ! 90: * ! 91: * The requested symbol is entered as undefined into the symbol table ! 92: * for this object, so the linker will pull in other object files as ! 93: * necessary to satisfy the reference. However, the undefined symbol ! 94: * is not referenced in any relocations, so the link can still succeed ! 95: * if no file contains it. ! 96: * ! 97: * A symbol passed to this macro may not be referenced anywhere ! 98: * else in the file. If you want to do that, see IMPORT_SYMBOL(). ! 99: */ ! 100: #ifdef ASSEMBLY ! 101: #define REQUEST_SYMBOL( _sym ) \ ! 102: .equ __need_ ## _sym, _sym ! 103: #else /* ASSEMBLY */ ! 104: #define REQUEST_SYMBOL( _sym ) \ ! 105: __asm__ ( ".equ\t__need_" #_sym ", " #_sym ) ! 106: #endif /* ASSEMBLY */ ! 107: ! 108: /** Set up a symbol to be usable in another file by IMPORT_SYMBOL() ! 109: * ! 110: * The symbol must already be marked as global. ! 111: */ ! 112: #define EXPORT_SYMBOL( _sym ) PROVIDE_SYMBOL ( __export_ ## _sym ) ! 113: ! 114: /** Make a symbol usable to this file if available at link time ! 115: * ! 116: * If no file passed to the linker contains the symbol, it will have ! 117: * @c NULL value to future uses. Keep in mind that the symbol value is ! 118: * really the @e address of a variable or function; see the code ! 119: * snippet below. ! 120: * ! 121: * In C using IMPORT_SYMBOL, you must specify the declaration as the ! 122: * second argument, for instance ! 123: * ! 124: * @code ! 125: * IMPORT_SYMBOL ( my_func, int my_func ( int arg ) ); ! 126: * IMPORT_SYMBOL ( my_var, int my_var ); ! 127: * ! 128: * void use_imports ( void ) { ! 129: * if ( my_func && &my_var ) ! 130: * my_var = my_func ( my_var ); ! 131: * } ! 132: * @endcode ! 133: * ! 134: * GCC considers a weak declaration to override a strong one no matter ! 135: * which comes first, so it is safe to include a header file declaring ! 136: * the imported symbol normally, but providing the declaration to ! 137: * IMPORT_SYMBOL is still required. ! 138: * ! 139: * If no EXPORT_SYMBOL declaration exists for the imported symbol in ! 140: * another file, the behavior will be most likely be identical to that ! 141: * for an unavailable symbol. ! 142: */ ! 143: #ifdef ASSEMBLY ! 144: #define IMPORT_SYMBOL( _sym ) \ ! 145: REQUEST_SYMBOL ( __export_ ## _sym ) ; \ ! 146: .weak _sym ! 147: #else /* ASSEMBLY */ ! 148: #define IMPORT_SYMBOL( _sym, _decl ) \ ! 149: REQUEST_SYMBOL ( __export_ ## _sym ) ; \ ! 150: extern _decl __attribute__ (( weak )) ! 151: #endif ! 152: ! 153: /** @} */ ! 154: ! 155: /** ! 156: * @defgroup objmacros Macros to provide or require explicit objects ! 157: * @{ ! 158: */ ! 159: ! 160: #define PREFIX_OBJECT( _prefix ) _C2 ( _prefix, OBJECT ) ! 161: #define OBJECT_SYMBOL PREFIX_OBJECT ( obj_ ) ! 162: #define REQUEST_EXPANDED( _sym ) REQUEST_SYMBOL ( _sym ) ! 163: #define CONFIG_SYMBOL PREFIX_OBJECT ( obj_config_ ) ! 164: ! 165: /** Always provide the symbol for the current object (defined by -DOBJECT) */ ! 166: PROVIDE_SYMBOL ( OBJECT_SYMBOL ); ! 167: ! 168: /** Pull in an object-specific configuration file if available */ ! 169: REQUEST_EXPANDED ( CONFIG_SYMBOL ); ! 170: ! 171: /** Explicitly require another object */ ! 172: #define REQUIRE_OBJECT( _obj ) REQUIRE_SYMBOL ( obj_ ## _obj ) ! 173: ! 174: /** Pull in another object if it exists */ ! 175: #define REQUEST_OBJECT( _obj ) REQUEST_SYMBOL ( obj_ ## _obj ) ! 176: ! 177: /** @} */ ! 178: ! 179: /** Select file identifier for errno.h (if used) */ ! 180: #define ERRFILE PREFIX_OBJECT ( ERRFILE_ ) ! 181: ! 182: #ifndef ASSEMBLY ! 183: ! 184: /** Declare a function as weak (use *before* the definition) ! 185: * ! 186: * Due to a bug in at least GCC 4.4.4 and earlier, weak symbols may be ! 187: * inlined if they have hidden visibility (see above for why hidden ! 188: * visibility is used). This results in the non-weak symbol never ! 189: * being used, so explicitly mark the function as noinline to prevent ! 190: * inlining. ! 191: */ ! 192: #define __weak __attribute__ (( weak, noinline )) ! 193: ! 194: /** Prevent a function from being optimized away without inlining ! 195: * ! 196: * Calls to functions with void return type that contain no code in their body ! 197: * may be removed by gcc's optimizer even when inlining is inhibited. Placing ! 198: * this macro in the body of the function prevents that from occurring. ! 199: */ ! 200: #define __keepme asm(""); ! 201: ! 202: #endif ! 203: ! 204: /** @defgroup dbg Debugging infrastructure ! 205: * @{ ! 206: */ ! 207: ! 208: /** @def DBG ! 209: * ! 210: * Print a debugging message. ! 211: * ! 212: * The debug level is set at build time by specifying the @c DEBUG= ! 213: * parameter on the @c make command line. For example, to enable ! 214: * debugging for the PCI bus functions (in pci.c) in a @c .dsk image ! 215: * for the @c rtl8139 card, you could use the command line ! 216: * ! 217: * @code ! 218: * ! 219: * make bin/rtl8139.dsk DEBUG=pci ! 220: * ! 221: * @endcode ! 222: * ! 223: * This will enable the debugging statements (DBG()) in pci.c. If ! 224: * debugging is not enabled, DBG() statements will be ignored. ! 225: * ! 226: * You can enable debugging in several objects simultaneously by ! 227: * separating them with commas, as in ! 228: * ! 229: * @code ! 230: * ! 231: * make bin/rtl8139.dsk DEBUG=pci,buffer,heap ! 232: * ! 233: * @endcode ! 234: * ! 235: * You can increase the debugging level for an object by specifying it ! 236: * with @c :N, where @c N is the level, as in ! 237: * ! 238: * @code ! 239: * ! 240: * make bin/rtl8139.dsk DEBUG=pci,buffer:2,heap ! 241: * ! 242: * @endcode ! 243: * ! 244: * which would enable debugging for the PCI, buffer-handling and ! 245: * heap-allocation code, with the buffer-handling code at level 2. ! 246: * ! 247: */ ! 248: ! 249: /* ! 250: * If debug_OBJECT is set to a true value, the macro DBG(...) will ! 251: * expand to printf(...) when compiling OBJECT, and the symbol ! 252: * DEBUG_LEVEL will be inserted into the object file. ! 253: * ! 254: */ ! 255: #define DEBUG_SYMBOL PREFIX_OBJECT ( debug_ ) ! 256: ! 257: #if DEBUG_SYMBOL == 0 ! 258: #define NDEBUG ! 259: #endif ! 260: ! 261: #ifndef ASSEMBLY ! 262: ! 263: /** printf() for debugging ! 264: * ! 265: * This function exists so that the DBG() macros can expand to ! 266: * printf() calls without dragging the printf() prototype into scope. ! 267: * ! 268: * As far as the compiler is concerned, dbg_printf() and printf() are ! 269: * completely unrelated calls; it's only at the assembly stage that ! 270: * references to the dbg_printf symbol are collapsed into references ! 271: * to the printf symbol. ! 272: */ ! 273: extern int __attribute__ (( format ( printf, 1, 2 ) )) ! 274: dbg_printf ( const char *fmt, ... ) asm ( "printf" ); ! 275: ! 276: extern void dbg_autocolourise ( unsigned long id ); ! 277: extern void dbg_decolourise ( void ); ! 278: extern void dbg_hex_dump_da ( unsigned long dispaddr, ! 279: const void *data, unsigned long len ); ! 280: extern void dbg_md5_da ( unsigned long dispaddr, ! 281: const void *data, unsigned long len ); ! 282: extern void dbg_pause ( void ); ! 283: extern void dbg_more ( void ); ! 284: ! 285: #if DEBUG_SYMBOL ! 286: #define DBGLVL_MAX DEBUG_SYMBOL ! 287: #else ! 288: #define DBGLVL_MAX 0 ! 289: #endif ! 290: ! 291: /* Allow for selective disabling of enabled debug levels */ ! 292: #if DBGLVL_MAX ! 293: int __debug_disable; ! 294: #define DBGLVL ( DBGLVL_MAX & ~__debug_disable ) ! 295: #define DBG_DISABLE( level ) do { \ ! 296: __debug_disable |= (level); \ ! 297: } while ( 0 ) ! 298: #define DBG_ENABLE( level ) do { \ ! 299: __debug_disable &= ~(level); \ ! 300: } while ( 0 ) ! 301: #else ! 302: #define DBGLVL 0 ! 303: #define DBG_DISABLE( level ) do { } while ( 0 ) ! 304: #define DBG_ENABLE( level ) do { } while ( 0 ) ! 305: #endif ! 306: ! 307: #define DBGLVL_LOG 1 ! 308: #define DBG_LOG ( DBGLVL & DBGLVL_LOG ) ! 309: #define DBGLVL_EXTRA 2 ! 310: #define DBG_EXTRA ( DBGLVL & DBGLVL_EXTRA ) ! 311: #define DBGLVL_PROFILE 4 ! 312: #define DBG_PROFILE ( DBGLVL & DBGLVL_PROFILE ) ! 313: #define DBGLVL_IO 8 ! 314: #define DBG_IO ( DBGLVL & DBGLVL_IO ) ! 315: ! 316: /** ! 317: * Print debugging message if we are at a certain debug level ! 318: * ! 319: * @v level Debug level ! 320: * @v ... printf() argument list ! 321: */ ! 322: #define DBG_IF( level, ... ) do { \ ! 323: if ( DBG_ ## level ) { \ ! 324: dbg_printf ( __VA_ARGS__ ); \ ! 325: } \ ! 326: } while ( 0 ) ! 327: ! 328: /** ! 329: * Print a hex dump if we are at a certain debug level ! 330: * ! 331: * @v level Debug level ! 332: * @v dispaddr Display address ! 333: * @v data Data to print ! 334: * @v len Length of data ! 335: */ ! 336: #define DBG_HDA_IF( level, dispaddr, data, len ) do { \ ! 337: if ( DBG_ ## level ) { \ ! 338: union { \ ! 339: unsigned long ul; \ ! 340: typeof ( dispaddr ) raw; \ ! 341: } da; \ ! 342: da.raw = dispaddr; \ ! 343: dbg_hex_dump_da ( da.ul, data, len ); \ ! 344: } \ ! 345: } while ( 0 ) ! 346: ! 347: /** ! 348: * Print a hex dump if we are at a certain debug level ! 349: * ! 350: * @v level Debug level ! 351: * @v data Data to print ! 352: * @v len Length of data ! 353: */ ! 354: #define DBG_HD_IF( level, data, len ) do { \ ! 355: const void *_data = data; \ ! 356: DBG_HDA_IF ( level, _data, _data, len ); \ ! 357: } while ( 0 ) ! 358: ! 359: /** ! 360: * Print an MD5 checksum if we are at a certain debug level ! 361: * ! 362: * @v level Debug level ! 363: * @v dispaddr Display address ! 364: * @v data Data to print ! 365: * @v len Length of data ! 366: */ ! 367: #define DBG_MD5A_IF( level, dispaddr, data, len ) do { \ ! 368: if ( DBG_ ## level ) { \ ! 369: union { \ ! 370: unsigned long ul; \ ! 371: typeof ( dispaddr ) raw; \ ! 372: } da; \ ! 373: da.raw = dispaddr; \ ! 374: dbg_md5_da ( da.ul, data, len ); \ ! 375: } \ ! 376: } while ( 0 ) ! 377: ! 378: /** ! 379: * Print an MD5 checksum if we are at a certain debug level ! 380: * ! 381: * @v level Debug level ! 382: * @v data Data to print ! 383: * @v len Length of data ! 384: */ ! 385: #define DBG_MD5_IF( level, data, len ) do { \ ! 386: const void *_data = data; \ ! 387: DBG_MD5A_IF ( level, _data, _data, len ); \ ! 388: } while ( 0 ) ! 389: ! 390: /** ! 391: * Prompt for key press if we are at a certain debug level ! 392: * ! 393: * @v level Debug level ! 394: */ ! 395: #define DBG_PAUSE_IF( level ) do { \ ! 396: if ( DBG_ ## level ) { \ ! 397: dbg_pause(); \ ! 398: } \ ! 399: } while ( 0 ) ! 400: ! 401: /** ! 402: * Prompt for more output data if we are at a certain debug level ! 403: * ! 404: * @v level Debug level ! 405: */ ! 406: #define DBG_MORE_IF( level ) do { \ ! 407: if ( DBG_ ## level ) { \ ! 408: dbg_more(); \ ! 409: } \ ! 410: } while ( 0 ) ! 411: ! 412: /** ! 413: * Select colour for debug messages if we are at a certain debug level ! 414: * ! 415: * @v level Debug level ! 416: * @v id Message stream ID ! 417: */ ! 418: #define DBG_AC_IF( level, id ) do { \ ! 419: if ( DBG_ ## level ) { \ ! 420: union { \ ! 421: unsigned long ul; \ ! 422: typeof ( id ) raw; \ ! 423: } dbg_stream; \ ! 424: dbg_stream.raw = id; \ ! 425: dbg_autocolourise ( dbg_stream.ul ); \ ! 426: } \ ! 427: } while ( 0 ) ! 428: ! 429: /** ! 430: * Revert colour for debug messages if we are at a certain debug level ! 431: * ! 432: * @v level Debug level ! 433: */ ! 434: #define DBG_DC_IF( level ) do { \ ! 435: if ( DBG_ ## level ) { \ ! 436: dbg_decolourise(); \ ! 437: } \ ! 438: } while ( 0 ) ! 439: ! 440: /* Autocolourising versions of the DBGxxx_IF() macros */ ! 441: ! 442: #define DBGC_IF( level, id, ... ) do { \ ! 443: DBG_AC_IF ( level, id ); \ ! 444: DBG_IF ( level, __VA_ARGS__ ); \ ! 445: DBG_DC_IF ( level ); \ ! 446: } while ( 0 ) ! 447: ! 448: #define DBGC_HDA_IF( level, id, ... ) do { \ ! 449: DBG_AC_IF ( level, id ); \ ! 450: DBG_HDA_IF ( level, __VA_ARGS__ ); \ ! 451: DBG_DC_IF ( level ); \ ! 452: } while ( 0 ) ! 453: ! 454: #define DBGC_HD_IF( level, id, ... ) do { \ ! 455: DBG_AC_IF ( level, id ); \ ! 456: DBG_HD_IF ( level, __VA_ARGS__ ); \ ! 457: DBG_DC_IF ( level ); \ ! 458: } while ( 0 ) ! 459: ! 460: #define DBGC_MD5A_IF( level, id, ... ) do { \ ! 461: DBG_AC_IF ( level, id ); \ ! 462: DBG_MD5A_IF ( level, __VA_ARGS__ ); \ ! 463: DBG_DC_IF ( level ); \ ! 464: } while ( 0 ) ! 465: ! 466: #define DBGC_MD5_IF( level, id, ... ) do { \ ! 467: DBG_AC_IF ( level, id ); \ ! 468: DBG_MD5_IF ( level, __VA_ARGS__ ); \ ! 469: DBG_DC_IF ( level ); \ ! 470: } while ( 0 ) ! 471: ! 472: #define DBGC_PAUSE_IF( level, id ) do { \ ! 473: DBG_AC_IF ( level, id ); \ ! 474: DBG_PAUSE_IF ( level ); \ ! 475: DBG_DC_IF ( level ); \ ! 476: } while ( 0 ) ! 477: ! 478: #define DBGC_MORE_IF( level, id ) do { \ ! 479: DBG_AC_IF ( level, id ); \ ! 480: DBG_MORE_IF ( level ); \ ! 481: DBG_DC_IF ( level ); \ ! 482: } while ( 0 ) ! 483: ! 484: /* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( LOG, ... )*/ ! 485: ! 486: #define DBG( ... ) DBG_IF ( LOG, ##__VA_ARGS__ ) ! 487: #define DBG_HDA( ... ) DBG_HDA_IF ( LOG, ##__VA_ARGS__ ) ! 488: #define DBG_HD( ... ) DBG_HD_IF ( LOG, ##__VA_ARGS__ ) ! 489: #define DBG_MD5A( ... ) DBG_MD5A_IF ( LOG, ##__VA_ARGS__ ) ! 490: #define DBG_MD5( ... ) DBG_MD5_IF ( LOG, ##__VA_ARGS__ ) ! 491: #define DBG_PAUSE( ... ) DBG_PAUSE_IF ( LOG, ##__VA_ARGS__ ) ! 492: #define DBG_MORE( ... ) DBG_MORE_IF ( LOG, ##__VA_ARGS__ ) ! 493: #define DBGC( ... ) DBGC_IF ( LOG, ##__VA_ARGS__ ) ! 494: #define DBGC_HDA( ... ) DBGC_HDA_IF ( LOG, ##__VA_ARGS__ ) ! 495: #define DBGC_HD( ... ) DBGC_HD_IF ( LOG, ##__VA_ARGS__ ) ! 496: #define DBGC_MD5A( ... ) DBGC_MD5A_IF ( LOG, ##__VA_ARGS__ ) ! 497: #define DBGC_MD5( ... ) DBGC_MD5_IF ( LOG, ##__VA_ARGS__ ) ! 498: #define DBGC_PAUSE( ... ) DBGC_PAUSE_IF ( LOG, ##__VA_ARGS__ ) ! 499: #define DBGC_MORE( ... ) DBGC_MORE_IF ( LOG, ##__VA_ARGS__ ) ! 500: ! 501: /* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( EXTRA, ... )*/ ! 502: ! 503: #define DBG2( ... ) DBG_IF ( EXTRA, ##__VA_ARGS__ ) ! 504: #define DBG2_HDA( ... ) DBG_HDA_IF ( EXTRA, ##__VA_ARGS__ ) ! 505: #define DBG2_HD( ... ) DBG_HD_IF ( EXTRA, ##__VA_ARGS__ ) ! 506: #define DBG2_MD5A( ... ) DBG_MD5A_IF ( EXTRA, ##__VA_ARGS__ ) ! 507: #define DBG2_MD5( ... ) DBG_MD5_IF ( EXTRA, ##__VA_ARGS__ ) ! 508: #define DBG2_PAUSE( ... ) DBG_PAUSE_IF ( EXTRA, ##__VA_ARGS__ ) ! 509: #define DBG2_MORE( ... ) DBG_MORE_IF ( EXTRA, ##__VA_ARGS__ ) ! 510: #define DBGC2( ... ) DBGC_IF ( EXTRA, ##__VA_ARGS__ ) ! 511: #define DBGC2_HDA( ... ) DBGC_HDA_IF ( EXTRA, ##__VA_ARGS__ ) ! 512: #define DBGC2_HD( ... ) DBGC_HD_IF ( EXTRA, ##__VA_ARGS__ ) ! 513: #define DBGC2_MD5A( ... ) DBGC_MD5A_IF ( EXTRA, ##__VA_ARGS__ ) ! 514: #define DBGC2_MD5( ... ) DBGC_MD5_IF ( EXTRA, ##__VA_ARGS__ ) ! 515: #define DBGC2_PAUSE( ... ) DBGC_PAUSE_IF ( EXTRA, ##__VA_ARGS__ ) ! 516: #define DBGC2_MORE( ... ) DBGC_MORE_IF ( EXTRA, ##__VA_ARGS__ ) ! 517: ! 518: /* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( PROFILE, ... )*/ ! 519: ! 520: #define DBGP( ... ) DBG_IF ( PROFILE, ##__VA_ARGS__ ) ! 521: #define DBGP_HDA( ... ) DBG_HDA_IF ( PROFILE, ##__VA_ARGS__ ) ! 522: #define DBGP_HD( ... ) DBG_HD_IF ( PROFILE, ##__VA_ARGS__ ) ! 523: #define DBGP_MD5A( ... ) DBG_MD5A_IF ( PROFILE, ##__VA_ARGS__ ) ! 524: #define DBGP_MD5( ... ) DBG_MD5_IF ( PROFILE, ##__VA_ARGS__ ) ! 525: #define DBGP_PAUSE( ... ) DBG_PAUSE_IF ( PROFILE, ##__VA_ARGS__ ) ! 526: #define DBGP_MORE( ... ) DBG_MORE_IF ( PROFILE, ##__VA_ARGS__ ) ! 527: #define DBGCP( ... ) DBGC_IF ( PROFILE, ##__VA_ARGS__ ) ! 528: #define DBGCP_HDA( ... ) DBGC_HDA_IF ( PROFILE, ##__VA_ARGS__ ) ! 529: #define DBGCP_HD( ... ) DBGC_HD_IF ( PROFILE, ##__VA_ARGS__ ) ! 530: #define DBGCP_MD5A( ... ) DBGC_MD5A_IF ( PROFILE, ##__VA_ARGS__ ) ! 531: #define DBGCP_MD5( ... ) DBGC_MD5_IF ( PROFILE, ##__VA_ARGS__ ) ! 532: #define DBGCP_PAUSE( ... ) DBGC_PAUSE_IF ( PROFILE, ##__VA_ARGS__ ) ! 533: #define DBGCP_MORE( ... ) DBGC_MORE_IF ( PROFILE, ##__VA_ARGS__ ) ! 534: ! 535: /* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( IO, ... )*/ ! 536: ! 537: #define DBGIO( ... ) DBG_IF ( IO, ##__VA_ARGS__ ) ! 538: #define DBGIO_HDA( ... ) DBG_HDA_IF ( IO, ##__VA_ARGS__ ) ! 539: #define DBGIO_HD( ... ) DBG_HD_IF ( IO, ##__VA_ARGS__ ) ! 540: #define DBGIO_MD5A( ... ) DBG_MD5A_IF ( IO, ##__VA_ARGS__ ) ! 541: #define DBGIO_MD5( ... ) DBG_MD5_IF ( IO, ##__VA_ARGS__ ) ! 542: #define DBGIO_PAUSE( ... ) DBG_PAUSE_IF ( IO, ##__VA_ARGS__ ) ! 543: #define DBGIO_MORE( ... ) DBG_MORE_IF ( IO, ##__VA_ARGS__ ) ! 544: #define DBGCIO( ... ) DBGC_IF ( IO, ##__VA_ARGS__ ) ! 545: #define DBGCIO_HDA( ... ) DBGC_HDA_IF ( IO, ##__VA_ARGS__ ) ! 546: #define DBGCIO_HD( ... ) DBGC_HD_IF ( IO, ##__VA_ARGS__ ) ! 547: #define DBGCIO_MD5A( ... ) DBGC_MD5A_IF ( IO, ##__VA_ARGS__ ) ! 548: #define DBGCIO_MD5( ... ) DBGC_MD5_IF ( IO, ##__VA_ARGS__ ) ! 549: #define DBGCIO_PAUSE( ... ) DBGC_PAUSE_IF ( IO, ##__VA_ARGS__ ) ! 550: #define DBGCIO_MORE( ... ) DBGC_MORE_IF ( IO, ##__VA_ARGS__ ) ! 551: ! 552: #endif /* ASSEMBLY */ ! 553: /** @} */ ! 554: ! 555: /** @defgroup attrs Miscellaneous attributes ! 556: * @{ ! 557: */ ! 558: #ifndef ASSEMBLY ! 559: ! 560: /** Declare a variable or data structure as unused. */ ! 561: #define __unused __attribute__ (( unused )) ! 562: ! 563: /** ! 564: * Declare a function as pure - i.e. without side effects ! 565: */ ! 566: #define __pure __attribute__ (( pure )) ! 567: ! 568: /** ! 569: * Declare a function as const - i.e. it does not access global memory ! 570: * (including dereferencing pointers passed to it) at all. ! 571: * Must also not call any non-const functions. ! 572: */ ! 573: #define __const __attribute__ (( const )) ! 574: ! 575: /** ! 576: * Declare a function's pointer parameters as non-null - i.e. force ! 577: * compiler to check pointers at compile time and enable possible ! 578: * optimizations based on that fact ! 579: */ ! 580: #define __nonnull __attribute__ (( nonnull )) ! 581: ! 582: /** ! 583: * Declare a pointer returned by a function as a unique memory address ! 584: * as returned by malloc-type functions. ! 585: */ ! 586: #define __malloc __attribute__ (( malloc )) ! 587: ! 588: /** ! 589: * Declare a function as used. ! 590: * ! 591: * Necessary only if the function is called only from assembler code. ! 592: */ ! 593: #define __used __attribute__ (( used )) ! 594: ! 595: /** Declare a data structure to be aligned with 16-byte alignment */ ! 596: #define __aligned __attribute__ (( aligned ( 16 ) )) ! 597: ! 598: /** Declare a function to be always inline */ ! 599: #define __always_inline __attribute__ (( always_inline )) ! 600: ! 601: /* Force all inline functions to not be instrumented ! 602: * ! 603: * This is required to cope with what seems to be a long-standing gcc ! 604: * bug, in which -finstrument-functions will cause instances of ! 605: * inlined functions to be reported as further calls to the ! 606: * *containing* function. This makes instrumentation very difficult ! 607: * to use. ! 608: * ! 609: * Work around this problem by adding the no_instrument_function ! 610: * attribute to all inlined functions. ! 611: */ ! 612: #define inline inline __attribute__ (( no_instrument_function )) ! 613: ! 614: /** ! 615: * Shared data. ! 616: * ! 617: * To save space in the binary when multiple-driver images are ! 618: * compiled, uninitialised data areas can be shared between drivers. ! 619: * This will typically be used to share statically-allocated receive ! 620: * and transmit buffers between drivers. ! 621: * ! 622: * Use as e.g. ! 623: * ! 624: * @code ! 625: * ! 626: * struct { ! 627: * char rx_buf[NUM_RX_BUF][RX_BUF_SIZE]; ! 628: * char tx_buf[TX_BUF_SIZE]; ! 629: * } my_static_data __shared; ! 630: * ! 631: * @endcode ! 632: * ! 633: */ ! 634: #define __shared __asm__ ( "_shared_bss" ) __aligned ! 635: ! 636: #endif /* ASSEMBLY */ ! 637: /** @} */ ! 638: ! 639: /** ! 640: * Optimisation barrier ! 641: */ ! 642: #ifndef ASSEMBLY ! 643: #define barrier() __asm__ __volatile__ ( "" : : : "memory" ) ! 644: #endif /* ASSEMBLY */ ! 645: ! 646: /** ! 647: * @defgroup licences Licence declarations ! 648: * ! 649: * For reasons that are partly historical, various different files ! 650: * within the iPXE codebase have differing licences. ! 651: * ! 652: * @{ ! 653: */ ! 654: ! 655: /** Declare a file as being in the public domain ! 656: * ! 657: * This licence declaration is applicable when a file states itself to ! 658: * be in the public domain. ! 659: */ ! 660: #define FILE_LICENCE_PUBLIC_DOMAIN \ ! 661: PROVIDE_SYMBOL ( __licence_public_domain ) ! 662: ! 663: /** Declare a file as being under version 2 (or later) of the GNU GPL ! 664: * ! 665: * This licence declaration is applicable when a file states itself to ! 666: * be licensed under the GNU GPL; "either version 2 of the License, or ! 667: * (at your option) any later version". ! 668: */ ! 669: #define FILE_LICENCE_GPL2_OR_LATER \ ! 670: PROVIDE_SYMBOL ( __licence_gpl2_or_later ) ! 671: ! 672: /** Declare a file as being under version 2 of the GNU GPL ! 673: * ! 674: * This licence declaration is applicable when a file states itself to ! 675: * be licensed under version 2 of the GPL, and does not include the ! 676: * "or, at your option, any later version" clause. ! 677: */ ! 678: #define FILE_LICENCE_GPL2_ONLY \ ! 679: PROVIDE_SYMBOL ( __licence_gpl2_only ) ! 680: ! 681: /** Declare a file as being under any version of the GNU GPL ! 682: * ! 683: * This licence declaration is applicable when a file states itself to ! 684: * be licensed under the GPL, but does not specify a version. ! 685: * ! 686: * According to section 9 of the GPLv2, "If the Program does not ! 687: * specify a version number of this License, you may choose any ! 688: * version ever published by the Free Software Foundation". ! 689: */ ! 690: #define FILE_LICENCE_GPL_ANY \ ! 691: PROVIDE_SYMBOL ( __licence_gpl_any ) ! 692: ! 693: /** Declare a file as being under the three-clause BSD licence ! 694: * ! 695: * This licence declaration is applicable when a file states itself to ! 696: * be licensed under terms allowing redistribution in source and ! 697: * binary forms (with or without modification) provided that: ! 698: * ! 699: * redistributions of source code retain the copyright notice, ! 700: * list of conditions and any attached disclaimers ! 701: * ! 702: * redistributions in binary form reproduce the copyright notice, ! 703: * list of conditions and any attached disclaimers in the ! 704: * documentation and/or other materials provided with the ! 705: * distribution ! 706: * ! 707: * the name of the author is not used to endorse or promote ! 708: * products derived from the software without specific prior ! 709: * written permission ! 710: * ! 711: * It is not necessary for the file to explicitly state that it is ! 712: * under a "BSD" licence; only that the licensing terms be ! 713: * functionally equivalent to the standard three-clause BSD licence. ! 714: */ ! 715: #define FILE_LICENCE_BSD3 \ ! 716: PROVIDE_SYMBOL ( __licence_bsd3 ) ! 717: ! 718: /** Declare a file as being under the two-clause BSD licence ! 719: * ! 720: * This licence declaration is applicable when a file states itself to ! 721: * be licensed under terms allowing redistribution in source and ! 722: * binary forms (with or without modification) provided that: ! 723: * ! 724: * redistributions of source code retain the copyright notice, ! 725: * list of conditions and any attached disclaimers ! 726: * ! 727: * redistributions in binary form reproduce the copyright notice, ! 728: * list of conditions and any attached disclaimers in the ! 729: * documentation and/or other materials provided with the ! 730: * distribution ! 731: * ! 732: * It is not necessary for the file to explicitly state that it is ! 733: * under a "BSD" licence; only that the licensing terms be ! 734: * functionally equivalent to the standard two-clause BSD licence. ! 735: */ ! 736: #define FILE_LICENCE_BSD2 \ ! 737: PROVIDE_SYMBOL ( __licence_bsd2 ) ! 738: ! 739: /** Declare a file as being under the one-clause MIT-style licence ! 740: * ! 741: * This licence declaration is applicable when a file states itself to ! 742: * be licensed under terms allowing redistribution for any purpose ! 743: * with or without fee, provided that the copyright notice and ! 744: * permission notice appear in all copies. ! 745: */ ! 746: #define FILE_LICENCE_MIT \ ! 747: PROVIDE_SYMBOL ( __licence_mit ) ! 748: ! 749: /** Declare a particular licence as applying to a file */ ! 750: #define FILE_LICENCE( _licence ) FILE_LICENCE_ ## _licence ! 751: ! 752: /** @} */ ! 753: ! 754: /* This file itself is under GPLv2-or-later */ ! 755: FILE_LICENCE ( GPL2_OR_LATER ); ! 756: ! 757: #include <bits/compiler.h> ! 758: ! 759: #endif /* COMPILER_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.