]> git.lizzy.rs Git - loadnothing.git/blob - stage1/boot.asm
Init more registers
[loadnothing.git] / stage1 / boot.asm
1 [bits 16]
2 [org 0x7c00]
3
4 %define STAGE2START 0x7e00
5 %define STAGE2SIZE 0xFF
6
7 ; Initialize registers
8 xor ax, ax
9 mov ds, ax
10 mov es, ax
11 mov fs, ax
12 mov gs, ax
13 mov ss, ax
14
15 jmp boot
16
17 ; Print al register
18 print_al:
19         mov ah, 0x0e ; TTY output
20         mov bh, 0x00 ; Page 0
21         mov bl, 0x07 ; Color: Light grey on black background
22         int 0x10
23
24         ret
25
26 ; Call print_al on all characters in si
27 ; si must be null terminated
28 print_bytes_si:
29         mov cl, 0 ; Start with iteration 0 - equivalent of int i = 0
30 print_bytes_si_loop:
31         lodsb                  ; Load next characet of si into al
32         call print_al
33
34         inc cl
35
36         cmp cl, ch
37         jb print_bytes_si_loop
38
39         ret
40
41 stage2_error:
42         mov ch, 33          ; Our string is 33 characters long
43         mov si, error
44         call print_bytes_si
45
46         jmp $               ; Infinite loop
47
48 ; Main
49 boot:
50         ; Clear the screen
51         mov ah, 0x06
52         mov al, 0x00
53         mov bh, 0x07
54         mov ch, 0x00
55         mov cl, 0x00
56         mov dh, 0xff
57         mov dl, 0xff
58         int 0x10
59
60         ; Move cursor to 0, 0 on page 0
61         mov ah, 0x02
62         mov bh, 0           ; Page
63         mov dh, 0           ; Row
64         mov dl, 0           ; Column
65         int 0x10
66
67         mov ch, 33          ; Our string is 33 characters long
68         mov si, hello
69         call print_bytes_si
70
71         mov ah, 0x02        ; Read sectors
72         mov al, STAGE2SIZE  ; Stage 2 size (16 MiB) in sectors
73         xor ch, ch          ; Cylinder 0
74         mov cl, 2           ; Second sector, they start at 1
75         xor dh, dh          ; Head 0
76         xor dl, dl          ; Drive 0
77         mov bx, STAGE2START ; Memory address to load stage 2 into
78         int 0x13
79
80         jc stage2_error     ; Carry flag is set if there was an error
81
82         cmp al, STAGE2SIZE  ; Have we read as many sectors as we requested?
83         jne stage2_error
84
85         jmp STAGE2START     ; Hand over control to stage 2
86
87 hello db 'Welcome to loadnothing stage 1!', 13, 10 ; \r\n
88 error db 'Error reading stage 2 from disk', 13, 10 ; \r\n
89
90 times (446 - ($ - $$)) db 0x00