1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Kernel/Debugger Interface (KDI) routines. Called during debugger under
* various system states (boot, while running, while the debugger has control).
* Functions intended for use while the debugger has control may not grab any
* locks or perform any functions that assume the availability of other system
* services.
*/
#include <sys/systm.h>
#include <sys/x86_archext.h>
#include <sys/kdi_impl.h>
#include <sys/smp_impldefs.h>
#include <sys/psm_types.h>
#include <sys/segments.h>
static void
kdi_system_claim(void)
{
psm_notifyf(PSM_DEBUG_ENTER);
}
static void
kdi_system_release(void)
{
psm_notifyf(PSM_DEBUG_EXIT);
}
static cpu_t *
kdi_gdt2cpu(uintptr_t gdtbase)
{
cpu_t *cp = cpu_list;
if (cp == NULL)
return (NULL);
do {
if (gdtbase == (uintptr_t)cp->cpu_gdt)
return (cp);
} while ((cp = cp->cpu_next) != cpu_list);
return (NULL);
}
#if defined(__amd64)
static uintptr_t
kdi_gdt2gsbase(uintptr_t gdtbase)
{
return ((uintptr_t)kdi_gdt2cpu(gdtbase));
}
#endif
static void
kdi_cpu_iter(void (*iter)(cpu_t *, uint_t), uint_t arg)
{
cpu_t *cp;
mutex_enter(&cpu_lock);
cp = cpu_list;
do {
iter(cp, arg);
} while ((cp = cp->cpu_next) != cpu_list);
mutex_exit(&cpu_lock);
}
static gate_desc_t *
curidt(void)
{
desctbr_t idtdesc;
rd_idtr(&idtdesc);
return ((gate_desc_t *)idtdesc.dtr_base);
}
static void
kdi_idt_init_gate(gate_desc_t *gate, void (*hdlr)(void), uint_t dpl,
int useboot)
{
bzero(gate, sizeof (gate_desc_t));
#if defined(__amd64)
set_gatesegd(gate, hdlr, (useboot ? B64CODE_SEL : KCS_SEL), 0,
SDT_SYSIGT, dpl);
#else
set_gatesegd(gate, hdlr, (useboot ? BOOTCODE_SEL : KCS_SEL), 0,
SDT_SYSIGT, dpl);
#endif
}
static void
kdi_idt_read(gate_desc_t *idt, gate_desc_t *gatep, uint_t vec)
{
if (idt == NULL)
idt = curidt();
*gatep = idt[vec];
}
static void
kdi_idt_write(gate_desc_t *idt, gate_desc_t *gate, uint_t vec)
{
if (idt == NULL)
idt = curidt();
idt[vec] = *gate;
}
static gate_desc_t *
kdi_cpu2idt(cpu_t *cp)
{
if (cp == NULL)
cp = CPU;
return (cp->cpu_idt);
}
void
kdi_flush_caches(void)
{
reload_cr3();
}
static int
kdi_get_cpuinfo(uint_t *vendorp, uint_t *familyp, uint_t *modelp)
{
desctbr_t gdtr;
cpu_t *cpu;
/*
* CPU doesn't work until the GDT and gs/GSBASE have been set up.
* Boot-loaded kmdb will call us well before then, so we have to
* find the current cpu_t the hard way.
*/
rd_gdtr(&gdtr);
if ((cpu = kdi_gdt2cpu(gdtr.dtr_base)) == NULL ||
!cpuid_checkpass(cpu, 1))
return (EAGAIN); /* cpuid isn't done yet */
*vendorp = cpuid_getvendor(cpu);
*familyp = cpuid_getfamily(cpu);
*modelp = cpuid_getmodel(cpu);
return (0);
}
static void
kdi_plat_call(void (*platfn)(void))
{
if (platfn != NULL)
platfn();
}
void
mach_kdi_init(kdi_t *kdi)
{
kdi->kdi_plat_call = kdi_plat_call;
kdi->mkdi_get_cpuinfo = kdi_get_cpuinfo;
kdi->mkdi_xc_initialized = kdi_xc_initialized;
kdi->mkdi_xc_others = kdi_xc_others;
kdi->mkdi_get_userlimit = kdi_get_userlimit;
kdi->mkdi_idt_init_gate = kdi_idt_init_gate;
kdi->mkdi_idt_read = kdi_idt_read;
kdi->mkdi_idt_write = kdi_idt_write;
kdi->mkdi_cpu2idt = kdi_cpu2idt;
kdi->mkdi_shutdownp = &psm_shutdownf;
#if defined(__amd64)
kdi->mkdi_gdt2gsbase = &kdi_gdt2gsbase;
#endif
kdi->mkdi_cpu_iter = kdi_cpu_iter;
}
/*ARGSUSED*/
void
mach_kdi_fini(kdi_t *kdi)
{
hat_kdi_fini();
}
void
plat_kdi_init(kdi_t *kdi)
{
kdi->pkdi_system_claim = kdi_system_claim;
kdi->pkdi_system_release = kdi_system_release;
}
|