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