working on exposing vga to userspace
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "vfs.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -9,6 +10,8 @@
|
||||
#include <common.h>
|
||||
#include <memory/mm.h>
|
||||
|
||||
#include <user/video.h>
|
||||
|
||||
static uint32_t framebuffer_address;
|
||||
static uint32_t framebuffer_width;
|
||||
static uint32_t framebuffer_height;
|
||||
@@ -34,36 +37,45 @@ vga_color_t VGA_COLOR_RED = {0, 0, 255, 255};
|
||||
vga_color_t VGA_COLOR_GREEN = {0, 255, 0, 255};
|
||||
vga_color_t VGA_COLOR_BLUE = {255, 0, 0, 255};
|
||||
|
||||
|
||||
uint32_t vga_mmap(vfs_node_t* node, uint32_t address) {
|
||||
uint32_t fb_size_bytes = framebuffer_height * framebuffer_pitch;
|
||||
uint32_t num_pages = (fb_size_bytes + 4095) / 4096;
|
||||
for (uint32_t i = 0; i < num_pages; i++) {
|
||||
uint32_t phys_addr = framebuffer_address + (i * 4096);
|
||||
uint32_t virt_addr = address + (i * 4096);
|
||||
map_page(virt_addr, phys_addr, PAGE_PRESENT | PAGE_WRITABLE);
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
uint32_t vga_ioctl(vfs_node_t* node, uint32_t request, void* arg) {
|
||||
if (request == FBIOGET_INFO) {
|
||||
fb_info_t* info = (fb_info_t*)arg;
|
||||
info->width = framebuffer_width;
|
||||
info->height = framebuffer_height;
|
||||
info->pitch = framebuffer_pitch;
|
||||
info->fb_size = framebuffer_total_pixels;
|
||||
info->bpp = framebuffer_bpp;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vga_init(
|
||||
vfs_node_t* dev,
|
||||
uint32_t fb_paddr,
|
||||
uint32_t fb_width,
|
||||
uint32_t fb_height,
|
||||
uint32_t fb_pitch,
|
||||
uint8_t fb_bpp,
|
||||
uint8_t _red_mask_sz,
|
||||
uint8_t _red_field_pos,
|
||||
uint8_t _green_mask_sz,
|
||||
uint8_t _green_field_pos,
|
||||
uint8_t _blue_mask_sz,
|
||||
uint8_t _blue_field_pos
|
||||
uint8_t fb_bpp
|
||||
) {
|
||||
framebuffer_address = VGA_FRAMEBUFFER;
|
||||
|
||||
red_mask_sz = _red_mask_sz;
|
||||
red_field_pos = _red_field_pos;
|
||||
green_mask_sz = _green_mask_sz;
|
||||
green_field_pos = _green_field_pos;
|
||||
blue_mask_sz = _blue_mask_sz;
|
||||
blue_field_pos = _blue_field_pos;
|
||||
|
||||
print_serial("initializing vga.\r\n");
|
||||
print_serial_hex(fb_paddr);
|
||||
print_serial("\r\n");
|
||||
print_serial_hex(framebuffer_address);
|
||||
print_serial("\r\n");
|
||||
print_serial("BPP: ");
|
||||
print_serial_hex(fb_bpp);
|
||||
print_serial("\r\n");
|
||||
framebuffer_address = fb_paddr;
|
||||
framebuffer_width = fb_width;
|
||||
framebuffer_height = fb_height;
|
||||
framebuffer_total_pixels = framebuffer_width * framebuffer_height;
|
||||
framebuffer_pitch = fb_pitch;
|
||||
framebuffer_bpp = fb_bpp;
|
||||
|
||||
uint32_t fb_size_bytes = fb_height * fb_pitch;
|
||||
uint32_t num_pages = (fb_size_bytes + 4095) / 4096;
|
||||
@@ -73,18 +85,15 @@ void vga_init(
|
||||
map_page(virt_addr, phys_addr, PAGE_PRESENT | PAGE_WRITABLE);
|
||||
}
|
||||
|
||||
framebuffer_width = fb_width;
|
||||
framebuffer_height = fb_height;
|
||||
framebuffer_total_pixels = framebuffer_width * framebuffer_height;
|
||||
|
||||
framebuffer_pitch = fb_pitch;
|
||||
framebuffer_bpp = fb_bpp;
|
||||
|
||||
vga_clear_scrn(0x00000000);
|
||||
|
||||
dev->flags = VFS_CHARDEVICE;
|
||||
dev->mmap = vga_mmap;
|
||||
dev->ioctl = vga_ioctl;
|
||||
}
|
||||
|
||||
uint32_t vga_get_framebuffer() {
|
||||
return framebuffer_address;
|
||||
return VGA_FRAMEBUFFER;
|
||||
}
|
||||
|
||||
uint32_t vga_get_width() {
|
||||
@@ -124,25 +133,3 @@ void vga_clear_scrn(uint32_t color) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t vga_write(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buf) {
|
||||
return size;
|
||||
}
|
||||
|
||||
void test_draw_vertical_line(uint32_t x, uint32_t y_start, uint32_t y_end, uint32_t color) {
|
||||
if (framebuffer_address == 0) return;
|
||||
|
||||
uint8_t* fb_bytes = (uint8_t*)framebuffer_address;
|
||||
|
||||
for (uint32_t y = y_start; y < y_end; y++) {
|
||||
if (y >= framebuffer_height) break;
|
||||
|
||||
uint8_t* row = fb_bytes + (y * framebuffer_pitch);
|
||||
|
||||
uint32_t* pixel_row = (uint32_t*)row;
|
||||
|
||||
if (x < framebuffer_width) {
|
||||
pixel_row[x] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user