diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-02-12 17:55:31 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-02-12 17:55:31 +0200 |
commit | 46a5f1ee4db70a037af5038deaa1d64ad0f7862c (patch) | |
tree | 0250b88f2eb69a7a0987a78d23a06e2125df74a2 /drivers/ports.h | |
parent | Add comments to explain CGA ports better (diff) | |
download | kernel.cpp-46a5f1ee4db70a037af5038deaa1d64ad0f7862c.tar.xz |
Add serial0 console output
Diffstat (limited to 'drivers/ports.h')
-rw-r--r-- | drivers/ports.h | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/drivers/ports.h b/drivers/ports.h index 338c3b8..8671f19 100644 --- a/drivers/ports.h +++ b/drivers/ports.h @@ -6,34 +6,36 @@ concept port_data_t = (is_same<T, uint8_t>::value || is_same<T, uint16_t>::value template <uint16_t port_num, port_data_t T> class Port { public: - [[nodiscard]] T read() { + [[nodiscard]] T read(uint16_t offset = 0) { + const uint16_t port = port_num + offset; T result; switch (sizeof(T)) { case 1: - asm volatile("inb %1, %0" : "=a"(result) : "Nd"(port_num)); + asm volatile("inb %1, %0" : "=a"(result) : "Nd"(port)); break; case 2: - asm volatile("inw %1, %0" : "=a"(result) : "Nd"(port_num)); + asm volatile("inw %1, %0" : "=a"(result) : "Nd"(port)); break; case 4: - asm volatile("inl %1, %0" : "=a"(result) : "Nd"(port_num)); + asm volatile("inl %1, %0" : "=a"(result) : "Nd"(port)); break; } return result; } - void write(T data) { + void write(T data, uint16_t offset = 0) { + const uint16_t port = port_num + offset; switch (sizeof(T)) { case 1: - asm volatile("outb %0, %1" : : "a"(data), "Nd"(port_num)); + asm volatile("outb %0, %1" : : "a"(data), "Nd"(port)); break; case 2: - asm volatile("outw %0, %1" : : "a"(data), "Nd"(port_num)); + asm volatile("outw %0, %1" : : "a"(data), "Nd"(port)); break; case 4: - asm volatile("outl %0, %1" : : "a"(data), "Nd"(port_num)); + asm volatile("outl %0, %1" : : "a"(data), "Nd"(port)); break; } } @@ -45,3 +47,9 @@ typedef Port<0x3d5, uint8_t> cga_dat_port; // 0x3d8 : mode select register // 0x3d8 : color control register // 0x3da : status register + +/* Serial ports */ +typedef Port<0x3f8, uint8_t> com1_port_t; +typedef Port<0x2f8, uint8_t> com2_port_t; +typedef Port<0x3e8, uint8_t> com3_port_t; +typedef Port<0x2e8, uint8_t> com4_port_t; |