From fc8836858207a10d2a431b01b67befab9d7a002a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 Oct 2018 22:11:46 +0200 Subject: [PATCH] Have Console::write() directly call vga_putch. --- Kernel/Console.cpp | 10 ++++++---- Kernel/Console.h | 2 ++ Kernel/VGA.cpp | 25 +++++++------------------ Kernel/VGA.h | 1 + Kernel/init.cpp | 3 ++- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Kernel/Console.cpp b/Kernel/Console.cpp index 5e4239f1722..22fc41754ba 100644 --- a/Kernel/Console.cpp +++ b/Kernel/Console.cpp @@ -25,16 +25,18 @@ ssize_t Console::read(byte* buffer, size_t bufferSize) return 0; } -extern int kprintfFromConsole(const char*, ...); +void Console::putChar(char ch) +{ + vga_putch(nullptr, ch); +} ssize_t Console::write(const byte* data, size_t size) { if (!size) return 0; - for (size_t i = 0; i < size; ++i) { - kprintfFromConsole("%c", data[i]); - } + for (size_t i = 0; i < size; ++i) + putChar(data[i]); return 0; } diff --git a/Kernel/Console.h b/Kernel/Console.h index 51b41839dd0..1eca381d2be 100644 --- a/Kernel/Console.h +++ b/Kernel/Console.h @@ -13,6 +13,8 @@ public: virtual ssize_t write(const byte* data, size_t size) override; private: + void putChar(char); + byte m_rows { 25 }; byte m_columns { 80 }; byte m_cursorRow { 0 }; diff --git a/Kernel/VGA.cpp b/Kernel/VGA.cpp index bb9cb49b4b0..9dffa336c98 100644 --- a/Kernel/VGA.cpp +++ b/Kernel/VGA.cpp @@ -10,8 +10,6 @@ PRIVATE BYTE *vga_mem = 0L; PRIVATE BYTE current_attr = 0x07; -PRIVATE volatile WORD soft_cursor; - template static int printNumber(PutChFunc, char*&, DWORD); template static int printHex(PutChFunc, char*&, DWORD, BYTE fields); template static int printSignedNumber(PutChFunc, char*&, int); @@ -21,20 +19,22 @@ static void console_putch(char*, char ch) Console::the().write((byte*)&ch, 1); } -static void vga_putch(char*, char ch) +void vga_putch(char*, char ch) { + WORD soft_cursor = vga_get_cursor(); WORD row; switch (ch) { case '\n': row = soft_cursor / 80; if (row == 23) { - memcpy( vga_mem, vga_mem + 160, 160 * 23 ); - memset( vga_mem + (160 * 23), 0, 160 ); + memcpy(vga_mem, vga_mem + 160, 160 * 23); + memset(vga_mem + (160 * 23), 0, 160); soft_cursor = row * 80; } else { soft_cursor = (row + 1) * 80; } + vga_set_cursor(soft_cursor); return; default: vga_mem[soft_cursor * 2] = ch; @@ -47,6 +47,8 @@ static void vga_putch(char*, char ch) memset(vga_mem + (160 * 23), 0, 160); soft_cursor = 23 * 80; } + + vga_set_cursor(soft_cursor); } template @@ -54,8 +56,6 @@ int kprintfInternal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap) { const char *p; - soft_cursor = vga_get_cursor(); - int ret = 0; char* bufptr = buffer; @@ -134,17 +134,6 @@ int kprintf(const char* fmt, ...) return ret; } -int kprintfFromConsole(const char* fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - soft_cursor = vga_get_cursor(); - int ret = kprintfInternal(vga_putch, nullptr, fmt, ap); - vga_set_cursor(soft_cursor); - va_end(ap); - return ret; -} - static void buffer_putch(char*& bufptr, char ch) { *bufptr++ = ch; diff --git a/Kernel/VGA.h b/Kernel/VGA.h index 7d5ff358f4e..c7816d05b09 100644 --- a/Kernel/VGA.h +++ b/Kernel/VGA.h @@ -8,6 +8,7 @@ void vga_set_attr(BYTE); void vga_set_cursor(WORD); void vga_set_cursor(BYTE row, BYTE column); WORD vga_get_cursor(); +void vga_putch(char*, char); int kprintf(const char *fmt, ...); int ksprintf(char* buf, const char *fmt, ...); diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 1e96ef12c30..297376c554e 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -26,6 +26,7 @@ #include #include "Console.h" +//#define TEST_VFS //#define TEST_ELF_LOADER //#define TEST_CRASHY_USER_PROCESSES @@ -163,7 +164,7 @@ void init() Disk::initialize(); -#if CHECK_VFS +#ifdef TEST_VFS auto vfs = make(); auto dev_zero = make();