aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2024-09-16 14:07:41 +0000
committerFelix Morgner <felix.morgner@ost.ch>2024-09-17 08:58:55 +0200
commit8f9b9cd8aac30572b7e275bbeb1b32d2cbb8950a (patch)
tree5e215dd93c34b3d58c287b036ad2d190e0a9a772 /arch/x86_64/include
parentc16a3739649fa15178df667d610553e93db83e4c (diff)
downloadteachos-8f9b9cd8aac30572b7e275bbeb1b32d2cbb8950a.tar.xz
teachos-8f9b9cd8aac30572b7e275bbeb1b32d2cbb8950a.zip
build: migrate away from conan
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/boot/pointers.hpp11
-rw-r--r--arch/x86_64/include/arch/io/port_io.hpp134
-rw-r--r--arch/x86_64/include/arch/kernel/main.hpp11
-rw-r--r--arch/x86_64/include/arch/video/vga/io.hpp41
-rw-r--r--arch/x86_64/include/arch/video/vga/text.hpp113
5 files changed, 310 insertions, 0 deletions
diff --git a/arch/x86_64/include/arch/boot/pointers.hpp b/arch/x86_64/include/arch/boot/pointers.hpp
new file mode 100644
index 0000000..dcd14fe
--- /dev/null
+++ b/arch/x86_64/include/arch/boot/pointers.hpp
@@ -0,0 +1,11 @@
+#ifndef TEACHOS_ARCH_X86_64_BOOT_POINTERS_HPP
+#define TEACHOS_ARCH_X86_64_BOOT_POINTERS_HPP
+
+#include <cstddef>
+
+namespace teachos::arch::boot
+{
+ extern "C" std::byte const multiboot_information_pointer;
+} // namespace teachos::arch::boot
+
+#endif \ No newline at end of file
diff --git a/arch/x86_64/include/arch/io/port_io.hpp b/arch/x86_64/include/arch/io/port_io.hpp
new file mode 100644
index 0000000..5b61f90
--- /dev/null
+++ b/arch/x86_64/include/arch/io/port_io.hpp
@@ -0,0 +1,134 @@
+#ifndef TEACHOS_ARCH_X86_64_IO_PORT_IO_HPP
+#define TEACHOS_ARCH_X86_64_IO_PORT_IO_HPP
+
+#include <concepts>
+#include <cstddef>
+#include <cstdint>
+#include <type_traits>
+
+namespace teachos::arch::io
+{
+
+ /**
+ * @brief An I/O port of a given size at a given address.
+ *
+ * @tparam Address The address (port number) of the I/O port.
+ * @tparam Size The size (in bytes) of the I/O port.
+ */
+ template<std::uint16_t Address, std::size_t Size>
+ struct port
+ {
+ static_assert(Size == 1 || Size == 2 || Size == 4, "A port must be either 1, 2, or 4 bytes in size");
+
+ /**
+ * @brief The type of data available for reading and writing through this port.
+ */
+ using io_type =
+ std::conditional_t<Size == 1, std::byte, std::conditional_t<Size == 2, std::uint16_t, std::uint32_t>>;
+
+ /**
+ * @brief Write a byte to the I/O port.
+ *
+ * @param data The data to write to the I/O port.
+ */
+ auto static write(io_type data) -> void
+ requires(Size == 1)
+ {
+ asm volatile("mov %[port], %%dx\n"
+ "mov %[data], %%al\n"
+ "out %%al, %%dx\n"
+ :
+ : [port] "i"(Address), [data] "im"(data)
+ : "dx", "al");
+ }
+
+ /**
+ * @brief Write a word to the I/O port.
+ *
+ * @param data The data to write to the I/O port.
+ */
+ auto static write(io_type data) -> void
+ requires(Size == 2)
+ {
+ asm volatile("mov %[port], %%dx\n"
+ "mov %[data], %%ax\n"
+ "out %%ax, %%dx\n"
+ :
+ : [port] "i"(Address), [data] "im"(data)
+ : "dx", "ax");
+ }
+
+ /**
+ * @brief Write a double-word to the I/O port.
+ *
+ * @param data The data to write to the I/O port.
+ */
+ auto static write(io_type data) -> void
+ requires(Size == 4)
+ {
+ asm volatile("mov %[port], %%dx\n"
+ "mov %[data], %%eax\n"
+ "out %%eax, %%dx\n"
+ :
+ : [port] "i"(Address), [data] "im"(data)
+ : "dx", "eax");
+ }
+
+ /**
+ * @brief Read a byte from the I/O port.
+ *
+ * @return The data read from the I/O port.
+ */
+ auto static read() -> io_type
+ requires(Size == 1)
+ {
+ auto data = io_type{};
+ asm volatile("mov %[port], %%dx\n"
+ "in %%dx, %%al\n"
+ "mov %%al, %[data]\n"
+ : [data] "=m"(data)
+ : [port] "i"(Address)
+ : "dx", "al");
+ return data;
+ }
+
+ /**
+ * @brief Read a word from the I/O port.
+ *
+ * @return The data read from the I/O port.
+ */
+ auto static read() -> io_type
+ requires(Size == 2)
+ {
+ auto data = io_type{};
+ asm volatile("mov %[port], %%dx\n"
+ "in %%dx, %%ax\n"
+ "mov %%ax, %[data]\n"
+ : [data] "=m"(data)
+ : [port] "i"(Address)
+ : "dx", "ax");
+ return data;
+ }
+
+ /**
+ * @brief Read a double-word from the I/O port.
+ *
+ * @return The data read from the I/O port.
+ */
+ auto static read() -> io_type
+ requires(Size == 4)
+ {
+ auto data = io_type{};
+ asm volatile("mov %[port], %%dx\n"
+ "in %%dx, %%eax\n"
+ "mov %%eax, %[data]\n"
+ : [data] "=m"(data)
+ : [port] "i"(Address)
+ : "dx", "eax");
+ return data;
+ }
+ };
+
+} // namespace teachos::arch::io
+
+#endif \ No newline at end of file
diff --git a/arch/x86_64/include/arch/kernel/main.hpp b/arch/x86_64/include/arch/kernel/main.hpp
new file mode 100644
index 0000000..6961594
--- /dev/null
+++ b/arch/x86_64/include/arch/kernel/main.hpp
@@ -0,0 +1,11 @@
+#ifndef TEACHOS_ARCH_X86_64_KERNEL_MAIN_HPP
+#define TEACHOS_ARCH_X86_64_KERNEL_MAIN_HPP
+
+#include <cstddef>
+
+namespace teachos::arch::kernel
+{
+ auto main() -> void;
+}
+
+#endif \ No newline at end of file
diff --git a/arch/x86_64/include/arch/video/vga/io.hpp b/arch/x86_64/include/arch/video/vga/io.hpp
new file mode 100644
index 0000000..9226c5c
--- /dev/null
+++ b/arch/x86_64/include/arch/video/vga/io.hpp
@@ -0,0 +1,41 @@
+#ifndef TEACHOS_ARCH_X86_64_VIDEO_VGA_IO_HPP
+#define TEACHOS_ARCH_X86_64_VIDEO_VGA_IO_HPP
+
+#include "arch/io/port_io.hpp"
+
+#include <cstddef>
+
+namespace teachos::arch::video::vga
+{
+
+ namespace crtc
+ {
+
+ /**
+ * @brief The address port of the CRT Controller
+ */
+ using address_port = arch::io::port<0x3d4, 1>;
+
+ /**
+ * @brief The data port of the CRT Controller
+ */
+ using data_port = arch::io::port<0x3d5, 1>;
+
+ namespace registers
+ {
+ /**
+ * @brief The address of the Cursor Start register of the CRTC
+ */
+ [[maybe_unused]] auto constexpr cursor_start = std::byte{0x0a};
+
+ /**
+ * @brief The address of the Cursor End register of the CRTC
+ */
+ [[maybe_unused]] auto constexpr curser_end = std::byte{0x0b};
+ } // namespace registers
+
+ }; // namespace crtc
+
+} // namespace teachos::arch::video::vga
+
+#endif \ No newline at end of file
diff --git a/arch/x86_64/include/arch/video/vga/text.hpp b/arch/x86_64/include/arch/video/vga/text.hpp
new file mode 100644
index 0000000..1e584d6
--- /dev/null
+++ b/arch/x86_64/include/arch/video/vga/text.hpp
@@ -0,0 +1,113 @@
+#ifndef TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP
+#define TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP
+
+#include <cstdint>
+#include <string_view>
+
+namespace teachos::arch::video::vga::text
+{
+ /**
+ * @brief The colors available in the standard VGA text mode.
+ */
+ enum struct color : std::uint8_t
+ {
+ black, /**< Equivalent to HTML color \#000000 */
+ blue, /**< Equivalent to HTML color \#0000AA */
+ green, /**< Equivalent to HTML color \#00AA00 */
+ cyan, /**< Equivalent to HTML color \#00AAAA */
+ red, /**< Equivalent to HTML color \#AA0000 */
+ purple, /**< Equivalent to HTML color \#AA00AA */
+ brown, /**< Equivalent to HTML color \#AA5500 */
+ gray, /**< Equivalent to HTML color \#AAAAAA */
+ };
+
+ /**
+ * @brief The foreground color modification flag.
+ */
+ enum struct foreground_flag : bool
+ {
+ none, /**< Apply no flag e.g., keep color as is. */
+ intense, /**< Make the color more intense (usually brighter). */
+ };
+
+ /**
+ * @brief The background color modification flag.
+ */
+ enum struct background_flag : bool
+ {
+ none, /**< Apply no flag e.g., keep color as is. */
+ blink_or_bright, /**< Make the cell blink or more intense, dependent on the VGA configuration */
+ };
+
+ /**
+ * @brief The VGA text mode attribute.
+ *
+ * In the text mode of VGA, every code point being presented is followed by an attribute description. This allows for
+ * the modification of how the relevant "cell" is presented.
+ *
+ * @see vga::text::foreground_flag
+ * @see vga::text::background_flag
+ */
+ struct attribute
+ {
+ color foreground_color : 3; /**< The foreground color of the cell, e.g. the color of the code point.*/
+ enum foreground_flag foreground_flag : 1; /**< The foreground color modification flag of the cell.*/
+ color bacground_color : 3; /**< The background color of the cell.*/
+ enum background_flag background_flag : 1; /**< The background color modification flag of the cell.*/
+ };
+
+ static_assert(sizeof(attribute) == 1, "The VGA text mode attribute must fit inside a single byte.");
+
+ /**
+ * @brief Commonly used VGA text mode attributes
+ */
+ namespace common_attributes
+ {
+ /**
+ * @brief Make the affected cell display with a gray foreground and black background.
+ */
+ [[maybe_unused]] auto constexpr gray_on_black =
+ attribute{color::gray, 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 green_on_black =
+ attribute{color::green, 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 =
+ attribute{color::gray, foreground_flag::intense, color::red, background_flag::none};
+ } // namespace common_attributes
+
+ /**
+ * @brief Clear the VGA text mode buffer.
+ *
+ * @note This function also resets the text mode buffer pointer.
+ *
+ * @param attribute The attribute to "clear" the screen with.
+ */
+ auto clear(attribute attribute = common_attributes::gray_on_black) -> void;
+
+ /**
+ * @brief Enable or disable the VGA text mode cursor.
+ *
+ * @param enabled Whether or not to enable the cursors.
+ */
+ auto cursor(bool enabled) -> void;
+
+ /**
+ * @brief Write a string of code points to the VGA text buffer.
+ *
+ * @note This function also updates the text mode buffer pointer.
+ *
+ * @param code_points A string of (8-bit) code points to write to the VGA text mode buffer.
+ * @param attribute The attribute to apply to the written sequence of code points.
+ * @see vga::text::attribute
+ */
+ auto write(std::string_view code_points, attribute attribute) -> void;
+} // namespace teachos::arch::video::vga::text
+
+#endif \ No newline at end of file