From: james.harris.1@gmail.com   
      
   On 14/12/2022 13:35, Dan Cross wrote:   
   > In article ,    
   wrote:   
   >> Dan Cross wrote:   
   >>> In article <34818e6d-23a5-4c02-a6ef-6dfeaaf1ce3fn@googlegroups.com>,   
      
   ...   
      
   >>>> Didn't know it needs to JMP to a new line of code after it, I thought the   
   jump at   
   >>>> the end of the scope of the function is enough, but it makes a lot of   
   sense I should identity-map the kernel's code into virtual mode. But I   
   >>>> reckon it's not my only problem there.   
   >>>   
   >>> This is for x86, but the same principle applies generally: once   
   >>> you turn on paging by setting the PG bit in %cr0, the next   
   >>> instruction must necessarily come from an address that is mapped   
   >>> in the address space described by the page tables that you are   
   >>> pointing to in %cr3. There is no jumping around permitted; the   
   >>> next instruction is either mapped or you get a page fault.   
   >>>   
   >>> Perhaps you were thinking of a long-jump between segments?   
   >>> Once you're turning on 32-bit paging, that's not generally at   
   >>> play anymore.   
   >>   
   >> 386 is special here: one have to jump to make sure that processor   
   >> view of state of the world is consistent. And yes, page tables   
   >> have to be correctly set up with 1-1 mapping of currently   
   >> executing code.   
   >   
   > You're referring to section 10.4.4 of the 80386 Programmer's   
   > Reference Manual? Such language is absent in the current Intel   
   > SDM (it was dropped when the 486 came out) when describing   
   > paging in 32-bit mode, and it is not clear that OP is   
   > targetting an actual 80386. Certainly, adding a `jmp 1f; 1:`   
   > isn't going to hurt, but it is not necessary on any Intel or   
   > AMD microprocessor manufactured in the last 30 years, even in   
   > 32-bit mode.   
      
   For ref, here's that section:   
      
    https://www.scs.stanford.edu/05au-cs240c/lab/i386/s10_04.htm   
      
   Certainly the 386 required identity mapping OR a jump (or both) whereas   
   the 486 needed both.   
      
   The Pentium Architecture and Programming Manual, Order Number 241430 says:   
      
   "The 32-bit Intel architectures have different requirements for enabling   
   paging and switching to protected mode. The Intel386 processor requires   
   following steps 1 [jump] or 2 [identify mapping] above. The Intel486   
   processor requires following both steps 1 and 2 above. The Pentium   
   processor requires only step 2 but for upwards and downwards code   
   compatibility with the Intel386 and Intel486 processors, it is   
   recommended both steps 1 and 2 be taken."   
      
      
   --   
   James Harris   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|