explicit naming of in/out functions with all variants

This commit is contained in:
uosfz 2025-01-31 15:00:34 +01:00
parent 6d364ed5d4
commit 5be8edd23a
Signed by: uosfz
SSH key fingerprint: SHA256:FlktuluyhTQg3jHZNLKwxOOC5hbfrUXM0tz3IA3lGJo
3 changed files with 22 additions and 16 deletions

View file

@ -3,9 +3,11 @@
#include <stdint.h> #include <stdint.h>
int inb(int port); uint8_t in8(int port);
uint32_t inl(int port); uint16_t in16(int port);
void outb(int port, int value); uint32_t in32(int port);
void outl(int port, uint32_t value); void out8(int port, uint8_t value);
void out16(int port, uint16_t value);
void out32(int port, uint32_t value);
#endif #endif

View file

@ -1,27 +1,31 @@
#include "asm.h" #include "asm.h"
int uint8_t in8(int port) {
inb(int port)
{
unsigned char value; unsigned char value;
__asm__ ("inb %%dx" : "=a"(value) : "d"(port)); __asm__ ("inb %%dx" : "=a"(value) : "d"(port));
return value; return value;
} }
uint32_t inl(int port) { uint16_t in16(int port) {
uint16_t value;
__asm__ ("inw %%dx" : "=a"(value) : "d"(port));
return value;
}
uint32_t in32(int port) {
uint32_t value; uint32_t value;
__asm__ ("inl %%dx" : "=a"(value) : "d"(port)); __asm__ ("inl %%dx" : "=a"(value) : "d"(port));
return value; return value;
} }
void void out8(int port, uint8_t value) {
outb(int port, int value)
{
__asm__ ("outb %%dx" :: "d"(port), "a"(value)); __asm__ ("outb %%dx" :: "d"(port), "a"(value));
} }
void void out16(int port, uint16_t value) {
outl(int port, uint32_t value) __asm__ ("outw %%dx" :: "d"(port), "a"(value));
{ }
void out32(int port, uint32_t value) {
__asm__ ("outl %%dx" :: "d"(port), "a"(value)); __asm__ ("outl %%dx" :: "d"(port), "a"(value));
} }

View file

@ -6,9 +6,9 @@ void
uart_write_char(char c) uart_write_char(char c)
{ {
while (1) { while (1) {
int line_status = inb(COM1_BASE_PORT + 5); int line_status = in8(COM1_BASE_PORT + 5);
if (line_status & 0x20) break; if (line_status & 0x20) break;
} }
outb(COM1_BASE_PORT, c); out8(COM1_BASE_PORT, c);
} }