home *** CD-ROM | disk | FTP | other *** search
/ CD-X 1 / cdx_01.iso / demodisc / tyrant / docs / 386code / 1.386 next >
Encoding:
Text File  |  1994-01-20  |  15.8 KB  |  351 lines

  1. Chapter 1  Introduction to the 80386
  2.  
  3. ────────────────────────────────────────────────────────────────────────────
  4.  
  5. The 80386 is an advanced 32-bit microprocessor optimized for multitasking
  6. operating systems and designed for applications needing very high
  7. performance. The 32-bit registers and data paths support 32-bit addresses
  8. and data types. The processor can address up to four gigabytes of physical
  9. memory and 64 terabytes (2^(46) bytes) of virtual memory. The on-chip
  10. memory-management facilities include address translation registers,
  11. advanced multitasking hardware, a protection mechanism, and paged virtual
  12. memory. Special debugging registers provide data and code breakpoints even
  13. in ROM-based software.
  14.  
  15.  
  16. 1.1  Organization of This Manual
  17.  
  18. This book presents the architecture of the 80386 in five parts:
  19.  
  20.    Part I      ── Applications Programming
  21.    Part II     ── Systems Programming
  22.    Part III    ── Compatibility
  23.    Part IV     ── Instruction Set
  24.    Appendices
  25.  
  26. These divisions are determined in part by the architecture itself and in
  27. part by the different ways the book will be used. As the following table
  28. indicates, the latter two parts are intended as reference material for
  29. programmers actually engaged in the process of developing software for the
  30. 80386. The first three parts are explanatory, showing the purpose of
  31. architectural features, developing terminology and concepts, and describing
  32. instructions as they relate to specific purposes or to specific
  33. architectural features.
  34.  
  35. Explanation                Part I   ── Applications Programming
  36.                            Part II  ── Systems Programming
  37.                            Part III ── Compatibility
  38.  
  39. Reference                  Part IV  ── Instruction Set
  40.                            Appendices
  41.  
  42. The first three parts follow the execution modes and protection features of
  43. the 80386 CPU. The distinction between applications features and systems
  44. features is determined by the protection mechanism of the 80386. One purpose
  45. of protection is to prevent applications from interfering with the operating
  46. system; therefore, the processor makes certain registers and instructions
  47. inaccessible to applications programs. The features discussed in Part I are
  48. those that are accessible to applications; the features in Part II are
  49. available only to systems software that has been given special privileges or
  50. in unprotected systems.
  51.  
  52. The processing mode of the 80386 also determines the features that are
  53. accessible. The 80386 has three processing modes:
  54.  
  55.    1.  Protected Mode.
  56.    2.  Real-Address Mode.
  57.    3.  Virtual 8086 Mode.
  58.  
  59. Protected mode is the natural 32-bit environment of the 80386 processor. In
  60. this mode all instructions and features are available.
  61.  
  62. Real-address mode (often called just "real mode") is the mode of the
  63. processor immediately after RESET. In real mode the 80386 appears to
  64. programmers as a fast 8086 with some new instructions. Most applications of
  65. the 80386 will use real mode for initialization only.
  66.  
  67. Virtual 8086 mode (also called V86 mode) is a dynamic mode in the sense
  68. that the processor can switch repeatedly and rapidly between V86 mode and
  69. protected mode. The CPU enters V86 mode from protected mode to execute an
  70. 8086 program, then leaves V86 mode and enters protected mode to continue
  71. executing a native 80386 program.
  72.  
  73. The features that are available to applications programs in protected mode
  74. and to all programs in V86 mode are the same. These features form the
  75. content of Part I. The additional features that are available to systems
  76. software in protected mode form Part II. Part III explains real-address
  77. mode and V86 mode, as well as how to execute a mix of 32-bit and 16-bit
  78. programs.
  79.  
  80. Available in All Modes             Part I ── Applications Programming
  81.  
  82. Available in Protected             Part II ── Systems Programming
  83. Mode Only
  84.  
  85. Compatibility Modes                Part III ── Compatibility
  86.  
  87.  
  88. 1.1.1  Part I ── Applications Programming
  89.  
  90. This part presents those aspects of the architecture that are customarily
  91. used by applications programmers.
  92.  
  93. Chapter 2 ── Basic Programming Model: Introduces the models of memory
  94. organization. Defines the data types. Presents the register set used by
  95. applications. Introduces the stack. Explains string operations. Defines the
  96. parts of an instruction. Explains addressing calculations. Introduces
  97. interrupts and exceptions as they may apply to applications programming.
  98.  
  99. Chapter 3 ── Application Instruction Set: Surveys the instructions commonly
  100. used for applications programming. Considers instructions in functionally
  101. related groups; for example, string instructions are considered in one
  102. section, while control-transfer instructions are considered in another.
  103. Explains the concepts behind the instructions. Details of individual
  104. instructions are deferred until Part IV, the instruction-set reference.
  105.  
  106.  
  107. 1.1.2  Part II ── Systems Programming
  108.  
  109. This part presents those aspects of the architecture that are customarily
  110. used by programmers who write operating systems, device drivers, debuggers,
  111. and other software that supports applications programs in the protected mode
  112. of the 80386.
  113.  
  114. Chapter 4 ── Systems Architecture: Surveys the features of the 80386 that 
  115. are used by systems programmers. Introduces the remaining registers and data
  116. structures of the 80386 that were not discussed in Part I. Introduces the
  117. systems-oriented instructions in the context of the registers and data
  118. structures they support. Points to the chapter where each register, data
  119. structure, and instruction is considered in more detail.
  120.  
  121. Chapter 5 ── Memory Management: Presents details of the data structures,
  122. registers, and instructions that support virtual memory and the concepts of
  123. segmentation and paging. Explains how systems designers can choose a model
  124. of memory organization ranging from completely linear ("flat") to fully
  125. paged and segmented.
  126.  
  127. Chapter 6 ── Protection: Expands on the memory management features of the
  128. 80386 to include protection as it applies to both segments and pages.
  129. Explains the implementation of privilege rules, stack switching, pointer
  130. validation, user and supervisor modes. Protection aspects of multitasking
  131. are deferred until the following chapter.
  132.  
  133. Chapter 7 ── Multitasking: Explains how the hardware of the 80386 supports
  134. multitasking with context-switching operations and intertask protection.
  135.  
  136. Chapter 8 ── Input/Output: Reveals the I/O features of the 80386, including
  137. I/O instructions, protection as it relates to I/O, and the I/O permission
  138. map.
  139.  
  140. Chapter 9 ── Exceptions and Interrupts: Explains the basic interrupt
  141. mechanisms of the 80386. Shows how interrupts and exceptions relate to
  142. protection. Discusses all possible exceptions, listing causes and including
  143. information needed to handle and recover from the exception.
  144.  
  145. Chapter 10 ── Initialization: Defines the condition of the processor after
  146. RESET or power-up. Explains how to set up registers, flags, and data
  147. structures for either real-address mode or protected mode. Contains an
  148. example of an initialization program.
  149.  
  150. Chapter 11 ── Coprocessing and Multiprocessing: Explains the instructions
  151. and flags that support a numerics coprocessor and multiple CPUs with shared
  152. memory.
  153.  
  154. Chapter 12 ── Debugging: Tells how to use the debugging registers of the
  155. 80386.
  156.  
  157.  
  158. 1.1.3  Part III ── Compatibility
  159.  
  160. Other parts of the book treat the processor primarily as a 32-bit machine,
  161. omitting for simplicity its facilities for 16-bit operations. Indeed, the
  162. 80386 is a 32-bit machine, but its design fully supports 16-bit operands and
  163. addressing, too. This part completes the picture of the 80386 by explaining
  164. the features of the architecture that support 16-bit programs and 16-bit
  165. operations in 32-bit programs. All three processor modes are used to
  166. execute 16-bit programs: protected mode can directly execute 16-bit 80286
  167. protected mode programs, real mode executes 8086 programs and real-mode
  168. 80286 programs, and virtual 8086 mode executes 8086 programs in a
  169. multitasking environment with other 80386 protected-mode programs. In
  170. addition, 32-bit and 16-bit modules and individual 32-bit and 16-bit
  171. operations can be mixed in protected mode.
  172.  
  173. Chapter 13 ── Executing 80286 Protected-Mode Code: In its protected mode,
  174. the 80386 can execute complete 80286 protected-mode systems, because 80286
  175. capabilities are a subset of 80386 capabilities.
  176.  
  177. Chapter 14 ── 80386 Real-Address Mode: Explains the real mode of the 80386
  178. CPU. In this mode the 80386 appears as a fast real-mode 80286 or fast 8086
  179. enhanced with additional instructions.
  180.  
  181. Chapter 15 ── Virtual 8086 Mode: The 80386 can switch rapidly between its
  182. protected mode and V86 mode, giving it the ability to multiprogram 8086
  183. programs along with "native mode" 32-bit programs.
  184.  
  185. Chapter 16 ── Mixing 16-Bit and 32-Bit Code: Even within a program or task,
  186. the 80386 can mix 16-bit and 32-bit modules. Furthermore, any given module
  187. can utilize both 16-bit and 32-bit operands and addresses.
  188.  
  189.  
  190. 1.1.4  Part IV ── Instruction Set
  191.  
  192. Parts I, II, and III present overviews of the instructions as they relate
  193. to specific aspects of the architecture, but this part presents the
  194. instructions in alphabetical order, providing the detail needed by
  195. assembly-language programmers and programmers of debuggers, compilers,
  196. operating systems, etc. Instruction descriptions include algorithmic
  197. description of operation, effect of flag settings, effect on flag settings,
  198. effect of operand- or address-size attributes, effect of processor modes,
  199. and possible exceptions.
  200.  
  201.  
  202. 1.1.5  Appendices
  203.  
  204. The appendices present tables of encodings and other details in a format
  205. designed for quick reference by assembly-language and systems programmers.
  206.  
  207.  
  208. 1.2  Related Literature
  209.  
  210. The following books contain additional material concerning the 80386
  211. microprocessor:
  212.  
  213.   ■  Introduction to the 80386, order number 231252
  214.  
  215.   ■  80386 Hardware Reference Manual, order number 231732
  216.  
  217.   ■  80386 System Software Writer's Guide, order number 231499
  218.  
  219.   ■  80386 High Performance 32-bit Microprocessor with Integrated Memory
  220.      Management (Data Sheet), order number 231630
  221.  
  222.  
  223. 1.3  Notational Conventions
  224.  
  225. This manual uses special notations for data-structure formats, for symbolic
  226. representation of instructions, for hexadecimal numbers, and for super- and
  227. sub-scripts. Subscript characters are surrounded by {curly brackets}, for
  228. example 10{2} = 10 base 2. Superscript characters are preceeded by a caret
  229. and enclosed within (parentheses), for example 10^(3) = 10 to the third
  230. power. A review of these notations will make it easier to read the
  231. manual.
  232.  
  233. 1.3.1  Data-Structure Formats
  234.  
  235. In illustrations of data structures in memory, smaller addresses appear at
  236. the lower-right part of the figure; addresses increase toward the left and
  237. upwards. Bit positions are numbered from right to left. Figure 1-1
  238. illustrates this convention.
  239.  
  240.  
  241. 1.3.2  Undefined Bits and Software Compatibility
  242.  
  243. In many register and memory layout descriptions, certain bits are marked as
  244. undefined. When bits are marked as undefined (as illustrated in Figure
  245. 1-1), it is essential for compatibility with future processors that
  246. software treat these bits as undefined. Software should follow these
  247. guidelines in dealing with undefined bits:
  248.  
  249.   ■  Do not depend on the states of any undefined bits when testing the
  250.      values of registers that contain such bits. Mask out the undefined bits
  251.      before testing.
  252.  
  253.   ■  Do not depend on the states of any undefined bits when storing them in
  254.      memory or in another register.
  255.  
  256.   ■  Do not depend on the ability to retain information written into any
  257.      undefined bits.
  258.  
  259.   ■  When loading a register, always load the undefined bits as zeros or
  260.      reload them with values previously stored from the same register.
  261.  
  262. ────────────────────────────────────────────────────────────────────────────
  263. NOTE
  264.   Depending upon the values of undefined register bits will make software
  265.   dependent upon the unspecified manner in which the 80386 handles these
  266.   bits. Depending upon undefined values risks making software incompatible
  267.   with future processors that define usages for these bits. AVOID ANY
  268.   SOFTWARE DEPENDENCE UPON THE STATE OF UNDEFINED 80386 REGISTER BITS.
  269. ────────────────────────────────────────────────────────────────────────────
  270.  
  271.  
  272. Figure 1-1.  Example Data Structure
  273.  
  274.  GREATEST                 DATA STRUCTURE
  275.  ADDRESS
  276.   31              23              15              7             0 ──BIT
  277.  ╔═══════════════╪═══════════════╪═══════════════╪═══════════════╗   OFFSET
  278.  ║                                                               ║28
  279.  ╠═══════════════╪═══════════════╪═══════════════╪═══════════════╣
  280.  ║                                                               ║24
  281.  ╠═══════════════╪═══════════════╪═══════════════╪═══════════════╣
  282.  ║                                                               ║20
  283.  ╠═══════════════╪═══════════════╪═══════════════╪═══════════════╣
  284.  ║                                                               ║16
  285.  ╠═══════════════╪═══════════════╪═══════════════╪═══════════════╣
  286.  ║                                                               ║12
  287.  ╠═══════════════╪═══════════════╪═══════════════╪═══════════════╣
  288.  ║                                                               ║8
  289.  ╠═══════════════╪═══════════════╪═══════════════╪═══════════════╣
  290.  ║                           UNDEFINED                           ║4
  291.  ╠═══════════════╪═══════════════╪═══════════════╪═══════════════╣  SMALLEST
  292.  ║    BYTE 3          BYTE 2          BYTE 1          BYTE 0     ║0 ADDRESS
  293.  ╚═══════════════╪═══════════════╪═══════════════╪═══════════════╝
  294.                                                     BYTE OFFSET───┘
  295.  
  296.  
  297. 1.3.3  Instruction Operands
  298.  
  299. When instructions are represented symbolically, a subset of the 80386
  300. Assembly Language is used. In this subset, an instruction has the following
  301. format:
  302.  
  303. label: prefix mnemonic argument1, argument2, argument3
  304.  
  305. where:
  306.  
  307.   ■  A label is an identifier that is followed by a colon.
  308.  
  309.   ■  A prefix is an optional reserved name for one of the instruction
  310.      prefixes.
  311.  
  312.   ■  A mnemonic is a reserved name for a class of instruction opcodes that
  313.      have the same function.
  314.  
  315.   ■  The operands argument1, argument2, and argument3 are optional. There
  316.      may be from zero to three operands, depending on the opcode.  When
  317.      present, they take the form of either literals or identifiers for data
  318.      items.  Operand identifiers are either reserved names of registers or
  319.      are assumed to be assigned to data items declared in another part of
  320.      the program (which may not be shown in the example). When two operands
  321.      are present in an instruction that modifies data, the right operand is
  322.      the source and the left operand is the destination.
  323.  
  324. For example:
  325.  
  326. LOADREG: MOV EAX, SUBTOTAL
  327.  
  328. In this example LOADREG is a label, MOV is the mnemonic identifier of an
  329. opcode, EAX is the destination operand, and SUBTOTAL is the source operand.
  330.  
  331. 1.3.4  Hexadecimal Numbers
  332.  
  333. Base 16 numbers are represented by a string of hexadecimal digits followed
  334. by the character H.  A hexadecimal digit is a character from the set (0, 1,
  335. 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F).  In some cases, especially in
  336. examples of program syntax, a leading zero is added if the number would
  337. otherwise begin with one of the digits A-F.  For example, 0FH is equivalent
  338. to the decimal number 15.
  339.  
  340. 1.3.5  Sub- and Super-Scripts
  341.  
  342. This manual uses special notation to represent sub- and super-script
  343. characters. Sub-script characters are surrounded by {curly brackets}, for
  344. example 10{2} = 10 base 2. Super-script characters are preceeded by a
  345. caret and enclosed within (parentheses), for example 10^(3) = 10 to the
  346. third power.
  347.  
  348.  
  349.                      PART I    APPLICATIONS PROGRAMMING                    
  350.  
  351.