From 6e481f72aa0d2de7543512401e92fc7e1d1ff702 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Wed, 16 May 2018 00:42:37 +0100 Subject: [PATCH] Now only required number of kernel pages assigned. --- kernel/arch/i386/paging.nim | 15 ++++++++++++++- kernel/arch/i386/tty.nim | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/kernel/arch/i386/paging.nim b/kernel/arch/i386/paging.nim index b1f01f6..cb9ae02 100644 --- a/kernel/arch/i386/paging.nim +++ b/kernel/arch/i386/paging.nim @@ -9,6 +9,13 @@ type const blankPageDirectory: PageDirectoryEntry = 0x00000002 +var + kernelMemoryStart{.importc: "_kernel_start"}: uint32 + kernelMemoryEnd{.importc: "_kernel_end"}: uint32 + +proc kernelMemoryStartAddress(): uint32 = cast[uint32](kernelMemoryStart.addr) +proc kernelMemoryEndAddress(): uint32 = cast[uint32](kernelMemoryEnd.addr) + var pageDirectory: ptr PageDirectory pageTable0{.exportc, codegenDecl: "$# $# __attribute__((aligned(0x1000)))".}: PageTable @@ -54,7 +61,13 @@ proc init*() = pageDirectory = cast[ptr PageDirectory](toVirtual(pagingAddress)) for i in 0..767: pageDirectory[][i] = blankPageDirectory - for i in 0..1023: + var pages: uint = uint(int(kernelMemoryEndAddress() - 0xC0000000'u32) / 0x1000) + serial.write("Pages:") + serial.writeLine(pages) + # Assign VGA memory area to 0xC0000000 + pageTable0[0] = createEntry(address = 0xB8000, readWrite = true, present = true) + # Assign kernel memory pages to 0xC0100000+ + for i in 256..pages: pageTable0[i] = createEntry(address = uint32(i) * 0x1000, readWrite = true, present = true) pageDirectory[][768] = createDirectory(address = toPhysical(cast[uint32](pageTable0.addr)), readWrite = true, present = true) for i in 769..1023: diff --git a/kernel/arch/i386/tty.nim b/kernel/arch/i386/tty.nim index cbf9a10..69c10b4 100644 --- a/kernel/arch/i386/tty.nim +++ b/kernel/arch/i386/tty.nim @@ -8,7 +8,7 @@ type VGAMemory = ptr array[0..(vgaWidth * vgaHeight - 1), VGADoubleByte] const - terminalBufferBaseAddress = 0xC00B8000 + terminalBufferBaseAddress = 0xC0000000 vgaMem = cast[VGAMemory](terminalBufferBaseAddress) var