You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compiler.h 22KB

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