blob: fa6a9e069be58b6e4e575980e71e85e425817c68 [file] [log] [blame]
Martin Roth8cc1aeb2016-02-24 13:03:52 -08001/* multiboot.c
2 *
3 * Copyright (C) 2008,2009 Robert Millan
4 *
Martin Roth61ea5412016-03-07 20:58:18 -07005 * Loosely based on coreboot.c, which is:
Martin Roth8cc1aeb2016-02-24 13:03:52 -08006 *
7 * Released under version 2 of the Gnu Public License.
8 * By Eric Biederman
9 */
10
11#include "multiboot.h"
12#include "test.h"
13
14extern struct multiboot_info *mbiptr;
15
16int query_multiboot(void)
17{
18 struct multiboot_mmap_entry *mem;
19 int i;
20
21 if (!mbiptr) {
22 return 0;
23 }
24 if (!mbiptr->mmap_addr) {
25 return 1;
26 }
27 if ((mbiptr->flags & MULTIBOOT_INFO_MEM_MAP) == 0) {
28 return 1;
29 }
30
31 mem = (struct multiboot_mmap_entry *) mbiptr->mmap_addr;
32 mem_info.e820_nr = 0;
33
34 for (i = 0; i < E820MAX; i++) {
35 if ((multiboot_uint32_t) mem >= (mbiptr->mmap_addr + mbiptr->mmap_length)) {
36 break;
37 }
38
39 mem_info.e820[mem_info.e820_nr].addr = mem->addr;
40 mem_info.e820[mem_info.e820_nr].size = mem->len;
41 /* Multiboot spec defines available / reserved types to match with E820. */
42 mem_info.e820[mem_info.e820_nr].type = mem->type;
43 mem_info.e820_nr++;
44
45 mem = (struct multiboot_mmap_entry *) ((multiboot_uint32_t) mem + mem->size + sizeof (mem->size));
46 }
47
48 return 1;
49}