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

Method initialize

lab7/src/3/src/kernel/memory.cpp:13–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13void MemoryManager::initialize()
14{
15 this->totalMemory = 0;
16 this->totalMemory = getTotalMemory();
17
18 // 预留的内存
19 int usedMemory = 256 * PAGE_SIZE + 0x100000;
20 if(this->totalMemory < usedMemory) {
21 printf("memory is too small, halt.\n");
22 asm_halt();
23 }
24 // 剩余的空闲的内存
25 int freeMemory = this->totalMemory - usedMemory;
26
27 int freePages = freeMemory / PAGE_SIZE;
28 int kernelPages = freePages / 2;
29 int userPages = freePages - kernelPages;
30
31 int kernelPhysicalStartAddress = usedMemory;
32 int userPhysicalStartAddress = usedMemory + kernelPages * PAGE_SIZE;
33
34 int kernelPhysicalBitMapStart = BITMAP_START_ADDRESS;
35 int userPhysicalBitMapStart = kernelPhysicalBitMapStart + ceil(kernelPages, 8);
36
37 kernelPhysical.initialize((char *)kernelPhysicalBitMapStart, kernelPages, kernelPhysicalStartAddress);
38 userPhysical.initialize((char *)userPhysicalBitMapStart, userPages, userPhysicalStartAddress);
39
40 printf("total memory: %d bytes ( %d MB )\n",
41 this->totalMemory,
42 this->totalMemory / 1024 / 1024);
43
44 printf("kernel pool\n"
45 " start address: 0x%x\n"
46 " total pages: %d ( %d MB )\n"
47 " bitmap start address: 0x%x\n",
48 kernelPhysicalStartAddress,
49 kernelPages, kernelPages * PAGE_SIZE / 1024 / 1024,
50 kernelPhysicalBitMapStart);
51
52 printf("user pool\n"
53 " start address: 0x%x\n"
54 " total pages: %d ( %d MB )\n"
55 " bit map start address: 0x%x\n",
56 userPhysicalStartAddress,
57 userPages, userPages * PAGE_SIZE / 1024 / 1024,
58 userPhysicalBitMapStart);
59}
60
61int MemoryManager::allocatePhysicalPages(enum AddressPoolType type, const int count)
62{

Callers

nothing calls this directly

Calls 2

printfFunction · 0.70
ceilFunction · 0.50

Tested by

no test coverage detected