diff options
Diffstat (limited to 'kernel/drivers/gpu')
-rw-r--r-- | kernel/drivers/gpu/bochs.c | 62 | ||||
-rw-r--r-- | kernel/drivers/gpu/gop.c | 27 | ||||
-rw-r--r-- | kernel/drivers/gpu/vga_text.c | 27 |
3 files changed, 71 insertions, 45 deletions
diff --git a/kernel/drivers/gpu/bochs.c b/kernel/drivers/gpu/bochs.c index a100908..3438ab5 100644 --- a/kernel/drivers/gpu/bochs.c +++ b/kernel/drivers/gpu/bochs.c @@ -2,6 +2,7 @@ #include <comus/asm.h> #include <comus/memory.h> #include <comus/drivers/pci.h> +#include <comus/drivers/gpu.h> #include <comus/drivers/gpu/bochs.h> #define INDEX 0x1CE @@ -30,10 +31,7 @@ #define BOCHS_HEIGHT 768 #define BOCHS_BIT_DEPTH 32 -static volatile uint32_t *framebuffer; -static uint16_t width = BOCHS_WIDTH; -static uint16_t height = BOCHS_HEIGHT; -static uint8_t bit_depth = BOCHS_BIT_DEPTH; +struct gpu bochs_dev = { 0 }; static void write(uint16_t index, uint16_t data) { @@ -47,23 +45,7 @@ static uint16_t read(uint16_t value) return inw(DATA); } -static int is_available(void) -{ - return (read(INDEX_ID) == 0xB0C5); -} - -static void set_mode(uint16_t width, uint16_t height, uint16_t bit_depth, - int lfb, int clear) -{ - write(INDEX_ENABLE, DATA_DISP_DISABLE); - write(INDEX_XRES, width); - write(INDEX_YRES, height); - write(INDEX_BPP, bit_depth); - write(INDEX_ENABLE, DATA_DISP_ENABLE | (lfb ? DATA_LFB_ENABLE : 0) | - (clear ? 0 : DATA_NO_CLEAR_MEM)); -} - -int bochs_init(void) +int bochs_init(struct gpu **gpu_dev) { struct pci_device bochs = { 0 }; bool found = @@ -71,34 +53,24 @@ int bochs_init(void) if (!found) return 1; - set_mode(width, height, bit_depth, true, true); - if (!is_available()) + write(INDEX_ENABLE, DATA_DISP_DISABLE); + write(INDEX_XRES, BOCHS_WIDTH); + write(INDEX_YRES, BOCHS_HEIGHT); + write(INDEX_BPP, BOCHS_BIT_DEPTH); + write(INDEX_ENABLE, DATA_DISP_ENABLE | DATA_LFB_ENABLE); + if (read(INDEX_ID) != 0xB0C5) return 1; uint32_t bar0 = pci_rcfg_d(bochs, PCI_BAR0_D); uint32_t *addr = (uint32_t *)(uintptr_t)bar0; - framebuffer = kmapaddr(addr, NULL, width * height * bit_depth, F_WRITEABLE); - return 0; -} + bochs_dev.name = "Bochs"; + bochs_dev.width = BOCHS_WIDTH; + bochs_dev.height = BOCHS_HEIGHT; + bochs_dev.bit_depth = BOCHS_BIT_DEPTH; + bochs_dev.framebuffer = kmapaddr( + addr, NULL, BOCHS_WIDTH * BOCHS_HEIGHT * BOCHS_BIT_DEPTH, F_WRITEABLE); + *gpu_dev = &bochs_dev; -uint32_t bochs_width(void) -{ - return width; -} - -uint32_t bochs_height(void) -{ - return height; -} - -uint8_t bochs_bit_depth(void) -{ - return bit_depth; -} - -void bochs_set_pixel(uint32_t x, uint32_t y, uint32_t r, uint32_t g, uint32_t b) -{ - uint32_t index = x + y * width; - framebuffer[index] = (b << 0) | (g << 8) | (r << 16); + return 0; } diff --git a/kernel/drivers/gpu/gop.c b/kernel/drivers/gpu/gop.c new file mode 100644 index 0000000..47da952 --- /dev/null +++ b/kernel/drivers/gpu/gop.c @@ -0,0 +1,27 @@ +#include <lib.h> +#include <comus/asm.h> +#include <comus/drivers/gpu.h> +#include <comus/drivers/gpu/gop.h> +#include <comus/efi.h> +#include <efi.h> + +struct gpu gop_dev = { 0 }; + +static EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; + +int gop_init(struct gpu **gpu_dev) +{ + gop = efi_get_gop(); + if (gop == NULL || gop->Mode == NULL) + return 1; + + gop_dev.name = "GOP"; + gop_dev.width = gop->Mode->Info->HorizontalResolution; + gop_dev.height = gop->Mode->Info->VerticalResolution; + gop_dev.bit_depth = 32; // we only allow 8bit color in efi/gop.c + gop_dev.framebuffer = kmapaddr((void *)gop->Mode->FrameBufferBase, NULL, + gop->Mode->FrameBufferSize, F_WRITEABLE); + *gpu_dev = &gop_dev; + + return 1; +} diff --git a/kernel/drivers/gpu/vga_text.c b/kernel/drivers/gpu/vga_text.c new file mode 100644 index 0000000..e3359c3 --- /dev/null +++ b/kernel/drivers/gpu/vga_text.c @@ -0,0 +1,27 @@ +#include <lib.h> +#include <comus/term.h> +#include <comus/asm.h> +#include <comus/memory.h> +#include <comus/drivers/gpu/vga_text.h> + +#define VGA_ADDR 0xB8000 +#define VGA_WIDTH 80 +#define VGA_HEIGHT 25 +static volatile uint16_t *buffer = (uint16_t *)VGA_ADDR; + +// color +static uint8_t fg = 15, bg = 0; + +void vga_text_draw_char(char c, uint16_t x, uint16_t y) +{ + // output character + const size_t index = y * VGA_WIDTH + x; + buffer[index] = c | bg << 12 | fg << 8; + + // set cursor position on screen + const uint16_t pos = y * VGA_HEIGHT + x; + outb(0x3D4, 0x0F); + outb(0x3D5, (uint8_t)(pos & 0xFF)); + outb(0x3D4, 0x0E); + outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF)); +} |