xref: /titanic_52/usr/src/uts/common/sys/kdi_impl.h (revision bfed486ad8de8b8ebc6345a8e10accae08bf2f45)
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 _KDI_IMPL_H
27 #define	_KDI_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/kdi.h>
32 #include <sys/kdi_machimpl.h>
33 #include <sys/privregs.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 struct module;
40 struct gdscr;
41 
42 /*
43  * The debugvec is used by the kernel to interact with the debugger.
44  */
45 struct kdi_debugvec {
46 	void	(*dv_kctl_vmready)(void);
47 	void	(*dv_kctl_memavail)(void);
48 	void	(*dv_kctl_modavail)(void);
49 	void	(*dv_kctl_thravail)(void);
50 
51 	void	(*dv_vmready)(void);
52 	void	(*dv_memavail)(caddr_t, size_t);
53 	void	(*dv_mod_loaded)(struct modctl *);
54 	void	(*dv_mod_unloading)(struct modctl *);
55 
56 #if defined(__i386) || defined(__amd64)
57 	void	(*dv_handle_fault)(greg_t, greg_t, greg_t, int);
58 #endif
59 #if defined(__sparc)
60 	void	(*dv_kctl_cpu_init)(void);
61 	void	(*dv_cpu_init)(struct cpu *);
62 	void	(*dv_cpr_restart)(void);
63 #endif
64 };
65 
66 typedef struct kdi_plat {
67 	void (*pkdi_system_claim)(void);
68 	void (*pkdi_system_release)(void);
69 	void (*pkdi_console_claim)(void);
70 	void (*pkdi_console_release)(void);
71 } kdi_plat_t;
72 
73 #define	pkdi_system_claim	kdi_plat.pkdi_system_claim
74 #define	pkdi_system_release	kdi_plat.pkdi_system_release
75 #define	pkdi_console_claim	kdi_plat.pkdi_console_claim
76 #define	pkdi_console_release	kdi_plat.pkdi_console_release
77 
78 /*
79  * The KDI, or Kernel/Debugger Interface, consists of an ops vector describing
80  * kernel services that may be directly invoked by the debugger.  Unless
81  * otherwise specified, the functions implementing this ops vector are designed
82  * to function when the debugger has control of the system - when all other CPUs
83  * have been stopped.  In such an environment, blocking services such as memory
84  * allocation or synchronization primitives are not available.
85  */
86 
87 struct kdi {
88 	int kdi_version;
89 
90 	/*
91 	 * Determines whether significant changes (loads or unloads) have
92 	 * been made to the modules since the last time this op was invoked.
93 	 */
94 	int (*kdi_mods_changed)(void);
95 
96 	/*
97 	 * Iterates through the current set of modctls, and invokes the
98 	 * caller-provided callback on each one.
99 	 */
100 	int (*kdi_mod_iter)(int (*)(struct modctl *, void *), void *);
101 
102 	/*
103 	 * Determines whether or not a given module is loaded.
104 	 */
105 	int (*kdi_mod_isloaded)(struct modctl *);
106 
107 	/*
108 	 * Has anything changed between two versions of the same modctl?
109 	 */
110 	int (*kdi_mod_haschanged)(struct modctl *, struct module *,
111 	    struct modctl *, struct module *);
112 
113 	/*
114 	 * Invoked by the debugger when it assumes control of the machine.
115 	 */
116 	void (*kdi_system_claim)(void);
117 
118 	/*
119 	 * Invoked by the debugger when it relinquishes control of the machine.
120 	 */
121 	void (*kdi_system_release)(void);
122 
123 	int (*kdi_pread)(caddr_t, size_t, uint64_t, size_t *);
124 	int (*kdi_pwrite)(caddr_t, size_t, uint64_t, size_t *);
125 	void (*kdi_flush_caches)(void);
126 
127 	size_t (*kdi_range_is_nontoxic)(uintptr_t, size_t, int);
128 
129 	struct cons_polledio *(*kdi_get_polled_io)(void);
130 
131 	int (*kdi_vtop)(uintptr_t, uint64_t *);
132 
133 	kdi_dtrace_state_t (*kdi_dtrace_get_state)(void);
134 	int (*kdi_dtrace_set)(kdi_dtrace_set_t);
135 
136 	void (*kdi_plat_call)(void (*)(void));
137 
138 	void (*kdi_kmdb_enter)(void);
139 
140 	kdi_mach_t kdi_mach;
141 	kdi_plat_t kdi_plat;
142 };
143 
144 extern void kdi_softcall(void (*)(void));
145 extern void kdi_setsoftint(uint64_t);
146 extern int kdi_pread(caddr_t, size_t, uint64_t, size_t *);
147 extern int kdi_pwrite(caddr_t, size_t, uint64_t, size_t *);
148 extern size_t kdi_range_is_nontoxic(uintptr_t, size_t, int);
149 extern void kdi_flush_caches(void);
150 extern kdi_dtrace_state_t kdi_dtrace_get_state(void);
151 extern int kdi_vtop(uintptr_t, uint64_t *);
152 
153 extern void cpu_kdi_init(kdi_t *);
154 extern void mach_kdi_init(kdi_t *);
155 extern void plat_kdi_init(kdi_t *);
156 
157 extern void *boot_kdi_tmpinit(void);
158 extern void boot_kdi_tmpfini(void *);
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif /* _KDI_IMPL_H */
165