diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-02-10 22:53:50 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-02-10 22:53:50 +0200 |
commit | 6f54758123abe9f137922df1e8d7e33835e9a9f2 (patch) | |
tree | e21b553a826c7ae67cc4b41ffde921e39ed4022b /src/ports.h | |
parent | Add some compiler warnings (diff) | |
download | kernel.cpp-6f54758123abe9f137922df1e8d7e33835e9a9f2.tar.xz |
Update VGA cursor position on printk
Diffstat (limited to 'src/ports.h')
-rw-r--r-- | src/ports.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/ports.h b/src/ports.h new file mode 100644 index 0000000..0371bcc --- /dev/null +++ b/src/ports.h @@ -0,0 +1,43 @@ +#pragma once + +template <typename T> +concept port_data_t = (is_same<T, uint8_t>::value || is_same<T, uint16_t>::value || is_same<T, uint32_t>::value); + +template <uint16_t port_num, port_data_t T> +class Port { +public: + [[nodiscard]] T read() { + T result; + + switch (sizeof(T)) { + case 1: + asm volatile("inb %1, %0" : "=a"(result) : "Nd"(port_num)); + break; + case 2: + asm volatile("inw %1, %0" : "=a"(result) : "Nd"(port_num)); + break; + case 4: + asm volatile("inl %1, %0" : "=a"(result) : "Nd"(port_num)); + break; + } + + return result; + } + + void write(T data) { + switch (sizeof(T)) { + case 1: + asm volatile("outb %0, %1" : : "a"(data), "Nd"(port_num)); + break; + case 2: + asm volatile("outw %0, %1" : : "a"(data), "Nd"(port_num)); + break; + case 4: + asm volatile("outl %0, %1" : : "a"(data), "Nd"(port_num)); + break; + } + } +}; + +typedef Port<0x3d4, uint8_t> vga_horizontal_total; +typedef Port<0x3d5, uint8_t> vga_horizontal_display_enable_end; |