I'm learning/tinkering with kernel memory management on x86-64 linux. I wanted to look at the beginning of the page directory pointed to by cr3 using the asm code below but dereferencing cr3 causes the kernel to lock-up. What's the proper way to access what cr3 points to? Note I know I need to be in ring 0 hence the code is a small kernel module (kmod.S):
.globl init_module
.globl cleanup_module
.text
init_module:
nop
movq $ENTER_MSG, %rdi
movq %cr3, %rsi
movq (%rsi), %rdx
xorq %rax, %rax
callq printk
xorq %rax, %rax
retq
cleanup_module:
nop
movq $LEAVE_MSG, %rdi
xorq %rax, %rax
callq printk
retq
.section .rodata
ENTER_MSG:
.asciz "\n\nHELLO! CR3: %p, (CR3): %p\n"
LEAVE_MSG:
.asciz "GOODBYE!\n\n"
And compiled using the folling Makefile:
obj-m += kmodule.o
kmodule-objs := kmod.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean