feature: vbe is enabled, drivers for vbe tbd
This commit is contained in:
68
src/multiboot.c
Normal file
68
src/multiboot.c
Normal file
@ -0,0 +1,68 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "kpanic.h"
|
||||
#include "memory.h"
|
||||
#include "multiboot.h"
|
||||
#include "utils.h"
|
||||
#include "vbe.h"
|
||||
|
||||
uint32_t multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
multiboot_memory_map_t *mmap_addr;
|
||||
multiboot_uint32_t mmap_length;
|
||||
|
||||
static void init_mmap(multiboot_info_t *mbd_virt, size_t *pt_index)
|
||||
{
|
||||
// Index mbd->mmap_addr pointers
|
||||
uint32_t i = 0;
|
||||
for (; i < mbd_virt->mmap_length; i++)
|
||||
multiboot_page_table[i + *pt_index] =
|
||||
((mbd_virt->mmap_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||
INIT_FLAGS;
|
||||
mmap_addr = (multiboot_memory_map_t *)(GET_PAGE_ADDR(1023, *pt_index) +
|
||||
(uint32_t)mbd_virt->mmap_addr %
|
||||
PAGE_SIZE);
|
||||
mmap_length = mbd_virt->mmap_length / sizeof(multiboot_memory_map_t);
|
||||
*pt_index += i;
|
||||
}
|
||||
|
||||
static void init_vbe(multiboot_info_t *mbd_virt, size_t *pt_index)
|
||||
{
|
||||
const uint32_t framebuffer_size = mbd_virt->framebuffer_height *
|
||||
mbd_virt->framebuffer_width *
|
||||
CEIL(mbd_virt->framebuffer_bpp, 4);
|
||||
uint32_t i = 0;
|
||||
for (; i < CEIL(framebuffer_size, PAGE_SIZE); i++)
|
||||
multiboot_page_table[i + *pt_index] =
|
||||
((mbd_virt->framebuffer_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||
INIT_FLAGS;
|
||||
display.buff = (uint32_t *)GET_PAGE_ADDR(1023, *pt_index) +
|
||||
(mbd_virt->framebuffer_addr % PAGE_SIZE);
|
||||
display.height = mbd_virt->framebuffer_height;
|
||||
display.width = mbd_virt->framebuffer_width;
|
||||
display.bpp = mbd_virt->framebuffer_bpp;
|
||||
*pt_index += i;
|
||||
}
|
||||
|
||||
void init_multiboot(multiboot_info_t *mbd, uint32_t magic)
|
||||
{
|
||||
if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
|
||||
kpanic("invalid magic number! (git good skill issue)");
|
||||
|
||||
init_page_table(multiboot_page_table, 0);
|
||||
page_directory[1023] =
|
||||
((uint32_t)multiboot_page_table - HEAP_END) | 0x03;
|
||||
size_t pt_index = CEIL(
|
||||
(uint32_t)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE);
|
||||
|
||||
// Index multiboot_info_t struct
|
||||
for (uint32_t i = 0; i < pt_index; i++)
|
||||
multiboot_page_table[i] =
|
||||
(((uint32_t)mbd + PAGE_SIZE * i) & PAGE_MASK) | INIT_FLAGS;
|
||||
multiboot_info_t *mbd_virt =
|
||||
(multiboot_info_t *)(GET_PAGE_ADDR(1023, 0) +
|
||||
(uint32_t)mbd % PAGE_SIZE);
|
||||
init_mmap(mbd_virt, &pt_index);
|
||||
init_vbe(mbd, &pt_index);
|
||||
}
|
Reference in New Issue
Block a user