home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v1.zip / DDKX86 / H / SELDESC.H < prev    next >
C/C++ Source or Header  |  1995-04-14  |  10KB  |  275 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT (C) Microsoft Corporation, 1989                                 */
  4. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  5. /*                                                                           */
  6. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  7. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  8. /*    drivers. You may use this code in accordance with the IBM License      */
  9. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  10. /*    Copyright statement may not be removed.                                */
  11. /*                                                                           */
  12. /*****************************************************************************/
  13. /*static char *SCCSID = "@(#)seldesc.h    6.1 90/11/16";*/
  14. /*    SCCSID = @(#)seldesc.h    13.2  90/07/10     */
  15.  
  16.  
  17. /*
  18.  *
  19.  *
  20.  */
  21.  
  22.  
  23. /*
  24. ;----------------------------------------------------
  25. ;
  26. ;   Some useful definitions
  27. ;
  28. ;----------------------------------------------------
  29. */
  30.  
  31. /* Definitions for selector fields */
  32.  
  33. #define TABLE_MASK    0x004
  34. #define RPL_MASK    0x003
  35. #define RPL_CLR        0x0fffc
  36.  
  37. #define RPL_RING0    0x000
  38. #define RPL_RING1    0x001
  39. #define RPL_RING2    0x002
  40. #define RPL_RING3    0x003
  41.  
  42.  
  43.  
  44. /*
  45. ; ---------------------------------------------------
  46. ;
  47. ; Definitions for the access byte in a descriptor
  48. ;
  49. ; ---------------------------------------------------
  50. */
  51.  
  52. /* Following fields are common to segment and control descriptors */
  53.  
  54. #define        D_PRES    0x80        /* present in memory */
  55. #define        D_NOTPRES    0        /* not present in memory*/
  56.  
  57. #define        D_DPL0    0        /* Ring 0 */
  58. #define        D_DPL1    0x20        /* Ring 1 */
  59. #define        D_DPL2    0x40        /* Ring 2 */
  60. #define        D_DPL3    0x60        /* Ring 3 */
  61. #define        D_PRIV    D_DPL3        /* DPL mask */
  62.  
  63. #define        D_SEG    0x10        /* Segment descriptor */
  64. #define        D_CTRL    0        /* Control descriptor */
  65.  
  66.  
  67. /* Following fields are specific to control descriptors */
  68.  
  69. #define        D_TSS_BUSY_BIT  0x2            /* TSS busy bit */
  70. #define        D_GATE        0x4            /* gate bit */
  71. #define        D_32        0x8            /* 32 bit gate/descriptor bit */
  72. #define        D_TSS        0x1            /* A Free TSS */
  73. #define        D_LDT        0x2            /* LDT */
  74. #define        D_TSS_BUSY        (D_TSS+D_TSS_BUSY_BIT) /* A Busy TSS */
  75. #define        D_CALLGATE        (D_GATE+0)        /* call gate */
  76. #define        D_TASKGATE        (D_GATE+1)        /* task gate */
  77. #define        D_INTGATE        (D_GATE+2)        /* interrupt gate  */
  78. #define        D_TRAPGATE        (D_GATE+3)        /* trap gate */
  79. #define        D_TSS32        (D_TSS+D_32)    /* 32 bit TSS */
  80. #define        D_TSSBUSY32        (D_TSS_BUSY+D_32) /* busy 32 bit TSS */
  81. #define        D_CALLGATE32    (D_CALLGATE+D_32) /* 32 bit call gate */
  82. #define        D_INTGATE32        (D_INTGATE+D_32)    /* 32 bit interrupt gate */
  83. #define        D_TRAPGATE32    (D_TRAPGATE+D_32)    /* 32 bit trap gate */
  84.  
  85. #define        D_TYPEMASK        0x0f         /* descriptor type mask */
  86. #define        D_WCMASK        0x01f         /* word count mask (call gates) */
  87. #define        D_MINGATE        D_CALLGATE         /* lowest numerical gate type */
  88. #define        D_MAXGATE        D_TRAPGATE32     /* highest numerical gate type */
  89.  
  90. #define        D_TSSBUSY_CLR   (~D_TSS_BUSY_BIT)
  91.  
  92. /* Following fields are specific to segment descriptors */
  93.  
  94. #define        D_CODE        0x8            /* code */
  95. #define        D_DATA        0            /* data */
  96.  
  97. #define        D_CONFORM        0x4            /* if code, conforming */
  98. #define        D_EXPDN        0x4            /* if data, expand down */
  99.  
  100. #define        D_RX        0x2            /* if code, readable */
  101. #define        D_X            0            /* if code, exec only */
  102. #define        D_W            0x2            /* if data, writable */
  103. #define        D_R            0            /* if data, read only */
  104.  
  105. #define        D_ACCESSED        0x1            /* segment accessed bit */
  106.  
  107. /*
  108. ; ---------------------------------------------------
  109. ;
  110. ; Definitions for the attribute byte in a descriptor
  111. ;
  112. ; ---------------------------------------------------
  113. */
  114.  
  115. #define D_GRAN4K    0x80        /* 4k granularity (limit only) */
  116. #define D_COPER32   0x40        /* code: use 32 bit operand size */
  117. #define D_DBIG        D_COPER32        /* data: use 32 bit offsets */
  118. #define D_PAD        0x20        /* unused */
  119. #define D_UVIRT        0x10        /* PhysToUvirt selector */
  120. #define D_EXTLIMIT  0x0f        /* extended limit mask */
  121. #define D_1MEG        0x100000        /* 1 Meg */
  122. #define D_GRANMASK  0x0fffff         /* 1Meg - 1 */
  123.  
  124. /* Useful combination access rights bytes */
  125.  
  126. #define D_DATA0        (D_PRES+D_DPL0+D_SEG+D_DATA+D_W)     /* Ring 0 rw data */
  127. #define D_CODE0        (D_PRES+D_DPL0+D_SEG+D_CODE+D_RX)     /* Ring 0 rx code */
  128. #define D_TRAP0        (D_PRES+D_DPL0+D_CTRL+D_TRAPGATE)     /* Ring 0 trap gate */
  129. #define D_INT0        (D_PRES+D_DPL0+D_CTRL+D_INTGATE)     /* Ring 0 int gate */
  130. #define D_TASK0        (D_PRES+D_DPL0+D_CTRL+D_TASKGATE)     /* Ring 0 task gate */
  131. #define D_TSS0        (D_PRES+D_DPL0+D_CTRL+D_TSS)     /* Ring 0 TSS */
  132. #define D_LDT0        (D_PRES+D_DPL0+D_CTRL+D_LDT)     /* Ring 0 LDT */
  133. #define D_TRAP032   (D_PRES+D_DPL0+D_CTRL+D_TRAPGATE32) /* Ring 0 32-bit TG */
  134. #define D_INT032    (D_PRES+D_DPL0+D_CTRL+D_INTGATE32)    /* Ring 0 32-bit IG */
  135. #define D_TSS032    (D_PRES+D_DPL0+D_CTRL+D_TSS32)    /* Ring 0 32-bit TSS*/
  136.  
  137. #define D_DATA1        (D_PRES+D_DPL1+D_SEG+D_DATA+D_W)     /* Ring 1 rw data */
  138. #define D_CODE1        (D_PRES+D_DPL1+D_SEG+D_CODE+D_RX)     /* Ring 1 rx code */
  139.  
  140. #define D_DATA2        (D_PRES+D_DPL2+D_SEG+D_DATA+D_W)     /* Ring 2 rw data */
  141. #define D_CODE2        (D_PRES+D_DPL2+D_SEG+D_CODE+D_RX)     /* Ring 2 rx code */
  142.  
  143. #define D_DATA3        (D_PRES+D_DPL3+D_SEG+D_DATA+D_W)     /* Ring 3 rw data */
  144. #define D_CODE3        (D_PRES+D_DPL3+D_SEG+D_CODE+D_RX)     /* Ring 3 rx code */
  145. #define D_INT3        (D_PRES+D_DPL3+D_CTRL+D_INTGATE)     /* Ring 3 int gate */
  146. #define D_TRAP3        (D_PRES+D_DPL3+D_CTRL+D_TRAPGATE)     /* Ring 3 trap gate */
  147. #define D_GATE3        (D_PRES+D_DPL3+D_CTRL+D_CALLGATE)     /* Ring 3 call gate */
  148. #define D_INT332    (D_PRES+D_DPL3+D_CTRL+D_INTGATE32)    /* Ring 3 32 bit int */
  149. #define D_GATE332   (D_PRES+D_DPL3+D_CTRL+D_CALLGATE32) /* Ring 3 32-bit CG */
  150. #define D_TRAP332   (D_PRES+D_DPL3+D_CTRL+D_TRAPGATE32) /* Ring 3 32-bit TG */
  151.  
  152.  
  153. /* Descriptor definition */
  154.  
  155. struct desctab {
  156.     ushort_t d_limit;     /* Segment limit */
  157.     ushort_t d_loaddr;    /* Low word of physical address */
  158.     unsigned char  d_hiaddr;    /* High byte of physical address */
  159.     unsigned char  d_access;    /* Access byte */
  160.     unsigned char  d_attr;        /* Attributes/extended limit */
  161.     unsigned char  d_extaddr;   /* Extended physical address byte */
  162. };
  163.  
  164.  
  165. struct desc32    {
  166.     ulong_t    d32_low;    /* low dword in descriptor */
  167.     ulong_t    d32_high;   /* high dword in descriptor */
  168. };
  169.  
  170. /*     GDT free list descriptor definitions */
  171.  
  172. #define d_flink        d_loaddr            /* Forward link */
  173. #define d_blink        d_limit            /* Back link */
  174.  
  175. /* XLATOFF */
  176. struct gate {
  177.     ushort_t    g_lowoffset;    /* low word of offset */
  178.     ushort_t    g_sel;        /* selector to gate segment */
  179.     uchar_t        g_parms;    /* Parameter word count for call gate */
  180.     uchar_t        g_access;    /* Access byte */
  181.     ushort_t    g_extoffset;    /* Extended target offset */
  182. };
  183.  
  184. /* XLATON */
  185. /*  Following is for the old masm code only */
  186.  
  187. /* ASM
  188.  
  189. gate    STRUC
  190. g_handler    DD    ?
  191. g_parms        DB    ?
  192. g_access    DB    ?
  193. g_extoffset    DW    ?
  194. gate    ENDS
  195.  
  196. g_lowoffset EQU        WORD PTR g_handler
  197. g_sel        EQU        WORD PTR g_handler + 2
  198.  
  199. */
  200.  
  201. /* LIDT/SIDT, LGDT/SGDT structure */
  202.  
  203. struct lidt_s {
  204.     ushort_t lidt_limit; /* limit of idt or gdt */
  205.     ulong_t lidt_base;   /* base of idt or gdt */
  206. };
  207.  
  208. /*
  209. ;    Task State Segment structure definition
  210. */
  211.  
  212. struct tss_s {
  213.     ushort_t  tss_backlink;   /* backlink to prev task (none) */
  214.     ushort_t  tss_reservdbl;
  215.     ulong_t   tss_esp0;
  216.     ushort_t  tss_ss0;        /* ring 0 ss */
  217.     ushort_t  tss_reservdss0;
  218.     ulong_t   tss_esp1;        /* ring 1 esp */
  219.     ushort_t  tss_ss1;        /* ring 1 ss */
  220.     ushort_t  tss_reservdss1;
  221.     ulong_t   tss_esp2;        /* ring 2 esp */
  222.     ushort_t  tss_ss2;        /* ring 2 ss */
  223.     ushort_t  tss_reservdss2;
  224.     ulong_t   tss_cr3;
  225.     ulong_t   tss_eip;         /* entry point */
  226.     ulong_t   tss_eflags;     /* eflags */
  227.     ulong_t   tss_eax;
  228.     ulong_t   tss_ecx;
  229.     ulong_t   tss_edx;
  230.     ulong_t   tss_ebx;
  231.     ulong_t   tss_esp;
  232.     ulong_t   tss_ebp;
  233.     ulong_t   tss_esi;
  234.     ulong_t   tss_edi;
  235.     ushort_t  tss_es;
  236.     ushort_t  tss_reservdes;
  237.     ushort_t  tss_cs;
  238.     ushort_t  tss_reservdcs;
  239.     ushort_t  tss_ss;
  240.     ushort_t  tss_reservdss;
  241.     ushort_t  tss_ds;
  242.     ushort_t  tss_reservdds;
  243.     ushort_t  tss_fs;
  244.     ushort_t  tss_reservdfs;
  245.     ushort_t  tss_gs;
  246.     ushort_t  tss_reservdgs;
  247.     ushort_t  tss_ldt;
  248.     ushort_t  tss_reservdldt;
  249.     ushort_t  tss_tflags;
  250.     ushort_t  tss_iomap;        /* I/O map TSS relative offset */
  251. } ;
  252.  
  253. /* XLATOFF */
  254. typedef struct tss_s TSS;
  255. typedef TSS *PTSS;
  256. /* XLATON */
  257.  
  258.  
  259. /*     tss_tflags bit definitions: */
  260.  
  261. #define TSS_DEBUGTRAP  0x001    /* raise debug exception on task switch */
  262.  
  263. /*     286/386 compatibility definitions: Needs to be included in seldesc.inc
  264.      file. */
  265. /* ASM
  266. tss_sp1        equ    word ptr tss_esp1
  267. tss_sp2        equ    word ptr tss_esp2
  268. tss_sp0        equ    word ptr tss_esp0
  269. tss_ip        equ    word ptr tss_eip
  270. tss_bx        equ    word ptr tss_ebx
  271. tss_sp        equ    word ptr tss_esp
  272. tss_flags    equ    word ptr tss_eflags
  273. tss_cs0        equ    word ptr tss_cs
  274. */
  275.