分类: LINUX
2008-12-13 17:25:03
%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个域:
?第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节 “movl $swapper_pg_dir-0xc0000000,%eax” 是因为“8 MB worth of linear addresses, starting from 0xc0000000”?