initial commit
[bootsplash] / bootsplash.asm
1         org 7c00h
2         bits 16
3
4 stacktop equ 7b00h
5 boot_driveno equ 7b00h  ; 1 byte
6 stage2_size equ stage2_end - stage2_start
7
8 start:
9         xor ax, ax
10         mov ds, ax
11         mov es, ax
12         mov ss, ax
13         mov gs, ax
14         mov fs, ax
15
16         mov sp, stacktop
17         mov [boot_driveno], dl
18
19         ; load the rest of the code at 7e00
20         xor ax, ax
21         mov es, ax
22         mov bx, stage2_start
23         mov ah, 2               ; read sectors LBA call
24         mov al, (stage2_size + 511) / 512  ; num sectors
25         mov cx, 2               ; ch: cylinder, cl: sector
26         xor dx, dx              ; dh: head
27         mov dl, [boot_driveno]
28         int 13h
29         jnc stage2_start        ; loaded successfully, jump to it
30
31         ; failed to load second sector
32         mov ax, str_load_fail
33         call printstr
34 .hang:  cli
35         hlt
36         jmp .hang
37
38         ; expects string ptr in ax
39 printstr:
40         mov bx, ax
41 .loop:  mov al, [bx]
42         inc bx
43         test al, al
44         jz .done
45         mov ah, 0eh
46         mov bx, 7
47         int 10h
48         jmp .loop
49 .done:  ret
50
51 str_load_fail db "Failed to load second stage!",0
52 str_foo db "Loaded 2nd stage boot loader",0
53
54
55         times 510-($-$$) db 0
56         dw 0xaa55
57
58         ; start of the second stage
59 stage2_start:
60         mov ax, 13h
61         int 10h
62
63         mov ax, 0a000h
64         mov es, ax
65         xor di, di
66         mov cx, 32000
67         mov ax, 0505h
68         rep stosw
69
70         call waitkey
71
72         mov ax, 3
73         int 10h
74
75         xor ax, ax
76         mov es, ax
77
78         mov ax, str_foo
79         call printstr
80
81 .hang:  cli
82         hlt
83         jmp .hang
84
85 waitkey:
86         in al, 64h
87         test al, 1
88         jz waitkey
89         in al, 60h
90         ret
91
92 stage2_end:
93
94 ; vi:set ft=nasm: