From 8a6d52e8d4ae94da6f348de7e897c364765aa281 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Sat, 28 Apr 2018 01:03:53 +0100 Subject: [PATCH] Simplified GDT installation. --- kernel/arch/i386/gdt.nim | 29 ++++++++++++++--------------- kernel/arch/i386/irq.nim | 11 ----------- 2 files changed, 14 insertions(+), 26 deletions(-) delete mode 100644 kernel/arch/i386/irq.nim diff --git a/kernel/arch/i386/gdt.nim b/kernel/arch/i386/gdt.nim index 8a5dafe..9fbe04e 100644 --- a/kernel/arch/i386/gdt.nim +++ b/kernel/arch/i386/gdt.nim @@ -18,23 +18,14 @@ type entries: array[0..2, GDTEntry] const - gdtAddress: uint32 = 0x00000800 + gdtAddress: uint32 = 0x800 gdt = cast[ptr GDT](gdtAddress) -{.push stackTrace:off.} proc gdtFlush(){.inline,asmNoStackFrame.} = asm """ - cli - lgdtl [`0x00000800`] - movw $0x10, %ax - movw %ax, %ds - movw %ax, %es - movw %ax, %fs - movw %ax, %gs - ljmp $0x08, $next - next: + lgdt (0x800) + ret """ -{.pop.} proc gdtSetGate(num: int, base: uint16, limit: uint32, access: AccessByte, flags: Flags) = # Setup the descriptor base address @@ -62,15 +53,23 @@ proc createFlags(granularity: bool, size: bool): Flags = result = result or 0b01000000'u8 proc gdtInstall*() = - gdt.descriptor.limit = uint16(sizeof(GDTEntry) * gdt.entries.len) - 1; + gdt.descriptor.limit = uint16(sizeof(gdt.entries)) - 1 gdt.descriptor.base = cast[uint32](gdt.entries.addr) + # NULL descriptor gdtSetGate(0, 0, 0, 0, 0); # The second entry is our Code Segment - gdtSetGate(1, 0'u16, 0xFFFFFFFF'u32, createAccessByte(0, false, true), createFlags(true, true)); + gdtSetGate(1, 0'u16, 0xFFFFFFFF'u32, 0x9A, createFlags(true, true)); # The third entry is our Data Segment - gdtSetGate(2, 0'u16, 0xFFFFFFFF'u32, createAccessByte(0, false, true), createFlags(true, true)); + gdtSetGate(2, 0'u16, 0xFFFFFFFF'u32, 0x92, createFlags(true, true)); + + #gdtSetGate(3, 0'u16, 0xFFFFFFFF'u32, 0xFA, createFlags(true, true)); + + #gdtSetGate(4, 0'u16, 0xFFFFFFFF'u32, 0xF2, createFlags(true, true)); + serial.write("GDT Address:") + serial.write(gdt.descriptor.base) + serial.write("\L") serial.write("Flushing GDT.\L") gdtFlush() diff --git a/kernel/arch/i386/irq.nim b/kernel/arch/i386/irq.nim deleted file mode 100644 index f0a5bad..0000000 --- a/kernel/arch/i386/irq.nim +++ /dev/null @@ -1,11 +0,0 @@ -type - InterruptFrame = ptr object - ip: uint - cs: uint - flags: uint - sp: uint - ss: uint - -# http://clang.llvm.org/docs/AttributeReference.html#interrupt-avr -proc interrupt_handler(frame: InterruptFrame) {.exportc, codegenDecl: "__attribute__((interrupt)) $# $#$#".} = - discard