From 8eef348ecabe1b3604b25288e5f96bb65cfe6e3f Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Thu, 16 Nov 2017 17:07:52 +0000 Subject: [PATCH] Implemented memcpy and memset. Allows larger local variables. --- kernel/arch/i386/tty.nim | 4 ++-- kernel/kernel.nim | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/kernel/arch/i386/tty.nim b/kernel/arch/i386/tty.nim index c7d3baf..5817093 100644 --- a/kernel/arch/i386/tty.nim +++ b/kernel/arch/i386/tty.nim @@ -65,9 +65,8 @@ proc terminalWrite*(data: string) = proc terminalWrite*(data: char) = terminalWriteChar(data) -var parsedData: array[0..9, char] - proc terminalWrite*(data: SomeSignedInt) = + var parsedData: array[0..9, char] if(data == 0): terminalWrite('0') return @@ -86,6 +85,7 @@ proc terminalWrite*(data: SomeSignedInt) = terminalWrite(parsedData[i]) proc terminalWrite*(data: SomeUnsignedInt) = + var parsedData: array[0..9, char] if(data == 0): terminalWrite('0') return diff --git a/kernel/kernel.nim b/kernel/kernel.nim index b4da3a8..d2c186e 100644 --- a/kernel/kernel.nim +++ b/kernel/kernel.nim @@ -3,6 +3,20 @@ import tty, gdt, irq, 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")