xref: /titanic_51/usr/src/uts/intel/sys/kdi_regs.h (revision dfb96a4f56fb431b915bc67e5d9d5c8d4f4f6679)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_KDI_REGS_H
27 #define	_SYS_KDI_REGS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifndef _ASM
32 #include <sys/types.h>
33 #include <sys/segments.h>
34 #include <sys/regset.h>
35 #include <sys/privregs.h>
36 #endif
37 
38 #if defined(__amd64)
39 #include <amd64/sys/kdi_regs.h>
40 #elif defined(__i386)
41 #include <ia32/sys/kdi_regs.h>
42 #endif
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #define	KDI_NCRUMBS	5
49 
50 #define	KDI_RESUME			0
51 #define	KDI_RESUME_PASS_TO_KERNEL	1
52 
53 #define	KDI_CPU_STATE_NONE		0
54 #define	KDI_CPU_STATE_MASTER		1
55 #define	KDI_CPU_STATE_SLAVE		2
56 
57 #define	KDIREG_DRCTL_WPALLEN_MASK	0x000000ff
58 #define	KDIREG_DRSTAT_RESERVED		0xffff0ff0
59 #define	KDIREG_DRCTL_RESERVED		0x00000700
60 
61 #define	KDI_MSR_READ		0x1	/* read during entry (unlimited) */
62 #define	KDI_MSR_WRITE		0x2	/* write during exit (unlimited) */
63 #define	KDI_MSR_WRITEDELAY	0x4	/* write after last branch (<= 1) */
64 #define	KDI_MSR_CLEARENTRY	0x3	/* clear before 1st branch (<= 1) */
65 
66 #ifndef _ASM
67 
68 /*
69  * We maintain a ring buffer of bread crumbs for debugging purposes.  The
70  * current buffer pointer is advanced along the ring with each intercepted
71  * trap (debugger entry, invalid memory access, fault during step, etc).
72  */
73 typedef struct kdi_crumb {
74 	greg_t krm_cpu_state;	/* This CPU's state at last entry */
75 	greg_t krm_pc;		/* Instruction pointer at trap */
76 	greg_t krm_sp;		/* Stack pointer at trap */
77 	greg_t krm_trapno;	/* The last trap number */
78 	greg_t krm_flag;	/* KAIF_CRUMB_F_* */
79 } kdi_crumb_t;
80 
81 #define	KDI_MAXWPIDX	3
82 
83 /*
84  * Storage for %dr0-3, %dr6, and %dr7.
85  */
86 typedef struct kdi_drreg {
87 	greg_t			dr_ctl;
88 	greg_t			dr_stat;
89 	greg_t			dr_addr[KDI_MAXWPIDX + 1];
90 } kdi_drreg_t;
91 
92 typedef struct kdi_msr {
93 	uint_t		msr_num;
94 	uint_t		msr_type;
95 	union {
96 		uint64_t *_msr_valp;
97 		uint64_t _msr_val;
98 	} _u;
99 } kdi_msr_t;
100 
101 #define	kdi_msr_val	_u._msr_val
102 #define	kdi_msr_valp	_u._msr_valp
103 
104 /*
105  * Data structure used to hold all of the state for a given CPU.
106  */
107 typedef struct kdi_cpusave {
108 	greg_t			*krs_gregs;	/* saved registers */
109 
110 	kdi_drreg_t		krs_dr;		/* saved debug registers */
111 
112 	user_desc_t		*krs_gdt;	/* GDT address */
113 	gate_desc_t		*krs_idt;	/* IDT address */
114 
115 	greg_t			krs_cr0;	/* saved %cr0 */
116 
117 	kdi_msr_t		*krs_msr;	/* ptr to MSR save area */
118 
119 	uint_t			krs_cpu_state;	/* KDI_CPU_STATE_* mstr/slv */
120 	uint_t			krs_cpu_flushed; /* Have caches been flushed? */
121 	uint_t			krs_cpu_id;	/* this CPU's ID */
122 
123 	/* Bread crumb ring buffer */
124 	ulong_t			krs_curcrumbidx; /* Current krs_crumbs idx */
125 	kdi_crumb_t		*krs_curcrumb;	/* Pointer to current crumb */
126 	kdi_crumb_t		krs_crumbs[KDI_NCRUMBS]; /* Crumbs */
127 } kdi_cpusave_t;
128 
129 #endif /* !_ASM */
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif /* _SYS_KDI_REGS_H */
136