home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / misc / realmem.zip / REALINIT.C < prev    next >
Text File  |  1994-01-30  |  1KB  |  38 lines

  1. // We are just too tired to convert this to assembler, so it's inline
  2. // assembly of C....
  3.  
  4. unsigned char MEM48[6];
  5. unsigned char GDT[]={
  6. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    //GDT entry 0 (null segment)
  7. 0xFF,0xFF,0x00,0x00,0x00,0x92,0xCF,0xFF};   //GDT entry 1 (seg 0, limit 4GB)
  8. void INITCPU32(void)
  9. {
  10.     asm mov MEM48[0],16
  11.     asm mov eax,seg GDT
  12.     asm shl eax,4
  13.     asm mov bx,offset GDT
  14.     asm movzx ebx,bx
  15.     asm add eax,ebx
  16.     asm mov dword ptr MEM48[2],eax
  17.     asm lgdt pword ptr MEM48        //Load global descriptor table address
  18.  
  19.     asm mov bx,08h                  //Load bx to point to GDT entry 1
  20.     asm push ds
  21.     asm cli                         //Disable interrupts
  22.     asm mov eax,cr0                 //Switch to protected mode 
  23.     asm or eax,1
  24.     asm mov cr0,eax                  
  25.     asm jmp PROTECTION_ENABLED      //Clear executionpipe
  26.     PROTECTION_ENABLED:
  27.     asm mov gs,bx                   //Load segment shadow-registers
  28.     asm mov fs,bx                   //with GDT entry 1 (4GB segment limit)
  29.     asm mov es,bx
  30.     asm mov ds,bx                   
  31.     asm and al,0FEh                 //Switch back to real-mode without
  32.     asm mov cr0,eax                 //resetting the CPU
  33.     asm jmp PROTECTION_DISABLED     //Clear executionpipe
  34.     PROTECTION_DISABLED:
  35.     asm sti                         //Enable interrupts
  36.     asm pop ds
  37. }
  38.