1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-10-30 12:03:52 -04:00
kernel/arch/multiboot.c

138 lines
3.8 KiB
C
Raw Normal View History

2017-11-03 23:31:13 -04:00
#include "kprintf.h"
2017-11-01 08:57:56 -04:00
2017-11-02 00:21:25 -04:00
#define MULTIBOOT_TAG_TYPE_END 0
#define MULTIBOOT_TAG_TYPE_CMDLINE 1
#define MULTIBOOT_TAG_TYPE_MODULE 3
#define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO 4
#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 addr;
unsigned long long len;
unsigned int type;
unsigned int zero;
}
__attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
2017-11-01 11:54:52 -04:00
struct multiboot_tag
{
unsigned int type;
unsigned int size;
};
struct multiboot_tag_string
{
unsigned int type;
unsigned int size;
char string[0];
};
struct multiboot_tag_module
{
unsigned int type;
unsigned int size;
unsigned int mod_start;
unsigned int mod_end;
char cmdline[0];
};
2017-11-02 00:21:25 -04:00
struct multiboot_tag_basic_meminfo
{
unsigned int type;
unsigned int size;
unsigned int mem_lower;
unsigned int mem_upper;
};
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 void print_multiboot_tag(const struct multiboot_tag *tag);
static void print_multiboot_tag_cmdline (const struct multiboot_tag_string *tag);
static void print_multiboot_tag_module (const struct multiboot_tag_module *tag);
static void print_multiboot_tag_basic_meminfo(const struct multiboot_tag_basic_meminfo *tag);
static void print_multiboot_tag_mmap (const struct multiboot_tag_mmap *tag);
2017-11-04 06:51:03 -04:00
void print_multiboot_info(unsigned long addr)
2017-11-01 08:57:56 -04:00
{
for (
2017-11-04 06:51:03 -04:00
struct multiboot_tag *tag = (struct multiboot_tag*)(addr + 8);
2017-11-01 08:57:56 -04:00
tag->type != MULTIBOOT_TAG_TYPE_END;
2017-11-01 12:01:02 -04:00
tag = (struct multiboot_tag*)((unsigned char*)tag + ((tag->size + 7) & ~7))
) {
print_multiboot_tag(tag);
}
}
2017-11-01 09:54:53 -04:00
void print_multiboot_tag(const struct multiboot_tag *const tag)
{
switch (tag->type)
{
case MULTIBOOT_TAG_TYPE_CMDLINE:
print_multiboot_tag_cmdline((struct multiboot_tag_string*)tag);
break;
case MULTIBOOT_TAG_TYPE_MODULE:
print_multiboot_tag_module((struct multiboot_tag_module*)tag);
break;
case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
print_multiboot_tag_basic_meminfo((struct multiboot_tag_basic_meminfo*)tag);
break;
case MULTIBOOT_TAG_TYPE_MMAP:
print_multiboot_tag_mmap((struct multiboot_tag_mmap*)tag);
break;
2017-11-01 08:57:56 -04:00
}
}
void print_multiboot_tag_cmdline(const struct multiboot_tag_string *const tag)
{
2017-11-03 23:31:13 -04:00
kprintf("Kernel command line: %s\n", tag->string);
}
void print_multiboot_tag_module(const struct multiboot_tag_module *const tag)
{
2017-11-03 23:31:13 -04:00
kprintf("Module at 0x%x-0x%x, command line: %s\n", tag->mod_start, tag->mod_end, tag->cmdline);
}
void print_multiboot_tag_basic_meminfo(const struct multiboot_tag_basic_meminfo *const tag)
{
2017-11-03 23:31:13 -04:00
kprintf("mem_lower = %uKB, mem_upper = %uKB\n", tag->mem_lower, tag->mem_upper);
}
void print_multiboot_tag_mmap(const struct multiboot_tag_mmap *const tag)
{
2017-11-03 23:31:13 -04:00
kprintf("Memory map:\n");
for (
2017-11-02 04:53:14 -04:00
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)
) {
2017-11-03 23:31:13 -04:00
kprintf(
" base_addr = 0x%x%x, length = 0x%x%x, type = 0x%x\n",
2017-11-02 04:53:14 -04:00
(unsigned)(mmap->addr >> 32),
(unsigned)(mmap->addr & 0xffffffff),
(unsigned)(mmap->len >> 32),
(unsigned)(mmap->len & 0xffffffff),
(unsigned)mmap->type
);
}
}