...
This commit is contained in:
@@ -21,7 +21,7 @@ static void *multiboot_find_tag(uptr multiboot_info, u32 type) {
|
||||
return tag;
|
||||
}
|
||||
|
||||
next = align(next + tag->size, MULTIBOOT_TAG_ALIGN);
|
||||
next = align_up(next + tag->size, MULTIBOOT_TAG_ALIGN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ static void *multiboot_find_tag(uptr multiboot_info, u32 type) {
|
||||
typedef struct {
|
||||
u64 base_address;
|
||||
u64 length;
|
||||
} region;
|
||||
} memory_region;
|
||||
|
||||
extern uptr kernel_start;
|
||||
extern uptr kernel_end;
|
||||
|
||||
static region regions[MAX_REGIONS] = {0};
|
||||
static size_t region_count = 0;
|
||||
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_find_tag(multiboot_info, MULTIBOOT_TAG_TYPE_MMAP);
|
||||
@@ -51,17 +51,23 @@ static void find_memory_regions(uptr multiboot_info) {
|
||||
multiboot_mmap_entry *entry = (multiboot_mmap_entry*)entry_ptr;
|
||||
|
||||
if (entry->type == MULTIBOOT_MEMORY_AVAILABLE) {
|
||||
if (region_count >= MAX_REGIONS) {
|
||||
if (memory_region_count >= MAX_REGIONS) {
|
||||
boot_panic("Too many memory regions");
|
||||
}
|
||||
|
||||
regions[region_count++] = (region){ entry->base_address, entry->length };
|
||||
memory_regions[memory_region_count++] = (memory_region){ entry->base_address, entry->length };
|
||||
}
|
||||
|
||||
entry_ptr += tag->entry_size;
|
||||
}
|
||||
}
|
||||
|
||||
void kmain(uptr multiboot_info) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user