SimpleKernel  0.0.1
memory.cpp
Go to the documentation of this file.
1 
17 #include <stdexcept>
18 
19 #include "load_elf.h"
20 #include "ostream.hpp"
21 
23  memory_map = LibMemoryMap(&desc_count, &map_key, &desc_size, &desc_version);
24  if (memory_map == nullptr) {
25  debug << L"LibMemoryMap failed: memory_map == nullptr" << ostream::endl;
26  throw std::runtime_error("memory_map == nullptr");
27  }
28 }
29 
31 
33  flush_desc();
34  debug << L"Type\t\t\t\tPages\tPhysicalStart\tVirtualStart\tAttribute"
35  << ostream::endl;
36  for (uint64_t i = 0; i < desc_count; i++) {
37  auto *MMap = reinterpret_cast<EFI_MEMORY_DESCRIPTOR *>(
38  (reinterpret_cast<uint8_t *>(memory_map)) + i * desc_size);
39 
40  switch (MMap->Type) {
41  case EfiReservedMemoryType: {
42  debug << L"iReservedMemoryType\t\t";
43  break;
44  }
45  case EfiLoaderCode: {
46  debug << L"EfiLoaderCode\t\t\t";
47  break;
48  }
49  case EfiLoaderData: {
50  debug << L"EfiLoaderData\t\t\t";
51  break;
52  }
53  case EfiBootServicesCode: {
54  debug << L"EfiBootServicesCode\t\t";
55  break;
56  }
57  case EfiBootServicesData: {
58  debug << L"EfiBootServicesData\t\t";
59  break;
60  }
61  case EfiRuntimeServicesCode: {
62  debug << L"EfiRuntimeServicesCode\t\t";
63  break;
64  }
65  case EfiRuntimeServicesData: {
66  debug << L"EfiRuntimeServicesData\t\t";
67  break;
68  }
69  case EfiConventionalMemory: {
70  debug << L"EfiConventionalMemory\t\t";
71  break;
72  }
73  case EfiUnusableMemory: {
74  debug << L"EfiUnusableMemory\t\t";
75  break;
76  }
77  case EfiACPIReclaimMemory: {
78  debug << L"EfiACPIReclaimMemory\t\t";
79  break;
80  }
81  case EfiACPIMemoryNVS: {
82  debug << L"EfiACPIMemoryNVS\t\t";
83  break;
84  }
85  case EfiMemoryMappedIO: {
86  debug << L"EfiMemoryMappedIO\t\t";
87  break;
88  }
89  case EfiMemoryMappedIOPortSpace: {
90  debug << L"EfiMemoryMappedIOPortSpace\t\t";
91  break;
92  }
93  case EfiPalCode: {
94  debug << L"EfiPalCode\t\t";
95  break;
96  }
97  case EfiMaxMemoryType: {
98  debug << L"EfiMaxMemoryType\t\t";
99  break;
100  }
101  default: {
102  debug << L"Unknown " << ostream::hex_x << MMap->Type << L"\t\t";
103  break;
104  }
105  }
106 
107  debug << MMap->NumberOfPages << L"\t" << ostream::hex_X
108  << MMap->PhysicalStart << L"\t" << ostream::hex_X
109  << MMap->VirtualStart << L"\t" << ostream::hex_X << MMap->Attribute
110  << ostream::endl;
111  }
112  debug << L"map_key: " << ostream::hex_X << map_key << ostream::endl;
113 }
uint64_t desc_count
Definition: load_elf.h:115
void flush_desc()
Definition: memory.cpp:22
EFI_MEMORY_DESCRIPTOR * memory_map
Definition: load_elf.h:116
Memory()
Definition: memory.cpp:30
uint32_t desc_version
Definition: load_elf.h:119
void print_info()
Definition: memory.cpp:32
uint64_t desc_size
Definition: load_elf.h:118
uint64_t map_key
Definition: load_elf.h:117
static auto endl(ostream &_ostream) -> ostream &
Definition: ostream.cpp:42
static auto hex_x(ostream &_ostream) -> ostream &
Definition: ostream.cpp:32
static auto hex_X(ostream &_ostream) -> ostream &
Definition: ostream.cpp:37
load_elf h
ostream hpp
static ostream debug
全局输出流
Definition: ostream.hpp:194