Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Mach Operating System | |
3 | * Copyright (c) 1991,1990 Carnegie Mellon University | |
4 | * All Rights Reserved. | |
5 | * | |
6 | * Permission to use, copy, modify and distribute this software and its | |
7 | * documentation is hereby granted, provided that both the copyright | |
8 | * notice and this permission notice appear in all copies of the | |
9 | * software, derivative works or modified versions, and any portions | |
10 | * thereof, and that both notices appear in supporting documentation. | |
11 | * | |
12 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS | |
13 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
14 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
15 | * | |
16 | * Carnegie Mellon requests users of this software to return to | |
17 | * | |
18 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
19 | * School of Computer Science | |
20 | * Carnegie Mellon University | |
21 | * Pittsburgh PA 15213-3890 | |
22 | * | |
23 | * any improvements or extensions that they make and grant Carnegie the | |
24 | * rights to redistribute these changes. | |
25 | */ | |
26 | /* | |
27 | * HISTORY | |
28 | * $Log: db_interface.c,v $ | |
29 | * Revision 1.1 1992/03/25 21:42:03 pace | |
30 | * Initial revision | |
31 | * | |
32 | * Revision 2.4 91/02/05 17:11:13 mrt | |
33 | * Changed to new Mach copyright | |
34 | * [91/02/01 17:31:17 mrt] | |
35 | * | |
36 | * Revision 2.3 90/12/04 14:45:55 jsb | |
37 | * Changes for merged intel/pmap.{c,h}. | |
38 | * [90/12/04 11:14:41 jsb] | |
39 | * | |
40 | * Revision 2.2 90/10/25 14:44:43 rwd | |
41 | * Added watchpoint support. | |
42 | * [90/10/18 rpd] | |
43 | * | |
44 | * Created. | |
45 | * [90/07/25 dbg] | |
46 | * | |
47 | * | |
48 | */ | |
49 | ||
50 | /* | |
51 | * Interface to new debugger. | |
52 | */ | |
53 | #include "param.h" | |
54 | #include "proc.h" | |
55 | #include <machine/db_machdep.h> | |
56 | ||
57 | #include <sys/reboot.h> | |
58 | #include <vm/vm_statistics.h> | |
59 | #include <vm/pmap.h> | |
60 | ||
61 | #include <setjmp.h> | |
62 | #include <sys/systm.h> /* just for boothowto --eichin */ | |
63 | int db_active = 0; | |
64 | ||
65 | /* | |
66 | * Received keyboard interrupt sequence. | |
67 | */ | |
68 | kdb_kbd_trap(regs) | |
69 | struct i386_saved_state *regs; | |
70 | { | |
71 | if (db_active == 0 && (boothowto & RB_KDB)) { | |
72 | printf("\n\nkernel: keyboard interrupt\n"); | |
73 | kdb_trap(-1, 0, regs); | |
74 | } | |
75 | } | |
76 | ||
77 | /* | |
78 | * kdb_trap - field a TRACE or BPT trap | |
79 | */ | |
80 | ||
81 | static jmp_buf *db_nofault = 0; | |
82 | ||
83 | kdb_trap(type, code, regs) | |
84 | int type, code; | |
85 | register struct i386_saved_state *regs; | |
86 | { | |
87 | #if 0 | |
88 | if ((boothowto&RB_KDB) == 0) | |
89 | return(0); | |
90 | #endif | |
91 | ||
92 | switch (type) { | |
93 | case T_BPTFLT /* T_INT3 */: /* breakpoint */ | |
94 | case T_KDBTRAP /* T_WATCHPOINT */: /* watchpoint */ | |
95 | case T_PRIVINFLT /* T_DEBUG */: /* single_step */ | |
96 | ||
97 | case -1: /* keyboard interrupt */ | |
98 | break; | |
99 | ||
100 | default: | |
101 | kdbprinttrap(type, code); | |
102 | ||
103 | if (db_nofault) { | |
104 | jmp_buf *no_fault = db_nofault; | |
105 | db_nofault = 0; | |
106 | longjmp(*no_fault, 1); | |
107 | } | |
108 | } | |
109 | ||
110 | /* Should switch to kdb`s own stack here. */ | |
111 | ||
112 | ddb_regs = *regs; | |
113 | ||
114 | if ((regs->tf_cs & 0x3) == 0) { | |
115 | /* | |
116 | * Kernel mode - esp and ss not saved | |
117 | */ | |
118 | ddb_regs.tf_esp = (int)®s->tf_esp; /* kernel stack pointer */ | |
119 | #if 0 | |
120 | ddb_regs.ss = KERNEL_DS; | |
121 | #endif | |
122 | asm(" movw %%ss,%%ax; movl %%eax,%0 " | |
123 | : "=g" (ddb_regs.tf_ss) | |
124 | : | |
125 | : "ax"); | |
126 | } | |
127 | ||
128 | db_active++; | |
129 | cnpollc(TRUE); | |
130 | db_trap(type, code); | |
131 | cnpollc(FALSE); | |
132 | db_active--; | |
133 | ||
134 | regs->tf_eip = ddb_regs.tf_eip; | |
135 | regs->tf_eflags = ddb_regs.tf_eflags; | |
136 | regs->tf_eax = ddb_regs.tf_eax; | |
137 | regs->tf_ecx = ddb_regs.tf_ecx; | |
138 | regs->tf_edx = ddb_regs.tf_edx; | |
139 | regs->tf_ebx = ddb_regs.tf_ebx; | |
140 | if (regs->tf_cs & 0x3) { | |
141 | /* | |
142 | * user mode - saved esp and ss valid | |
143 | */ | |
144 | regs->tf_esp = ddb_regs.tf_esp; /* user stack pointer */ | |
145 | regs->tf_ss = ddb_regs.tf_ss & 0xffff; /* user stack segment */ | |
146 | } | |
147 | regs->tf_ebp = ddb_regs.tf_ebp; | |
148 | regs->tf_esi = ddb_regs.tf_esi; | |
149 | regs->tf_edi = ddb_regs.tf_edi; | |
150 | regs->tf_es = ddb_regs.tf_es & 0xffff; | |
151 | regs->tf_cs = ddb_regs.tf_cs & 0xffff; | |
152 | regs->tf_ds = ddb_regs.tf_ds & 0xffff; | |
153 | #if 0 | |
154 | regs->tf_fs = ddb_regs.tf_fs & 0xffff; | |
155 | regs->tf_gs = ddb_regs.tf_gs & 0xffff; | |
156 | #endif | |
157 | ||
158 | return (1); | |
159 | } | |
160 | ||
161 | /* | |
162 | * Print trap reason. | |
163 | */ | |
164 | kdbprinttrap(type, code) | |
165 | int type, code; | |
166 | { | |
167 | printf("kernel: "); | |
168 | printf("type %d", type); | |
169 | printf(" trap, code=%x\n", code); | |
170 | } | |
171 | ||
172 | /* | |
173 | * Read bytes from kernel address space for debugger. | |
174 | */ | |
175 | ||
176 | extern jmp_buf db_jmpbuf; | |
177 | ||
178 | void | |
179 | db_read_bytes(addr, size, data) | |
180 | vm_offset_t addr; | |
181 | register int size; | |
182 | register char *data; | |
183 | { | |
184 | register char *src; | |
185 | ||
186 | db_nofault = &db_jmpbuf; | |
187 | ||
188 | src = (char *)addr; | |
189 | while (--size >= 0) | |
190 | *data++ = *src++; | |
191 | ||
192 | db_nofault = 0; | |
193 | } | |
194 | ||
195 | struct pte *pmap_pte(pmap_t, vm_offset_t); | |
196 | ||
197 | /* | |
198 | * Write bytes to kernel address space for debugger. | |
199 | */ | |
200 | void | |
201 | db_write_bytes(addr, size, data) | |
202 | vm_offset_t addr; | |
203 | register int size; | |
204 | register char *data; | |
205 | { | |
206 | register char *dst; | |
207 | ||
208 | register pt_entry_t *ptep0 = 0; | |
209 | pt_entry_t oldmap0 = { 0 }; | |
210 | vm_offset_t addr1; | |
211 | register pt_entry_t *ptep1 = 0; | |
212 | pt_entry_t oldmap1 = { 0 }; | |
213 | extern char etext; | |
214 | ||
215 | db_nofault = &db_jmpbuf; | |
216 | ||
217 | if (addr >= VM_MIN_KERNEL_ADDRESS && | |
218 | addr <= (vm_offset_t)&etext) | |
219 | { | |
220 | ptep0 = pmap_pte(kernel_pmap, addr); | |
221 | oldmap0 = *ptep0; | |
222 | *(int *)ptep0 |= /* INTEL_PTE_WRITE */ PG_RW; | |
223 | ||
224 | addr1 = i386_trunc_page(addr + size - 1); | |
225 | if (i386_trunc_page(addr) != addr1) { | |
226 | /* data crosses a page boundary */ | |
227 | ||
228 | ptep1 = pmap_pte(kernel_pmap, addr1); | |
229 | oldmap1 = *ptep1; | |
230 | *(int *)ptep1 |= /* INTEL_PTE_WRITE */ PG_RW; | |
231 | } | |
232 | tlbflush(); | |
233 | } | |
234 | ||
235 | dst = (char *)addr; | |
236 | ||
237 | while (--size >= 0) | |
238 | *dst++ = *data++; | |
239 | ||
240 | db_nofault = 0; | |
241 | ||
242 | if (ptep0) { | |
243 | *ptep0 = oldmap0; | |
244 | if (ptep1) { | |
245 | *ptep1 = oldmap1; | |
246 | } | |
247 | tlbflush(); | |
248 | } | |
249 | } | |
250 | ||
251 | Debugger (msg) | |
252 | char *msg; | |
253 | { | |
254 | asm ("int $3"); | |
255 | } |