background image

7-12 Vol. 3A

TASK MANAGEMENT

The TS (task switched) flag in the control register CR0 is set every time a task switch occurs. System software uses 
the TS flag to coordinate the actions of floating-point unit when generating floating-point exceptions with the rest 
of the processor. The TS flag indicates that the context of the floating-point unit may be different from that of the 
current task. See Section 2.5, “Control Registers”, for a detailed description of the function and use of the TS flag.

7.4 TASK 

LINKING

The previous task link field of the TSS (sometimes called the “backlink”) and the NT flag in the EFLAGS register are 
used to return execution to the previous task. EFLAGS.NT = 1 indicates that the currently executing task is nested 
within the execution of another task. 
When a CALL instruction, an interrupt, or an exception causes a task switch: the processor copies the segment 
selector for the current TSS to the previous task link field of the TSS for the new task; it then sets EFLAGS.NT = 1. 
If software uses an IRET instruction to suspend the new task, the processor checks for EFLAGS.NT = 1; it then uses 
the value in the previous task link field to return to the previous task. See Figures 7-8.
When a JMP instruction causes a task switch, the new task is not nested. The previous task link field is not used and 
EFLAGS.NT = 0. Use a JMP instruction to dispatch a new task when nesting is not desired.

Table 7-2 shows 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.
The NT flag may be modified by software executing at any privilege level. It is possible for a program to set the NT 
flag and execute an IRET instruction. This might randomly invoke the task specified in the previous link field of the 
current task's TSS. To keep such spurious task switches from succeeding, the operating system should initialize the 
previous task link field in every TSS that it creates to 0.

DS, ES, FS, and GS segments are present in memory.

#NP

New Data Segment

DS, ES, FS, and GS segment DPL greater than or equal to CPL (unless these are 

conforming segments).

#TS

New Data Segment

NOTES:

1. #NP is segment-not-present exception, #GP is general-protection exception, #TS is invalid-TSS exception, and #SS is stack-fault 

exception.

2. The error code contains an index to the segment descriptor referenced in this column.
3. A segment selector is valid if it is in a compatible type of table (GDT or LDT), occupies an address within the table's segment limit, 

and refers to a compatible type of descriptor (for example, a segment selector in the CS register only is valid when it points to a 

code-segment descriptor).

Figure 7-8.  Nested Tasks

Table 7-1.  Exception Conditions Checked During a Task Switch  (Contd.)

Condition Checked

Exception

1

Error Code Reference

2

Top Level

Task

NT=0

Previous

TSS

Nested

Task

NT=1

TSS

More Deeply

Nested Task

NT=1

TSS

Currently Executing

Task

NT=1

EFLAGS

Task Register

Task Link

Previous

Task Link

Previous

Task Link