xref: /illumos-gate/usr/src/contrib/bhyve/x86/psl.h (revision d0b3c59b)
1bf21cd93STycho Nightingale /*-
2bf21cd93STycho Nightingale  * Copyright (c) 1990 The Regents of the University of California.
3bf21cd93STycho Nightingale  * All rights reserved.
4bf21cd93STycho Nightingale  *
5bf21cd93STycho Nightingale  * This code is derived from software contributed to Berkeley by
6bf21cd93STycho Nightingale  * William Jolitz.
7bf21cd93STycho Nightingale  *
8bf21cd93STycho Nightingale  * Redistribution and use in source and binary forms, with or without
9bf21cd93STycho Nightingale  * modification, are permitted provided that the following conditions
10bf21cd93STycho Nightingale  * are met:
11bf21cd93STycho Nightingale  * 1. Redistributions of source code must retain the above copyright
12bf21cd93STycho Nightingale  *    notice, this list of conditions and the following disclaimer.
13bf21cd93STycho Nightingale  * 2. Redistributions in binary form must reproduce the above copyright
14bf21cd93STycho Nightingale  *    notice, this list of conditions and the following disclaimer in the
15bf21cd93STycho Nightingale  *    documentation and/or other materials provided with the distribution.
16bf21cd93STycho Nightingale  * 4. Neither the name of the University nor the names of its contributors
17bf21cd93STycho Nightingale  *    may be used to endorse or promote products derived from this software
18bf21cd93STycho Nightingale  *    without specific prior written permission.
19bf21cd93STycho Nightingale  *
20bf21cd93STycho Nightingale  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21bf21cd93STycho Nightingale  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22bf21cd93STycho Nightingale  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23bf21cd93STycho Nightingale  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24bf21cd93STycho Nightingale  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25bf21cd93STycho Nightingale  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26bf21cd93STycho Nightingale  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27bf21cd93STycho Nightingale  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28bf21cd93STycho Nightingale  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29bf21cd93STycho Nightingale  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30bf21cd93STycho Nightingale  * SUCH DAMAGE.
31bf21cd93STycho Nightingale  *
32bf21cd93STycho Nightingale  *	from: @(#)psl.h	5.2 (Berkeley) 1/18/91
33bf21cd93STycho Nightingale  * $FreeBSD: head/sys/x86/include/psl.h 258135 2013-11-14 15:37:20Z emaste $
34bf21cd93STycho Nightingale  */
35bf21cd93STycho Nightingale 
36bf21cd93STycho Nightingale #ifndef _MACHINE_PSL_H_
37bf21cd93STycho Nightingale #define	_MACHINE_PSL_H_
38bf21cd93STycho Nightingale 
39bf21cd93STycho Nightingale /*
40bf21cd93STycho Nightingale  * 386 processor status longword.
41bf21cd93STycho Nightingale  */
42bf21cd93STycho Nightingale #define	PSL_C		0x00000001	/* carry bit */
43bf21cd93STycho Nightingale #define	PSL_PF		0x00000004	/* parity bit */
44bf21cd93STycho Nightingale #define	PSL_AF		0x00000010	/* bcd carry bit */
45bf21cd93STycho Nightingale #define	PSL_Z		0x00000040	/* zero bit */
46bf21cd93STycho Nightingale #define	PSL_N		0x00000080	/* negative bit */
47bf21cd93STycho Nightingale #define	PSL_T		0x00000100	/* trace enable bit */
48bf21cd93STycho Nightingale #define	PSL_I		0x00000200	/* interrupt enable bit */
49bf21cd93STycho Nightingale #define	PSL_D		0x00000400	/* string instruction direction bit */
50bf21cd93STycho Nightingale #define	PSL_V		0x00000800	/* overflow bit */
51bf21cd93STycho Nightingale #define	PSL_IOPL	0x00003000	/* i/o privilege level */
52bf21cd93STycho Nightingale #define	PSL_NT		0x00004000	/* nested task bit */
53bf21cd93STycho Nightingale #define	PSL_RF		0x00010000	/* resume flag bit */
54bf21cd93STycho Nightingale #define	PSL_VM		0x00020000	/* virtual 8086 mode bit */
55bf21cd93STycho Nightingale #define	PSL_AC		0x00040000	/* alignment checking */
56bf21cd93STycho Nightingale #define	PSL_VIF		0x00080000	/* virtual interrupt enable */
57bf21cd93STycho Nightingale #define	PSL_VIP		0x00100000	/* virtual interrupt pending */
58bf21cd93STycho Nightingale #define	PSL_ID		0x00200000	/* identification bit */
59bf21cd93STycho Nightingale 
60bf21cd93STycho Nightingale /*
61bf21cd93STycho Nightingale  * The i486 manual says that we are not supposed to change reserved flags,
62bf21cd93STycho Nightingale  * but this is too much trouble since the reserved flags depend on the cpu
63bf21cd93STycho Nightingale  * and setting them to their historical values works in practice.
64bf21cd93STycho Nightingale  */
65bf21cd93STycho Nightingale #define	PSL_RESERVED_DEFAULT	0x00000002
66bf21cd93STycho Nightingale 
67bf21cd93STycho Nightingale /*
68bf21cd93STycho Nightingale  * Initial flags for kernel and user mode.  The kernel later inherits
69bf21cd93STycho Nightingale  * PSL_I and some other flags from user mode.
70bf21cd93STycho Nightingale  */
71bf21cd93STycho Nightingale #define	PSL_KERNEL	PSL_RESERVED_DEFAULT
72bf21cd93STycho Nightingale #define	PSL_USER	(PSL_RESERVED_DEFAULT | PSL_I)
73bf21cd93STycho Nightingale 
74bf21cd93STycho Nightingale /*
75bf21cd93STycho Nightingale  * Bits that can be changed in user mode on 486's.  We allow these bits
76bf21cd93STycho Nightingale  * to be changed using ptrace(), sigreturn() and procfs.  Setting PS_NT
77bf21cd93STycho Nightingale  * is undesirable but it may as well be allowed since users can inflict
78bf21cd93STycho Nightingale  * it on the kernel directly.  Changes to PSL_AC are silently ignored on
79bf21cd93STycho Nightingale  * 386's.
80bf21cd93STycho Nightingale  *
81bf21cd93STycho Nightingale  * Users are allowed to change the privileged flag PSL_RF.  The cpu sets PSL_RF
82bf21cd93STycho Nightingale  * in tf_eflags for faults.  Debuggers should sometimes set it there too.
83bf21cd93STycho Nightingale  * tf_eflags is kept in the signal context during signal handling and there is
84bf21cd93STycho Nightingale  * no other place to remember it, so the PSL_RF bit may be corrupted by the
85bf21cd93STycho Nightingale  * signal handler without us knowing.  Corruption of the PSL_RF bit at worst
86bf21cd93STycho Nightingale  * causes one more or one less debugger trap, so allowing it is fairly
87bf21cd93STycho Nightingale  * harmless.
88bf21cd93STycho Nightingale  */
89bf21cd93STycho Nightingale #define	PSL_USERCHANGE (PSL_C | PSL_PF | PSL_AF | PSL_Z | PSL_N | PSL_T \
90bf21cd93STycho Nightingale 			| PSL_D | PSL_V | PSL_NT | PSL_RF | PSL_AC | PSL_ID)
91bf21cd93STycho Nightingale 
92bf21cd93STycho Nightingale #endif /* !_MACHINE_PSL_H_ */
93