home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 202.img / SCO386N2.TD0 / usr / include / sys / seg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-09  |  7.4 KB  |  272 lines

  1. /*
  2.  *    @(#) seg.h 2.3 88/12/09 
  3.  *
  4.  *    Copyright (C) The Santa Cruz Operation, 1984, 1985, 1986, 1987, 1988.
  5.  *    Copyright (C) Microsoft Corporation, 1984, 1985, 1986, 1987, 1988.
  6.  *    This Module contains Proprietary Information of
  7.  *    The Santa Cruz Operation, Microsoft Corporation
  8.  *    and AT&T, and should be treated as Confidential.
  9.  */
  10.  
  11. #ifdef M_I386
  12.  
  13. /* 
  14.  * format of a descriptor
  15.  *
  16.  *    N.B. - the value of d_type has different meanings
  17.  *        depending on the value of d_segment.
  18.  */
  19. struct descriptor {
  20.     unsigned short    d_limitlo;    /* low 16 bits of limit */
  21.     unsigned short    d_baselo:16;    /* low 16 bits of base */
  22.     unsigned char    d_basemid:8;    /* mid 8 bits of base */
  23.     unsigned char    d_type:4;    /* type of control descr */
  24.     unsigned char     d_segment:1;    /* 1 = seg descr, 0 = control descr */
  25.     unsigned char    d_dpl:2;    /* descriptor priv level */
  26.     unsigned char    d_present:1;    /* 0 = not present, 1 = present */
  27.     unsigned char    d_limithi:4;    /* high 4 bits of limit */
  28.     unsigned char    d_avail:1;    /* not used */
  29.     unsigned char    d_zero:1;    /* must be zero */
  30.     unsigned char    d_size:1;    /* default op/addr size */
  31.     unsigned char    d_gran:1;    /* granularity of limit */
  32.     unsigned char    d_basehi:8;    /* high 8 bits of base */
  33. };
  34.  
  35. /* 
  36.  * values of d_type when d_segment is zero
  37.  */
  38. #define DT_UNDEF0    0    /* undefined */
  39. #define DT_ATSS286    1    /* available 286 tss */
  40. #define DT_LDT        2    /* local descriptor table */
  41. #define DT_BTSS286    3    /* busy 286 tss */
  42. #define DT_CALLGT286    4    /* 286 call gate */
  43. #define DT_TASKGT    5    /* task gate */
  44. #define DT_INTRGT286    6    /* 286 interrupt gate */
  45. #define DT_TRAPGT286    7    /* 286 trap gate */
  46. #define DT_UNDEF8    8    /* undefined */
  47. #define DT_ATSS        9    /* available 386 tss */
  48. #define DT_UNDEF10    10    /* undefined */
  49. #define DT_BTSS        11    /* busy 386 tss */
  50. #define DT_CALLGT    12    /* 386 call gate */
  51. #define DT_UNDEF13    13    /* undefined */
  52. #define DT_INTRGT    14    /* 386 interrupt gate */
  53. #define DT_TRAPGT    15    /* 386 trap gate */
  54.  
  55. /*
  56.  * values of d_type when d_seg is one
  57.  */
  58. #define DT_ACCESSED    1    /* segment has been accessed */
  59. #define DT_WRITE    2    /* data segment is writable */
  60. #define DT_READ        2    /* code segment is readable */
  61. #define DT_EXDOWN    4    /* segment expands down */
  62. #define DT_CONFORM    4    /* code segment is conforming */
  63. #define DT_ISCODE    8    /* segment is code */
  64.  
  65. /*
  66.  * d_type values for standard code or data segments
  67.  */
  68. #define DT_CODE        (DT_ISCODE|DT_READ)
  69. #define DT_DATA        (DT_WRITE)
  70.  
  71.  
  72. /*
  73.  * values of d_segment
  74.  */
  75. #define DS_CTRL        0
  76. #define DS_SEG        1
  77.  
  78. /*
  79.  * values of d_dpl
  80.  */
  81. #define DPL_KERNEL    0    
  82. #define DPL_USER    3
  83.  
  84. /*
  85.  * values of d_present
  86.  */
  87. #define DP_ABSENT    0
  88. #define DP_PRESENT    1
  89.  
  90.  
  91. /*
  92.  * values of d_size
  93.  */
  94. #define DSZ_16BIT    0
  95. #define DSZ_32BIT    1
  96.  
  97. /*
  98.  * values of d_gran
  99.  */
  100. #define DG_BYTE        0
  101. #define DG_PAGE        1
  102.  
  103. /*
  104.  * macros to strip out proper parts 
  105.  * of base and limit to match struct
  106.  */
  107. #define baselo(a)    (((int)(a)) & 0xffff)        /* bits 0 - 15 */
  108. #define basemid(a)    ((((int)(a)) >> 16) & (0xff))    /* bits 16 - 23 */
  109. #define basehi(a)    (((int)(a)) >> 24)        /* bits 24 - 31 */
  110. #define limitlo(l)    (((int)(l)) & (0xffff))        /* bits 0 - 15 */
  111. #define limithi(l)    ((((int)(l)) >> 16) & (0xf))     /* bits 16 - 19 */
  112.  
  113. /*
  114.  * macros to get base and limit values out of descriptor structure
  115.  * into a long.
  116.  */
  117. #define desc_limit(a)    (((long) (a).d_limithi << 16) |    (a).d_limitlo)
  118. #define desc_base(a)    (((long) (a).d_basehi << 24) |        \
  119.             ((long) (a).d_basemid << 16) |        \
  120.                 (a).d_baselo)
  121.  
  122. /*
  123.  * format of a selector
  124.  */
  125. struct selector {
  126.     unsigned s_rpl:2;    /* selector ring priv level */
  127.     unsigned s_ti:1;    /* table index, 0 = gdt */
  128.     unsigned s_index:13;    /* index into table */
  129. };
  130.  
  131.  
  132. /*
  133.  * format of a gate descriptor
  134.  */
  135. struct gate {
  136.     unsigned short    g_offsetlo;    /* low 16 bits of offset */
  137.     unsigned short    g_sel;      /* selector */
  138.     unsigned char    g_wcnt:5;    /* word count */
  139.     unsigned char    g_zero:3;    /* must be zero */
  140.     unsigned char    g_type:4;    /* type of control descriptor */
  141.     unsigned char    g_zero2:1;    /* must be zero */
  142.     unsigned char    g_dpl:2;    /* descriptor priv level */
  143.     unsigned char    g_present:1;    /* 0 = not present, 1 = present */
  144.     unsigned short    g_offsethi;    /* high 16 bits of offset */
  145. };
  146.  
  147. /*
  148.  * macros to strip out proper parts 
  149.  * of offset to match struct
  150.  */
  151. #define offsetlo(a)    (((int)a) & 0xffff)        /* bits 0 - 15 */
  152. #define offsethi(a)    (((int)a) >> 16)        /* bits 16 - 31 */
  153.  
  154. /* 
  155.  * macro to convert selector to offset into table
  156.  */
  157. #define stoi(sel)    (((unsigned short)(sel)) >> 3)
  158.  
  159. #define NULL_SEL    0x0
  160. #define GDT_SEL        0x8
  161. #define IDT_SEL        0x10
  162. #define KDS_SEL        0x18
  163. #define KCS_SEL        0x20
  164. #define EMULU_SEL    0x2B
  165. #define DEBUG_SEL    0x40
  166. #define KSS_SEL        0x48
  167. #define TSS_SEL        0x50
  168. #define LDT_SEL        0x58
  169.  
  170. #ifdef VPIX
  171. #define DFTSS_SEL    0x60
  172. #endif
  173.  
  174. #define KWORK1        0x98
  175.  
  176. #ifdef VPIX
  177. #define T_TSSSEL    0x100
  178. #define XTSSSEL        0x108
  179. #define U_TSSSEL    0x110        /* always points at tss */
  180. #endif
  181.  
  182. #define LAST_SEL    0x118
  183.  
  184. #define SELSZ        sizeof(struct descriptor)
  185.  
  186. #define    CGATE_SYS    0x7    /* kernel entry selector (system call) */
  187. #define    CGATE_SIG    0xf    /* kernel entry selector (signal return) */
  188. #define UICPSEL        0x14
  189. #define UDCPSEL        0x1c
  190. #define STKALIAS_SEL    0x27    /* alias 32 bit stack selector for emulator */
  191. #define USERFP_SEL    0x2f    /* data selector for emulator */
  192. #define FIRSTU_SEL    0x3f
  193.  
  194. /*
  195.  *    The following two defines are used in xdata.c. CSALIAS_SEL
  196.  *    is a hardwired selector used as the CS alias when execseg
  197.  *    is called from a 386 program. Currently the only valid argument
  198.  *    for 386 execseg is DSEL386, that is the first and only data
  199.  *    selector
  200.  */
  201. #define CSALIAS_SEL    0x37    /* CS alias to DS for 386 programs */
  202. #define DSEL386        0x47    /* 386 Data Selector, Hardwired */
  203.  
  204. #define NGDT        60        /* number of GDT entries */
  205. #define    MAXLDT        8192        /* maximum number of LDT entries */
  206.  
  207. struct tss {
  208.     unsigned t_link;        /* link to previous tss */
  209.     unsigned t_esp0;        /* level 0 stack pointer (ss0:esp0) */
  210.     unsigned t_ss0;
  211.     unsigned t_esp1;        /* level 1 stack pointer (ss1:esp1) */
  212.     unsigned t_ss1;
  213.     unsigned t_esp2;        /* level 2 stack pointer (ss2:esp2) */
  214.     unsigned t_ss2;
  215.     unsigned t_cr3;            /* swapped on a task switch */
  216.     unsigned t_eip;
  217.     unsigned t_eflags;
  218.     unsigned t_eax;
  219.     unsigned t_ecx;
  220.     unsigned t_edx;
  221.     unsigned t_ebx;
  222.     unsigned t_esp;
  223.     unsigned t_ebp;
  224.     unsigned t_esi;
  225.     unsigned t_edi;
  226.     unsigned t_es;
  227.     unsigned t_cs;
  228.     unsigned t_ss;
  229.     unsigned t_ds;
  230.     unsigned t_fs;
  231.     unsigned t_gs;
  232.     unsigned t_ldt;            /* ldt selector */    
  233. #ifdef VPIX
  234.     unsigned short t_debugtrap:1;    /* if 1 in "new" tss get debug except */
  235.     unsigned short t_res:15;     /* Intel reserved */
  236.     unsigned short t_bitmapbase;    /* I/O bit map base address */
  237. #else
  238.     unsigned char t_debugtrap:1;    /* if 1 in "new" tss get debug except */
  239.     unsigned long t_avail:31;    /* available for use */
  240. #endif
  241. };
  242.  
  243. #ifdef VPIX
  244. #define MAXTSSSIZE    0x10000        /* Maximum size of tss = 64k */
  245. #define MAXTSSIOADDR    0x8000        /* largest I/O address for now */
  246. #endif
  247.  
  248. /* 
  249.  * ldtinfo flag values indicating the type of segment represented
  250.  */
  251.  
  252. #define LT_OWN        0x0001        /* maps user-owned, private memory */
  253. #define LT_ITER        0x0008        /* iterated data or text segment */
  254. #define LT_EXEC        0x0080        /* executable segment */
  255. #define LT_RO        0x0100        /* read-only segment */
  256.  
  257. struct ldtinfo {                
  258.     unsigned short flag;
  259.     long        filpos;    /* file position */
  260.     long        psize;    /* physical size (in file) */
  261.     long        limit;    /* virtual size (in core) */
  262.     long        rbase;    /* relocation base address/offset */
  263. };
  264.  
  265. #define SOTOFAR(seg,off)    ((unsigned)((unsigned)(seg) << 16) | (off))
  266. #define FTOOFF(farp)        loword((farp))
  267. #define FTOSEG(farp)        hiword((farp))
  268.  
  269. extern struct gate sysc_gt;        /* system call gate template */
  270. extern struct gate sigr_gt;        /* signal return template */
  271. #endif
  272.