home *** CD-ROM | disk | FTP | other *** search
- /*
- * @(#) seg.h 2.3 88/12/09
- *
- * Copyright (C) The Santa Cruz Operation, 1984, 1985, 1986, 1987, 1988.
- * Copyright (C) Microsoft Corporation, 1984, 1985, 1986, 1987, 1988.
- * This Module contains Proprietary Information of
- * The Santa Cruz Operation, Microsoft Corporation
- * and AT&T, and should be treated as Confidential.
- */
-
- #ifdef M_I386
-
- /*
- * format of a descriptor
- *
- * N.B. - the value of d_type has different meanings
- * depending on the value of d_segment.
- */
- struct descriptor {
- unsigned short d_limitlo; /* low 16 bits of limit */
- unsigned short d_baselo:16; /* low 16 bits of base */
- unsigned char d_basemid:8; /* mid 8 bits of base */
- unsigned char d_type:4; /* type of control descr */
- unsigned char d_segment:1; /* 1 = seg descr, 0 = control descr */
- unsigned char d_dpl:2; /* descriptor priv level */
- unsigned char d_present:1; /* 0 = not present, 1 = present */
- unsigned char d_limithi:4; /* high 4 bits of limit */
- unsigned char d_avail:1; /* not used */
- unsigned char d_zero:1; /* must be zero */
- unsigned char d_size:1; /* default op/addr size */
- unsigned char d_gran:1; /* granularity of limit */
- unsigned char d_basehi:8; /* high 8 bits of base */
- };
-
- /*
- * values of d_type when d_segment is zero
- */
- #define DT_UNDEF0 0 /* undefined */
- #define DT_ATSS286 1 /* available 286 tss */
- #define DT_LDT 2 /* local descriptor table */
- #define DT_BTSS286 3 /* busy 286 tss */
- #define DT_CALLGT286 4 /* 286 call gate */
- #define DT_TASKGT 5 /* task gate */
- #define DT_INTRGT286 6 /* 286 interrupt gate */
- #define DT_TRAPGT286 7 /* 286 trap gate */
- #define DT_UNDEF8 8 /* undefined */
- #define DT_ATSS 9 /* available 386 tss */
- #define DT_UNDEF10 10 /* undefined */
- #define DT_BTSS 11 /* busy 386 tss */
- #define DT_CALLGT 12 /* 386 call gate */
- #define DT_UNDEF13 13 /* undefined */
- #define DT_INTRGT 14 /* 386 interrupt gate */
- #define DT_TRAPGT 15 /* 386 trap gate */
-
- /*
- * values of d_type when d_seg is one
- */
- #define DT_ACCESSED 1 /* segment has been accessed */
- #define DT_WRITE 2 /* data segment is writable */
- #define DT_READ 2 /* code segment is readable */
- #define DT_EXDOWN 4 /* segment expands down */
- #define DT_CONFORM 4 /* code segment is conforming */
- #define DT_ISCODE 8 /* segment is code */
-
- /*
- * d_type values for standard code or data segments
- */
- #define DT_CODE (DT_ISCODE|DT_READ)
- #define DT_DATA (DT_WRITE)
-
-
- /*
- * values of d_segment
- */
- #define DS_CTRL 0
- #define DS_SEG 1
-
- /*
- * values of d_dpl
- */
- #define DPL_KERNEL 0
- #define DPL_USER 3
-
- /*
- * values of d_present
- */
- #define DP_ABSENT 0
- #define DP_PRESENT 1
-
-
- /*
- * values of d_size
- */
- #define DSZ_16BIT 0
- #define DSZ_32BIT 1
-
- /*
- * values of d_gran
- */
- #define DG_BYTE 0
- #define DG_PAGE 1
-
- /*
- * macros to strip out proper parts
- * of base and limit to match struct
- */
- #define baselo(a) (((int)(a)) & 0xffff) /* bits 0 - 15 */
- #define basemid(a) ((((int)(a)) >> 16) & (0xff)) /* bits 16 - 23 */
- #define basehi(a) (((int)(a)) >> 24) /* bits 24 - 31 */
- #define limitlo(l) (((int)(l)) & (0xffff)) /* bits 0 - 15 */
- #define limithi(l) ((((int)(l)) >> 16) & (0xf)) /* bits 16 - 19 */
-
- /*
- * macros to get base and limit values out of descriptor structure
- * into a long.
- */
- #define desc_limit(a) (((long) (a).d_limithi << 16) | (a).d_limitlo)
- #define desc_base(a) (((long) (a).d_basehi << 24) | \
- ((long) (a).d_basemid << 16) | \
- (a).d_baselo)
-
- /*
- * format of a selector
- */
- struct selector {
- unsigned s_rpl:2; /* selector ring priv level */
- unsigned s_ti:1; /* table index, 0 = gdt */
- unsigned s_index:13; /* index into table */
- };
-
-
- /*
- * format of a gate descriptor
- */
- struct gate {
- unsigned short g_offsetlo; /* low 16 bits of offset */
- unsigned short g_sel; /* selector */
- unsigned char g_wcnt:5; /* word count */
- unsigned char g_zero:3; /* must be zero */
- unsigned char g_type:4; /* type of control descriptor */
- unsigned char g_zero2:1; /* must be zero */
- unsigned char g_dpl:2; /* descriptor priv level */
- unsigned char g_present:1; /* 0 = not present, 1 = present */
- unsigned short g_offsethi; /* high 16 bits of offset */
- };
-
- /*
- * macros to strip out proper parts
- * of offset to match struct
- */
- #define offsetlo(a) (((int)a) & 0xffff) /* bits 0 - 15 */
- #define offsethi(a) (((int)a) >> 16) /* bits 16 - 31 */
-
- /*
- * macro to convert selector to offset into table
- */
- #define stoi(sel) (((unsigned short)(sel)) >> 3)
-
- #define NULL_SEL 0x0
- #define GDT_SEL 0x8
- #define IDT_SEL 0x10
- #define KDS_SEL 0x18
- #define KCS_SEL 0x20
- #define EMULU_SEL 0x2B
- #define DEBUG_SEL 0x40
- #define KSS_SEL 0x48
- #define TSS_SEL 0x50
- #define LDT_SEL 0x58
-
- #ifdef VPIX
- #define DFTSS_SEL 0x60
- #endif
-
- #define KWORK1 0x98
-
- #ifdef VPIX
- #define T_TSSSEL 0x100
- #define XTSSSEL 0x108
- #define U_TSSSEL 0x110 /* always points at tss */
- #endif
-
- #define LAST_SEL 0x118
-
- #define SELSZ sizeof(struct descriptor)
-
- #define CGATE_SYS 0x7 /* kernel entry selector (system call) */
- #define CGATE_SIG 0xf /* kernel entry selector (signal return) */
- #define UICPSEL 0x14
- #define UDCPSEL 0x1c
- #define STKALIAS_SEL 0x27 /* alias 32 bit stack selector for emulator */
- #define USERFP_SEL 0x2f /* data selector for emulator */
- #define FIRSTU_SEL 0x3f
-
- /*
- * The following two defines are used in xdata.c. CSALIAS_SEL
- * is a hardwired selector used as the CS alias when execseg
- * is called from a 386 program. Currently the only valid argument
- * for 386 execseg is DSEL386, that is the first and only data
- * selector
- */
- #define CSALIAS_SEL 0x37 /* CS alias to DS for 386 programs */
- #define DSEL386 0x47 /* 386 Data Selector, Hardwired */
-
- #define NGDT 60 /* number of GDT entries */
- #define MAXLDT 8192 /* maximum number of LDT entries */
-
- struct tss {
- unsigned t_link; /* link to previous tss */
- unsigned t_esp0; /* level 0 stack pointer (ss0:esp0) */
- unsigned t_ss0;
- unsigned t_esp1; /* level 1 stack pointer (ss1:esp1) */
- unsigned t_ss1;
- unsigned t_esp2; /* level 2 stack pointer (ss2:esp2) */
- unsigned t_ss2;
- unsigned t_cr3; /* swapped on a task switch */
- unsigned t_eip;
- unsigned t_eflags;
- unsigned t_eax;
- unsigned t_ecx;
- unsigned t_edx;
- unsigned t_ebx;
- unsigned t_esp;
- unsigned t_ebp;
- unsigned t_esi;
- unsigned t_edi;
- unsigned t_es;
- unsigned t_cs;
- unsigned t_ss;
- unsigned t_ds;
- unsigned t_fs;
- unsigned t_gs;
- unsigned t_ldt; /* ldt selector */
- #ifdef VPIX
- unsigned short t_debugtrap:1; /* if 1 in "new" tss get debug except */
- unsigned short t_res:15; /* Intel reserved */
- unsigned short t_bitmapbase; /* I/O bit map base address */
- #else
- unsigned char t_debugtrap:1; /* if 1 in "new" tss get debug except */
- unsigned long t_avail:31; /* available for use */
- #endif
- };
-
- #ifdef VPIX
- #define MAXTSSSIZE 0x10000 /* Maximum size of tss = 64k */
- #define MAXTSSIOADDR 0x8000 /* largest I/O address for now */
- #endif
-
- /*
- * ldtinfo flag values indicating the type of segment represented
- */
-
- #define LT_OWN 0x0001 /* maps user-owned, private memory */
- #define LT_ITER 0x0008 /* iterated data or text segment */
- #define LT_EXEC 0x0080 /* executable segment */
- #define LT_RO 0x0100 /* read-only segment */
-
- struct ldtinfo {
- unsigned short flag;
- long filpos; /* file position */
- long psize; /* physical size (in file) */
- long limit; /* virtual size (in core) */
- long rbase; /* relocation base address/offset */
- };
-
- #define SOTOFAR(seg,off) ((unsigned)((unsigned)(seg) << 16) | (off))
- #define FTOOFF(farp) loword((farp))
- #define FTOSEG(farp) hiword((farp))
-
- extern struct gate sysc_gt; /* system call gate template */
- extern struct gate sigr_gt; /* signal return template */
- #endif
-