I'm now working on code for initializing MMU handler (I did it in assembly with my 32-bit kernel without problem, but now I want to do it in C).
and I have something like this:
Code: Select all
// add page structures for foo_ptr to SOME_ADDRESS
// flush CR3
_MOVCR3 (KADDR_PMA(k_PML4E));
//kprintf ("foo\n");
uint64_t* foo_ptr = (uint64_t*) SOME_ADDRESS;
foo_ptr[0] = 1;
kprintf ("bar\n");
If I put kprintf("foo") there, gcc put the statements in the expected order, and the write is succeeded.
So, what's the proper way to ensure code dependency is followed and avoid too aggressive optimization?