diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2023-10-07 17:15:31 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2023-10-07 17:15:31 +0200 |
| commit | ff81b5438f280a59ca1825bfdf120d8f256bd154 (patch) | |
| tree | 0a63ea3eb9fc28ca655c3ca3d1c70000d514aecd /source/kernel/arch/x86_64 | |
| parent | 7e785ff5a7a2e9c98fd1679e74a728f4babf722a (diff) | |
| download | teachos-ff81b5438f280a59ca1825bfdf120d8f256bd154.tar.xz teachos-ff81b5438f280a59ca1825bfdf120d8f256bd154.zip | |
x86_64: implement very simple VGA text output
Diffstat (limited to 'source/kernel/arch/x86_64')
| -rw-r--r-- | source/kernel/arch/x86_64/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | source/kernel/arch/x86_64/include/kernel/vga.hpp | 11 | ||||
| -rw-r--r-- | source/kernel/arch/x86_64/src/entry.cpp | 9 | ||||
| -rw-r--r-- | source/kernel/arch/x86_64/src/vga.cpp | 30 |
4 files changed, 46 insertions, 5 deletions
diff --git a/source/kernel/arch/x86_64/CMakeLists.txt b/source/kernel/arch/x86_64/CMakeLists.txt index 99fafe7..ffce50c 100644 --- a/source/kernel/arch/x86_64/CMakeLists.txt +++ b/source/kernel/arch/x86_64/CMakeLists.txt @@ -7,6 +7,7 @@ mark_as_advanced(TEACHOS_KERNEL_LINKER_SCRIPT) target_sources("kernel" PRIVATE "src/entry.cpp" + "src/vga.cpp" ) target_include_directories("kernel" PRIVATE diff --git a/source/kernel/arch/x86_64/include/kernel/vga.hpp b/source/kernel/arch/x86_64/include/kernel/vga.hpp new file mode 100644 index 0000000..ee5a808 --- /dev/null +++ b/source/kernel/arch/x86_64/include/kernel/vga.hpp @@ -0,0 +1,11 @@ +#ifndef TEACHOS_KERNEL_VGA_HPP +#define TEACHOS_KERNEL_VGA_HPP + +#include <string_view> + +namespace teachos::kernel::vga +{ + auto write(std::string_view text, std::byte color) -> void; +} + +#endif
\ No newline at end of file diff --git a/source/kernel/arch/x86_64/src/entry.cpp b/source/kernel/arch/x86_64/src/entry.cpp index 2d4e7fb..fd9d9d0 100644 --- a/source/kernel/arch/x86_64/src/entry.cpp +++ b/source/kernel/arch/x86_64/src/entry.cpp @@ -1,10 +1,9 @@ -namespace teachos +#include "kernel/vga.hpp" + +namespace teachos::kernel { extern "C" auto kernel_main() -> void { - while (true) - { - asm volatile("nop"); - } + vga::write("TeachOS is starting up...", static_cast<std::byte>(0x4f)); } } // namespace teachos diff --git a/source/kernel/arch/x86_64/src/vga.cpp b/source/kernel/arch/x86_64/src/vga.cpp new file mode 100644 index 0000000..d25eaa5 --- /dev/null +++ b/source/kernel/arch/x86_64/src/vga.cpp @@ -0,0 +1,30 @@ +#include "kernel/vga.hpp" + +#include "boot/asm_pointer.hpp" +#include "boot/pointers.hpp" + +#include <string_view> +#include <algorithm> + +namespace teachos::kernel::vga +{ + + namespace + { + auto constinit text_buffer_pointer = boot::asm_pointer{boot::vga_buffer_pointer}; + + auto write(char character, std::byte color) -> void + { + auto & p = *text_buffer_pointer; + (*p++) = static_cast<std::byte>(character); + (*p++) = color; + }; + } // namespace + + auto write(std::string_view text, std::byte color) -> void { + std::ranges::for_each(text, [&](auto character) { + write(character, color); + }); + } + +} // namespace teachos::kernel
\ No newline at end of file |
