55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
#include "console.h"
|
|
#include "multiboot2.h"
|
|
|
|
#include <def.h>
|
|
#include "console.h"
|
|
#include "multiboot2.h"
|
|
#include "panic.h"
|
|
#include "util.h"
|
|
|
|
#define MAX_REGIONS 64
|
|
|
|
typedef struct {
|
|
u64 base_address;
|
|
u64 length;
|
|
} memory_region;
|
|
|
|
extern uptr kernel_start;
|
|
extern uptr kernel_end;
|
|
|
|
static memory_region memory_regions[MAX_REGIONS] = {0};
|
|
static size_t memory_region_count = 0;
|
|
|
|
static void find_memory_regions(uptr multiboot_info) {
|
|
multiboot_tag_mmap *tag = multiboot_get_mmap(multiboot_info);
|
|
if (tag == NULL) {
|
|
boot_panic("Multiboot did not provide mmap tag");
|
|
}
|
|
|
|
u32 entry_count = (tag->size - 16) / tag->entry_size;
|
|
u8 *entry_ptr = (u8*)tag->entries;
|
|
|
|
for (u32 i = 0; i < entry_count; ++i) {
|
|
multiboot_mmap_entry *entry = (multiboot_mmap_entry*)entry_ptr;
|
|
|
|
if (entry->type == MULTIBOOT_MEMORY_AVAILABLE) {
|
|
if (memory_region_count >= MAX_REGIONS) {
|
|
boot_panic("Too many memory regions");
|
|
}
|
|
|
|
memory_regions[memory_region_count++] = (memory_region){ entry->base_address, entry->length };
|
|
}
|
|
|
|
entry_ptr += tag->entry_size;
|
|
}
|
|
}
|
|
|
|
// We are now in long mode with kernel pages and vga buffer identity mapped
|
|
void x86_64_main(uptr multiboot_info) {
|
|
console_clear();
|
|
find_memory_regions(multiboot_info);
|
|
|
|
for (u32 i = 0; i < memory_region_count; ++i) {
|
|
kprintf("region: base_address=0x%X, length=0x%X\n", memory_regions[i].base_address, memory_regions[i].length);
|
|
}
|
|
} |