| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include <libpayload-config.h> |
| 30 |
#include <libpayload.h> |
| 31 |
#include <multiboot_tables.h> |
| 32 |
|
| 33 |
unsigned long loader_eax; |
| 34 |
unsigned long loader_ebx; |
| 35 |
|
| 36 |
static int mb_add_memrange(struct sysinfo_t *info, unsigned long long base, |
| 37 |
unsigned long long size, unsigned int type) |
| 38 |
{ |
| 39 |
if (info->n_memranges >= SYSINFO_MAX_MEM_RANGES) |
| 40 |
return -1; |
| 41 |
|
| 42 |
#if CONFIG(LP_MEMMAP_RAM_ONLY) |
| 43 |
|
| 44 |
if (type != 1) |
| 45 |
return 0; |
| 46 |
#endif |
| 47 |
|
| 48 |
info->memrange[info->n_memranges].base = base; |
| 49 |
info->memrange[info->n_memranges].size = size; |
| 50 |
info->memrange[info->n_memranges].type = type; |
| 51 |
info->n_memranges++; |
| 52 |
|
| 53 |
return 0; |
| 54 |
} |
| 55 |
|
| 56 |
static void mb_parse_mmap(struct multiboot_header *table, |
| 57 |
struct sysinfo_t *info) |
| 58 |
{ |
| 59 |
u8 *start = (u8 *) phys_to_virt(table->mmap_addr); |
| 60 |
u8 *ptr = start; |
| 61 |
|
| 62 |
info->n_memranges = 0; |
| 63 |
|
| 64 |
while(ptr < (start + table->mmap_length)) { |
| 65 |
struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr; |
| 66 |
|
| 67 |
if (mb_add_memrange(info, mmap->addr, mmap->length, mmap->type)) |
| 68 |
return; |
| 69 |
|
| 70 |
ptr += (mmap->size + sizeof(mmap->size)); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
static void mb_parse_meminfo(struct multiboot_header *table, |
| 75 |
struct sysinfo_t *info) |
| 76 |
{ |
| 77 |
unsigned long long mem_low = table->mem_lower; |
| 78 |
unsigned long long mem_high = table->mem_higher; |
| 79 |
|
| 80 |
info->n_memranges = 0; |
| 81 |
|
| 82 |
if (mem_low) |
| 83 |
mb_add_memrange(info, 0 * MiB, mem_low * KiB, 1); |
| 84 |
|
| 85 |
if (mem_high) |
| 86 |
mb_add_memrange(info, 1 * MiB, mem_high * KiB, 1); |
| 87 |
} |
| 88 |
|
| 89 |
static void mb_parse_cmdline(struct multiboot_header *table) |
| 90 |
{ |
| 91 |
extern int main_argc; |
| 92 |
extern char *main_argv[]; |
| 93 |
char *c = phys_to_virt(table->cmdline); |
| 94 |
|
| 95 |
while(*c != '\0' && main_argc < MAX_ARGC_COUNT) { |
| 96 |
main_argv[main_argc++] = c; |
| 97 |
|
| 98 |
for( ; *c != '\0' && !isspace(*c); c++); |
| 99 |
|
| 100 |
if (*c) { |
| 101 |
*c = 0; |
| 102 |
c++; |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
int get_multiboot_info(struct sysinfo_t *info) |
| 108 |
{ |
| 109 |
struct multiboot_header *table; |
| 110 |
|
| 111 |
if (loader_eax != MULTIBOOT_MAGIC) |
| 112 |
return -1; |
| 113 |
|
| 114 |
table = (struct multiboot_header *) phys_to_virt(loader_ebx); |
| 115 |
|
| 116 |
info->mbtable = phys_to_virt(loader_ebx); |
| 117 |
|
| 118 |
if (table->flags & MULTIBOOT_FLAGS_MMAP) |
| 119 |
mb_parse_mmap(table, info); |
| 120 |
else if (table->flags & MULTIBOOT_FLAGS_MEMINFO) |
| 121 |
mb_parse_meminfo(table, info); |
| 122 |
|
| 123 |
if (table->flags & MULTIBOOT_FLAGS_CMDLINE) |
| 124 |
mb_parse_cmdline(table); |
| 125 |
|
| 126 |
return 0; |
| 127 |
} |