Skip to content

Commit

Permalink
Merge pull request #226 from panix-os/225-Basic-Framebuffer-Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kfeavel authored Jun 16, 2021
2 parents 6cb8282 + 5ba9ae3 commit 15c507e
Show file tree
Hide file tree
Showing 11 changed files with 417 additions and 164 deletions.
1 change: 1 addition & 0 deletions boot/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ set default=0

menuentry "Panix" {
multiboot2 /boot/kernel
set vbemode=auto
boot
}
12 changes: 0 additions & 12 deletions kernel/arch/i386/boot/multiboot.S

This file was deleted.

11 changes: 11 additions & 0 deletions kernel/arch/i386/boot/multiboot2.S
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ MULTIBOOT_ARCH equ 0
MULTIBOOT_LENGTH equ (__multiboot_header_end - __multiboot2_header_start)
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_MAGIC + MULTIBOOT_ARCH + MULTIBOOT_LENGTH)

MULTIBOOT_TAG_OPTIONAL equ 1
MULTIBOOT_TAG_ENTRY equ 3
MULTIBOOT_TAG_FRAMEBUFFER equ 5
MULTIBOOT_TAG_LAST equ 0

extern _start:code
Expand Down Expand Up @@ -34,6 +36,15 @@ __multiboot2_entry_tag:
dd MULTIBOOT_ENTRY
tag_end

__multiboot2_framebuffer_tag:
tag_begin MULTIBOOT_TAG_FRAMEBUFFER
dw MULTIBOOT_TAG_OPTIONAL
dd 20
dd 0
dd 0
dd 32
tag_end

__multiboot2_last_tag:
tag_begin MULTIBOOT_TAG_LAST
tag_end
Expand Down
10 changes: 4 additions & 6 deletions kernel/arch/i386/boot/stivale2.S
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ __stivale2_header:
dd 0 ; stack, high bits
dq 0 ; flags
; tags
dd 0 ; __stivale2_framebuffer
dd __stivale2_framebuffer
dd 0

%if 0
section .early_data
align 4
__stivale2_framebuffer:
dq 0x3ecc1bc43d0f7971
dq 0
dw 1280
dw 720
dw 32
%endif
dw 0 ; Width (0 = Best)
dw 0 ; Height (0 = Best)
dw 0 ; Color depth (0 = Best)
115 changes: 42 additions & 73 deletions kernel/boot/Handoff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,70 +23,6 @@

namespace Boot {

/*
* ___ _ __ __
* | __| _ __ _ _ __ ___| |__ _ _ / _|/ _|___ _ _
* | _| '_/ _` | ' \/ -_) '_ \ || | _| _/ -_) '_|
* |_||_| \__,_|_|_|_\___|_.__/\_,_|_| |_| \___|_|
*
*/

FramebufferInfo::FramebufferInfo()
: _addr(NULL)
, _width(0)
, _height(0)
, _depth(0)
, _pitch(0)
, _redMaskSize(0)
, _redMaskShift(0)
, _greenMaskSize(0)
, _greenMaskShift(0)
, _blueMaskSize(0)
, _blueMaskShift(0)
, _memoryModel(Undefined_FBMM)
{
// Default constructor.
}

FramebufferInfo::FramebufferInfo(uint32_t width, uint32_t height, uint16_t depth, uint32_t pitch, void* addr)
: _addr(addr)
, _width(width)
, _height(height)
, _depth(depth)
, _pitch(pitch)
, _redMaskSize(0)
, _redMaskShift(0)
, _greenMaskSize(0)
, _greenMaskShift(0)
, _blueMaskSize(0)
, _blueMaskShift(0)
, _memoryModel(Undefined_FBMM)
{
// Common parameters constructor
}

FramebufferInfo::FramebufferInfo(uint32_t width, uint32_t height,
uint16_t depth, uint32_t pitch,
void* addr, FramebufferMemoryModel model,
uint8_t redMaskSize, uint8_t redMaskShift,
uint8_t greenMaskSize, uint8_t greenMaskShift,
uint8_t blueMaskSize, uint8_t blueMaskShift)
: _addr(addr)
, _width(width)
, _height(height)
, _depth(depth)
, _pitch(pitch)
, _redMaskSize(redMaskSize)
, _redMaskShift(redMaskShift)
, _greenMaskSize(greenMaskSize)
, _greenMaskShift(greenMaskShift)
, _blueMaskSize(blueMaskSize)
, _blueMaskShift(blueMaskShift)
, _memoryModel(model)
{
// All parameters constructor
}

/*
* _ _ _ __ __
* | || |__ _ _ _ __| |___ / _|/ _|
Expand All @@ -95,6 +31,13 @@ FramebufferInfo::FramebufferInfo(uint32_t width, uint32_t height,
*
*/

Handoff::Handoff()
: _handle(NULL)
, _magic(0)
{
// Initialize nothing.
}

Handoff::Handoff(void* handoff, uint32_t magic)
: _handle(handoff)
, _magic(magic)
Expand Down Expand Up @@ -145,7 +88,7 @@ void Handoff::parseStivale2(Handoff* that, void* handoff)
{
auto cmdline = (struct stivale2_struct_tag_cmdline*)tag;
rs232_printf("Stivale2 cmdline: '%s'\n", (const char *)cmdline->cmdline);
that->_cmdline = (const char *)(cmdline->cmdline);
that->_cmdline = (char *)(cmdline->cmdline);
break;
}
case STIVALE2_STRUCT_TAG_FRAMEBUFFER_ID:
Expand All @@ -156,15 +99,28 @@ void Handoff::parseStivale2(Handoff* that, void* handoff)
rs232_printf("\tResolution: %ix%ix%i\n",
framebuffer->framebuffer_width,
framebuffer->framebuffer_height,
(framebuffer->framebuffer_bpp * 8));
framebuffer->framebuffer_bpp);
rs232_printf("\tPixel format:\n"
"\t\tRed size: %u\n"
"\t\tRed shift: %u\n"
"\t\tGreen size: %u\n"
"\t\tGreen shift: %u\n"
"\t\tBlue size: %u\n"
"\t\tBlue shift: %u\n",
framebuffer->red_mask_size,
framebuffer->red_mask_shift,
framebuffer->green_mask_size,
framebuffer->green_mask_shift,
framebuffer->blue_mask_size,
framebuffer->blue_mask_shift);
// Initialize the framebuffer information
that->_fbInfo = FramebufferInfo(
that->_fbInfo = fb::FramebufferInfo(
framebuffer->framebuffer_width,
framebuffer->framebuffer_height,
framebuffer->framebuffer_bpp,
framebuffer->framebuffer_pitch,
(void*)framebuffer->framebuffer_addr,
(FramebufferMemoryModel)framebuffer->memory_model,
reinterpret_cast<void*>(framebuffer->framebuffer_addr),
static_cast<fb::FramebufferMemoryModel>(framebuffer->memory_model),
framebuffer->red_mask_size,
framebuffer->red_mask_shift,
framebuffer->green_mask_size,
Expand Down Expand Up @@ -217,7 +173,7 @@ void Handoff::parseMultiboot2(Handoff* that, void* handoff)
{
auto cmdline = (struct multiboot_tag_string *) tag;
rs232_printf("Multiboot2 cmdline: '%s'\n", cmdline->string);
that->_cmdline = (const char *)(cmdline->string);
that->_cmdline = (char *)(cmdline->string);
break;
}
case MULTIBOOT_TAG_TYPE_FRAMEBUFFER:
Expand All @@ -228,15 +184,28 @@ void Handoff::parseMultiboot2(Handoff* that, void* handoff)
rs232_printf("\tResolution: %ix%ix%i\n",
framebuffer->common.framebuffer_width,
framebuffer->common.framebuffer_height,
(framebuffer->common.framebuffer_bpp * 8));
(framebuffer->common.framebuffer_bpp));
rs232_printf("\tPixel format:\n"
"\t\tRed size: %u\n"
"\t\tRed shift: %u\n"
"\t\tGreen size: %u\n"
"\t\tGreen shift: %u\n"
"\t\tBlue size: %u\n"
"\t\tBlue shift: %u\n",
framebuffer->framebuffer_red_mask_size,
framebuffer->framebuffer_red_field_position,
framebuffer->framebuffer_green_mask_size,
framebuffer->framebuffer_green_field_position,
framebuffer->framebuffer_blue_mask_size,
framebuffer->framebuffer_blue_field_position);
// Initialize the framebuffer information
that->_fbInfo = FramebufferInfo(
that->_fbInfo = fb::FramebufferInfo(
framebuffer->common.framebuffer_width,
framebuffer->common.framebuffer_height,
framebuffer->common.framebuffer_bpp,
framebuffer->common.framebuffer_pitch,
(void*)framebuffer->common.framebuffer_addr,
(FramebufferMemoryModel)framebuffer->common.framebuffer_type,
(fb::FramebufferMemoryModel)framebuffer->common.framebuffer_type,
framebuffer->framebuffer_red_mask_size,
framebuffer->framebuffer_red_field_position,
framebuffer->framebuffer_green_mask_size,
Expand Down
74 changes: 74 additions & 0 deletions kernel/dev/vga/fb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @file fb.cpp
* @author Keeton Feavel ([email protected])
* @brief
* @version 0.1
* @date 2021-06-11
*
* @copyright Copyright the Panix Contributors (c) 2021
*
*/
#include <dev/vga/fb.hpp>
// Types
#include <stddef.h>
#include <stdint.h>

namespace fb {

FramebufferInfo::FramebufferInfo()
: _addr(NULL)
, _width(0)
, _height(0)
, _depth(0)
, _pitch(0)
, _redMaskSize(0)
, _redMaskShift(0)
, _greenMaskSize(0)
, _greenMaskShift(0)
, _blueMaskSize(0)
, _blueMaskShift(0)
, _memoryModel(Undefined_FBMM)
{
// Default constructor.
}

FramebufferInfo::FramebufferInfo(uint32_t width, uint32_t height, uint16_t depth, uint32_t pitch, void* addr)
: _addr(addr)
, _width(width)
, _height(height)
, _depth(depth)
, _pitch(pitch)
, _redMaskSize(0)
, _redMaskShift(0)
, _greenMaskSize(0)
, _greenMaskShift(0)
, _blueMaskSize(0)
, _blueMaskShift(0)
, _memoryModel(Undefined_FBMM)
{
// Common parameters constructor
}

FramebufferInfo::FramebufferInfo(uint32_t width, uint32_t height,
uint16_t depth, uint32_t pitch,
void* addr, FramebufferMemoryModel model,
uint8_t redMaskSize, uint8_t redMaskShift,
uint8_t greenMaskSize, uint8_t greenMaskShift,
uint8_t blueMaskSize, uint8_t blueMaskShift)
: _addr(addr)
, _width(width)
, _height(height)
, _depth(depth)
, _pitch(pitch)
, _redMaskSize(redMaskSize)
, _redMaskShift(redMaskShift)
, _greenMaskSize(greenMaskSize)
, _greenMaskShift(greenMaskShift)
, _blueMaskSize(blueMaskSize)
, _blueMaskShift(blueMaskShift)
, _memoryModel(model)
{
// All parameters constructor
}

};
Loading

0 comments on commit 15c507e

Please sign in to comment.