diff options
| -rw-r--r-- | source/arch/x86_64/include/arch/boot/pointers.hpp | 1 | ||||
| -rw-r--r-- | source/arch/x86_64/include/arch/video/vga/text.hpp | 53 | ||||
| -rw-r--r-- | source/arch/x86_64/src/boot/boot.s | 6 | ||||
| -rw-r--r-- | source/arch/x86_64/src/kernel/main.cpp | 9 | ||||
| -rw-r--r-- | source/arch/x86_64/src/video/vga/text.cpp | 21 | ||||
| -rw-r--r-- | source/include/memory/asm_pointer.hpp | 2 |
6 files changed, 72 insertions, 20 deletions
diff --git a/source/arch/x86_64/include/arch/boot/pointers.hpp b/source/arch/x86_64/include/arch/boot/pointers.hpp index 052b115..dcd14fe 100644 --- a/source/arch/x86_64/include/arch/boot/pointers.hpp +++ b/source/arch/x86_64/include/arch/boot/pointers.hpp @@ -6,7 +6,6 @@ namespace teachos::arch::boot { extern "C" std::byte const multiboot_information_pointer; - extern "C" std::byte * vga_buffer_pointer; } // namespace teachos::arch::boot #endif
\ No newline at end of file diff --git a/source/arch/x86_64/include/arch/video/vga/text.hpp b/source/arch/x86_64/include/arch/video/vga/text.hpp index 04b74d1..c9a79b8 100644 --- a/source/arch/x86_64/include/arch/video/vga/text.hpp +++ b/source/arch/x86_64/include/arch/video/vga/text.hpp @@ -1,12 +1,59 @@ #ifndef TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP #define TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP -#include <cstddef> +#include <cstdint> #include <string_view> namespace teachos::arch::video::vga::text { - auto write(std::string_view text, std::byte color) -> void; -} + enum struct color : std::uint8_t + { + black, + blue, + green, + cyan, + red, + purple, + brown, + gray, + }; + + enum struct foreground_flag : bool + { + none, + intense, + }; + + enum struct background_flag : bool + { + none, + blink_or_bright, + }; + + struct attribute + { + color foreground_color : 3; + enum foreground_flag foreground_flag : 1; + color bacground_color : 3; + enum background_flag background_flag : 1; + }; + + static_assert(sizeof(attribute) == 1); + + namespace common_attributes + { + [[maybe_unused]] + auto constexpr gray_on_black = attribute{color::gray, foreground_flag::none, color::black, background_flag::none}; + + [[maybe_unused]] + auto constexpr green_on_black = attribute{color::green, foreground_flag::none, color::black, background_flag::none}; + + [[maybe_unused]] + auto constexpr white_on_red = attribute{color::gray, foreground_flag::intense, color::red, background_flag::none}; + } + + auto clear(attribute attribute = common_attributes::gray_on_black) -> void; + auto write(std::string_view code_points, attribute attribute) -> void; +} // namespace teachos::arch::video::vga::text #endif
\ No newline at end of file diff --git a/source/arch/x86_64/src/boot/boot.s b/source/arch/x86_64/src/boot/boot.s index 45f261e..7b4e193 100644 --- a/source/arch/x86_64/src/boot/boot.s +++ b/source/arch/x86_64/src/boot/boot.s @@ -362,11 +362,7 @@ _transition_to_long_mode: mov %rax, %fs mov %rax, %gs - /* Clear the screen */ - mov $0x0f200f200f200f20, %rax - mov $0x0b8000, %rdi - mov $500, %rcx - rep stosq + movl $0xb8000, (vga_buffer_pointer) call _init diff --git a/source/arch/x86_64/src/kernel/main.cpp b/source/arch/x86_64/src/kernel/main.cpp index 9ea756a..26ae730 100644 --- a/source/arch/x86_64/src/kernel/main.cpp +++ b/source/arch/x86_64/src/kernel/main.cpp @@ -6,10 +6,9 @@ namespace teachos::arch::kernel { auto main() -> void { - video::vga::text::write("TeachOS is starting up...", static_cast<std::byte>(0x4f)); - while (true) - { - asm volatile("hlt"); - } + using namespace video::vga; + + text::clear(); + text::write("TeachOS is starting up...", text::common_attributes::green_on_black); } } // namespace teachos::arch::kernel diff --git a/source/arch/x86_64/src/video/vga/text.cpp b/source/arch/x86_64/src/video/vga/text.cpp index 11e3b1a..df61ce6 100644 --- a/source/arch/x86_64/src/video/vga/text.cpp +++ b/source/arch/x86_64/src/video/vga/text.cpp @@ -5,25 +5,34 @@ #include <algorithm> #include <string_view> +#include <utility> namespace teachos::arch::video::vga::text { namespace { - auto constinit text_buffer = teachos::boot::asm_pointer{boot::vga_buffer_pointer}; + auto constexpr default_text_buffer_address = 0xb8000; - auto write(char character, std::byte color) -> void + extern "C" std::pair<char, attribute> * vga_buffer_pointer; + auto constinit text_buffer = teachos::boot::asm_pointer{vga_buffer_pointer}; + + auto write(char code_point, attribute attribute) -> void { auto & p = *text_buffer; - (*p++) = static_cast<std::byte>(character); - (*p++) = color; + (*p++) = std::pair{code_point, attribute}; }; } // namespace - auto write(std::string_view text, std::byte color) -> void + auto clear(attribute attribute) -> void + { + *text_buffer = reinterpret_cast<decltype(text_buffer)::pointer>(default_text_buffer_address); + std::ranges::generate_n(*text_buffer, 2000, [&]{ return std::pair{' ', attribute}; }); + } + + auto write(std::string_view code_points, attribute attribute) -> void { - std::ranges::for_each(text, [&](auto character) { write(character, color); }); + std::ranges::for_each(code_points, [&](auto code_point) { write(code_point, attribute); }); } } // namespace teachos::arch::video::vga::text
\ No newline at end of file diff --git a/source/include/memory/asm_pointer.hpp b/source/include/memory/asm_pointer.hpp index ec7141e..b2e890c 100644 --- a/source/include/memory/asm_pointer.hpp +++ b/source/include/memory/asm_pointer.hpp @@ -7,6 +7,8 @@ namespace teachos::boot template<typename Type> struct asm_pointer { + using pointer = Type; + constexpr asm_pointer(Type & pointer) : m_pointer{&pointer} { |
