diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-03-28 20:03:38 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-08-12 10:13:59 +0300 |
commit | edf9e71e2a7b6b89775c29cf28c19c6b89992c25 (patch) | |
tree | 3adbf944d9e47a743063487c4facb7eed1fbdee0 /devices/vga.c | |
download | kernel-edf9e71e2a7b6b89775c29cf28c19c6b89992c25.tar.xz |
Initial commit
x86 kernel that prints a hello world message to com1
Diffstat (limited to 'devices/vga.c')
-rw-r--r-- | devices/vga.c | 35 |
1 files changed, 35 insertions, 0 deletions
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 <stddef.h> +#include <stdint.h> + +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; + } +} |