mem.c: Clean up page table walk logic

Convert the ugly hardcoded addresses to a function which shifts the
entries to the correct positions. Also makes the code slightly more
robust against the recursive mapping number changing.