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 23KB

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