summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64/boot.c
diff options
context:
space:
mode:
authordzwdz2022-08-15 23:03:18 +0200
committerdzwdz2022-08-15 23:03:18 +0200
commit63fd7ce362c7f1d59365045f19cf1ca87ffe2db9 (patch)
treed991957f52e74afebe88a1ec88ec0d371728160b /src/kernel/arch/amd64/boot.c
parent3e80780859c4cbe5223ca4329bfd6176f5c2c879 (diff)
kernel: combine kmain_early and kmain
Diffstat (limited to 'src/kernel/arch/amd64/boot.c')
-rw-r--r--src/kernel/arch/amd64/boot.c70
1 files changed, 39 insertions, 31 deletions
diff --git a/src/kernel/arch/amd64/boot.c b/src/kernel/arch/amd64/boot.c
index a03c21d..e92b040 100644
--- a/src/kernel/arch/amd64/boot.c
+++ b/src/kernel/arch/amd64/boot.c
@@ -1,3 +1,4 @@
+#include <kernel/arch/amd64/3rdparty/multiboot2.h>
#include <kernel/arch/amd64/boot.h>
#include <kernel/arch/amd64/driver/fsroot.h>
#include <kernel/arch/amd64/driver/pata.h>
@@ -6,12 +7,11 @@
#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/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>
+#include <kernel/proc.h>
static void *mbi_tag(void *mbi, uint32_t type) {
struct multiboot_tag *tag;
@@ -27,8 +27,10 @@ static void *mbi_tag(void *mbi, uint32_t type) {
}
void kmain_early(void *mbi) {
- struct kmain_info info;
struct fb_info vid;
+ struct {
+ void *addr; size_t len;
+ } init;
tty_init();
kprintf("idt...");
@@ -36,44 +38,50 @@ void kmain_early(void *mbi) {
kprintf("irq...");
irq_init();
- 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;
+ {
+ kprintf("mem...\n");
+ struct multiboot_tag_basic_meminfo *meminfo;
+ meminfo = mbi_tag(mbi, MULTIBOOT_TAG_TYPE_BASIC_MEMINFO);
+ mem_init((void*)(long)(meminfo->mem_upper * 1024));
+ }
- 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;
+ {
+ 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;
+ mem_reserve(vid.b, vid.size);
+ kprintf("framebuffer at 0x%x, %ux%u bpp %u\n", vid.b, vid.width, vid.height, vid.bpp);
+ }
- kprintf("mem...\n");
- mem_init(&info);
+ {
+ struct multiboot_tag_module *mod;
+ mod = mbi_tag(mbi, MULTIBOOT_TAG_TYPE_MODULE);
+ init.addr = (void*)(long)mod->mod_start;
+ init.len = mod->mod_end - mod->mod_start;
+ mem_reserve(init.addr, init.len);
+ }
kprintf("rootfs...\n");
vfs_root_init();
ps2_init();
serial_init();
+ video_init(vid);
kprintf("ata...\n");
pata_init();
- 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);
+ kprintf("running init...\n");
+ process_seed(init.addr, init.len);
+ process_switch_any();
+}
- kmain(info);
+void shutdown(void) {
+ kprintf("shutting off\n");
+ mem_debugprint();
+ cpu_shutdown();
}