compiler.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef COMPILER_H
  2. #define COMPILER_H
  3. /* We export the symbol obj_OBJECT (OBJECT is defined on command-line)
  4. * as a global symbol, so that the linker can drag in selected object
  5. * files from the library using -u obj_OBJECT.
  6. *
  7. * Not quite sure why cpp requires two levels of macro call in order
  8. * to actually expand OBJECT...
  9. */
  10. #undef _H1
  11. #define _H1( x, y ) x ## y
  12. #undef _H2
  13. #define _H2( x, y ) _H1 ( x, y )
  14. #define PREFIX_OBJECT(prefix) _H2 ( prefix, OBJECT )
  15. #define OBJECT_SYMBOL PREFIX_OBJECT(obj_)
  16. #undef _STR
  17. #define _STR(s) #s
  18. #undef _XSTR
  19. #define _XSTR(s) _STR(s)
  20. #define OBJECT_SYMBOL_STR _XSTR ( OBJECT_SYMBOL )
  21. #ifdef ASSEMBLY
  22. .globl OBJECT_SYMBOL
  23. .equ OBJECT_SYMBOL, 0
  24. #else /* ASSEMBLY */
  25. __asm__ ( ".globl\t" OBJECT_SYMBOL_STR );
  26. __asm__ ( ".equ\t" OBJECT_SYMBOL_STR ", 0" );
  27. /*
  28. * Macro to allow objects to explicitly drag in other objects by
  29. * object name. Used by config.c.
  30. *
  31. */
  32. #define REQUIRE_OBJECT(object) \
  33. __asm__ ( ".equ\tneed_" #object ", obj_" #object );
  34. /*
  35. * If debug_OBJECT is set to a true value, the macro DBG(...) will
  36. * expand to printf(...) when compiling OBJECT, and the symbol
  37. * DEBUG_LEVEL will be inserted into the object file.
  38. *
  39. */
  40. #define DEBUG_SYMBOL PREFIX_OBJECT(debug_)
  41. #if DEBUG_SYMBOL
  42. #include "console.h"
  43. #define DEBUG_SYMBOL_STR _XSTR ( DEBUG_SYMBOL )
  44. __asm__ ( ".equ\tDEBUG_LEVEL, " DEBUG_SYMBOL_STR );
  45. #endif
  46. #define DBG_PRINT(...) printf ( __VA_ARGS__ )
  47. #define DBG_DISCARD(...)
  48. #define DBG DBG_DISCARD
  49. #define DBG2 DBG_DISCARD
  50. #if DEBUG_SYMBOL >= 1
  51. #undef DBG
  52. #define DBG DBG_PRINT
  53. #endif
  54. #if DEBUG_SYMBOL >= 2
  55. #undef DBG2
  56. #define DBG2 DBG_PRINT
  57. #endif
  58. /*
  59. * ASSERT() macros
  60. *
  61. */
  62. #define ASSERT(x)
  63. #if DEBUG_SYMBOL >= 1
  64. #undef ASSERT
  65. #define ASSERT(x) \
  66. do { \
  67. if ( ! (x) ) { \
  68. DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \
  69. __FILE__, __LINE__, __FUNCTION__ ); \
  70. } \
  71. } while (0)
  72. #endif
  73. /*
  74. * Commonly-used attributes.
  75. *
  76. * Note that __used can be used only for functions. If you have a
  77. * static variable declaration that you want to force to be included,
  78. * use __unused.
  79. *
  80. */
  81. #define PACKED __attribute__ (( packed ))
  82. #define __unused __attribute__ (( unused ))
  83. #define __used __attribute__ (( used ))
  84. #define __aligned __attribute__ (( aligned ( 16 ) ))
  85. /*
  86. * To save space in the binary when multiple-driver images are
  87. * compiled, uninitialised data areas can be shared between drivers.
  88. * This will typically be used to share statically-allocated receive
  89. * and transmit buffers between drivers.
  90. *
  91. * Use as e.g.
  92. *
  93. * struct {
  94. * char rx_buf[NUM_RX_BUF][RX_BUF_SIZE];
  95. * char tx_buf[TX_BUF_SIZE];
  96. * } my_static_data __shared;
  97. *
  98. */
  99. #define __shared __asm__ ( "_shared_bss" )
  100. #endif /* ASSEMBLY */
  101. #endif /* COMPILER_H */