1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Move TLB-handling code to the cpu pkg

This commit is contained in:
Achilleas Anagnostopoulos 2017-06-21 07:57:05 +01:00
parent 3923e09aac
commit d793300279
5 changed files with 22 additions and 19 deletions

11
kernel/cpu/cpu_amd64.go Normal file
View File

@ -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

View File

@ -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

View File

@ -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"}
)

View File

@ -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

View File

@ -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