aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kernel.cc4
-rw-r--r--src/makefile1
-rw-r--r--src/ports.h43
-rw-r--r--src/vga.cc92
-rw-r--r--src/vga.h59
5 files changed, 2 insertions, 197 deletions
diff --git a/src/kernel.cc b/src/kernel.cc
index 4569107..4c17969 100644
--- a/src/kernel.cc
+++ b/src/kernel.cc
@@ -10,15 +10,15 @@
#include <stdlib.h>
#include <types.h>
+#include "cga.h"
#include "gdt.h"
-#include "vga.h"
extern "C" {
void dump_multiboot(uint32_t mb_magic, uint32_t mb_addr);
void dump_gdt();
void kernel_main([[maybe_unused]] uint32_t mb_magic, [[maybe_unused]] uint32_t mb_addr) {
- VGA terminal;
+ CGA terminal;
Console::set(&terminal);
printk("Hello, kernel World!\n");
diff --git a/src/makefile b/src/makefile
index 25c58be..8214d03 100644
--- a/src/makefile
+++ b/src/makefile
@@ -4,6 +4,5 @@ CXX_OBJ += src/kernel.o \
src/kernel/dump_gdt.o \
src/kernel/dump_multiboot.o \
src/memory.o \
- src/vga.o \
src/gdt.o \
src/gdt/segmentdescriptor.o
diff --git a/src/ports.h b/src/ports.h
deleted file mode 100644
index 0371bcc..0000000
--- a/src/ports.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#pragma once
-
-template <typename T>
-concept port_data_t = (is_same<T, uint8_t>::value || is_same<T, uint16_t>::value || is_same<T, uint32_t>::value);
-
-template <uint16_t port_num, port_data_t T>
-class Port {
-public:
- [[nodiscard]] T read() {
- T result;
-
- switch (sizeof(T)) {
- case 1:
- asm volatile("inb %1, %0" : "=a"(result) : "Nd"(port_num));
- break;
- case 2:
- asm volatile("inw %1, %0" : "=a"(result) : "Nd"(port_num));
- break;
- case 4:
- asm volatile("inl %1, %0" : "=a"(result) : "Nd"(port_num));
- break;
- }
-
- return result;
- }
-
- void write(T data) {
- switch (sizeof(T)) {
- case 1:
- asm volatile("outb %0, %1" : : "a"(data), "Nd"(port_num));
- break;
- case 2:
- asm volatile("outw %0, %1" : : "a"(data), "Nd"(port_num));
- break;
- case 4:
- asm volatile("outl %0, %1" : : "a"(data), "Nd"(port_num));
- break;
- }
- }
-};
-
-typedef Port<0x3d4, uint8_t> vga_horizontal_total;
-typedef Port<0x3d5, uint8_t> vga_horizontal_display_enable_end;
diff --git a/src/vga.cc b/src/vga.cc
deleted file mode 100644
index 66a6b3a..0000000
--- a/src/vga.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-#include "vga.h"
-#include <string.h>
-
-static_assert(sizeof(VGA::Entry) == 2);
-
-VGA::VGA(vga_color fg, vga_color bg, uint32_t address) : color_fg(fg), color_bg(bg) {
- buffer = reinterpret_cast<Entry*>(address);
-
- // clear buffer
- for (size_t y = 0; y < max_rows; y++) {
- for (size_t x = 0; x < max_columns; x++) {
- const size_t index = y * max_columns + x;
- buffer[index].c = ' ';
- buffer[index].fg = color_fg;
- buffer[index].bg = color_bg;
- }
- }
-
- enable_cursor(14, 15);
- update_cursor();
-}
-
-void VGA::set_color(vga_color fg, vga_color bg) {
- color_fg = fg;
- color_bg = bg;
- for (size_t y = 0; y < max_rows; y++) {
- for (size_t x = 0; x < max_columns; x++) {
- const size_t index = y * max_columns + x;
- buffer[index].fg = color_fg;
- buffer[index].bg = color_bg;
- }
- }
-}
-
-void VGA::enable_cursor(uint8_t start, uint8_t end) {
- p_3d4.write(0x0a);
- p_3d5.write((p_3d5.read() & 0xc0) | start);
-
- p_3d4.write(0x0b);
- p_3d5.write((p_3d5.read() & 0xe0) | end);
-}
-void VGA::disable_cursor() {
- p_3d4.write(0x0a);
- p_3d5.write(0x20);
-}
-void VGA::update_cursor() {
- const uint16_t pos = row * max_columns + column;
-
- p_3d4.write(0x0f);
- p_3d5.write(static_cast<uint8_t>(pos & 0xff));
-
- p_3d4.write(0x0e);
- p_3d5.write(static_cast<uint8_t>((pos >> 8) & 0xff));
-}
-
-void VGA::write(char c) {
- switch (c) {
- case '\n':
- column = 0;
- ++row;
- break;
- default: {
- const size_t index = row * max_columns + column;
- buffer[index].c = c;
- ++column;
- }
- }
-
- if (column == max_columns) {
- column = 0;
- ++row;
- }
-
- if (row == max_rows) {
- // scroll up - move rows 1~25 up by one
- for (size_t y = 1; y < max_rows; y++) {
- const auto prev_y = y - 1;
- for (size_t x = 0; x < max_columns; ++x) {
- const auto prev = prev_y * max_columns + x;
- const auto idx = y * max_columns + x;
- buffer[prev] = buffer[idx];
- }
- }
- --row;
- }
-}
-
-void VGA::write(ViewIterator& iter) {
- while (iter) {
- write(iter.next());
- }
-}
diff --git a/src/vga.h b/src/vga.h
deleted file mode 100644
index 7a8c755..0000000
--- a/src/vga.h
+++ /dev/null
@@ -1,59 +0,0 @@
-#pragma once
-#include <stdlib.h>
-#include "ports.h"
-
-class VGA : public Console {
-public:
- /* Hardware text mode color constants. */
- enum vga_color : uint8_t {
- VGA_COLOR_BLACK = 0,
- VGA_COLOR_BLUE = 1,
- VGA_COLOR_GREEN = 2,
- VGA_COLOR_CYAN = 3,
- VGA_COLOR_RED = 4,
- VGA_COLOR_MAGENTA = 5,
- VGA_COLOR_BROWN = 6,
- VGA_COLOR_LIGHT_GREY = 7,
- VGA_COLOR_DARK_GREY = 8,
- VGA_COLOR_LIGHT_BLUE = 9,
- VGA_COLOR_LIGHT_GREEN = 10,
- VGA_COLOR_LIGHT_CYAN = 11,
- VGA_COLOR_LIGHT_RED = 12,
- VGA_COLOR_LIGHT_MAGENTA = 13,
- VGA_COLOR_LIGHT_BROWN = 14,
- VGA_COLOR_WHITE = 15,
- };
-
- VGA(vga_color fg = VGA_COLOR_BLACK, vga_color bg = VGA_COLOR_LIGHT_GREY, uint32_t address = 0xB8000);
- ~VGA() = default;
-
- void set_color(vga_color fg, vga_color bg);
-
- void enable_cursor(uint8_t start, uint8_t end);
- void disable_cursor();
- void update_cursor() override;
-
- void write(char c) override;
- void write(ViewIterator& iter) override;
-
-
- struct Entry {
- char c;
- vga_color fg : 4;
- vga_color bg : 4;
- } __attribute((packed));
-
-private:
- const size_t max_columns = 80, max_rows = 25;
- size_t column = 0, row = 0;
-
- vga_color color_fg;
- vga_color color_bg;
-
- Entry* buffer;
-
- // ports
- vga_horizontal_total p_3d4;
- vga_horizontal_display_enable_end p_3d5;
-};
-