feature: vbe is enabled, drivers for vbe tbd
This commit is contained in:
parent
30d22b3334
commit
2a281522cf
@ -20,6 +20,8 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
// https://imgflip.com/i/9cflls
|
||||
|
||||
#pragma once
|
||||
|
||||
/* How many bytes from the start of the file we search for the header. */
|
||||
@ -260,3 +262,7 @@ struct multiboot_apm_info {
|
||||
};
|
||||
|
||||
#endif /* ! ASM_FILE */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void init_multiboot(multiboot_info_t *mbd, uint32_t magic);
|
||||
|
12
headers/vbe.h
Normal file
12
headers/vbe.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct vbe_interface {
|
||||
uint32_t *buff;
|
||||
uint16_t height;
|
||||
uint16_t width;
|
||||
uint8_t bpp;
|
||||
};
|
||||
|
||||
extern struct vbe_interface display;
|
10
src/drivers/vbe.c
Normal file
10
src/drivers/vbe.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include "vbe.h"
|
||||
#include "drivers.h"
|
||||
|
||||
struct vbe_interface display;
|
||||
|
||||
void put_pixel(uint16_t x, uint16_t y)
|
||||
{
|
||||
|
||||
//
|
||||
}
|
14
src/kernel.c
14
src/kernel.c
@ -10,6 +10,7 @@
|
||||
#include "shell.h"
|
||||
#include "string.h"
|
||||
#include "terminal.h"
|
||||
#include "vbe.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
@ -28,14 +29,17 @@
|
||||
|
||||
void kernel_main(multiboot_info_t *mbd, uint32_t magic)
|
||||
{
|
||||
terminal_initialize();
|
||||
/* terminal_initialize(); */
|
||||
init_gdt();
|
||||
init_idt();
|
||||
init_memory(mbd, magic);
|
||||
load_drivers();
|
||||
kprintf(KERN_ALERT
|
||||
"I see no way to confuse an array of 256 seg:off pairs with a "
|
||||
"complex 8*unknown quantity -byte descriptor table. -- Troy "
|
||||
"Martin 03:50, 22 March 2009 (UTC)\n");
|
||||
/* kprintf(KERN_ALERT */
|
||||
/* "I see no way to confuse an array of 256 seg:off pairs with a
|
||||
* " */
|
||||
/* "complex 8*unknown quantity -byte descriptor table. -- Troy "
|
||||
*/
|
||||
/* "Martin 03:50, 22 March 2009 (UTC)\n"); */
|
||||
display.buff[1024] = 255;
|
||||
shell_init();
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
extern uint32_t page_table1[1024];
|
||||
|
||||
void kpanic(const char *format, ...)
|
||||
__attribute__((noreturn)) void kpanic(const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
#include "memory.h"
|
||||
#include "debug.h"
|
||||
#include "kprintf.h"
|
||||
#include "string.h"
|
||||
#include "utils.h"
|
||||
|
||||
@ -8,43 +6,10 @@
|
||||
|
||||
uint32_t *page_directory = &boot_page_directory;
|
||||
uint32_t page_table_default[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
uint32_t multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
uint32_t frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
|
||||
uint32_t mem_size;
|
||||
multiboot_memory_map_t *mmap_addr;
|
||||
multiboot_uint32_t mmap_length;
|
||||
struct frame_zone *head;
|
||||
|
||||
static 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;
|
||||
const size_t mbd_size = CEIL(
|
||||
(uint32_t)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE);
|
||||
|
||||
// Index multiboot_info_t struct
|
||||
for (uint32_t i = 0; i < mbd_size; 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);
|
||||
|
||||
// Index mbd->mmap_addr pointers
|
||||
for (uint32_t i = 0; i < mbd_virt->mmap_length; i++)
|
||||
multiboot_page_table[i + mbd_size] =
|
||||
((mbd_virt->mmap_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||
INIT_FLAGS;
|
||||
mmap_addr = (multiboot_memory_map_t *)(GET_PAGE_ADDR(1023, mbd_size) +
|
||||
(uint32_t)mbd_virt->mmap_addr %
|
||||
PAGE_SIZE);
|
||||
mmap_length = mbd_virt->mmap_length / sizeof(multiboot_memory_map_t);
|
||||
}
|
||||
|
||||
static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
|
||||
{
|
||||
if (!*root) {
|
||||
@ -124,7 +89,7 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
|
||||
uint32_t i = 1;
|
||||
for (; i < CEIL(nb_frame, PAGE_SIZE); i++)
|
||||
frame_zones_page_table[index + i] =
|
||||
((uint32_t)start_addr + i * PAGE_SIZE & PAGE_MASK) |
|
||||
((uint32_t)(start_addr + i * PAGE_SIZE) & PAGE_MASK) |
|
||||
INIT_FLAGS;
|
||||
current->addr = (void *)start_addr + i * PAGE_SIZE;
|
||||
index += i - 1;
|
||||
@ -143,7 +108,6 @@ static void init_frame_zones(void)
|
||||
|
||||
void init_memory(multiboot_info_t *mbd, uint32_t magic)
|
||||
{
|
||||
assert(page_directory);
|
||||
for (uint16_t i = 0; i < 0x300; i++)
|
||||
page_directory[i] = 0x02;
|
||||
init_page_table(page_table_default, 0);
|
||||
|
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user