home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 7.ddi / INCLUDES / HW386.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-26  |  13.1 KB  |  420 lines

  1. /* HW386.H - Hardware defintions for the 80386 CPU */
  2. /* $Id: hw386.h 1.4 90/06/26 11:24:23 diego Exp $ */
  3.  
  4. /************************************************************************/
  5. /*    Copyright (C) 1986-1988 Phar Lap Software, Inc.            */
  6. /*    Unpublished - rights reserved under the Copyright Laws of the    */
  7. /*    United States.  Use, duplication, or disclosure by the         */
  8. /*    Government is subject to restrictions as set forth in         */
  9. /*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  10. /*    Computer Software clause at 252.227-7013.            */
  11. /*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  12. /************************************************************************/
  13.  
  14. /*
  15.  
  16. This file contains C language definitions for the Intel 80386 CPU.
  17. The following definitions are present in the file:
  18.  
  19.     * Format of selector numbers
  20.     * Format of segment descriptors in the LDT, GDT, and IDT
  21.     * Format of the special 386 registers including the FLAGS,    
  22.       CR0, and DR7
  23.     * Format of page table entries
  24.     * Reserved interrupt numbers for exceptions
  25.     * 286 and 386 TSS formats
  26.  
  27. */
  28.  
  29.  
  30. /*
  31.  
  32. Masks for various fields in segment selector values
  33.  
  34. */
  35.  
  36. #define SEL_IDX 0xFFF8        /* index into GDT or LDT */
  37. #define SEL_GDT    0x0000        /* GDT selector */
  38. #define SEL_LDT    0x0004        /* LDT selector */
  39. #define SEL_RPL    0x0003        /* requested privilege level */
  40.  
  41.  
  42. /*
  43.  
  44. 80386 segment descriptors
  45.  
  46. */
  47.  
  48. typedef struct
  49. {
  50.     USHORT limit0_15;        /* Bits 0-15 of the segment limit */
  51.     USHORT base0_15;        /* Bits 0-15 of the segment base */
  52.     UCHAR base16_23;        /* Bits 16-23 of the segment base */
  53.     UCHAR arights;            /* Access rights */
  54.     UCHAR limit16_19;        /* Bits 16-19 of the segment limit
  55.                        plus some flags */
  56.     UCHAR base24_31;        /* Bits 24-31 of the segment base */
  57. } CD_DES;
  58.  
  59. typedef struct
  60. {
  61.     USHORT    loffs;        /* bits 0-15 of handler offset */
  62.     USHORT    select;        /* segment selector handler is in */
  63.     UCHAR    wcount;        /* word count field;  unused */
  64.     UCHAR    arights;    /* access rights byte */
  65.     USHORT    hoffs;        /* bits 16-31 of handler offset */
  66. } IT_DES;
  67.  
  68.  
  69. /* Access rights */
  70.  
  71. #define AR_ACCESSED    0x01        /* Segment was accessed */
  72.  
  73. #define AR_CREAD    0x02        /* Code segment is readable flag */
  74. #define AR_CCONF    0x04        /* Code segment is conforming */
  75. #define AR_CSEG        0x08        /* Is a code segment */
  76.  
  77. #define AR_DREADO    0x00        /* Read only data segment */
  78. #define AR_DWRITE    0x02        /* Read/write data segment */
  79. #define AR_EUP        0x00        /* Expand up */
  80. #define AR_EDOWN    0x04        /* Expand down */
  81.  
  82. #define AR_SYS        0x00        /* System descriptor */
  83. #define AR_USER        0x10        /* User descriptor */
  84.  
  85. #define AR_DPLM        0x60        /* DPL mask */
  86. #define AR_DPLSC    5        /* DPL shift count */
  87. #define AR_DPL0        0x00        /* DPL 0 */
  88. #define AR_DPL1        0x20        /* DPL 1 */
  89. #define AR_DPL2        0x40        /* DPL 2 */
  90. #define AR_DPL3        0x60        /* DPL 3 */
  91.  
  92. #define AR_PRESENT    0x80        /* Segment is present */
  93.  
  94. #define AR_CODE    (AR_PRESENT | AR_USER | AR_CSEG | AR_CREAD)
  95. #define AR_DATA    (AR_PRESENT | AR_USER | AR_DWRITE)
  96.  
  97. /* Flags (limit16_19) */
  98.  
  99. #define SG_BYTE     0x00            /* Byte segment granularity */
  100. #define SG_PAGE     0x80            /* Page segment granularity */
  101.  
  102. #define DOS_16   0x00            /* Default operand size is 16 */
  103. #define DOS_32   0x40            /* Default operand size is 32 */
  104.  
  105. #define SW_AVL    0x10            /* bit available for system software */
  106.  
  107. #define D6_HLIM     0x0F            /* bits 16-19 of limit */
  108.  
  109.  
  110. /*
  111.  
  112. System segment descriptor types
  113.  
  114. */
  115.  
  116. #define SSDT_A286TSS    1        /* Available 286 TSS */
  117. #define    SSDT_LDT    2        /* LDT */
  118. #define SSDT_B286TSS    3        /* Busy 286 TSS */
  119. #define    SSDT_CG286    4        /* 286 call gate */
  120. #define SSDT_TG        5        /* Task gate */
  121. #define SSDT_IG286    6        /* 286 interrupt gate */
  122. #define SSDT_XG286    7        /* 286 trap gate */
  123.  
  124. #define SSDT_A386TSS    9        /* Available 386 TSS */
  125. #define SSDT_B386TSS    11        /* Busy 386 TSS */
  126. #define    SSDT_CG386    12        /* 386 call gate */
  127. #define SSDT_IG386    14        /* 386 interrupt gate */
  128. #define SSDT_XG386    15        /* 386 trap gate */
  129.  
  130. #define SSDT_MASK    0x1F        /* Mask for segment/gate type */
  131. #define SSDT_TSSBSY    0x02        /* TSS is busy */
  132.  
  133. #define SSDP_MASK    0x60        /* Mask for DPL */
  134. #define SSDP_SHFT    0x05        /* Shift left 5 bits */
  135.  
  136. /*
  137.  
  138. EFLAGS register definitions
  139.  
  140. */
  141.  
  142. #define EF_AC    0x00040000L        /* alignment check flag, 486 only */
  143. #define EF_VM    0x00020000L        /* Virtual 8086 mode */
  144. #define EF_RF    0x00010000L        /* Resume flag */
  145. #define EF_NT     0x00004000L        /* Nested task */
  146. #define EF_IOPL    0x00003000L        /* I/O privilege mask */
  147. #define EF_SC_IOPL 12            /* # bits to shift IOPL */
  148. #define EF_OF    0x00000800L        /* Overflow flag */
  149. #define EF_DF    0x00000400L        /* Direction flag */
  150. #define EF_IF    0x00000200L        /* Interrupt enable flag */
  151. #define EF_TF    0x00000100L        /* Trace flag */
  152. #define EF_SF    0x00000080L        /* Sign flag */
  153. #define EF_ZF    0x00000040L        /* Zero flag */
  154. #define EF_AF    0x00000010L        /* Auxilary carry flag */
  155. #define EF_PF    0x00000004L        /* Parity flag */
  156. #define EF_CF    0x00000001L        /* Carry flag */
  157. #define EF_1BITS 0x00000002L        /* Bits always set to 1 in EFLAGS */
  158. #define EF_DEFINED    0x00037FD7L    /* mask for all defined bits on 386 */
  159. #define EF_486DEFINED    0x00077FD7L    /* mask for all defined bits on 486 */
  160.  
  161. /*
  162.  
  163. Control register 0 (CR0) definitions
  164.  
  165. */
  166.  
  167. #define CR0_PG    0x80000000L        /* Paging enabled */
  168. #define CR0_CD    0x40000000L        /* cache disable, 486 only */
  169. #define CR0_NW    0x20000000L        /* not write-through, 486 only */
  170. #define CR0_AM    0x00040000L        /* alignment check enable, 486 only */
  171. #define CR0_WP    0x00010000L    /* write protect at priv lev 0-2, 486 only */
  172. #define CR0_NE    0x00000020L    /* numerics exception enable, 486 only */
  173. #define CR0_ET  0x00000010L        /* 287 vs 387 flag */
  174. #define CR0_TS  0x00000008L        /* Task switched */
  175. #define CR0_EM  0x00000004L        /* Emulate coprocessor */
  176. #define CR0_MP    0x00000002L        /* Monitor coprocessor */
  177. #define CR0_PE    0x00000001L        /* Protected mode */
  178. #define CR0_DEFINED 0x8000001FL        /* mask for all defined bits on 386 */
  179. #define CR0_486DEFINED 0xE005003FL    /* mask for all defined bits on 486 */
  180.  
  181.  
  182. /*
  183. Control register 3 (CR3) definitions
  184. */
  185. #define CR3_PCD        0x00000010L    /* page cache disable, 486 only */
  186. #define CR3_PWT        0x00000008L    /* page write-thru, 486 only */
  187. #define CR3_DEFINED    0xFFFFF000L    /* mask for all defined bits on 386 */
  188. #define CR3_486DEFINED    0xFFFFF018L    /* mask for all defined bits on 486 */
  189.  
  190.  
  191. /*
  192.  
  193. Debug register 6 definitions
  194.  
  195. */
  196.  
  197. #define DR6_B0 0x00000001L        /* Breakpoint 0 */
  198. #define DR6_B1 0x00000002L        /* Breakpoint 1 */
  199. #define DR6_B2 0x00000004L        /* Breakpoint 2 */
  200. #define DR6_B3 0x00000008L        /* Breakpoint 3 */
  201. #define DR6_BD 0x00002000L        /* Debug register accessed */
  202. #define DR6_BS 0x00004000L        /* Single step */
  203. #define DR6_BT 0x00008000L        /* Task switch */
  204. #define DR6_DEFINED 0x0000E00FL        /* mask for all defined bits */
  205.  
  206.  
  207. #define DR6_BSHIFT(n)    (n)        /* Number of bits to shift to get Bn */
  208.  
  209.  
  210. /*
  211.  
  212. Debug register 7 definitions
  213.  
  214. */
  215.  
  216. #define DR7_LE 0x00000100L        /* Enable all local breakpoints */
  217. #define DR7_GE 0x00000200L        /* Enable all global breakpoints */
  218.  
  219. #define DR7_GLMASK 0x00000003L        /* Mask for G and L bits for a bkpt */
  220. #define DR7_GLSHIFT(n) ((n) * 2)    /* Number of bits to shift to get */
  221.                     /* G and L bits for bkpt Bn */
  222. #define DR7_GEMASK 0x00000002L        /* global enable (G bit) mask */
  223. #define DR7_LEMASK 0x00000001L        /* local enable (L bit) mask */
  224.  
  225. #define DR7_RWLMASK 0x0000000FL        /*Mask for R/W and LEN bits for a bkpt*/
  226. #define DR7_RWLSHIFT(n) (16 + (n) * 4)    /* Number of bits to shift to get */
  227.                     /* R/W/LEN bits for bkpt Bn */
  228. #define DR7_RWMASK 0x00000003L        /* R/W bits mask */
  229. #define DR7_BINST 0x00000000L        /* R/W specifies break on instr exec */
  230. #define DR7_BWR    0x00000001L        /* R/W specifies break on data write */
  231. #define DR7_BRW    0x00000003L        /* R/W specifies break on data read */
  232.                     /* or write */
  233. #define DR7_LMASK 0x0000000CL        /* LEN bits mask */
  234. #define DR7_L1    0x00000000L        /* LEN specifies 1-byte length */
  235. #define DR7_L2    0x00000004L        /* LEN specifies 2-byte length */
  236. #define DR7_L4    0x0000000CL        /* LEN specifies 4-byte length */
  237.  
  238. #define DR7_GD    0x00002000L    /* global debug register access detect */
  239.  
  240. #define DR7_DEFINED 0xFFFF23FFL        /* mask for all defined bits  */
  241.  
  242. /*
  243. Test registers (TR3, TR4, TR5 are 486 only.  TR6 and TR7 are 386 and 486)
  244. */
  245. #define TR4_DEFINED    0xFFFFFFF8L    /* mask for all defined bits in TR4 */
  246.  
  247. #define TR5_DEFINED    0x000007FFL    /* mask for all defined bits in TR5 */
  248.  
  249. #define TR6_DEFINED    0xFFFFFFE3L    /* mask for all defined bits in TR6 */
  250.  
  251. #define TR7_DEFINED    0xFFFFF01CL    /* mask for all defined bits on 386 */
  252. #define TR7_486DEFINED    0xFFFFFF9CL    /* mask for all defined bits on 486 */
  253.  
  254.  
  255. /*
  256.  
  257. Bit definitions for a page table entry
  258.  
  259. */
  260.  
  261. #define PE_PFA        0xFFFFF000L    /* page frame address */
  262. #define PE_DIRTY    0x00000040L    /* page dirty */
  263. #define PE_ACCESSED    0x00000020L    /* page accessed */
  264. #define PE_PCD        0x00000010L    /* page cache disable -- 486 only */
  265. #define PE_PWT        0x00000008L    /* page write through -- 486 only */
  266. #define PE_USER        0x00000004L    /* page can be accessed by user */
  267.                     /* (privilege level 3) */
  268. #define PE_WRITE    0x00000002L    /* page can be written */
  269. #define PE_PRESENT    0x00000001L    /* page is present in memory */
  270. #define PE_STDPROT    (PE_PRESENT | PE_WRITE | PE_USER) /* std prot bits */
  271. #define PE_DEFINED 0xFFFFFE67L    /* defined bits in a page table entry on 386 */
  272. #define PE_486DEFINED 0xFFFFFE7FL /* defined bits in a pg tbl entry on 486 */
  273.  
  274.  
  275. /*
  276.  
  277. Masks for fields in a linear address 
  278.  
  279. */
  280.  
  281. #define LA_PDE        0xFFC00000L    /* page directory entry index */
  282. #define LA_PTE        0x003FF000L    /* page table entry index */
  283. #define LA_POFFS    0x00000FFFL    /* byte offset in page */
  284. #define PDE_SHIFT    22    /* # bits to shift a page directory index */
  285. #define PTE_SHIFT    12    /* # bits to shift a page table index */
  286.  
  287.  
  288. /*
  289.  
  290. Page table constants
  291.  
  292. */
  293.  
  294. #define PAGE_SIZE    0x1000        /* page size, in bytes */
  295. #define PAGE_SHIFT    12        /* # bits to shift a page number */
  296. #define NPARA_PAGE    0x100        /* number of paragraphs in a page */
  297.  
  298.  
  299. /*
  300.  
  301. Field definitions for error code returned by some interrupts.
  302.  
  303. */
  304.  
  305. #define IE_SELX        0x0000FFF8L    /* segment selector index */
  306. #define IE_TI        0x00000004L    /* table indicator: 0 => GDT, 1 => LDT*/
  307. #define IE_IDT        0x00000002L    /* selector is in IDT (TI bit ignored */
  308. #define IE_EXT        0x00000001L    /* an external event caused interrupt */
  309.  
  310.  
  311. /*
  312.  
  313. Reserved interrupt numbers
  314.  
  315. */
  316.  
  317. #define INT_DIV        0        /* Divide by zero */
  318. #define INT_DBG        1        /* Debug */
  319. #define    INT_NMI        2        /* Non-maskable interrupt */
  320. #define INT_INT3    3        /* One-byte interrupt (INT3) */
  321. #define    INT_INTO    4        /* Interrupt on overflow */
  322. #define    INT_BND        5        /* BOUND interrupt */
  323. #define INT_ILL        6        /* Illegal instruction */
  324. #define INT_DNA        7        /* Device not available */
  325. #define INT_DBLF    8        /* Double fault */
  326. #define INT_CPSEG    9        /* Coprocessor segment overrun */
  327. #define    INT_ITSS    10        /* Invalid TSS */
  328. #define INT_SNP        11        /* Segment not present */
  329. #define INT_STKF    12        /* Stack fault */
  330. #define INT_PROTF    13        /* Protection fault */
  331. #define INT_PAGEF    14        /* Page fault */
  332. #define INT_CPE        16        /* Coprocessor error */
  333.  
  334.  
  335. /*
  336.  
  337. TSS for the 286
  338.  
  339. */
  340.  
  341. typedef struct
  342. {
  343.     USHORT tss_backl;    /* Back link selector to TSS */
  344.     USHORT tss_sp0;        /* SP for CPL 0 */
  345.     USHORT tss_ss0;        /* SS for CPL 0 */
  346.     USHORT tss_sp1;        /* SP for CPL 1 */
  347.     USHORT tss_ss1;        /* SS for CPL 1 */
  348.     USHORT tss_sp2;        /* SP for CPL 2 */
  349.     USHORT tss_ss2;        /* SS for CPL 2 */
  350.     USHORT tss_ip;        /* IP */
  351.     USHORT tss_flags;    /* Flags */
  352.     USHORT tss_ax;        /* AX */
  353.     USHORT tss_cx;        /* CX */
  354.     USHORT tss_dx;        /* DX */
  355.     USHORT tss_bx;        /* BX */
  356.     USHORT tss_sp;        /* SP */
  357.     USHORT tss_bp;        /* BP */
  358.     USHORT tss_si;        /* SI */
  359.     USHORT tss_di;        /* DI */
  360.     USHORT tss_es;        /* ES */
  361.     USHORT tss_cs;        /* CS */
  362.     USHORT tss_ss;        /* SS */
  363.     USHORT tss_ds;        /* DS */
  364.     USHORT tss_ldtr;    /* LDTR */
  365. } TSS286;
  366.  
  367.  
  368. /*
  369.  
  370. TSS for the 386
  371.  
  372. */
  373.  
  374. typedef struct
  375. {
  376.     USHORT tss_backl;    /* Back link selector to TSS */
  377.     USHORT tss_fl1;        /* Filler */
  378.     ULONG tss_esp0;        /* SP for CPL 0 */
  379.     USHORT tss_ss0;        /* SS for CPL 0 */
  380.     USHORT tss_fl2;        /* Filler */
  381.     ULONG tss_esp1;        /* SP for CPL 1 */
  382.     USHORT tss_ss1;        /* SS for CPL 1 */
  383.     USHORT tss_fl3;        /* Filler */
  384.     ULONG tss_esp2;        /* SP for CPL 2 */
  385.     USHORT tss_ss2;        /* SS for CPL 2 */
  386.     USHORT tss_fl4;        /* Filler */
  387.     ULONG tss_cr3;        /* CR3 */
  388.     ULONG tss_eip;        /* EIP */
  389.     ULONG tss_eflags;    /* Extended flags */
  390.     ULONG tss_eax;        /* EAX */
  391.     ULONG tss_ecx;        /* ECX */
  392.     ULONG tss_edx;        /* EDX */
  393.     ULONG tss_ebx;        /* EBX */
  394.     ULONG tss_esp;        /* ESP */
  395.     ULONG tss_ebp;        /* EBP */
  396.     ULONG tss_esi;        /* ESI */
  397.     ULONG tss_edi;        /* EDI */
  398.     USHORT tss_es;        /* ES */
  399.     USHORT tss_fl5;        /* Filler */
  400.     USHORT tss_cs;        /* CS */
  401.     USHORT tss_fl6;        /* Filler */
  402.     USHORT tss_ss;        /* SS */
  403.     USHORT tss_fl7;        /* Filler */
  404.     USHORT tss_ds;        /* DS */
  405.     USHORT tss_fl8;        /* Filler */
  406.     USHORT tss_fs;        /* FS */
  407.     USHORT tss_fl9;        /* Filler */
  408.     USHORT tss_gs;        /* GS */
  409.     USHORT tss_fl10;    /* Filler */
  410.     USHORT tss_ldtr;    /* LDTR */
  411.     USHORT tss_fl11;    /* Filler */
  412.     USHORT tss_dflags;    /* Debugger flags */
  413.     USHORT tss_iomapb;    /* I/O map base */
  414. } TSS386;
  415.  
  416. #define TSS_TRAPF 0x0001    /* Debug trap flag in TSS */
  417.  
  418. #define TSS286_SIZE 0x2C    /* Size of a 286 TSS */
  419. #define TSS386_SIZE 0x68    /* Size of a 386 TSS */
  420.