.set ALIGN,    1<<0
.set MEMINFO,  1<<1
.set GRAPHICS, 1<<2

.set FLAGS,    ALIGN | MEMINFO | GRAPHICS 
.set MAGIC,    0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)

.section .multiboot, "a"
	.align 4
	.long MAGIC
	.long FLAGS
	.long CHECKSUM

	.long 0   /* header_addr */
    .long 0   /* load_addr */
    .long 0   /* load_end_addr */
    .long 0   /* bss_end_addr */
    .long 0   /* entry_addr */

	.long 0     /* Mode Type: 0 = Linear Framebuffer, 1 = Standard EGA Text */
    .long 1024  /* Width (Pixels) */
    .long 768   /* Height (Pixels) */
    .long 32    /* Color Depth (Bits Per Pixel) */

.section .text
.global _start
_start:
	cli

	mov $(page_directory - 0xC0000000), %ecx

	mov %cr4, %edx
    or $0x00000010, %edx
    mov %edx, %cr4

	mov %ecx, %cr3

	mov %cr0, %edx
    or $0x80000000, %edx
    mov %edx, %cr0

	lea higher, %ecx
    jmp *%ecx
higher:
	mov $stack_top, %esp
	mov $0xC0000000, %eax
	add %eax, %ebx
	push %ebx
	call kmain
loop:
	hlt
	jmp loop

.section .bss
.align 16
stack_bottom:
.skip 16384 # 16 KiB
stack_top:

.section .data, "a"
.align 4096
.global page_directory
page_directory:
	.long 0x00000083
	.skip 3068
	.long 0x00000083
	.skip 1016
	.long (page_directory - 0xC0000000) + 0x03