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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 2018 Joyent, Inc.
*/
/*
* Intel-specific portions of the DPI
*/
#include <sys/types.h>
#include <sys/trap.h>
#include <kmdb/kmdb_dpi_impl.h>
#include <kmdb/kmdb_fault.h>
#include <kmdb/kmdb_kdi.h>
#include <mdb/mdb_err.h>
#include <mdb/mdb_debug.h>
#include <mdb/mdb_kreg.h>
#include <mdb/mdb.h>
void
kmdb_dpi_handle_fault(kreg_t trapno, kreg_t pc, kreg_t sp, int cpuid)
{
kmdb_kdi_system_claim();
mdb_dprintf(MDB_DBG_DPI, "\ndpi_handle_fault: trapno %u, pc 0x%0?p, "
"sp 0x%0?p\n", (int)trapno, pc, sp);
switch (trapno) {
case T_GPFLT:
errno = EACCES;
break;
default:
errno = EMDB_NOMAP;
}
if (kmdb_dpi_fault_pcb != NULL) {
longjmp(*kmdb_dpi_fault_pcb, 1);
/*NOTREACHED*/
}
/* Debugger fault */
kmdb_fault(trapno, pc, sp, cpuid);
}
/*ARGSUSED*/
int
kmdb_dpi_get_register(const char *regname, kreg_t *kregp)
{
return (mdb.m_dpi->dpo_get_register(regname, kregp));
}
/*ARGSUSED*/
int
kmdb_dpi_set_register(const char *regname, kreg_t kreg)
{
return (mdb.m_dpi->dpo_set_register(regname, kreg));
}
/*
* Continue/resume handling. If the target calls kmdb_dpi_resume(), it
* expects that the world will be resumed, and that the call will return
* when the world has stopped again.
*
* For support, we have resume_return(), which is called from main() when
* the continuation has completed (when the world has stopped again).
* set_resume_exit() tells where to jump to actually restart the world.
*
* CAUTION: This routine may be called *after* mdb_destroy.
*/
void
kmdb_dpi_resume_common(int cmd)
{
kreg_t pc, trapno;
ASSERT(kmdb_dpi_resume_requested == 0);
if (setjmp(kmdb_dpi_resume_pcb) == 0) {
(void) kmdb_dpi_get_register("pc", &pc);
mdb_dprintf(MDB_DBG_PROC, "Resume requested, pc is %p\n",
(void *)pc);
if (cmd != KMDB_DPI_CMD_RESUME_UNLOAD)
kmdb_dpi_resume_requested = 1;
longjmp(kmdb_dpi_entry_pcb, cmd);
/*NOTREACHED*/
} else {
(void) kmdb_dpi_get_register("pc", &pc);
(void) kmdb_dpi_get_register("trapno", &trapno);
mdb_dprintf(MDB_DBG_PROC, "Back from resume, pc: %p, "
"trapno: %u\n", (void *)pc, (int)trapno);
kmdb_dpi_resume_requested = 0;
switch (trapno) {
case T_BPTFLT:
kmdb_dpi_set_state(DPI_STATE_FAULTED,
DPI_STATE_WHY_BKPT);
break;
case T_DBGENTR:
kmdb_dpi_set_state(DPI_STATE_STOPPED, 0);
break;
default:
kmdb_dpi_set_state(DPI_STATE_FAULTED,
DPI_STATE_WHY_TRAP);
break;
}
}
mdb_dprintf(MDB_DBG_PROC, "returning from resume\n");
}
void
kmdb_dpi_reboot(void)
{
/*
* We're going to skip all of the niceties we employ in resume_common,
* as we don't plan to ever return.
*/
longjmp(kmdb_dpi_entry_pcb, KMDB_DPI_CMD_REBOOT);
}
|