diff options
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 9 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/vga/io.hpp (renamed from arch/x86_64/include/arch/video/vga/io.hpp) | 12 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/vga/text.hpp (renamed from arch/x86_64/include/arch/video/vga/text.hpp) | 16 | ||||
| -rw-r--r-- | arch/x86_64/src/io.cpp | 28 | ||||
| -rw-r--r-- | arch/x86_64/src/vga/text.cpp | 66 | ||||
| -rw-r--r-- | arch/x86_64/src/video/vga/text.cpp | 66 | ||||
| -rw-r--r-- | kern/src/main.cpp | 3 |
7 files changed, 108 insertions, 92 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index dd54b39..86c9559 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -7,6 +7,7 @@ target_include_directories("arch-x86_64" PUBLIC target_link_libraries("arch-x86_64" PUBLIC "arch::any" + "os::kern" "libs::multiboot2" ) @@ -39,6 +40,14 @@ target_sources("arch-x86_64" PRIVATE "src/boot/multiboot.s" ) +#[============================================================================[ +# VGA Code +#]============================================================================] + +target_sources("arch-x86_64" PRIVATE + "src/vga/text.cpp" +) + # #[============================================================================[ # # The Kernel Library # #]============================================================================] diff --git a/arch/x86_64/include/arch/video/vga/io.hpp b/arch/x86_64/include/x86_64/vga/io.hpp index c399fad..803dc21 100644 --- a/arch/x86_64/include/arch/video/vga/io.hpp +++ b/arch/x86_64/include/x86_64/vga/io.hpp @@ -1,11 +1,11 @@ -#ifndef TEACHOS_ARCH_X86_64_VIDEO_VGA_IO_HPP -#define TEACHOS_ARCH_X86_64_VIDEO_VGA_IO_HPP +#ifndef TEACHOS_X86_64_VGA_IO_HPP +#define TEACHOS_X86_64_VGA_IO_HPP #include "arch/io/port_io.hpp" #include <cstddef> -namespace teachos::arch::video::vga +namespace teachos::x86_64::vga::io { namespace crtc { @@ -29,11 +29,11 @@ namespace teachos::arch::video::vga /** * @brief The address of the Cursor End register of the CRTC. */ - [[maybe_unused]] auto constexpr curser_end = std::byte{0x0b}; + [[maybe_unused]] auto constexpr cursor_end = std::byte{0x0b}; } // namespace registers }; // namespace crtc -} // namespace teachos::arch::video::vga +} // namespace teachos::x86_64::vga::io -#endif // TEACHOS_ARCH_X86_64_VIDEO_VGA_IO_HPP +#endif
\ No newline at end of file diff --git a/arch/x86_64/include/arch/video/vga/text.hpp b/arch/x86_64/include/x86_64/vga/text.hpp index cfbf98f..267eae9 100644 --- a/arch/x86_64/include/arch/video/vga/text.hpp +++ b/arch/x86_64/include/x86_64/vga/text.hpp @@ -1,14 +1,12 @@ -#ifndef TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP -#define TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP +#ifndef TEACHOS_X86_64_VIDEO_VGA_TEXT_HPP +#define TEACHOS_X86_64_VIDEO_VGA_TEXT_HPP #include <cstdint> #include <string_view> #include <type_traits> -namespace teachos::arch::video::vga::text +namespace teachos::x86_64::vga::text { - auto constexpr DEFAULT_VGA_TEXT_BUFFER_ADDRESS = 0xB8000; - /** * @brief The colors available in the standard VGA text mode. */ @@ -79,6 +77,12 @@ namespace teachos::arch::video::vga::text attribute{color::green, foreground_flag::none, color::black, background_flag::none}; /** + * @brief Make the affected cell display with a green foreground and black background. + */ + [[maybe_unused]] auto constexpr red_on_black = + attribute{color::red, foreground_flag::none, color::black, background_flag::none}; + + /** * @brief Make the affected cell display with a white (gray + intense) foreground and red background. */ [[maybe_unused]] auto constexpr white_on_red = @@ -164,6 +168,6 @@ namespace teachos::arch::video::vga::text } } -} // namespace teachos::arch::video::vga::text +} // namespace teachos::x86_64::vga::text #endif // TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP
\ No newline at end of file diff --git a/arch/x86_64/src/io.cpp b/arch/x86_64/src/io.cpp index 8808dbb..5fb1c85 100644 --- a/arch/x86_64/src/io.cpp +++ b/arch/x86_64/src/io.cpp @@ -1,22 +1,22 @@ +#include "kern/print.hpp" +#include "x86_64/vga/text.hpp" + namespace teachos::arch::io { - // using x86_64::vga::text_mode::attributes; - // using x86_64::vga::text_mode::color; - - // namespace - // { - // auto constexpr error_attributes = - // attributes{.foreground = color::light_gray, .bright = true, .background = color::red, .blink = true}; - // } // namespace - auto init() -> void { - // kernel::set_print_handler([](auto text) { return x86_64::vga::text_mode::print(text); }); - // kernel::set_println_handler([](auto text) { return x86_64::vga::text_mode::println(text); }); - // kernel::set_print_error_handler([](auto text) { return x86_64::vga::text_mode::print(text, error_attributes); }); - // kernel::set_println_error_handler( - // [](auto text) { return x86_64::vga::text_mode::println(text, error_attributes); }); + teachos::set_print_handler( + [](auto text) { return x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); }); + teachos::set_println_handler( + [](auto text) { return x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::green_on_black); }); + + teachos::set_print_error_handler( + [](auto text) { return x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); }); + teachos::set_println_error_handler( + [](auto text) { return x86_64::vga::text::write(text, x86_64::vga::text::common_attributes::red_on_black); }); + + teachos::println("[x86-64] Basic VGA text output initialized."); } } // namespace teachos::arch::io diff --git a/arch/x86_64/src/vga/text.cpp b/arch/x86_64/src/vga/text.cpp new file mode 100644 index 0000000..9b7946d --- /dev/null +++ b/arch/x86_64/src/vga/text.cpp @@ -0,0 +1,66 @@ +#include "x86_64/vga/text.hpp" + +#include "arch/asm_pointer.hpp" +#include "x86_64/vga/io.hpp" + +#include <algorithm> +#include <cstddef> +#include <string_view> +#include <utility> + +extern "C" teachos::arch::asm_pointer<std::pair<char, teachos::x86_64::vga::text::attribute>> vga_buffer_pointer; + +namespace teachos::x86_64::vga::text +{ + namespace + { + // auto constexpr DEFAULT_VGA_TEXT_BUFFER_ADDRESS = 0xB8000; + + auto buffer_offset = std::ptrdiff_t{}; + + auto constexpr DEFAULT_TEXT_BUFFER_WIDTH = 80U; + auto constexpr DEFAULT_TEXT_BUFFER_HEIGHT = 25U; + } // namespace + + auto clear(attribute attribute) -> void + { + buffer_offset = 0; + std::ranges::fill_n(vga_buffer_pointer.get(), 2000, std::pair{' ', attribute}); + } + + auto cursor(bool enabled) -> void + { + auto cursor_disable_byte = std::byte{!enabled} << 5; + + io::crtc::address_port::write(io::crtc::registers::cursor_start); + io::crtc::data_port::write(io::crtc::data_port::read() | cursor_disable_byte); + } + + auto newline() -> void + { + auto current_line = buffer_offset / DEFAULT_TEXT_BUFFER_WIDTH; + auto next_line = current_line + 1; + + if (next_line >= DEFAULT_TEXT_BUFFER_HEIGHT) + { + auto begin = vga_buffer_pointer + DEFAULT_TEXT_BUFFER_WIDTH; + auto end = vga_buffer_pointer + DEFAULT_TEXT_BUFFER_WIDTH * DEFAULT_TEXT_BUFFER_HEIGHT; + std::ranges::move(begin, end, vga_buffer_pointer.get()); + buffer_offset = current_line * DEFAULT_TEXT_BUFFER_WIDTH; + } + else + { + buffer_offset = next_line * DEFAULT_TEXT_BUFFER_WIDTH; + } + } + + auto write_char(char code_point, attribute attribute) -> void + { + vga_buffer_pointer[buffer_offset++] = std::pair{code_point, attribute}; + }; + + auto write(std::string_view code_points, attribute attribute) -> void + { + std::ranges::for_each(code_points, [&](auto code_point) { write_char(code_point, attribute); }); + } +} // namespace teachos::x86_64::vga::text diff --git a/arch/x86_64/src/video/vga/text.cpp b/arch/x86_64/src/video/vga/text.cpp deleted file mode 100644 index b070a0a..0000000 --- a/arch/x86_64/src/video/vga/text.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "arch/video/vga/text.hpp" - -#include "arch/video/vga/io.hpp" -#include "memory/asm_pointer.hpp" - -#include <algorithm> -#include <string_view> -#include <utility> - -extern "C" std::pair<char, teachos::arch::video::vga::text::attribute> * vga_buffer_pointer; - -namespace teachos::arch::video::vga::text -{ - namespace - { - auto constexpr DEFAULT_TEXT_BUFFER_WIDTH = 80U; - auto constexpr DEFAULT_TEXT_BUFFER_HEIGHT = 25U; - - auto constinit text_buffer = teachos::memory::asm_pointer{vga_buffer_pointer}; - } // namespace - - auto clear(attribute attribute) -> void - { - *text_buffer = reinterpret_cast<decltype(text_buffer)::pointer>(DEFAULT_VGA_TEXT_BUFFER_ADDRESS); - std::ranges::fill_n(*text_buffer, 2000, std::pair{' ', attribute}); - } - - auto cursor(bool enabled) -> void - { - auto cursor_disable_byte = std::byte{!enabled} << 5; - - crtc::address_port::write(crtc::registers::cursor_start); - crtc::data_port::write(vga::crtc::data_port::read() | cursor_disable_byte); - } - - auto newline() -> void - { - auto base = reinterpret_cast<decltype(text_buffer)::pointer>(DEFAULT_VGA_TEXT_BUFFER_ADDRESS); - auto & raw_buffer = *text_buffer; - auto current_line = (raw_buffer - base) / DEFAULT_TEXT_BUFFER_WIDTH; - auto next_line = current_line + 1; - - if (next_line >= DEFAULT_TEXT_BUFFER_HEIGHT) - { - auto begin = base + DEFAULT_TEXT_BUFFER_WIDTH; - auto end = base + DEFAULT_TEXT_BUFFER_WIDTH * DEFAULT_TEXT_BUFFER_HEIGHT; - std::ranges::move(begin, end, base); - raw_buffer = base + current_line * DEFAULT_TEXT_BUFFER_WIDTH; - } - else - { - raw_buffer = base + next_line * DEFAULT_TEXT_BUFFER_WIDTH; - } - } - - auto write_char(char code_point, attribute attribute) -> void - { - auto & p = *text_buffer; - (*p++) = std::pair{code_point, attribute}; - }; - - auto write(std::string_view code_points, attribute attribute) -> void - { - std::ranges::for_each(code_points, [&](auto code_point) { write_char(code_point, attribute); }); - } -} // namespace teachos::arch::video::vga::text diff --git a/kern/src/main.cpp b/kern/src/main.cpp index 5e1b6ea..b99fb37 100644 --- a/kern/src/main.cpp +++ b/kern/src/main.cpp @@ -1,10 +1,13 @@ #include "arch/io.hpp" #include "arch/memory.hpp" #include "kern/error.hpp" +#include "kern/print.hpp" auto main() -> int { teachos::arch::io::init(); + teachos::println("[OS] IO subsystem initialized."); + teachos::arch::memory::init(); teachos::panic("Architecture specific main returned!"); |
