Added logging via serial output.

This commit is contained in:
neviyn 2017-11-08 02:36:35 +00:00
parent a03745805b
commit 86760fd9de
6 changed files with 37 additions and 5 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ isodir/
myos.iso
*.o
myos.bin
serial.log

View File

@ -2,4 +2,4 @@
make clean
make
./builddisc.sh
qemu-system-i386 -cdrom myos.iso
qemu-system-i386 -cdrom myos.iso -serial file:serial.log

View File

@ -5,12 +5,14 @@ type
{.push stackTrace:off.}
proc outb*(data: IOPacket) =
let x = data.value
let y = data.port
asm """
outb `data.value` `data.port`
"outb %%al, %%dx" : :"a"(`x`), "d"(`y`)
"""
proc inb*(port: uint16): uint =
asm """
inb `port` `result`
"inb %%dx, %%al" :"=a"(`result`) :"d"(`port`)
"""
{.pop.}

View File

@ -0,0 +1,26 @@
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')

View File

@ -1,7 +1,10 @@
import tty, gdt
import tty, gdt, irq, serial
proc kernelMain() {.exportc: "kernel_main"}=
serial.init()
serial.write("Booting OS")
gdt.gdtInstall()
serial.write("GDT installed")
terminalInitialize()
terminalWrite("Hello World!\L")
terminalWrite("MAX_INT:")

View File

@ -10,4 +10,4 @@ bootloader:
nasm -felf32 kernel/arch/i386/boot.s -o boot.o
clean:
rm -r myos.bin nimcache/ boot.o
rm -r myos.bin nimcache/ boot.o serial.log