From 9b2a78fa52249ab481493550490aa5f37872dcf6 Mon Sep 17 00:00:00 2001 From: aqua Date: Sat, 10 Dec 2022 20:56:57 +0200 Subject: Rewrite drivers/uart and drivers/vga in cpp --- i686/sys/cpuid.h | 2 +- i686/sys/io.h | 23 +++++++++++++++++++++++ i686/sys/io.hpp | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 i686/sys/io.hpp (limited to 'i686/sys') diff --git a/i686/sys/cpuid.h b/i686/sys/cpuid.h index 862601f..65b43c6 100644 --- a/i686/sys/cpuid.h +++ b/i686/sys/cpuid.h @@ -12,7 +12,7 @@ struct CPUVersion { unsigned int family_ex : 8; unsigned int __unused_2 : 4; } __attribute__((packed, aligned(__alignof__(unsigned int)))); -_Static_assert(sizeof(struct CPUVersion) == sizeof(unsigned int), "cpuid version struct size"); +// FIXME _Static_assert(sizeof(struct CPUVersion) == sizeof(unsigned int), "cpuid version struct size"); unsigned int family(const struct CPUVersion v) diff --git a/i686/sys/io.h b/i686/sys/io.h index 74d4950..b6c24c5 100644 --- a/i686/sys/io.h +++ b/i686/sys/io.h @@ -1,5 +1,27 @@ #pragma once +// port listings +enum UART { + COM1 = 0x3f8, + COM2 = 0x2f8, + COM3 = 0x3e8, + COM4 = 0x2e8, + COM5 = 0x5f8, + COM6 = 0x4f8, + COM7 = 0x5e8, + COM8 = 0x4e8, +}; +enum UARTPortOffset { + Data = 0, // read from receive buffer / write to transmit buffer | BaudDiv_l + InterruptControl = 1, // interrupt enable | BaudDiv_h + FifoControl = 2, // interrupt ID and FIFO control + LineControl = 3, // most significant bit is the DLAB + ModemControl = 4, + LineStatus = 5, + ModemStatus = 6, + Scratch = 7, +}; + static inline void outb(unsigned char val, unsigned short port) { @@ -77,3 +99,4 @@ insl(unsigned short port, void *__buf, unsigned long __n) { asm volatile("cld; rep; insl" : "+D"(__buf), "+c"(__n) : "d"(port)); } + diff --git a/i686/sys/io.hpp b/i686/sys/io.hpp new file mode 100644 index 0000000..bea9323 --- /dev/null +++ b/i686/sys/io.hpp @@ -0,0 +1,15 @@ +#pragma once + +template struct Port { + static void + out(T val, unsigned short offset = 0) + { + outb(val, port + offset); + } + + static auto + in(unsigned short offset = 0) + { + return inb(port + offset); + } +}; -- cgit v1.2.1