xref: /titanic_50/usr/src/cmd/mdb/common/kmdb/kctl/kctl.h (revision 9f758caf94c37c3ad28c48cfe503f9fc830a66d5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _KCTL_H
27 #define	_KCTL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <kmdb/kmdb_auxv.h>
32 #include <kmdb/kmdb_wr.h>
33 
34 #include <sys/ddi.h>
35 #include <sys/sunddi.h>
36 #include <sys/kdi.h>
37 #include <sys/modctl.h>
38 #include <sys/ksynch.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 typedef enum {
45 	KCTL_ST_INACTIVE = 0,		/* kmdb is inactive */
46 	KCTL_ST_DSEG_ALLOCED,		/* kmdb segment has been allocated */
47 	KCTL_ST_INITIALIZED,		/* kmdb_init has been called */
48 	KCTL_ST_KCTL_PREACTIVATED,	/* kctl preactivation completed */
49 	KCTL_ST_MOD_NOTIFIERS,		/* krtld module notifiers registered */
50 	KCTL_ST_THREAD_STARTED,		/* WR queue thread started */
51 	KCTL_ST_DBG_ACTIVATED,		/* kmdb activated */
52 	KCTL_ST_ACTIVE,			/* kernel is aware of kmdb activation */
53 	KCTL_ST_DEACTIVATING		/* debugger is being deactivated */
54 } kctl_state_t;
55 
56 typedef enum {
57 	KCTL_WR_ST_RUN,			/* WR queue thread is running */
58 	KCTL_WR_ST_STOP,		/* WR queue thread is stopping */
59 	KCTL_WR_ST_STOPPED		/* WR queue thread has stopped */
60 } kctl_wr_state_t;
61 
62 typedef struct kctl {
63 	dev_info_t *kctl_drv_dip;	/* Driver's device info structure */
64 	size_t kctl_memgoalsz;		/* Desired size of debugger memory */
65 	caddr_t	kctl_dseg;		/* Debugger segment (Oz) address */
66 	size_t kctl_dseg_size;		/* Debugger segment (Oz) size */
67 	caddr_t kctl_mrbase;		/* Add'l Oz memory range base address */
68 	size_t kctl_mrsize;		/* Add'l Oz memory range size */
69 	vnode_t kctl_vp;		/* vnode used to allocate dbgr seg */
70 	kctl_state_t kctl_state;	/* State of debugger */
71 	uint_t kctl_boot_loaded;	/* Set if debugger loaded at boot */
72 	struct bootops *kctl_boot_ops;	/* Boot operations (during init only) */
73 	const char *kctl_execname;	/* Path of this module */
74 	uint_t kctl_wr_avail;		/* Work available on the WR queue */
75 	ksema_t kctl_wr_avail_sem;	/* For WR thr: Work avail on WR queue */
76 	kthread_t *kctl_wr_thr;		/* Thread that processes WR queue */
77 	kctl_wr_state_t kctl_wr_state;	/* State of WR queue thread */
78 	kmutex_t kctl_lock;		/* serializes (de)activation */
79 	kcondvar_t kctl_wr_cv;		/* WR queue thread completion */
80 	kmutex_t kctl_wr_lock;		/* WR queue thread completion */
81 	uint_t kctl_flags;		/* KMDB_F_* from kmdb.h */
82 #ifdef __sparc
83 	caddr_t kctl_tba;		/* kmdb's native trap table */
84 #endif
85 } kctl_t;
86 
87 extern kctl_t kctl;
88 
89 struct bootops;
90 
91 extern void kctl_dprintf(const char *, ...);
92 extern void kctl_warn(const char *, ...);
93 
94 extern int kctl_preactivate_isadep(void);
95 extern void kctl_activate_isadep(kdi_debugvec_t *);
96 extern void kctl_depreactivate_isadep(void);
97 extern void kctl_cleanup(void);
98 
99 extern void *kctl_boot_tmpinit(void);
100 extern void kctl_boot_tmpfini(void *);
101 
102 extern void kctl_auxv_init(kmdb_auxv_t *, const char *, const char **, void *);
103 extern void kctl_auxv_init_isadep(kmdb_auxv_t *, void *);
104 extern void kctl_auxv_fini(kmdb_auxv_t *);
105 extern void kctl_auxv_fini_isadep(kmdb_auxv_t *);
106 #ifdef sun4v
107 extern void kctl_auxv_set_promif(kmdb_auxv_t *);
108 extern void kctl_switch_promif(void);
109 #endif
110 
111 extern void kctl_wrintr(void);
112 extern void kctl_wrintr_fire(void);
113 extern void kctl_wr_thr_start(void);
114 extern void kctl_wr_thr_stop(void);
115 extern void kctl_wr_thr_join(void);
116 
117 extern int kctl_mod_decompress(struct modctl *);
118 extern void kctl_mod_loaded(struct modctl *);
119 extern void kctl_mod_changed(uint_t, struct modctl *);
120 extern void kctl_mod_notify_reg(void);
121 extern void kctl_mod_notify_unreg(void);
122 
123 extern void kctl_dmod_init(void);
124 extern void kctl_dmod_fini(void);
125 extern void kctl_dmod_sync(void);
126 extern void kctl_dmod_autoload(const char *);
127 extern void kctl_dmod_unload_all(void);
128 extern void kctl_dmod_path_reset(void);
129 
130 extern int kctl_wr_process(void);
131 extern void kctl_wr_unload(void);
132 
133 extern char *kctl_basename(char *);
134 extern char *kctl_strdup(const char *);
135 extern void kctl_strfree(char *);
136 
137 #if defined(__sparc)
138 extern kthread_t *kctl_curthread_set(kthread_t *);
139 #endif
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif /* _KCTL_H */
146