.code16
.org 0

movw	$0x07C0, %ax
movw	%ax, %ds

movw	$0x8000, %ax
movw	%ax, %ss
movw	$0xF000, %sp

mov	%dl, (bootdrv)

mov	$0x3, %ax
int	$0x10
	
xor	%ax, %ax
int	$0x13

push	%es	
mov	$0x100, %ax
mov	%ax, %es
mov	$0, %bx

mov	$0x02, %ah
mov	$50, %al
mov	$0, %ch
mov	$2, %cl
mov	$0, %dh
mov 	(bootdrv), %dl
int	$0x13
pop	%es	
	
cli
lgdt	(gdtr)
movl	%cr0, %eax
orl	$1, %eax
movl	%eax, %cr0
	
jmp	flush
flush:
	
movw	$0x10, %ax
movw	%ax, %ds
movw	%ax, %es
movw	%ax, %fs
movw	%ax, %gs
movw	%ax, %ss
	
movl	%ebx, %eax
lcall	$0x08, $0x1000
#jmp	$0x08:0x1000

	
bootdrv:
	.byte 0
gdt:
	.byte 0, 0, 0, 0, 0, 0, 0, 0
gdt_cs:
	.byte 0xFF, 0xFF, 0x0, 0x0, 0x0, 0b10011011, 0b11011111, 0x0
gdt_ds:
	.byte 0xFF, 0xFF, 0x0, 0x0, 0x0, 0b10010011, 0b11011111, 0x0
gdtend:

gdtr:
	.word 3 * 8 - 1
gdtr_addr:
	.long gdt + 0x7C00
gdtrend:

.org	0x1fe, 0x90
.word 0xAA55