// We are just too tired to convert this to assembler, so it's inline
// assembly of C....

unsigned char MEM48[6];
unsigned char GDT[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,    //GDT entry 0 (null segment)
0xFF,0xFF,0x00,0x00,0x00,0x92,0xCF,0xFF};   //GDT entry 1 (seg 0, limit 4GB)
void INITCPU32(void)
{
	asm mov MEM48[0],16
	asm mov eax,seg GDT
	asm shl eax,4
	asm mov bx,offset GDT
	asm movzx ebx,bx
	asm add eax,ebx
	asm mov dword ptr MEM48[2],eax
	asm lgdt pword ptr MEM48        //Load global descriptor table address

	asm mov bx,08h                  //Load bx to point to GDT entry 1
	asm push ds
	asm cli                         //Disable interrupts
	asm mov eax,cr0                 //Switch to protected mode 
	asm or eax,1
	asm mov cr0,eax                  
	asm jmp PROTECTION_ENABLED      //Clear executionpipe
	PROTECTION_ENABLED:
	asm mov gs,bx                   //Load segment shadow-registers
	asm mov fs,bx                   //with GDT entry 1 (4GB segment limit)
	asm mov es,bx
	asm mov ds,bx                   
	asm and al,0FEh                 //Switch back to real-mode without
	asm mov cr0,eax                 //resetting the CPU
	asm jmp PROTECTION_DISABLED     //Clear executionpipe
	PROTECTION_DISABLED:
	asm sti                         //Enable interrupts
	asm pop ds
}
