home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 7.ddi / INCLUDES / HW386.AH < prev    next >
Encoding:
Text File  |  1991-01-02  |  10.1 KB  |  278 lines

  1. comment #**********************************************************************
  2.  
  3. HW386.AH - 80386 Specific Hardware Definitions
  4. /* $ID$ */
  5. /************************************************************************/
  6. /*    Copyright (C) 1986-1988 Phar Lap Software, Inc.            */
  7. /*    Unpublished - rights reserved under the Copyright Laws of the    */
  8. /*    United States.  Use, duplication, or disclosure by the         */
  9. /*    Government is subject to restrictions as set forth in         */
  10. /*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  11. /*    Computer Software clause at 252.227-7013.            */
  12. /*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  13. /************************************************************************/
  14.  
  15. REVISION LOG
  16.  
  17. Rev. 1.00, JMB, 06-Feb-89    File creation date.
  18.  
  19.     FILE DESCRIPTION
  20.  
  21. This file contains the assembly language definitions for 80386 specific
  22. registers, etc.
  23.  
  24. #******************************************************************************
  25. ;
  26. ; Bit definitions for 80386 registers.  Note that for registers which have
  27. ; undefined bits, we also include a mask for the defined bits in the register.
  28. ; For future compatibility, Intel states that programs should mask
  29. ; out all undefined bits when storing registers in memory, and set all
  30. ; undefined bits to zero when loading registers.
  31. ;
  32. ;******************************************************************************
  33. ;
  34. ; EFLAGS register.  Note that the VM and RF flags cannot be changed under
  35. ; program control;  reloading EFLAGS with a new value will not affect these
  36. ; flags.
  37. ;
  38. EF_AC    equ    00040000h    ; alignment check flag, 486 only
  39. EF_VM    equ    00020000h    ; virtual mode flag
  40. EF_RF    equ    00010000h    ; resume flag
  41. EF_NT    equ    00004000h    ; nested task flag
  42. EF_IOPL    equ    00003000h    ; I/O privilege level
  43. EF_OF    equ    00000800h    ; overflow flag
  44. EF_DF    equ    00000400h    ; direction flag
  45. EF_IF    equ    00000200h    ; interrupt enable flag
  46. EF_TF    equ    00000100h    ; trap flag
  47. EF_SF    equ    00000080h    ; sign flag
  48. EF_ZF    equ    00000040h    ; zero flag
  49. EF_AF    equ    00000010h    ; auxiliary carry flag
  50. EF_PF    equ    00000004h    ; parity flag
  51. EF_CF    equ    00000001h    ; carry flag
  52. EF_1BITS equ    00000002h    ; bits that are always set to 1
  53. EF_DEFINED equ    00037FD7h    ; mask for all defined bits on 386
  54. EF_486DEFINED equ 00077FD7h    ; mask for all defined bits on 486
  55. EF_IFBIT equ    9        ; bit number for IF
  56.  
  57. ;
  58. ; CR0 register
  59. ;
  60. CR0_PG    equ    80000000h    ; page enable bit
  61. CR0_CD    equ    40000000h    ; cache disable, 486 only
  62. CR0_NW    equ    20000000h    ; not write-through, 486 only
  63. CR0_AM    equ    00040000h    ; alignment check enable, 486 only
  64. CR0_WP    equ    00010000h    ; write protect at priv lev 0-2, 486 only
  65. CR0_NE    equ    00000020h    ; numerics exception enable, 486 only
  66. CR0_ET    equ    00000010h    ; processor extension type
  67. CR0_TS    equ    00000008h    ; task switched bit
  68. CR0_EM    equ    00000004h    ; emulate coprocessor bit
  69. CR0_MP    equ    00000002h    ; monitor coprocessor bit
  70. CR0_PE    equ    00000001h    ; protected mode enable bit
  71. CR0_DEFINED equ    8000001Fh    ; mask for all defined bits on 386
  72. CR0_486DEFINED equ 0E005003Fh    ; mask for all defined bits on 486
  73. CR0_PEBIT equ    0        ; bit number of PE bit
  74.  
  75. ;
  76. ; CR3 register
  77. ;
  78. CR3_PCD        equ    00000010h    ; page cache disable, 486 only
  79. CR3_PWT        equ    00000008h    ; page write-thru, 486 only
  80. CR3_DEFINED    equ    0FFFFF000h    ; mask for all defined bits on 386
  81. CR3_486DEFINED    equ    0FFFFF018h    ; mask for all defined bits on 486
  82.  
  83. ;
  84. ; DR6 register
  85. ;
  86. DR6_BT    equ    00008000h    ; task switch bit
  87. DR6_BS    equ    00004000h    ; single step trap
  88. DR6_BD    equ    00002000h    ; debug register accessed
  89. DR6_B3    equ    00000008h    ; breakpoint 3 occurred
  90. DR6_B2    equ    00000004h    ; breakpoint 2 occurred
  91. DR6_B1    equ    00000002h    ; breakpoint 1 occurred
  92. DR6_B0    equ    00000001h    ; breakpoint 0 occurred
  93. DR6_DEFINED equ    0000E00Fh    ; mask for all defined bits
  94.  
  95. ;
  96. ; DR7 register
  97. ;
  98. DR7_DEFINED equ    0FFFF23FFh    ; mask for all defined bits
  99.  
  100. ;
  101. ; TR4,TR5 registers -- 486 only
  102. ;
  103. TR4_DEFINED    equ    0FFFFFFF8h    ; mask for all defined bits in TR4
  104. TR5_DEFINED    equ    000007FFh    ; mask for all defined bits in TR5
  105.  
  106. ;
  107. ; TR6 register
  108. ;
  109. TR6_DEFINED    equ    0FFFFFFE3h    ; mask for all defined bits
  110.  
  111. ;
  112. ; TR7 register
  113. ;
  114. TR7_DEFINED    equ    0FFFFF01Ch    ; mask for all defined bits on 386
  115. TR7_486DEFINED    equ    0FFFFFF9Ch    ; mask for all defined bits on 486
  116. page
  117. ;**************************************************************************
  118. ; Descriptor tables and segment selectors
  119. ;**************************************************************************
  120.  
  121. ;
  122. ; Masks for various fields in segment selector
  123. ;
  124. SEL_IDX    EQU    0FFF8h    ; index into GDT or LDT
  125. SEL_TI    EQU    0004h    ; table indicator;  0 ==> GDT, 1 ==> LDT
  126. SEL_RPL    EQU    0003h    ; requested privilege level
  127. SEL_BTI    EQU    2    ; Bit number of table indicator bit
  128.  
  129. ;
  130. ; Code or data segment descriptor, or system segment descriptor
  131. ;
  132. CD_DES    struc
  133.     CD_LLIM    DW    0    ; bits 0-15 of limit
  134.     CD_BASE0 DW    0    ; bits 0-15 of base
  135.     CD_BASE16 DB    0    ; bits 16-23 of base
  136.     CD_ACC    DB    0    ; access rights byte
  137.     CD_HLIM    DB    0    ; bits 16-19 of limit, granularity, default oper
  138.     CD_BASE24 DB    0    ; bits 24-31 of base
  139. CD_DES    ends
  140.  
  141. ;
  142. ; Bit fields in the access rights byte of code/data/system segment descriptors
  143. ;
  144. AR_DTYPE equ    10h    ; descriptor type; 0 ==> system, 1 ==> code or data
  145. AR_DPL    equ    60h    ; descriptor privilege level
  146. AR_DPLSC equ    5    ; shift count for descr priv level
  147. AR_PRES    equ    80h    ; present bit;  1 ==> segment is present
  148.  
  149. ;
  150. ; If the system bit is zero, the selector is for a code or data segment, and
  151. ; the rest of the bits in the access rights byte look as follows
  152. ;
  153. AR_ACCESS equ    01h    ; accessed bit -- set by processor when segment accessed
  154. AR_CSEG equ    08h    ; code segment;  1 ==> code seg, 0 ==> data seg
  155. AR_ED_CONF equ    04h    ; if data seg, 1 ==> expand down, 0 ==> expand up
  156.             ; if code seg, 1 ==> conforming, 0 ==> not conforming
  157. AR_RW    equ    02h    ; if data seg, 1 ==> writeable, 0 ==> not writeable
  158.             ; if code seg, 1 ==> readable, 0 ==> not readable
  159. AR_CBIT equ    3    ; code segment bit number
  160.  
  161. ;
  162. ; If the system bit is zero, the selector is for a system segment, and the
  163. ; rest 4 LS bits in the access rights byte are a type code which may assume
  164. ; one of the following values.  Note also that for system segment descriptors,
  165. ; the default operation size bit in byte 6 of the descriptor MUST be 0.
  166. ;
  167. AR_A2TSS equ    01h    ; available 286 TSS
  168. AR_LDT    equ    02h    ; LDT segment
  169. AR_B2TSS equ    03h    ; Busy 286 TSS
  170. AR_C286    equ    04h    ; 286 call gate
  171. AR_TASK    equ    05h    ; 286 or 386 task gate
  172. AR_I286    equ    06h    ; 286 interrupt gate
  173. AR_T286 equ    07h    ; 286 trap gate
  174. AR_A3TSS equ    09h    ; available 386 TSS
  175. AR_B3TSS equ    0Bh    ; busy 386 TSS
  176. AR_C386    equ    0Ch    ; 386 call gate
  177. AR_I386    equ    0Eh    ; 386 interrupt gate
  178. AR_T386 equ    0Fh    ; 386 trap gate
  179.  
  180. ;
  181. ; Standard access rights byte for code & data segments
  182. ;
  183. AR_CODE    equ    AR_PRES or AR_DTYPE or AR_CSEG or AR_RW    ; readable, not conform
  184. AR_DATA equ    AR_PRES or AR_DTYPE or AR_RW        ; writeable, expand up
  185.  
  186. ;
  187. ; Bit fields in byte 6 of code/data/system segment descriptors
  188. ;
  189. D6_HLIM    equ    0Fh    ; bits 16-19 of limit
  190. D6_USE32 equ    40h    ; Default operation size; 0 ==> 16 bits, 1 ==> 32 bits
  191.             ; This is D bit for code segments, B bit for data segs
  192.             ; This bit MUST be 0 for system segment descriptors
  193. SW_AVL    equ    10h    ; bit available for system software
  194. D6_GRAN    equ    80h    ; Limit granularity; 0 ==> byte granular, 1 ==> page
  195.  
  196. ;
  197. ; Standard byte 6 for code & data segments
  198. ;
  199. D6_CODE equ    D6_USE32        ; byte granular, USE32 segment
  200. D6_DATA equ    D6_USE32        ; byte granular, USE32 segment
  201.  
  202. ;
  203. ; Gate descriptors.  For system segments which are call, task, interrupt, or
  204. ; trap gates, the descriptor has the following format, where the access byte
  205. ; bit definitions are the same as those identified above for system segment
  206. ; descriptors
  207. ;
  208. IT_DES    struc
  209.     IT_LOFFS DW    0    ; bits 0-15 of offset of handler routine
  210.     IT_SEL    DW    0    ; selector of code seg handler routine is in
  211.         DB    0    ; word count field unused for int/trap gates
  212.     IT_ACC    DB    0    ; access byte
  213.     IT_HOFFS DW    0    ; bits 16-31 of offset of handler routine
  214. IT_DES    ends
  215.  
  216. ;
  217. ; Standard access bytes for interrupt gates and trap gates.  The required
  218. ; privilege level to access the descriptor is 0 (most privileged)
  219. ;
  220. IT_INT    equ    AR_I386 or AR_PRES
  221. IT_TRAP    equ    AR_T386 or AR_PRES
  222. page
  223. ;**************************************************************************
  224. ; Other data structures and constants used to interface to protected mode.
  225. ;**************************************************************************
  226. ;
  227. ; A FAR pointer, used for both protected mode and real mode (in real mode,
  228. ; of course, the 16 MS bits of the offset should be zero).
  229. ;
  230. ; Note that this struct is ordered exactly like a 386 FAR pointer, so that,
  231. ; for example, it could be used with the lds/les/lfs/lgs/lss instruction.
  232. ;
  233. PTR386    struc
  234.     SOFFS    dd    ?    ; offset within segment
  235.     SELECTOR dw    ?    ; segment selector value
  236. PTR386    ends
  237.  
  238. ;
  239. ; Some commonly used numerical constants
  240. ;
  241. NUM_1K    equ    400h        ; 1K bytes
  242. SHIFT1K    equ    10        ; # bits to shift to convert Ks to bytes
  243. NUM_4K    equ    1000h        ; 4K bytes
  244. NUM_64K    equ    10000h        ; 64 K bytes
  245. NUM_1M    equ    100000h        ; 1 megabyte
  246.  
  247. ;**************************************************************************
  248. ; Page table definitions
  249. ;**************************************************************************
  250. ;
  251. ; Hardware-defined page table entry bit definitions
  252. ;
  253. PE_PFA    equ    0FFFFF000h    ; page frame physical address
  254. PE_DIRTY equ    00000040h    ; page dirty
  255. PE_ACCESSED equ    00000020h    ; page accessed
  256. PE_PCD    equ    00000010h    ; page cache disable -- 486 only
  257. PE_PWT    equ    00000008h    ; page write through -- 486 only
  258. PE_USER    equ    00000004h    ; user (priv. level 3) can access page
  259. PE_WRITE equ    00000002h    ; page can be written to
  260. PE_PRESENT equ    00000001h    ; page is present in memory
  261. PE_DEFINED equ    0FFFFFE67h    ; defined bits in a page table entry on 386
  262. PE_486DEFINED equ 0FFFFFE7Fh    ; defined bits in a page table entry on 486
  263.  
  264. ;
  265. ; Masks and shift counts for fields in a linear address
  266. ;
  267. LA_PDE    equ    0FFC00000h    ; page directory entry index
  268. LA_PTE    equ    003FF000h    ; page table entry index
  269. LA_POFFS equ    00000FFFh    ; byte offset in page
  270. PDE_SHIFT equ    22        ; # bits to shift a page directory index
  271. PTE_SHIFT equ    12        ; # bits to shift a page table index
  272.  
  273. ;
  274. ; Some constants used for page tables
  275. ;
  276. PAGE_SIZE equ    1000h        ; size of a page, in bytes, is 4K
  277. PAGE_SHIFT equ    12        ; # bits to shift a page number to get addr
  278.