alcedo/kernel/kernel.nim

40 lines
1.1 KiB
Nim

{.link: "../boot.o".}
{.passL: "-ffreestanding -target i386 -nostdlib -T arch/i386/linker.ld".}
{.passC: "-ffreestanding -nostdlib --target=i386-pc-none-elf -march=i386".}
import tty, gdt, interrupts, serial
type
MemoryPointer{.unchecked.} = ptr array[0, char]
proc memcpy*(dest: ByteAddress, src: ByteAddress, count: int){.exportc.} =
var destMem = cast[MemoryPointer](dest)
var srcMem = cast[MemoryPointer](src)
for i in 0..count-1:
destMem[i] = srcMem[i]
proc memset*(dest: ByteAddress, value: char, count: int){.exportc.} =
var destMem = cast[MemoryPointer](dest)
for i in 0..count-1:
destMem[i] = value
proc kernelMain() {.exportc: "kernel_main"}=
serial.init()
serial.write("Booting OS\L")
gdt.gdtInstall()
serial.write("GDT installed\L")
interrupts.idtInstall()
serial.write("IDT installed\L")
terminalInitialize()
terminalWrite("Hello World!\L")
terminalWrite("MAX_INT:")
terminalWrite(high(int))
terminalWrite("\LMIN_INT:")
terminalWrite(low(int32)+1)
for i in 0..22:
terminalWrite(i)
terminalWrite('\L')
asm """
int $0x3
"""