iPXE
compiler.h
Go to the documentation of this file.
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 ipxenote Macros to provide ELF notes
171 * @{
172 */
173
174/* Construct an iPXE-specific ELF note */
175#define IPXE_NOTE( type ) \
176 __asm__ ( ".section \".note.ipxe\", \"\", " \
177 _S2 ( ASM_TCHAR ) "note\n\t" \
178 /* Owner name length */ \
179 ".long 4\n\t" \
180 /* Content length */ \
181 ".long 0\n\t" \
182 /* Type */ \
183 ".long " _S2 ( _C2 ( IPXE_NOTE_, type ) ) \
184 "\n\t" \
185 /* Owner name */ \
186 ".ascii \"iPXE\"\n\t" \
187 ".previous\n\t" )
188
189/** Build will use a disk-based console log, if present */
190#define IPXE_NOTE_DISKLOG 0x18aed109
191
192/** @} */
193
194/**
195 * @defgroup objmacros Macros to provide or require explicit objects
196 * @{
197 */
198
199#define PREFIX_OBJECT( _prefix ) _C2 ( _prefix, OBJECT )
200#define OBJECT_SYMBOL PREFIX_OBJECT ( obj_ )
201
202/** Always provide the symbol for the current object (defined by -DOBJECT) */
204
205/**
206 * Request an object
207 *
208 * @v object Object name
209 *
210 * Request an object to be included within the link. If the object
211 * cannot be found, the link will succeed anyway.
212 */
213#define REQUEST_OBJECT( object ) REQUEST_SYMBOL ( obj_ ## object )
214
215/**
216 * Require an object
217 *
218 * @v object Object name
219 *
220 * Require an object to be included within the link. If the object
221 * cannot be found, the link will fail.
222 *
223 * To use this macro within a file, you must also specify the file's
224 * "requiring symbol" using the REQUIRING_SYMBOL() or
225 * PROVIDE_REQUIRING_SYMBOL() macros.
226 */
227#define REQUIRE_OBJECT( object ) REQUIRE_SYMBOL ( obj_ ## object )
228
229/** @} */
230
231/** Select file identifier for errno.h (if used) */
232#define ERRFILE PREFIX_OBJECT ( ERRFILE_ )
233
234#ifndef ASSEMBLY
235
236/** Declare a function as weak (use *before* the definition)
237 *
238 * Due to a bug in at least GCC 4.4.4 and earlier, weak symbols may be
239 * inlined if they have hidden visibility (see above for why hidden
240 * visibility is used). This results in the non-weak symbol never
241 * being used, so explicitly mark the function as noinline to prevent
242 * inlining.
243 */
244#define __weak __attribute__ (( weak, noinline ))
245
246#endif
247
248/** @defgroup dbg Debugging infrastructure
249 * @{
250 */
251
252/** @def DBG
253 *
254 * Print a debugging message.
255 *
256 * The debug level is set at build time by specifying the @c DEBUG=
257 * parameter on the @c make command line. For example, to enable
258 * debugging for the PCI bus functions (in pci.c) in a @c .dsk image
259 * for the @c rtl8139 card, you could use the command line
260 *
261 * @code
262 *
263 * make bin/rtl8139.dsk DEBUG=pci
264 *
265 * @endcode
266 *
267 * This will enable the debugging statements (DBG()) in pci.c. If
268 * debugging is not enabled, DBG() statements will be ignored.
269 *
270 * You can enable debugging in several objects simultaneously by
271 * separating them with commas, as in
272 *
273 * @code
274 *
275 * make bin/rtl8139.dsk DEBUG=pci,buffer,heap
276 *
277 * @endcode
278 *
279 * You can increase the debugging level for an object by specifying it
280 * with @c :N, where @c N is the level, as in
281 *
282 * @code
283 *
284 * make bin/rtl8139.dsk DEBUG=pci,buffer:2,heap
285 *
286 * @endcode
287 *
288 * which would enable debugging for the PCI, buffer-handling and
289 * heap-allocation code, with the buffer-handling code at level 2.
290 *
291 */
292
293#ifndef DBGLVL_MAX
294#define NDEBUG
295#define DBGLVL_MAX 0
296#endif
297
298#ifndef DBGLVL_DFLT
299#define DBGLVL_DFLT DBGLVL_MAX
300#endif
301
302#ifndef ASSEMBLY
303
304/** printf() for debugging */
305extern void __attribute__ (( format ( printf, 1, 2 ) ))
306dbg_printf ( const char *fmt, ... );
307extern void dbg_autocolourise ( unsigned long id );
308extern void dbg_decolourise ( void );
309extern void dbg_hex_dump_da ( unsigned long dispaddr,
310 const void *data, unsigned long len );
311extern void dbg_md5_da ( unsigned long dispaddr,
312 const void *data, unsigned long len );
313extern void dbg_pause ( void );
314extern void dbg_more ( void );
315
316/* Allow for selective disabling of enabled debug levels */
317#define __debug_disable( object ) _C2 ( __debug_disable_, object )
319#define DBG_DISABLE_OBJECT( object, level ) do { \
320 extern char __debug_disable(object); \
321 __debug_disable(object) |= (level); \
322 } while ( 0 )
323#define DBG_ENABLE_OBJECT( object, level ) do { \
324 extern char __debug_disable(object); \
325 __debug_disable(object) &= ~(level); \
326 } while ( 0 )
327#if DBGLVL_MAX
328#define DBGLVL ( DBGLVL_MAX & ~__debug_disable(OBJECT) )
329#define DBG_DISABLE( level ) do { \
330 __debug_disable(OBJECT) |= ( (level) & DBGLVL_MAX ); \
331 } while ( 0 )
332#define DBG_ENABLE( level ) do { \
333 __debug_disable(OBJECT) &= ~( (level) & DBGLVL_MAX ); \
334 } while ( 0 )
335#else
336#define DBGLVL 0
337#define DBG_DISABLE( level ) do { } while ( 0 )
338#define DBG_ENABLE( level ) do { } while ( 0 )
339#endif
340
341#define DBGLVL_LOG 1
342#define DBG_LOG ( DBGLVL & DBGLVL_LOG )
343#define DBGLVL_EXTRA 2
344#define DBG_EXTRA ( DBGLVL & DBGLVL_EXTRA )
345#define DBGLVL_PROFILE 4
346#define DBG_PROFILE ( DBGLVL & DBGLVL_PROFILE )
347#define DBGLVL_IO 8
348#define DBG_IO ( DBGLVL & DBGLVL_IO )
349
350/**
351 * Print debugging message if we are at a certain debug level
352 *
353 * @v level Debug level
354 * @v ... printf() argument list
355 */
356#define DBG_IF( level, ... ) do { \
357 if ( DBG_ ## level ) { \
358 dbg_printf ( __VA_ARGS__ ); \
359 } \
360 } while ( 0 )
361
362/**
363 * Print a hex dump if we are at a certain debug level
364 *
365 * @v level Debug level
366 * @v dispaddr Display address
367 * @v data Data to print
368 * @v len Length of data
369 */
370#define DBG_HDA_IF( level, dispaddr, data, len ) do { \
371 if ( DBG_ ## level ) { \
372 union { \
373 unsigned long ul; \
374 typeof ( dispaddr ) raw; \
375 } da; \
376 da.ul = 0; \
377 da.raw = dispaddr; \
378 dbg_hex_dump_da ( da.ul, data, len ); \
379 } \
380 } while ( 0 )
381
382/**
383 * Print a hex dump if we are at a certain debug level
384 *
385 * @v level Debug level
386 * @v data Data to print
387 * @v len Length of data
388 */
389#define DBG_HD_IF( level, data, len ) do { \
390 const void *_data = data; \
391 DBG_HDA_IF ( level, _data, _data, len ); \
392 } while ( 0 )
393
394/**
395 * Print an MD5 checksum if we are at a certain debug level
396 *
397 * @v level Debug level
398 * @v dispaddr Display address
399 * @v data Data to print
400 * @v len Length of data
401 */
402#define DBG_MD5A_IF( level, dispaddr, data, len ) do { \
403 if ( DBG_ ## level ) { \
404 union { \
405 unsigned long ul; \
406 typeof ( dispaddr ) raw; \
407 } da; \
408 da.ul = 0; \
409 da.raw = dispaddr; \
410 dbg_md5_da ( da.ul, data, len ); \
411 } \
412 } while ( 0 )
413
414/**
415 * Print an MD5 checksum if we are at a certain debug level
416 *
417 * @v level Debug level
418 * @v data Data to print
419 * @v len Length of data
420 */
421#define DBG_MD5_IF( level, data, len ) do { \
422 const void *_data = data; \
423 DBG_MD5A_IF ( level, _data, _data, len ); \
424 } while ( 0 )
425
426/**
427 * Prompt for key press if we are at a certain debug level
428 *
429 * @v level Debug level
430 */
431#define DBG_PAUSE_IF( level, ... ) do { \
432 if ( DBG_ ## level ) { \
433 dbg_pause(); \
434 } \
435 } while ( 0 )
436
437/**
438 * Prompt for more output data if we are at a certain debug level
439 *
440 * @v level Debug level
441 */
442#define DBG_MORE_IF( level, ... ) do { \
443 if ( DBG_ ## level ) { \
444 dbg_more(); \
445 } \
446 } while ( 0 )
447
448/**
449 * Select colour for debug messages if we are at a certain debug level
450 *
451 * @v level Debug level
452 * @v id Message stream ID
453 */
454#define DBG_AC_IF( level, id ) do { \
455 if ( DBG_ ## level ) { \
456 union { \
457 unsigned long ul; \
458 typeof ( id ) raw; \
459 } dbg_stream; \
460 dbg_stream.ul = 0; \
461 dbg_stream.raw = id; \
462 dbg_autocolourise ( dbg_stream.ul ); \
463 } \
464 } while ( 0 )
465
466/**
467 * Revert colour for debug messages if we are at a certain debug level
468 *
469 * @v level Debug level
470 */
471#define DBG_DC_IF( level ) do { \
472 if ( DBG_ ## level ) { \
473 dbg_decolourise(); \
474 } \
475 } while ( 0 )
476
477/* Autocolourising versions of the DBGxxx_IF() macros */
478
479#define DBGC_IF( level, id, ... ) do { \
480 DBG_AC_IF ( level, id ); \
481 DBG_IF ( level, __VA_ARGS__ ); \
482 DBG_DC_IF ( level ); \
483 } while ( 0 )
484
485#define DBGC_HDA_IF( level, id, ... ) do { \
486 DBG_AC_IF ( level, id ); \
487 DBG_HDA_IF ( level, __VA_ARGS__ ); \
488 DBG_DC_IF ( level ); \
489 } while ( 0 )
490
491#define DBGC_HD_IF( level, id, ... ) do { \
492 DBG_AC_IF ( level, id ); \
493 DBG_HD_IF ( level, __VA_ARGS__ ); \
494 DBG_DC_IF ( level ); \
495 } while ( 0 )
496
497#define DBGC_MD5A_IF( level, id, ... ) do { \
498 DBG_AC_IF ( level, id ); \
499 DBG_MD5A_IF ( level, __VA_ARGS__ ); \
500 DBG_DC_IF ( level ); \
501 } while ( 0 )
502
503#define DBGC_MD5_IF( level, id, ... ) do { \
504 DBG_AC_IF ( level, id ); \
505 DBG_MD5_IF ( level, __VA_ARGS__ ); \
506 DBG_DC_IF ( level ); \
507 } while ( 0 )
508
509#define DBGC_PAUSE_IF( level, id ) do { \
510 DBG_AC_IF ( level, id ); \
511 DBG_PAUSE_IF ( level ); \
512 DBG_DC_IF ( level ); \
513 } while ( 0 )
514
515#define DBGC_MORE_IF( level, id ) do { \
516 DBG_AC_IF ( level, id ); \
517 DBG_MORE_IF ( level ); \
518 DBG_DC_IF ( level ); \
519 } while ( 0 )
520
521/* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( LOG, ... )*/
522
523#define DBG( ... ) DBG_IF ( LOG, ##__VA_ARGS__ )
524#define DBG_HDA( ... ) DBG_HDA_IF ( LOG, ##__VA_ARGS__ )
525#define DBG_HD( ... ) DBG_HD_IF ( LOG, ##__VA_ARGS__ )
526#define DBG_MD5A( ... ) DBG_MD5A_IF ( LOG, ##__VA_ARGS__ )
527#define DBG_MD5( ... ) DBG_MD5_IF ( LOG, ##__VA_ARGS__ )
528#define DBG_PAUSE( ... ) DBG_PAUSE_IF ( LOG, ##__VA_ARGS__ )
529#define DBG_MORE( ... ) DBG_MORE_IF ( LOG, ##__VA_ARGS__ )
530#define DBGC( ... ) DBGC_IF ( LOG, ##__VA_ARGS__ )
531#define DBGC_HDA( ... ) DBGC_HDA_IF ( LOG, ##__VA_ARGS__ )
532#define DBGC_HD( ... ) DBGC_HD_IF ( LOG, ##__VA_ARGS__ )
533#define DBGC_MD5A( ... ) DBGC_MD5A_IF ( LOG, ##__VA_ARGS__ )
534#define DBGC_MD5( ... ) DBGC_MD5_IF ( LOG, ##__VA_ARGS__ )
535#define DBGC_PAUSE( ... ) DBGC_PAUSE_IF ( LOG, ##__VA_ARGS__ )
536#define DBGC_MORE( ... ) DBGC_MORE_IF ( LOG, ##__VA_ARGS__ )
537
538/* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( EXTRA, ... )*/
539
540#define DBG2( ... ) DBG_IF ( EXTRA, ##__VA_ARGS__ )
541#define DBG2_HDA( ... ) DBG_HDA_IF ( EXTRA, ##__VA_ARGS__ )
542#define DBG2_HD( ... ) DBG_HD_IF ( EXTRA, ##__VA_ARGS__ )
543#define DBG2_MD5A( ... ) DBG_MD5A_IF ( EXTRA, ##__VA_ARGS__ )
544#define DBG2_MD5( ... ) DBG_MD5_IF ( EXTRA, ##__VA_ARGS__ )
545#define DBG2_PAUSE( ... ) DBG_PAUSE_IF ( EXTRA, ##__VA_ARGS__ )
546#define DBG2_MORE( ... ) DBG_MORE_IF ( EXTRA, ##__VA_ARGS__ )
547#define DBGC2( ... ) DBGC_IF ( EXTRA, ##__VA_ARGS__ )
548#define DBGC2_HDA( ... ) DBGC_HDA_IF ( EXTRA, ##__VA_ARGS__ )
549#define DBGC2_HD( ... ) DBGC_HD_IF ( EXTRA, ##__VA_ARGS__ )
550#define DBGC2_MD5A( ... ) DBGC_MD5A_IF ( EXTRA, ##__VA_ARGS__ )
551#define DBGC2_MD5( ... ) DBGC_MD5_IF ( EXTRA, ##__VA_ARGS__ )
552#define DBGC2_PAUSE( ... ) DBGC_PAUSE_IF ( EXTRA, ##__VA_ARGS__ )
553#define DBGC2_MORE( ... ) DBGC_MORE_IF ( EXTRA, ##__VA_ARGS__ )
554
555/* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( PROFILE, ... )*/
556
557#define DBGP( ... ) DBG_IF ( PROFILE, ##__VA_ARGS__ )
558#define DBGP_HDA( ... ) DBG_HDA_IF ( PROFILE, ##__VA_ARGS__ )
559#define DBGP_HD( ... ) DBG_HD_IF ( PROFILE, ##__VA_ARGS__ )
560#define DBGP_MD5A( ... ) DBG_MD5A_IF ( PROFILE, ##__VA_ARGS__ )
561#define DBGP_MD5( ... ) DBG_MD5_IF ( PROFILE, ##__VA_ARGS__ )
562#define DBGP_PAUSE( ... ) DBG_PAUSE_IF ( PROFILE, ##__VA_ARGS__ )
563#define DBGP_MORE( ... ) DBG_MORE_IF ( PROFILE, ##__VA_ARGS__ )
564#define DBGCP( ... ) DBGC_IF ( PROFILE, ##__VA_ARGS__ )
565#define DBGCP_HDA( ... ) DBGC_HDA_IF ( PROFILE, ##__VA_ARGS__ )
566#define DBGCP_HD( ... ) DBGC_HD_IF ( PROFILE, ##__VA_ARGS__ )
567#define DBGCP_MD5A( ... ) DBGC_MD5A_IF ( PROFILE, ##__VA_ARGS__ )
568#define DBGCP_MD5( ... ) DBGC_MD5_IF ( PROFILE, ##__VA_ARGS__ )
569#define DBGCP_PAUSE( ... ) DBGC_PAUSE_IF ( PROFILE, ##__VA_ARGS__ )
570#define DBGCP_MORE( ... ) DBGC_MORE_IF ( PROFILE, ##__VA_ARGS__ )
571
572/* Versions of the DBGxxx_IF() macros that imply DBGxxx_IF( IO, ... )*/
573
574#define DBGIO( ... ) DBG_IF ( IO, ##__VA_ARGS__ )
575#define DBGIO_HDA( ... ) DBG_HDA_IF ( IO, ##__VA_ARGS__ )
576#define DBGIO_HD( ... ) DBG_HD_IF ( IO, ##__VA_ARGS__ )
577#define DBGIO_MD5A( ... ) DBG_MD5A_IF ( IO, ##__VA_ARGS__ )
578#define DBGIO_MD5( ... ) DBG_MD5_IF ( IO, ##__VA_ARGS__ )
579#define DBGIO_PAUSE( ... ) DBG_PAUSE_IF ( IO, ##__VA_ARGS__ )
580#define DBGIO_MORE( ... ) DBG_MORE_IF ( IO, ##__VA_ARGS__ )
581#define DBGCIO( ... ) DBGC_IF ( IO, ##__VA_ARGS__ )
582#define DBGCIO_HDA( ... ) DBGC_HDA_IF ( IO, ##__VA_ARGS__ )
583#define DBGCIO_HD( ... ) DBGC_HD_IF ( IO, ##__VA_ARGS__ )
584#define DBGCIO_MD5A( ... ) DBGC_MD5A_IF ( IO, ##__VA_ARGS__ )
585#define DBGCIO_MD5( ... ) DBGC_MD5_IF ( IO, ##__VA_ARGS__ )
586#define DBGCIO_PAUSE( ... ) DBGC_PAUSE_IF ( IO, ##__VA_ARGS__ )
587#define DBGCIO_MORE( ... ) DBGC_MORE_IF ( IO, ##__VA_ARGS__ )
588
589#endif /* ASSEMBLY */
590/** @} */
591
592/** @defgroup attrs Miscellaneous attributes
593 * @{
594 */
595#ifndef ASSEMBLY
596
597/** Declare a variable or data structure as unused. */
598#define __unused __attribute__ (( unused ))
599
600/**
601 * Declare a function as pure - i.e. without side effects
602 */
603#define __pure __attribute__ (( pure ))
604
605/**
606 * Declare a function as const - i.e. it does not access global memory
607 * (including dereferencing pointers passed to it) at all.
608 * Must also not call any non-const functions.
609 */
610#define __const __attribute__ (( const ))
611
612/**
613 * Declare a function's pointer parameters as non-null - i.e. force
614 * compiler to check pointers at compile time and enable possible
615 * optimizations based on that fact
616 */
617#define __nonnull __attribute__ (( nonnull ))
618
619/**
620 * Declare a pointer returned by a function as a unique memory address
621 * as returned by malloc-type functions.
622 */
623#define __malloc __attribute__ (( malloc ))
624
625/**
626 * Declare a function as used.
627 *
628 * Necessary only if the function is called only from assembler code.
629 */
630#define __used __attribute__ (( used ))
631
632/** Declare a data structure to be aligned with 16-byte alignment */
633#define __aligned __attribute__ (( aligned ( 16 ) ))
634
635/** Declare a function to be always inline */
636#define __always_inline __attribute__ (( always_inline ))
637
638/* Force all inline functions to not be instrumented
639 *
640 * This is required to cope with what seems to be a long-standing gcc
641 * bug, in which -finstrument-functions will cause instances of
642 * inlined functions to be reported as further calls to the
643 * *containing* function. This makes instrumentation very difficult
644 * to use.
645 *
646 * Work around this problem by adding the no_instrument_function
647 * attribute to all inlined functions.
648 */
649#define inline inline __attribute__ (( no_instrument_function ))
650
651#endif /* ASSEMBLY */
652/** @} */
653
654/**
655 * Optimisation barrier
656 */
657#ifndef ASSEMBLY
658#define barrier() __asm__ __volatile__ ( "" : : : "memory" )
659#endif /* ASSEMBLY */
660
661/**
662 * Array size
663 */
664#ifndef ASSEMBLY
665#define ARRAY_SIZE(array) ( sizeof (array) / sizeof ( (array)[0] ) )
666#endif /* ASSEMBLY */
667
668/** @defgroup abs Absolute symbols
669 * @{
670 */
671#ifndef ASSEMBLY
672
673/** Declare an absolute symbol (e.g. a value defined by a linker script)
674 *
675 * Use as e.g.:
676 *
677 * extern int ABS_SYMBOL ( _my_symbol );
678 *
679 */
680#define ABS_SYMBOL( name ) name[]
681
682/** Get value of an absolute symbol for use in a static initializer
683 *
684 * Use as e.g.:
685 *
686 * extern int ABS_SYMBOL ( _my_symbol );
687 * static int my_symbol = ABS_VALUE_INIT ( _my_symbol );
688 *
689 * Note that the declared type must be at least as large as a pointer
690 * type, since the compiler sees the absolute symbol as being an
691 * address.
692 */
693#define ABS_VALUE_INIT( name ) ( ( typeof ( name[0] ) ) name )
694
695/** Get value of an absolute symbol
696 *
697 * In a position-dependent executable, where all addresses are fixed
698 * at link time, we can use the standard technique as documented by
699 * GNU ld, e.g.:
700 *
701 * extern char _my_symbol[];
702 *
703 * printf ( "Absolute symbol value is %x\n", ( ( int ) _my_symbol ) );
704 *
705 * This technique may not work in a position-independent executable.
706 * When dynamic relocations are applied, the runtime addresses will no
707 * longer be equal to the link-time addresses. If the code to obtain
708 * the address of _my_symbol uses PC-relative addressing, then it
709 * will calculate the runtime "address" of the absolute symbol, which
710 * will no longer be equal the the link-time "address" (i.e. the
711 * correct value) of the absolute symbol.
712 *
713 * We can work around this by instead declaring a static variable to
714 * contain the absolute value, and returning the contents of this
715 * static variable:
716 *
717 * extern char _my_symbol[];
718 * static void * volatile my_symbol = _my_symbol;
719 *
720 * printf ( "Absolute symbol value is %x\n", ( ( int ) my_symbol ) );
721 *
722 * The value of the static variable cannot possibly use PC-relative
723 * addressing (since there is no applicable program counter for
724 * non-code), and so will instead be filled in with the correct
725 * absolute value at link time. (No dynamic relocation will be
726 * generated that might change its value, since the symbol providing
727 * the value is an absolute symbol.)
728 *
729 * This second technique will work for both position-dependent and
730 * position-independent code, but incurs the unnecssary overhead of an
731 * additional static variable in position-dependent code. The
732 * ABS_VALUE() macro abstracts away these differences, using the most
733 * efficient available technique. Use as e.g.:
734 *
735 * extern int ABS_SYMBOL ( _my_symbol );
736 * #define my_symbol ABS_VALUE ( _my_symbol )
737 *
738 * printf ( "Absolute symbol value is %x\n", my_symbol );
739 *
740 * The ABS_VALUE() macro uses the (otherwise redundant) type declared
741 * on the ABS_SYMBOL() array to automatically determine the correct
742 * type for the ABS_VALUE() expression.
743 *
744 * Unlike ABS_VALUE_INIT(), there is no restriction that the type must
745 * be at least as large as a pointer type.
746 */
747#ifndef __pie__
748#define ABS_VALUE( name ) ( ( typeof ( name[0] ) ) ( intptr_t ) name )
749#else
750#define ABS_VALUE( name ) ( { \
751 static void * volatile static_ ## name = name; \
752 ( ( typeof ( name[0] ) ) ( intptr_t ) static_ ## name ); \
753 } )
754#endif
755
756#endif /* ASSEMBLY */
757/** @} */
758
759/**
760 * @defgroup licences Licence declarations
761 *
762 * For reasons that are partly historical, various different files
763 * within the iPXE codebase have differing licences.
764 *
765 * @{
766 */
767
768/** Declare a file as being in the public domain
769 *
770 * This licence declaration is applicable when a file states itself to
771 * be in the public domain.
772 */
773#define FILE_LICENCE_PUBLIC_DOMAIN \
774 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__public_domain__ ) )
775
776/** Declare a file as being under version 2 (or later) of the GNU GPL
777 *
778 * This licence declaration is applicable when a file states itself to
779 * be licensed under the GNU GPL; "either version 2 of the License, or
780 * (at your option) any later version".
781 */
782#define FILE_LICENCE_GPL2_OR_LATER \
783 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_or_later__ ) )
784
785/** Declare a file as being under version 2 of the GNU GPL
786 *
787 * This licence declaration is applicable when a file states itself to
788 * be licensed under version 2 of the GPL, and does not include the
789 * "or, at your option, any later version" clause.
790 */
791#define FILE_LICENCE_GPL2_ONLY \
792 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_only__ ) )
793
794/** Declare a file as being under any version of the GNU GPL
795 *
796 * This licence declaration is applicable when a file states itself to
797 * be licensed under the GPL, but does not specify a version.
798 *
799 * According to section 9 of the GPLv2, "If the Program does not
800 * specify a version number of this License, you may choose any
801 * version ever published by the Free Software Foundation".
802 */
803#define FILE_LICENCE_GPL_ANY \
804 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl_any__ ) )
805
806/** Declare a file as being under the three-clause BSD licence
807 *
808 * This licence declaration is applicable when a file states itself to
809 * be licensed under terms allowing redistribution in source and
810 * binary forms (with or without modification) provided that:
811 *
812 * redistributions of source code retain the copyright notice,
813 * list of conditions and any attached disclaimers
814 *
815 * redistributions in binary form reproduce the copyright notice,
816 * list of conditions and any attached disclaimers in the
817 * documentation and/or other materials provided with the
818 * distribution
819 *
820 * the name of the author is not used to endorse or promote
821 * products derived from the software without specific prior
822 * written permission
823 *
824 * It is not necessary for the file to explicitly state that it is
825 * under a "BSD" licence; only that the licensing terms be
826 * functionally equivalent to the standard three-clause BSD licence.
827 */
828#define FILE_LICENCE_BSD3 \
829 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd3__ ) )
830
831/** Declare a file as being under the two-clause BSD licence
832 *
833 * This licence declaration is applicable when a file states itself to
834 * be licensed under terms allowing redistribution in source and
835 * binary forms (with or without modification) provided that:
836 *
837 * redistributions of source code retain the copyright notice,
838 * list of conditions and any attached disclaimers
839 *
840 * redistributions in binary form reproduce the copyright notice,
841 * list of conditions and any attached disclaimers in the
842 * documentation and/or other materials provided with the
843 * distribution
844 *
845 * It is not necessary for the file to explicitly state that it is
846 * under a "BSD" licence; only that the licensing terms be
847 * functionally equivalent to the standard two-clause BSD licence.
848 */
849#define FILE_LICENCE_BSD2 \
850 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd2__ ) )
851
852/** Declare a file as being under the two-clause BSD plus patent licence
853 *
854 * This licence declaration is applicable when a file states itself to
855 * be licensed under terms allowing redistribution in source and
856 * binary forms (with or without modification) provided that:
857 *
858 * redistributions of source code retain the copyright notice,
859 * list of conditions and any attached disclaimers
860 *
861 * redistributions in binary form reproduce the copyright notice,
862 * list of conditions and any attached disclaimers in the
863 * documentation and/or other materials provided with the
864 * distribution
865 *
866 * and in addition states that
867 *
868 * Subject to the terms and conditions of this license, each
869 * copyright holder and contributor hereby grants to those
870 * receiving rights under this license a perpetual, worldwide,
871 * non-exclusive, no-charge, royalty-free, irrevocable (except for
872 * failure to satisfy the conditions of this license) patent
873 * license to make, have made, use, offer to sell, sell, import,
874 * and otherwise transfer this software, where such license
875 * applies only to those patent claims, already acquired or
876 * hereafter acquired, licensable by such copyright holder or
877 * contributor that are necessarily infringed by:
878 *
879 * their Contribution(s) (the licensed copyrights of copyright
880 * holders and non-copyrightable additions of contributors, in
881 * source or binary form) alone; or
882 *
883 * combination of their Contribution(s) with the work of
884 * authorship to which such Contribution(s) was added by such
885 * copyright holder or contributor, if, at the time the
886 * Contribution is added, such addition causes such combination
887 * to be necessarily infringed. The patent license shall not
888 * apply to any other combinations which include the
889 * Contribution.
890 *
891 * It is not necessary for the file to explicitly state that it is
892 * under a "BSD" licence; only that the licensing terms be
893 * functionally equivalent to the standard two-clause BSD licence with
894 * patent grant.
895 */
896#define FILE_LICENCE_BSD2_PATENT \
897 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd2_patent__ ) )
898
899/** Declare a file as being under the one-clause MIT-style licence
900 *
901 * This licence declaration is applicable when a file states itself to
902 * be licensed under terms allowing redistribution for any purpose
903 * with or without fee, provided that the copyright notice and
904 * permission notice appear in all copies.
905 */
906#define FILE_LICENCE_MIT \
907 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__mit__ ) )
908
909/** Declare a file as being under GPLv2+ or UBDL
910 *
911 * This licence declaration is applicable when a file states itself to
912 * be licensed under the GNU GPL; "either version 2 of the License, or
913 * (at your option) any later version" and also states that it may be
914 * distributed under the terms of the Unmodified Binary Distribution
915 * Licence (as given in the file COPYING.UBDL).
916 */
917#define FILE_LICENCE_GPL2_OR_LATER_OR_UBDL \
918 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_or_later_or_ubdl__ ) )
919
920/** Declare a particular licence as applying to a file */
921#define FILE_LICENCE( _licence ) FILE_LICENCE_ ## _licence
922
923/** @} */
924
925/* This file itself is under GPLv2+/UBDL */
926FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
927
928/**
929 * @defgroup secboot UEFI Secure Boot restrictions
930 *
931 * Not all files within the iPXE codebase are allowed to be included
932 * in UEFI Secure Boot signed builds.
933 *
934 * Files that are permitted in a UEFI Secure Boot build are subject to
935 * stricter code review requirements. In particular, contributions
936 * from third parties may not be marked as permitted unless they have
937 * passed an approved security review.
938 *
939 * @{
940 */
941
942/** Declare a file as being permitted in a UEFI Secure Boot build */
943#define FILE_SECBOOT_PERMITTED \
944 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __secboot__permitted__ ) )
945
946/** Declare a file as being forbidden in a UEFI Secure Boot build */
947#define FILE_SECBOOT_FORBIDDEN \
948 PROVIDE_SYMBOL ( PREFIX_OBJECT ( __secboot__forbidden__ ) )
949
950/** Declare a file's UEFI Secure Boot permission status */
951#define FILE_SECBOOT( _status ) FILE_SECBOOT_ ## _status
952
953/** @} */
954
955/* This file itself is permitted in a Secure Boot build */
956FILE_SECBOOT ( PERMITTED );
957
958#include <bits/compiler.h>
959
960#endif /* COMPILER_H */
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
void dbg_pause(void)
Pause until a key is pressed.
Definition debug.c:59
#define __debug_disable(object)
Definition compiler.h:317
void dbg_hex_dump_da(unsigned long dispaddr, const void *data, unsigned long len)
Print hex dump with specified display address.
Definition debug.c:117
void dbg_more(void)
Indicate more data to follow and pause until a key is pressed.
Definition debug.c:69
void dbg_decolourise(void)
Revert to normal colour.
Definition debug.c:210
#define DBGLVL_DFLT
Definition compiler.h:299
void dbg_autocolourise(unsigned long stream)
Select automatic colour for debug messages.
Definition debug.c:197
void dbg_md5_da(unsigned long dispaddr, const void *data, unsigned long len)
Print an MD5 checksum with specified display address.
Definition debug_md5.c:38
#define DBGLVL_MAX
Definition compiler.h:295
void dbg_printf(const char *fmt,...)
Print debug message.
Definition debug.c:39
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define OBJECT_SYMBOL
Definition compiler.h:200
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#define PROVIDE_SYMBOL(symbol)
Provide a symbol within this object file.
Definition compiler.h:84
#define __attribute__(x)
Definition compiler.h:10
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465
int ssize_t const char * fmt
Definition vsprintf.h:73
int const char * format
Definition xfer.h:105