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

  1. Chapter 13  Executing 80286 Protected-Mode Code
  2.  
  3. ────────────────────────────────────────────────────────────────────────────
  4.  
  5. 13.1  80286 Code Executes as a Subset of the 80386
  6.  
  7. In general, programs designed for execution in protected mode on an 80286
  8. execute without modification on the 80386, because the features of the 80286
  9. are a subset of those of the 80386.
  10.  
  11. All the descriptors used by the 80286 are supported by the 80386 as long as
  12. the Intel-reserved word (last word) of the 80286 descriptor is zero.
  13.  
  14. The descriptors for data segments, executable segments, local descriptor
  15. tables, and task gates are common to both the 80286 and the 80386. Other
  16. 80286 descriptors──TSS segment, call gate, interrupt gate, and trap
  17. gate──are supported by the 80386. The 80386 also has new versions of
  18. descriptors for TSS segment, call gate, interrupt gate, and trap gate that
  19. support the 32-bit nature of the 80386. Both sets of descriptors can be
  20. used simultaneously in the same system.
  21.  
  22. For those descriptors that are common to both the 80286 and the 80386, the
  23. presence of zeros in the final word causes the 80386 to interpret these
  24. descriptors exactly as 80286 does; for example:
  25.  
  26. Base Address      The high-order eight bits of the 32-bit base address are
  27.                   zero, limiting base addresses to 24 bits.
  28.  
  29. Limit             The high-order four bits of the limit field are zero,
  30.                   restricting the value of the limit field to 64K.
  31.  
  32. Granularity bit   The granularity bit is zero, which implies that the value
  33.                   of the 16-bit limit is interpreted in units of one byte.
  34.  
  35. B-bit             In a data-segment descriptor, the B-bit is zero, implying
  36.                   that the segment is no larger than 64 Kbytes.
  37.  
  38. D-bit             In an executable-segment descriptor, the D-bit is zero,
  39.                   implying that 16-bit addressing and operands are the
  40.                   default.
  41.  
  42. For formats of these descriptors and documentation of their use refer to
  43. the iAPX 286 Programmer's Reference Manual.
  44.  
  45.  
  46. 13.2  Two ways to Execute 80286 Tasks
  47.  
  48. When porting 80286 programs to the 80386, there are two cases to consider:
  49.  
  50.   1.  Porting an entire 80286 system to the 80386, complete with 80286
  51.       operating system, loader, and system builder.
  52.  
  53.       In this case, all tasks will have 80286 TSSs. The 80386 is being used
  54.       as a faster 286.
  55.  
  56.   2.  Porting selected 80286 applications to run in an 80386 environment
  57.       with an 80386 operating system, loader, and system builder.
  58.  
  59.       In this case, the TSSs used to represent 80286 tasks should be
  60.       changed to 80386 TSSs. It is theoretically possible to mix 80286 and
  61.       80386 TSSs, but the benefits are slight and the problems are great. It
  62.       is recommended that all tasks in a 80386 software system have 80386
  63.       TSSs. It is not necessary to change the 80286 object modules
  64.       themselves; TSSs are usually constructed by the operating system, by
  65.       the loader, or by the system builder. Refer to Chapter 16 for further
  66.       discussion of the interface between 16-bit and 32-bit code.
  67.  
  68.  
  69. 13.3  Differences From 80286
  70.  
  71. The few differences that do exist primarily affect operating system code.
  72.  
  73.  
  74. 13.3.1  Wraparound of 80286 24-Bit Physical Address Space
  75.  
  76. With the 80286, any base and offset combination that addresses beyond 16M
  77. bytes wraps around to the first megabyte of the 80286 address space. With
  78. the 80386, since it has a greater physical address space, any such address
  79. falls into the 17th megabyte. In the unlikely event that any software
  80. depends on this anomaly, the same effect can be simulated on the 80386 by
  81. using paging to map the first 64K bytes of the 17th megabyte of logical
  82. addresses to physical addresses in the first megabyte.
  83.  
  84.  
  85. 13.3.2  Reserved Word of Descriptor
  86.  
  87. Because the 80386 uses the contents of the reserved word (last word) of
  88. every descriptor, 80286 programs that place values in this word may not
  89. execute correctly on the 80386.
  90.  
  91.  
  92. 13.3.3  New Descriptor Type Codes
  93.  
  94. Operating-system code that manages space in descriptor tables often uses an
  95. invalid value in the access-rights field of descriptor-table entries to
  96. identify unused entries. Access rights values of 80H and 00H remain invalid
  97. for both the 80286 and 80386. Other values that were invalid on for the
  98. 80286 may be valid for the 80386 because of the additional descriptor types
  99. defined by the 80386.
  100.  
  101.  
  102. 13.3.4  Restricted Semantics of LOCK
  103.  
  104. The 80286 processor implements the bus lock function differently than the
  105. 80386. Programs that use forms of memory locking specific to the 80286 may
  106. not execute properly when transported to a specific application of the
  107. 80386.
  108.  
  109. The LOCK prefix and its corresponding output signal should only be used to
  110. prevent other bus masters from interrupting a data movement operation.  LOCK
  111. may only be used with the following 80386 instructions when they modify
  112. memory. An undefined-opcode exception results from using LOCK before any
  113. other instruction.
  114.  
  115.   ■  Bit test and change:  BTS, BTR, BTC.
  116.   ■  Exchange: XCHG.
  117.   ■  One-operand arithmetic and logical: INC, DEC, NOT, and NEG.
  118.   ■  Two-operand arithmetic and logical:  ADD, ADC, SUB, SBB, AND, OR, XOR.
  119.  
  120. A locked instruction is guaranteed to lock only the area of memory defined
  121. by the destination operand, but may lock a larger memory area.  For example,
  122. typical 8086 and 80286 configurations lock the entire physical memory space.
  123. With the 80386, the defined area of memory is guaranteed to be locked
  124. against access by a processor executing a locked instruction on exactly the
  125. same memory area, i.e., an operand with identical starting address and
  126. identical length.
  127.  
  128.  
  129. 13.3.5  Additional Exceptions
  130.  
  131. The 80386 defines new exceptions that can occur even in systems designed
  132. for the 80286.
  133.  
  134.   ■  Exception #6 ── invalid opcode
  135.  
  136.      This exception can result from improper use of the LOCK instruction.
  137.  
  138.   ■  Exception #14 ── page fault
  139.  
  140.      This exception may occur in an 80286 program if the operating system
  141.      enables paging. Paging can be used in a system with 80286 tasks as long
  142.      as all tasks use the same page directory. Because there is no place in
  143.      an 80286 TSS to store the PDBR, switching to an 80286 task does not
  144.      change the value of PDBR. Tasks ported from the 80286 should be given
  145.      80386 TSSs so they can take full advantage of paging.
  146.  
  147.  
  148.