-/* Usage:
-* kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START),
-* offset, 0, 0, 0,0)
-*
-* For ex,
-*
-* #include <sys/kdebug.h>
-*
-* #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1)
-*
-*
-* void
-* ip_init()
-* {
-* register struct protosw *pr;
-* register int i;
-*
-* KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0)
-* --------
-* KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0)
-* --------
-* KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0)
-* }
-*
-
-*/
-
-extern unsigned int kdebug_enable;
-#define KDEBUG_ENABLE_TRACE 0x1
-#define KDEBUG_ENABLE_ENTROPY 0x2
-#define KDEBUG_ENABLE_CHUD 0x4
-#define KDEBUG_ENABLE_PPT 0x8
-
-/*
- * Infer the supported kernel debug event level from config option.
- * Use (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect
- * unaudited debug code.
- */
-#define KDEBUG_LEVEL_NONE 0
-#define KDEBUG_LEVEL_IST 1
-#define KDEBUG_LEVEL_STANDARD 2
-#define KDEBUG_LEVEL_FULL 3
-
-#if NO_KDEBUG
-#define KDEBUG_LEVEL KDEBUG_LEVEL_NONE
-#elif IST_KDEBUG
-#define KDEBUG_LEVEL KDEBUG_LEVEL_IST
-#elif KDEBUG
-#define KDEBUG_LEVEL KDEBUG_LEVEL_FULL
-#else
-#define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
-#endif
-
-#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
-#ifdef XNU_KERNEL_PRIVATE
-#define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
-do { \
- if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
- kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
- (uintptr_t)d,(uintptr_t)e); \
-} while(0)
-
-#define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
-do { \
- if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
- kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
- (uintptr_t)d,(uintptr_t)e); \
-} while(0)
-#else /* XNU_KERNEL_PRIVATE */
-#define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
-do { \
- if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
- kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
- (uintptr_t)d,(uintptr_t)e); \
-} while(0)
-
-#define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
-do { \
- if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
- kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
- (uintptr_t)d,(uintptr_t)e); \
-} while(0)
-#endif /* XNU_KERNEL_PRIVATE */
-#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
-#define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) do { } while(0)
-#define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) do { } while(0)
-#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
-
-/*
- * Specify KDEBUG_PPT to indicate that the event belongs to the
- * limited PPT set.
- */
-#define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_ENTROPY|KDEBUG_ENABLE_CHUD|KDEBUG_ENABLE_PPT)
-#define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_ENTROPY|KDEBUG_ENABLE_CHUD)
-#define KDEBUG_PPT (KDEBUG_ENABLE_PPT)
-
-/*
- * KERNEL_DEBUG_CONSTANT_IST events provide an audited subset of
- * tracepoints for userland system tracing tools.
- */
-#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
-#ifdef XNU_KERNEL_PRIVATE
-#define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
-do { \
- if (__improbable(kdebug_enable & type)) \
- kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
- (uintptr_t)d,(uintptr_t)e); \
-} while(0)
-#else /* XNU_KERNEL_PRIVATE */
-#define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
-do { \
- if (kdebug_enable & type) \
- kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
- (uintptr_t)d,(uintptr_t)e); \
-} while(0)
-#endif /* XNU_KERNEL_PRIVATE */
-#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
-#define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) do { } while(0)
-#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
-
-#if NO_KDEBUG
-#define __kdebug_constant_only __unused
-#endif
-
-extern void kernel_debug(
- uint32_t debugid,
- uintptr_t arg1,
- uintptr_t arg2,
- uintptr_t arg3,
- uintptr_t arg4,
- uintptr_t arg5);
-
-extern void kernel_debug1(
- uint32_t debugid,
- uintptr_t arg1,
- uintptr_t arg2,
- uintptr_t arg3,
- uintptr_t arg4,
- uintptr_t arg5);
-
-
-#if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL)
-#ifdef XNU_KERNEL_PRIVATE
-#define KERNEL_DEBUG(x,a,b,c,d,e) \
-do { \
- if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
- kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
- (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
-} while(0)
-
-#define KERNEL_DEBUG1(x,a,b,c,d,e) \
-do { \
- if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
- kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
- (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
-} while(0)
-
-#define __kdebug_only
-#else /* !XNU_KERNEL_PRIVATE */
-#define KERNEL_DEBUG(x,a,b,c,d,e) \
-do { \
- if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
- kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
- (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
-} while(0)
-
-#define KERNEL_DEBUG1(x,a,b,c,d,e) \
-do { \
- if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
- kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
- (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
-} while(0)
-#endif /* XNU_KERNEL_PRIVATE */
-#else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
-#define KERNEL_DEBUG(x,a,b,c,d,e) do {} while (0)
-#define KERNEL_DEBUG1(x,a,b,c,d,e) do {} while (0)
-
-#define __kdebug_only __unused
-#endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
-
-#ifdef KERNEL_PRIVATE
-#include <mach/boolean.h>
-struct proc;
-extern void kdbg_trace_data(struct proc *proc, long *arg_pid);
-
-extern void kdbg_trace_string(struct proc *proc, long *arg1, long *arg2, long *arg3, long *arg4);
-
-extern void kdbg_dump_trace_to_file(const char *);
-void start_kern_tracing(unsigned int);
-struct task;
-extern void kdbg_get_task_name(char*, int, struct task *task);
-void disable_wrap(uint32_t *old_slowcheck, uint32_t *old_flags);
-void enable_wrap(uint32_t old_slowcheck, boolean_t lostevents);
-void release_storage_unit(int cpu, uint32_t storage_unit);
-int allocate_storage_unit(int cpu);
-
-void trace_handler_map_ctrl_page(uintptr_t addr, unsigned long ctrl_page_size, unsigned long storage_size, unsigned long kds_ptr_size);
-void trace_handler_map_bufinfo(uintptr_t addr, unsigned long size);
-void trace_handler_unmap_bufinfo(void);
-void trace_handler_map_buffer(int index, uintptr_t addr, unsigned long size);
-void trace_handler_unmap_buffer(int index);
-void trace_set_timebases(uint64_t tsc, uint64_t ns);
-
-
-#endif /* KERNEL_PRIVATE */