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