home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / INCLUDE / HW386.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-27  |  13.9 KB  |  438 lines

  1. /* HW386.H - Hardware defintions for the 80386 CPU */
  2. /* $Id: hw386.h 1.5 92/10/27 16:40:12 rwm 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_ID    0x00200000L        /* ID flag, 586 only */
  143. #define    EF_VIP    0x00100000L        /*virtual interrupt pending, 586 only*/
  144. #define    EF_VIF    0x00080000L        /* virtual interrupt flag, 586 only */
  145. #define EF_AC    0x00040000L        /* alignment check flag, 486 only */
  146. #define EF_VM    0x00020000L        /* Virtual 8086 mode */
  147. #define EF_RF    0x00010000L        /* Resume flag */
  148. #define EF_NT     0x00004000L        /* Nested task */
  149. #define EF_IOPL    0x00003000L        /* I/O privilege mask */
  150. #define EF_SC_IOPL 12            /* # bits to shift IOPL */
  151. #define EF_OF    0x00000800L        /* Overflow flag */
  152. #define EF_DF    0x00000400L        /* Direction flag */
  153. #define EF_IF    0x00000200L        /* Interrupt enable flag */
  154. #define EF_TF    0x00000100L        /* Trace flag */
  155. #define EF_SF    0x00000080L        /* Sign flag */
  156. #define EF_ZF    0x00000040L        /* Zero flag */
  157. #define EF_AF    0x00000010L        /* Auxilary carry flag */
  158. #define EF_PF    0x00000004L        /* Parity flag */
  159. #define EF_CF    0x00000001L        /* Carry flag */
  160. #define EF_1BITS 0x00000002L        /* Bits always set to 1 in EFLAGS */
  161. #define EF_DEFINED    0x00037FD7L    /* mask for all defined bits on 386 */
  162. #define EF_486DEFINED    0x00077FD7L    /* mask for all defined bits on 486 */
  163.  
  164. /*
  165.  
  166. Control register 0 (CR0) definitions
  167.  
  168. */
  169.  
  170. #define CR0_PG    0x80000000L        /* Paging enabled */
  171. #define CR0_CD    0x40000000L        /* cache disable, 486 only */
  172. #define CR0_NW    0x20000000L        /* not write-through, 486 only */
  173. #define CR0_AM    0x00040000L        /* alignment check enable, 486 only */
  174. #define CR0_WP    0x00010000L    /* write protect at priv lev 0-2, 486 only */
  175. #define CR0_NE    0x00000020L    /* numerics exception enable, 486 only */
  176. #define CR0_ET  0x00000010L        /* 287 vs 387 flag */
  177. #define CR0_TS  0x00000008L        /* Task switched */
  178. #define CR0_EM  0x00000004L        /* Emulate coprocessor */
  179. #define CR0_MP    0x00000002L        /* Monitor coprocessor */
  180. #define CR0_PE    0x00000001L        /* Protected mode */
  181. #define CR0_DEFINED 0x8000001FL        /* mask for all defined bits on 386 */
  182. #define CR0_486DEFINED 0xE005003FL    /* mask for all defined bits on 486 */
  183.  
  184.  
  185. /*
  186. Control register 3 (CR3) definitions
  187. */
  188. #define CR3_PCD        0x00000010L    /* page cache disable, 486 only */
  189. #define CR3_PWT        0x00000008L    /* page write-thru, 486 only */
  190. #define CR3_DEFINED    0xFFFFF000L    /* mask for all defined bits on 386 */
  191. #define CR3_486DEFINED    0xFFFFF018L    /* mask for all defined bits on 486 */
  192.  
  193. /*
  194. CR4 register (586 only)
  195. */
  196. #define CR4_VME        0x00000001L    /* Virtual Mode Extensions enabled */
  197. #define CR4_PVI        0x00000002L    /* Prot Mode Virtual Interrupts 
  198.                         enabled */
  199. #define CR4_TSD        0x00000004L    /* RTSC instr disabled except at 
  200.                         ring 0 */
  201. #define CR4_DE        0x00000008L    /* Debugging Extensions (I/O bkpts)
  202.                         enabled */
  203. #define CR4_PSE        0x00000010L    /* Page Size Extension enabled */
  204. #define CR4_PAE        0x00000020L    /* Physical Address Extension enabled */
  205. #define CR4_MCE        0x00000040L    /* Machine Check Exceptions enabled */
  206. #define CR4_DEFINED    0x0000007FL    /* mask for all defined bits */
  207.  
  208.  
  209. /*
  210.  
  211. Debug register 6 definitions
  212.  
  213. */
  214.  
  215. #define DR6_B0 0x00000001L        /* Breakpoint 0 */
  216. #define DR6_B1 0x00000002L        /* Breakpoint 1 */
  217. #define DR6_B2 0x00000004L        /* Breakpoint 2 */
  218. #define DR6_B3 0x00000008L        /* Breakpoint 3 */
  219. #define DR6_BD 0x00002000L        /* Debug register accessed */
  220. #define DR6_BS 0x00004000L        /* Single step */
  221. #define DR6_BT 0x00008000L        /* Task switch */
  222. #define DR6_DEFINED 0x0000E00FL        /* mask for all defined bits */
  223.  
  224.  
  225. #define DR6_BSHIFT(n)    (n)        /* Number of bits to shift to get Bn */
  226.  
  227.  
  228. /*
  229.  
  230. Debug register 7 definitions
  231.  
  232. */
  233.  
  234. #define DR7_LE 0x00000100L        /* Enable all local breakpoints */
  235. #define DR7_GE 0x00000200L        /* Enable all global breakpoints */
  236.  
  237. #define DR7_GLMASK 0x00000003L        /* Mask for G and L bits for a bkpt */
  238. #define DR7_GLSHIFT(n) ((n) * 2)    /* Number of bits to shift to get */
  239.                     /* G and L bits for bkpt Bn */
  240. #define DR7_GEMASK 0x00000002L        /* global enable (G bit) mask */
  241. #define DR7_LEMASK 0x00000001L        /* local enable (L bit) mask */
  242.  
  243. #define DR7_RWLMASK 0x0000000FL        /*Mask for R/W and LEN bits for a bkpt*/
  244. #define DR7_RWLSHIFT(n) (16 + (n) * 4)    /* Number of bits to shift to get */
  245.                     /* R/W/LEN bits for bkpt Bn */
  246. #define DR7_RWMASK 0x00000003L        /* R/W bits mask */
  247. #define DR7_BINST 0x00000000L        /* R/W specifies break on instr exec */
  248. #define DR7_BWR    0x00000001L        /* R/W specifies break on data write */
  249. #define DR7_BRW    0x00000003L        /* R/W specifies break on data read */
  250.                     /* or write */
  251. #define DR7_LMASK 0x0000000CL        /* LEN bits mask */
  252. #define DR7_L1    0x00000000L        /* LEN specifies 1-byte length */
  253. #define DR7_L2    0x00000004L        /* LEN specifies 2-byte length */
  254. #define DR7_L4    0x0000000CL        /* LEN specifies 4-byte length */
  255.  
  256. #define DR7_GD    0x00002000L    /* global debug register access detect */
  257.  
  258. #define DR7_DEFINED 0xFFFF23FFL        /* mask for all defined bits  */
  259.  
  260. /*
  261. Test registers (TR3, TR4, TR5 are 486 only.  TR6 and TR7 are 386 and 486)
  262. */
  263. #define TR4_DEFINED    0xFFFFFFF8L    /* mask for all defined bits in TR4 */
  264.  
  265. #define TR5_DEFINED    0x000007FFL    /* mask for all defined bits in TR5 */
  266.  
  267. #define TR6_DEFINED    0xFFFFFFE3L    /* mask for all defined bits in TR6 */
  268.  
  269. #define TR7_DEFINED    0xFFFFF01CL    /* mask for all defined bits on 386 */
  270. #define TR7_486DEFINED    0xFFFFFF9CL    /* mask for all defined bits on 486 */
  271.  
  272.  
  273. /*
  274.  
  275. Bit definitions for a page table entry
  276.  
  277. */
  278.  
  279. #define PE_PFA        0xFFFFF000L    /* page frame address */
  280. #define PE_DIRTY    0x00000040L    /* page dirty */
  281. #define PE_ACCESSED    0x00000020L    /* page accessed */
  282. #define PE_PCD        0x00000010L    /* page cache disable -- 486 only */
  283. #define PE_PWT        0x00000008L    /* page write through -- 486 only */
  284. #define PE_USER        0x00000004L    /* page can be accessed by user */
  285.                     /* (privilege level 3) */
  286. #define PE_WRITE    0x00000002L    /* page can be written */
  287. #define PE_PRESENT    0x00000001L    /* page is present in memory */
  288. #define PE_STDPROT    (PE_PRESENT | PE_WRITE | PE_USER) /* std prot bits */
  289. #define PE_DEFINED 0xFFFFFE67L    /* defined bits in a page table entry on 386 */
  290. #define PE_486DEFINED 0xFFFFFE7FL /* defined bits in a pg tbl entry on 486 */
  291.  
  292.  
  293. /*
  294.  
  295. Masks for fields in a linear address 
  296.  
  297. */
  298.  
  299. #define LA_PDE        0xFFC00000L    /* page directory entry index */
  300. #define LA_PTE        0x003FF000L    /* page table entry index */
  301. #define LA_POFFS    0x00000FFFL    /* byte offset in page */
  302. #define PDE_SHIFT    22    /* # bits to shift a page directory index */
  303. #define PTE_SHIFT    12    /* # bits to shift a page table index */
  304.  
  305.  
  306. /*
  307.  
  308. Page table constants
  309.  
  310. */
  311.  
  312. #define PAGE_SIZE    0x1000        /* page size, in bytes */
  313. #define PAGE_SHIFT    12        /* # bits to shift a page number */
  314. #define NPARA_PAGE    0x100        /* number of paragraphs in a page */
  315.  
  316.  
  317. /*
  318.  
  319. Field definitions for error code returned by some interrupts.
  320.  
  321. */
  322.  
  323. #define IE_SELX        0x0000FFF8L    /* segment selector index */
  324. #define IE_TI        0x00000004L    /* table indicator: 0 => GDT, 1 => LDT*/
  325. #define IE_IDT        0x00000002L    /* selector is in IDT (TI bit ignored */
  326. #define IE_EXT        0x00000001L    /* an external event caused interrupt */
  327.  
  328.  
  329. /*
  330.  
  331. Reserved interrupt numbers
  332.  
  333. */
  334.  
  335. #define INT_DIV        0        /* Divide by zero */
  336. #define INT_DBG        1        /* Debug */
  337. #define    INT_NMI        2        /* Non-maskable interrupt */
  338. #define INT_INT3    3        /* One-byte interrupt (INT3) */
  339. #define    INT_INTO    4        /* Interrupt on overflow */
  340. #define    INT_BND        5        /* BOUND interrupt */
  341. #define INT_ILL        6        /* Illegal instruction */
  342. #define INT_DNA        7        /* Device not available */
  343. #define INT_DBLF    8        /* Double fault */
  344. #define INT_CPSEG    9        /* Coprocessor segment overrun */
  345. #define    INT_ITSS    10        /* Invalid TSS */
  346. #define INT_SNP        11        /* Segment not present */
  347. #define INT_STKF    12        /* Stack fault */
  348. #define INT_PROTF    13        /* Protection fault */
  349. #define INT_PAGEF    14        /* Page fault */
  350. #define INT_CPE        16        /* Coprocessor error */
  351.  
  352.  
  353. /*
  354.  
  355. TSS for the 286
  356.  
  357. */
  358.  
  359. typedef struct
  360. {
  361.     USHORT tss_backl;    /* Back link selector to TSS */
  362.     USHORT tss_sp0;        /* SP for CPL 0 */
  363.     USHORT tss_ss0;        /* SS for CPL 0 */
  364.     USHORT tss_sp1;        /* SP for CPL 1 */
  365.     USHORT tss_ss1;        /* SS for CPL 1 */
  366.     USHORT tss_sp2;        /* SP for CPL 2 */
  367.     USHORT tss_ss2;        /* SS for CPL 2 */
  368.     USHORT tss_ip;        /* IP */
  369.     USHORT tss_flags;    /* Flags */
  370.     USHORT tss_ax;        /* AX */
  371.     USHORT tss_cx;        /* CX */
  372.     USHORT tss_dx;        /* DX */
  373.     USHORT tss_bx;        /* BX */
  374.     USHORT tss_sp;        /* SP */
  375.     USHORT tss_bp;        /* BP */
  376.     USHORT tss_si;        /* SI */
  377.     USHORT tss_di;        /* DI */
  378.     USHORT tss_es;        /* ES */
  379.     USHORT tss_cs;        /* CS */
  380.     USHORT tss_ss;        /* SS */
  381.     USHORT tss_ds;        /* DS */
  382.     USHORT tss_ldtr;    /* LDTR */
  383. } TSS286;
  384.  
  385.  
  386. /*
  387.  
  388. TSS for the 386
  389.  
  390. */
  391.  
  392. typedef struct
  393. {
  394.     USHORT tss_backl;    /* Back link selector to TSS */
  395.     USHORT tss_fl1;        /* Filler */
  396.     ULONG tss_esp0;        /* SP for CPL 0 */
  397.     USHORT tss_ss0;        /* SS for CPL 0 */
  398.     USHORT tss_fl2;        /* Filler */
  399.     ULONG tss_esp1;        /* SP for CPL 1 */
  400.     USHORT tss_ss1;        /* SS for CPL 1 */
  401.     USHORT tss_fl3;        /* Filler */
  402.     ULONG tss_esp2;        /* SP for CPL 2 */
  403.     USHORT tss_ss2;        /* SS for CPL 2 */
  404.     USHORT tss_fl4;        /* Filler */
  405.     ULONG tss_cr3;        /* CR3 */
  406.     ULONG tss_eip;        /* EIP */
  407.     ULONG tss_eflags;    /* Extended flags */
  408.     ULONG tss_eax;        /* EAX */
  409.     ULONG tss_ecx;        /* ECX */
  410.     ULONG tss_edx;        /* EDX */
  411.     ULONG tss_ebx;        /* EBX */
  412.     ULONG tss_esp;        /* ESP */
  413.     ULONG tss_ebp;        /* EBP */
  414.     ULONG tss_esi;        /* ESI */
  415.     ULONG tss_edi;        /* EDI */
  416.     USHORT tss_es;        /* ES */
  417.     USHORT tss_fl5;        /* Filler */
  418.     USHORT tss_cs;        /* CS */
  419.     USHORT tss_fl6;        /* Filler */
  420.     USHORT tss_ss;        /* SS */
  421.     USHORT tss_fl7;        /* Filler */
  422.     USHORT tss_ds;        /* DS */
  423.     USHORT tss_fl8;        /* Filler */
  424.     USHORT tss_fs;        /* FS */
  425.     USHORT tss_fl9;        /* Filler */
  426.     USHORT tss_gs;        /* GS */
  427.     USHORT tss_fl10;    /* Filler */
  428.     USHORT tss_ldtr;    /* LDTR */
  429.     USHORT tss_fl11;    /* Filler */
  430.     USHORT tss_dflags;    /* Debugger flags */
  431.     USHORT tss_iomapb;    /* I/O map base */
  432. } TSS386;
  433.  
  434. #define TSS_TRAPF 0x0001    /* Debug trap flag in TSS */
  435.  
  436. #define TSS286_SIZE 0x2C    /* Size of a 286 TSS */
  437. #define TSS386_SIZE 0x68    /* Size of a 386 TSS */
  438.