diff --git a/headers/multiboot.h b/headers/multiboot.h index b34c0fd..83e55ce 100644 --- a/headers/multiboot.h +++ b/headers/multiboot.h @@ -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 + +void init_multiboot(multiboot_info_t *mbd, uint32_t magic); diff --git a/headers/vbe.h b/headers/vbe.h new file mode 100644 index 0000000..41b7fd6 --- /dev/null +++ b/headers/vbe.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +struct vbe_interface { + uint32_t *buff; + uint16_t height; + uint16_t width; + uint8_t bpp; +}; + +extern struct vbe_interface display; diff --git a/src/drivers/vbe.c b/src/drivers/vbe.c new file mode 100644 index 0000000..67f416e --- /dev/null +++ b/src/drivers/vbe.c @@ -0,0 +1,10 @@ +#include "vbe.h" +#include "drivers.h" + +struct vbe_interface display; + +void put_pixel(uint16_t x, uint16_t y) +{ + + // +} diff --git a/src/kernel.c b/src/kernel.c index 5ee48d3..3d7871b 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -10,6 +10,7 @@ #include "shell.h" #include "string.h" #include "terminal.h" +#include "vbe.h" #include #include @@ -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(); } diff --git a/src/kpanic.c b/src/kpanic.c index 276f296..713e81c 100644 --- a/src/kpanic.c +++ b/src/kpanic.c @@ -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; diff --git a/src/memory/memory.c b/src/memory/memory.c index 87d739d..c209b42 100644 --- a/src/memory/memory.c +++ b/src/memory/memory.c @@ -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); diff --git a/src/multiboot.c b/src/multiboot.c new file mode 100644 index 0000000..51d654d --- /dev/null +++ b/src/multiboot.c @@ -0,0 +1,68 @@ +#include +#include + +#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); +}