alcedo/kernel/kernel.nim

47 lines
1.4 KiB
Nim
Raw Normal View History

{.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, multiboot, paging
const version {.strdefine.} = "UNKNOWN"
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 getMemoryMap(mbd: multiboot_info) =
discard # Use this if we need to do anything with the GRUB memory map
2018-05-16 01:47:52 +01:00
proc kernelMain(mbd: multiboot_info, magic: uint) {.exportc: "kernel_main"}=
#proc kernelMain() {.exportc: "kernel_main"}=
getMemoryMap(mbd)
paging.init()
2017-11-08 02:36:35 +00:00
serial.init()
serial.writeLine("Version:" & (version))
serial.writeLine("Booting OS")
2017-11-06 21:44:17 +00:00
gdt.gdtInstall()
serial.writeLine("GDT installed")
interrupts.idtInstall()
serial.writeLine("IDT installed")
2018-05-02 23:02:46 +01:00
tty.init()
serial.writeLine("TTY initialised")
tty.writeLine("Version:" & version)
tty.writeLine("Hello World!")
tty.write("MAX_INT:")
tty.writeLine(high(int))
tty.write("MIN_INT:")
tty.writeLine((low(int)+1))
tty.write("MAX_UINT:")
tty.writeLine(high(uint32))
asm """int $0x3"""