/*        @(#)pte.h	13.1 (RC Computer) 91/02/02           */

/*
 * RC9000 page table entry
 *
 * There are two major kinds of pte's: those which have ever existed (and are
 * thus either now in core or on the swap device), and those which have
 * never existed, but which will be filled on demand at first reference.
 * There is a structure describing each.  There is also an ancillary
 * structure used in page clustering.
 */

#ifdef LANGUAGE_C
struct pte
{
#ifdef MIPSEB
unsigned int	pg_pfnum:20,		/* HW: core page frame number or 0 */
		pg_n:1,			/* HW: non-cacheable bit */
		pg_m:1,			/* HW: modified (dirty) bit */
		pg_v:1,			/* HW: valid bit */
		pg_g:1,			/* HW: ignore pid bit */
#ifdef RPU
		pg_uku:1,		/* RTE: Used in KUSEG */
		pg_rku:1,		/* RTE: Reserved for KUSEG */
		pg_uk2:1,		/* RTE: Used in KSEG2 */
		pg_rk2:1,		/* RTE: Reserved for KSEG2 */
#else UPU
		:3,
		pg_swapm:1,		/* SW: page must be forced to swap */
#endif
		pg_flush:1,		/* SW: flush i-cache before use */
		pg_fod:1,		/* SW: is fill on demand (=0) */
		pg_prot:2;		/* SW: access control */
#endif MIPSEB
#ifdef MIPSEL
unsigned int	pg_prot:2,		/* SW: access control */
		pg_fod:1,		/* SW: is fill on demand (=0) */
		pg_flush:1,		/* SW: flush i-cache before use */
#ifdef RPU
		pg_rk2:1,		/* RTE: Reserved for KSEG2 */
		pg_uk2:1,		/* RTE: Used in KSEG2 */
		pg_rku:1,		/* RTE: Reserved for KUSEG */
		pg_uku:1,		/* RTE: Used in KUSEG */
#else UPU
		pg_swapm:1,		/* SW: page must be forced to swap */
		:3,
#endif
		pg_g:1,			/* HW: ignore pid bit */
		pg_v:1,			/* HW: valid bit */
		pg_m:1,			/* HW: modified (dirty) bit */
		pg_n:1,			/* HW: non-cacheable bit */
		pg_pfnum:20;		/* HW: core page frame number or 0 */
#endif MIPSEL
};
struct hpte
{
#ifdef MIPSEB
unsigned int	pg_pfnum:20,
		pg_high:12;		/* special for clustering */
#endif MIPSEB
#ifdef MIPSEL
unsigned int	pg_high:12,		/* special for clustering */
		pg_pfnum:20;
#endif MIPSEL
};
struct fpte
{
#ifdef MIPSEB
unsigned int	pg_blkno:20,		/* file system block number */
		:4,			/* overlays v,m,g,n bits */
		pg_fileno:4,		/* file mapped from or TEXT or ZERO */
		pg_flush:1,		/* flush i-cache before use */
		pg_fod:1,		/* is fill on demand (=1) */
		pg_prot:2;
#endif MIPSEB
#ifdef MIPSEL
unsigned int	pg_prot:2,
		pg_fod:1,		/* is fill on demand (=1) */
		pg_flush:1,		/* flush i-cache before use */
		pg_fileno:4,		/* file mapped from or TEXT or ZERO */
		:4,			/* overlays v,m,g,n bits */
		pg_blkno:20;		/* file system block number */
#endif MIPSEL
};
#endif LANGUAGE_C

#define	PG_PFNUM	0xfffff000
#define	PG_N		0x00000800
#define	PG_M		0x00000400
#define	PG_V		0x00000200
#define	PG_G		0x00000100
#define	PG_FILENO	0x000000f0
#define	PG_SWAPM	0x00000010
#define PG_FLUSH	0x00000008
#define	PG_FOD		0x00000004
#define	PG_PROT		0x00000003

#define	PG_FZERO	(14)
#define	PG_FTEXT	(15)
#define	PG_FMAX		(PG_FTEXT)

#ifdef RPU
#define PG_UKU		0x00000080
#define	PG_RKU		0x00000040
#define	PG_UK2		0x00000020
#define	PG_RK2		0x00000010
#endif

#define	PG_KR		0x00000000
#define	PG_KW		0x00000001
#define	PG_URKR		0x00000002
#define	PG_UW		0x00000003

#define	PROT_KR		0
#define	PROT_KW		1
#define	PROT_URKR	2
#define	PROT_UW		3

#define	PTE_PFNSHIFT	12
#define	PTE_FILENOSHIFT	4


/*
 * Pte related macros
 */
#define	dirty(pte)	\
    ((pte)->pg_fod == 0 && (pte)->pg_pfnum && ((pte)->pg_m || (pte)->pg_swapm))

#ifdef LANGUAGE_C
#endif LANGUAGE_C
