Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86163
  • 博文数量: 15
  • 博客积分: 581
  • 博客等级: 中士
  • 技术积分: 185
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-23 15:29
文章分类
文章存档

2009年(10)

2008年(5)

我的朋友

分类: LINUX

2008-12-13 17:25:03

%三种地址:
  1. 逻辑地址(logical address)。大概就是汇编中的那种地址,包含段地址和位移两部分。
  2. 线性地址(linear address)。也叫做虚拟地址(virtual address)。也就是那4G地址空间。
  3. 物理地址(physical address)。
%三种地址的转换:
逻辑地址->分段单元(segmentation unit)->线性地址->分页单元(paging unit)->物理地址
%逻辑地址:
逻辑地址由两部分组成:一个段标识符和段内位移。段标识符长16位,又叫做段选择符(segment selector)段寄存器(共6个)存放段选择符。其中cs寄存器有两位用于specifies the Current Privilege Level (CPL) of the CPU.0表示级别最高,3表示最低。每个段有一个叫做段描述符(segment descriptor)的来描述这个段的特征。段描述符存放在内存中的Global Descriptor Table (GDT ) or in the Local Descriptor Table(LDT)。这两个表在内存中的位置分别保存在gdtr和ldtr两个寄存器中。
%快速访问段描述符:
每个段寄存器各有相对应的一个nonprogrammable register,用于存放相对应的8个字节的段描述符。
%三个PL(privilige level):
  1. RPL:是段选择符的一个字段。当该段选择符装入到cs中时,它决定了cs中的CPL;
  2. CPL:是cs中的两个位。指明CPU的当前特权级别;
  3. DPL:是段描述符中的一个字段。用于表示为访问这个段而要求的CPU的最小的privilige level。
%GDT的第一项总是0,这确保空的段选择符的逻辑地址是无效的。
%分段单元转换逻辑地址的过程:
  1. 查段选择符的TI以决定段描述符的存放位置(GDT或者LDT);
  2. 段选择符的index字段乘8;
  3. 与段描述符的base字段相加

%Linux中主要使用分页的方式,只有在80x386中才使用分段

%All Linux processes running in User Mode use the same pair of segments to address instructions and data;all Linux processes running in Kernel Mode use the same pair of segments to address instructions and data.

%Another important consequence of having all segments start at 0x00000000 is that in Linux, logical addresses coincide with linear addresses; that is, the value of the Offset field of a logical address always coincides with the value of the corresponding linear address.

?第2.3节,the linear addresses associated with such segments all start at 0 and reach the addressing limit of 232 -1是指计算位移的时候的起始地址?

%一个CPU对应一个GDT。所以,多CPU的系统中有多个GDT。这些所有的GDT都保存在cpu_gdt_table这个数组中,而所有的GDT地址和大小保存在cpu_gdt_descr数组(用于初始化gdtr)中。每个CPU都对应一个任务状态段(TSS)。所有的任务状态段都顺序存放在init_tss数组中。

%各个数据结构的关系:

内存



Cpu_gdt_table(数组)



Gdt(没有用变量保存,只是把一个区域叫做gdt)



段描述符(结构体)


%Most Linux User Mode applications do not make use of a Local Descriptor Table, thus the kernel defines a default LDT to be shared by most processes.缺省的LDT存放在default_ldt中。


%为了效率起见,线性地址被分成以固定长度为单位的组,称为页。所有的RAM被分成固定长度的page frame(有时候叫做物理页(physical page))。contiguous linear addresses within a page are mapped into contiguous physical addresses. In this way, the kernel can specify the physical address and the access rights of a page instead of those of all the linear addresses included in it.


%页和物理页的长度一致。页只是一个数据块,可以存放在任何物理页,甚至磁盘中。

%把线性地址映射到物理地址的数据结构称为页表。页表存放在主存中,由内核初始化。


%线性地址的转换基于页目录表和页表。32位的线性地址分为3个域:

  1. directory(目录),最高的10位;
  2. table(页表),中间的10位;
  3. offset(偏移量),最低12位
二级模式通过只为进程实际使用的那些虚拟内存区请求页表来减少内存容量。
 
%第2.3节,"segmentation can assign a different linear address space to each process, while paging can map the same linear address space into different physical address spaces." 这里的the same是指大家都是0~4G。
 
%第2.3节,"when they share the same set of linear addresses." 这里的share是指整个0~4G都可以使用,而不是说,一个进程用0~1M,另一个用3M~6M这样,然后所以进程用的加上没有的构成0~4G这样,是每个进程都可以使用全部0~4G的空间。
 
%第2.3节,"while paging can map the same linear address space into different physical address spaces." 如上一点所说,因为所有进程都使用0~4G,所以就会出现不同进程用了同样的线性地址。这句话的意思就是指同样的线性地址(属于不同进程)会被映射到不同的物理地址上。

?第2.5节, For 32-bit architectures with no Physical Address Extension, two paging levels are sufficient. Linux essentially eliminates the Page Upper Directory and the Page Middle Directory fields by saying that they contain zero bits(这是指线性地址,属于它们的位为0?). However, the positions of the Page Upper Directory and the Page Middle Directory in the sequence of pointers are kept so that the same code can work on 32-bit and 64-bit architectures. The kernel keeps a position for the Page Upper Directory and the Page Middle Directory by setting the number of entries in them to 1 and mapping these two entries into the proper entry of the Page Global Directory(这里的PGD的表项是不是直接指向页表,而不是PUD?).

%

 项目  初始化时间  保存变量
 PGD  内核编译时静态初始化  swapper_pg_dir
 PT  由head.S里的汇编函数startup_32()初始化  pg0

%第2.5.5.1节 “In order to map 8 MB of RAM, two Page Tables are required.”  8M/(1024*4096)=2.其中1024是一个页表的表项数;4096是每个页表的大小。


 

%第2.5.5.2节 “except for entries 0, 1, 0x300 (decimal 768), and 0x301 (decimal 769); the latter two entries span all linear addresses between 0xc0000000 and 0xc07fffff” 0xc0000000=0x300*1024*4096 1024是每个PGD指向的页表的表项数,4096是每页大小

?第2.5.5.2节 “movl $swapper_pg_dir-0xc0000000,%eax” 是因为“8 MB worth of linear addresses, starting from 0xc0000000”?























































阅读(658) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~