Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

compiler.h 22KB

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