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