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 #include <sys/cdefs.h>
28 /*
29 * Interface to new debugger.
30 */
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kdb.h>
35 #include <sys/pcpu.h>
36 #include <sys/proc.h>
37
38 #include <machine/psl.h>
39
40 #include <ddb/ddb.h>
41
42 /*
43 * Read bytes from kernel address space for debugger.
44 */
45 int
db_read_bytes(vm_offset_t addr,size_t size,char * data)46 db_read_bytes(vm_offset_t addr, size_t size, char *data)
47 {
48 jmp_buf jb;
49 void *prev_jb;
50 char *src;
51 int ret;
52
53 prev_jb = kdb_jmpbuf(jb);
54 ret = setjmp(jb);
55 if (ret == 0) {
56 src = (char *)addr;
57 while (size-- > 0)
58 *data++ = *src++;
59 }
60 (void)kdb_jmpbuf(prev_jb);
61 return (ret);
62 }
63
64 /*
65 * Write bytes to kernel address space for debugger.
66 */
67 int
db_write_bytes(vm_offset_t addr,size_t size,char * data)68 db_write_bytes(vm_offset_t addr, size_t size, char *data)
69 {
70 jmp_buf jb;
71 void *prev_jb;
72 char *dst;
73 int ret;
74
75 prev_jb = kdb_jmpbuf(jb);
76 ret = setjmp(jb);
77 if (ret == 0) {
78 dst = (char *)addr;
79 while (size-- > 0)
80 *dst++ = *data++;
81 }
82 (void)kdb_jmpbuf(prev_jb);
83 return (ret);
84 }
85
86 int
db_segsize(struct trapframe * tfp)87 db_segsize(struct trapframe *tfp)
88 {
89 struct proc_ldt *plp;
90 struct segment_descriptor *sdp;
91 int sel;
92
93 if (tfp == NULL)
94 return (32);
95 if (tfp->tf_eflags & PSL_VM)
96 return (16);
97 sel = tfp->tf_cs & 0xffff;
98 if (sel == GSEL(GCODE_SEL, SEL_KPL))
99 return (32);
100 /* Rare cases follow. User mode cases are currently unreachable. */
101 if (ISLDT(sel)) {
102 plp = curthread->td_proc->p_md.md_ldt;
103 sdp = (plp != NULL) ? &plp->ldt_sd : &ldt[0].sd;
104 } else {
105 sdp = &gdt[PCPU_GET(cpuid) * NGDT].sd;
106 }
107 return (sdp[IDXSEL(sel)].sd_def32 == 0 ? 16 : 32);
108 }
109
110 void
db_show_mdpcpu(struct pcpu * pc)111 db_show_mdpcpu(struct pcpu *pc)
112 {
113
114 db_printf("APIC ID = %d\n", pc->pc_apic_id);
115 db_printf("currentldt = 0x%x\n", pc->pc_currentldt);
116 db_printf("trampstk = 0x%x\n", pc->pc_trampstk);
117 db_printf("kesp0 = 0x%x\n", pc->pc_kesp0);
118 db_printf("common_tssp = 0x%x\n", (u_int)pc->pc_common_tssp);
119 db_printf("tlb gen = %u\n", pc->pc_smp_tlb_done);
120 }
121