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

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