home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 3,899 of 4,675   
   wolfgang kern to Rick C. Hodgin   
   Re: Entering Protected Mode   
   01 Jul 19 06:30:08   
   
   From: nowhere@nospicedham.never.at   
      
   On 19.06.2019 17:25, Rick C. Hodgin wrote:   
   > In my custom OS kernel, I use this code to enter protected mode:   
   >   
   >      cli                               ; Clear interrupts   
   >      mov     eax,cr0   
   >      or      al,1   
   >      mov     cr0,eax   
   > ;; Ok, we're in protected mode, still 16-bit code segment though   
      
   Not at all!   
   it will remain in true real mode until change of CS [JMPF/RETF/IRET]   
      
   >      jmp     $+2                       ; Clear the cache   
   ^redundant^   
      
   >      lidt    fword ptr IDT_ptr         ; Load IDT   
   >      lgdt    fword ptr GDT_ptr         ; Load GDT   
      
   f..kword? I use 16:32 loads for both above   
   and I have LGDT run once during boot and LIDT in front of the CR0 change   
   to allow other mode switches use the same code.   
      
   >      xor     ax,ax   
   >      lldt    ax                        ; Load LDT with NULL   
      
   I don't care LDT because never used   
      
   >      mov     ax,_sTSS                  ; Load TR   
   >      ltr     ax   
   >    ; Data segment registers   
   >      mov     ax,_sDATA   
   >      mov     ds,ax   
   >      mov     es,ax   
   >    ; Extra segment registers   
   >      mov     ax,_sVGA   
   >      mov     fs,ax   
   >      mov     ax,_sMONO   
   >      mov     gs,ax   
   >    ; Stack   
   >      mov     ax,_sSTACK   
   >      mov     ss,ax   
   >      mov     esp,_sSTACK_limit - 4   
   >      sti   
      
   my setting: ds=es=fs=gs=4GB FLAT, ss=64K   
      
   > After this I push the new target address on the stack and issue   
   > a RETF to go there.   
      
   I do a JMP far imm 16:32 right after MOV CRo,eax.   
   __   
   wolfgang   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca