xref: /illumos-gate/usr/src/cmd/mdb/common/kmdb/kctl/kctl.h (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _KCTL_H
277c478bd9Sstevel@tonic-gate #define	_KCTL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_auxv.h>
307c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_wr.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
337c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
347c478bd9Sstevel@tonic-gate #include <sys/kdi.h>
357c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
367c478bd9Sstevel@tonic-gate #include <sys/ksynch.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef __cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate typedef enum {
437c478bd9Sstevel@tonic-gate 	KCTL_ST_INACTIVE = 0,		/* kmdb is inactive */
447c478bd9Sstevel@tonic-gate 	KCTL_ST_DSEG_ALLOCED,		/* kmdb segment has been allocated */
457c478bd9Sstevel@tonic-gate 	KCTL_ST_INITIALIZED,		/* kmdb_init has been called */
467c478bd9Sstevel@tonic-gate 	KCTL_ST_KCTL_PREACTIVATED,	/* kctl preactivation completed */
477c478bd9Sstevel@tonic-gate 	KCTL_ST_MOD_NOTIFIERS,		/* krtld module notifiers registered */
487c478bd9Sstevel@tonic-gate 	KCTL_ST_THREAD_STARTED,		/* WR queue thread started */
497c478bd9Sstevel@tonic-gate 	KCTL_ST_DBG_ACTIVATED,		/* kmdb activated */
507c478bd9Sstevel@tonic-gate 	KCTL_ST_ACTIVE,			/* kernel is aware of kmdb activation */
517c478bd9Sstevel@tonic-gate 	KCTL_ST_DEACTIVATING		/* debugger is being deactivated */
527c478bd9Sstevel@tonic-gate } kctl_state_t;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate typedef enum {
557c478bd9Sstevel@tonic-gate 	KCTL_WR_ST_RUN,			/* WR queue thread is running */
567c478bd9Sstevel@tonic-gate 	KCTL_WR_ST_STOP,		/* WR queue thread is stopping */
577c478bd9Sstevel@tonic-gate 	KCTL_WR_ST_STOPPED		/* WR queue thread has stopped */
587c478bd9Sstevel@tonic-gate } kctl_wr_state_t;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate typedef struct kctl {
617c478bd9Sstevel@tonic-gate 	dev_info_t *kctl_drv_dip;	/* Driver's device info structure */
627c478bd9Sstevel@tonic-gate 	size_t kctl_memgoalsz;		/* Desired size of debugger memory */
637c478bd9Sstevel@tonic-gate 	caddr_t	kctl_dseg;		/* Debugger segment (Oz) address */
647c478bd9Sstevel@tonic-gate 	size_t kctl_dseg_size;		/* Debugger segment (Oz) size */
657c478bd9Sstevel@tonic-gate 	caddr_t kctl_mrbase;		/* Add'l Oz memory range base address */
667c478bd9Sstevel@tonic-gate 	size_t kctl_mrsize;		/* Add'l Oz memory range size */
677c478bd9Sstevel@tonic-gate 	vnode_t kctl_vp;		/* vnode used to allocate dbgr seg */
687c478bd9Sstevel@tonic-gate 	kctl_state_t kctl_state;	/* State of debugger */
697c478bd9Sstevel@tonic-gate 	uint_t kctl_boot_loaded;	/* Set if debugger loaded at boot */
707c478bd9Sstevel@tonic-gate 	struct bootops *kctl_boot_ops;	/* Boot operations (during init only) */
717c478bd9Sstevel@tonic-gate 	const char *kctl_execname;	/* Path of this module */
727c478bd9Sstevel@tonic-gate 	uint_t kctl_wr_avail;		/* Work available on the WR queue */
737c478bd9Sstevel@tonic-gate 	ksema_t kctl_wr_avail_sem;	/* For WR thr: Work avail on WR queue */
747c478bd9Sstevel@tonic-gate 	kthread_t *kctl_wr_thr;		/* Thread that processes WR queue */
757c478bd9Sstevel@tonic-gate 	kctl_wr_state_t kctl_wr_state;	/* State of WR queue thread */
767c478bd9Sstevel@tonic-gate 	kmutex_t kctl_lock;		/* serializes (de)activation */
777c478bd9Sstevel@tonic-gate 	kcondvar_t kctl_wr_cv;		/* WR queue thread completion */
787c478bd9Sstevel@tonic-gate 	kmutex_t kctl_wr_lock;		/* WR queue thread completion */
797c478bd9Sstevel@tonic-gate 	uint_t kctl_flags;		/* KMDB_F_* from kmdb.h */
807c478bd9Sstevel@tonic-gate #ifdef __sparc
817c478bd9Sstevel@tonic-gate 	caddr_t kctl_tba;		/* kmdb's native trap table */
827c478bd9Sstevel@tonic-gate #endif
837c478bd9Sstevel@tonic-gate } kctl_t;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate extern kctl_t kctl;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate struct bootops;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate extern void kctl_dprintf(const char *, ...);
907c478bd9Sstevel@tonic-gate extern void kctl_warn(const char *, ...);
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate extern int kctl_preactivate_isadep(void);
93*ae115bc7Smrj extern void kctl_activate_isadep(kdi_debugvec_t *);
947c478bd9Sstevel@tonic-gate extern void kctl_depreactivate_isadep(void);
957c478bd9Sstevel@tonic-gate extern void kctl_cleanup(void);
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate extern void *kctl_boot_tmpinit(void);
987c478bd9Sstevel@tonic-gate extern void kctl_boot_tmpfini(void *);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate extern void kctl_auxv_init(kmdb_auxv_t *, const char *, const char **, void *);
1017c478bd9Sstevel@tonic-gate extern void kctl_auxv_init_isadep(kmdb_auxv_t *, void *);
1027c478bd9Sstevel@tonic-gate extern void kctl_auxv_fini(kmdb_auxv_t *);
1037c478bd9Sstevel@tonic-gate extern void kctl_auxv_fini_isadep(kmdb_auxv_t *);
1041ae08745Sheppo #ifdef sun4v
1051ae08745Sheppo extern void kctl_auxv_set_promif(kmdb_auxv_t *);
1061ae08745Sheppo extern void kctl_switch_promif(void);
1071ae08745Sheppo #endif
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate extern void kctl_wrintr(void);
1107c478bd9Sstevel@tonic-gate extern void kctl_wrintr_fire(void);
1117c478bd9Sstevel@tonic-gate extern void kctl_wr_thr_start(void);
1127c478bd9Sstevel@tonic-gate extern void kctl_wr_thr_stop(void);
1137c478bd9Sstevel@tonic-gate extern void kctl_wr_thr_join(void);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate extern int kctl_mod_decompress(struct modctl *);
1167c478bd9Sstevel@tonic-gate extern void kctl_mod_loaded(struct modctl *);
1177c478bd9Sstevel@tonic-gate extern void kctl_mod_changed(uint_t, struct modctl *);
1187c478bd9Sstevel@tonic-gate extern void kctl_mod_notify_reg(void);
1197c478bd9Sstevel@tonic-gate extern void kctl_mod_notify_unreg(void);
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate extern void kctl_dmod_init(void);
1227c478bd9Sstevel@tonic-gate extern void kctl_dmod_fini(void);
1237c478bd9Sstevel@tonic-gate extern void kctl_dmod_sync(void);
1247c478bd9Sstevel@tonic-gate extern void kctl_dmod_autoload(const char *);
1257c478bd9Sstevel@tonic-gate extern void kctl_dmod_unload_all(void);
1267c478bd9Sstevel@tonic-gate extern void kctl_dmod_path_reset(void);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate extern int kctl_wr_process(void);
1297c478bd9Sstevel@tonic-gate extern void kctl_wr_unload(void);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate extern char *kctl_basename(char *);
1327c478bd9Sstevel@tonic-gate extern char *kctl_strdup(const char *);
1337c478bd9Sstevel@tonic-gate extern void kctl_strfree(char *);
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #if defined(__sparc)
1367c478bd9Sstevel@tonic-gate extern kthread_t *kctl_curthread_set(kthread_t *);
1377c478bd9Sstevel@tonic-gate #endif
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate #endif
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #endif /* _KCTL_H */
144