karlos/x86_64/uart.c

34 lines
483 B
C

#define COM1_BASE_PORT 0x3F8
int
inb(int port)
{
unsigned char value;
__asm__ ("inb %%dx" : "=a"(value) : "d"(port));
return value;
}
void
outb(int port, int value)
{
__asm__ ("outb %%dx" :: "d"(port), "a"(value));
}
void
write_char(char c)
{
while (1) {
int line_status = inb(COM1_BASE_PORT + 5);
if (line_status & 0x20) break;
}
outb(COM1_BASE_PORT, c);
}
void
write_string(const char *string)
{
for (const char *c = string; *c != 0; c++) {
write_char(*c);
}
}