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

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