.section .multiboot .align 8 multiboot_header: .long 0xE85250D6 .long 0 .long multiboot_header_end - multiboot_header .long -(0xE85250D6 + 0 + (multiboot_header_end - multiboot_header)) .short 0 .short 0 .long 8 multiboot_header_end: .section .text.boot .code32 .global _start .type _start, @function .extern kmain _start: cli cld movl %eax, multiboot_magic movl %ebx, multiboot_info movl $__boot_stack_top, %esp /** * Bootstrap page tables * * PML4[0] = PML4[511] = PDPT * PDPT[0] = PDPT[510] = PD */ movl $pdpt_table, %eax orl $0x3, %eax movl %eax, pml4_table movl %eax, pml4_table + (511 * 8) movl $pd_table, %eax orl $0x3, %eax movl %eax, pdpt_table movl %eax, pdpt_table + (510 * 8) xorl %ecx, %ecx movl $pd_table, %edi .fill_pd: movl %ecx, %eax shll $21, %eax orl $0x83, %eax movl %eax, (%edi) addl $8, %edi incl %ecx cmpl $512, %ecx jne .fill_pd movl $pml4_table, %eax movl %eax, %cr3 movl %cr4, %eax orl $0x20, %eax movl %eax, %cr4 movl $0xC0000080, %ecx rdmsr orl $0x900, %eax wrmsr movl %cr0, %eax orl $0x80000001, %eax movl %eax, %cr0 lgdt gdt_descriptor ljmp $0x08, $long_mode_entry .code64 enable_sse: movq %cr0, %rax andw $0xFFFB, %ax orw $0x0002, %ax movq %rax, %cr0 movq %cr4, %rax orw $0x600, %ax movq %rax, %cr4 ret long_mode_entry: movw $0x10, %ax movw %ax, %ds movw %ax, %es movw %ax, %ss movw %ax, %fs movw %ax, %gs movq $__boot_stack_top, %rsp andq $-16, %rsp xorq %rbp, %rbp call run_global_constructors call enable_sse movabs $kmain, %rax jmp *%rax .hang: cli hlt jmp .hang .extern __init_array_start .extern __init_array_end run_global_constructors: pushq %rbp movq %rsp, %rbp movq $__init_array_start, %rax .constructor_loop: cmpq $__init_array_end, %rax jae .constructors_done movq (%rax), %rdx call *%rdx addq $8, %rax jmp .constructor_loop .constructors_done: popq %rbp ret .align 8 gdt: .quad 0x0000000000000000 .quad 0x00AF9A000000FFFF .quad 0x00AF92000000FFFF gdt_end: gdt_descriptor: .word gdt_end - gdt - 1 .long gdt .section .bss.boot .align 8 .global multiboot_magic multiboot_magic: .quad 0 .global multiboot_info multiboot_info: .quad 0 .align 4096 pml4_table: .skip 4096 .align 4096 pdpt_table: .skip 4096 .align 4096 pd_table: .skip 4096 .section .stack.boot, "aw", @nobits .align 16 .global __boot_stack_bottom __boot_stack_bottom: .skip 16384 .global __boot_stack_top __boot_stack_top: