diff options
Diffstat (limited to 'src/kernel/io/io.c')
-rw-r--r-- | src/kernel/io/io.c | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/src/kernel/io/io.c b/src/kernel/io/io.c index 3abbb18..c5ae657 100644 --- a/src/kernel/io/io.c +++ b/src/kernel/io/io.c @@ -5,64 +5,74 @@ #include <mlibc/string.h> #include <mlibc/stdlib.h> -uint8_t receive_b(uint16_t port) { +uint8_t inb(uint16_t port) +{ uint8_t value; - asm volatile ("inb %1, %0" : "=a"(value) : "Nd"(port)); + asm ("inb %1, %0" : "=a"(value) : "Nd"(port)); return value; } -uint16_t receive_w(uint16_t port) { +uint16_t inw(uint16_t port) +{ uint16_t value; - asm volatile("inw %1, %0" : "=a"(value) : "Nd"(port)); + asm ("inw %1, %0" : "=a"(value) : "Nd"(port)); return value; } -uint32_t receive_l(uint16_t port) { +uint32_t inl(uint16_t port) +{ uint32_t value; - asm volatile ("inb %1, %0" : "=a"(value) : "Nd"(port)); + asm ("inl %1, %0" : "=a"(value) : "Nd"(port)); return value; } -void send_b(uint16_t port, uint8_t data) { - asm volatile ("outb %0, %1"::"a" (data), "Nd"(port)); +void outb(uint16_t port, uint8_t data) +{ + asm ("outb %0, %1"::"a" (data), "Nd"(port)); } -void send_w(uint16_t port, uint16_t data) { - asm volatile ("outw %0, %1"::"a" (data), "Nd"(port)); +void outw(uint16_t port, uint16_t data) +{ + asm ("outw %0, %1"::"a" (data), "Nd"(port)); } -void send_l(uint16_t port, uint32_t data) { - asm volatile ("outl %0, %1"::"a" (data), "Nd"(port)); +void outl(uint16_t port, uint32_t data) +{ + asm ("outl %0, %1"::"a" (data), "Nd"(port)); } -void init_serial() { - send_b(0x3f8 + 1, 0x00); - send_b(0x3f8 + 3, 0x80); - send_b(0x3f8 + 0, 0x03); - send_b(0x3f8 + 1, 0x00); - send_b(0x3f8 + 3, 0x03); - send_b(0x3f8 + 2, 0xC7); - send_b(0x3f8 + 4, 0x0B); - serial_write("Installed serial connection!\n"); - vga_log("Installed serial connection", 3); +void init_serial() +{ + outb(0x3f8 + 1, 0x00); + outb(0x3f8 + 3, 0x80); + outb(0x3f8 + 0, 0x03); + outb(0x3f8 + 1, 0x00); + outb(0x3f8 + 3, 0x03); + outb(0x3f8 + 2, 0xC7); + outb(0x3f8 + 4, 0x0B); + vga_log("Installed serial connection", 2); } -int is_transmit_empty() { - return receive_b(0x3f8 + 5) & 0x20; +int is_transmit_empty() +{ + return inb(0x3f8 + 5) & 0x20; } -void serial_put(char ch) { +void serial_put(char ch) +{ while (is_transmit_empty() == 0); - send_b(0x3f8, ch); + outb(0x3f8, ch); } -void serial_write(const char *data) { +void serial_write(const char *data) +{ for (size_t i = 0; i < strlen(data); i++) { serial_put(data[i]); } } -void serial_write_hex(int n) { +void serial_write_hex(int n) +{ int tmp; serial_write("0x"); @@ -89,6 +99,7 @@ void serial_write_hex(int n) { } } -void serial_write_dec(int n) { +void serial_write_dec(int n) +{ serial_write(itoa(n)); } |