/*****************************************************************************
 *
 * Debugging macros for the Generic Engine.
 * Copyright (C) 2001  Bart Trojanowski <bart@jukie.net>.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 *****************************************************************************/
#ifndef ENGINE_DEBUG_H
#define ENGINE_DEBUG_H

#ifdef __KERNEL__

#include "engine.h"

extern int ge_debug_message_mask;

#define GE_DBG_ALL      0xFFFFFFFF
#define GE_DBG_FNTRACE  0x00000001 /* function trace, see below */
#define GE_DBG_OBJREF   0x00000002 /* object references */

#define GE_ERR(fmt,arg...) \
  do { printk(KERN_ERR " GE: " fmt, ##arg); } while(0)

#if defined(CONFIG_GE_DEBUG_MESSAGES)
#define GE_DBG(level,fmt,arg...) \
  do { (level&ge_debug_message_mask)?\
       (printk(KERN_DEBUG "GE: " fmt, ##arg)):(0); } while(0)
#else
#define GE_DBG(level,fmt,arg...) \
  do { /* nothing */ } while(0)
#endif

/* FIN()         - show that we entered the function
 * FOUT()        - show that we exited the function with success
 * FERR()        - show that we exited the function with an error
 * FEXIT(assert) - if assertion passes FOUT, else FERR
 */
#define GE_FN(lbl) do { GE_DBG(GE_DBG_FNTRACE, lbl " %s [%s:%d]\n",\
  __PRETTY_FUNCTION__,__FILE__,__LINE__); } while(0)
#define FIN()   GE_FN("IN ")
#define FSTP()  GE_FN("STP")
#define FOUT()  GE_FN("OUT")
#define FERR()  GE_FN("ERR")

#if defined(CONFIG_GE_DEBUG_MESSAGES)
#define FEXIT(assert)  do { if( assert ) FOUT(); else FERR(); } while(0)
#else
#define FEXIT(assert) do { /* nothing */ } while(0)
#endif

static inline void
ge_data_dump(const char * label, const u8 *data, const u32 len)
{
  u32 i;
  u32 max = MIN(len,128);
  u8 *p, buffer[max*4];
  printk(KERN_DEBUG "%s, %d bytes\n",label, len);
  p = buffer;
  for(i=0;i<max;i++)
    p+=sprintf(p,"%02x ",data[i]);
  printk(KERN_DEBUG "%s\n", buffer);
}


#endif /* __KERNEL__ */

#endif /* ENGINE_DEBUG_H */

/*****************************************************************************
 *
 * $Log: engine-debug.h,v $
 * Revision 1.6  2001/06/04 02:11:22  bart
 * added GE_ERR; now using KERN_{DEBUG,ERROR}
 *
 * Revision 1.5  2001/06/03 15:21:35  bart
 * added ge_data_dump()
 *
 * Revision 1.4  2001/06/03 02:15:54  bart
 * fixed spelling 'bug'
 *
 * Revision 1.3  2001/06/02 22:51:50  bart
 * improved debug logging
 *
 * Revision 1.2  2001/06/02 22:28:54  bart
 * fixed a bug in the GE_DBG macro
 *
 * Revision 1.1  2001/06/02 22:24:59  bart
 * added debug messages to generic engine.
 *
 *
 *****************************************************************************/

