summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64/boot.c
diff options
context:
space:
mode:
authordzwdz2022-08-15 20:48:23 +0200
committerdzwdz2022-08-15 20:48:23 +0200
commit3e80780859c4cbe5223ca4329bfd6176f5c2c879 (patch)
tree92f42d2720d84434276c5382f1b43b8d73124827 /src/kernel/arch/amd64/boot.c
parentfa082df2da6b3be52c66ce0d48c209a3df38115d (diff)
kernel: port to multiboot2
Diffstat (limited to 'src/kernel/arch/amd64/boot.c')
-rw-r--r--src/kernel/arch/amd64/boot.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/src/kernel/arch/amd64/boot.c b/src/kernel/arch/amd64/boot.c
index 1041c7d..a03c21d 100644
--- a/src/kernel/arch/amd64/boot.c
+++ b/src/kernel/arch/amd64/boot.c
@@ -6,25 +6,27 @@
#include <kernel/arch/amd64/driver/video.h>
#include <kernel/arch/amd64/interrupts/idt.h>
#include <kernel/arch/amd64/interrupts/irq.h>
-#include <kernel/arch/amd64/multiboot.h>
+#include <kernel/arch/amd64/3rdparty/multiboot2.h>
#include <kernel/arch/amd64/tty/tty.h>
#include <kernel/arch/generic.h>
#include <kernel/main.h>
#include <kernel/mem/alloc.h>
#include <kernel/panic.h>
-static void find_init(struct multiboot_info *multiboot, struct kmain_info *info)
-{
- struct multiboot_mod *module = (void*)(long)multiboot->mods;
- if (multiboot->mods_count != 1) {
- kprintf("unexpected amount of multiboot modules\n");
- panic_invalid_state();
+static void *mbi_tag(void *mbi, uint32_t type) {
+ struct multiboot_tag *tag;
+ for (tag = mbi + 8;
+ tag->type != MULTIBOOT_TAG_TYPE_END;
+ tag = ((void*)tag) + ((tag->size + 7) & ~7))
+ {
+ if (tag->type == type)
+ return tag;
}
- info->init.at = (void*)(long)module->start;
- info->init.size = module->end - module->start;
+ kprintf("bootloader didn't pass required tag type %u\n", type);
+ panic_invalid_state();
}
-void kmain_early(struct multiboot_info *multiboot) {
+void kmain_early(void *mbi) {
struct kmain_info info;
struct fb_info vid;
@@ -34,10 +36,27 @@ void kmain_early(struct multiboot_info *multiboot) {
kprintf("irq...");
irq_init();
- info.memtop = (void*)(long)(multiboot->mem_upper * 1024);
- find_init(multiboot, &info);
- info.fb.at = (void*)multiboot->framebuffer_addr;
- info.fb.size = multiboot->framebuffer_pitch * multiboot->framebuffer_height;
+ struct multiboot_tag_basic_meminfo *meminfo;
+ meminfo = mbi_tag(mbi, MULTIBOOT_TAG_TYPE_BASIC_MEMINFO);
+ info.memtop = (void*)(long)(meminfo->mem_upper * 1024);
+
+ struct multiboot_tag_framebuffer *framebuf;
+ framebuf = mbi_tag(mbi, MULTIBOOT_TAG_TYPE_FRAMEBUFFER);
+ vid.b = (void*)framebuf->common.framebuffer_addr;
+ vid.pitch = framebuf->common.framebuffer_pitch;
+ vid.width = framebuf->common.framebuffer_width;
+ vid.height = framebuf->common.framebuffer_height;
+ vid.bpp = framebuf->common.framebuffer_bpp;
+ vid.size = vid.pitch * vid.height;
+ // TODO framebuffer doesn't need to be part of kmain_info
+ info.fb.at = vid.b;
+ info.fb.size = vid.size;
+
+ struct multiboot_tag_module *init;
+ init = mbi_tag(mbi, MULTIBOOT_TAG_TYPE_MODULE);
+ info.init.at = (void*)(long)init->mod_start;
+ info.init.size = init->mod_end - init->mod_start;
+
kprintf("mem...\n");
mem_init(&info);
@@ -49,21 +68,12 @@ void kmain_early(struct multiboot_info *multiboot) {
kprintf("ata...\n");
pata_init();
- vid.b = (void*)multiboot->framebuffer_addr;
- vid.pitch = multiboot->framebuffer_pitch;
- vid.width = multiboot->framebuffer_width;
- vid.height = multiboot->framebuffer_height;
- vid.bpp = multiboot->framebuffer_bpp;
- vid.size = vid.pitch * vid.height;
-
kprintf("kernel %8x -> %8x\n", 0, &_bss_end);
kprintf("init %8x -> %8x\n", info.init.at, info.init.at + info.init.size);
kprintf("video %8x -> %8x\n", vid.b, vid.b + vid.size);
kprintf("limit %8x\n", info.memtop);
-
kprintf("framebuffer at 0x%x, %ux%u bpp %u\n", vid.b, vid.width, vid.height, vid.bpp);
video_init(vid);
-
kmain(info);
}