xref: /titanic_44/usr/src/cmd/mdb/common/kmdb/kvm_cpu.c (revision ee5416c9d7e449233197d5d20bc6b81e4ff091b2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * CPU-specific target implementation
31  *
32  * Each CPU provides a set of debugging facilities.  We have per-CPU "modules",
33  * each of which exposes a kmt_cpu_t.  When initialized, these modules will
34  * install dcmds, walkers, and the like in order to allow the user to take
35  * advantage of features specific to the CPU being used.
36  */
37 
38 #include <kmdb/kmdb_kdi.h>
39 #include <kmdb/kvm_cpu_impl.h>
40 #include <mdb/mdb_target.h>
41 #include <mdb/mdb_err.h>
42 #include <mdb/mdb.h>
43 
44 static kmt_cpu_ctor_f *const kmt_cpu_ctors[] = {
45 #if defined(__i386) || defined(__amd64)
46 	kmt_cpu_amd_create,
47 	kmt_cpu_p4_create,
48 #if defined(__i386)
49 	kmt_cpu_p6_create,
50 #endif	/* __i386 */
51 #endif	/* __i386 || __amd64 */
52 	NULL
53 };
54 
55 kmt_cpu_t *
56 kmt_cpu_create(mdb_tgt_t *t)
57 {
58 	kmt_cpu_t *cpu;
59 	int retry = 0;
60 	int i;
61 
62 	for (i = 0; kmt_cpu_ctors[i] != NULL; i++) {
63 		if ((cpu = kmt_cpu_ctors[i](t)) != NULL)
64 			return (cpu);
65 		else if (errno == EAGAIN)
66 			retry = 1;
67 	}
68 
69 	if (retry)
70 		(void) set_errno(EAGAIN);
71 
72 	return (NULL);
73 }
74 
75 void
76 kmt_cpu_destroy(kmt_cpu_t *cpu)
77 {
78 	if (cpu != NULL)
79 		cpu->kmt_cpu_ops->kco_destroy(cpu);
80 }
81 
82 int
83 kmt_cpu_step_branch(mdb_tgt_t *t, kmt_cpu_t *cpu)
84 {
85 	if (cpu == NULL || cpu->kmt_cpu_ops->kco_step_branch == NULL)
86 		return (set_errno(EMDB_TGTHWNOTSUP));
87 
88 	return (cpu->kmt_cpu_ops->kco_step_branch(cpu, t));
89 }
90 
91 const char *
92 kmt_cpu_name(kmt_cpu_t *cpu)
93 {
94 	if (cpu == NULL)
95 		return ("none");
96 	else
97 		return (cpu->kmt_cpu_ops->kco_name(cpu));
98 }
99