xref: /freebsd-src/sys/x86/include/reg.h (revision 29363fb446372cb3f10bc98664e9767c53fbb457)
101cd1968STijl Coosemans /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
401cd1968STijl Coosemans  * Copyright (c) 2003 Peter Wemm.
501cd1968STijl Coosemans  * Copyright (c) 1990 The Regents of the University of California.
601cd1968STijl Coosemans  * All rights reserved.
701cd1968STijl Coosemans  *
801cd1968STijl Coosemans  * This code is derived from software contributed to Berkeley by
901cd1968STijl Coosemans  * William Jolitz.
1001cd1968STijl Coosemans  *
1101cd1968STijl Coosemans  * Redistribution and use in source and binary forms, with or without
1201cd1968STijl Coosemans  * modification, are permitted provided that the following conditions
1301cd1968STijl Coosemans  * are met:
1401cd1968STijl Coosemans  * 1. Redistributions of source code must retain the above copyright
1501cd1968STijl Coosemans  *    notice, this list of conditions and the following disclaimer.
1601cd1968STijl Coosemans  * 2. Redistributions in binary form must reproduce the above copyright
1701cd1968STijl Coosemans  *    notice, this list of conditions and the following disclaimer in the
1801cd1968STijl Coosemans  *    documentation and/or other materials provided with the distribution.
19fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
2001cd1968STijl Coosemans  *    may be used to endorse or promote products derived from this software
2101cd1968STijl Coosemans  *    without specific prior written permission.
2201cd1968STijl Coosemans  *
2301cd1968STijl Coosemans  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2401cd1968STijl Coosemans  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2501cd1968STijl Coosemans  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2601cd1968STijl Coosemans  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2701cd1968STijl Coosemans  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2801cd1968STijl Coosemans  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2901cd1968STijl Coosemans  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3001cd1968STijl Coosemans  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3101cd1968STijl Coosemans  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3201cd1968STijl Coosemans  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3301cd1968STijl Coosemans  * SUCH DAMAGE.
3401cd1968STijl Coosemans  */
3501cd1968STijl Coosemans 
3601cd1968STijl Coosemans #ifndef _MACHINE_REG_H_
3701cd1968STijl Coosemans #define	_MACHINE_REG_H_
3801cd1968STijl Coosemans 
399bb8a409SAlex Richardson #include <sys/_types.h>
4001cd1968STijl Coosemans 
4101cd1968STijl Coosemans #ifdef __i386__
4201cd1968STijl Coosemans /*
4301cd1968STijl Coosemans  * Indices for registers in `struct trapframe' and `struct regs'.
4401cd1968STijl Coosemans  *
4501cd1968STijl Coosemans  * This interface is deprecated.  In the kernel, it is only used in FPU
4601cd1968STijl Coosemans  * emulators to convert from register numbers encoded in instructions to
4701cd1968STijl Coosemans  * register values.  Everything else just accesses the relevant struct
4801cd1968STijl Coosemans  * members.  In userland, debuggers tend to abuse this interface since
4901cd1968STijl Coosemans  * they don't understand that `struct regs' is a struct.  I hope they have
5001cd1968STijl Coosemans  * stopped accessing the registers in the trap frame via PT_{READ,WRITE}_U
5101cd1968STijl Coosemans  * and we can stop supporting the user area soon.
5201cd1968STijl Coosemans  */
5301cd1968STijl Coosemans #define	tFS	(0)
5401cd1968STijl Coosemans #define	tES	(1)
5501cd1968STijl Coosemans #define	tDS	(2)
5601cd1968STijl Coosemans #define	tEDI	(3)
5701cd1968STijl Coosemans #define	tESI	(4)
5801cd1968STijl Coosemans #define	tEBP	(5)
5901cd1968STijl Coosemans #define	tISP	(6)
6001cd1968STijl Coosemans #define	tEBX	(7)
6101cd1968STijl Coosemans #define	tEDX	(8)
6201cd1968STijl Coosemans #define	tECX	(9)
6301cd1968STijl Coosemans #define	tEAX	(10)
6401cd1968STijl Coosemans #define	tERR	(12)
6501cd1968STijl Coosemans #define	tEIP	(13)
6601cd1968STijl Coosemans #define	tCS	(14)
6701cd1968STijl Coosemans #define	tEFLAGS	(15)
6801cd1968STijl Coosemans #define	tESP	(16)
6901cd1968STijl Coosemans #define	tSS	(17)
7001cd1968STijl Coosemans 
7101cd1968STijl Coosemans /*
7201cd1968STijl Coosemans  * Indices for registers in `struct regs' only.
7301cd1968STijl Coosemans  *
7401cd1968STijl Coosemans  * Some registers live in the pcb and are only in an "array" with the
7501cd1968STijl Coosemans  * other registers in application interfaces that copy all the registers
7601cd1968STijl Coosemans  * to or from a `struct regs'.
7701cd1968STijl Coosemans  */
7801cd1968STijl Coosemans #define	tGS	(18)
7901cd1968STijl Coosemans #endif /* __i386__ */
8001cd1968STijl Coosemans 
8101cd1968STijl Coosemans /* Rename the structs below depending on the machine architecture. */
8201cd1968STijl Coosemans #ifdef	__i386__
8301cd1968STijl Coosemans #define	__reg32		reg
8401cd1968STijl Coosemans #define	__fpreg32	fpreg
8501cd1968STijl Coosemans #define	__dbreg32	dbreg
86*931983eeSJohn Baldwin #define	__segbasereg32	segbasereg
8701cd1968STijl Coosemans #else
8801cd1968STijl Coosemans #define	__reg32		reg32
8901cd1968STijl Coosemans #define	__reg64		reg
9001cd1968STijl Coosemans #define	__fpreg32	fpreg32
9101cd1968STijl Coosemans #define	__fpreg64	fpreg
9201cd1968STijl Coosemans #define	__dbreg32	dbreg32
9301cd1968STijl Coosemans #define	__dbreg64	dbreg
94*931983eeSJohn Baldwin #define	__segbasereg32	segbasereg32
95*931983eeSJohn Baldwin #define	__segbasereg64	segbasereg
96dbee5c67SJohn Baldwin #define	__HAVE_REG32
9701cd1968STijl Coosemans #endif
9801cd1968STijl Coosemans 
9901cd1968STijl Coosemans /*
10001cd1968STijl Coosemans  * Register set accessible via /proc/$pid/regs and PT_{SET,GET}REGS.
10101cd1968STijl Coosemans  */
10201cd1968STijl Coosemans struct __reg32 {
10301cd1968STijl Coosemans 	__uint32_t	r_fs;
10401cd1968STijl Coosemans 	__uint32_t	r_es;
10501cd1968STijl Coosemans 	__uint32_t	r_ds;
10601cd1968STijl Coosemans 	__uint32_t	r_edi;
10701cd1968STijl Coosemans 	__uint32_t	r_esi;
10801cd1968STijl Coosemans 	__uint32_t	r_ebp;
10901cd1968STijl Coosemans 	__uint32_t	r_isp;
11001cd1968STijl Coosemans 	__uint32_t	r_ebx;
11101cd1968STijl Coosemans 	__uint32_t	r_edx;
11201cd1968STijl Coosemans 	__uint32_t	r_ecx;
11301cd1968STijl Coosemans 	__uint32_t	r_eax;
11401cd1968STijl Coosemans 	__uint32_t	r_trapno;
11501cd1968STijl Coosemans 	__uint32_t	r_err;
11601cd1968STijl Coosemans 	__uint32_t	r_eip;
11701cd1968STijl Coosemans 	__uint32_t	r_cs;
11801cd1968STijl Coosemans 	__uint32_t	r_eflags;
11901cd1968STijl Coosemans 	__uint32_t	r_esp;
12001cd1968STijl Coosemans 	__uint32_t	r_ss;
12101cd1968STijl Coosemans 	__uint32_t	r_gs;
12201cd1968STijl Coosemans };
12301cd1968STijl Coosemans 
12401cd1968STijl Coosemans struct __reg64 {
12501cd1968STijl Coosemans 	__int64_t	r_r15;
12601cd1968STijl Coosemans 	__int64_t	r_r14;
12701cd1968STijl Coosemans 	__int64_t	r_r13;
12801cd1968STijl Coosemans 	__int64_t	r_r12;
12901cd1968STijl Coosemans 	__int64_t	r_r11;
13001cd1968STijl Coosemans 	__int64_t	r_r10;
13101cd1968STijl Coosemans 	__int64_t	r_r9;
13201cd1968STijl Coosemans 	__int64_t	r_r8;
13301cd1968STijl Coosemans 	__int64_t	r_rdi;
13401cd1968STijl Coosemans 	__int64_t	r_rsi;
13501cd1968STijl Coosemans 	__int64_t	r_rbp;
13601cd1968STijl Coosemans 	__int64_t	r_rbx;
13701cd1968STijl Coosemans 	__int64_t	r_rdx;
13801cd1968STijl Coosemans 	__int64_t	r_rcx;
13901cd1968STijl Coosemans 	__int64_t	r_rax;
14001cd1968STijl Coosemans 	__uint32_t	r_trapno;
14101cd1968STijl Coosemans 	__uint16_t	r_fs;
14201cd1968STijl Coosemans 	__uint16_t	r_gs;
14301cd1968STijl Coosemans 	__uint32_t	r_err;
14401cd1968STijl Coosemans 	__uint16_t	r_es;
14501cd1968STijl Coosemans 	__uint16_t	r_ds;
14601cd1968STijl Coosemans 	__int64_t	r_rip;
14701cd1968STijl Coosemans 	__int64_t	r_cs;
14801cd1968STijl Coosemans 	__int64_t	r_rflags;
14901cd1968STijl Coosemans 	__int64_t	r_rsp;
15001cd1968STijl Coosemans 	__int64_t	r_ss;
15101cd1968STijl Coosemans };
15201cd1968STijl Coosemans 
15301cd1968STijl Coosemans /*
15401cd1968STijl Coosemans  * Register set accessible via /proc/$pid/fpregs.
15501cd1968STijl Coosemans  *
15601cd1968STijl Coosemans  * XXX should get struct from fpu.h.  Here we give a slightly
15701cd1968STijl Coosemans  * simplified struct.  This may be too much detail.  Perhaps
15801cd1968STijl Coosemans  * an array of unsigned longs is best.
15901cd1968STijl Coosemans  */
16001cd1968STijl Coosemans struct __fpreg32 {
16101cd1968STijl Coosemans 	__uint32_t	fpr_env[7];
16201cd1968STijl Coosemans 	__uint8_t	fpr_acc[8][10];
16301cd1968STijl Coosemans 	__uint32_t	fpr_ex_sw;
16401cd1968STijl Coosemans 	__uint8_t	fpr_pad[64];
16501cd1968STijl Coosemans };
16601cd1968STijl Coosemans 
16701cd1968STijl Coosemans struct __fpreg64 {
16801cd1968STijl Coosemans 	__uint64_t	fpr_env[4];
16901cd1968STijl Coosemans 	__uint8_t	fpr_acc[8][16];
17001cd1968STijl Coosemans 	__uint8_t	fpr_xacc[16][16];
17101cd1968STijl Coosemans 	__uint64_t	fpr_spare[12];
17201cd1968STijl Coosemans };
17301cd1968STijl Coosemans 
17401cd1968STijl Coosemans /*
17501cd1968STijl Coosemans  * Register set accessible via PT_GETXMMREGS (i386).
17601cd1968STijl Coosemans  */
17701cd1968STijl Coosemans struct xmmreg {
17801cd1968STijl Coosemans 	/*
17901cd1968STijl Coosemans 	 * XXX should get struct from npx.h.  Here we give a slightly
18001cd1968STijl Coosemans 	 * simplified struct.  This may be too much detail.  Perhaps
18101cd1968STijl Coosemans 	 * an array of unsigned longs is best.
18201cd1968STijl Coosemans 	 */
18301cd1968STijl Coosemans 	__uint32_t	xmm_env[8];
18401cd1968STijl Coosemans 	__uint8_t	xmm_acc[8][16];
18501cd1968STijl Coosemans 	__uint8_t	xmm_reg[8][16];
18601cd1968STijl Coosemans 	__uint8_t	xmm_pad[224];
18701cd1968STijl Coosemans };
18801cd1968STijl Coosemans 
18901cd1968STijl Coosemans /*
19001cd1968STijl Coosemans  * Register set accessible via /proc/$pid/dbregs.
19101cd1968STijl Coosemans  */
19201cd1968STijl Coosemans struct __dbreg32 {
19301cd1968STijl Coosemans 	__uint32_t	dr[8];	/* debug registers */
19401cd1968STijl Coosemans 				/* Index 0-3: debug address registers */
19501cd1968STijl Coosemans 				/* Index 4-5: reserved */
19601cd1968STijl Coosemans 				/* Index 6: debug status */
19701cd1968STijl Coosemans 				/* Index 7: debug control */
19801cd1968STijl Coosemans };
19901cd1968STijl Coosemans 
20001cd1968STijl Coosemans struct __dbreg64 {
20101cd1968STijl Coosemans 	__uint64_t	dr[16];	/* debug registers */
20201cd1968STijl Coosemans 				/* Index 0-3: debug address registers */
20301cd1968STijl Coosemans 				/* Index 4-5: reserved */
20401cd1968STijl Coosemans 				/* Index 6: debug status */
20501cd1968STijl Coosemans 				/* Index 7: debug control */
20601cd1968STijl Coosemans 				/* Index 8-15: reserved */
20701cd1968STijl Coosemans };
20801cd1968STijl Coosemans 
2099e2154ffSJohn Baldwin #define	DBREG_DR6_RESERVED1	0xffff0ff0
2109e2154ffSJohn Baldwin #define	DBREG_DR6_BMASK		0x000f
2119e2154ffSJohn Baldwin #define	DBREG_DR6_B(i)		(1 << (i))
2129e2154ffSJohn Baldwin #define	DBREG_DR6_BD		0x2000
2139e2154ffSJohn Baldwin #define	DBREG_DR6_BS		0x4000
2149e2154ffSJohn Baldwin #define	DBREG_DR6_BT		0x8000
2159e2154ffSJohn Baldwin 
2169e2154ffSJohn Baldwin #define	DBREG_DR7_RESERVED1	0x0400
21701cd1968STijl Coosemans #define	DBREG_DR7_LOCAL_ENABLE	0x01
21801cd1968STijl Coosemans #define	DBREG_DR7_GLOBAL_ENABLE	0x02
21901cd1968STijl Coosemans #define	DBREG_DR7_LEN_1		0x00	/* 1 byte length          */
22001cd1968STijl Coosemans #define	DBREG_DR7_LEN_2		0x01
22101cd1968STijl Coosemans #define	DBREG_DR7_LEN_4		0x03
22201cd1968STijl Coosemans #define	DBREG_DR7_LEN_8		0x02
22301cd1968STijl Coosemans #define	DBREG_DR7_EXEC		0x00	/* break on execute       */
22401cd1968STijl Coosemans #define	DBREG_DR7_WRONLY	0x01	/* break on write         */
22501cd1968STijl Coosemans #define	DBREG_DR7_RDWR		0x03	/* break on read or write */
22601cd1968STijl Coosemans #define	DBREG_DR7_MASK(i)	\
22701cd1968STijl Coosemans 	((__u_register_t)(0xf) << ((i) * 4 + 16) | 0x3 << (i) * 2)
22801cd1968STijl Coosemans #define	DBREG_DR7_SET(i, len, access, enable)				\
22901cd1968STijl Coosemans 	((__u_register_t)((len) << 2 | (access)) << ((i) * 4 + 16) | 	\
23001cd1968STijl Coosemans 	(enable) << (i) * 2)
23101cd1968STijl Coosemans #define	DBREG_DR7_GD		0x2000
23201cd1968STijl Coosemans #define	DBREG_DR7_ENABLED(d, i)	(((d) & 0x3 << (i) * 2) != 0)
23301cd1968STijl Coosemans #define	DBREG_DR7_ACCESS(d, i)	((d) >> ((i) * 4 + 16) & 0x3)
23401cd1968STijl Coosemans #define	DBREG_DR7_LEN(d, i)	((d) >> ((i) * 4 + 18) & 0x3)
23501cd1968STijl Coosemans 
23601cd1968STijl Coosemans #define	DBREG_DRX(d,x)	((d)->dr[(x)])	/* reference dr0 - dr7 by
23701cd1968STijl Coosemans 					   register number */
23801cd1968STijl Coosemans 
239*931983eeSJohn Baldwin /*
240*931983eeSJohn Baldwin  * Register set accessible via NT_X86_SEGBASES.
241*931983eeSJohn Baldwin  */
242*931983eeSJohn Baldwin struct __segbasereg32 {
243*931983eeSJohn Baldwin 	__uint32_t	r_fsbase;
244*931983eeSJohn Baldwin 	__uint32_t	r_gsbase;
245*931983eeSJohn Baldwin };
246*931983eeSJohn Baldwin 
247*931983eeSJohn Baldwin struct __segbasereg64 {
248*931983eeSJohn Baldwin 	__uint64_t	r_fsbase;
249*931983eeSJohn Baldwin 	__uint64_t	r_gsbase;
250*931983eeSJohn Baldwin };
251*931983eeSJohn Baldwin 
25201cd1968STijl Coosemans #undef __reg32
25301cd1968STijl Coosemans #undef __reg64
25401cd1968STijl Coosemans #undef __fpreg32
25501cd1968STijl Coosemans #undef __fpreg64
25601cd1968STijl Coosemans #undef __dbreg32
25701cd1968STijl Coosemans #undef __dbreg64
258*931983eeSJohn Baldwin #undef __segbasereg32
259*931983eeSJohn Baldwin #undef __segbasereg64
26001cd1968STijl Coosemans 
26101cd1968STijl Coosemans #ifdef _KERNEL
26201cd1968STijl Coosemans /*
26301cd1968STijl Coosemans  * XXX these interfaces are MI, so they should be declared in a MI place.
26401cd1968STijl Coosemans  */
26501cd1968STijl Coosemans int	fill_frame_regs(struct trapframe *, struct reg *);
26601cd1968STijl Coosemans #endif
26701cd1968STijl Coosemans 
26801cd1968STijl Coosemans #endif /* !_MACHINE_REG_H_ */
269