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
|
/* $OpenBSD: db_interface.c,v 1.4 1996/04/18 19:18:06 niklas Exp $ */
/* $NetBSD: db_interface.c,v 1.20 1996/03/15 00:07:18 chuck Exp $ */
/*
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*
* db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU)
*/
/*
* Interface to new debugger.
*/
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/systm.h> /* just for boothowto --eichin */
#include <vm/vm.h>
#include <machine/db_machdep.h>
extern label_t *db_recover;
int db_active = 0;
/*
* kdb_trap - field a TRACE or BPT trap
*/
kdb_trap(type, code, regs)
int type, code;
register db_regs_t *regs;
{
int s;
#if 0
if ((boothowto&RB_KDB) == 0)
return(0);
#endif
switch (type) {
case T_BPTFLT: /* breakpoint */
case T_TRCTRAP: /* single_step */
case -1: /* keyboard interrupt */
break;
default:
kdbprinttrap(type, code);
if (db_recover != 0) {
db_error("Faulted in DDB; continuing...\n");
/*NOTREACHED*/
}
}
/* XXX Should switch to kdb`s own stack here. */
ddb_regs = *regs;
if (KERNELMODE(regs->tf_cs, regs->tf_eflags)) {
/*
* Kernel mode - esp and ss not saved
*/
ddb_regs.tf_esp = (int)®s->tf_esp; /* kernel stack pointer */
asm("movw %%ss,%w0" : "=r" (ddb_regs.tf_ss));
}
s = splhigh();
db_active++;
cnpollc(TRUE);
db_trap(type, code);
cnpollc(FALSE);
db_active--;
splx(s);
regs->tf_es = ddb_regs.tf_es;
regs->tf_ds = ddb_regs.tf_ds;
regs->tf_edi = ddb_regs.tf_edi;
regs->tf_esi = ddb_regs.tf_esi;
regs->tf_ebp = ddb_regs.tf_ebp;
regs->tf_ebx = ddb_regs.tf_ebx;
regs->tf_edx = ddb_regs.tf_edx;
regs->tf_ecx = ddb_regs.tf_ecx;
regs->tf_eax = ddb_regs.tf_eax;
regs->tf_eip = ddb_regs.tf_eip;
regs->tf_cs = ddb_regs.tf_cs;
regs->tf_eflags = ddb_regs.tf_eflags;
if (!KERNELMODE(regs->tf_cs, regs->tf_eflags)) {
/* ring transit - saved esp and ss valid */
regs->tf_esp = ddb_regs.tf_esp;
regs->tf_ss = ddb_regs.tf_ss;
}
return (1);
}
extern char *trap_type[];
extern int trap_types;
/*
* Print trap reason.
*/
kdbprinttrap(type, code)
int type, code;
{
db_printf("kernel: ");
if (type >= trap_types || type < 0)
db_printf("type %d", type);
else
db_printf("%s", trap_type[type]);
db_printf(" trap, code=%x\n", code);
}
/*
* Read bytes from kernel address space for debugger.
*/
void
db_read_bytes(addr, size, data)
vm_offset_t addr;
register int size;
register char *data;
{
register char *src;
src = (char *)addr;
while (--size >= 0)
*data++ = *src++;
}
pt_entry_t *pmap_pte __P((pmap_t, vm_offset_t));
/*
* Write bytes to kernel address space for debugger.
*/
void
db_write_bytes(addr, size, data)
vm_offset_t addr;
register int size;
register char *data;
{
register char *dst;
register pt_entry_t *ptep0 = 0;
pt_entry_t oldmap0 = { 0 };
vm_offset_t addr1;
register pt_entry_t *ptep1 = 0;
pt_entry_t oldmap1 = { 0 };
extern char etext;
if (addr >= VM_MIN_KERNEL_ADDRESS &&
addr < (vm_offset_t)&etext) {
ptep0 = pmap_pte(pmap_kernel(), addr);
oldmap0 = *ptep0;
*(int *)ptep0 |= /* INTEL_PTE_WRITE */ PG_RW;
addr1 = i386_trunc_page(addr + size - 1);
if (i386_trunc_page(addr) != addr1) {
/* data crosses a page boundary */
ptep1 = pmap_pte(pmap_kernel(), addr1);
oldmap1 = *ptep1;
*(int *)ptep1 |= /* INTEL_PTE_WRITE */ PG_RW;
}
pmap_update();
}
dst = (char *)addr;
while (--size >= 0)
*dst++ = *data++;
if (ptep0) {
*ptep0 = oldmap0;
if (ptep1)
*ptep1 = oldmap1;
pmap_update();
}
}
void
Debugger()
{
asm("int $3");
}
|