Overview   API Reference  

core/system/l4/macros.hpp

00001 #if !defined(__SYSTEM_L4_MACROS_HPP__)
00002 #define __SYSTEM_L4_MACROS_HPP__
00003 
00004 //
00005 // L4 includes
00006 //
00007 #include <l4/util/macros.h>
00008 
00009 //
00010 // local includes
00011 //
00012 #include "core/util/static_assert.hpp"
00013 
00014 //
00015 // formats strings
00016 //
00017 #undef  l4util_idfmt
00018 #define l4util_idfmt        "%x.%02x"
00019 
00020 #if __WORDSIZE == 32
00021     #undef  l4_umword_fmt
00022     #define l4_umword_fmt   "0x%08lx"
00023 
00024     #undef  l4_addr_fmt
00025     #define l4_addr_fmt     "0x%08lx"
00026 
00027     #define l4_size_fmt     "0x%08zx"
00028 #elif __WORDSIZE == 64
00029     #undef  l4_umword_fmt
00030     #define l4_umword_fmt   "0x%016lx"
00031 
00032     #undef  l4_addr_fmt
00033     #define l4_addr_fmt     "0x%016lx"
00034 
00035     #define l4_size_fmt     "0x%016zx"
00036 #endif
00037 
00038 //
00039 // logging & debugging
00040 //
00041 #undef  LOG
00042 #define LOG(args...)                    log::debug(args)
00043 #undef  LOGd
00044 #define LOGd(debug_condition, args...)  logd(debug_condition, args)
00045 
00046 #if !defined(__GNUC__)
00047     #define __PRETTY_FUNCTION__         __func__
00048 #endif
00049 
00050 #define logd(debug_condition, args...)                                          \
00051     {                                                                           \
00052         static_assert_const(debug_condition);                                   \
00053         if (debug_condition) log::print(args);                                  \
00054     }
00055 
00056 #define assert(condition)                                                       \
00057     {                                                                           \
00058         if (!(condition)) {                                                     \
00059             log::error("assertion %s failed\n"                                  \
00060                        "  in %s\n"                                              \
00061                        "  in %s at line %d\n",                                  \
00062                        #condition, __PRETTY_FUNCTION__, __FILE__, __LINE__);    \
00063             enter_kdebug(" assertion failed ");                                 \
00064         }                                                                       \
00065     }
00066 
00067 #define assert_log(condition, message...)                                       \
00068     {                                                                           \
00069         if (!(condition)) {                                                     \
00070             log::error(message);                                                \
00071             log::error("assertion %s failed\n"                                  \
00072                        "  in %s\n"                                              \
00073                        "  in %s at line %d\n",                                  \
00074                        #condition, __PRETTY_FUNCTION__, __FILE__, __LINE__);    \
00075             enter_kdebug(" assertion failed ");                                 \
00076         }                                                                       \
00077     }
00078 
00079 #define assertd(debug_condition, condition)                                     \
00080     {                                                                           \
00081         static_assert_const(debug_condition);                                   \
00082         if (debug_condition) assert(condition)                                  \
00083     }                                                                           \
00084 
00085 #define assert_logd(debug_condition, condition, message...)                     \
00086     {                                                                           \
00087         static_assert_const(debug_condition);                                   \
00088         if (debug_condition) assert_log(condition, message)                     \
00089     }                                                                           \
00090 
00091 #endif
00092 
00093 // ***** end of source ***** //
00094 

L4vmm Reference Manual, written by Mario Schwalbe  © 2006-2008