| 1 |
|
| 2 |
|
| 3 |
#include <multiboot_tables.h> |
| 4 |
#include "coreinfo.h" |
| 5 |
|
| 6 |
#if CONFIG(MODULE_MULTIBOOT) |
| 7 |
|
| 8 |
#define MAX_MEMORY_COUNT 10 |
| 9 |
|
| 10 |
static struct { |
| 11 |
int mem_count; |
| 12 |
|
| 13 |
struct { |
| 14 |
u64 start; |
| 15 |
u64 size; |
| 16 |
int type; |
| 17 |
} range[MAX_MEMORY_COUNT]; |
| 18 |
} cb_info; |
| 19 |
|
| 20 |
static int tables_good = 0; |
| 21 |
|
| 22 |
static int multiboot_module_redraw(WINDOW *win) |
| 23 |
{ |
| 24 |
int row = 2; |
| 25 |
int i; |
| 26 |
|
| 27 |
print_module_title(win, "Multiboot Tables"); |
| 28 |
|
| 29 |
if (tables_good == 0) { |
| 30 |
mvwprintw(win, row++, 1, "No multiboot tables were found"); |
| 31 |
return 0; |
| 32 |
} |
| 33 |
|
| 34 |
row++; |
| 35 |
mvwprintw(win, row++, 1, "-- Memory Map --"); |
| 36 |
|
| 37 |
for (i = 0; i < cb_info.mem_count; i++) { |
| 38 |
|
| 39 |
if (cb_info.range[i].type == 1) |
| 40 |
mvwprintw(win, row++, 3, " RAM: "); |
| 41 |
else |
| 42 |
mvwprintw(win, row++, 3, "Reserved: "); |
| 43 |
|
| 44 |
wprintw(win, "%16.16llx - %16.16llx", |
| 45 |
cb_info.range[i].start, |
| 46 |
cb_info.range[i].start + cb_info.range[i].size - 1); |
| 47 |
} |
| 48 |
|
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
static void parse_memory(struct multiboot_header *table) |
| 53 |
{ |
| 54 |
u8 *start = (u8 *) phys_to_virt(table->mmap_addr); |
| 55 |
u8 *ptr = start; |
| 56 |
int i = 0; |
| 57 |
|
| 58 |
cb_info.mem_count = 0; |
| 59 |
|
| 60 |
while(ptr < (start + table->mmap_length)) { |
| 61 |
struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr; |
| 62 |
|
| 63 |
cb_info.range[i].start = mmap->addr; |
| 64 |
cb_info.range[i].size = mmap->length; |
| 65 |
cb_info.range[i].type = mmap->type; |
| 66 |
|
| 67 |
if (++cb_info.mem_count == MAX_MEMORY_COUNT) |
| 68 |
return; |
| 69 |
|
| 70 |
ptr += (mmap->size + sizeof(mmap->size)); |
| 71 |
i++; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
static void parse_header(unsigned long addr) |
| 76 |
{ |
| 77 |
struct multiboot_header *table = (struct multiboot_header *) addr; |
| 78 |
|
| 79 |
if (table->flags & MULTIBOOT_FLAGS_MMAP) |
| 80 |
parse_memory(table); |
| 81 |
} |
| 82 |
|
| 83 |
static int multiboot_module_init(void) |
| 84 |
{ |
| 85 |
unsigned long mbaddr; |
| 86 |
tables_good = sysinfo_have_multiboot(&mbaddr); |
| 87 |
|
| 88 |
parse_header(mbaddr); |
| 89 |
|
| 90 |
return tables_good ? 0 : -1; |
| 91 |
} |
| 92 |
|
| 93 |
struct coreinfo_module multiboot_module = { |
| 94 |
.name = "Multiboot", |
| 95 |
.init = multiboot_module_init, |
| 96 |
.redraw = multiboot_module_redraw, |
| 97 |
}; |
| 98 |
|
| 99 |
#else |
| 100 |
|
| 101 |
struct coreinfo_module multiboot_module = { |
| 102 |
}; |
| 103 |
|
| 104 |
#endif |