Added logging via serial output.
This commit is contained in:
parent
a03745805b
commit
86760fd9de
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ isodir/
|
|||||||
myos.iso
|
myos.iso
|
||||||
*.o
|
*.o
|
||||||
myos.bin
|
myos.bin
|
||||||
|
serial.log
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
make clean
|
make clean
|
||||||
make
|
make
|
||||||
./builddisc.sh
|
./builddisc.sh
|
||||||
qemu-system-i386 -cdrom myos.iso
|
qemu-system-i386 -cdrom myos.iso -serial file:serial.log
|
||||||
|
@ -5,12 +5,14 @@ type
|
|||||||
|
|
||||||
{.push stackTrace:off.}
|
{.push stackTrace:off.}
|
||||||
proc outb*(data: IOPacket) =
|
proc outb*(data: IOPacket) =
|
||||||
|
let x = data.value
|
||||||
|
let y = data.port
|
||||||
asm """
|
asm """
|
||||||
outb `data.value` `data.port`
|
"outb %%al, %%dx" : :"a"(`x`), "d"(`y`)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc inb*(port: uint16): uint =
|
proc inb*(port: uint16): uint =
|
||||||
asm """
|
asm """
|
||||||
inb `port` `result`
|
"inb %%dx, %%al" :"=a"(`result`) :"d"(`port`)
|
||||||
"""
|
"""
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
26
kernel/arch/i386/serial.nim
Normal file
26
kernel/arch/i386/serial.nim
Normal 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')
|
||||||
|
|
@ -1,7 +1,10 @@
|
|||||||
import tty, gdt
|
import tty, gdt, irq, serial
|
||||||
|
|
||||||
proc kernelMain() {.exportc: "kernel_main"}=
|
proc kernelMain() {.exportc: "kernel_main"}=
|
||||||
|
serial.init()
|
||||||
|
serial.write("Booting OS")
|
||||||
gdt.gdtInstall()
|
gdt.gdtInstall()
|
||||||
|
serial.write("GDT installed")
|
||||||
terminalInitialize()
|
terminalInitialize()
|
||||||
terminalWrite("Hello World!\L")
|
terminalWrite("Hello World!\L")
|
||||||
terminalWrite("MAX_INT:")
|
terminalWrite("MAX_INT:")
|
||||||
|
Loading…
Reference in New Issue
Block a user