/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _KDI_H
#define	_KDI_H

#pragma ident	"@(#)kdi.h	1.5	04/11/08 SMI"

/*
 * The Kernel/Debugger interface.
 *
 * The Debugger -> Kernel portion of the interface is handled by the kdi_t,
 * which is defined in the archkdi.h files.  These functions are intended to
 * be called only when the system is stopped and the debugger is in control.
 *
 * The Kernel -> Debugger portion is handled by the debugvec_t, which is
 * defined here.  These functions are used by the kernel to inform the debugger
 * of various state changes.
 */

#ifdef __cplusplus
extern "C" {
#endif

/* The VA range reserved for the debugger. */
#if defined(__sparc)
#define	SEGDEBUGBASE	0xedd00000
#define	SEGDEBUGSIZE	(0xf0000000 - SEGDEBUGBASE)
#elif defined(__amd64)
#define	SEGDEBUGBASE	0xffffffffff800000
#define	SEGDEBUGSIZE	0x400000
#else
#define	SEGDEBUGBASE	0xff800000
#define	SEGDEBUGSIZE	0x400000
#endif

struct cpu;
struct modctl;
struct gate_desc;
struct user_desc;

typedef struct kdi_debugvec kdi_debugvec_t;
typedef struct kdi kdi_t;

extern kdi_debugvec_t *kdi_dvec;

#define	KDI_VERSION		6

extern void kdi_dvec_enter(void);
extern void kdi_dvec_cpu_init(struct cpu *);
#if defined(__i386) || defined(__amd64)
extern void kdi_dvec_idt_sync(struct gate_desc *);
#endif	/* __i386 || __amd64 */
extern void kdi_dvec_vmready(void);
extern void kdi_dvec_memavail(void);
#if defined(__sparc)
extern void kdi_dvec_cpr_restart(void);
#endif
extern void kdi_dvec_modavail(void);
extern void kdi_dvec_thravail(void);
extern void kdi_dvec_mod_loaded(struct modctl *);
extern void kdi_dvec_mod_unloading(struct modctl *);

/*
 * The state machine described below is used to coordinate the efforts of
 * kmdb and dtrace.  As both use breakpoints, only one may be currently be
 * active at a given time.  Transitions are possible between the idle state
 * and either of the active states, but not directly between the two active
 * states.
 */
typedef enum kdi_dtrace_set {
	KDI_DTSET_DTRACE_ACTIVATE,
	KDI_DTSET_DTRACE_DEACTIVATE,
	KDI_DTSET_KMDB_BPT_ACTIVATE,
	KDI_DTSET_KMDB_BPT_DEACTIVATE
} kdi_dtrace_set_t;

typedef enum {
	KDI_DTSTATE_DTRACE_ACTIVE,
	KDI_DTSTATE_IDLE,
	KDI_DTSTATE_KMDB_BPT_ACTIVE
} kdi_dtrace_state_t;

extern int kdi_dtrace_set(kdi_dtrace_set_t);

#ifdef __cplusplus
}
#endif

#endif /* _KDI_H */
