4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Kernel/Debugger Interface (KDI) routines. Called during debugger under
30 * various system states (boot, while running, while the debugger has control).
31 * Functions intended for use while the debugger has control may not grab any
32 * locks or perform any functions that assume the availability of other system
36 #include <sys/systm.h>
37 #include <sys/x86_archext.h>
38 #include <sys/kdi_impl.h>
39 #include <sys/smp_impldefs.h>
40 #include <sys/psm_types.h>
41 #include <sys/segments.h>
42 #include <sys/archsystm.h>
43 #include <sys/controlregs.h>
46 #include <sys/kobj_impl.h>
47 #include <sys/mach_mmu.h>
50 kdi_idt_write(gate_desc_t
*gate
, uint_t vec
)
52 gate_desc_t
*idt
= CPU
->cpu_m
.mcpu_idt
;
60 idt
= (gate_desc_t
*)idtr
.dtr_base
;
71 return (kdi_getdr0());
73 return (kdi_getdr1());
75 return (kdi_getdr2());
77 return (kdi_getdr3());
79 return (kdi_getdr6());
81 return (kdi_getdr7());
83 panic("invalid debug register dr%d", reg
);
89 kdi_dreg_set(int reg
, ulong_t value
)
111 panic("invalid debug register dr%d", reg
);
117 kdi_flush_caches(void)
122 extern void kdi_slave_entry(void);
125 kdi_stop_slaves(int cpu
, int doxc
)
128 kdi_xc_others(cpu
, kdi_slave_entry
);
132 * On i86pc, slaves busy-loop, so we don't need to do anything here.
135 kdi_start_slaves(void)
146 * These routines are called -extremely- early, during kmdb initialization.
148 * Many common kernel functions assume that %gs has been initialized,
149 * and fail horribly if it hasn't. At this point, the boot code has
150 * reserved a descriptor for us (KMDBGS_SEL) in it's GDT; arrange for it
151 * to point at a dummy cpu_t, temporarily at least.
153 * Note that kmdb entry relies on the fake cpu_t having zero cpu_idt/cpu_id.
159 boot_kdi_tmpinit(void)
161 cpu_t
*cpu
= kobj_zalloc(sizeof (*cpu
), KM_TMP
);
166 old
= (uintptr_t)rdmsr(MSR_AMD_GSBASE
);
167 wrmsr(MSR_AMD_GSBASE
, (uint64_t)cpu
);
168 return ((void *)old
);
172 boot_kdi_tmpfini(void *old
)
174 wrmsr(MSR_AMD_GSBASE
, (uint64_t)old
);
177 #elif defined(__i386)
180 boot_kdi_tmpinit(void)
182 cpu_t
*cpu
= kobj_zalloc(sizeof (*cpu
), KM_TMP
);
190 bgdt
= (user_desc_t
*)(b_gdtr
.dtr_base
);
192 set_usegd(&bgdt
[GDT_BGSTMP
],
193 cpu
, sizeof (*cpu
), SDT_MEMRWA
, SEL_KPL
, SDP_BYTES
, SDP_OP32
);
196 * Now switch %gs to point at it.
201 return ((void *)old
);
205 boot_kdi_tmpfini(void *old
)
207 setgs((uintptr_t)old
);