x86: add inline function to fetch cr2
Better to encapsulate asm operations in inline functions than embed directly in other C code. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
3f7ae0d749
commit
5b5bdb5fbd
|
@ -298,13 +298,12 @@ static void log_exception(uintptr_t vector, uintptr_t code)
|
|||
|
||||
static void dump_page_fault(z_arch_esf_t *esf)
|
||||
{
|
||||
uintptr_t err, cr2;
|
||||
|
||||
/* See Section 6.15 of the IA32 Software Developer's Manual vol 3 */
|
||||
__asm__ ("mov %%cr2, %0" : "=r" (cr2));
|
||||
uintptr_t err;
|
||||
void *cr2;
|
||||
|
||||
cr2 = z_x86_cr2_get();
|
||||
err = esf_get_code(esf);
|
||||
LOG_ERR("Page fault at address 0x%lx (error code 0x%lx)", cr2, err);
|
||||
LOG_ERR("Page fault at address %p (error code 0x%lx)", cr2, err);
|
||||
|
||||
if ((err & RSVD) != 0) {
|
||||
LOG_ERR("Reserved bits set in page tables");
|
||||
|
@ -325,7 +324,7 @@ static void dump_page_fault(z_arch_esf_t *esf)
|
|||
}
|
||||
|
||||
#ifdef CONFIG_X86_MMU
|
||||
z_x86_dump_mmu_flags(get_ptables(esf), (void *)cr2);
|
||||
z_x86_dump_mmu_flags(get_ptables(esf), cr2);
|
||||
#endif /* CONFIG_X86_MMU */
|
||||
}
|
||||
#endif /* CONFIG_EXCEPTION_DEBUG */
|
||||
|
|
|
@ -166,6 +166,21 @@ static inline pentry_t *z_x86_page_tables_get(void)
|
|||
return (pentry_t *)z_x86_cr3_get();
|
||||
}
|
||||
|
||||
/* Return cr2 value, which contains the page fault linear address.
|
||||
* See Section 6.15 of the IA32 Software Developer's Manual vol 3.
|
||||
* Used by page fault handling code.
|
||||
*/
|
||||
static inline void *z_x86_cr2_get(void)
|
||||
{
|
||||
void *cr2;
|
||||
#ifdef CONFIG_X86_64
|
||||
__asm__ volatile("movq %%cr2, %0\n\t" : "=r" (cr2));
|
||||
#else
|
||||
__asm__ volatile("movl %%cr2, %0\n\t" : "=r" (cr2));
|
||||
#endif
|
||||
return cr2;
|
||||
}
|
||||
|
||||
/* Kernel's page table. This is in CR3 for all supervisor threads.
|
||||
* if KPTI is enabled, we switch to this when handling exceptions or syscalls
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue