summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mdb/common/kmdb/kctl/kctl.h
blob: 612ed8db13264b37c18600b9413e85aaea5ed10a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _KCTL_H
#define	_KCTL_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <kmdb/kmdb_auxv.h>
#include <kmdb/kmdb_wr.h>

#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/kdi.h>
#include <sys/modctl.h>
#include <sys/ksynch.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
	KCTL_ST_INACTIVE = 0,		/* kmdb is inactive */
	KCTL_ST_DSEG_ALLOCED,		/* kmdb segment has been allocated */
	KCTL_ST_INITIALIZED,		/* kmdb_init has been called */
	KCTL_ST_KCTL_PREACTIVATED,	/* kctl preactivation completed */
	KCTL_ST_MOD_NOTIFIERS,		/* krtld module notifiers registered */
	KCTL_ST_THREAD_STARTED,		/* WR queue thread started */
	KCTL_ST_DBG_ACTIVATED,		/* kmdb activated */
	KCTL_ST_KCTL_ACTIVATED,		/* kctl activated */
	KCTL_ST_ACTIVE,			/* kernel is aware of kmdb activation */
	KCTL_ST_DEACTIVATING		/* debugger is being deactivated */
} kctl_state_t;

typedef enum {
	KCTL_WR_ST_RUN,			/* WR queue thread is running */
	KCTL_WR_ST_STOP,		/* WR queue thread is stopping */
	KCTL_WR_ST_STOPPED		/* WR queue thread has stopped */
} kctl_wr_state_t;

typedef struct kctl {
	dev_info_t *kctl_drv_dip;	/* Driver's device info structure */
	size_t kctl_memgoalsz;		/* Desired size of debugger memory */
	caddr_t	kctl_dseg;		/* Debugger segment (Oz) address */
	size_t kctl_dseg_size;		/* Debugger segment (Oz) size */
	caddr_t kctl_mrbase;		/* Add'l Oz memory range base address */
	size_t kctl_mrsize;		/* Add'l Oz memory range size */
	vnode_t kctl_vp;		/* vnode used to allocate dbgr seg */
	kctl_state_t kctl_state;	/* State of debugger */
	uint_t kctl_boot_loaded;	/* Set if debugger loaded at boot */
	struct bootops *kctl_boot_ops;	/* Boot operations (during init only) */
	const char *kctl_execname;	/* Path of this module */
	uint_t kctl_wr_avail;		/* Work available on the WR queue */
	ksema_t kctl_wr_avail_sem;	/* For WR thr: Work avail on WR queue */
	kthread_t *kctl_wr_thr;		/* Thread that processes WR queue */
	kctl_wr_state_t kctl_wr_state;	/* State of WR queue thread */
	kmutex_t kctl_lock;		/* serializes (de)activation */
	kcondvar_t kctl_wr_cv;		/* WR queue thread completion */
	kmutex_t kctl_wr_lock;		/* WR queue thread completion */
	uint_t kctl_flags;		/* KMDB_F_* from kmdb.h */
#ifdef __sparc
	caddr_t kctl_tba;		/* kmdb's native trap table */
#endif
} kctl_t;

extern kctl_t kctl;

struct bootops;

extern void kctl_dprintf(const char *, ...);
extern void kctl_warn(const char *, ...);

extern int kctl_preactivate_isadep(void);
extern int kctl_activate_isadep(kdi_debugvec_t *);
extern void kctl_depreactivate_isadep(void);
extern void kctl_deactivate_isadep(void);
extern void kctl_cleanup(void);

extern void *kctl_boot_tmpinit(void);
extern void kctl_boot_tmpfini(void *);

extern void kctl_auxv_init(kmdb_auxv_t *, const char *, const char **, void *);
extern void kctl_auxv_init_isadep(kmdb_auxv_t *, void *);
extern void kctl_auxv_fini(kmdb_auxv_t *);
extern void kctl_auxv_fini_isadep(kmdb_auxv_t *);
#ifdef sun4v
extern void kctl_auxv_set_promif(kmdb_auxv_t *);
extern void kctl_switch_promif(void);
#endif

extern void kctl_wrintr(void);
extern void kctl_wrintr_fire(void);
extern void kctl_wr_thr_start(void);
extern void kctl_wr_thr_stop(void);
extern void kctl_wr_thr_join(void);

extern int kctl_mod_decompress(struct modctl *);
extern void kctl_mod_loaded(struct modctl *);
extern void kctl_mod_changed(uint_t, struct modctl *);
extern void kctl_mod_notify_reg(void);
extern void kctl_mod_notify_unreg(void);

extern void kctl_dmod_init(void);
extern void kctl_dmod_fini(void);
extern void kctl_dmod_sync(void);
extern void kctl_dmod_autoload(const char *);
extern void kctl_dmod_unload_all(void);
extern void kctl_dmod_path_reset(void);

extern int kctl_wr_process(void);
extern void kctl_wr_unload(void);

extern char *kctl_basename(char *);
extern char *kctl_strdup(const char *);
extern void kctl_strfree(char *);

#if defined(__sparc)
extern kthread_t *kctl_curthread_set(kthread_t *);
#endif

#ifdef __cplusplus
}
#endif

#endif /* _KCTL_H */