xref: /illumos-gate/usr/src/uts/intel/sys/kdi_regs.h (revision 399ca3a7ff315244c51a7bbd1d3ce2709ef6c7c6)
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  * Copyright 2018 Joyent, Inc.
26  */
27 
28 #ifndef _SYS_KDI_REGS_H
29 #define	_SYS_KDI_REGS_H
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_CPU_STATE_NONE		0
51 #define	KDI_CPU_STATE_MASTER		1
52 #define	KDI_CPU_STATE_SLAVE		2
53 
54 #define	KDIREG_DRCTL_WPALLEN_MASK	0x000000ff
55 #define	KDIREG_DRSTAT_RESERVED		0xffff0ff0
56 #define	KDIREG_DRCTL_RESERVED		0x00000700
57 
58 #ifndef _ASM
59 
60 /*
61  * We maintain a ring buffer of bread crumbs for debugging purposes.  The
62  * current buffer pointer is advanced along the ring with each intercepted
63  * trap (debugger entry, invalid memory access, fault during step, etc).
64  */
65 typedef struct kdi_crumb {
66 	greg_t krm_cpu_state;	/* This CPU's state at last entry */
67 	greg_t krm_pc;		/* Instruction pointer at trap */
68 	greg_t krm_sp;		/* Stack pointer at trap */
69 	greg_t krm_trapno;	/* The last trap number */
70 	greg_t krm_flag;	/* KAIF_CRUMB_F_* */
71 } kdi_crumb_t;
72 
73 #define	KDI_MAXWPIDX	3
74 
75 /*
76  * Storage for %dr0-3, %dr6, and %dr7.
77  */
78 typedef struct kdi_drreg {
79 	greg_t			dr_ctl;
80 	greg_t			dr_stat;
81 	greg_t			dr_addr[KDI_MAXWPIDX + 1];
82 } kdi_drreg_t;
83 
84 /*
85  * Data structure used to hold all of the state for a given CPU.
86  */
87 typedef struct kdi_cpusave {
88 	greg_t			*krs_gregs;	/* saved registers */
89 
90 	kdi_drreg_t		krs_dr;		/* saved debug registers */
91 
92 	user_desc_t		*krs_gdt;	/* GDT address */
93 	gate_desc_t		*krs_idt;	/* IDT address */
94 
95 	greg_t			krs_cr0;	/* saved %cr0 */
96 
97 	uint_t			krs_cpu_state;	/* KDI_CPU_STATE_* mstr/slv */
98 	uint_t			krs_cpu_flushed; /* Have caches been flushed? */
99 	uint_t			krs_cpu_id;	/* this CPU's ID */
100 
101 	/* Bread crumb ring buffer */
102 	ulong_t			krs_curcrumbidx; /* Current krs_crumbs idx */
103 	kdi_crumb_t		*krs_curcrumb;	/* Pointer to current crumb */
104 	kdi_crumb_t		krs_crumbs[KDI_NCRUMBS]; /* Crumbs */
105 } kdi_cpusave_t;
106 
107 #endif /* !_ASM */
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* _SYS_KDI_REGS_H */
114