/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _IA32_SYS_PSW_H
#define	_IA32_SYS_PSW_H

#pragma ident	"@(#)psw.h	1.4	04/09/28 SMI"

#ifdef	__cplusplus
extern "C" {
#endif

#ifndef _ASM

/* Flags Register */

typedef struct flags {
	uint_t	fl_cf	:  1,		/* carry/borrow */
			:  1,		/* reserved */
		fl_pf	:  1,		/* parity */
			:  1,		/* reserved */
		fl_af	:  1,		/* carry/borrow */
			:  1,		/* reserved */
		fl_zf	:  1,		/* zero */
		fl_sf	:  1,		/* sign */
		fl_tf	:  1,		/* trace */
		fl_if	:  1,		/* interrupt enable */
		fl_df	:  1,		/* direction */
		fl_of	:  1,		/* overflow */
		fl_iopl :  2,		/* I/O privilege level */
		fl_nt	:  1,		/* nested task */
			:  1,		/* reserved */
		fl_rf	:  1,		/* reset */
		fl_vm	:  1,		/* virtual 86 mode */
		fl_res	: 14;		/* reserved */
} flags_t;

#endif		/* !_ASM */

#define	PS_C		0x0001		/* carry bit			*/
#define	PS_P		0x0004		/* parity bit			*/
#define	PS_AC		0x0010		/* auxiliary carry bit		*/
#define	PS_Z		0x0040		/* zero bit			*/
#define	PS_N		0x0080		/* negative bit			*/
#define	PS_T		0x0100		/* trace enable bit		*/
#define	PS_IE		0x0200		/* interrupt enable bit		*/
#define	PS_D		0x0400		/* direction bit		*/
#define	PS_V		0x0800		/* overflow bit			*/
#define	PS_IOPL		0x3000		/* I/O privilege level		*/
#define	PS_NT		0x4000		/* nested task flag		*/
#define	PS_RF		0x10000		/* restore flag			*/
#define	PS_VM		0x20000		/* virtual 86 mode flag		*/
#define	PS_ACHK		0x40000		/* alignment check enable (486) */
#define	PS_VINT		0x80000		/* virtual interrupt flag	*/
#define	PS_VINTP	0x100000	/* virtual interrupt pending	*/
#define	PS_ID		0x200000	/* ID flag			*/

#define	PS_ICC		(PS_C|PS_AC|PS_Z|PS_N)	   /* integer condition codes */

#define	FMT_FLAGS_REG				\
	"\20\26id\25vip\24vif\23ac\22vm\21rf"	\
	"\17nt\14of\13df\12if\11tf\10sf\7zf\5af\3pf\1cf"

#define	PSL_USER	0x202		/* initial user FLAGS */

/* user variable PS bits */
#define	PSL_USERMASK	(PS_ICC|PS_D|PS_T|PS_V|PS_P|PS_ACHK|PS_NT)

/*
 * kernel flags settings
 */
#define	F_OFF		0x2		/* interrupts off */
#define	F_ON		0x202		/* interrupts on */

#ifndef _ASM
typedef int	psw_t;
#endif

#include <sys/tss.h>
#include <sys/segments.h>			/* selector definitions */

#define	USERMODE(cs)	((uint_t)((cs)&CPL_MASK) != 0)

#include <sys/spl.h>

#ifdef	__cplusplus
}
#endif

#endif	/* _IA32_SYS_PSW_H */
