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

Method initialize

lab7/src/4/src/kernel/memory.cpp:14–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

printfFunction · 0.70
ceilFunction · 0.50

Tested by

no test coverage detected