Kernel: Shell now actually prints to its TTY

This commit is contained in:
Bananymous 2022-12-27 20:11:49 +02:00
parent f0fd62c703
commit 2a65c5fd0f
1 changed files with 27 additions and 24 deletions

View File

@ -9,6 +9,9 @@
#include <kernel/Serial.h> #include <kernel/Serial.h>
#include <kernel/TTY.h> #include <kernel/TTY.h>
#define TTY_PRINT(...) BAN::Formatter::print([this](char c) { m_tty->PutChar(c); }, __VA_ARGS__)
#define TTY_PRINTLN(...) BAN::Formatter::println([this](char c) { m_tty->PutChar(c); }, __VA_ARGS__)
namespace Kernel namespace Kernel
{ {
@ -29,7 +32,7 @@ namespace Kernel
void Shell::PrintPrompt() void Shell::PrintPrompt()
{ {
kprint("\e[32muser\e[m# "); TTY_PRINT("\e[32muser\e[m# ");
} }
void Shell::SetTTY(TTY* tty) void Shell::SetTTY(TTY* tty)
@ -56,11 +59,11 @@ namespace Kernel
{ {
if (arguments.Size() != 1) if (arguments.Size() != 1)
{ {
kprintln("'date' does not support command line arguments"); TTY_PRINTLN("'date' does not support command line arguments");
return; return;
} }
auto time = RTC::GetCurrentTime(); auto time = RTC::GetCurrentTime();
kprintln("{}", time); TTY_PRINTLN("{}", time);
return; return;
} }
@ -68,11 +71,11 @@ namespace Kernel
{ {
if (arguments.Size() > 1) if (arguments.Size() > 1)
{ {
kprint("{}", arguments[1]); TTY_PRINT("{}", arguments[1]);
for (size_t i = 2; i < arguments.Size(); i++) for (size_t i = 2; i < arguments.Size(); i++)
kprint(" {}", arguments[i]); TTY_PRINT(" {}", arguments[i]);
} }
kprintln(""); TTY_PRINTLN("");
return; return;
} }
@ -80,7 +83,7 @@ namespace Kernel
{ {
if (arguments.Size() != 1) if (arguments.Size() != 1)
{ {
kprintln("'clear' does not support command line arguments"); TTY_PRINTLN("'clear' does not support command line arguments");
return; return;
} }
m_tty->Clear(); m_tty->Clear();
@ -95,7 +98,7 @@ namespace Kernel
auto start = PIT::ms_since_boot(); auto start = PIT::ms_since_boot();
ProcessCommand(new_args); ProcessCommand(new_args);
auto duration = PIT::ms_since_boot() - start; auto duration = PIT::ms_since_boot() - start;
kprintln("took {} ms", duration); TTY_PRINTLN("took {} ms", duration);
return; return;
} }
@ -103,12 +106,12 @@ namespace Kernel
{ {
if (arguments.Size() != 1) if (arguments.Size() != 1)
{ {
kprintln("'cpuinfo' does not support command line arguments"); TTY_PRINTLN("'cpuinfo' does not support command line arguments");
return; return;
} }
if (!CPUID::IsAvailable()) if (!CPUID::IsAvailable())
{ {
kprintln("'cpuid' instruction not available"); TTY_PRINTLN("'cpuid' instruction not available");
return; return;
} }
@ -116,16 +119,16 @@ namespace Kernel
auto vendor = CPUID::GetVendor(); auto vendor = CPUID::GetVendor();
CPUID::GetFeatures(ecx, edx); CPUID::GetFeatures(ecx, edx);
kprintln("Vendor: '{}'", vendor); TTY_PRINTLN("Vendor: '{}'", vendor);
bool first = true; bool first = true;
for (int i = 0; i < 32; i++) for (int i = 0; i < 32; i++)
if (ecx & ((uint32_t)1 << i)) if (ecx & ((uint32_t)1 << i))
kprint("{}{}", first ? (first = false, "") : ", ", CPUID::FeatStringECX((uint32_t)1 << i)); TTY_PRINT("{}{}", first ? (first = false, "") : ", ", CPUID::FeatStringECX((uint32_t)1 << i));
for (int i = 0; i < 32; i++) for (int i = 0; i < 32; i++)
if (edx & ((uint32_t)1 << i)) if (edx & ((uint32_t)1 << i))
kprint("{}{}", first ? (first = false, "") : ", ", CPUID::FeatStringEDX((uint32_t)1 << i)); TTY_PRINT("{}{}", first ? (first = false, "") : ", ", CPUID::FeatStringEDX((uint32_t)1 << i));
if (!first) if (!first)
kprintln(""); TTY_PRINTLN("");
return; return;
} }
@ -134,19 +137,19 @@ namespace Kernel
{ {
if (arguments.Size() != 1) if (arguments.Size() != 1)
{ {
kprintln("'random' does not support command line arguments"); TTY_PRINTLN("'random' does not support command line arguments");
return; return;
} }
if (!CPUID::IsAvailable()) if (!CPUID::IsAvailable())
{ {
kprintln("'cpuid' instruction not available"); TTY_PRINTLN("'cpuid' instruction not available");
return; return;
} }
uint32_t ecx, edx; uint32_t ecx, edx;
CPUID::GetFeatures(ecx, edx); CPUID::GetFeatures(ecx, edx);
if (!(ecx & CPUID::Features::ECX_RDRND)) if (!(ecx & CPUID::Features::ECX_RDRND))
{ {
kprintln("cpu does not support RDRAND instruction"); TTY_PRINTLN("cpu does not support RDRAND instruction");
return; return;
} }
@ -154,7 +157,7 @@ namespace Kernel
{ {
uint32_t random; uint32_t random;
asm volatile("rdrand %0" : "=r"(random)); asm volatile("rdrand %0" : "=r"(random));
kprintln(" 0x{8H}", random); TTY_PRINTLN(" 0x{8H}", random);
} }
return; return;
@ -164,7 +167,7 @@ namespace Kernel
{ {
if (arguments.Size() != 1) if (arguments.Size() != 1)
{ {
kprintln("'reboot' does not support command line arguments"); TTY_PRINTLN("'reboot' does not support command line arguments");
return; return;
} }
uint8_t good = 0x02; uint8_t good = 0x02;
@ -175,7 +178,7 @@ namespace Kernel
return; return;
} }
kprintln("unrecognized command '{}'", arguments.Front()); TTY_PRINTLN("unrecognized command '{}'", arguments.Front());
} }
static bool IsSingleUnicode(BAN::StringView sv) static bool IsSingleUnicode(BAN::StringView sv)
@ -220,7 +223,7 @@ namespace Kernel
{ {
if (!m_buffer.Empty()) if (!m_buffer.Empty())
{ {
kprint("\b \b", 3); TTY_PRINT("\b \b", 3);
uint32_t last_len = GetLastLength(m_buffer); uint32_t last_len = GetLastLength(m_buffer);
for (uint32_t i = 0; i < last_len; i++) for (uint32_t i = 0; i < last_len; i++)
@ -232,7 +235,7 @@ namespace Kernel
case Keyboard::Key::Enter: case Keyboard::Key::Enter:
case Keyboard::Key::NumpadEnter: case Keyboard::Key::NumpadEnter:
{ {
kprint("\n"); TTY_PRINT("\n");
ProcessCommand(MUST(m_buffer.SV().Split(' '))); ProcessCommand(MUST(m_buffer.SV().Split(' ')));
m_buffer.Clear(); m_buffer.Clear();
PrintPrompt(); PrintPrompt();
@ -240,7 +243,7 @@ namespace Kernel
} }
case Keyboard::Key::Escape: case Keyboard::Key::Escape:
kprintln("time since boot {} ms", PIT::ms_since_boot()); TTY_PRINTLN("time since boot {} ms", PIT::ms_since_boot());
break; break;
case Keyboard::Key::Tab: case Keyboard::Key::Tab:
@ -251,7 +254,7 @@ namespace Kernel
const char* utf8 = Keyboard::key_event_to_utf8(event); const char* utf8 = Keyboard::key_event_to_utf8(event);
if (utf8) if (utf8)
{ {
kprint("{}", utf8); TTY_PRINT("{}", utf8);
m_buffer.Append(utf8); m_buffer.Append(utf8);
} }
break; break;