X-Git-Url: http://git.dujemihanovic.xyz/posts?a=blobdiff_plain;f=boot.s;h=a40b7508781e9dbc59b82587e003f2ccca6a21f8;hb=c9f2bccb44c5437f1cae0862b2c84d3af47eade8;hp=eb115d0324dd6a2e8e83d94aee9d197d71299392;hpb=b85f8e94af0b9720083f5cd48092ead24e6004c3;p=nameless-os.git diff --git a/boot.s b/boot.s index eb115d0..a40b750 100644 --- a/boot.s +++ b/boot.s @@ -1,23 +1,135 @@ - bits 16 ; boot sectors run in real mode - org 7c00h ; boot sector is loaded at 0x7c00 + bits 16 + org 7C00h - mov di, printing_numbers - call print +KERNEL_OFFSET equ 1000h - mov dx, 0DEADh ; number to print - call print_word - mov dx, 0BEEFh - call print_word + mov [BOOT_DRIVE], dl - mov di, goodbye - call print + mov bp, 9000h + mov sp, bp + mov di, 0 + + xor ax, ax + int 13h + jc reset_error + + mov ah, 2 + mov al, 10 + xor ch, ch + mov cl, 2 + xor dh, dh + xor bx, bx + mov es, bx + mov bx, KERNEL_OFFSET + int 13h + jc read_error + cmp al, 10 + jl read_error + jmp switch_to_pm + +reset_error + mov bx, 0B800h + mov es, bx + mov byte [es:di], '1' + jmp halt + +read_error + mov bx, 0B800h + mov es, bx + mov byte [es:di], '2' + jmp halt + + call switch_to_pm + +halt jmp $ -printing_numbers: db "Printing some random hex numbers", 0 -goodbye: db "Thank you for your attention", 0 +switch_to_pm + mov bx, 0B800h + mov es, bx + mov byte [es:0], 'L' + + cli + xor ax, ax + mov ds, ax + lgdt [gdt_desc] + + mov eax, cr0 + or eax, 1 + mov cr0, eax + jmp CODE_SEG:protected + + bits 32 +protected + mov ax, DATA_SEG + mov ds, ax + mov ss, ax + mov es, ax + mov fs, ax + mov gs, ax + + mov ebp, 090000h + mov esp, ebp + + mov ebx, pm_success + call pmprint + + call KERNEL_OFFSET + + jmp $ + +pmprint + pusha + mov edx, video_memory + +.loop + mov al, [ebx] + mov ah, 0Fh + + cmp al, 0 + je .done + + mov [edx], al + mov [edx+1], ah + + inc ebx + add edx, 2 + + jmp .loop + +.done + popa + ret + +pm_success db "Now in protected mode", 0 +video_memory equ 0B8000h + +gdt_start +null_seg + dq 0 +code_seg + dw 0FFFFh + dw 0 + db 0 + db 10011010b + db 11001111b + db 0 +data_seg + dw 0FFFFh + dw 0 + db 0 + db 10010010b + db 11001111b + db 0 +gdt_end +gdt_desc + dw gdt_end - gdt_start - 1 + dd gdt_start +CODE_SEG equ code_seg - gdt_start +DATA_SEG equ data_seg - gdt_start -%include "print.s" +BOOT_DRIVE db 0 - times 510-($-$$) db 0 ; fill with 0 until 0x1fc is reached - dw 0AA55h ; BIOS MBR signature + times 510-($-$$) db 0 + dw 0AA55h