From d7933002795dcfd702e231c88141ada8501901ae Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Wed, 21 Jun 2017 07:57:05 +0100 Subject: [PATCH] Move TLB-handling code to the cpu pkg --- kernel/cpu/cpu_amd64.go | 11 +++++++++++ kernel/{mem/vmm/tlb_amd64.s => cpu/cpu_amd64.s} | 11 ++++++----- kernel/mem/vmm/map.go | 3 ++- kernel/mem/vmm/pdt.go | 5 +++-- kernel/mem/vmm/tlb.go | 11 ----------- 5 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 kernel/cpu/cpu_amd64.go rename kernel/{mem/vmm/tlb_amd64.s => cpu/cpu_amd64.s} (53%) delete mode 100644 kernel/mem/vmm/tlb.go diff --git a/kernel/cpu/cpu_amd64.go b/kernel/cpu/cpu_amd64.go new file mode 100644 index 0000000..4943fa2 --- /dev/null +++ b/kernel/cpu/cpu_amd64.go @@ -0,0 +1,11 @@ +package cpu + +// FlushTLBEntry flushes a TLB entry for a particular virtual address. +func FlushTLBEntry(virtAddr uintptr) + +// SwitchPDT sets the root page table directory to point to the specified +// physical address and flushes the TLB. +func SwitchPDT(pdtPhysAddr uintptr) + +// ActivePDT returns the physical address of the currently active page table. +func ActivePDT() uintptr diff --git a/kernel/mem/vmm/tlb_amd64.s b/kernel/cpu/cpu_amd64.s similarity index 53% rename from kernel/mem/vmm/tlb_amd64.s rename to kernel/cpu/cpu_amd64.s index 0f12a43..002c8cb 100644 --- a/kernel/mem/vmm/tlb_amd64.s +++ b/kernel/cpu/cpu_amd64.s @@ -1,15 +1,16 @@ - #include "textflag.h" - -TEXT ·flushTLBEntry(SB),NOSPLIT,$0 +#include "textflag.h" + +TEXT ·FlushTLBEntry(SB),NOSPLIT,$0 INVLPG virtAddr+0(FP) RET -TEXT ·switchPDT(SB),NOSPLIT,$0 +TEXT ·SwitchPDT(SB),NOSPLIT,$0 // loading CR3 also triggers a TLB flush MOVQ pdtPhysAddr+0(FP), CR3 RET -TEXT ·activePDT(SB),NOSPLIT,$0 +TEXT ·ActivePDT(SB),NOSPLIT,$0 MOVQ CR3, AX MOVQ AX, ret+0(FP) RET + diff --git a/kernel/mem/vmm/map.go b/kernel/mem/vmm/map.go index 4dfe64d..fc472da 100644 --- a/kernel/mem/vmm/map.go +++ b/kernel/mem/vmm/map.go @@ -4,6 +4,7 @@ import ( "unsafe" "github.com/achilleasa/gopher-os/kernel" + "github.com/achilleasa/gopher-os/kernel/cpu" "github.com/achilleasa/gopher-os/kernel/mem" "github.com/achilleasa/gopher-os/kernel/mem/pmm" ) @@ -18,7 +19,7 @@ var ( // flushTLBEntryFn is used by tests to override calls to flushTLBEntry // which will cause a fault if called in user-mode. - flushTLBEntryFn = flushTLBEntry + flushTLBEntryFn = cpu.FlushTLBEntry errNoHugePageSupport = &kernel.Error{Module: "vmm", Message: "huge pages are not supported"} ) diff --git a/kernel/mem/vmm/pdt.go b/kernel/mem/vmm/pdt.go index e60b336..68505cd 100644 --- a/kernel/mem/vmm/pdt.go +++ b/kernel/mem/vmm/pdt.go @@ -4,6 +4,7 @@ import ( "unsafe" "github.com/achilleasa/gopher-os/kernel" + "github.com/achilleasa/gopher-os/kernel/cpu" "github.com/achilleasa/gopher-os/kernel/mem" "github.com/achilleasa/gopher-os/kernel/mem/pmm" ) @@ -11,11 +12,11 @@ import ( var ( // activePDTFn is used by tests to override calls to activePDT which // will cause a fault if called in user-mode. - activePDTFn = activePDT + activePDTFn = cpu.ActivePDT // switchPDTFn is used by tests to override calls to switchPDT which // will cause a fault if called in user-mode. - switchPDTFn = switchPDT + switchPDTFn = cpu.SwitchPDT // mapFn is used by tests and is automatically inlined by the compiler. mapFn = Map diff --git a/kernel/mem/vmm/tlb.go b/kernel/mem/vmm/tlb.go deleted file mode 100644 index 703e597..0000000 --- a/kernel/mem/vmm/tlb.go +++ /dev/null @@ -1,11 +0,0 @@ -package vmm - -// flushTLBEntry flushes a TLB entry for a particular virtual address. -func flushTLBEntry(virtAddr uintptr) - -// switchPDT sets the root page table directory to point to the specified -// physical address and flushes the TLB. -func switchPDT(pdtPhysAddr uintptr) - -// activePDT returns the physical address of the currently active page table. -func activePDT() uintptr