From edf9e71e2a7b6b89775c29cf28c19c6b89992c25 Mon Sep 17 00:00:00 2001 From: aqua Date: Mon, 28 Mar 2022 20:03:38 +0300 Subject: Initial commit x86 kernel that prints a hello world message to com1 --- devices/vga.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 devices/vga.c (limited to 'devices/vga.c') diff --git a/devices/vga.c b/devices/vga.c new file mode 100644 index 0000000..983e630 --- /dev/null +++ b/devices/vga.c @@ -0,0 +1,35 @@ +#include "vga.h" +#include +#include + +struct __attribute__((packed)) VGAEntry { + unsigned char text; + uint8_t foreground : 4; + uint8_t background : 4; +}; + +_Static_assert(sizeof(struct VGAEntry) == 2); + +const size_t width = 80; +const size_t height = 25; + +struct VGAEntry *buffer; + +void +vga_init() +{ + buffer = (struct VGAEntry *)0xc03ff000; + vga_clear(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_LIGHT_GREY); +} + +void +vga_clear(enum vga_color foreground, enum vga_color background) +{ + for (size_t y = 0; y < height; ++y) + for (size_t x = 0; x < width; ++x) { + const size_t index = y * width + x; + buffer[index].text = ' '; + buffer[index].foreground = foreground; + buffer[index].background = background; + } +} -- cgit v1.2.1