5 * Doxygen can't cope with some of the more esoteric areas of C, so we
6 * make its life simpler.
10 #define __attribute__(x)
15 * Global compiler definitions.
17 * This file is implicitly included by every @c .c file in Etherboot.
18 * It defines global macros such as DBG().
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>.
27 /* Not quite sure why cpp requires two levels of macro call in order
28 * to actually expand OBJECT...
31 #define _H1( x, y ) x ## y
33 #define _H2( x, y ) _H1 ( x, y )
34 #define PREFIX_OBJECT(prefix) _H2 ( prefix, OBJECT )
35 #define OBJECT_SYMBOL PREFIX_OBJECT(obj_)
39 #define _XSTR(s) _STR(s)
40 #define OBJECT_SYMBOL_STR _XSTR ( OBJECT_SYMBOL )
49 __asm__ ( ".globl\t" OBJECT_SYMBOL_STR );
50 __asm__ ( ".equ\t" OBJECT_SYMBOL_STR ", 0" );
53 * Drag in an object by object name.
55 * Macro to allow objects to explicitly drag in other objects by
56 * object name. Used by config.c.
59 #define REQUIRE_OBJECT(object) \
60 __asm__ ( ".equ\tneed_" #object ", obj_" #object );
64 * Print a debugging message.
66 * The debug level is set at build time by specifying the @c DEBUG=
67 * parameter on the @c make command line. For example, to enable
68 * debugging for the PCI bus functions (in pci.c) in a @c .dsk image
69 * for the @c rtl8139 card, you could use the command line
73 * make bin/rtl8139.dsk DEBUG=pci
77 * This will enable the debugging statements (DBG()) in pci.c. If
78 * debugging is not enabled, DBG() statements will be ignored.
80 * You can enable debugging in several objects simultaneously by
81 * separating them with commas, as in
85 * make bin/rtl8139.dsk DEBUG=pci,buffer,heap
89 * You can increase the debugging level for an object by specifying it
90 * with @c :N, where @c N is the level, as in
94 * make bin/rtl8139.dsk DEBUG=pci,buffer:2,heap
98 * which would enable debugging for the PCI, buffer-handling and
99 * heap-allocation code, with the buffer-handling code at level 2.
105 * Print a level 2 debugging message.
107 * As for DBG(). DBG2() takes effect only when the debugging level is
113 * If debug_OBJECT is set to a true value, the macro DBG(...) will
114 * expand to printf(...) when compiling OBJECT, and the symbol
115 * DEBUG_LEVEL will be inserted into the object file.
118 #define DEBUG_SYMBOL PREFIX_OBJECT(debug_)
122 #define DEBUG_SYMBOL_STR _XSTR ( DEBUG_SYMBOL )
123 __asm__ ( ".equ\tDEBUG_LEVEL, " DEBUG_SYMBOL_STR );
128 * This function is used only for printf()-style format string
129 * checking. The function body does not exist, and no reference to it
130 * should ever appear in any compiled object.
132 extern int __attribute__ (( format ( printf, 1, 2 ) ))
133 __do_not_printf ( const char *fmt, ... );
135 #define DBG_PRINT(...) printf ( __VA_ARGS__ )
136 #define DBG_DISCARD(...) do { \
137 if ( 0 ) __do_not_printf ( __VA_ARGS__ ); \
140 #define DBG DBG_DISCARD
141 #define DBG2 DBG_DISCARD
143 #if DEBUG_SYMBOL >= 1
145 #define DBG DBG_PRINT
148 #if DEBUG_SYMBOL >= 2
150 #define DBG2 DBG_PRINT
153 #if DEBUG_SYMBOL == 0
157 /** Declare a data structure as packed. */
158 #define PACKED __attribute__ (( packed ))
161 * Declare a variable or data structure as unused.
163 * Note that using #__unused on a static global variable (such as a
164 * table structure as mentioned in tables.h) is necessary in order to
165 * inhibit compiler warnings.
168 #define __unused __attribute__ (( unused ))
171 * Declare a function as used.
173 * Necessary only if the function is called only from assembler code.
174 * You cannot use this attribute for static global variables; use
178 #define __used __attribute__ (( used ))
180 /** Declare a data structure to be aligned with 16-byte alignment */
181 #define __aligned __attribute__ (( aligned ( 16 ) ))
186 * To save space in the binary when multiple-driver images are
187 * compiled, uninitialised data areas can be shared between drivers.
188 * This will typically be used to share statically-allocated receive
189 * and transmit buffers between drivers.
196 * char rx_buf[NUM_RX_BUF][RX_BUF_SIZE];
197 * char tx_buf[TX_BUF_SIZE];
198 * } my_static_data __shared;
203 #define __shared __asm__ ( "_shared_bss" )
205 #endif /* ASSEMBLY */
207 #endif /* COMPILER_H */