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