]> git.dujemihanovic.xyz Git - nameless-os.git/blob - boot/x86/old/boot.s
a7fe3c31ff1fb0f6cedf9a5fdd39f2718643dcac
[nameless-os.git] / boot / x86 / old / boot.s
1 bits 16 ; boot sectors run in real mode
2 org 7C00h ; BIOS loads us at 0x7c00
3
4 KERNEL_OFFSET equ 1000h ; where we will load our kernel
5
6 mov [BOOT_DRIVE], dl ; BIOS puts the number of our boot drive in dl, so we will want to remember this
7
8 mov bp, 9000h ; initialize stack at a spot sufficiently distanced from this code
9 mov sp, bp
10
11 mov di, 0
12
13 xor ax, ax ; clear accumulator
14 int 13h ; BIOS disk services, with a cleared accumulator this will reset the disk controller
15 jc reset_error ; halt if controller reset fails
16
17 mov ah, 2 ; instruct BIOS's interrupt 13h to read sectors
18 mov al, 30 ; load 30 sectors, might be excessive (for now) but it's still good to do so
19 xor ch, ch ; read from 1st cylinder
20 mov cl, 2 ; start reading from 2nd sector, right after the boot sector
21 xor dh, dh ; read from 1st head
22 xor bx, bx ; clear B register
23 mov es, bx ; clear extended segment
24 mov bx, KERNEL_OFFSET ; put the sectors in our desired offset
25 ; dl holds the number of the drive to read from, but BIOS already filled this in
26 int 13h ; do the read
27 jc read_error ; halt if read fails
28 cmp al, 10 ; make sure we actually read 10 sectors
29 jl read_error ; halt if we didn't
30
31 call check_a20
32 cmp ax, 1
33 jne a20_is_off
34
35 a20_is_on
36 jmp switch_to_pm
37 a20_is_off
38 call enable_a20
39 jmp switch_to_pm
40
41 reset_error
42 mov bx, 0B800h
43 mov es, bx
44 mov byte [es:di], '1'
45 jmp $
46
47 read_error
48 mov bx, 0B800h
49 mov es, bx
50 mov byte [es:di], '2'
51 jmp $
52
53 %include "a20.s"
54 %include "print.s"
55 %include "protected.s"
56
57 BOOT_DRIVE resb 1
58
59 times 510-($-$$) db 0
60 dw 0AA55h ; MBR signature