⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s09_08.htm

📁 Programmer s Reference Manual is an improtant book on Intel processor architecture and programming.
💻 HTM
📖 第 1 页 / 共 2 页
字号:
</A><H2>9.8.11 Interrupt 11 -- Segment Not Present</H2>Exception 11 occurs when the processor detects that the present bit of adescriptor is zero. The processor can trigger this fault in any of thesecases:<UL><LI> While attempting to load the CS, DS, ES, FS, or GS registers; loadingthe SS register, however, causes a stack fault.<LI> While attempting loading the LDT register with an <A HREF="LLDT.htm">LLDT</A> instruction;loading the LDT register during a task switch operation, however,causes the "invalid TSS" exception.<LI> While attempting to use a gate descriptor that is marked not-present.</UL>This fault is restartable. If the exception handler makes the segmentpresent and returns, the interrupted program will resume execution.<P>If a not-present exception occurs during a task switch, not all the stepsof the task switch are complete. During a task switch, the processor firstloads all the segment registers, then checks their contents for validity. Ifa not-present exception is discovered, the remaining segment registers havenot been checked and therefore may not be usable for referencing memory. Thenot-present handler should not rely on being able to use the values foundin CS, SS, DS, ES, FS, and GS without causing another exception. Theexception handler should check all segment registers before trying to resumethe new task; otherwise, general protection faults may result later underconditions that make diagnosis more difficult. There are three ways tohandle this case:<OL><LI> Handle the not-present fault with a task. The task switch back to theinterrupted task will cause the processor to check the registers as itloads them from the TSS.<LI> <A HREF="PUSH.htm">PUSH</A> and <A HREF="POP.htm">POP</A> all segment registers. Each <A HREF="POP.htm">POP</A> causes the processor tocheck the new contents of the segment register.<LI> Scrutinize the contents of each segment-register image in the TSS,simulating the test that the processor makes when it loads a segmentregister.</OL>This exception pushes an error code onto the stack. The EXT bit of theerror code is set if an event external to the program caused an interruptthat subsequently referenced a not-present segment. The I-bit is set if theerror code refers to an IDT entry, e.g., an <A HREF="INT.htm">INT</A> instruction referencing anot-present gate.<P>An operating system typically uses the "segment not present" exception toimplement virtual memory at the segment level. A not-present indication in agate descriptor, however, usually does not indicate that a segment is notpresent (because gates do not necessarily correspond to segments).Not-present gates may be used by an operating system to trigger exceptionsof special significance to the operating system.<H2>9.8.12 Interrupt 12 -- Stack Exception</H2>A stack fault occurs in either of two general conditions:<UL><LI> As a result of a limit violation in any operation that refers to theSS register. This includes stack-oriented instructions such as <A HREF="POP.htm">POP</A>,<A HREF="PUSH.htm">PUSH</A>, <A HREF="ENTER.htm">ENTER</A>, and <A HREF="LEAVE.htm">LEAVE</A>, as well as other memory references thatimplicitly use SS (for example, <TT><A HREF="MOV.htm">MOV</A> AX, [BP+6]</TT>). <A HREF="ENTER.htm">ENTER</A> causes thisexception when the stack is too small for the indicated local-variablespace.<LI> When attempting to load the SS register with a descriptor that ismarked not-present but is otherwise valid. This can occur in a taskswitch, an interlevel <A HREF="CALL.htm">CALL</A>, an interlevel return, an <A HREF="LGS.htm">LSS</A> instruction,or a <A HREF="MOV.htm">MOV</A> or <A HREF="POP.htm">POP</A> instruction to SS.</UL>When the processor detects a stack exception, it pushes an error code ontothe stack of the exception handler. If the exception is due to a not-presentstack segment or to overflow of the new stack during an interlevel <A HREF="CALL.htm">CALL</A>, theerror code contains a selector to the segment in question (the exceptionhandler can test the present bit in the descriptor to determine whichexception occurred); otherwise the error code is zero.<P>An instruction that causes this fault is restartable in all cases. Thereturn pointer pushed onto the exception handler's stack points to theinstruction that needs to be restarted. This instruction is usually the onethat caused the exception; however, in the case of a stack exception due toloading of a not-present stack-segment descriptor during a task switch, theindicated instruction is the first instruction of the new task.<P>When a stack fault occurs during a task switch, the segment registers maynot be usable for referencing memory. During a task switch, the selectorvalues are loaded before the descriptors are checked. If a stack fault isdiscovered, the remaining segment registers have not been checked andtherefore may not be usable for referencing memory. The stack fault handlershould not rely on being able to use the values found in CS, SS, DS, ES,FS, and GS without causing another exception. The exception handler shouldcheck all segment registers before trying to resume the new task; otherwise,general protection faults may result later under conditions that makediagnosis more difficult.<H2>9.8.13 Interrupt 13 -- General Protection Exception</H2>All protection violations that do not cause another exception cause ageneral protection exception. This includes (but is not limited to):<OL><LI> Exceeding segment limit when using CS, DS, ES, FS, or GS<LI> Exceeding segment limit when referencing a descriptor table<LI> Transferring control to a segment that is not executable<LI> Writing into a read-only data segment or into a code segment<LI> Reading from an execute-only segment<LI> Loading the SS register with a read-only descriptor (unless theselector comes from the TSS during a task switch, in which case a TSSexception occurs<LI> Loading SS, DS, ES, FS, or GS with the descriptor of a system segment<LI> Loading DS, ES, FS, or GS with the descriptor of an executablesegment that is not also readable<LI> Loading SS with the descriptor of an executable segment<LI> Accessing memory via DS, ES, FS, or GS when the segment registercontains a null selector<LI> Switching to a busy task<LI> Violating privilege rules<LI> Loading CR0 with PG=1 and PE=0.<LI> Interrupt or exception via trap or interrupt gate from V86 mode toprivilege level other than zero.<LI> Exceeding the instruction length limit of 15 bytes (this can occuronly if redundant prefixes are placed before an instruction)</OL>The general protection exception is a fault. In response to a generalprotection exception, the processor pushes an error code onto the exceptionhandler's stack. If loading a descriptor causes the exception, the errorcode contains a selector to the descriptor; otherwise, the error code isnull. The source of the selector in an error code may be any of thefollowing:<OL><LI> An operand of the instruction.<LI> A selector from a gate that is the operand of the instruction.<LI> A selector from a TSS involved in a task switch.</OL><H2>9.8.14 Interrupt 14 -- Page Fault</H2>This exception occurs when paging is enabled (PG=1) and the processordetects one of the following conditions while translating a linear addressto a physical address:<UL><LI> The page-directory or page-table entry needed for the addresstranslation has zero in its present bit.<LI> The current procedure does not have sufficient privilege to access theindicated page.</UL>The processor makes available to the page fault handler two items ofinformation that aid in diagnosing the exception and recovering from it:<UL><LI> An error code on the stack. The error code for a page fault has aformat different from that for other exceptions (see <A HREF="#fig9-8">Figure 9-8</A>  ). Theerror code tells the exception handler three things:<OL><LI> Whether the exception was due to a not present page or to an accessrights violation.<LI> Whether the processor was executing at user or supervisor level atthe time of the exception.<LI> Whether the memory access that caused the exception was a read orwrite.</OL><LI> CR2 (control register two). The processor stores in CR2 the linearaddress used in the access that caused the exception (see <A HREF="#fig9-9">Figure 9-9</A>).The exception handler can use this address to locate the correspondingpage directory and page table entries. If another page fault can occurduring execution of the page fault handler, the handler should push CR2onto the stack.</UL><P><A NAME="fig9-8"><IMG align=center SRC="fig9-8.gif" border=0><P><H3>9.8.14.1  Page Fault During Task Switch</H3>The processor may access any of four segments during a task switch:<OL><LI> Writes the state of the original task in the TSS of that task.<LI> Reads the GDT to locate the TSS descriptor of the new task.<LI> Reads the TSS of the new task to check the types of segmentdescriptors from the TSS.<LI> May read the LDT of the new task in order to verify the segmentregisters stored in the new TSS.</OL>A page fault can result from accessing any of these segments. In the lattertwo cases the exception occurs in the context of the new task. Theinstruction pointer refers to the next instruction of the new task, not tothe instruction that caused the task switch. If the design of the operatingsystem permits page faults to occur during task-switches, the page-faulthandler should be invoked via a task gate.<P><A NAME="fig9-9"><IMG align=center SRC="fig9-9.gif" border=0><H3>9.8.14.2  Page Fault with Inconsistent Stack Pointer</H3>Special care should be taken to ensure that a page fault does not cause theprocessor to use an invalid stack pointer (SS:ESP). Software written forearlier processors in the 8086 family often uses a pair of instructions tochange to a new stack; for example:<PRE><A HREF="MOV.htm">MOV</A> SS, AX<A HREF="MOV.htm">MOV</A> SP, StackTop</PRE>With the 80386, because the second instruction accesses memory, it ispossible to get a page fault after SS has been changed but before SP hasreceived the corresponding change. At this point, the two parts of the stackpointer SS:SP (or, for 32-bit programs, SS:ESP) are inconsistent.<P>The processor does not use the inconsistent stack pointer if the handlingof the page fault causes a stack switch to a well defined stack (i.e., thehandler is a task or a more privileged procedure). However, if the pagefault handler is invoked by a trap or interrupt gate and the page faultoccurs at the same privilege level as the page fault handler, the processorwill attempt to use the stack indicated by the current (invalid) stackpointer.<P>In systems that implement paging and that handle page faults within thefaulting task (with trap or interrupt gates), software that executes at thesame privilege level as the page fault handler should initialize a new stackby using the new <A HREF="LGS.htm">LSS</A> instruction rather than an instruction pair shownabove. When the page fault handler executes at privilege level zero (thenormal case), the scope of the problem is limited to privilege-level zerocode, typically the kernel of the operating system.<H2>9.8.15 Interrupt 16 -- Coprocessor Error</H2>The 80386 reports this exception when it detects a signal from the 80287 or80387 on the 80386's ERROR# input pin. The 80386 tests this pin only at thebeginning of certain ESC instructions and when it encounters a <A HREF="WAIT.htm">WAIT</A>instruction while the EM bit of the MSW is zero (no emulation). Refer to<A HREF="c11.htm">Chapter 11</A>   for more information on the coprocessor interface.<P><HR><P><B>up:</B> <A HREF="c09.htm">Chapter 9 -- Exceptions and Interrupts</A><BR><B>prev:</B> <A HREF="s09_07.htm">9.7  Error Code</A><BR><B>next:</B> <A HREF="s09_09.htm">9.9  Exception Summary</A></BODY>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -