;============================================================================
; Mobur Technologies
; Protected Mode Switching Sample
; by Philip Eastman
;============================================================================

.386p

;----------------------------------------------------------------------------
codeSegment	segment	use16
		assume	cs:codeSegment

mainStack	dw	100h dup(0)

nullDescriptor	dq	0

textDescriptor	dq	0000920b8000ffffh

gdtRegister	dw      10h
		dd	0

;============================================================================
mainProgramme:  mov	ax,cs
		mov	ds,ax
		mov	es,ax
		mov	ss,ax
		xor	sp,sp

		xor	eax,eax
		mov     ax,cs
		shl	eax,4
		add	eax,offset nullDescriptor
		mov	dword ptr gdtRegister[2], eax

		cli

		lgdt	fword ptr gdtRegister

		mov	eax,cr0
		or	al,1
		mov	cr0,eax
		jmp	far ptr protectedMode

protectedMode:	mov	ax,8
		mov	ds,ax
		mov	byte ptr ds:[0],'P'

		mov	eax,cr0
		and	al,0feh
		mov	cr0,eax
		jmp	far ptr realMode

realMode:	mov	ax,4c00h
		int	21h
codeSegment	ends
		end	mainProgramme
