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

  1. Chapter 4  Systems Architecture
  2.  
  3. ────────────────────────────────────────────────────────────────────────────
  4.  
  5. Many of the architectural features of the 80386 are used only by systems
  6. programmers. This chapter presents an overview of these aspects of the
  7. architecture.
  8.  
  9. The systems-level features of the 80386 architecture include:
  10.  
  11.   Memory Management
  12.   Protection
  13.   Multitasking
  14.   Input/Output
  15.   Exceptions and Interrupts
  16.   Initialization
  17.   Coprocessing and Multiprocessing
  18.   Debugging
  19.  
  20. These features are implemented by registers and instructions, all of which
  21. are introduced in the following sections. The purpose of this chapter is not
  22. to explain each feature in detail, but rather to place the remaining
  23. chapters of Part II in perspective. Each mention in this chapter of a
  24. register or instruction is either accompanied by an explanation or a
  25. reference to a following chapter where detailed information can be obtained.
  26.  
  27.  
  28. 4.1  Systems Registers
  29.  
  30. The registers designed for use by systems programmers fall into these
  31. classes:
  32.  
  33.   EFLAGS
  34.   Memory-Management Registers
  35.   Control Registers
  36.   Debug Registers
  37.   Test Registers
  38.  
  39.  
  40. 4.1.1  Systems Flags
  41.  
  42. The systems flags of the EFLAGS register control I/O, maskable interrupts,
  43. debugging, task switching, and enabling of virtual 8086 execution in a
  44. protected, multitasking environment. These flags are highlighted in Figure
  45. 4-1.
  46.  
  47. IF (Interrupt-Enable Flag, bit 9)
  48.  
  49.    Setting IF allows the CPU to recognize external (maskable) interrupt
  50.    requests. Clearing IF disables these interrupts. IF has no effect on
  51.    either exceptions or nonmaskable external interrupts. Refer to Chapter
  52.    9 for more details about interrupts.
  53.  
  54. NT (Nested Task, bit 14)
  55.  
  56.    The processor uses the nested task flag to control chaining of
  57.    interrupted and called tasks. NT influences the operation of the IRET
  58.    instruction. Refer to Chapter 7 and Chapter 9 for more information on
  59.    nested tasks.
  60.  
  61. RF (Resume Flag, bit 16)
  62.  
  63.    The RF flag temporarily disables debug exceptions so that an instruction
  64.    can be restarted after a debug exception without immediately causing
  65.    another debug exception. Refer to Chapter 12 for details.
  66.  
  67. TF (Trap Flag, bit 8)
  68.  
  69.    Setting TF puts the processor into single-step mode for debugging. In
  70.    this mode, the CPU automatically generates an exception after each
  71.    instruction, allowing a program to be inspected as it executes each
  72.    instruction. Single-stepping is just one of several debugging features of
  73.    the 80386. Refer to Chapter 12 for additional information.
  74.  
  75. VM (Virtual 8086 Mode, bit 17)
  76.  
  77.    When set, the VM flag indicates that the task is executing an 8086
  78.    program. Refer to Chapter 14 for a detailed discussion of how the 80386
  79.    executes 8086 tasks in a protected, multitasking environment.
  80.  
  81.  
  82. Figure 4-1.  System Flags of EFLAGS Register
  83.  
  84.       31              23               15                7           0
  85.      ╔═══════════════╪═══════════╤═╤═╤╪╤═╤════╤═╤═╤═╤═╤╪╤═╤═╤═╤═╤═╤═╤═╗
  86.      ║▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│V│R│▒│N│ID  │O│D│I│T│S│Z│▒│A│▒│P│▒│C║
  87.      ║0 0 0 0 0 0 0 0 0 0 0 0 0 0│ │ │0│ │    │▒│▒│ │▒│▒│▒│0│▒│0│▒│1│▒║
  88.      ║▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│M│F│▒│T│  PL│F│F│F│F│F│F│▒│F│▒│F│▒│F║
  89.      ╚═══════════════╪═══════════╧╤╧╤╧╪╧╤╧═╤══╧═╧═╧╤╧═╧╪╧═╧═╧═╧═╧═╧═╧═╝
  90.                                   │ │   │  │       │
  91.              VIRTUAL 8086 MODE────┘ │   │  │       │
  92.                    RESUME FLAG──────┘   │  │       │
  93.               NESTED TASK FLAG──────────┘  │       │
  94.            I/O PRIVILEGE LEVEL─────────────┘       │
  95.               INTERRUPT ENABLE─────────────────────┘
  96.  
  97. ────────────────────────────────────────────────────────────────────────────
  98. NOTE
  99.       0 OR 1 INDICATES INTEL RESERVED. DO NOT DEFINE.
  100. ────────────────────────────────────────────────────────────────────────────
  101.  
  102.  
  103. 4.1.2  Memory-Management Registers
  104.  
  105. Four registers of the 80386 locate the data structures that control
  106. segmented memory management:
  107.  
  108. GDTR    Global Descriptor Table Register
  109. LDTR    Local Descriptor Table Register
  110.  
  111.    These registers point to the segment descriptor tables GDT and LDT.
  112.    Refer to Chapter 5 for an explanation of addressing via descriptor
  113.    tables.
  114.  
  115. IDTR    Interrupt Descriptor Table Register
  116.  
  117.    This register points to a table of entry points for interrupt handlers
  118.    (the IDT). Refer to Chapter 9 for details of the interrupt mechanism.
  119.  
  120. TR      Task Register
  121.  
  122.    This register points to the information needed by the processor to define
  123.    the current task. Refer to Chapter 7 for a description of the
  124.    multitasking features of the 80386.
  125.  
  126.  
  127. 4.1.3  Control Registers
  128.  
  129. Figure 4-2 shows the format of the 80386 control registers CR0, CR2, and
  130. CR3. These registers are accessible to systems programmers only via variants
  131. of the MOV instruction, which allow them to be loaded from or stored in
  132. general registers; for example:
  133.  
  134. MOV EAX, CR0
  135. MOV CR3, EBX
  136.  
  137. CR0 contains system control flags, which control or indicate conditions
  138. that apply to the system as a whole, not to an individual task.
  139.  
  140. EM (Emulation, bit 2)
  141.  
  142.    EM indicates whether coprocessor functions are to be emulated. Refer to
  143.    Chapter 11 for details.
  144.  
  145. ET (Extension Type, bit 4)
  146.  
  147.    ET indicates the type of coprocessor present in the system (80287 or
  148.    80387). Refer to Chapter 11 and Chapter 10 for details.
  149.  
  150. MP (Math Present, bit 1)
  151.  
  152.    MP controls the function of the WAIT instruction, which is used to
  153.    coordinate a coprocessor. Refer to Chapter 11 for details.
  154.  
  155. PE (Protection Enable, bit 0)
  156.  
  157.    Setting PE causes the processor to begin executing in protected mode.
  158.    Resetting PE returns to real-address mode. Refer to Chapter 14 and
  159.    Chapter 10 for more information on changing processor modes.
  160.  
  161. PG (Paging, bit 31)
  162.  
  163.    PG indicates whether the processor uses page tables to translate linear
  164.    addresses into physical addresses. Refer to Chapter 5 for a description
  165.    of page translation; refer to Chapter 10 for a discussion of how to set
  166.    PG.
  167.  
  168. TS (Task Switched, bit 3)
  169.  
  170.    The processor sets TS with every task switch and tests TS when
  171.    interpreting coprocessor instructions. Refer to Chapter 11 for details.
  172.  
  173. CR2 is used for handling page faults when PG is set. The processor stores
  174. in CR2 the linear address that triggers the fault. Refer to Chapter 9 for a
  175. description of page-fault handling.
  176.  
  177. CR3 is used when PG is set. CR3 enables the processor to locate the page
  178. table directory for the current task. Refer to Chapter 5 for a description
  179. of page tables and page translation.
  180.  
  181.  
  182. Figure 4-2.  Control Registers
  183.  
  184.  31                23                15                7               0
  185. ╔═════════════════╪═════════════════╪════════╦════════╪═════════════════╗
  186. ║                                            ║                          ║
  187. ║    PAGE DIRECTORY BASE REGISTER (PDBR)     ║         RESERVED         ║CR3
  188. ╟────────────────────────────────────────────╨──────────────────────────╢
  189. ║                                                                       ║
  190. ║                       PAGE FAULT LINEAR ADDRESS                       ║CR2
  191. ╟───────────────────────────────────────────────────────────────────────╢
  192. ║                                                                       ║
  193. ║                                RESERVED                               ║CR1
  194. ╟─┬───────────────────────────────────────────────────────────┬─┬─┬─┬─┬─╢
  195. ║P│                                                           │E│T│E│M│P║
  196. ║G│                              RESERVED                     │T│S│M│P│E║CR0
  197. ╚═╧═══════════════╪═════════════════╪═════════════════╪═══════╧═╧═╧═╧═╧═╝
  198.  
  199.  
  200. 4.1.4  Debug Register
  201.  
  202. The debug registers bring advanced debugging abilities to the 80386,
  203. including data breakpoints and the ability to set instruction breakpoints
  204. without modifying code segments. Refer to Chapter 12 for a complete
  205. description of formats and usage.
  206.  
  207.  
  208. 4.1.5  Test Registers
  209.  
  210. The test registers are not a standard part of the 80386 architecture. They
  211. are provided solely to enable confidence testing of the translation
  212. lookaside buffer (TLB), the cache used for storing information from page
  213. tables. Chapter 12 explains how to use these registers.
  214.  
  215.  
  216. 4.2  Systems Instructions
  217.  
  218. Systems instructions deal with such functions as:
  219.  
  220.   1.  Verification of pointer parameters (refer to Chapter 6):
  221.  
  222.     ARPL             ── Adjust RPL
  223.     LAR              ── Load Access Rights
  224.     LSL              ── Load Segment Limit
  225.     VERR             ── Verify for Reading
  226.     VERW             ── Verify for Writing
  227.  
  228.   2.  Addressing descriptor tables (refer to Chaper 5):
  229.  
  230.     LLDT             ── Load LDT Register
  231.     SLDT             ── Store LDT Register
  232.     LGDT             ── Load GDT Register
  233.     SGDT             ── Store GDT Register
  234.  
  235.   3.  Multitasking (refer to Chapter 7):
  236.  
  237.     LTR              ── Load Task Register
  238.     STR              ── Store Task Register
  239.  
  240.   4. Coprocessing and Multiprocessing (refer to Chapter 11):
  241.  
  242.     CLTS             ── Clear Task-Switched Flag
  243.     ESC              ── Escape instructions
  244.     WAIT             ── Wait until Coprocessor not Busy
  245.     LOCK             ── Assert Bus-Lock Signal
  246.  
  247.   5.  Input and Output (refer to Chapter 8):
  248.  
  249.     IN               ── Input
  250.     OUT              ── Output
  251.     INS              ── Input String
  252.     OUTS             ── Output String
  253.  
  254.   6.  Interrupt control (refer to Chapter 9):
  255.  
  256.     CLI              ── Clear Interrupt-Enable Flag
  257.     STI              ── Set Interrupt-Enable Flag
  258.     LIDT             ── Load IDT Register
  259.     SIDT             ── Store IDT Register
  260.  
  261.   7.  Debugging (refer to Chapter 12):
  262.  
  263.     MOV              ── Move to and from debug registers
  264.  
  265.   8.  TLB testing (refer to Chapter 10):
  266.  
  267.     MOV              ── Move to and from test registers
  268.  
  269.   9.  System Control:
  270.  
  271.     SMSW             ── Set MSW
  272.     LMSW             ── Load MSW
  273.     HLT              ── Halt Processor
  274.     MOV              ── Move to and from control registers
  275.  
  276. The instructions SMSW and LMSW are provided for compatibility with the
  277. 80286 processor.  80386 programs access the MSW in CR0 via variants of the
  278. MOV instruction.  HLT stops the processor until receipt of an INTR or RESET
  279. signal.
  280.  
  281. In addition to the chapters cited above, detailed information about each of
  282. these instructions can be found in the instruction reference chapter,
  283. Chapter 17.
  284.  
  285.  
  286.