home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / INCLUDE / HW386.AH < prev    next >
Encoding:
Text File  |  1992-11-16  |  10.9 KB  |  295 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_ID    equ    00200000h    ; ID flag, 586 only
  39. EF_VIP    equ    00100000h    ; virtual interrupt pending flag, 586 only
  40. EF_VIF    equ    00080000h    ; virtual interrupt flag, 586 only
  41. EF_AC    equ    00040000h    ; alignment check flag, 486 only
  42. EF_VM    equ    00020000h    ; virtual mode flag
  43. EF_RF    equ    00010000h    ; resume flag
  44. EF_NT    equ    00004000h    ; nested task flag
  45. EF_IOPL    equ    00003000h    ; I/O privilege level
  46. EF_OF    equ    00000800h    ; overflow flag
  47. EF_DF    equ    00000400h    ; direction flag
  48. EF_IF    equ    00000200h    ; interrupt enable flag
  49. EF_TF    equ    00000100h    ; trap flag
  50. EF_SF    equ    00000080h    ; sign flag
  51. EF_ZF    equ    00000040h    ; zero flag
  52. EF_AF    equ    00000010h    ; auxiliary carry flag
  53. EF_PF    equ    00000004h    ; parity flag
  54. EF_CF    equ    00000001h    ; carry flag
  55. EF_1BITS equ    00000002h    ; bits that are always set to 1
  56. EF_DEFINED equ    00037FD7h    ; mask for all defined bits on 386
  57. EF_486DEFINED equ 00077FD7h    ; mask for all defined bits on 486
  58. EF_586DEFINED equ 003F7FD7h    ; mask for all defined bits on 586
  59. EF_IFBIT equ    9        ; bit number for IF
  60.  
  61. ;
  62. ; CR0 register
  63. ;
  64. CR0_PG    equ    80000000h    ; page enable bit
  65. CR0_CD    equ    40000000h    ; cache disable, 486 only
  66. CR0_NW    equ    20000000h    ; not write-through, 486 only
  67. CR0_AM    equ    00040000h    ; alignment check enable, 486 only
  68. CR0_WP    equ    00010000h    ; write protect at priv lev 0-2, 486 only
  69. CR0_NE    equ    00000020h    ; numerics exception enable, 486 only
  70. CR0_ET    equ    00000010h    ; processor extension type
  71. CR0_TS    equ    00000008h    ; task switched bit
  72. CR0_EM    equ    00000004h    ; emulate coprocessor bit
  73. CR0_MP    equ    00000002h    ; monitor coprocessor bit
  74. CR0_PE    equ    00000001h    ; protected mode enable bit
  75. CR0_DEFINED equ    8000001Fh    ; mask for all defined bits on 386
  76. CR0_486DEFINED equ 0E005003Fh    ; mask for all defined bits on 486
  77. CR0_PEBIT equ    0        ; bit number of PE bit
  78.  
  79. ;
  80. ; CR3 register
  81. ;
  82. CR3_PCD        equ    00000010h    ; page cache disable, 486 only
  83. CR3_PWT        equ    00000008h    ; page write-thru, 486 only
  84. CR3_DEFINED    equ    0FFFFF000h    ; mask for all defined bits on 386
  85. CR3_486DEFINED    equ    0FFFFF018h    ; mask for all defined bits on 486
  86.  
  87. ;
  88. ; CR4 register (586 only)
  89. ;
  90. CR4_VME        equ    00000001h    ; Virtual Mode Extensions enabled
  91. CR4_PVI        equ    00000002h    ; Prot Mode Virtual Interrupts enabled
  92. CR4_TSD        equ    00000004h    ; RTSC instr disabled except at ring 0
  93. CR4_DE        equ    00000008h    ; Debugging Extensions (I/O bkpts)
  94.                         ; enabled
  95. CR4_PSE        equ    00000010h    ; Page Size Extension enabled
  96. CR4_PAE        equ    00000020h    ; Physical Address Extension enabled
  97. CR4_MCE        equ    00000040h    ; Machine Check Exceptions enabled
  98. CR4_DEFINED    equ    0000007Fh    ; mask for all defined bits
  99.  
  100. ;
  101. ; DR6 register
  102. ;
  103. DR6_BT    equ    00008000h    ; task switch bit
  104. DR6_BS    equ    00004000h    ; single step trap
  105. DR6_BD    equ    00002000h    ; debug register accessed
  106. DR6_B3    equ    00000008h    ; breakpoint 3 occurred
  107. DR6_B2    equ    00000004h    ; breakpoint 2 occurred
  108. DR6_B1    equ    00000002h    ; breakpoint 1 occurred
  109. DR6_B0    equ    00000001h    ; breakpoint 0 occurred
  110. DR6_DEFINED equ    0000E00Fh    ; mask for all defined bits
  111.  
  112. ;
  113. ; DR7 register
  114. ;
  115. DR7_DEFINED equ    0FFFF23FFh    ; mask for all defined bits
  116.  
  117. ;
  118. ; TR4,TR5 registers -- 486 only
  119. ;
  120. TR4_DEFINED    equ    0FFFFFFF8h    ; mask for all defined bits in TR4
  121. TR5_DEFINED    equ    000007FFh    ; mask for all defined bits in TR5
  122.  
  123. ;
  124. ; TR6 register
  125. ;
  126. TR6_DEFINED    equ    0FFFFFFE3h    ; mask for all defined bits
  127.  
  128. ;
  129. ; TR7 register
  130. ;
  131. TR7_DEFINED    equ    0FFFFF01Ch    ; mask for all defined bits on 386
  132. TR7_486DEFINED    equ    0FFFFFF9Ch    ; mask for all defined bits on 486
  133. page
  134. ;**************************************************************************
  135. ; Descriptor tables and segment selectors
  136. ;**************************************************************************
  137.  
  138. ;
  139. ; Masks for various fields in segment selector
  140. ;
  141. SEL_IDX    EQU    0FFF8h    ; index into GDT or LDT
  142. SEL_TI    EQU    0004h    ; table indicator;  0 ==> GDT, 1 ==> LDT
  143. SEL_RPL    EQU    0003h    ; requested privilege level
  144. SEL_BTI    EQU    2    ; Bit number of table indicator bit
  145.  
  146. ;
  147. ; Code or data segment descriptor, or system segment descriptor
  148. ;
  149. CD_DES    struc
  150.     CD_LLIM    DW    0    ; bits 0-15 of limit
  151.     CD_BASE0 DW    0    ; bits 0-15 of base
  152.     CD_BASE16 DB    0    ; bits 16-23 of base
  153.     CD_ACC    DB    0    ; access rights byte
  154.     CD_HLIM    DB    0    ; bits 16-19 of limit, granularity, default oper
  155.     CD_BASE24 DB    0    ; bits 24-31 of base
  156. CD_DES    ends
  157.  
  158. ;
  159. ; Bit fields in the access rights byte of code/data/system segment descriptors
  160. ;
  161. AR_DTYPE equ    10h    ; descriptor type; 0 ==> system, 1 ==> code or data
  162. AR_DPL    equ    60h    ; descriptor privilege level
  163. AR_DPLSC equ    5    ; shift count for descr priv level
  164. AR_PRES    equ    80h    ; present bit;  1 ==> segment is present
  165.  
  166. ;
  167. ; If the system bit is zero, the selector is for a code or data segment, and
  168. ; the rest of the bits in the access rights byte look as follows
  169. ;
  170. AR_ACCESS equ    01h    ; accessed bit -- set by processor when segment accessed
  171. AR_CSEG equ    08h    ; code segment;  1 ==> code seg, 0 ==> data seg
  172. AR_ED_CONF equ    04h    ; if data seg, 1 ==> expand down, 0 ==> expand up
  173.             ; if code seg, 1 ==> conforming, 0 ==> not conforming
  174. AR_RW    equ    02h    ; if data seg, 1 ==> writeable, 0 ==> not writeable
  175.             ; if code seg, 1 ==> readable, 0 ==> not readable
  176. AR_CBIT equ    3    ; code segment bit number
  177.  
  178. ;
  179. ; If the system bit is zero, the selector is for a system segment, and the
  180. ; rest 4 LS bits in the access rights byte are a type code which may assume
  181. ; one of the following values.  Note also that for system segment descriptors,
  182. ; the default operation size bit in byte 6 of the descriptor MUST be 0.
  183. ;
  184. AR_A2TSS equ    01h    ; available 286 TSS
  185. AR_LDT    equ    02h    ; LDT segment
  186. AR_B2TSS equ    03h    ; Busy 286 TSS
  187. AR_C286    equ    04h    ; 286 call gate
  188. AR_TASK    equ    05h    ; 286 or 386 task gate
  189. AR_I286    equ    06h    ; 286 interrupt gate
  190. AR_T286 equ    07h    ; 286 trap gate
  191. AR_A3TSS equ    09h    ; available 386 TSS
  192. AR_B3TSS equ    0Bh    ; busy 386 TSS
  193. AR_C386    equ    0Ch    ; 386 call gate
  194. AR_I386    equ    0Eh    ; 386 interrupt gate
  195. AR_T386 equ    0Fh    ; 386 trap gate
  196.  
  197. ;
  198. ; Standard access rights byte for code & data segments
  199. ;
  200. AR_CODE    equ    AR_PRES or AR_DTYPE or AR_CSEG or AR_RW    ; readable, not conform
  201. AR_DATA equ    AR_PRES or AR_DTYPE or AR_RW        ; writeable, expand up
  202.  
  203. ;
  204. ; Bit fields in byte 6 of code/data/system segment descriptors
  205. ;
  206. D6_HLIM    equ    0Fh    ; bits 16-19 of limit
  207. D6_USE32 equ    40h    ; Default operation size; 0 ==> 16 bits, 1 ==> 32 bits
  208.             ; This is D bit for code segments, B bit for data segs
  209.             ; This bit MUST be 0 for system segment descriptors
  210. SW_AVL    equ    10h    ; bit available for system software
  211. D6_GRAN    equ    80h    ; Limit granularity; 0 ==> byte granular, 1 ==> page
  212.  
  213. ;
  214. ; Standard byte 6 for code & data segments
  215. ;
  216. D6_CODE equ    D6_USE32        ; byte granular, USE32 segment
  217. D6_DATA equ    D6_USE32        ; byte granular, USE32 segment
  218.  
  219. ;
  220. ; Gate descriptors.  For system segments which are call, task, interrupt, or
  221. ; trap gates, the descriptor has the following format, where the access byte
  222. ; bit definitions are the same as those identified above for system segment
  223. ; descriptors
  224. ;
  225. IT_DES    struc
  226.     IT_LOFFS DW    0    ; bits 0-15 of offset of handler routine
  227.     IT_SEL    DW    0    ; selector of code seg handler routine is in
  228.         DB    0    ; word count field unused for int/trap gates
  229.     IT_ACC    DB    0    ; access byte
  230.     IT_HOFFS DW    0    ; bits 16-31 of offset of handler routine
  231. IT_DES    ends
  232.  
  233. ;
  234. ; Standard access bytes for interrupt gates and trap gates.  The required
  235. ; privilege level to access the descriptor is 0 (most privileged)
  236. ;
  237. IT_INT    equ    AR_I386 or AR_PRES
  238. IT_TRAP    equ    AR_T386 or AR_PRES
  239. page
  240. ;**************************************************************************
  241. ; Other data structures and constants used to interface to protected mode.
  242. ;**************************************************************************
  243. ;
  244. ; A FAR pointer, used for both protected mode and real mode (in real mode,
  245. ; of course, the 16 MS bits of the offset should be zero).
  246. ;
  247. ; Note that this struct is ordered exactly like a 386 FAR pointer, so that,
  248. ; for example, it could be used with the lds/les/lfs/lgs/lss instruction.
  249. ;
  250. PTR386    struc
  251.     SOFFS    dd    ?    ; offset within segment
  252.     SELECTOR dw    ?    ; segment selector value
  253. PTR386    ends
  254.  
  255. ;
  256. ; Some commonly used numerical constants
  257. ;
  258. NUM_1K    equ    400h        ; 1K bytes
  259. SHIFT1K    equ    10        ; # bits to shift to convert Ks to bytes
  260. NUM_4K    equ    1000h        ; 4K bytes
  261. NUM_64K    equ    10000h        ; 64 K bytes
  262. NUM_1M    equ    100000h        ; 1 megabyte
  263.  
  264. ;**************************************************************************
  265. ; Page table definitions
  266. ;**************************************************************************
  267. ;
  268. ; Hardware-defined page table entry bit definitions
  269. ;
  270. PE_PFA    equ    0FFFFF000h    ; page frame physical address
  271. PE_DIRTY equ    00000040h    ; page dirty
  272. PE_ACCESSED equ    00000020h    ; page accessed
  273. PE_PCD    equ    00000010h    ; page cache disable -- 486 only
  274. PE_PWT    equ    00000008h    ; page write through -- 486 only
  275. PE_USER    equ    00000004h    ; user (priv. level 3) can access page
  276. PE_WRITE equ    00000002h    ; page can be written to
  277. PE_PRESENT equ    00000001h    ; page is present in memory
  278. PE_DEFINED equ    0FFFFFE67h    ; defined bits in a page table entry on 386
  279. PE_486DEFINED equ 0FFFFFE7Fh    ; defined bits in a page table entry on 486
  280.  
  281. ;
  282. ; Masks and shift counts for fields in a linear address
  283. ;
  284. LA_PDE    equ    0FFC00000h    ; page directory entry index
  285. LA_PTE    equ    003FF000h    ; page table entry index
  286. LA_POFFS equ    00000FFFh    ; byte offset in page
  287. PDE_SHIFT equ    22        ; # bits to shift a page directory index
  288. PTE_SHIFT equ    12        ; # bits to shift a page table index
  289.  
  290. ;
  291. ; Some constants used for page tables
  292. ;
  293. PAGE_SIZE equ    1000h        ; size of a page, in bytes, is 4K
  294. PAGE_SHIFT equ    12        ; # bits to shift a page number to get addr
  295.