5.1 Segment Translation 段转换

Figure 5-2 shows in more detail how the processor converts a logical address into a linear address.

图5-2展示了处理器将一个逻辑地址转换为线性地址的细节。

To perform this translation, the processor uses the following data structures:

处理器使用以下数据结构实现转换:

  • Descriptors 描述符
  • Descriptor tables 描述符表
  • Selectors 选择子
  • Segment Registers 段寄存器

5.1.1 Descriptors 描述符

The segment descriptor provides the processor with the data it needs to map a logical address into a linear address. Descriptors are created by compilers, linkers, loaders, or the operating system, not by applications programmers. Figure 5-3 illustrates the two general descriptor formats. All types of segment descriptors take one of these formats. Segment-descriptor fields are:

段寄存器为处理器提供了逻辑地址转换为线性地址所需要的数据。描述符由编译器、连接器、装载器或操作系统提供,而不能由应用程序提供。图5-3解释了两种通用的描述符格式。所有的段描述符类型都使用其中一种。段描述符字段为:

BASE: Defines the location of the segment within the 4 gigabyte linear address space. The processor concatenates the three fragments of the base address to form a single 32-bit value.

基址(BASE):定义了一个段的4G线性地址空间的超始位置。处理器将三处的段基址组成一个32位值。

LIMIT: Defines the size of the segment. When the processor concatenates the two parts of the limit field, a 20-bit value results. The processor interprets the limit field in one of two ways, depending on the setting of the granularity bit:

段限长(LIMIT):定义段大小。处理器将两部分的组成一个20位的段限长值。处理器使用以下两种方式之一来解释段限长,这依赖于描述符的粒度位设置:

  1. In units of one byte, to define a limit of up to 1 megabyte.

一个单元为一个字节,定义限长为1M。

  1. In units of 4 Kilobytes, to define a limit of up to 4 gigabytes. The limit is shifted left by 12 bits when loaded, and low-order one-bits are inserted.

一个单元为4K字节,最长到4G。限长在载和时左移12位,从低字节处插入位。

Granularity bit: Specifies the units with which the LIMIT field is interpreted. When thebit is clear, the limit is interpreted in units of one byte; when set, the limit is interpreted in units of 4 Kilobytes.

粒度位:指定一个单元,段限长如何解释。当该位被清空时,限长被解释了每个单元一个字节;当置位时,限长被解释成一个单元4K字节。

TYPE: Distinguishes between various kinds of descriptors.

类型:用来区分多种描述符。

DPL (Descriptor Privilege Level): Used by the protection mechanism (refer to Chapter 6 ) .

特权级别描述(DPL):保护机制使用(参见第6章)

Segment-Present bit: If this bit is zero, the descriptor is not valid for use in address transformation; the processor will signal an exception when a selector for the descriptor is loaded into a segment register. Figure 5-4 shows the format of a descriptor when the present-bit is zero. The operating system is free to use the locations marked AVAILABLE. Operating systems that implement segment-based virtual memory clear the present bit in either of these cases:

段存在位:该位为0时,描述符对于地址转换不可用;当该描述符的选择子被装入段寄存器时处理器会生成一个异常。图5-4展示了当存在伴是0时描述符的格式。在以下两种情况时实现基于段的虚拟内存的操作系统会清空存在位:

  • When the linear space spanned by the segment is not mapped by the paging mechanism.

当一个跨段的线性地址空间未被分面机制映射时。

  • When the segment is not present in memory.

当一个段不在内存中时。

Accessed bit: The processor sets this bit when the segment is accessed; i.e., a selector for the descriptor is loaded into a segment register or used by a selector test instruction. Operating systems that implement virtual memory at the segment level may, by periodically testing and clearing this bit, monitor frequency of segment usage.

访问位:处理器当段被访问时处理器设置该位;比如:一个描述符的选择子被装入段寄存器或被选择子测试指令使用时。实现分段虚拟内存的操作系统可以通过临时测试和清空这些位来监视接下来的段使用。

Creation and maintenance of descriptors is the responsibility of systems software, usually requiring the cooperation of compilers, program loaders or system builders, and therating system.

创建和保持描述符是系统软件的责任,通常需要编译器、程序装载器或系统构建和协作。

5.1.2 Descriptor Tables

描述符表

Segment descriptors are stored in either of two kinds of descriptor table:

段描述符可以被存储在下面两种描述符表中:

  • The global descriptor table (GDT) 全局描述符表(GDT)
  • A local descriptor table (LDT) 本地描述符表(LDT)

A descriptor table is simply a memory array of 8-byte entries that contain descriptors, as Figure 5-5 shows. A descriptor table is variable in length and may contain up to 8192 (2^(13)) descriptors. The first entry of the GDT (INDEX=0) is not used by the processor, however.

正如图5-5所示,段描述符表是一个箱单的内存数组,每个项为8字节,包含一个描述符。描述符表长度可变,最多可以包含8192(2^32)个描述符。但是,处理器并不使用GDT的第一项描述符。

The processor locates the GDT and the current LDT in memory by means of the GDTR and LDTR registers. These registers store the base addresses of the tables in the linear address space and store the segment limits. The instructions LGDT and SGDT give access to the GDTR; the instructions LLDT and SLDT give access to the LDTR.

处理器通过GDTR和LDTR寄存器的值定位GDT和LDT在内存中的位置。这些寄存器保存描述符表在线性地址空间中的基址和段限长。指令LGDT和SGDt用来访问GDTR寄存器;指令LLDT和SLDT访问LDTR寄存器。

5.1.3 Selectors 选择子

The selector portion of a logical address identifies a descriptor by specifying a descriptor table and indexing a descriptor within that table. Selectors may be visible to applications programs as a field within a pointer variable, but the values of selectors are usually assigned (fixed up) by linkers or linking loaders.Figure 5-6 shows the format of a selector.

逻辑地址中的选择子部分通过指定一个描述符表和描述符在表中的索引来标识一个描述符。选择子对于应用程序可以作为指针变量的一部分,但是其值通常是连接器或装载器指定。图5-6展示了一个选择子的格式。

Index: Selects one of 8192 descriptors in a descriptor table. The processor simply multiplies this index value by 8 (the length of a descriptor), and adds the result to the base address of the descriptor table in order to access the appropriate segment descriptor in the table.

索引:8192个描述符表项中的一个。处理器简单地将这个索引值乘以8(一个描述符的长度),然后将其结果加到描述符的基址上,用来访问一个表中所描述的一个段。

Table Indicator: Specifies to which descriptor table the selector refers. A zero indicates the GDT; a one indicates the current LDT.

表声明(TI):指定选择子所引用的哪个描述符表。当该位为0时表明为GDT;当为1时表示为LDT。

Requested Privilege Level: Used by the protection mechanism. (Refer to Chapter 6)

需要的特权级别(RPL):保护机制使用。(参见第6章)

Because the first entry of the GDT is not used by the processor, a selector that has an index of zero and a table indicator of zero (i.e., a selector that points to the first entry of the GDT), can be used as a null selector. The processor does not cause an exception when a segment register (other than CS or SS) is loaded with a null selector. It will, however, cause an exception when the segment register is used to access memory. This feature is useful for initializing unused segment registers so as to trap accidental references.

因为处理器不使用GDT的第一项,所以一个索引项为0(一个指向GDT第一项的选择子)的选择子和描述符表为0,可以被当作一个空选择子。当一个空选择子被装入段寄存器时(CS或SS)时,处理器并不产生异常。然而,当处理器使用该段来访问内存时会导致一个异常。

5.1.4 Segment Registers 段寄存器

The 80386 stores information from descriptors in segment registers, thereby avoiding the need to consult a descriptor table every time it accesses memory.

80386将描述符信息存在段寄存器中,这样避免了每次访问内存都去访问描述符表。

Every segment register has a "visible" portion and an "invisible" portion, as Figure 5-7 illustrates. The visible portions of these segment address registers are manipulated by programs as if they were simply 16-bit registers. The invisible portions are manipulated by the processor.

每个段寄存器都有一个隐含的部分和一个可见的部分,正如图5-7所示。可见部分被程序当作一个简单的16位寄存来操控。不可见部分由处理器操控。

The operations that load these registers are normal program instructions (previously described in Chapter 3). These instructions are of two classes:

将其装入这些寄存器操作是普通的程序指令(见前面第3章所述)。这些指令分为两类:

  1. Direct load instructions; for example, MOVPOPLDSLSSLGSLFS. These instructions explicitly reference the segment registers.

直接装入指令;例如:MOV、POP、LDS、LSS、LGS、LFS。这些指令明确引用这些段寄存器。

  1. Implied load instructions; for example, far CALL and JMP. These instructions implicitly reference the CS register, and load it with a new value.

隐含地装入指令;例如:远程调用CALL和远程跳转JMP指令。这些指令隐含地引用CS寄存器,并将一个新值装入CS寄存器。

Using these instructions, a program loads the visible part of the segment register with a 16-bit selector. The processor automatically fetches the base address, limit, type, and other information from a descriptor table and loads them into the invisible part of the segment register.

使用这些指令,程序将一个16位选择子装入段寄存器的可见部分。处理器自动从描述表中取得基址、段限长、类型和其他信息,并将其装入段寄存器的不可见部分。

Because most instructions refer to data in segments whose selectors have already been loaded into segment registers, the processor can add the segment-relative offset supplied by the instruction to the segment base address with no additional overhead.

对于大部分指令而言,其引用的段内数据,其段的选择子已装入段寄存器,处理器无需要额外的指令就可以将段内偏移加到段基址上提供给指令使用。

【译】x86程序员手册14-5.1段转换的更多相关文章

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

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

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

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

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

    6.3 Segment-Level Protection 段级保护 All five aspects of protection apply to segment translation: 段转换时会 ...

  4. 【译】x86程序员手册17-第6章保护

    Chapter 6 Protection 第六章 保护 6.1 Why Protection? 为什么要保护? The purpose of the protection features of th ...

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

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

  6. 【译】x86程序员手册00 - 翻译起因

    从上一次学习MIT的操作系统课程又过去了一年.上次学习并没有坚持下去.想来虽有种种原因,其还在自身无法坚持罢了.故此次再鼓起勇气重新学习,发现课程都已由2014改版为2016了.但大部分内容并没有改变 ...

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

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

  8. 【译】x86程序员手册35-9.8异常条件

    译注:一些异常没有翻译,因为看书时主要为了理解linux代码,所以代码中没有主要使用的就没有仔细看.这部分内容后期再看时再进行翻译. 9.8 Exception Conditions 异常条件 The ...

  9. 【译】x86程序员手册34-9.7错误代码

    9.7 Error Code 错误代码 With exceptions that relate to a specific segment, the processor pushes an error ...

随机推荐

  1. Hackerrank manasa-and-combinatorics(数学推导)

    题意:有n个字符A,2n个字符B,问你能用这3n个字母组成多少种字符串,使得组成的字符串所有前缀与后缀的B的数目都大于等于A的数目,对答案mod 99991 分析:类似卡特兰数 ans=总方案数-存在 ...

  2. MyBatis3-传递多个参数(Multiple Parameters)

    传递多个参数一般用在查询上,比如多个条件组成的查询,有以下方式去实现: 版本信息: MyBatis:3.4.4 1.自带方法 <select id="getUserArticlesBy ...

  3. Linux内核project导论——前言

    想要研究linux内核.使用linux内核,首先要知道linux内核能做到什么,提供了什么.我看过非常多刚開始学习的人一进入公司就開始使用linux内核开发内核模块.使用的不管是通信方式.内存接口还是 ...

  4. oracle em 5500访问问题

    oracle em 5500访问问题 需要加s了:https://127.0.0.1:5500/em/

  5. Yocto tips (17): Yocto License问题:restricted license not whitelisted in LICENSE_FLAGS_WHITELIST

    Yocto中能够配置一个Distrbution的License.然后全部的软件包,都须要符合这个license才干够被shipped到image中,假设我们须要使用违反此license的软件包,那么就 ...

  6. Linux下C++访问MySQL数据库

    由于想要开始了解并学习用LAMP进行web开发,所以昨晚我在Fedora上安装了MySQL,学习了MySQL的几个常用命令.想着在学习进行web开发(PHP访问数据库)之前,先用我熟悉的C++连接数据 ...

  7. 2014年辛星starphp第一节设置入口文件以及App类

    *********************本节目标**************** 1.首先是我们的框架大致布局,我们即将写成的这个框架.它的入口文件统一为star.php.它须要做的一些事,比方载入 ...

  8. xcode 4.5 new feature __ ios6 新特性

    上两周看了wwdc 2012 developer session 400 - 412的视频,以下总结一下xcode4.5的新特性.(部分參考onevcat的文章,在此感谢.) @synthesize ...

  9. QSettings读写注冊表、配置文件

    简述 普通情况下.我们在开发软件过程中,都会缓存一些信息到本地,能够使用轻量级数据库sqlite.也能够操作注冊表.读写配置文件. 关于QSettings的使用前面已经介绍过了.比較具体,见" ...

  10. 第二课 MongoDB 数据模型

    1.课程大纲 本课程主要介绍MongoDB数据模型相关知识.包含文档.集合与数据库的基本概念.用法及命名规则:MongoDB主要的数据类型介绍以及MongoDB Shell的简单介绍与使用. 文档 ( ...