.code16 .text .global _start _start: jmp everything .org 20 .global kernel_size kernel_size: .long _end - _start everything: mov $0x1000, %ax mov %ax, %es mov %ax, %ds # reset disk mov $0, %ah int $0x13 # stop the cursor mov $1, %ah mov $0,%cl mov $0x20,%ch int $0x11 # get the system memory, if this call fails then halt clc mov $0, %bx mov $0xe801, %ax int $0x15 jc halt shr $10, %ax shr $4, %bx add %ax, %bx mov %bx, total_mem_mb-_start # vga text mode mov $0x0003, %ax int $0x10 enable_a20: #enable the a20 gate inb $0x92, %al orb $2, %al outb %al, $0x92 prep_protected: cli lgdt (gdt_init-_start) mov %cr0, %eax or $0x01, %eax mov %eax, %cr0 # protected bit set ljmpl $8, $protected halt16: jmp halt16 .code32 protected: mov $2*8, %ax mov %ax, %es mov %ax, %ds mov %ax, %ss mov $5*8, %ax ltr %ax mov $0, %ax mov %ax, %fs mov %ax, %gs mov $0xFFF0, %sp mov $0xFFF0, %bp ljmpl $8, $kmain .align 4 .global video_info_struct video_info_struct: .word 0 .byte 0,0 .word 0,0,0,0 .long 0 .global video_xbytes video_xbytes: .word 0 .global video_xres video_xres: .word 0 .global video_yres video_yres: .word 0 .byte 0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0 .global video_buffer video_buffer: .long 0 .long 0 .word 0 .word 0 .byte 0,0,0,0,0,0,0,0,0,0 .long 0 .rept 190 .byte 0 .endr # some assembly stubs we can call from the kernel .global idt_load .extern idtr idt_load: lidt (idtr) ret .global gdt_load gdt_load: lgdt (gdt_init) ret .global reboot reboot: cli lidt reboot_struct int $1 reboot_struct: .word 0 .long 0 .global halt halt: cli hlt jmp halt # kernel data structures .align 16 .global gdt gdt: .word 0,0,0,0 .word 0xffff, 0x0000, 0x9a00, 0x00cf .word 0xffff, 0x0000, 0x9200, 0x00cf .word 0xffff, 0x0000, 0xfa00, 0x00cf .word 0xffff, 0x0000, 0xf200, 0x00cf .word 0x0068, (tss-_start), 0x8901, 0x00cf gdt_init: .word gdt_init-gdt .long gdt .align 16 .global tss tss: .long 0 .global total_mem_mb total_mem_mb: .word 0