From c5aa5fe05f931b324438ad917cd9387e90c0c515 Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Wed, 21 Jun 2017 18:18:29 +0100 Subject: [PATCH] Add method for reading the CR2 register value This will allow us to figure out the virtual address that caused a page- or general protection fault. --- kernel/cpu/cpu_amd64.go | 3 +++ kernel/cpu/cpu_amd64.s | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/kernel/cpu/cpu_amd64.go b/kernel/cpu/cpu_amd64.go index 7776082..c757266 100644 --- a/kernel/cpu/cpu_amd64.go +++ b/kernel/cpu/cpu_amd64.go @@ -18,3 +18,6 @@ func SwitchPDT(pdtPhysAddr uintptr) // ActivePDT returns the physical address of the currently active page table. func ActivePDT() uintptr + +// ReadCR2 returns the value stored in the CR2 register. +func ReadCR2() uint64 diff --git a/kernel/cpu/cpu_amd64.s b/kernel/cpu/cpu_amd64.s index 5ef45db..b654195 100644 --- a/kernel/cpu/cpu_amd64.s +++ b/kernel/cpu/cpu_amd64.s @@ -27,3 +27,7 @@ TEXT ·ActivePDT(SB),NOSPLIT,$0 MOVQ AX, ret+0(FP) RET +TEXT ·ReadCR2(SB),NOSPLIT,$0 + MOVQ CR2, AX + MOVQ AX, ret+0(FP) + RET