【译】x86程序员手册26-7.5任务切换
7.5 Task Switching 任务切换
The 80386 switches execution to another task in any of four cases:
80386在以下四种情况下会切换另一个任务去执行:
当前任务执行了一个引用了TSS描述符的JMP或CALL。
当前任务执行了一个引用任务门的JMP或CALL。
- An interrupt or exception vectors to a task gate in the IDT.
中断或异常向量指向一个IDT中的任务门。
- The current task executes an IRET when the NT flag is set.
当NT标志被置位时,当前任务执行了IRET指令。
JMP, CALL, IRET, interrupts, and exceptions are all ordinary mechanisms of the 80386 that can be used in circumstances that do not require a task switch. Either the type of descriptor referenced or the NT (nested task) bit in the flag word distinguishes between the standard mechanism and the variant that causes a task switch.
JMP、CALL、IRET、中断、异常都是80386的普通机制,用来在不能要求任务切换的情况下使用。引用的描述符类型或是标志字中的NT(嵌套任务)位区分标准机制和非标准机制引起任务切换。
To cause a task switch, a JMP or CALL instruction can refer either to a TSS descriptor or to a task gate. The effect is the same in either case: the 80386 switches to the indicated task.
为了引起任务切换,JMP或CALL指令可以引用TSS描述符或一个任务门。二者效果相同:80386切换到指明的任务。
An exception or interrupt causes a task switch when it vectors to a task gate in the IDT. If it vectors to an interrupt or trap gate in the IDT, a task switch does not occur . Refer to Chapter 9 for more information on the interrupt mechanism.
当中断或异常指向IDT中一个任务门时,引发任务切换。如果它指向一个IDT中的中断或陷阱门,任务切换不发生。参见第9章关于中断机制的更多描述。
Whether invoked as a task or as a procedure of the interrupted task, an interrupt handler always returns control to the interrupted procedure in the interrupted task. If the NT flag is set, however, the handler is an interrupt task, and the IRET switches back to the interrupted task.
无论是作为任务还是中断任务的程序,一个中断处理例程总会将控制交回到被中断任务里的被中断程序中。然而,如果NT标志置位,处理例程是一个中断任务,并且IRET切换回被中断的任务。
A task switching operation involves these steps:
任务切换操作按如下步骤进行:
- Checking that the current task is allowed to switch to the designated task. Data-access privilege rules apply in the case of JMP or CALL instructions. The DPL of the TSS descriptor or task gate must be numerically greater (e.g., lower privilege level) than or equal to the maximum of CPL and the RPL of the gate selector. Exceptions, interrupts, and IRET are permitted to switch tasks regardless of the DPL of the target task gate or TSS descriptor.
检查当前任务是否可以切换到指定的任务。在这种情况下,JMP或CALL指令要实施数据访问特权规则。TSS描述符或者任务门的DPL必须在数值上大于(低特权级别)或等于CPL和门选择子之间的最大者。允许异常、中断和IRET切换任务,而不管目标任务门或TSS描述符的DPL值如何。
- Checking that the TSS descriptor of the new task is marked present and has a valid limit. Any errors up to this point occur in the context of the outgoing task. Errors are restartable and can be handled in a way that is transparent to applications procedures.
检查新任务的TSS描述符是否标记为存在以及限长是否有效。任何错误都是发生在被换出任务的上下文环境中。错误是可重现的,可以被处理,并且对于应用程序是透明的。
- Saving the state of the current task. The processor finds the base address of the current TSS cached in the task register. It copies the registers into the current TSS (EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, ES, CS, SS, DS, FS, GS, and the flag register). The EIP field of the TSS points to the instruction after the one that caused the task switch.
保存当前任务的状态。处理器找到绑在在任务寄存器中的当前TSS基址。拷贝寄存器到当前TSS(EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, ES, CS, SS, DS, FS, GS, and 标志寄存器 EFLAGS)。TSS中的EIP字段指向引发任务切换的下一条指令。
- Loading the task register with the selector of the incoming task's TSS descriptor, marking the incoming task's TSS descriptor as busy, and setting the TS (task switched) bit of the MSW. The selector is either the operand of a control transfer instruction or is taken from a task gate.
将随后任务TSS描述符的选择子装入任务寄存器,标志该任务TSS描述符为忙,设置MSW(机器状态字)中的TS(任务切换)位。从任务门中取得的选择子即也是控制转移指令的操作数。
- Loading the incoming task's state from its TSS and resuming execution. The registers loaded are the LDT register; the flag register; the general registers EIP, EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI; the segment registers ES, CS, SS, DS, FS, and GS; and PDBR. Any errors detected in this step occur in the context of the incoming task. To an exception handler, it appears that the first instruction of the new task has not yet executed.
从TSS中装入随后的任务状态并恢复执行。被装载的寄存器为LDT寄存器;标志寄存器;通用寄存器EIP, EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI;段寄存器 ES, CS, SS, DS, FS, GS;以及PDBR寄存器。在这一步侦测到的任何错误都发生在随后的任务上下文中。对于一个异常处理例程,很显然新任务中的第一条指令并没有被执行。
Note that the state of the outgoing task is always saved when a task switch occurs. If execution of that task is resumed, it starts after the instruction that caused the task switch. The registers are restored to the values they held when the task stopped executing.
注意,当任务切换发生时,被换出的任务状态总是被保存的。如果这个任务被恢复,它从引发任务切换的指令后面开始。寄存器的值被恢复到任务停止执行时的值。
Every task switch sets the TS (task switched) bit in the MSW (machine status word). The TS flag is useful to systems software when a coprocessor (such as a numerics coprocessor) is present. The TS bit signals that the context of the coprocessor may not correspond to the current 80386 task. Chapter 11 discusses the TS bit and coprocessors in more detail .
每次任务切换都会设置MSW(机器状态字)中的TS(任务切换)位。当协处理器(例如数据协处理器)存在时,TS标志对于系统软件很有用。TS位发送信号,来表明协处理器上下文,不用和当前80386任务一致。第11章讨论TS位和协处理器的更多细节。
Exception handlers that field task-switch exceptions in the incoming task (exceptions due to tests 4 thru 16 of Table 7-1) should be cautious about taking any action that might load the selector that caused the exception. Such an action will probably cause another exception, unless the exception handler first examines the selector and fixes any potential problem.
在随后任务(表7-1的4到16的测试关于异常)中处理任务切换异常的例程应当关注任何会引发异常的装入选择子动作。这样的动作可能会引发另一个异常,除非异常处理例程首先检测选择子并修任何潜在的问题。
The privilege level at which execution resumes in the incoming task is neither restricted nor affected by the privilege level at which the outgoing task was executing. Because the tasks are isolated by their separate address spaces and TSSs and because privilege rules can be used to prevent improper access to a TSS, no privilege rules are needed to constrain the relation between the CPLs of the tasks. The new task begins executing at the privilege level indicated by the RPL of the CS selector value that is loaded from the TSS.
在被恢复执行的随后任务中的特权级别即不受被切出的任务的特权级别的约束,也不受影响。因为任务是通过独立的地址空间和TSS隔离的,同时特权规则可以用来阻止对TSS的不正确访问,没有特权规则用来限制任务的CPL之间的关联。从TSS中装入的CS选择子的RPL表明了新任务的特权级别。
Table 7-1. Checks Made during a Task Switch 任务切换时的检验
NP = Segment-not-present exception
GP = General protection fault
TS = Invalid TSS
SF = Stack fault
Validity tests of a selector check that the selector is in the proper
table (e.g., the LDT selector refers to the GDT), lies within the bounds of
the table, and refers to the proper type of descriptor (e.g., the LDT
selector refers to an LDT descriptor).
Test Test Description Exception Error Code Selects
1 Incoming TSS descriptor is
present NP Incoming TSS
2 Incoming TSS descriptor is
marked not-busy GP Incoming TSS
marked not-busy
3 Limit of incoming TSS is
greater than or equal to 103 TS Incoming TSS
-- All register and selector values are loaded --
4 LDT selector of incoming
task is valid TS Incoming TSS
5 LDT of incoming task is
present TS Incoming TSS
6 CS selector is valid TS Code segment
7 Code segment is present NP Code segment
8 Code segment DPL matches
CS RPL TS Code segment
9 Stack segment is valid GP Stack segment
10 Stack segment is present SF Stack segment
11 Stack segment DPL = CPL SF Stack segment
12 Stack-selector RPL = CPL GP Stack segment
13 DS, ES, FS, GS selectors are
valid GP Segment
14 DS, ES, FS, GS segments
are readable GP Segment
15 DS, ES, FS, GS segments
are present NP Segment
16 DS, ES, FS, GS segment DPL
>= CPL (unless these are
conforming segments) GP Segment
【译】x86程序员手册26-7.5任务切换的更多相关文章
- 【译】x86程序员手册01
Intel 80386 Reference Programmer's Manual 80386程序员参考手册 Chapter 1 -- Introduction to the 80386 第1章 - ...
- 【译】x86程序员手册03 - 2.1内存组织和分段
2.1 Memory Organization and Segmentation 内存组织和分段 The physical memory of an 80386 system is organized ...
- 【译】x86程序员手册00 - 翻译起因
从上一次学习MIT的操作系统课程又过去了一年.上次学习并没有坚持下去.想来虽有种种原因,其还在自身无法坚持罢了.故此次再鼓起勇气重新学习,发现课程都已由2014改版为2016了.但大部分内容并没有改变 ...
- 【译】x86程序员手册38-10.2实在址模式下的软件初始化
10.2 Software Initialization for Real-Address Mode 实地址模式的软件初始化 In real-address mode a few structur ...
- 【译】x86程序员手册09-第3章程序指令集
注:觉得本章内容与理解操作系统不直接相关,所以本章并未看完,也就没有翻译完,放在这里中是为了保证手册的完整.有兴趣的人可以去原址查看. https://pdos.csail.mit.edu/6.828 ...
- 【译】x86程序员手册05 - 2.3寄存器
2.3 Registers 寄存器 The 80386 contains a total of sixteen registers that are of interest to the applic ...
- 【译】x86程序员手册02 - 基本的程序模式
Chapter 2 -- Basic Programming Model: 基本的程序模式 Introduces the models of memory organization. Defines ...
- 【译】x86程序员手册40-10.5初始化的例子
10.5 Initialization Example初始化的例子 译注:本来想把这个例子全部注释完,但由于对intel汇编实不熟悉,有太多的伪指令,本人也是免强看懂,所以就不再做翻译了. $TITL ...
- 【译】x86程序员手册39-10.3切换到保护模式
10.3 Switching to Protected Mode 切换到保护模式 Setting the PE bit of the MSW in CR0 causes the 80386 to b ...
- 【译】x86程序员手册37-第10章 初始化
Chapter 10 Initialization 第10章 初始化 After a signal on the RESET pin, certain registers of the 80386 a ...
随机推荐
- JSTL简单入门学习实例
Maven依赖: <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</ ...
- react 项目实战(七)用户编辑与删除
添加操作列 编辑与删除功能都是针对已存在的某一个用户执行的操作,所以在用户列表中需要再加一个“操作”列来展现[编辑]与[删除]这两个按钮. 修改/src/pages/UserList.js文件,添加方 ...
- Unity 5.x 导入教学Demo
前言 小巫也来玩Unity3D了.以后会把学习的一些过程博客记录下来,方大家也方便自己学习和查看.本篇博客介绍怎样在Unityclient中导入Assert Store中下载的项目资源,方便我们进一步 ...
- FreeRTOS系列第14篇---FreeRTOS任务通知
注:本文介绍任务通知的基础知识,具体源代码分析见<FreeRTOS高级篇8---FreeRTOS任务通知分析> 每一个RTOS任务都有一个32位的通知值,任务创建时,这个值被初始化为0.R ...
- web container和spring container之间的关系
1 tomcat是一个web container,它提供java web应用的运行环境,因为它实现了好多java ee规范,比如java Servlet.JSP等,也就是说,没有它,java web应 ...
- Python读取大文件(GB)
Python读取大文件(GB) - CSDN博客 https://blog.csdn.net/shudaqi2010/article/details/54017766
- java多线程面试题(来自转载)
在典型的Java面试中, 面试官会从线程的基本概念问起, 如:为什么你需要使用线程, 如何创建线程,用什么方式创建线程比较好(比如:继承thread类还是调用Runnable接口),然后逐渐问到并发问 ...
- poj 2186(tarjan+缩点)
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 37083 Accepted: 15104 De ...
- HTTP请求错误码大全(转)
一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 详细分解: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 ...
- SQL常用指令集(Oracle)
1. Select rownum(oracle) top(mysql): 用于规定返回指定数目的值 Where roenum < number 2. Like 用于在where子句搜索指定模式 ...