Compare commits

..

No commits in common. "9ff9d679e96598b42e9ccc63788245d73cefc6ea" and "9f4cb5c4dd5cd80fedd4d1ae47810d8fdba3ec91" have entirely different histories.

4 changed files with 86 additions and 98 deletions

View File

@ -30,7 +30,6 @@ namespace Kernel
{} {}
BAN::ErrorOr<void> initialize(); BAN::ErrorOr<void> initialize();
void move_cursor_impl(uint32_t x, uint32_t y);
private: private:
const paddr_t m_paddr; const paddr_t m_paddr;
@ -38,10 +37,6 @@ namespace Kernel
const uint32_t m_height; const uint32_t m_height;
const uint32_t m_pitch; const uint32_t m_pitch;
vaddr_t m_vaddr { 0 }; vaddr_t m_vaddr { 0 };
uint32_t m_cursor_x { 0 };
uint32_t m_cursor_y { 0 };
bool m_cursor_shown { true };
static constexpr Color s_cursor_color = TerminalColor::WHITE; static constexpr Color s_cursor_color = TerminalColor::WHITE;
}; };

View File

@ -562,7 +562,7 @@ acpi_release_global_lock:
} }
// system must not execute after sleep registers are written // system must not execute after sleep registers are written
panic("ACPI shutdown failed. You can now safely shutdown your computer."); ASSERT_NOT_REACHED();
} }
BAN::ErrorOr<void> ACPI::reset() BAN::ErrorOr<void> ACPI::reset()

View File

@ -11,21 +11,20 @@ namespace Kernel
{ {
TerminalDriver::Palette palette; TerminalDriver::Palette palette;
palette[ 0] = 0x000000; palette[ 0] = 0x000000;
palette[ 1] = 0xAA0000; palette[ 1] = 0x0000AA;
palette[ 2] = 0x00AA00; palette[ 2] = 0x00AA00;
palette[ 3] = 0xAA5500; palette[ 3] = 0x00AAAA;
palette[ 4] = 0x0000AA; palette[ 4] = 0xAA0000;
palette[ 5] = 0xAA00AA; palette[ 5] = 0xAA00AA;
palette[ 6] = 0x00AAAA; palette[ 6] = 0xAA5500;
palette[ 7] = 0xAAAAAA; palette[ 7] = 0xAAAAAA;
palette[ 8] = 0x555555; palette[ 8] = 0x555555;
palette[ 9] = 0xFF5555; palette[ 9] = 0x5555FF;
palette[10] = 0x55FF55; palette[10] = 0x55FF55;
palette[11] = 0xFFFF55; palette[11] = 0x55FFFF;
palette[12] = 0x5555FF; palette[12] = 0xFF5555;
palette[13] = 0xFF55FF; palette[13] = 0xFF55FF;
palette[14] = 0x55FFFF; palette[14] = 0xFFFF55;
palette[15] = 0xFFFFFF; palette[15] = 0xFFFFFF;
return palette; return palette;
} }
@ -48,10 +47,7 @@ namespace Kernel
closest = i; closest = i;
} }
constexpr uint8_t terminal_to_text[16] { return closest;
0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15
};
return terminal_to_text[closest];
} }
BAN::ErrorOr<BAN::RefPtr<TextModeTerminalDriver>> TextModeTerminalDriver::create_from_boot_info() BAN::ErrorOr<BAN::RefPtr<TextModeTerminalDriver>> TextModeTerminalDriver::create_from_boot_info()
@ -122,11 +118,32 @@ namespace Kernel
{ {
for (uint32_t y = 0; y < m_height; y++) for (uint32_t y = 0; y < m_height; y++)
for (uint32_t x = 0; x < m_width; x++) for (uint32_t x = 0; x < m_width; x++)
putchar_at(' ', x, y, TerminalColor::WHITE, color); putchar_at(' ', x, y, color, color);
} }
void TextModeTerminalDriver::move_cursor_impl(uint32_t x, uint32_t y) void TextModeTerminalDriver::set_cursor_shown(bool shown)
{ {
if (shown)
{
IO::outb(0x3D4, 0x0A);
IO::outb(0x3D5, (IO::inb(0x3D5) & 0xC0) | 14);
IO::outb(0x3D4, 0x0B);
IO::outb(0x3D5, (IO::inb(0x3D5) & 0xE0) | 15);
}
else
{
IO::outb(0x3D4, 0x0A);
IO::outb(0x3D5, 0x20);
}
}
void TextModeTerminalDriver::set_cursor_position(uint32_t x, uint32_t y)
{
// NOTE: cursor is allowed to be on width as scrolling only
// happens after character gets printed to next line
if (x == m_width)
return;
const uint16_t pos = y * m_width + x; const uint16_t pos = y * m_width + x;
IO::outb(0x3D4, 0x0F); IO::outb(0x3D4, 0x0F);
IO::outb(0x3D5, pos & 0xFF); IO::outb(0x3D5, pos & 0xFF);
@ -134,32 +151,4 @@ namespace Kernel
IO::outb(0x3D5, pos >> 8); IO::outb(0x3D5, pos >> 8);
} }
void TextModeTerminalDriver::set_cursor_shown(bool shown)
{
if (m_cursor_shown == shown)
return;
m_cursor_shown = shown;
if (shown)
move_cursor_impl(m_cursor_x, m_cursor_y);
else
move_cursor_impl(0, m_height);
}
void TextModeTerminalDriver::set_cursor_position(uint32_t x, uint32_t y)
{
ASSERT(x <= m_width);
ASSERT(y < m_height);
m_cursor_x = x;
m_cursor_y = y;
if (!m_cursor_shown)
return;
if (x == m_width)
move_cursor_impl(0, m_height);
else
move_cursor_impl(x, y);
}
} }

View File

@ -282,39 +282,37 @@ char* strstr(const char* haystack, const char* needle)
return nullptr; return nullptr;
} }
#define CHAR_UCHAR(ch) \ size_t strcspn(const char* s1, const char* s2)
static_cast<unsigned char>(ch) {
size_t i = 0;
#define CHAR_BITMASK(str) \ for (; s1[i]; i++)
uint32_t bitmask[0x100 / 32] {}; \ for (size_t j = 0; s2[j]; j++)
for (size_t i = 0; str[i]; i++) \ if (s1[i] == s2[j])
bitmask[CHAR_UCHAR(str[i]) / 32] |= (1 << (CHAR_UCHAR(str[i]) % 32)) return i;
return i;
#define CHAR_BITMASK_TEST(ch) \ }
(bitmask[CHAR_UCHAR(ch) / 32] & (1 << (CHAR_UCHAR(ch) % 32)))
char* strpbrk(const char* s1, const char* s2) char* strpbrk(const char* s1, const char* s2)
{ {
CHAR_BITMASK(s2);
for (size_t i = 0; s1[i]; i++) for (size_t i = 0; s1[i]; i++)
if (CHAR_BITMASK_TEST(s1[i])) for (size_t j = 0; s2[j]; j++)
return const_cast<char*>(&s1[i]); if (s1[i] == s2[j])
return const_cast<char*>(s1 + i);
return nullptr; return nullptr;
} }
size_t strspn(const char* s1, const char* s2) size_t strspn(const char* s1, const char* s2)
{ {
CHAR_BITMASK(s2); size_t i = 0;
for (size_t i = 0;; i++) for (; s1[i]; i++)
if (s1[i] == '\0' || !CHAR_BITMASK_TEST(s1[i]))
return i;
}
size_t strcspn(const char* s1, const char* s2)
{ {
CHAR_BITMASK(s2); bool found = false;
for (size_t i = 0;; i++) for (size_t j = 0; s2[j] && !found; j++)
if (s1[i] == '\0' || CHAR_BITMASK_TEST(s1[i])) if (s1[i] == s2[j])
found = true;
if (!found)
break;
}
return i; return i;
} }
@ -326,43 +324,49 @@ char* strtok(char* __restrict s, const char* __restrict sep)
char* strtok_r(char* __restrict str, const char* __restrict sep, char** __restrict state) char* strtok_r(char* __restrict str, const char* __restrict sep, char** __restrict state)
{ {
CHAR_BITMASK(sep);
if (str) if (str)
*state = str; {
while (*str)
if (*state == nullptr) {
return nullptr; bool found = false;
for (size_t i = 0; sep[i] && !found; i++)
str = *state; if (*str == sep[i])
found = true;
for (; *str; str++) if (!found)
if (!CHAR_BITMASK_TEST(*str))
break; break;
str++;
}
if (*str == '\0') if (!*str)
{ {
*state = nullptr; *state = nullptr;
return nullptr; return nullptr;
} }
*state = str;
}
if (!*state)
return nullptr;
str = *state;
for (size_t i = 0; str[i]; i++) for (size_t i = 0; str[i]; i++)
{ {
if (!CHAR_BITMASK_TEST(str[i])) for (size_t j = 0; sep[j]; j++)
continue; {
if (str[i] == sep[j])
{
str[i] = '\0'; str[i] = '\0';
*state = str + i + 1; *state = str + i + 1;
return str; return str;
} }
}
}
*state = nullptr; *state = nullptr;
return str; return str;
} }
#undef CHAR_UCHAR
#undef CHAR_BITMASK
#undef CHAR_BITMASK_TEST
char* strsignal(int signum) char* strsignal(int signum)
{ {
static char buffer[128]; static char buffer[128];