10.3 Switching to Protected Mode 

切换到保护模式

Setting the PE bit of the MSW in CR0 causes the 80386 to begin executing in protected mode. The current privilege level (CPL) starts at zero. The segment registers continue to point to the same linear addresses as in real address mode (in real address mode, linear addresses are the same physical addresses).

设置CR0中的MSW的PE位将导致80386开始在保护模式下执行。当前特权级别(CPL)开始时为0。段寄存器继续指向一个和实地址模式下相同的线性地址(在实地址模式中,线性地址与物理地址相同)。

Immediately after setting the PE flag, the initialization code must flush the processor's instruction prefetch queue by executing a JMP instruction. The 80386 fetches and decodes instructions and addresses before they are used; however, after a change into protected mode, the prefetched instruction information (which pertains to real-address mode) is no longer valid. A JMP forces the processor to discard the invalid information.

设置PE标志后,初始化代码必须通过执行一个JMP指令来刷新处理器的指令预取序列。80386取到并编码指令并在使用前进行寻址;然而,在进入保护模式后,预取的指令信息(与实地址模式有关)不再有效。JMP强制处理器抛弃无效的信息。

10.4 Software Initialization for Protected Mode 

保护模式的软件初始化

Most of the initialization needed for protected mode can be done either before or after switching to protected mode. If done in protected mode, however, the initialization procedures must not use protected-mode features that are not yet initialized.

大部分保护模式需要的初始化即可在切换到保护模式之前做,也可以在切换后做。如果在保护模式中做,初始化程序必须不使用保护模式的特性,因为他们还没有被初始化。

10.4.1 Interrupt Descriptor Table 中断描述符表

The IDTR may be loaded in either real-address or protected mode. However, the format of the interrupt table for protected mode is different than that for real-address mode. It is not possible to change to protected mode and change interrupt table formats at the same time; therefore, it is inevitable that, if IDTR selects an interrupt table, it will have the wrong format at some time. An interrupt or exception that occurs at this time will have unpredictable results. To avoid this unpredictability, interrupts should remain disabled until interrupt handlers are in place and a valid IDT has been created in protected mode.

IDTR即可在实地址模式装入也可以在保护模式中装入。然而,保护模式下中断表的格式与实地址模式下的不同。切换保护模式和修改中断表格式不能同时进行;因此,如果IDTR选择一个中断表,它在某个时段将有一个错误的格式,这是不可避免的。在这个时刻发生的中断或异常将引发不可预知的结果。为避免这种不可预知的问题,中断应当保持关闭状态,直到中断处理程序被放置,并且一个有效的IDT已经在保护模式下创建好。

10.4.2 Stack 栈

The SS register may be loaded in either real-address mode or protected mode. If loaded in real-address mode, SS continues to point to the same linear base-address after the switch to protected mode.

SS寄存器即可以在实模式下也可以在保护模式下装入。如果在实模式下装入,在切换到保护模式后,SS继续指向同一个线性基址。

10.4.3 Global Descriptor Table 全局描述符表

Before any segment register is changed in protected mode, the GDT register must point to a valid GDT. Initialization of the GDT and GDTR may be done in real-address mode. The GDT (as well as LDTs) should reside in RAM, because the processor modifies the accessed bit of descriptors.

保护模式中任何段寄存器在被修改前,GDT寄存器必须指向一个有效的GDT。GDT和GDTR要在实模式中初始化。GDT(此外LDT也一样)应当保存在RAM中,因为处理器会修改描述符中的访问位。

10.4.4 Page Tables 页表

Page tables and the PDBR in CR3 can be initialized in either real-address mode or in protected mode; however, the paging enabled (PG) bit of CR0 cannot be set until the processor is in protected mode. PG may be set simultaneously with PE, or later. When PG is set, the PDBR in CR3 should already be initialized with a physical address that points to a valid page directory. The initialization procedure should adopt one of the following strategies to ensure consistent addressing before and after paging is enabled:

页表和CR3中的PDBR可以实模式中或保护模式中初始化;然而,CR0的分页启用位(PG)直到处理器工作在保护模式中下才能设置。当设置PG时,CR3中的PDBR应当已经使用物理地址初始化过,并且指向一个有效的页目录。初始化程序应当采取下面的策略之一来确保分页启用之前与之后连续处理:

  • The page that is currently being executed should map to the same physical addresses both before and after PG is set.

设置PG之前与之后,当前执行的页应当映射到同一个物理地址。

  • JMP instruction should immediately follow the setting of PG.

设置PG后,应当马上个JMP指令。

10.4.5 First Task 第一个任务

The initialization procedure can run awhile in protected mode without initializing the task register; however, before the first task switch, the following conditions must prevail:

在没有初始化任务寄存情况下,初始化程序可以在保护模式中执行片刻;然而,切换到第一个任务之前,下列条件必须满足:

  • There must be a valid task state segment (TSS) for the new task. The stack pointers in the TSS for privilege levels numerically less than or equal to the initial CPL must point to valid stack segments.

新任务必须有一个有效的任务状态段(TSS)。TSS中的栈指针必须指向一个有效的栈段,该TSS的特权级别在数值上必须小于或等于初始CPL。

  • The task register must point to an area in which to save the current task state. After the first task switch, the information dumped in this area is not needed, and the area can be used for other purposes.

任务寄存器必须指向一个用来保存当前任务状态的区域。在切换到第一个任务后,取出这个区域的信息不是必须的,这个区域可以用做其他目的。

【译】x86程序员手册39-10.3切换到保护模式的更多相关文章

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

    7.5 Task Switching 任务切换 The 80386 switches execution to another task in any of four cases: 80386在以下四 ...

  2. 【译】x86程序员手册01

    Intel 80386 Reference Programmer's Manual 80386程序员参考手册 Chapter 1 -- Introduction to the 80386 第1章 - ...

  3. 【译】x86程序员手册10 - 第4章系统架构

    1.1.2 Part II -- Systems Programming 系统编程 This part presents those aspects of the architecture that ...

  4. 【译】x86程序员手册38-10.2实在址模式下的软件初始化

    10.2 Software Initialization for Real-Address Mode   实地址模式的软件初始化 In real-address mode a few structur ...

  5. 【译】x86程序员手册31- 第9章 异常和中断

    Chapter 9 Exceptions and Interrupts 第9章 异常和中断 Interrupts and exceptions are special kinds of control ...

  6. 【译】x86程序员手册11- 4.1系统寄存器

    4.1 Systems Registers 系统寄存器 The registers designed for use by systems programmers fall into these cl ...

  7. 【译】x86程序员手册09-第3章程序指令集

    注:觉得本章内容与理解操作系统不直接相关,所以本章并未看完,也就没有翻译完,放在这里中是为了保证手册的完整.有兴趣的人可以去原址查看. https://pdos.csail.mit.edu/6.828 ...

  8. 【译】x86程序员手册03 - 2.1内存组织和分段

    2.1 Memory Organization and Segmentation 内存组织和分段 The physical memory of an 80386 system is organized ...

  9. 【译】x86程序员手册02 - 基本的程序模式

    Chapter 2 -- Basic Programming Model: 基本的程序模式 Introduces the models of memory organization. Defines ...

随机推荐

  1. C#生成Excel文件后彻底解除占用代码(来着CSDN)

    http://bbs.csdn.net/topics/280078428 jy251 LS说KILL进程的朋友们···我说...你们真行!!!如果用户是administrator还行,如果不是怎么办? ...

  2. 用css解决Unigui在IE系列浏览器中字体变小的问题(设置UniServeModule的customcss属性)

    Unigui运行在chrome浏览器下可以有最佳的效果,但用ie打开用unigui做的项目会发现字体明显小一截,可以用自定义css来解决这个问题. 可以在UniServeModule的customcs ...

  3. docker启动centos容器后如何用putty连接

    在前面的文章中,我提到过,win10 docker启动容器时,只有配置了宿主机和docker容器的端口映射,外部应用才能访问到容器中的服务,比如映射到Nginx的80端口.现在我将宿主机的某个端口映射 ...

  4. html页面缓存问题

    若IIS没有设置,html页面一旦缓存,则永远缓存. Chrome如下 火狐如下 一种方法:我们一般通过xxx.html?20151010这样URL欺骗浏览器. 另一种方法:设置IIS,让永远客户端不 ...

  5. 一步一步学Silverlight 2系列(1):创建一个基本的Silverlight应用

    概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...

  6. hdu4975 A simple Gaussian elimination problem.(最大流+判环)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 题意:和hdu4888基本一样( http://www.cnblogs.com/a-clown/ ...

  7. bzoj 3028: 食物【生成函数】

    承德汉堡:\( 1+x^2+x^4+...=\frac{1}{1-x^2} \) 可乐:\(1+x \) 鸡腿:\( 1+x+x^2=\frac{x^3-1}{x-1} \) 蜜桃多:\( x+x^3 ...

  8. 关于自增id 你可能还不知道

    导读:在使用MySQL建表时,我们通常会创建一个自增字段(AUTO_INCREMENT),并以此字段作为主键.本篇文章将以问答的形式讲述关于自增id的一切. 注: 本文所讲的都是基于Innodb存储引 ...

  9. -------Pokemon Master------很水-------

    A - Pokemon Master Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Sta ...

  10. maven-将依赖的 jar包一起打包到项目 jar 包中

    前言: 有时候在项目开发中,需要很多依赖的 jar 包,其中依赖的 jar 包也会依赖其他的 jar 包,导致jar 包的管理很容易不全,以下有两种方法可以规避这个问题. 一.在pom.xml 文件中 ...