.section .bootstrap_stack, "aw", @nobits stack_bottom: .skip 16384 stack_top: .section .bss, "aw", @nobits .align 4096 page_directory: .skip 4096 page_table1: .skip 4096 page_table2: .skip 4096 .set P, 1<<0 .set RW, 1<<1 .set FLAGS, P | RW .set KERNEL_VM, 0xC0000000 .section .multiboot.text, "a" .global _start .type _start, @function _start: _start: cli mov $stack_top - KERNEL_VM, %esp pushl %eax pushl %ebx movl $page_table1 - KERNEL_VM + FLAGS, page_directory - KERNEL_VM + 0 * 4 movl $page_table2 - KERNEL_VM + FLAGS, page_directory - KERNEL_VM + 1 * 4 movl $page_table1 - KERNEL_VM + FLAGS, page_directory - KERNEL_VM + 768 * 4 movl $page_table2 - KERNEL_VM + FLAGS, page_directory - KERNEL_VM + 769 * 4 mov $0, %ecx not_done: mov $0x1000, %eax mul %ecx orl $FLAGS, %eax mov %eax, %edi // page_table1[%ecx] = 0x1000 * %ecx | 0x3 mov $4, %eax mul %ecx add $page_table1 - KERNEL_VM, %eax movl %edi, (%eax) // page_table2[%ecx] = 0x1000 * %ecx | 0x3 mov $4, %eax mul %ecx add $1024 * 0x1000, %edi add $page_table2 - KERNEL_VM, %eax movl %edi, (%eax) inc %ecx cmp $1024, %ecx je done jmp not_done done: movl $(page_directory - KERNEL_VM), %ecx movl %ecx, %cr3 movl %cr0, %ecx orl $0x80001000, %ecx movl %ecx, %cr0 lea 7f, %ecx jmp *%ecx .section .boot32.rodata gdt: gdt_null = . - gdt .quad 0 kernel_code = . - gdt .long 0xFFFF .byte 0 .byte 0x9A .byte 0xCF .byte 0 kernel_data = . - gdt .long 0xFFFF .byte 0 .byte 0x92 .byte 0xCF .byte 0 user_code = . - gdt .long 0xFFFF .byte 0 .byte 0xFA .byte 0xCF .byte 0 user_data = . - gdt .long 0xFFFF .byte 0 .byte 0xF2 .byte 0xCF .byte 0 .global gdtp gdtp: .word . - gdt - 1 .long gdt .section .text 7: addl $KERNEL_VM, %esp lgdtl gdtp ljmp $0x08, $code code: movw $0x10, %ax movw %ax, %ds movw %ax, %es movw %ax, %fs movw %ax, %gs movw %ax, %ss call kernel_main hlt