diff --git a/kernel/arch/i386/TTY.cpp b/kernel/arch/i386/TTY.cpp new file mode 100644 index 00000000..a3d5cd81 --- /dev/null +++ b/kernel/arch/i386/TTY.cpp @@ -0,0 +1,337 @@ +#include +#include +#include +#include +#include +#include + +#include + +#define BEL 0x07 +#define BS 0x08 +#define HT 0x09 +#define LF 0x0A +#define FF 0x0C +#define CR 0x0D +#define ESC 0x1B + +#define CSI '[' + +template inline constexpr T max(T a, T b) { return a > b ? a : b; } +template inline constexpr T min(T a, T b) { return a < b ? a : b; } +template inline constexpr T clamp(T x, T a, T b) { return x < a ? a : x > b ? b : x; } + +static TTY* s_tty = nullptr; + +TTY::TTY() +{ + m_width = VESA::GetTerminalWidth(); + m_height = VESA::GetTerminalHeight(); + + m_buffer = new Cell[m_width * m_height]; + + if (s_tty == nullptr) + s_tty = this; +} + +void TTY::Clear() +{ + for (uint32_t i = 0; i < m_width * m_height; i++) + { + m_buffer[i].foreground = m_foreground; + m_buffer[i].background = m_background; + m_buffer[i].character = ' '; + } + VESA::Clear(m_background); +} + +static void update_cursor(uint16_t pos) +{ + IO::outb(0x3D4, 0x0F); + IO::outb(0x3D5, (uint8_t) (pos & 0xFF)); + IO::outb(0x3D4, 0x0E); + IO::outb(0x3D5, (uint8_t) ((pos >> 8) & 0xFF)); +} + +void TTY::SetCursorPos(int x, int y) +{ + m_row = y; + m_column = x; + update_cursor(m_row * m_width + m_column); +} + +static uint16_t handle_unicode(uint8_t ch) +{ + static uint8_t unicode_left = 0; + static uint16_t codepoint = 0; + + if (unicode_left) + { + if ((ch >> 6) == 0b10) + { + codepoint = (codepoint << 6) | ch; + unicode_left--; + if (unicode_left > 0) + return 0xFFFF; + return codepoint; + } + else + { + // invalid utf-8 + unicode_left = 0; + return 0x00; + } + } + else + { + if ((ch >> 3) == 0b11110) + { + unicode_left = 3; + codepoint = ch & 0b00000111; + return 0xFFFF; + } + if ((ch >> 4) == 0b1110) + { + unicode_left = 2; + codepoint = ch & 0b00001111; + return 0xFFFF; + } + if ((ch >> 5) == 0b110) + { + unicode_left = 1; + codepoint = ch & 0b00011111; + return 0xFFFF; + } + } + + return ch & 0x7F; +} + +void TTY::ResetAnsiEscape() +{ + m_ansi_state.mode = '\0'; + m_ansi_state.index = 0; + m_ansi_state.nums[0] = -1; + m_ansi_state.nums[1] = -1; +} + +void TTY::HandleAnsiSGR() +{ + switch (m_ansi_state.nums[0]) + { + case -1: + case 0: + m_foreground = VESA::Color::BRIGHT_WHITE; + m_background = VESA::Color::BLACK; + break; + + case 30: m_foreground = VESA::Color::BRIGHT_BLACK; break; + case 31: m_foreground = VESA::Color::BRIGHT_RED; break; + case 32: m_foreground = VESA::Color::BRIGHT_GREEN; break; + case 33: m_foreground = VESA::Color::BRIGHT_YELLOW; break; + case 34: m_foreground = VESA::Color::BRIGHT_BLUE; break; + case 35: m_foreground = VESA::Color::BRIGHT_MAGENTA; break; + case 36: m_foreground = VESA::Color::BRIGHT_CYAN; break; + case 37: m_foreground = VESA::Color::BRIGHT_WHITE; break; + + case 40: m_background = VESA::Color::BRIGHT_BLACK; break; + case 41: m_background = VESA::Color::BRIGHT_RED; break; + case 42: m_background = VESA::Color::BRIGHT_GREEN; break; + case 43: m_background = VESA::Color::BRIGHT_YELLOW; break; + case 44: m_background = VESA::Color::BRIGHT_BLUE; break; + case 45: m_background = VESA::Color::BRIGHT_MAGENTA; break; + case 46: m_background = VESA::Color::BRIGHT_CYAN; break; + case 47: m_background = VESA::Color::BRIGHT_WHITE; break; + } +} + +void TTY::HandleAnsiEscape(uint16_t ch) +{ + switch (m_ansi_state.mode) + { + case '\1': + { + if (ch == CSI) + { + m_ansi_state.mode = CSI; + return; + } + return ResetAnsiEscape(); + } + + case CSI: + { + switch (ch) + { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + { + int32_t& val = m_ansi_state.nums[m_ansi_state.index]; + val = (val == -1) ? (ch - '0') : (val * 10 + ch - '0'); + return; + } + case ';': + m_ansi_state.index++; + return; + case 'A': // Cursor Up + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + m_row = max(m_row - m_ansi_state.nums[0], 0); + return ResetAnsiEscape(); + case 'B': // Curson Down + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + m_row = min(m_row + m_ansi_state.nums[0], m_height - 1); + return ResetAnsiEscape(); + case 'C': // Cursor Forward + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + m_column = min(m_column + m_ansi_state.nums[0], m_width - 1); + return ResetAnsiEscape(); + case 'D': // Cursor Back + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + m_column = max(m_column - m_ansi_state.nums[0], 0); + return ResetAnsiEscape(); + case 'E': // Cursor Next Line + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + m_row = min(m_row + m_ansi_state.nums[0], m_height - 1); + m_column = 0; + return ResetAnsiEscape(); + case 'F': // Cursor Previous Line + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + m_row = max(m_row - m_ansi_state.nums[0], 0); + m_column = 0; + return ResetAnsiEscape(); + case 'G': // Cursor Horizontal Absolute + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + m_column = clamp(m_ansi_state.nums[0] - 1, 0, m_width - 1); + return ResetAnsiEscape(); + case 'H': // Cursor Position + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + if (m_ansi_state.nums[1] == -1) + m_ansi_state.nums[1] = 1; + m_row = clamp(m_ansi_state.nums[0] - 1, 0, m_height - 1); + m_column = clamp(m_ansi_state.nums[1] - 1, 0, m_width - 1); + return ResetAnsiEscape(); + case 'J': // Erase in Display + dprintln("Unsupported ANSI CSI character J"); + return ResetAnsiEscape(); + case 'K': // Erase in Line + dprintln("Unsupported ANSI CSI character K"); + return ResetAnsiEscape(); + case 'S': // Scroll Up + dprintln("Unsupported ANSI CSI character S"); + return ResetAnsiEscape(); + case 'T': // Scroll Down + dprintln("Unsupported ANSI CSI character T"); + return ResetAnsiEscape(); + case 'f': // Horizontal Vertical Position + dprintln("Unsupported ANSI CSI character f"); + return ResetAnsiEscape(); + case 'm': + HandleAnsiSGR(); + return ResetAnsiEscape(); + default: + dprintln("Unsupported ANSI CSI character {}", ch); + return ResetAnsiEscape(); + } + } + + default: + dprintln("Unsupported ANSI mode"); + return ResetAnsiEscape(); + } +} + +void TTY::PutChar(char ch) +{ + uint16_t cp = handle_unicode(ch); + if (cp == 0xFFFF) + return; + + if (m_ansi_state.mode != 0) + return HandleAnsiEscape(cp); + + // https://en.wikipedia.org/wiki/ANSI_escape_code + switch (cp) + { + case BEL: // TODO + break; + case BS: + if (m_column > 0) + m_column--; + break; + case HT: + m_column++; + while (m_column % 8) + m_column++; + break; + case LF: + m_column = 0; + m_row++; + break; + case FF: + m_row++; + break; + case CR: + m_column = 0; + break; + case ESC: + m_ansi_state.mode = '\1'; + break; + default: + VESA::PutEntryAt(cp, m_column, m_row, m_foreground, m_background); + m_column++; + break; + } + + if (m_column >= m_width) + { + m_column = 0; + m_row++; + } + + while (m_row >= m_height) + { + VESA::Scroll(); + for (size_t x = 0; x < m_width; x++) + VESA::PutEntryAt(' ', x, m_height - 1, m_foreground, m_background); + + m_column = 0; + m_row--; + } + + update_cursor(m_row * m_width + m_column); +} + +void TTY::Write(const char* data, size_t size) +{ + for (size_t i = 0; i < size; i++) + PutChar(data[i]); +} + +void TTY::WriteString(const char* data) +{ + while (*data) + { + PutChar(*data); + data++; + } +} + +void TTY::PutCharCurrent(char ch) +{ + if (s_tty) + { + s_tty->PutChar(ch); + } + else + { + + } +} diff --git a/kernel/arch/i386/VESA.cpp b/kernel/arch/i386/VESA.cpp index 05eb96a9..07928083 100644 --- a/kernel/arch/i386/VESA.cpp +++ b/kernel/arch/i386/VESA.cpp @@ -80,7 +80,7 @@ namespace VESA return 0; } - bool PreInitialize() + bool Initialize() { if (!(s_multiboot_info->flags & MULTIBOOT_FLAGS_FRAMEBUFFER)) return false; @@ -101,14 +101,12 @@ namespace VESA return false; } - dprintln("VESA in Graphics mode {}x{} ({} bpp)", s_width, s_height, s_bpp); GraphicsClear(Color::BLACK); return true; } if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_TEXT) { - dprintln("VESA in Text mode {}x{}", s_width, s_height); TextClear(Color::BLACK); return true; } @@ -117,22 +115,6 @@ namespace VESA return false; } - void Initialize() - { - if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS) - { - s_buffer = kmalloc_eternal(s_height * s_pitch); - if (s_buffer == nullptr) - kprintln("Could not allocate a buffer for VESA"); - else - memcpy(s_buffer, s_addr, s_height * s_pitch); - } - } - - - - - static uint32_t s_graphics_colors[] { 0x00'00'00'00, @@ -228,7 +210,7 @@ namespace VESA if (s_bpp == 32) { - uint32_t bytes_per_row = s_pitch / (s_bpp / 8); + uint32_t bytes_per_row = s_pitch / 4; for (uint32_t y = 0; y < s_height; y++) for (uint32_t x = 0; x < s_width; x++) ((uint32_t*)s_addr)[y * bytes_per_row + x] = u32_color; @@ -256,7 +238,7 @@ namespace VESA { if (s_bpp == 32) { - uint32_t bytes_per_row = s_pitch / (s_bpp / 8); + uint32_t bytes_per_row = s_pitch / 4; for (uint32_t y = 0; y < s_height - font.Height; y++) { for (uint32_t x = 0; x < s_width; x++) diff --git a/kernel/arch/i386/make.config b/kernel/arch/i386/make.config index a4013aae..10de656d 100644 --- a/kernel/arch/i386/make.config +++ b/kernel/arch/i386/make.config @@ -10,5 +10,5 @@ $(ARCHDIR)/CPUID.o \ $(ARCHDIR)/font.o \ $(ARCHDIR)/GDT.o \ $(ARCHDIR)/IDT.o \ -$(ARCHDIR)/tty.o \ +$(ARCHDIR)/TTY.o \ $(ARCHDIR)/VESA.o \ diff --git a/kernel/arch/i386/tty.cpp b/kernel/arch/i386/tty.cpp deleted file mode 100644 index e35abfdd..00000000 --- a/kernel/arch/i386/tty.cpp +++ /dev/null @@ -1,353 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -#define BEL 0x07 -#define BS 0x08 -#define HT 0x09 -#define LF 0x0A -#define FF 0x0C -#define CR 0x0D -#define ESC 0x1B - -#define CSI '[' - -namespace TTY -{ - - static uint32_t terminal_height = 0; - static uint32_t terminal_width = 0; - static uint32_t terminal_row = 0; - static uint32_t terminal_col = 0; - static VESA::Color terminal_fg = VESA::Color::BRIGHT_WHITE; - static VESA::Color terminal_bg = VESA::Color::BLACK; - - static char s_ansi_escape_mode = '\0'; - static int s_ansi_escape_index = 0; - static int s_ansi_escape_nums[2] = { -1, -1 }; - - template inline constexpr T max(T a, T b) { return a > b ? a : b; } - template inline constexpr T min(T a, T b) { return a < b ? a : b; } - template inline constexpr T clamp(T x, T a, T b) { return x < a ? a : x > b ? b : x; } - - void initialize() - { - terminal_width = VESA::GetTerminalWidth(); - terminal_height = VESA::GetTerminalHeight(); - } - - void clear() - { - VESA::Clear(VESA::Color::BLACK); - } - - void setcolor(VESA::Color fg, VESA::Color bg) - { - terminal_fg = fg; - terminal_bg = bg; - } - - void clear_line(size_t line) - { - for (size_t x = 0; x < terminal_width; x++) - VESA::PutEntryAt(' ', x, line, terminal_fg, terminal_bg); - } - - static void update_cursor() - { - uint16_t pos = terminal_row * terminal_width + terminal_col; - IO::outb(0x3D4, 0x0F); - IO::outb(0x3D5, (uint8_t) (pos & 0xFF)); - IO::outb(0x3D4, 0x0E); - IO::outb(0x3D5, (uint8_t) ((pos >> 8) & 0xFF)); - } - - void set_cursor_pos(int x, int y) - { - terminal_row = y; - terminal_col = x; - update_cursor(); - } - - static uint16_t handle_unicode(uint8_t ch) - { - static uint8_t unicode_left = 0; - static uint16_t codepoint = 0; - - if (unicode_left) - { - if ((ch >> 6) == 0b10) - { - codepoint = (codepoint << 6) | ch; - unicode_left--; - if (unicode_left > 0) - return 0xFFFF; - return codepoint; - } - else - { - // invalid utf-8 - unicode_left = 0; - return 0x00; - } - } - else - { - if ((ch >> 3) == 0b11110) - { - unicode_left = 3; - codepoint = ch & 0b00000111; - return 0xFFFF; - } - if ((ch >> 4) == 0b1110) - { - unicode_left = 2; - codepoint = ch & 0b00001111; - return 0xFFFF; - } - if ((ch >> 5) == 0b110) - { - unicode_left = 1; - codepoint = ch & 0b00011111; - return 0xFFFF; - } - } - - return ch & 0x7F; - } - - static void reset_ansi_escape() - { - s_ansi_escape_mode = '\0'; - s_ansi_escape_index = 0; - s_ansi_escape_nums[0] = -1; - s_ansi_escape_nums[1] = -1; - } - - static void handle_ansi_SGR() - { - switch (s_ansi_escape_nums[0]) - { - case -1: - case 0: - terminal_fg = VESA::Color::BRIGHT_WHITE; - terminal_bg = VESA::Color::BLACK; - break; - - case 30: terminal_fg = VESA::Color::BRIGHT_BLACK; break; - case 31: terminal_fg = VESA::Color::BRIGHT_RED; break; - case 32: terminal_fg = VESA::Color::BRIGHT_GREEN; break; - case 33: terminal_fg = VESA::Color::BRIGHT_YELLOW; break; - case 34: terminal_fg = VESA::Color::BRIGHT_BLUE; break; - case 35: terminal_fg = VESA::Color::BRIGHT_MAGENTA; break; - case 36: terminal_fg = VESA::Color::BRIGHT_CYAN; break; - case 37: terminal_fg = VESA::Color::BRIGHT_WHITE; break; - - case 40: terminal_bg = VESA::Color::BRIGHT_BLACK; break; - case 41: terminal_bg = VESA::Color::BRIGHT_RED; break; - case 42: terminal_bg = VESA::Color::BRIGHT_GREEN; break; - case 43: terminal_bg = VESA::Color::BRIGHT_YELLOW; break; - case 44: terminal_bg = VESA::Color::BRIGHT_BLUE; break; - case 45: terminal_bg = VESA::Color::BRIGHT_MAGENTA; break; - case 46: terminal_bg = VESA::Color::BRIGHT_CYAN; break; - case 47: terminal_bg = VESA::Color::BRIGHT_WHITE; break; - } - } - - static void handle_ansi_escape(uint16_t c) - { - switch (s_ansi_escape_mode) - { - case '\1': - { - if (c == CSI) - { - s_ansi_escape_mode = CSI; - return; - } - return reset_ansi_escape(); - } - - case CSI: - { - switch (c) - { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - { - int& val = s_ansi_escape_nums[s_ansi_escape_index]; - val = (val == -1) ? (c - '0') : (val * 10 + c - '0'); - return; - } - case ';': - s_ansi_escape_index++; - return; - case 'A': // Cursor Up - if (s_ansi_escape_nums[0] == -1) - s_ansi_escape_nums[0] = 1; - terminal_row = max(terminal_row - s_ansi_escape_nums[0], 0); - return reset_ansi_escape(); - case 'B': // Curson Down - if (s_ansi_escape_nums[0] == -1) - s_ansi_escape_nums[0] = 1; - terminal_row = min(terminal_row + s_ansi_escape_nums[0], terminal_height - 1); - return reset_ansi_escape(); - case 'C': // Cursor Forward - if (s_ansi_escape_nums[0] == -1) - s_ansi_escape_nums[0] = 1; - terminal_col = min(terminal_col + s_ansi_escape_nums[0], terminal_width - 1); - return reset_ansi_escape(); - case 'D': // Cursor Back - if (s_ansi_escape_nums[0] == -1) - s_ansi_escape_nums[0] = 1; - terminal_col = max(terminal_col - s_ansi_escape_nums[0], 0); - return reset_ansi_escape(); - case 'E': // Cursor Next Line - if (s_ansi_escape_nums[0] == -1) - s_ansi_escape_nums[0] = 1; - terminal_row = min(terminal_row + s_ansi_escape_nums[0], terminal_height - 1); - terminal_col = 0; - return reset_ansi_escape(); - case 'F': // Cursor Previous Line - if (s_ansi_escape_nums[0] == -1) - s_ansi_escape_nums[0] = 1; - terminal_row = max(terminal_row - s_ansi_escape_nums[0], 0); - terminal_col = 0; - return reset_ansi_escape(); - case 'G': // Cursor Horizontal Absolute - if (s_ansi_escape_nums[0] == -1) - s_ansi_escape_nums[0] = 1; - terminal_col = clamp(s_ansi_escape_nums[0] - 1, 0, terminal_width - 1); - return reset_ansi_escape(); - case 'H': // Cursor Position - if (s_ansi_escape_nums[0] == -1) - s_ansi_escape_nums[0] = 1; - if (s_ansi_escape_nums[1] == -1) - s_ansi_escape_nums[1] = 1; - terminal_row = clamp(s_ansi_escape_nums[0] - 1, 0, terminal_height - 1); - terminal_col = clamp(s_ansi_escape_nums[1] - 1, 0, terminal_width - 1); - return reset_ansi_escape(); - case 'J': // Erase in Display - dprintln("Unsupported ANSI CSI character J"); - return reset_ansi_escape(); - case 'K': // Erase in Line - switch (s_ansi_escape_nums[0]) - { - case -1: case 0: - for (size_t i = terminal_col; i < terminal_width; i++) - VESA::PutEntryAt(' ', i, terminal_row, terminal_fg, terminal_bg); - break; - case 1: - for (size_t i = 0; i <= terminal_col; i++) - VESA::PutEntryAt(' ', i, terminal_row, terminal_fg, terminal_bg); - break; - case 2: - for (size_t i = 0; i < terminal_width; i++) - VESA::PutEntryAt(' ', i, terminal_row, terminal_fg, terminal_bg); - break; - } - return reset_ansi_escape(); - case 'S': // Scroll Up - dprintln("Unsupported ANSI CSI character S"); - return reset_ansi_escape(); - case 'T': // Scroll Down - dprintln("Unsupported ANSI CSI character T"); - return reset_ansi_escape(); - case 'f': // Horizontal Vertical Position - dprintln("Unsupported ANSI CSI character f"); - return reset_ansi_escape(); - case 'm': - handle_ansi_SGR(); - return reset_ansi_escape(); - default: - dprintln("Unsupported ANSI CSI character {}", c); - return reset_ansi_escape(); - } - } - - default: - dprintln("Unsupported ANSI mode"); - return reset_ansi_escape(); - } - } - - void putchar(char _c) - { - uint16_t cp = handle_unicode(_c); - if (cp == 0xFFFF) - return; - - if (s_ansi_escape_mode) - return handle_ansi_escape(cp); - - // https://en.wikipedia.org/wiki/ANSI_escape_code - switch (cp) - { - case BEL: // TODO - break; - case BS: - if (terminal_col > 0) - terminal_col--; - break; - case HT: - terminal_col++; - while (terminal_col % 8) - terminal_col++; - break; - case LF: - terminal_col = 0; - terminal_row++; - break; - case FF: - terminal_row++; - break; - case CR: - terminal_col = 0; - break; - case ESC: - s_ansi_escape_mode = '\1'; - break; - default: - VESA::PutEntryAt(cp, terminal_col, terminal_row, terminal_fg, terminal_bg); - terminal_col++; - break; - } - - if (terminal_col >= terminal_width) - { - terminal_col = 0; - terminal_row++; - } - - while (terminal_row >= terminal_height) - { - VESA::Scroll(); - clear_line(terminal_height - 1); - - terminal_col = 0; - terminal_row--; - } - - update_cursor(); - } - - void write(const char* data, size_t size) - { - for (size_t i = 0; i < size; i++) - putchar(data[i]); - } - - void writestring(const char* data) - { - while (*data) - { - putchar(*data); - data++; - } - } - -} \ No newline at end of file diff --git a/kernel/include/kernel/Shell.h b/kernel/include/kernel/Shell.h index 6b24c7d1..79a6f194 100644 --- a/kernel/include/kernel/Shell.h +++ b/kernel/include/kernel/Shell.h @@ -2,6 +2,7 @@ #include #include +#include namespace Kernel { @@ -13,6 +14,8 @@ namespace Kernel static Shell& Get(); + void SetTTY(TTY* tty); + void Run(); private: @@ -22,7 +25,8 @@ namespace Kernel void KeyEventCallback(Keyboard::KeyEvent); private: - BAN::String m_buffer; + TTY* m_tty; + BAN::String m_buffer; }; } \ No newline at end of file diff --git a/kernel/include/kernel/TTY.h b/kernel/include/kernel/TTY.h new file mode 100644 index 00000000..413b40d7 --- /dev/null +++ b/kernel/include/kernel/TTY.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include + +class TTY +{ +public: + TTY(); + void Clear(); + void PutChar(char ch); + void Write(const char* data, size_t size); + void WriteString(const char* data); + void SetCursorPos(int x, int y); + + static void PutCharCurrent(char ch); + +private: + void ResetAnsiEscape(); + void HandleAnsiSGR(); + void HandleAnsiEscape(uint16_t ch); + +private: + struct Cell + { + VESA::Color foreground = VESA::Color::BRIGHT_WHITE; + VESA::Color background = VESA::Color::BLACK; + uint8_t character = ' '; + }; + + struct AnsiState + { + uint8_t mode = '\0'; + int32_t index = 0; + int32_t nums[2] = { -1, -1 }; + }; + + uint32_t m_width { 0 }; + uint32_t m_height { 0 }; + uint32_t m_row { 0 }; + uint32_t m_column { 0 }; + VESA::Color m_foreground { VESA::Color::BRIGHT_WHITE}; + VESA::Color m_background { VESA::Color::BLACK }; + Cell* m_buffer { nullptr }; + AnsiState m_ansi_state; +}; diff --git a/kernel/include/kernel/VESA.h b/kernel/include/kernel/VESA.h index 686580d8..11325d6a 100644 --- a/kernel/include/kernel/VESA.h +++ b/kernel/include/kernel/VESA.h @@ -25,8 +25,7 @@ namespace VESA BRIGHT_WHITE = 15, }; - bool PreInitialize(); - void Initialize(); + bool Initialize(); void PutEntryAt(uint16_t, uint32_t, uint32_t, Color, Color); void Clear(Color); void Scroll(); diff --git a/kernel/include/kernel/kprint.h b/kernel/include/kernel/kprint.h index f73583f8..a44c020e 100644 --- a/kernel/include/kernel/kprint.h +++ b/kernel/include/kernel/kprint.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include -#define kprint(...) BAN::Formatter::print(__VA_ARGS__) -#define kprintln(...) BAN::Formatter::println(__VA_ARGS__) +#define kprint(...) BAN::Formatter::print(__VA_ARGS__) +#define kprintln(...) BAN::Formatter::println(__VA_ARGS__) diff --git a/kernel/include/kernel/tty.h b/kernel/include/kernel/tty.h deleted file mode 100644 index b9a56d6b..00000000 --- a/kernel/include/kernel/tty.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -namespace TTY -{ - - void initialize(); - void putchar(char c); - void clear(); - void write(const char* data, size_t size); - void writestring(const char* data); - void set_cursor_pos(int x, int y); - -} \ No newline at end of file diff --git a/kernel/kernel/Shell.cpp b/kernel/kernel/Shell.cpp index b6978314..6673b47c 100644 --- a/kernel/kernel/Shell.cpp +++ b/kernel/kernel/Shell.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include namespace Kernel { @@ -32,6 +32,11 @@ namespace Kernel kprint("\e[32muser\e[m# "); } + void Shell::SetTTY(TTY* tty) + { + m_tty = tty; + } + void Shell::Run() { PrintPrompt(); @@ -78,8 +83,8 @@ namespace Kernel kprintln("'clear' does not support command line arguments"); return; } - TTY::clear(); - TTY::set_cursor_pos(0, 0); + m_tty->Clear(); + m_tty->SetCursorPos(0, 0); return; } diff --git a/kernel/kernel/kernel.cpp b/kernel/kernel/kernel.cpp index fce1fe42..99b9bf25 100644 --- a/kernel/kernel/kernel.cpp +++ b/kernel/kernel/kernel.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #define DISABLE_INTERRUPTS() asm volatile("cli") @@ -52,16 +52,14 @@ extern "C" void kernel_main(multiboot_info_t* mbi, uint32_t magic) s_multiboot_info = mbi; - if (!VESA::PreInitialize()) + if (!VESA::Initialize()) { dprintln("Could not initialize VESA"); return; } - TTY::initialize(); - kmalloc_initialize(); - VESA::Initialize(); + TTY* tty1 = new TTY; ParsedCommandLine cmdline; if (mbi->flags & 0x02) @@ -80,7 +78,7 @@ extern "C" void kernel_main(multiboot_info_t* mbi, uint32_t magic) kprintln("Hello from the kernel!"); auto& shell = Kernel::Shell::Get(); - + shell.SetTTY(tty1); shell.Run(); for (;;)