IntelSoftwareDevelopersManual

To keep spurious task switches from succeeding the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: within the execution of another task, and the previous task link field of the current task's TSS holds the TSS selector for the higher-level task in the nesting hierarchy, if there is one (refer to Figure 6-7). When a CALL instruction, an interrupt, or an exception causes a task switch, the processor copies the segment selector for the current TSS into the previous task link field of the TSS for the new task, and then sets the NT flag in the EFLAGS register. The NT flag indicates that the previous task link field of the TSS has been loaded with a saved TSS segment selector. If software uses an IRET instruction to suspend the new task, the processor uses the value in the previous task link field and the NT flag to return to the previous task; that is, if the NT flag is set, the processor performs a task switch to the task specified in the previous task link field. 6-14 TASK MANAGEMENT NOTE When a JMP instruction causes a task switch, the new task is not nested; that is, the NT flag is set to 0 and the previous task link field is not used. A JMP instruction is used to dispatch a new task when nesting is not desired. Top Level Task TSS Nested Task TSS More Deeply Nested Task TSS Currently Executing Task EFLAGS NT=1 NT=0 NT=1 NT=1 Prev. Task Link Prev. Task Link Prev. Task Link Task Register Figure 6-7. Nested Tasks Table 6-2 summarizes the uses of the busy flag (in the TSS segment descriptor), the NT flag, the previous task link field, and TS flag (in control register CR0) during a task switch. Note that the NT flag may be modified by software executing at any privilege level. It is possible for a program to set its NT flag and execute an IRET instruction, which would have the effect of invoking the task specified in the previous link field of the current task’s TSS. To keep spurious task switches from succeeding, the operating system should initialize the previous task link field for every TSS it creates to 0. Table 6-2. Effect of a Task Switch on Busy Flag, NT Flag, Previous Task Link Field, and TS Flag Effect of JMP instruction Flag is set. Must have been clear before. Flag is cleared. No change. No change. No change. No change. Flag is set. Effect of CALL Instruction or Interrupt Flag is set. Must have been clear before. No change. Flag is currently set. Flag is set. No change. Loaded with selector for old task’s TSS. No change. Flag is set. Effect of IRET Instruction No change. Must have been set. Flag is cleared. Restored to value from TSS of new task. Flag is cleared. No change. No change. Flag is set. Flag or Field Busy (B) flag of new task. Busy flag of old task. NT flag of new task. NT flag of old task. Previous task link field of new task. Previous task link field of old task. TS flag in control register CR0. 6-15 TASK MANAGEMENT 6.4.1. Use of Busy Flag To Prevent Recursive Task Switching A TSS allows only one context to be saved for a task; therefore, once a task is called (dispatched), a recursive (or re-entrant) call to the task would cause the current state of the task to be lost. The busy flag in the TSS segment descriptor is provided to prevent re-entrant task switching and subsequent loss of task state information. The processor manages the busy flag as follows: 1. When dispatching a task, the processor sets the busy flag of the new task. 2. If during a task switch, the current task is placed in a nested chain (the task switch is being generated by a CALL instruction, an interrupt, or an exception), the busy flag for the current task remains set. 3. When switching to the new task (initiated by a CALL instruction, interrupt, or exception), the processor generates a general-protection exception (#GP) if the busy flag of the new task is already set. (If the task switch is initiated with an IRET instruction, the exception is not raised because the processor expects the busy flag to be set.) 4. When a task is terminated by a jump to a new task (initiated with a JMP instruction in the task code) or by an IRET instruction in the task code, the processor clears the busy flag, returning the task to the “not busy” state. In this manner the processor prevents recursive task switching by preventing a task from switching to itself or to any task in a nested chain of tasks. The chain of nested suspended tasks may grow to any length, due to multiple calls, interrupts, or exceptions. The busy flag prevents a task from being invoked if it is in this chain. The busy flag may be used in multiprocessor configurations, because the processor follows a LOCK protocol (on the bus or in the cache) when it sets or clears the busy flag. This lock keeps two processors from invoking the same task at the same time. (Refer to Section 7.1.2.1., “Automatic Locking” in Chapter 7, Multiple-Processor Management for more information about setting the busy flag in a multiprocessor applications.) 6.4.2. Modifying Task Linkages In a uniprocessor system, in situations where it is necessary to remove a task from a chain of linked tasks, use the following procedure to remove the task: 1...
View Full Document

Ask a homework question - tutors are online