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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
|
/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* The DPI, or debugger/PROM interface, is used to isolate the debugger from the
* means by which we use the PROM to control the machine.
*/
#include <sys/types.h>
#include <setjmp.h>
#include <kmdb/kmdb_dpi_impl.h>
#include <kmdb/kmdb_kdi.h>
#include <kmdb/kmdb_auxv.h>
#include <kmdb/kmdb_wr_impl.h>
#include <kmdb/kmdb_module.h>
#include <kmdb/kmdb_start.h>
#include <kmdb/kmdb_asmutil.h>
#include <mdb/mdb_debug.h>
#include <mdb/mdb_err.h>
#include <mdb/mdb_string.h>
#include <mdb/mdb.h>
jmp_buf *kmdb_dpi_fault_pcb;
jmp_buf kmdb_dpi_resume_pcb;
jmp_buf kmdb_dpi_entry_pcb;
static int kmdb_dpi_state;
static int kmdb_dpi_state_why;
uint_t kmdb_dpi_resume_requested;
uint_t kmdb_dpi_switch_target = (uint_t)-1;
/* Used by the style-specific resume interfaces to signal the driver */
void (*kmdb_dpi_wrintr_fire)(void);
int
kmdb_dpi_init(kmdb_auxv_t *kav)
{
kmdb_dpi_state = DPI_STATE_INIT;
kmdb_dpi_resume_requested = 0;
kmdb_dpi_wrintr_fire = kav->kav_wrintr_fire;
mdb.m_dpi = &kmdb_dpi_ops;
return (mdb.m_dpi->dpo_init(kav));
}
/*ARGSUSED1*/
void
kmdb_activate(kdi_debugvec_t **dvecp, uint_t flags)
{
mdb.m_dpi->dpo_debugger_activate(dvecp, flags);
}
void
kmdb_deactivate(void)
{
mdb.m_dpi->dpo_debugger_deactivate();
}
int
kmdb_dpi_reenter(void)
{
int cmd;
kmdb_kdi_system_claim();
if ((cmd = setjmp(kmdb_dpi_entry_pcb)) == 0) {
/* Direct entry from the driver */
if (kmdb_dpi_resume_requested)
longjmp(kmdb_dpi_resume_pcb, 1);
kmdb_first_start();
fail("kmdb_first_start returned");
/*NOTREACHED*/
}
mdb_dprintf(MDB_DBG_DPI, "returning to driver - cmd %d%s\n", cmd,
(kmdb_dpi_work_required() ? " (work required)" : ""));
kmdb_kdi_system_release();
membar_producer();
/*
* The debugger wants us to do something - it returned a command
* via the setjmp(). The driver will know what to do with the
* command.
*/
return (cmd);
}
void
kmdb_dpi_enter_mon(void)
{
mdb.m_dpi->dpo_enter_mon();
}
void
kmdb_dpi_modchg_register(void (*func)(struct modctl *, int))
{
mdb.m_dpi->dpo_modchg_register(func);
}
void
kmdb_dpi_modchg_cancel(void)
{
mdb.m_dpi->dpo_modchg_cancel();
}
int
kmdb_dpi_get_cpu_state(int cpuid)
{
return (mdb.m_dpi->dpo_get_cpu_state(cpuid));
}
int
kmdb_dpi_get_master_cpuid(void)
{
return (mdb.m_dpi->dpo_get_master_cpuid());
}
const mdb_tgt_gregset_t *
kmdb_dpi_get_gregs(int cpuid)
{
return (mdb.m_dpi->dpo_get_gregs(cpuid));
}
jmp_buf *
kmdb_dpi_set_fault_hdlr(jmp_buf *jb)
{
jmp_buf *oldpcb = kmdb_dpi_fault_pcb;
kmdb_dpi_fault_pcb = jb;
return (oldpcb);
}
void
kmdb_dpi_restore_fault_hdlr(jmp_buf *jb)
{
(void) kmdb_dpi_set_fault_hdlr(jb);
}
/*
* Used to tell the driver that it needs to do work after the resume.
*
* CAUTION: This routine may be called *after* mdb_destroy
*/
int
kmdb_dpi_work_required(void)
{
return (kmdb_kdi_get_unload_request() ||
!kmdb_wr_driver_notify_isempty());
}
void
kmdb_dpi_resume_master(void)
{
kmdb_dpi_resume_common(KMDB_DPI_CMD_RESUME_MASTER);
}
void
kmdb_dpi_resume(void)
{
kmdb_dpi_resume_common(KMDB_DPI_CMD_RESUME_ALL);
}
void
kmdb_dpi_resume_unload(void)
{
kmdb_dpi_resume_common(KMDB_DPI_CMD_RESUME_UNLOAD);
}
int
kmdb_dpi_switch_master(int tgt_cpuid)
{
if (kmdb_dpi_get_cpu_state(tgt_cpuid) < 0)
return (-1); /* errno is set for us */
kmdb_dpi_switch_target = tgt_cpuid;
kmdb_dpi_resume_common(KMDB_DPI_CMD_SWITCH_CPU);
return (0);
}
void
kmdb_dpi_flush_slave_caches(void)
{
kmdb_dpi_resume_common(KMDB_DPI_CMD_FLUSH_CACHES);
}
typedef struct work_results {
mdb_nv_t res_loads;
mdb_nv_t res_unloads;
} work_results_t;
static int
kmdb_dbgnotify_cb(kmdb_wr_t *wn, void *arg)
{
work_results_t *res = arg;
switch (WR_TASK(wn)) {
case WNTASK_DMOD_LOAD: {
/*
* If this is an ack, the driver finished processing a load we
* requested. We process it and free the message. If this
* isn't an ack, then it's a driver-initiated load. We process
* the message, and send it back as an ack so the driver can
* free it.
*/
kmdb_wr_load_t *dlr = (kmdb_wr_load_t *)wn;
mdb_dprintf(MDB_DBG_DPI, "received module load message\n");
if (kmdb_module_loaded(dlr) && res != NULL) {
(void) mdb_nv_insert(&res->res_loads,
strbasename(dlr->dlr_fname), NULL, 0, 0);
}
if (WR_ISACK(dlr)) {
kmdb_module_load_ack(dlr);
return (0);
}
/* Send it back as an ack */
mdb_dprintf(MDB_DBG_DPI, "Sending load request for %s back "
"as an ack\n", dlr->dlr_fname);
WR_ACK(wn);
kmdb_wr_driver_notify(wn);
return (0);
}
case WNTASK_DMOD_LOAD_ALL:
/*
* We initiated the load-all, so this must be an ack. The
* individual module load messages will arrive separately -
* there's no need to do anything further with this message.
*/
ASSERT(WR_ISACK(wn));
mdb_dprintf(MDB_DBG_DPI, "received module load all ack\n");
kmdb_module_load_all_ack(wn);
return (0);
case WNTASK_DMOD_UNLOAD: {
/*
* The debugger received an unload message. The driver isn't
* supposed to initiate unloads, so we shouldn't see anything
* but acks. We tell the dmod subsystem that the module has
* been unloaded, and we free the message.
*/
kmdb_wr_unload_t *dur = (kmdb_wr_unload_t *)wn;
ASSERT(WR_ISACK(dur));
mdb_dprintf(MDB_DBG_DPI, "received module unload ack\n");
if (kmdb_module_unloaded(dur) && res != NULL) {
(void) mdb_nv_insert(&res->res_unloads,
dur->dur_modname, NULL, 0, 0);
}
/* Done with message */
kmdb_module_unload_ack(dur);
return (0);
}
case WNTASK_DMOD_PATH_CHANGE: {
/*
* The debugger received a path change message. The driver
* can't initiate these, so it must be an acknowledgement.
* There's no processing to be done, so just free the message.
*/
kmdb_wr_path_t *dpth = (kmdb_wr_path_t *)wn;
ASSERT(WR_ISACK(dpth));
mdb_dprintf(MDB_DBG_DPI, "received path change ack\n");
kmdb_module_path_ack(dpth);
return (0);
}
default:
mdb_warn("Received unknown message type %d from driver\n",
wn->wn_task);
/* Ignore it */
return (0);
}
}
static void
print_modules(mdb_nv_t *mods)
{
mdb_var_t *v;
mdb_nv_rewind(mods);
while ((v = mdb_nv_advance(mods)) != NULL)
mdb_printf(" %s", mdb_nv_get_name(v));
}
void
kmdb_dpi_process_work_queue(void)
{
work_results_t res;
(void) mdb_nv_create(&res.res_loads, UM_SLEEP);
(void) mdb_nv_create(&res.res_unloads, UM_SLEEP);
mdb_dprintf(MDB_DBG_DPI, "processing work queue\n");
(void) kmdb_wr_debugger_process(kmdb_dbgnotify_cb, &res);
if (mdb_nv_size(&res.res_loads)) {
mdb_printf("Loaded modules: [");
print_modules(&res.res_loads);
mdb_printf(" ]\n");
}
if (mdb_nv_size(&res.res_unloads)) {
mdb_printf("Unloaded modules: [");
print_modules(&res.res_unloads);
mdb_printf(" ]\n");
}
mdb_nv_destroy(&res.res_loads);
mdb_nv_destroy(&res.res_unloads);
}
int
kmdb_dpi_step(void)
{
return (mdb.m_dpi->dpo_step());
}
uintptr_t
kmdb_dpi_call(uintptr_t func, uint_t argc, const uintptr_t *argv)
{
return (mdb.m_dpi->dpo_call(func, argc, argv));
}
int
kmdb_dpi_brkpt_arm(uintptr_t addr, mdb_instr_t *instrp)
{
int rc;
if ((rc = mdb.m_dpi->dpo_brkpt_arm(addr, instrp)) < 0)
mdb_warn("failed to arm breakpoint at %a", addr);
mdb_dprintf(MDB_DBG_DPI, "brkpt armed at %p %A\n", (void *)addr, addr);
return (rc);
}
int
kmdb_dpi_brkpt_disarm(uintptr_t addr, mdb_instr_t instrp)
{
int rc;
if ((rc = mdb.m_dpi->dpo_brkpt_disarm(addr, instrp)) < 0)
mdb_warn("failed to disarm breakpoint at %a", addr);
mdb_dprintf(MDB_DBG_DPI, "brkpt disarmed at %p %A\n", (void *)addr,
addr);
return (rc);
}
int
kmdb_dpi_wapt_validate(kmdb_wapt_t *wp)
{
if (mdb.m_dpi->dpo_wapt_validate(wp) < 0)
return (-1); /* errno is set for us */
return (0);
}
int
kmdb_dpi_wapt_reserve(kmdb_wapt_t *wp)
{
if (mdb.m_dpi->dpo_wapt_reserve(wp) < 0)
return (-1); /* errno is set for us */
mdb_dprintf(MDB_DBG_DPI, "wapt reserve type %d at %p, priv %p\n",
wp->wp_type, (void *)wp->wp_addr, wp->wp_priv);
return (0);
}
void
kmdb_dpi_wapt_release(kmdb_wapt_t *wp)
{
mdb.m_dpi->dpo_wapt_release(wp);
}
void
kmdb_dpi_wapt_arm(kmdb_wapt_t *wp)
{
mdb.m_dpi->dpo_wapt_arm(wp);
mdb_dprintf(MDB_DBG_DPI, "wapt armed at %p (type %d, priv %p)\n",
(void *)wp->wp_addr, wp->wp_type, wp->wp_priv);
}
void
kmdb_dpi_wapt_disarm(kmdb_wapt_t *wp)
{
mdb.m_dpi->dpo_wapt_disarm(wp);
mdb_dprintf(MDB_DBG_DPI, "wapt disarmed at %p (type %d, priv %p)\n",
(void *)wp->wp_addr, wp->wp_type, wp->wp_priv);
}
int
kmdb_dpi_wapt_match(kmdb_wapt_t *wp)
{
return (mdb.m_dpi->dpo_wapt_match(wp));
}
void
kmdb_dpi_set_state(int state, int why)
{
if (kmdb_dpi_state != DPI_STATE_LOST) {
mdb_dprintf(MDB_DBG_DPI, "dpi_set_state %d why %d\n",
state, why);
kmdb_dpi_state = state;
kmdb_dpi_state_why = why;
}
}
int
kmdb_dpi_get_state(int *whyp)
{
if (whyp != NULL)
*whyp = kmdb_dpi_state_why;
return (kmdb_dpi_state);
}
void
kmdb_dpi_dump_crumbs(uintptr_t addr, int cpuid)
{
mdb.m_dpi->dpo_dump_crumbs(addr, cpuid);
}
|