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