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() and ASSERT().
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 );
126 #define DBG_PRINT(...) printf ( __VA_ARGS__ )
127 #define DBG_DISCARD(...)
128 #define DBG DBG_DISCARD
129 #define DBG2 DBG_DISCARD
131 #if DEBUG_SYMBOL >= 1
133 #define DBG DBG_PRINT
136 #if DEBUG_SYMBOL >= 2
138 #define DBG2 DBG_PRINT
142 * Assert a condition.
144 * If the condition is not true, a debug message will be printed.
145 * Assertions only take effect if the debug level is non-zero (see
151 #if DEBUG_SYMBOL >= 1
156 DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \
157 __FILE__, __LINE__, __FUNCTION__ ); \
162 /** Declare a data structure as packed. */
163 #define PACKED __attribute__ (( packed ))
166 * Declare a variable or data structure as unused.
168 * Note that using #__unused on a static global variable (such as a
169 * table structure as mentioned in tables.h) is necessary in order to
170 * inhibit compiler warnings.
173 #define __unused __attribute__ (( unused ))
176 * Declare a function as used.
178 * Necessary only if the function is called only from assembler code.
179 * You cannot use this attribute for static global variables; use
183 #define __used __attribute__ (( used ))
185 /** Declare a data structure to be aligned with 16-byte alignment */
186 #define __aligned __attribute__ (( aligned ( 16 ) ))
191 * To save space in the binary when multiple-driver images are
192 * compiled, uninitialised data areas can be shared between drivers.
193 * This will typically be used to share statically-allocated receive
194 * and transmit buffers between drivers.
201 * char rx_buf[NUM_RX_BUF][RX_BUF_SIZE];
202 * char tx_buf[TX_BUF_SIZE];
203 * } my_static_data __shared;
208 #define __shared __asm__ ( "_shared_bss" )
210 #endif /* ASSEMBLY */
212 #endif /* COMPILER_H */