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