Chinaunix首页 | 论坛 | 博客
  • 博客访问: 56291
  • 博文数量: 47
  • 博客积分: 2095
  • 博客等级: 大尉
  • 技术积分: 560
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-01 18:42
文章分类

全部博文(47)

文章存档

2011年(1)

2008年(46)

我的朋友

分类: LINUX

2008-04-01 19:12:28

Segmentation in Hardware
Starting with the 80286 model, Intel microprocessors perform address translation in two different ways called real mode and protected mode . We'll focus in the next sections on address translation when protected mode is enabled. Real mode exists mostly to maintain processor compatibility with older models and to allow the operating system to bootstrap (see Appendix A for a short description of real mode).

从80286开始,Intel的微处理器采用两种不同的地址转换方式:实模式和保护模式。实模式仅用在保持处理器的兼容性和OS启动时。

Segment Selectors and Segmentation Registers
A logical address consists of two parts: a segment identifier and an offset that specifies the relative address within the segment. The segment identifier is a 16-bit field called the Segment Selector (see Figure 2-2), while the offset is a 32-bit field. We'll describe the fields of Segment Selectors in the section "Fast Access to Segment Descriptors" later in this chapter.
Figure 2-2. Segment Selector format

逻辑地址包含两部分:段标识符和指明段内的相对偏移。段标识符长为16bit,又被称为段选择子,偏移长为32bit。
 
To make it easy to retrieve segment selectors quickly, the processor provides segmentation registers whose only purpose is to hold Segment Selectors; these registers are called cs, ss, ds, es, fs, and gs. Although there are only six of them, a program can reuse the same segmentation register for different purposes by saving its content in memory and then restoring it later.

为了快速容易地获得段选择子,处理器提供了段寄存器存放段选择子:它们是CS、SS、DS、ES、FS和GS。尽管只有6个段寄存器,可以通过保存其中的内容在内存中,稍后再重置,使得不同的程序复用同一个的段寄存器。

Three of the six segmentation registers have specific purposes:
 
cs The code segment register, which points to a segment containing program instructions
CS 代码段寄存器,指向一个包含程序指令的段
 
ss The stack segment register, which points to a segment containing the current program stack
SS 堆栈段寄存器,指向一个包含当前程序堆栈的段
 
ds The data segment register, which points to a segment containing global and static data
DS 数据段寄存器,指向一个包含全局和静态数据的段

The remaining three segmentation registers are general purpose and may refer to arbitrary data segments.

The cs register has another important function: it includes a 2-bit field that specifies the Current Privilege Level (CPL) of the CPU. The value 0 denotes the highest privilege level, while the value 3 denotes the lowest one. Linux uses only levels 0 and 3, which are respectively called Kernel Mode and User Mode.

CS寄存器还有一个重要的作用:它包含了一个2bit的字段指明了CPUCPL(当前权限级别)值:0表示最高级,而3表示最低级。Linux仅使用了03,分别对应了内核模式和用户模式。
阅读(295) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~