assemblyx86pagingosdevprotected-mode

Why must the MOV CR0 and JMP instructions come from a page that is identity mapped while switching to protected mode?


why we have to put the mov cr0 and jmp instructions into a page that is identity mapped?

I have been using Google to search this question but I am not able to understand the results.


Solution

  • When enabling protected mode (and not enabling paging); you don't need to make sure the page is identity mapped.

    When enabling paging (possibly while also enabling protected mode) the CPU will try to fetch the next instruction after the mov cr0 from the (virtual) address after the mov cr0. The easiest way to deal with this is to identity map the page, so that the instruction after the mov cr0 in physical memory will also be the instruction after the mov cr0 in virtual memory. However; this is not strictly required. For example, if you arrange for the mov cr0 to be in the very last bytes of a page (so that the instruction executed immediately after paging is enabled will be at the start of a different page) the page containing the mov cr0 won't need to be identity mapped and the next page won't need to be identity mapped either.