Simplified tty and serial write functions.

This commit is contained in:
neviyn 2018-04-28 22:22:05 +01:00
parent 56cd64ef93
commit 1e3e34d9f7
6 changed files with 42 additions and 47 deletions

View File

@ -69,7 +69,6 @@ proc gdtInstall*() =
#gdtSetGate(4, 0'u16, 0xFFFFFFFF'u32, 0xF2, createFlags(true, true)); #gdtSetGate(4, 0'u16, 0xFFFFFFFF'u32, 0xF2, createFlags(true, true));
serial.write("GDT Address:") serial.write("GDT Address:")
serial.write(gdt.descriptor.base) serial.writeLine(gdt.descriptor.base)
serial.write("\L") serial.writeLine("Flushing GDT.")
serial.write("Flushing GDT.\L")
gdtFlush() gdtFlush()

View File

@ -80,17 +80,10 @@ macro generateISR(code: static[uint8], isError: static[bool]): typed =
nnkCall.newTree( nnkCall.newTree(
nnkDotExpr.newTree( nnkDotExpr.newTree(
newIdentNode("serial"), newIdentNode("serial"),
newIdentNode("write") newIdentNode("writeLine")
), ),
newLit(code) newLit(code)
), ),
nnkCall.newTree(
nnkDotExpr.newTree(
newIdentNode("serial"),
newIdentNode("write")
),
newLit("\x0A")
),
nnkAsmStmt.newTree( nnkAsmStmt.newTree(
newEmptyNode(), newEmptyNode(),
newLit((if isError: "" else: "push 0\x0A") & "push " & $code & "\x0A") newLit((if isError: "" else: "push 0\x0A") & "push " & $code & "\x0A")
@ -181,5 +174,5 @@ proc idtInstall*() =
idtSetGate(29, cast[uint32](isr29), selector, flags) idtSetGate(29, cast[uint32](isr29), selector, flags)
idtSetGate(30, cast[uint32](isr30), selector, flags) idtSetGate(30, cast[uint32](isr30), selector, flags)
idtSetGate(31, cast[uint32](isr31), selector, flags) idtSetGate(31, cast[uint32](isr31), selector, flags)
serial.write("Flushing IDT.\L") serial.writeLine("Flushing IDT.")
idtFlush() idtFlush()

View File

@ -21,18 +21,18 @@ proc write*(input: char) =
proc write*(input: string) = proc write*(input: string) =
for i in 0 .. input.len - 1: for i in 0 .. input.len - 1:
write(input[i]) serial.write(input[i])
var parsedData: array[0..9, char] var parsedData: array[0..9, char]
proc write*(data: SomeSignedInt) = proc write*(data: SomeSignedInt) =
if(data == 0): if(data == 0):
write('0') serial.write('0')
return return
var input = data var input = data
var i = 0 var i = 0
if(input < 0): if(input < 0):
write('-') serial.write('-')
input = input * -1 input = input * -1
while(input != 0): while(input != 0):
let parsedChar: char = char(48 + (input mod 10)) let parsedChar: char = char(48 + (input mod 10))
@ -41,11 +41,11 @@ proc write*(data: SomeSignedInt) =
input = input div 10 input = input div 10
while i > 0: while i > 0:
i = i - 1 i = i - 1
write(parsedData[i]) serial.write(parsedData[i])
proc write*(data: SomeUnsignedInt) = proc write*(data: SomeUnsignedInt) =
if(data == 0): if(data == 0):
write('0') serial.write('0')
return return
var input = data var input = data
var i = 0 var i = 0
@ -56,6 +56,10 @@ proc write*(data: SomeUnsignedInt) =
input = input div 10 input = input div 10
while i > 0: while i > 0:
i = i - 1 i = i - 1
write(parsedData[i]) serial.write(parsedData[i])
proc newLine*() = write('\L') proc newLine*() = write('\L')
proc writeLine*(data: any) =
serial.write(data)
newLine()

View File

@ -26,7 +26,7 @@ proc terminalClear*() =
terminalRow = 0 terminalRow = 0
terminalColumn = 0 terminalColumn = 0
proc terminalInitialize*() = proc initialize*() =
terminalColour = vgaEntryColour(VGA_Colour.lightGreen, VGA_Colour.red) terminalColour = vgaEntryColour(VGA_Colour.lightGreen, VGA_Colour.red)
terminalClear() terminalClear()
@ -58,22 +58,22 @@ proc terminalWriteChar(writeChar: char) =
if(terminalColumn == vgaWidth): if(terminalColumn == vgaWidth):
scrollCheckAndSet() scrollCheckAndSet()
proc terminalWrite*(data: string) = proc write*(data: string) =
for i in 0 .. data.len - 1: for i in 0 .. data.len - 1:
terminalWriteChar(data[i]) terminalWriteChar(data[i])
proc terminalWrite*(data: char) = proc write*(data: char) =
terminalWriteChar(data) terminalWriteChar(data)
proc terminalWrite*(data: SomeSignedInt) = proc write*(data: SomeSignedInt) =
var parsedData: array[0..9, char] var parsedData: array[0..9, char]
if(data == 0): if(data == 0):
terminalWrite('0') tty.write('0')
return return
var input = data var input = data
var i = 0 var i = 0
if(input < 0): if(input < 0):
terminalWrite('-') tty.write('-')
input = input * -1 input = input * -1
while(input != 0): while(input != 0):
let parsedChar: char = char(48 + (input mod 10)) let parsedChar: char = char(48 + (input mod 10))
@ -82,12 +82,12 @@ proc terminalWrite*(data: SomeSignedInt) =
input = input div 10 input = input div 10
while i > 0: while i > 0:
i = i - 1 i = i - 1
terminalWrite(parsedData[i]) tty.write(parsedData[i])
proc terminalWrite*(data: SomeUnsignedInt) = proc write*(data: SomeUnsignedInt) =
var parsedData: array[0..9, char] var parsedData: array[0..9, char]
if(data == 0): if(data == 0):
terminalWrite('0') tty.write('0')
return return
var input = data var input = data
var i = 0 var i = 0
@ -98,4 +98,8 @@ proc terminalWrite*(data: SomeUnsignedInt) =
input = input div 10 input = input div 10
while i > 0: while i > 0:
i = i - 1 i = i - 1
terminalWrite(parsedData[i]) tty.write(parsedData[i])
proc writeLine*(data: any) =
tty.write(data)
tty.write('\L')

View File

@ -22,24 +22,19 @@ proc memset*(dest: ByteAddress, value: char, count: int){.exportc.} =
proc kernelMain() {.exportc: "kernel_main"}= proc kernelMain() {.exportc: "kernel_main"}=
serial.init() serial.init()
serial.write("Version:") serial.writeLine("Version:" & (version))
serial.write(version) serial.writeLine("Booting OS")
serial.write("\L")
serial.write("Booting OS\L")
gdt.gdtInstall() gdt.gdtInstall()
serial.write("GDT installed\L") serial.writeLine("GDT installed")
interrupts.idtInstall() interrupts.idtInstall()
serial.write("IDT installed\L") serial.writeLine("IDT installed")
terminalInitialize() tty.initialize()
terminalWrite("Version:") tty.writeLine("Version:" & version)
terminalWrite(version) tty.writeLine("Hello World!")
terminalWrite("\L") tty.write("MAX_INT:")
terminalWrite("Hello World!\L") tty.writeLine(high(int))
terminalWrite("MAX_INT:") tty.write("LMIN_INT:")
terminalWrite(high(int)) tty.writeLine((low(int)+1))
terminalWrite("\LMIN_INT:") tty.write("MAX_UINT:")
terminalWrite(low(int)+1) tty.writeLine(high(uint32))
terminalWrite("\LMAX_UINT:")
terminalWrite(high(uint32))
terminalWrite("\L")
asm """int $0x3""" asm """int $0x3"""

View File

@ -3,7 +3,7 @@ import tty
{.push stack_trace: off, profiler:off.} {.push stack_trace: off, profiler:off.}
proc rawoutput(s: string) = proc rawoutput(s: string) =
tty.terminalWrite(s) tty.write(s)
proc panic(s: string) = proc panic(s: string) =
rawoutput(s) rawoutput(s)