Max OS 0.3
Loading...
Searching...
No Matches
vesa.cpp
Go to the documentation of this file.
1
10#include <common/logger.h>
11
12using namespace MaxOS;
13using namespace MaxOS::drivers;
14using namespace MaxOS::drivers::video;
15using namespace MaxOS::memory;
16using namespace MaxOS::system;
17using namespace MaxOS::common;
18
25: m_framebuffer_info(framebuffer_info)
26{
27
28 Logger::INFO() << "Setting up VESA driver\n";
29
30 // Save the framebuffer info
31 m_bpp = m_framebuffer_info->common.framebuffer_bpp;
32 m_pitch = m_framebuffer_info->common.framebuffer_pitch;
33 m_framebuffer_size = m_framebuffer_info->common.framebuffer_height * m_pitch;
34 this->set_mode(framebuffer_info->common.framebuffer_width, framebuffer_info->common.framebuffer_height, framebuffer_info->common.framebuffer_bpp);
35 Logger::DEBUG() << "Framebuffer: bpp=" << m_bpp << ", pitch=" << m_pitch << ", size=" << m_framebuffer_size << "\n";
36
37 // Map the frame buffer into the higher half
38 auto physical_address = (uint64_t) m_framebuffer_info->common.framebuffer_addr;
40 PhysicalMemoryManager::s_current_manager->map_area((physical_address_t *) physical_address, m_framebuffer_address, m_framebuffer_size, WRITE | PRESENT);
41
42 // Reserve the physical memory
43 size_t pages = PhysicalMemoryManager::size_to_frames(m_framebuffer_size);
44 PhysicalMemoryManager::s_current_manager->reserve(m_framebuffer_info->common.framebuffer_addr, pages, "Framebuffer");
45
46 // Log info
47 Logger::DEBUG() << "Framebuffer address: physical=0x" << (uint64_t) physical_address << ", virtual=0x" << (uint64_t) m_framebuffer_address << "\n";
48 Logger::DEBUG() << "Framebuffer mapped: 0x" << (uint64_t) m_framebuffer_address << " - 0x" << (uint64_t) (m_framebuffer_address + m_framebuffer_size) << " (pages: " << pages << ")\n";
49
50}
51
52VideoElectronicsStandardsAssociation::~VideoElectronicsStandardsAssociation() = default;
53
62bool VideoElectronicsStandardsAssociation::internal_set_mode(uint32_t width, uint32_t height, uint32_t color_depth) {
63
64 // Can only use the mode set up already by grub
65 return width == m_framebuffer_info->common.framebuffer_width
66 && height == m_framebuffer_info->common.framebuffer_height
67 && color_depth == m_framebuffer_info->common.framebuffer_bpp;
68
69}
70
80
81 // Check if the mode is supported
82 return width == m_framebuffer_info->common.framebuffer_width
83 && height == m_framebuffer_info->common.framebuffer_height
84 && color_depth == m_framebuffer_info->common.framebuffer_bpp;
85}
86
94void VideoElectronicsStandardsAssociation::render_pixel_32_bit(uint32_t x, uint32_t y, uint32_t colour) {
95
96 auto *pixel_address = (uint32_t *) ((uint8_t *) m_framebuffer_address + (m_pitch * y) + (m_bpp * x) / 8);
97 *pixel_address = colour;
98
99}
100
108uint32_t VideoElectronicsStandardsAssociation::get_rendered_pixel_32_bit(uint32_t x, uint32_t y) {
109
110 auto *pixel_address = (uint32_t *) ((uint8_t *) m_framebuffer_address + m_pitch * (y) + m_bpp * (x) / 8);
111 return *pixel_address;
112}
113
120
121 // Creator of the VESA standard
122 return "NEC Home Electronics";
123}
124
131 return "VESA compatible graphics card";
132}
static Logger DEBUG()
Gets active logger set to DEBUG level.
Definition logger.cpp:193
static Logger INFO()
Gets active logger set to info level.
Definition logger.cpp:171
uint32_t width() const
Gets the width of the screen.
uint64_t * m_framebuffer_address
The address of the framebuffer.
uint32_t height() const
Gets the height of the screen.
uint32_t color_depth() const
Gets the current color depth (bits per pixel)
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
bool set_mode(uint32_t width, uint32_t height, uint32_t color_depth)
Set the mode of the video driver.
Definition video.cpp:53
bool supports_mode(uint32_t width, uint32_t height, uint32_t) final
Checks if the VESA driver supports the given mode.
Definition vesa.cpp:79
VideoElectronicsStandardsAssociation(multiboot_tag_framebuffer *framebuffer_info)
Constructs a new VESA driver object. Maps the framebuffer into the higher half.
Definition vesa.cpp:24
string device_name() final
The name of the device.
Definition vesa.cpp:130
string vendor_name() final
The name of the vendor of the VESA standard.
Definition vesa.cpp:119
static void * to_dm_region(uintptr_t physical_address)
Converts a physical address to a direct map region address if it is in the lower region using the hig...
Definition physical.cpp:930
static PhysicalMemoryManager * s_current_manager
The current physical memory manager in use.
Definition physical.h:185
static size_t size_to_frames(size_t size)
Converts a size to the number of frames.
Definition physical.cpp:156
Defines a Logger class for logging messages with different severity levels to multiple output streams...
@ PRESENT
The page is present in memory.
Definition physical.h:43
@ WRITE
Memory in this page is writable.
Definition physical.h:44
A tag containing information about the framebuffer.
Definition multiboot.h:356
struct multiboot_tag_framebuffer_common common
*copydoc multiboot_tag_framebuffer_common
Definition multiboot.h:357
Defines a Video Electronics Standards Association (VESA) video driver for handling pixel rendering us...