home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / bsd / 4878 < prev    next >
Encoding:
Internet Message Format  |  1992-08-30  |  7.6 KB

  1. From: uhclem@nemesis.UUCP
  2. Date: 29 Aug 92 22:50 CDT
  3. Newsgroups: comp.unix.bsd
  4. Subject: Description of Trap Codes
  5. Message-ID: <-13547389@nemesis>
  6. Path: sparky!uunet!cs.utexas.edu!convex!news.oc.com!utacfd.uta.edu!trsvax!trsvax!nemesis!uhclem
  7. Nf-ID: #N:nemesis:-13547389:000:7408
  8. Nf-From: nemesis.UUCP!uhclem    Aug 29 22:50:00 1992
  9. Lines: 193
  10.  
  11.  
  12. There have been several questions about the various Trap codes
  13. being encountered on the 386/486.  Here is a list of the Trap codes,
  14. along with some common causes for each.
  15.  
  16. Trap    0    Divide Error
  17.         The DIV or IDIV instruction is executed with a zero denominator
  18.         or the quotient is too large for the destination operand.
  19.  
  20.  
  21. Trap    1    Debug Exceptions
  22.         Used in conjunction with DR6 and DR7, The following flags
  23.         need to be tested to determine what caused the trap:
  24.         BS=1                Single-step trap
  25.         B0=1 AND (GE0=1 or LE0=1)    Breakpoint, DR0, LEN0, R/W0
  26.         B1=1 AND (GE1=1 or LE1=1)    Breakpoint, DR1, LEN1, R/W1
  27.         B2=1 AND (GE2=1 or LE2=1)    Breakpoint, DR2, LEN2, R/W2
  28.         B3=1 AND (GE3=1 or LE3=1)    Breakpoint, DR3, LEN3, R/W3
  29.         BD=1                Debug registers not available,
  30.                         in use by ICE-386
  31.         BT=1                Task Switch
  32.         
  33.  
  34. Trap    2    NMI Interrupt
  35.         On PC/AT systems, the NMI input to the CPU is usually
  36.         connected to the main memory parity circuit.  By the time the
  37.         error signal is generated, the data may have already been
  38.         used in an instruction, so it isn't possible to reliably
  39.         recover.
  40.  
  41.  
  42. Trap    3    Breakpoint
  43.         The result of executing an INT 3 instruction.  MS-DOS and
  44.         Windows and some other non-386 systems use this for debugging.
  45.         Code specific to the 386 and later processors should use
  46.         the debugging features tied to Trap 1.
  47.  
  48.  
  49. Trap    4    INT0 Detected Overflow
  50.         Occurs if an INT0 instruction is executed and the overflow
  51.         flag (OF) is currently set.
  52.  
  53.  
  54. Trap    5    BOUND Range Exceeded
  55.         Occurs if the BOUND instruction is executed and the array
  56.         index points beyond the area of memory containing the array
  57.         being tested.
  58.  
  59.  
  60. Trap    6    Invalid Opcode
  61.         The value read at CS:IP is not a valid opcode.
  62.  
  63.  
  64. Trap    7    Coprocessor Not Available
  65.         This occurs if the processor fetches an instruction that is
  66.         for the coprocessor and no coprocessor is present.
  67.  
  68.  
  69. Trap    8    Double Exception (Fault)
  70.         An exception occurred while trying to execute the handler
  71.         for a prior exception.  Example, an application causes a
  72.         General Protection Fault (13) and the area of memory where
  73.         the GPF handler should be is flagged not-present (paged-out?).
  74.         The double-fault handler is invoked in these conditions.
  75.         If a fault occurs while trying to run the double-fault handler,
  76.         a triple-fault occurs and the CPU resets.
  77.  
  78.         The rules for deciding if a double-fault should occur or
  79.         if the two faults can be handled serially are discussed in
  80.         more detail in the Intel song book.
  81.  
  82.  
  83. Trap    9    Coprocessor Segment Overrun
  84.         A page or segment violation occurred while transferring
  85.         the middle part of a coprocessor operand to the NPX.
  86.  
  87.  
  88. Trap    10    Invalid Task State Segment
  89.         During a task switch, the new TSS was invalid.  Here is
  90.         a table of conditions that Invalidate the TSS:
  91.         TSS id + EXT    The limit in the TSS descriptor is < 103
  92.         LTD id + EXT    Invalid LDT selector or LDT not present
  93.         SS id + EXT    Stack segment selector is outside table limit
  94.         SS id + EXT    Stack segment is not a writable segment
  95.         SS id + EXT    Stack segment DPL does not match new CPL
  96.         SS id + EXT    Stack segment selector RPL <> CPL
  97.         CS id + EXT     Code segment is outside table limit
  98.         CS id + EXT    Code segment selector does not refer to
  99.                     code segment
  100.         CS id + EXT    DPL of non-conforming code segment <> new CPL
  101.         CS id + EXT    CPL of conforming code segment > new CPL
  102.         DS/ES/FS/GS id + EXT    DS, ES, FS or GS segment selector is
  103.                     outside table limits
  104.         DS/ES/FS/FS id + EXT    DS, ES, FS, or GS is not readable
  105.                     segment
  106.  
  107.  
  108. Trap    11    Segment Not Present
  109.         Occurs when the "present" bit of a descriptor is zero.
  110.         This can occur while loading any of these segment registers
  111.         CS, DS, ES, FS, or GS.  Loading SS causes a Stack fault.
  112.         Also occurs when attempting to use a gate descriptor that is
  113.         marked "not present", and if attempting to load the LDT with
  114.         an LLDT instruction.  Note that loading the LDT during a
  115.         task switch causes an "invalid TSS" trap.
  116.  
  117.  
  118. Trap    12    Stack Fault
  119.         A limit violation relating to an address referenced off
  120.         the SS register.  Includes POP, PUSH, ENTER and LEAVE
  121.         opcodes, as well as references such as MOV AX,[BP+8]
  122.         (which has an implied SS:).
  123.         Also causes by loading SS with a descriptor that is marked
  124.         "not present".
  125.  
  126.  
  127. Trap    13    General Protection Fault (GPF)
  128.         Americas Favorite, in the Windows 3.0 world, it is known as
  129.         the UAE error.  The instruction tried to access data out of
  130.         the bounds designated by the descriptors.  The access that
  131.         failed can be a read, write or instruction fetch.  There are
  132.         15 classifications of GPFs:
  133.         1.  Exceeding segment limit when using CS, DE, ES, FS or GS.
  134.         2.  Exceeding segment limit when referencing a descriptor
  135.             table.
  136.         3.  Transferring control to a segment that is not executable.
  137.         4.  Writing into a read-only data segment or into a code
  138.             segment.
  139.         5.  Reading from an execute-only segment.
  140.         6.  Loading the SS register with a read-only descriptor
  141.             (unless the selector comes from the TSS during a task
  142.             switch, in which case a TSS exception occurs.)
  143.         7.  Loading SS, DS, ES, FS or GS with the descriptor of a
  144.             system segment.
  145.         8.  Loading, DS, ES, FS or GS with the descriptor of an
  146.             executable segment that is not also readable.
  147.         9.  Loading SS with the descriptor of an executable segment.
  148.         10. Accessing memory via, DS, ES, FS or GS when the segment
  149.             register contains a null selector.
  150.         11. Switching to a busy task.
  151.         12. Violating priviledge rules.
  152.         13. Loading CR0 with a PG=1 and PE=0.
  153.         14. Interrupt or exception via trap or interrupt gate from
  154.             V86 mode to prviledge level other than zero.
  155.         15. Exceeding the instruction limit of 15 bytes (this can
  156.             only occur if redundant prefixes are placed before an
  157.             instruction).
  158.         To determine which condition caused the trap, you need
  159.         the instruction, the contents of all associated registers,
  160.         particularly the segment registers involved, then the various
  161.         LDT, GDT and page control tables.  Lots of common coding
  162.         errors cause the GPFs.  Even a stack imbalance will usually
  163.         show up as a GPF.   Even MOV AX,7 MOV ES,AX or 
  164.         MOV AX,5 PUSH AX POP DS will get a GPF error.  You can't
  165.         use a segment register for "temporary storage" of any
  166.         old value the way you could on the 8086.  The values loaded
  167.         into the segment registers are checked in protected mode.
  168.  
  169.  
  170. Trap    14    Page Fault
  171.         The page directory or page table entry needed for the address
  172.         translation has a zero in the present bit, or the current
  173.         procedure does not have sufficient priviledge to access the
  174.         indicated page.
  175.  
  176. Trap    15    (reserved)
  177.  
  178.  
  179. Trap    16    Coprocessor Error
  180.         The coprocessor asserted the ERROR# input pin on the 386
  181.         (internal on the 486)
  182.  
  183.  
  184. Trap    17    Alignment Check (486 and later)
  185.         If enabled, this trap will occur if a data fetch does not
  186.         occur on a word boundary.  I don't know of any software that
  187.         activates this feature yet.  I have seen SCO UNIX get this
  188.         error on early Cyrix processors, even though SCO had not
  189.         enabled the feature.
  190.  
  191.  
  192. Trap    18-32    (reserved)
  193.  
  194. All this information and more can be found in the variuous programmers
  195. references from Intel and other compatible chip vendors.
  196.  
  197.  
  198. Frank Durda IV <uhclem@nemesis.lonestar.org>|"The Knights who say "LETNi"
  199. ...utacfd!nemesis!uhclem (nearest internet) | demand...  A SEGMENT REGISTER!!!"
  200. ...letni!rwsys!nemesis!uhclem                |"A what?"
  201. ...decvax!microsoft!trsvax!nemesis!uhclem   |"LETNi! LETNi! LETNi!"  - 1983
  202.  
  203.  
  204.