I am trying to write directly to a physical memory location, so I am using an assembly function to first disable paging, write the value, and then re-enable paging, but for some reason a page fault is still triggered when trying to write the value.
As I understand it, in x86-32bit, paging is set on and off by flipping bit 32 in cr0, so here is my assembly function:
mov 4(%esp), %ecx //address
mov 8(%esp), %edx //value
mov %cr0, %eax
and $0x7fffffff, %eax
mov %eax, %cr0
mov %edx, (%ecx) //this line still triggers a page fault somehow
or $0x80000000, %eax
mov %eax, %cr0
ret
Is this the correct way to achieve what I am wanting to do? If so, why is a page fault still being triggered with the bit in cr0 flipped?
/dev/mem
orDevice\PhysicalMemory
) or a function provided by the kernel.BTW, It seems (I'm not used to AT&T syntax) that you inverted value an address in your code. – NeitsaEIP
is a physical address. Have you single-stepped this inbochs
or something to see exactly what is going on when you get the fault? – Peter Cordes