Graphics mode & linear framebuffer update #1

Merged
xamidev merged 13 commits from dev into main 2024-08-23 15:24:09 +02:00
4 changed files with 108 additions and 20 deletions
Showing only changes of commit ca001598fc - Show all commits

View File

@@ -1,4 +1,5 @@
menuentry "Blank OS" {
multiboot /boot/kernel.elf
set gfxpayload=1024x768x32
multiboot2 /boot/kernel.elf
boot
}

15
link.ld
View File

@@ -1,28 +1,27 @@
ENTRY(loader)
SECTIONS {
/* Address to load at; 1MB */
/* Address to load at; 2MB */
. = 0x00100000;
/*. = 2M;*/
.__mbHeader : {
*(.__mbHeader)
.multiboot_header ALIGN(4K) : {
*(.multiboot_header)
}
/* Align relevant sections at 4KB */
.text ALIGN (0x1000) :
.text ALIGN (4K) :
{
*(.text)
*(.rodata)
}
.data ALIGN (0x1000) :
.data ALIGN (4K) :
{
*(.data)
}
.bss ALIGN (0x1000) :
.bss ALIGN (4K) :
{
*(COMMON)
*(.bss)

View File

@@ -5,6 +5,25 @@
#include "system.h"
#include "paging.h"
#include "../drivers/ata.h"
#include "../libc/stdint.h"
typedef struct {
uint32_t type;
uint32_t size;
uint64_t framebuffer_addr;
uint32_t framebuffer_pitch;
uint32_t framebuffer_width;
uint32_t framebuffer_height;
uint8_t framebuffer_bpp;
uint8_t framebuffer_type;
uint16_t reserved;
} multiboot2_tag_framebuffer;
typedef struct {
uint32_t total_size;
uint32_t reserved;
uint8_t tags[0];
} multiboot2_info;
char* ascii_title =
"\n"
@@ -17,10 +36,52 @@ char* ascii_title =
unsigned int g_multiboot_info_address;
void kmain(unsigned int multiboot_info_address)
void kmain(multiboot2_info *mb_info)
{
g_multiboot_info_address = multiboot_info_address;
multiboot2_tag_framebuffer *fb_info = NULL;
uint8_t *tags = mb_info->tags;
while (1) {
uint32_t tag_type = *((uint32_t*) tags);
uint32_t tag_size = *((uint32_t*) (tags + 4));
if (tag_type == 0) break;
if (tag_type == 8) {
fb_info = (multiboot2_tag_framebuffer*) tags;
}
tags += ((tag_size + 7) & ~7);
}
serial_printf(3, "Framebuffer Address: 0x%x\r\n", fb_info->framebuffer_addr);
serial_printf(3, "Framebuffer Width: %u\r\n", fb_info->framebuffer_width);
serial_printf(3, "Framebuffer Height: %u\r\n", fb_info->framebuffer_height);
serial_printf(3, "Framebuffer Pitch: %u\r\n", fb_info->framebuffer_pitch);
serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp);
if (fb_info) {
log("Entered fb_info\r\n", 3);
uint32_t *framebuffer = (uint32_t *) fb_info->framebuffer_addr;
uint32_t width = fb_info->framebuffer_width;
uint32_t height = fb_info->framebuffer_height;
uint32_t pitch = fb_info->framebuffer_pitch;
uint32_t bpp = fb_info->framebuffer_bpp;
for (uint32_t y = 0; y < 100; y++) {
for (uint32_t x = 0; x < 100; x++) {
framebuffer[y * (pitch / 4) + x] = 0xFF0000; // Rouge
}
}
log("Drew to framebuffer.\r\n", 3);
}
puts("This should NOT work.");
while (1);
/*
init_serial();
log("serial connection established\n", 3);
gdt_install();
@@ -51,4 +112,5 @@ void kmain(unsigned int multiboot_info_address)
serial_printf(2, "%d\tinitialized keyboard handler", global_ticks);
shell_install();
serial_printf(2, "%d\tstarted system shell", global_ticks);
*/
}

View File

@@ -1,19 +1,45 @@
global loader
section .__mbHeader
section .multiboot_header
align 0x4
section .text:
align 8
MAGIC_NUMBER equ 0x1BADB002 ; multiboot magic
FLAGS equ 0x0
CHECKSUM equ -MAGIC_NUMBER
KERNEL_STACK_SIZE equ 4096
; ASM macros
dd MAGIC_NUMBER
dd FLAGS
MAGIC_NUMBER equ 0xe85250d6 ; multiboot2 magic
FLAGS equ 0x0 ; 32-bit protected mode for i386
HEADER_LEN equ 44 ; Tags=2+2+4+4+4+4+2+2+4=28
CHECKSUM equ -(MAGIC_NUMBER + FLAGS + HEADER_LEN)
; Multiboot 2 header, according to specification (16bytes)
dd MAGIC_NUMBER ; dd = 4 bytes = 32bits = u32
dd FLAGS
dd HEADER_LEN
dd CHECKSUM
; Tags? (28bytes)
; Tag 1 : set graphics mode (only recommended, can be overriden by GRUB)
dw 5 ; 2
dw 0 ; 2
dd 20 ; 4
dd 1920 ; 4
dd 1080 ; 4
dd 32 ; 4
; End of tags
dw 0 ; 2
;dw 0 ; 2
dd 8 ; 4
; End of Multiboot 2 header
section .text:
KERNEL_STACK_SIZE equ 4096
extern kmain
loader: