文章目录
内存管理续
- Linux0.11版内核中页表初始化
- 虚拟内存
- 分段机制
1.Linux0.11版内核中启动时页表初始化过程
声明
Linux0.11版内核只能管理16M内存,一个页4KB,那么一个页表可管理4MB内存,所以只需要4个页表即可管理所有内存,然后加一个页目录(一级页表、外表)。
所以设置页表的时候需要设置:一个页目录+4个页表
首先看下有关数据的声明:
/*
* linux/boot/head.s
*
* (C) 1991 Linus Torvalds
*/
/*
* head.s contains the 32-bit startup code.
*
* NOTE!!! Startup happens at absolute address 0x00000000, which is also where
* the page directory will exist. The startup code will be overwritten by
* the page directory.
*/
.text
.globl idt,gdt,pg_dir,tmp_floppy_area
pg_dir:
.globl startup_32
这里有价值的信息是:pg_dir,即页目录,页目录所在地址是0x00000000。
然后是页表地址:
/*
* I put the kernel page tables right after the page directory,
* using 4 of them to span 16 Mb of physical memory. People with
* more than 16MB will have to expand this.
*/
.org 0x1000
pg0:
.org 0x2000
pg1:
.org 0x3000
pg2:
.org 0x4000
pg3:
.org 0x5000
一个页框是4K,页目录放在0x0000-0x0FFF, pg0放在0x1000-0x1FFF同理每个页表均占4KB大小(即0x1000B)。
上述程序声明了4个页表所在地址。
设置页表项
看程序之前先看下页表项结构:
低三位全为1,表示:用户页表、可读写、当前页表存在。
/*
* Setup_paging
*
* This routine s