.intel_syntax noprefix .code16 .extern _stack_start .extern _stack_end .global stage1_sector .section .stage1, "ax" stage1_sector: xor ax, ax mov ah, 0x0e mov al, 'C' mov bh, 0x0 mov bl, 0x0 int 0x10 cli lgdt gdtr mov eax, cr0 or eax, (1 << 0) mov cr0, eax jmp 0x8:_32_start cli hlt .code32 _32_start: mov eax, 0x10 mov ds, ax mov ss, ax mov es, ax mov fs, ax mov gs, ax jmp 0x8:_32_entry cli hlt _32_entry: mov eax, offset _stack_start mov ebp, eax mov eax, offset _stack_end mov esp, eax call centry cli hlt .code16 .section .stage1_ro, "aw" gdt: .quad 0x0 // Null seg .word 0xFFFF // Code seg .word 0x0000 .byte 0x0 .byte 0b10011011 // A=1 RW=1 DC=0 E=1 S=1 DPL=00 P=1 .byte 0b11001111 .byte 0x0000 .word 0xFFFF // Data Seg .word 0x0000 .byte 0x0 .byte 0b10010011 // A=1 RW=1 DC=0 E=0 S=1 DPL=00 P=1 .byte 0b11001111 .byte 0x0000 end_gdt: gdtr: .word end_gdt - gdt - 1 .long gdt