From d553d38ecf33c652f9d066b95209ce9d48aaa897 Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Thu, 12 Mar 2015 09:20:30 +0100 Subject: [PATCH] hw_x86_64: Model cr2 register in CPU state Make the cr2 control register accessible in the Cpu class. The register is needed to retrieve the linear address that caused a page fault. --- repos/base-hw/src/core/include/spec/x86/cpu.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/repos/base-hw/src/core/include/spec/x86/cpu.h b/repos/base-hw/src/core/include/spec/x86/cpu.h index 3ab736fc1..72f240909 100644 --- a/repos/base-hw/src/core/include/spec/x86/cpu.h +++ b/repos/base-hw/src/core/include/spec/x86/cpu.h @@ -64,6 +64,23 @@ class Genode::Cpu static constexpr addr_t exception_entry = 0x0; /* XXX */ static constexpr addr_t mtc_size = 1 << 13; + /** + * Control register 2: Page-fault linear address + * + * See Intel SDM Vol. 3A, section 2.5. + */ + struct Cr2 : Register<64> + { + struct Addr : Bitfield<0, 63> { }; + + static access_t read() + { + access_t v; + asm volatile ("mov %%cr2, %0" : "=r" (v) :: ); + return v; + } + }; + /** * Control register 3: Page-Directory base register *