; GASM GDT Example by Gareth Owen. gaz@athene.co.uk
; This is a boot sector, so you will need to write it to
; the first sector of a disk, all it does is set the 
; top left hand character to 'h'...
; Its very easy to turn that into a print function

[ORG  0x7C00]

	cli				;{0}
n5:	in	al, 0x64		;Enable A20 {4A} {5}
	test	al, 2
	jnz	n5
	mov	al, 0xD1
	out	0x64, al
n6:	in	al, 0x64
	test	al, 2
	jnz	n6
	mov	al, 0xDF
	out	0x60, al
        lgdt    [gdtinfo]               ;Load GDT
	mov	ecx, CR0		;Switch to protected mode
	inc	cx
	mov	CR0, ecx


	mov	ax, flat_data-gdt_table	;Selector for 4Gb data seg
	mov	ds, ax			;{2} Extend limit for ds
	mov	es, ax			;Extend limit for es

	mov esi, 0xB8000
        mov byte [esi], 'h'
        mov byte [esi+1], 0x07
	


hang:
jmp word hang

gdtinfo:

dw	gdtlength
dd	gdt_table
dw	0

gdt_table:

null_desc	desc	0,0,0

flat_code	desc	0, 0xFFBFF, D_CODE+D_READ+D_BIG+D_BIG_LIM

flat_data	desc	0, 0xFFFFF, D_DATA+D_WRITE+D_BIG+D_BIG_LIM

gdtlength equ $ - gdt_table - 1

times 510-($-0x7c00) db 0
dw 0xAA55