Tue Aug 15 06:57:53 2017 UTC ()
Reduce the diff between amd64 and i386.


(maxv)
diff -r1.25 -r1.26 src/sys/arch/amd64/amd64/db_interface.c
diff -r1.72 -r1.73 src/sys/arch/i386/i386/db_interface.c

cvs diff -r1.25 -r1.26 src/sys/arch/amd64/amd64/db_interface.c (expand / switch to unified diff)

--- src/sys/arch/amd64/amd64/db_interface.c 2017/05/23 08:54:38 1.25
+++ src/sys/arch/amd64/amd64/db_interface.c 2017/08/15 06:57:53 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: db_interface.c,v 1.25 2017/05/23 08:54:38 nonaka Exp $ */ 1/* $NetBSD: db_interface.c,v 1.26 2017/08/15 06:57:53 maxv Exp $ */
2 2
3/* 3/*
4 * Mach Operating System 4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University 5 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Permission to use, copy, modify and distribute this software and its 8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright 9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the 10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions 11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation. 12 * thereof, and that both notices appear in supporting documentation.
13 * 13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * Pittsburgh PA 15213-3890 23 * Pittsburgh PA 15213-3890
24 * 24 *
25 * any improvements or extensions that they make and grant Carnegie the 25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes. 26 * rights to redistribute these changes.
27 * 27 *
28 * db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU) 28 * db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU)
29 */ 29 */
30 30
31/* 31/*
32 * Interface to new debugger. 32 * Interface to new debugger.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.25 2017/05/23 08:54:38 nonaka Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.26 2017/08/15 06:57:53 maxv Exp $");
37 37
38#include "opt_ddb.h" 38#include "opt_ddb.h"
39#include "opt_multiprocessor.h" 39#include "opt_multiprocessor.h"
40 40
41#include "lapic.h" 41#include "lapic.h"
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/proc.h> 44#include <sys/proc.h>
45#include <sys/reboot.h> 45#include <sys/reboot.h>
46#include <sys/systm.h> 46#include <sys/systm.h>
47#include <sys/atomic.h> 47#include <sys/atomic.h>
48#include <sys/cpu.h> 48#include <sys/cpu.h>
49 49
@@ -56,38 +56,38 @@ __KERNEL_RCSID(0, "$NetBSD: db_interface @@ -56,38 +56,38 @@ __KERNEL_RCSID(0, "$NetBSD: db_interface
56#include <machine/i82489reg.h> 56#include <machine/i82489reg.h>
57#include <machine/i82489var.h> 57#include <machine/i82489var.h>
58 58
59#include <ddb/db_sym.h> 59#include <ddb/db_sym.h>
60#include <ddb/db_command.h> 60#include <ddb/db_command.h>
61#include <ddb/db_extern.h> 61#include <ddb/db_extern.h>
62#include <ddb/db_access.h> 62#include <ddb/db_access.h>
63#include <ddb/db_output.h> 63#include <ddb/db_output.h>
64#include <ddb/ddbvar.h> 64#include <ddb/ddbvar.h>
65 65
66extern const char *const trap_type[]; 66extern const char *const trap_type[];
67extern int trap_types; 67extern int trap_types;
68 68
69int db_active; 69int db_active = 0;
70db_regs_t ddb_regs; /* register state */ 70db_regs_t ddb_regs; /* register state */
71db_regs_t *ddb_regp; 71db_regs_t *ddb_regp = NULL;
72 72
73void db_mach_cpu (db_expr_t, bool, db_expr_t, const char *); 73void db_mach_cpu (db_expr_t, bool, db_expr_t, const char *);
74 74
75const struct db_command db_machine_command_table[] = { 75const struct db_command db_machine_command_table[] = {
76#ifdef MULTIPROCESSOR 76#ifdef MULTIPROCESSOR
77 { DDB_ADD_CMD("cpu", db_mach_cpu, 0, 77 { DDB_ADD_CMD("cpu", db_mach_cpu, 0,
78 "switch to another cpu", "cpu-no", NULL) }, 78 "switch to another cpu", "cpu-no", NULL) },
79#endif 79#endif
80 { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) }, 80 { DDB_ADD_CMD(NULL, NULL, 0, NULL, NULL, NULL) },
81}; 81};
82 82
83void kdbprinttrap(int, int); 83void kdbprinttrap(int, int);
84#ifdef MULTIPROCESSOR 84#ifdef MULTIPROCESSOR
85extern void ddb_ipi(struct trapframe); 85extern void ddb_ipi(struct trapframe);
86static void ddb_suspend(struct trapframe *); 86static void ddb_suspend(struct trapframe *);
87#ifndef XEN 87#ifndef XEN
88int ddb_vec; 88int ddb_vec;
89#endif /* XEN */ 89#endif /* XEN */
90static bool ddb_mp_online; 90static bool ddb_mp_online;
91#endif 91#endif
92 92
93#define NOCPU -1 93#define NOCPU -1
@@ -133,27 +133,26 @@ db_suspend_others(void) @@ -133,27 +133,26 @@ db_suspend_others(void)
133#endif /* XEN */ 133#endif /* XEN */
134 134
135 __cpu_simple_lock(&db_lock); 135 __cpu_simple_lock(&db_lock);
136 if (ddb_cpu == NOCPU) 136 if (ddb_cpu == NOCPU)
137 ddb_cpu = cpu_me; 137 ddb_cpu = cpu_me;
138 win = (ddb_cpu == cpu_me); 138 win = (ddb_cpu == cpu_me);
139 __cpu_simple_unlock(&db_lock); 139 __cpu_simple_unlock(&db_lock);
140 if (win) { 140 if (win) {
141#ifdef XEN 141#ifdef XEN
142 xen_broadcast_ipi(XEN_IPI_DDB); 142 xen_broadcast_ipi(XEN_IPI_DDB);
143#else 143#else
144 x86_ipi(ddb_vec, LAPIC_DEST_ALLEXCL, LAPIC_DLMODE_FIXED); 144 x86_ipi(ddb_vec, LAPIC_DEST_ALLEXCL, LAPIC_DLMODE_FIXED);
145#endif /* XEN */ 145#endif /* XEN */
146 
147 } 146 }
148 ddb_mp_online = x86_mp_online; 147 ddb_mp_online = x86_mp_online;
149 x86_mp_online = false; 148 x86_mp_online = false;
150 return win; 149 return win;
151} 150}
152 151
153static void 152static void
154db_resume_others(void) 153db_resume_others(void)
155{ 154{
156 CPU_INFO_ITERATOR cii; 155 CPU_INFO_ITERATOR cii;
157 struct cpu_info *ci; 156 struct cpu_info *ci;
158 157
159 x86_mp_online = ddb_mp_online; 158 x86_mp_online = ddb_mp_online;
@@ -191,27 +190,27 @@ kdb_trap(int type, int code, db_regs_t * @@ -191,27 +190,27 @@ kdb_trap(int type, int code, db_regs_t *
191{ 190{
192 int s; 191 int s;
193 db_regs_t dbreg; 192 db_regs_t dbreg;
194 193
195 switch (type) { 194 switch (type) {
196 case T_NMI: /* NMI */ 195 case T_NMI: /* NMI */
197 printf("NMI ... going to debugger\n"); 196 printf("NMI ... going to debugger\n");
198 /*FALLTHROUGH*/ 197 /*FALLTHROUGH*/
199 case T_BPTFLT: /* breakpoint */ 198 case T_BPTFLT: /* breakpoint */
200 case T_TRCTRAP: /* single_step */ 199 case T_TRCTRAP: /* single_step */
201 case -1: /* keyboard interrupt */ 200 case -1: /* keyboard interrupt */
202 break; 201 break;
203 default: 202 default:
204 if (!db_onpanic && db_recover==0) 203 if (!db_onpanic && db_recover == 0)
205 return (0); 204 return (0);
206 205
207 kdbprinttrap(type, code); 206 kdbprinttrap(type, code);
208 if (db_recover != 0) { 207 if (db_recover != 0) {
209 db_error("Faulted in DDB; continuing...\n"); 208 db_error("Faulted in DDB; continuing...\n");
210 /*NOTREACHED*/ 209 /*NOTREACHED*/
211 } 210 }
212 } 211 }
213 212
214#ifdef MULTIPROCESSOR 213#ifdef MULTIPROCESSOR
215 if (!db_suspend_others()) { 214 if (!db_suspend_others()) {
216 ddb_suspend(regs); 215 ddb_suspend(regs);
217 } else { 216 } else {
@@ -225,30 +224,30 @@ kdb_trap(int type, int code, db_regs_t * @@ -225,30 +224,30 @@ kdb_trap(int type, int code, db_regs_t *
225 ddb_regs.tf_ds &= 0xffff; 224 ddb_regs.tf_ds &= 0xffff;
226 ddb_regs.tf_es &= 0xffff; 225 ddb_regs.tf_es &= 0xffff;
227 ddb_regs.tf_fs &= 0xffff; 226 ddb_regs.tf_fs &= 0xffff;
228 ddb_regs.tf_gs &= 0xffff; 227 ddb_regs.tf_gs &= 0xffff;
229 ddb_regs.tf_ss &= 0xffff; 228 ddb_regs.tf_ss &= 0xffff;
230 229
231 s = splhigh(); 230 s = splhigh();
232 db_active++; 231 db_active++;
233 cnpollc(true); 232 cnpollc(true);
234 db_trap(type, code); 233 db_trap(type, code);
235 cnpollc(false); 234 cnpollc(false);
236 db_active--; 235 db_active--;
237 splx(s); 236 splx(s);
238#ifdef MULTIPROCESSOR  237#ifdef MULTIPROCESSOR
239 db_resume_others(); 238 db_resume_others();
240 } 239 }
241#endif  240#endif
242 ddb_regp = &dbreg; 241 ddb_regp = &dbreg;
243 242
244 *regs = ddb_regs; 243 *regs = ddb_regs;
245 244
246 return (1); 245 return (1);
247} 246}
248 247
249void 248void
250cpu_Debugger(void) 249cpu_Debugger(void)
251{ 250{
252 breakpoint(); 251 breakpoint();
253} 252}
254 253

cvs diff -r1.72 -r1.73 src/sys/arch/i386/i386/db_interface.c (expand / switch to unified diff)

--- src/sys/arch/i386/i386/db_interface.c 2017/05/23 08:54:38 1.72
+++ src/sys/arch/i386/i386/db_interface.c 2017/08/15 06:57:53 1.73
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: db_interface.c,v 1.72 2017/05/23 08:54:38 nonaka Exp $ */ 1/* $NetBSD: db_interface.c,v 1.73 2017/08/15 06:57:53 maxv Exp $ */
2 2
3/* 3/*
4 * Mach Operating System 4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University 5 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Permission to use, copy, modify and distribute this software and its 8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright 9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the 10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions 11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation. 12 * thereof, and that both notices appear in supporting documentation.
13 * 13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
@@ -23,94 +23,90 @@ @@ -23,94 +23,90 @@
23 * Pittsburgh PA 15213-3890 23 * Pittsburgh PA 15213-3890
24 * 24 *
25 * any improvements or extensions that they make and grant Carnegie the 25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes. 26 * rights to redistribute these changes.
27 * 27 *
28 * db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU) 28 * db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU)
29 */ 29 */
30 30
31/* 31/*
32 * Interface to new debugger. 32 * Interface to new debugger.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.72 2017/05/23 08:54:38 nonaka Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.73 2017/08/15 06:57:53 maxv Exp $");
37 37
38#include "opt_ddb.h" 38#include "opt_ddb.h"
39#include "opt_multiprocessor.h" 39#include "opt_multiprocessor.h"
40 40
41#include "ioapic.h" 41#include "ioapic.h"
42#include "lapic.h" 42#include "lapic.h"
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/proc.h> 45#include <sys/proc.h>
46#include <sys/reboot.h> 46#include <sys/reboot.h>
47#include <sys/systm.h> 47#include <sys/systm.h>
48#include <sys/atomic.h> 48#include <sys/atomic.h>
49#include <sys/cpu.h> 49#include <sys/cpu.h>
50 50
51#include <uvm/uvm_extern.h> 
52 
53#include <dev/cons.h> 51#include <dev/cons.h>
54 52
55#include <machine/cpufunc.h> 53#include <machine/cpufunc.h>
56#include <machine/db_machdep.h> 54#include <machine/db_machdep.h>
57#include <machine/cpuvar.h> 55#include <machine/cpuvar.h>
58#if NIOAPIC > 0 56#if NIOAPIC > 0
59#include <machine/i82093var.h> 57#include <machine/i82093var.h>
60#endif 58#endif
61#if NLAPIC > 0 59#if NLAPIC > 0
62#include <machine/i82489reg.h> 60#include <machine/i82489reg.h>
63#include <machine/i82489var.h> 61#include <machine/i82489var.h>
64#endif 62#endif
65 63
66#include <ddb/db_sym.h> 64#include <ddb/db_sym.h>
67#include <ddb/db_command.h> 65#include <ddb/db_command.h>
68#include <ddb/db_extern.h> 66#include <ddb/db_extern.h>
69#include <ddb/db_access.h> 67#include <ddb/db_access.h>
70#include <ddb/db_output.h> 68#include <ddb/db_output.h>
71#include <ddb/ddbvar.h> 69#include <ddb/ddbvar.h>
72 70
73extern const char *const trap_type[]; 71extern const char *const trap_type[];
74extern int trap_types; 72extern int trap_types;
75 73
76int db_active = 0; 74int db_active = 0;
77db_regs_t ddb_regs; /* register state */ 75db_regs_t ddb_regs; /* register state */
 76db_regs_t *ddb_regp = NULL;
78 77
79void db_mach_cpu (db_expr_t, bool, db_expr_t, const char *); 78void db_mach_cpu (db_expr_t, bool, db_expr_t, const char *);
80 79
81const struct db_command db_machine_command_table[] = { 80const struct db_command db_machine_command_table[] = {
82#ifdef MULTIPROCESSOR 81#ifdef MULTIPROCESSOR
83 { DDB_ADD_CMD("cpu", db_mach_cpu, 0, 82 { DDB_ADD_CMD("cpu", db_mach_cpu, 0,
84 "switch to another cpu", "cpu-no", NULL) }, 83 "switch to another cpu", "cpu-no", NULL) },
85#endif 84#endif
86  85 { DDB_ADD_CMD(NULL, NULL, 0, NULL, NULL, NULL) },
87 { DDB_ADD_CMD(NULL, NULL, 0, NULL,NULL,NULL) }, 
88}; 86};
89 87
90void kdbprinttrap(int, int); 88void kdbprinttrap(int, int);
91#ifdef MULTIPROCESSOR 89#ifdef MULTIPROCESSOR
92extern void ddb_ipi(int, struct trapframe); 90extern void ddb_ipi(int, struct trapframe);
93extern void ddb_ipi_tss(struct i386tss *); 91extern void ddb_ipi_tss(struct i386tss *);
94static void ddb_suspend(struct trapframe *); 92static void ddb_suspend(struct trapframe *);
95#ifndef XEN 93#ifndef XEN
96int ddb_vec; 94int ddb_vec;
97#endif /* XEN */ 95#endif /* XEN */
98static bool ddb_mp_online; 96static bool ddb_mp_online;
99#endif 97#endif
100 98
101db_regs_t *ddb_regp = 0; 99#define NOCPU -1
102 
103#define NOCPU -1 
104 100
105int ddb_cpu = NOCPU; 101int ddb_cpu = NOCPU;
106 102
107typedef void (vector)(void); 103typedef void (vector)(void);
108extern vector Xintrddbipi, Xx2apic_intrddbipi; 104extern vector Xintrddbipi, Xx2apic_intrddbipi;
109 105
110void 106void
111db_machine_init(void) 107db_machine_init(void)
112{ 108{
113 109
114#ifdef MULTIPROCESSOR 110#ifdef MULTIPROCESSOR
115#ifndef XEN 111#ifndef XEN
116 vector *handler = &Xintrddbipi; 112 vector *handler = &Xintrddbipi;
@@ -236,26 +232,27 @@ kdb_trap(int type, int code, db_regs_t * @@ -236,26 +232,27 @@ kdb_trap(int type, int code, db_regs_t *
236 /* 232 /*
237 * Kernel mode - esp and ss not saved 233 * Kernel mode - esp and ss not saved
238 */ 234 */
239 ddb_regs.tf_esp = (int)&regs->tf_esp; /* kernel stack pointer */ 235 ddb_regs.tf_esp = (int)&regs->tf_esp; /* kernel stack pointer */
240 ddb_regs.tf_ss = x86_getss(); 236 ddb_regs.tf_ss = x86_getss();
241 } 237 }
242 238
243 ddb_regs.tf_cs &= 0xffff; 239 ddb_regs.tf_cs &= 0xffff;
244 ddb_regs.tf_ds &= 0xffff; 240 ddb_regs.tf_ds &= 0xffff;
245 ddb_regs.tf_es &= 0xffff; 241 ddb_regs.tf_es &= 0xffff;
246 ddb_regs.tf_fs &= 0xffff; 242 ddb_regs.tf_fs &= 0xffff;
247 ddb_regs.tf_gs &= 0xffff; 243 ddb_regs.tf_gs &= 0xffff;
248 ddb_regs.tf_ss &= 0xffff; 244 ddb_regs.tf_ss &= 0xffff;
 245
249 s = splhigh(); 246 s = splhigh();
250 db_active++; 247 db_active++;
251 cnpollc(true); 248 cnpollc(true);
252 db_trap(type, code); 249 db_trap(type, code);
253 cnpollc(false); 250 cnpollc(false);
254 db_active--; 251 db_active--;
255 splx(s); 252 splx(s);
256#ifdef MULTIPROCESSOR 253#ifdef MULTIPROCESSOR
257 db_resume_others(); 254 db_resume_others();
258 } 255 }
259#endif 256#endif
260 ddb_regp = &dbreg; 257 ddb_regp = &dbreg;
261 258
@@ -346,41 +343,38 @@ ddb_suspend(struct trapframe *frame) @@ -346,41 +343,38 @@ ddb_suspend(struct trapframe *frame)
346 flags = regs.tf_err & TC_FLAGMASK; 343 flags = regs.tf_err & TC_FLAGMASK;
347 regs.tf_err &= ~TC_FLAGMASK; 344 regs.tf_err &= ~TC_FLAGMASK;
348 if (!(flags & TC_TSS) && KERNELMODE(regs.tf_cs, regs.tf_eflags)) { 345 if (!(flags & TC_TSS) && KERNELMODE(regs.tf_cs, regs.tf_eflags)) {
349 /* 346 /*
350 * Kernel mode - esp and ss not saved 347 * Kernel mode - esp and ss not saved
351 */ 348 */
352 regs.tf_esp = (int)&frame->tf_esp; /* kernel stack pointer */ 349 regs.tf_esp = (int)&frame->tf_esp; /* kernel stack pointer */
353 regs.tf_ss = x86_getss(); 350 regs.tf_ss = x86_getss();
354 } 351 }
355 352
356 ci->ci_ddb_regs = &regs; 353 ci->ci_ddb_regs = &regs;
357 354
358 atomic_or_32(&ci->ci_flags, CPUF_PAUSE); 355 atomic_or_32(&ci->ci_flags, CPUF_PAUSE);
 356
359 while (ci->ci_flags & CPUF_PAUSE) 357 while (ci->ci_flags & CPUF_PAUSE)
360 ; 358 ;
361 ci->ci_ddb_regs = 0; 359 ci->ci_ddb_regs = 0;
362 tlbflushg(); 360 tlbflushg();
363} 361}
364 362
365 363
366extern void cpu_debug_dump(void); /* XXX */ 364extern void cpu_debug_dump(void); /* XXX */
367 365
368void 366void
369db_mach_cpu( 367db_mach_cpu(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
370 db_expr_t addr, 
371 bool have_addr, 
372 db_expr_t count, 
373 const char * modif) 
374{ 368{
375 struct cpu_info *ci; 369 struct cpu_info *ci;
376 if (!have_addr) { 370 if (!have_addr) {
377 cpu_debug_dump(); 371 cpu_debug_dump();
378 return; 372 return;
379 } 373 }
380 374
381 if (addr < 0) { 375 if (addr < 0) {
382 db_printf("%ld: CPU out of range\n", addr); 376 db_printf("%ld: CPU out of range\n", addr);
383 return; 377 return;
384 } 378 }
385 ci = cpu_lookup(addr); 379 ci = cpu_lookup(addr);
386 if (ci == NULL) { 380 if (ci == NULL) {
@@ -391,15 +385,14 @@ db_mach_cpu( @@ -391,15 +385,14 @@ db_mach_cpu(
391 if (!(ci->ci_flags & CPUF_PAUSE)) { 385 if (!(ci->ci_flags & CPUF_PAUSE)) {
392 db_printf("CPU %ld not paused\n", addr); 386 db_printf("CPU %ld not paused\n", addr);
393 return; 387 return;
394 } 388 }
395 } 389 }
396 if (ci->ci_ddb_regs == 0) { 390 if (ci->ci_ddb_regs == 0) {
397 db_printf("CPU %ld has no saved regs\n", addr); 391 db_printf("CPU %ld has no saved regs\n", addr);
398 return; 392 return;
399 } 393 }
400 db_printf("using CPU %ld", addr); 394 db_printf("using CPU %ld", addr);
401 ddb_regp = ci->ci_ddb_regs; 395 ddb_regp = ci->ci_ddb_regs;
402} 396}
403 397
404 
405#endif 398#endif