MCPcopy Create free account
hub / github.com/YatSenOS/YatSenOS-Tutorial-Volume-1 / openPageMechanism

Method openPageMechanism

lab8/src/1/src/kernel/memory.cpp:130–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130void MemoryManager::openPageMechanism()
131{
132 // 页目录表指针
133 int *directory = (int *)PAGE_DIRECTORY;
134 //线性地址0~4MB对应的页表
135 int *page = (int *)(PAGE_DIRECTORY + PAGE_SIZE);
136
137 // 初始化页目录表
138 memset(directory, 0, PAGE_SIZE);
139 // 初始化线性地址0~4MB对应的页表
140 memset(page, 0, PAGE_SIZE);
141
142 int address = 0;
143 // 将线性地址0~1MB恒等映射到物理地址0~1MB
144 for (int i = 0; i < 256; ++i)
145 {
146 // U/S = 1, R/W = 1, P = 1
147 page[i] = address | 0x7;
148 address += PAGE_SIZE;
149 }
150
151 // 初始化页目录项
152
153 // 0~1MB
154 directory[0] = ((int)page) | 0x07;
155 // 3GB的内核空间
156 directory[768] = directory[0];
157 // 最后一个页目录项指向页目录表
158 directory[1023] = ((int)directory) | 0x7;
159
160 // 初始化cr3,cr0,开启分页机制
161 asm_init_page_reg(directory);
162
163 printf("open page mechanism\n");
164}
165
166int MemoryManager::allocatePages(enum AddressPoolType type, const int count)
167{

Callers 1

setup_kernelFunction · 0.45

Calls 2

printfFunction · 0.70
memsetFunction · 0.50

Tested by

no test coverage detected