mirror of https://github.com/tailix/kernel.git
Get memory map with <kernaux/multiboot2.h>
This commit is contained in:
parent
cf3e917bd9
commit
3cebdbb432
|
@ -58,6 +58,43 @@ void main(
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
const struct KernAux_Multiboot2_Tag_MemoryMap *const tag =
|
||||
(struct KernAux_Multiboot2_Tag_MemoryMap*)
|
||||
KernAux_Multiboot2_first_tag_with_type(
|
||||
multiboot2_info,
|
||||
KERNAUX_MULTIBOOT2_TAGTYPE_MEMORY_MAP
|
||||
);
|
||||
|
||||
if (!tag) {
|
||||
panic("No memory map provided in Multiboot 2 info.");
|
||||
}
|
||||
|
||||
for (
|
||||
const struct KernAux_Multiboot2_Tag_MemoryMap_EntryBase *entry =
|
||||
(struct KernAux_Multiboot2_Tag_MemoryMap_EntryBase*)tag->data;
|
||||
(unsigned char*)entry < (unsigned char*)tag + tag->base.size;
|
||||
entry =
|
||||
(struct KernAux_Multiboot2_Tag_MemoryMap_EntryBase*)
|
||||
((unsigned char*)entry + tag->entry_size)
|
||||
) {
|
||||
if (kinfo.areas_count >= KERNELMQ_INFO_AREAS_MAX) {
|
||||
panic("Too many memory map entries in Multiboot 2 info.");
|
||||
}
|
||||
|
||||
struct KernelMQ_Info_Area *const area =
|
||||
&kinfo.areas[kinfo.areas_count];
|
||||
|
||||
area->base = entry->base_addr;
|
||||
area->size = entry->length;
|
||||
area->limit = area->base + area->size - 1;
|
||||
|
||||
area->is_available = entry->type == 1;
|
||||
|
||||
++kinfo.areas_count;
|
||||
}
|
||||
}
|
||||
|
||||
if (!multiboot_parse(&kinfo, (unsigned long)multiboot2_info)) {
|
||||
panic("Can not parse Multiboot 2 info.");
|
||||
}
|
||||
|
|
|
@ -2,24 +2,8 @@
|
|||
|
||||
#include "stdlib.h"
|
||||
|
||||
#define MULTIBOOT_TAG_TYPE_END 0
|
||||
#define MULTIBOOT_TAG_TYPE_MODULE 3
|
||||
#define MULTIBOOT_TAG_TYPE_MMAP 6
|
||||
|
||||
#define MULTIBOOT_MEMORY_AVAILABLE 1
|
||||
#define MULTIBOOT_MEMORY_RESERVED 2
|
||||
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
|
||||
#define MULTIBOOT_MEMORY_NVS 4
|
||||
|
||||
struct multiboot_mmap_entry
|
||||
{
|
||||
unsigned long long base;
|
||||
unsigned long long size;
|
||||
unsigned int type;
|
||||
unsigned int zero;
|
||||
};
|
||||
|
||||
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
|
||||
#define MULTIBOOT_TAG_TYPE_END 0
|
||||
#define MULTIBOOT_TAG_TYPE_MODULE 3
|
||||
|
||||
struct multiboot_tag
|
||||
{
|
||||
|
@ -43,19 +27,9 @@ struct multiboot_tag_module
|
|||
char cmdline[0];
|
||||
};
|
||||
|
||||
struct multiboot_tag_mmap
|
||||
{
|
||||
unsigned int type;
|
||||
unsigned int size;
|
||||
unsigned int entry_size;
|
||||
unsigned int entry_version;
|
||||
struct multiboot_mmap_entry entries[0];
|
||||
};
|
||||
|
||||
static unsigned char print_multiboot_tag(struct KernelMQ_Info *kinfo, const struct multiboot_tag *tag);
|
||||
|
||||
static unsigned char print_multiboot_tag_module (struct KernelMQ_Info *kinfo, const struct multiboot_tag_module *tag);
|
||||
static unsigned char print_multiboot_tag_mmap (struct KernelMQ_Info *kinfo, const struct multiboot_tag_mmap *tag);
|
||||
static unsigned char print_multiboot_tag_module(struct KernelMQ_Info *kinfo, const struct multiboot_tag_module *tag);
|
||||
|
||||
unsigned char multiboot_parse(struct KernelMQ_Info *kinfo, unsigned long base)
|
||||
{
|
||||
|
@ -87,9 +61,6 @@ unsigned char print_multiboot_tag(struct KernelMQ_Info *kinfo, const struct mult
|
|||
{
|
||||
case MULTIBOOT_TAG_TYPE_MODULE:
|
||||
return print_multiboot_tag_module(kinfo, (struct multiboot_tag_module*)tag);
|
||||
|
||||
case MULTIBOOT_TAG_TYPE_MMAP:
|
||||
return print_multiboot_tag_mmap(kinfo, (struct multiboot_tag_mmap*)tag);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -121,28 +92,3 @@ unsigned char print_multiboot_tag_module(struct KernelMQ_Info *kinfo, const stru
|
|||
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned char print_multiboot_tag_mmap(struct KernelMQ_Info *kinfo, const struct multiboot_tag_mmap *const tag)
|
||||
{
|
||||
for (
|
||||
const multiboot_memory_map_t *mmap = tag->entries;
|
||||
(unsigned char*)mmap < (unsigned char*)tag + tag->size;
|
||||
mmap = (multiboot_memory_map_t*)((unsigned long) mmap + tag->entry_size)
|
||||
) {
|
||||
if (kinfo->areas_count >= KERNELMQ_INFO_AREAS_MAX) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct KernelMQ_Info_Area *area = &kinfo->areas[kinfo->areas_count];
|
||||
|
||||
area->base = mmap->base;
|
||||
area->size = mmap->size;
|
||||
area->limit = area->base + area->size - 1;
|
||||
|
||||
area->is_available = mmap->type == MULTIBOOT_MEMORY_AVAILABLE;
|
||||
|
||||
++kinfo->areas_count;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue