【译】x86程序员手册27-7.6任务链

7.6 Task Linking 任务链

The back-link field of the TSS and the NT (nested task) bit of the flag word together allow the 80386 to automatically return to a task that CALLed another task or was interrupted by another task. When a CALL instruction, an interrupt instruction, an external interrupt, or an exception causes a switch to a new task, the 80386 automatically fills the back-link of the new TSS with the selector of the outgoing task‘s TSS and, at the same time, sets the NT bit in the new task‘s flag register.

The NT flag indicates whether the back-link field is valid. The new task releases control by executing an IRET instruction. When interpreting an IRET, the 80386 examines the NT flag. If NT is set, the 80386 switches back to the task selected by the back-link field. Table 7-2 summarizes the uses of these fields.

TSS中的后向连接字段和标志字中的NT位一起允许80386自动返回到一个任务,返回的任务是调用任务的调用者(CALLed)或被另一个任务中断的任务。当一个CALL指令、中断指令、内部中断或者异常导致切换到一个新任务时,80386使用切换出去的任务的TSS的选择子来自动填充新TSS的后向连接字段,同时,在新任务的标志寄存器中设置NT位。

NT位表明一个后向连接字段是有效的。新任务通过IRET指令来释放控制权。当解释一条IRET指令时,80386检查NT位。如果NT位被置位,80386通过后向连接位选择切换回的任务。表7-2总结了这些字段的用法。

Table 7-2. Effect of Task Switch on BUSY, NT, and Back-Link

Affected Field      Effect of JMP      Effect of            Effect of

Instruction        CALL Instruction     IRET Instruction

Busy bit of         Set, must be       Set, must be 0       Unchanged,

incoming task       0 before           before               must be set

Busy bit of         Cleared            Unchanged            Cleared

outgoing task                          (already set)

NT bit of           Cleared            Set                  Unchanged

incoming task

NT bit of           Unchanged          Unchanged            Cleared

outgoing task

Back-link of        Unchanged          Set to outgoing      Unchanged

incoming task                          TSS selector

Back-link of        Unchanged          Unchanged            Unchanged

outgoing task

7.6.1 Busy Bit Prevents Loops 忙位阻止循环

The B-bit (busy bit) of the TSS descriptor ensures the integrity of the back-link. A chain of back-links may grow to any length as interrupt tasks interrupt other interrupt tasks or as called tasks call other tasks. The busy bit ensures that the CPU can detect any attempt to create a loop. A loop would indicate an attempt to reenter a task that is already busy; however, the TSS is not a reentrable resource.

TSS描述符的B位(忙位)确保后向连接的完整。当中断任务又中断其他中断任务或当调用任务再调用其他任务时,后向连接链可能增长得很大。忙位确保CPU可以检测任何创建一个循环的企图。循环表明企图重入一个已经在忙的任务;然而,TSS是不可重入资源。

The processor uses the busy bit as follows:

处理器在以下场景使用忙位:

  1. When switching to a task, the processor automatically sets the busy bit of the new task.

当切换到一个任务时,处理器自动设置新任务的忙位。

  1. When switching from a task, the processor automatically clears the busy bit of the old task if that task is not to be placed on the back-link chain (i.e., the instruction causing the task switch is JMP or IRET). If the task is placed on the back-link chain, its busy bit remains set.

当从一个任务切换时,处理器自动清除一个旧任务的忙位,如果那个任务没有被放入到后向连接链中(JMP或IRET指令引起的任务切换)。如果任务被放在后向连接链中,它的忙位将保持设置状态。

  1. When switching to a task, the processor signals an exception if the busy bit of the new task is already set.

当切换到一个任务时,如果新任务的忙位已经被置位,处理器会发送一个异常信号。

By these actions, the processor prevents a task from switching to itself or to any task that is on a back-link chain, thereby preventing invalid reentry into a task.

通过这些动作,处理器阻止一个任务切换到自身或者任何已经在后向连接链中的任务,因此可阻止对任务的无效重入。

The busy bit is effective even in multiprocessor configurations, because the processor automatically asserts a bus lock when it sets or clears the busy bit. This action ensures that two processors do not invoke the same task at the same time . (Refer to Chapter 11 for more on multiprocessing.)

即使在多处理器环境中忙位也是有效的,因为处理器在设置或清除一个忙位时会自动验证一个忙位锁。这个动作确保两个处理器在同一时间不会激活同一个任务。(参见第11章关于多处理器内容。)

7.6.2 Modifying Task Linkages 修改任务连

Any modification of the linkage order of tasks should be accomplished only by software that can be trusted to correctly update the back-link and the busy-bit. Such changes may be needed to resume an interrupted task before the task that interrupted it. Trusted software that removes a task from the back-link chain must follow one of the following policies:

任何对任务顺序连进行的修改都应当谨慎,只有那些被信任可以正确更新后向连接和忙位的软件才能实施。这样的修改对于在中断它的任务之前重启一个被中断的任务可能是需要。可信任的软件从后向连接移除一个任务时必须遵循以下策略:

  1. First change the back-link field in the TSS of the interrupting task, then clear the busy-bit in the TSS descriptor of the task removed from the list.

首先,修改正处于中断的任务的TSS的后向连接字段,然后清除从链表中被移除的任务的TSS描述符中的忙位。

  1. Ensure that no interrupts occur between updating the back-link chain and the busy bit.

确保在更新后向连接链和忙位时没有中断发生。

时间: 2024-11-03 22:40:52

【译】x86程序员手册27-7.6任务链的相关文章

【译】x86程序员手册25-7.1任务状态段

7.1 Task State Segment 任务状态段 All the information the processor needs in order to manage a task is stored in a special type of segment, a task state segment (TSS). Figure 7-1 shows the format of a TSS for executing 80386 tasks. (Another format is used

【译】x86程序员手册26-7.5任务切换

7.5 Task Switching 任务切换 The 80386 switches execution to another task in any of four cases: 80386在以下四种情况下会切换另一个任务去执行: The current task executes a JMP or CALL that refers to a TSS descriptor. 当前任务执行了一个引用了TSS描述符的JMP或CALL. The current task executes a JMP

【译】x86程序员手册29-第8章 输入输出

Chapter 8 Input/Output 输入/输出 This chapter presents the I/O features of the 80386 from the following perspectives: 本章从以下方面来介绍80386的I/O特性: Methods of addressing I/O ports I/O端口的寻址方式 Instructions that cause I/O operations 引起IO操作的指令 Protection as it appl

【译】x86程序员手册30-8.2 I/O指令

8.2 I/O Instructions I/O指令 The I/O instructions of the 80386 provide access to the processor's I/O ports for the transfer of data to and from peripheral devices. These instructions have as one operand the address of a port in the I/O address space. T

【译】x86程序员手册18-6.3.1描述符保存保护参数

6.3 Segment-Level Protection 段级保护 All five aspects of protection apply to segment translation: 段转换时会提供以下5个方面的保护: Type checking 类型检验 Limit checking 限长检验 Restriction of addressable domain 可寻址域的限定 Restriction of procedure entry points 程序入口点的限定 Restricti

【译】x86程序员手册19-6.3.2数据访问的约束

6.3.2 Restricting Access to Data  数据访问的约束 To address operands in memory, an 80386 program must load the selector of a data segment into a data-segment register (DS, ES, FS, GS, SS). The processor automatically evaluates access to a data segment by co

【译】x86程序员手册12-4.2系统指令

4.2 Systems Instructions 系统指令 Systems instructions deal with such functions as: 系统指令具有以下功能: Verification of pointer parameters (refer to Chapter 6): 验证指印参数(参见第6章) ARPL> -- Adjust RPL RPL= request provilege level LAR -- Load Access Rights LSL -- Load

【译】x86程序员手册13-第5章 内存管理

Chapter 5 Memory Management 内存管理 The 80386 transforms logical addresses (i.e., addresses as viewed by programmers) into physical address (i.e., actual addresses in physical memory) in two steps: 80386通过两步将一个逻辑地址(程序所引用的地址)转移为物理地址(实际的物理内存地址). Segment t

【译】x86程序员手册15-5.2页转换

5.2 Page Translation 页转换 In the second phase of address transformation, the 80386 transforms a linear address into a physical address. This phase of address transformation implements the basic features needed for page-oriented virtual-memory systems

【译】x86程序员手册16-5.3联合使用段与分页转换

5.3 Combining Segment and Page Translation  联合使用段与分页转换 Figure 5-12 combines Figure 5-2 and Figure 5-9 to summarize both phases of the transformation from a logical address to a physical address when paging is enabled. By appropriate choice of options