Print this page
9210 remove KMDB branch debugging support
9211 ::crregs could do with cr2/cr3 support
9209 ::ttrace should be able to filter by thread
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Yuri Pankov <yuripv@yuripv.net>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/os/arch_kdi.c
+++ new/usr/src/uts/intel/os/arch_kdi.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 + *
25 + * Copyright 2018 Joyent, Inc.
24 26 */
25 27
26 28 /*
27 29 * Kernel/Debugger Interface (KDI) routines. Called during debugger under
28 30 * various system states (boot, while running, while the debugger has control).
29 31 * Functions intended for use while the debugger has control may not grab any
30 32 * locks or perform any functions that assume the availability of other system
31 33 * services.
32 34 */
33 35
34 36 #include <sys/systm.h>
35 37 #include <sys/x86_archext.h>
36 38 #include <sys/kdi_impl.h>
37 39 #include <sys/smp_impldefs.h>
38 40 #include <sys/psm_types.h>
39 41 #include <sys/segments.h>
40 42 #include <sys/archsystm.h>
41 43 #include <sys/controlregs.h>
42 44 #include <sys/trap.h>
43 45 #include <sys/kobj.h>
44 46 #include <sys/kobj_impl.h>
45 47 #include <sys/clock_impl.h>
46 48
47 49 static void
48 50 kdi_system_claim(void)
49 51 {
50 52 lbolt_debug_entry();
51 53
52 54 psm_notifyf(PSM_DEBUG_ENTER);
53 55 }
54 56
55 57 static void
56 58 kdi_system_release(void)
57 59 {
58 60 psm_notifyf(PSM_DEBUG_EXIT);
59 61
60 62 lbolt_debug_return();
61 63 }
62 64
63 65 static cpu_t *
64 66 kdi_gdt2cpu(uintptr_t gdtbase)
65 67 {
66 68 cpu_t *cp = cpu_list;
67 69
68 70 if (cp == NULL)
69 71 return (NULL);
70 72
71 73 do {
72 74 if (gdtbase == (uintptr_t)cp->cpu_gdt)
73 75 return (cp);
74 76 } while ((cp = cp->cpu_next) != cpu_list);
75 77
76 78 return (NULL);
77 79 }
78 80
79 81 #if defined(__amd64)
80 82 uintptr_t
81 83 kdi_gdt2gsbase(uintptr_t gdtbase)
82 84 {
83 85 return ((uintptr_t)kdi_gdt2cpu(gdtbase));
84 86 }
85 87 #endif
86 88
87 89 static uintptr_t
88 90 kdi_get_userlimit(void)
89 91 {
90 92 return (_userlimit);
91 93 }
92 94
93 95 static int
94 96 kdi_get_cpuinfo(uint_t *vendorp, uint_t *familyp, uint_t *modelp)
95 97 {
96 98 desctbr_t gdtr;
97 99 cpu_t *cpu;
98 100
99 101 /*
100 102 * CPU doesn't work until the GDT and gs/GSBASE have been set up.
101 103 * Boot-loaded kmdb will call us well before then, so we have to
102 104 * find the current cpu_t the hard way.
103 105 */
104 106 rd_gdtr(&gdtr);
105 107 if ((cpu = kdi_gdt2cpu(gdtr.dtr_base)) == NULL ||
106 108 !cpuid_checkpass(cpu, 1))
107 109 return (EAGAIN); /* cpuid isn't done yet */
108 110
109 111 *vendorp = cpuid_getvendor(cpu);
110 112 *familyp = cpuid_getfamily(cpu);
111 113 *modelp = cpuid_getmodel(cpu);
112 114
113 115 return (0);
114 116 }
115 117
116 118 void
117 119 kdi_idtr_set(gate_desc_t *idt, size_t limit)
118 120 {
119 121 desctbr_t idtr;
120 122
121 123 /*
122 124 * This rare case could happen if we entered kmdb whilst still on the
123 125 * fake CPU set up by boot_kdi_tmpinit(). We're trying to restore the
124 126 * kernel's IDT that we saved on entry, but it was from the fake cpu_t
125 127 * rather than the real IDT (which is still boot's). It's unpleasant,
126 128 * but we just encode knowledge that it's idt0 we want to restore.
127 129 */
128 130 if (idt == NULL)
129 131 idt = idt0;
130 132
131 133 CPU->cpu_m.mcpu_idt = idt;
132 134 idtr.dtr_base = (uintptr_t)idt;
133 135 idtr.dtr_limit = limit;
134 136 kdi_idtr_write(&idtr);
135 137 }
136 138
137 139 static void
138 140 kdi_plat_call(void (*platfn)(void))
139 141 {
140 142 if (platfn != NULL)
141 143 platfn();
142 144 }
143 145
144 146 /*
145 147 * On Intel, most of these are shared between i86*, so this is really an
146 148 * arch_kdi_init().
↓ open down ↓ |
113 lines elided |
↑ open up ↑ |
147 149 */
148 150 void
149 151 mach_kdi_init(kdi_t *kdi)
150 152 {
151 153 kdi->kdi_plat_call = kdi_plat_call;
152 154 kdi->kdi_kmdb_enter = kmdb_enter;
153 155 kdi->mkdi_activate = kdi_activate;
154 156 kdi->mkdi_deactivate = kdi_deactivate;
155 157 kdi->mkdi_idt_switch = kdi_idt_switch;
156 158 kdi->mkdi_update_drreg = kdi_update_drreg;
157 - kdi->mkdi_set_debug_msrs = kdi_set_debug_msrs;
158 159 kdi->mkdi_get_userlimit = kdi_get_userlimit;
159 160 kdi->mkdi_get_cpuinfo = kdi_get_cpuinfo;
160 161 kdi->mkdi_stop_slaves = kdi_stop_slaves;
161 162 kdi->mkdi_start_slaves = kdi_start_slaves;
162 163 kdi->mkdi_slave_wait = kdi_slave_wait;
163 164 kdi->mkdi_memrange_add = kdi_memrange_add;
164 165 kdi->mkdi_reboot = kdi_reboot;
165 166 }
166 167
167 168 void
168 169 plat_kdi_init(kdi_t *kdi)
169 170 {
170 171 kdi->pkdi_system_claim = kdi_system_claim;
171 172 kdi->pkdi_system_release = kdi_system_release;
172 173 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX