alcedo/kernel/arch/i386/serial.nim

27 lines
855 B
Nim

import io
const portCOM1 = 0x3f8'u16
proc init*() =
io.outb((portCOM1 + 1, 0x00'u8)); # Disable all interrupts
io.outb((portCOM1 + 3, 0x80'u8)); # Enable DLAB (set baud rate divisor)
io.outb((portCOM1 + 0, 0x03'u8)); # Set divisor to 3 (lo byte) 38400 baud
io.outb((portCOM1 + 1, 0x00'u8)); # (hi byte)
io.outb((portCOM1 + 3, 0x03'u8)); # 8 bits, no parity, one stop bit
io.outb((portCOM1 + 2, 0xC7'u8)); # Enable FIFO, clear them, with 14-byte threshold
io.outb((portCOM1 + 4, 0x0B'u8)); # IRQs enabled, RTS/DSR set
proc isTransitEmpty(): uint =
result = io.inb(portCOM1 + 5) and 0x20'u
proc write*(input: char) =
while isTransitEmpty() == 0:
discard
io.outb((portCOM1, uint8(input)))
proc write*(input: string) =
for i in 0 .. input.len - 1:
write(input[i])
write('\L')