2005-04-08 15:01:17 +00:00
|
|
|
#ifndef COMPILER_H
|
|
|
|
#define COMPILER_H
|
|
|
|
|
2005-05-18 14:42:02 +00:00
|
|
|
/*
|
|
|
|
* Doxygen can't cope with some of the more esoteric areas of C, so we
|
|
|
|
* make its life simpler.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifdef DOXYGEN
|
2005-05-18 15:02:23 +00:00
|
|
|
#define __attribute__(x)
|
2005-05-18 14:42:02 +00:00
|
|
|
#endif
|
|
|
|
|
2005-05-19 19:00:21 +00:00
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* Global compiler definitions.
|
|
|
|
*
|
|
|
|
* This file is implicitly included by every @c .c file in Etherboot.
|
2006-03-23 19:33:57 +00:00
|
|
|
* It defines global macros such as DBG().
|
2005-04-08 15:01:17 +00:00
|
|
|
*
|
2005-05-19 19:00:21 +00:00
|
|
|
* We arrange for each object to export the symbol @c obj_OBJECT
|
|
|
|
* (where @c OBJECT is the object name, e.g. @c rtl8139) as a global
|
|
|
|
* symbol, so that the linker can drag in selected object files from
|
|
|
|
* the library using <tt> -u obj_OBJECT </tt>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Not quite sure why cpp requires two levels of macro call in order
|
2005-04-08 15:01:17 +00:00
|
|
|
* to actually expand OBJECT...
|
|
|
|
*/
|
|
|
|
#undef _H1
|
|
|
|
#define _H1( x, y ) x ## y
|
|
|
|
#undef _H2
|
|
|
|
#define _H2( x, y ) _H1 ( x, y )
|
2005-04-27 11:59:37 +00:00
|
|
|
#define PREFIX_OBJECT(prefix) _H2 ( prefix, OBJECT )
|
|
|
|
#define OBJECT_SYMBOL PREFIX_OBJECT(obj_)
|
2005-04-08 15:01:17 +00:00
|
|
|
#undef _STR
|
|
|
|
#define _STR(s) #s
|
|
|
|
#undef _XSTR
|
|
|
|
#define _XSTR(s) _STR(s)
|
|
|
|
#define OBJECT_SYMBOL_STR _XSTR ( OBJECT_SYMBOL )
|
|
|
|
|
|
|
|
#ifdef ASSEMBLY
|
|
|
|
|
|
|
|
.globl OBJECT_SYMBOL
|
|
|
|
.equ OBJECT_SYMBOL, 0
|
|
|
|
|
|
|
|
#else /* ASSEMBLY */
|
|
|
|
|
|
|
|
__asm__ ( ".globl\t" OBJECT_SYMBOL_STR );
|
|
|
|
__asm__ ( ".equ\t" OBJECT_SYMBOL_STR ", 0" );
|
|
|
|
|
2005-05-19 19:00:21 +00:00
|
|
|
/**
|
|
|
|
* Drag in an object by object name.
|
|
|
|
*
|
2005-04-14 11:35:45 +00:00
|
|
|
* Macro to allow objects to explicitly drag in other objects by
|
|
|
|
* object name. Used by config.c.
|
|
|
|
*
|
|
|
|
*/
|
2005-04-08 15:01:17 +00:00
|
|
|
#define REQUIRE_OBJECT(object) \
|
|
|
|
__asm__ ( ".equ\tneed_" #object ", obj_" #object );
|
|
|
|
|
2005-05-19 19:00:21 +00:00
|
|
|
/** @def DBG
|
|
|
|
*
|
|
|
|
* Print a debugging message.
|
|
|
|
*
|
|
|
|
* The debug level is set at build time by specifying the @c DEBUG=
|
|
|
|
* parameter on the @c make command line. For example, to enable
|
|
|
|
* debugging for the PCI bus functions (in pci.c) in a @c .dsk image
|
|
|
|
* for the @c rtl8139 card, you could use the command line
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
*
|
|
|
|
* make bin/rtl8139.dsk DEBUG=pci
|
|
|
|
*
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* This will enable the debugging statements (DBG()) in pci.c. If
|
|
|
|
* debugging is not enabled, DBG() statements will be ignored.
|
|
|
|
*
|
|
|
|
* You can enable debugging in several objects simultaneously by
|
|
|
|
* separating them with commas, as in
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
*
|
|
|
|
* make bin/rtl8139.dsk DEBUG=pci,buffer,heap
|
|
|
|
*
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* You can increase the debugging level for an object by specifying it
|
|
|
|
* with @c :N, where @c N is the level, as in
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
*
|
|
|
|
* make bin/rtl8139.dsk DEBUG=pci,buffer:2,heap
|
|
|
|
*
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* which would enable debugging for the PCI, buffer-handling and
|
|
|
|
* heap-allocation code, with the buffer-handling code at level 2.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @def DBG2
|
|
|
|
*
|
|
|
|
* Print a level 2 debugging message.
|
|
|
|
*
|
|
|
|
* As for DBG(). DBG2() takes effect only when the debugging level is
|
|
|
|
* 2 or greater.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-04-14 11:35:45 +00:00
|
|
|
/*
|
|
|
|
* If debug_OBJECT is set to a true value, the macro DBG(...) will
|
|
|
|
* expand to printf(...) when compiling OBJECT, and the symbol
|
2005-04-25 16:28:07 +00:00
|
|
|
* DEBUG_LEVEL will be inserted into the object file.
|
2005-04-14 11:35:45 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-04-27 11:59:37 +00:00
|
|
|
#define DEBUG_SYMBOL PREFIX_OBJECT(debug_)
|
2005-04-25 16:28:07 +00:00
|
|
|
|
2005-04-14 11:35:45 +00:00
|
|
|
#if DEBUG_SYMBOL
|
2005-04-17 10:25:06 +00:00
|
|
|
#include "console.h"
|
2005-04-14 11:35:45 +00:00
|
|
|
#define DEBUG_SYMBOL_STR _XSTR ( DEBUG_SYMBOL )
|
2005-04-25 16:28:07 +00:00
|
|
|
__asm__ ( ".equ\tDEBUG_LEVEL, " DEBUG_SYMBOL_STR );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DBG_PRINT(...) printf ( __VA_ARGS__ )
|
2006-09-14 17:38:17 +00:00
|
|
|
#define DBG_DISCARD(...) do { if ( 0 ) printf ( __VA_ARGS__ ); } while ( 0 )
|
|
|
|
/*#define DBG_DISCARD(...) do {} while ( 0 )*/
|
|
|
|
|
2005-04-25 16:28:07 +00:00
|
|
|
#define DBG DBG_DISCARD
|
|
|
|
#define DBG2 DBG_DISCARD
|
|
|
|
|
|
|
|
#if DEBUG_SYMBOL >= 1
|
|
|
|
#undef DBG
|
|
|
|
#define DBG DBG_PRINT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEBUG_SYMBOL >= 2
|
|
|
|
#undef DBG2
|
|
|
|
#define DBG2 DBG_PRINT
|
2005-04-14 11:35:45 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-23 19:33:57 +00:00
|
|
|
#if DEBUG_SYMBOL == 0
|
|
|
|
#define NDEBUG
|
2005-05-13 10:18:21 +00:00
|
|
|
#endif
|
|
|
|
|
2005-05-19 19:00:21 +00:00
|
|
|
/** Declare a data structure as packed. */
|
|
|
|
#define PACKED __attribute__ (( packed ))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declare a variable or data structure as unused.
|
2005-05-17 12:16:28 +00:00
|
|
|
*
|
2005-05-20 10:27:02 +00:00
|
|
|
* Note that using #__unused on a static global variable (such as a
|
2005-05-19 19:00:21 +00:00
|
|
|
* table structure as mentioned in tables.h) is necessary in order to
|
|
|
|
* inhibit compiler warnings.
|
2005-05-17 12:16:28 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define __unused __attribute__ (( unused ))
|
2005-05-19 19:00:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Declare a function as used.
|
|
|
|
*
|
|
|
|
* Necessary only if the function is called only from assembler code.
|
2005-05-20 10:27:02 +00:00
|
|
|
* You cannot use this attribute for static global variables; use
|
|
|
|
* #__unused instead.
|
2005-05-19 19:00:21 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-05-17 12:16:28 +00:00
|
|
|
#define __used __attribute__ (( used ))
|
2005-05-19 19:00:21 +00:00
|
|
|
|
|
|
|
/** Declare a data structure to be aligned with 16-byte alignment */
|
2005-05-17 12:16:28 +00:00
|
|
|
#define __aligned __attribute__ (( aligned ( 16 ) ))
|
2005-04-08 15:01:17 +00:00
|
|
|
|
2005-05-19 19:00:21 +00:00
|
|
|
/**
|
|
|
|
* Shared data.
|
|
|
|
*
|
2005-05-02 16:21:52 +00:00
|
|
|
* To save space in the binary when multiple-driver images are
|
|
|
|
* compiled, uninitialised data areas can be shared between drivers.
|
|
|
|
* This will typically be used to share statically-allocated receive
|
|
|
|
* and transmit buffers between drivers.
|
|
|
|
*
|
|
|
|
* Use as e.g.
|
|
|
|
*
|
2005-05-19 19:00:21 +00:00
|
|
|
* @code
|
|
|
|
*
|
|
|
|
* struct {
|
2005-05-02 16:21:52 +00:00
|
|
|
* char rx_buf[NUM_RX_BUF][RX_BUF_SIZE];
|
|
|
|
* char tx_buf[TX_BUF_SIZE];
|
2005-05-19 19:00:21 +00:00
|
|
|
* } my_static_data __shared;
|
|
|
|
*
|
|
|
|
* @endcode
|
2005-05-02 16:21:52 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-05-03 09:02:24 +00:00
|
|
|
#define __shared __asm__ ( "_shared_bss" )
|
2005-05-02 16:21:52 +00:00
|
|
|
|
2005-04-08 15:01:17 +00:00
|
|
|
#endif /* ASSEMBLY */
|
|
|
|
|
|
|
|
#endif /* COMPILER_H */
|