added README and license
[bootcensus] / src / boot / boot2.s
1 # pcboot - bootable PC demo/game kernel
2 # Copyright (C) 2018  John Tsiombikas <nuclear@member.fsf.org>
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17 # this is the second-stage boot loader
18         .code16
19         .section .boot2,"a"
20
21         .extern ser_putchar
22
23         mov $0x13, %ax
24         int $0x10
25
26         movb $10, %al
27         call ser_putchar
28
29         # copy palette
30         mov $logo_pal, %si
31         xor %cl, %cl
32
33 0:      xor %eax, %eax
34         mov $0x3c8, %dx
35         movb %cl, %al
36         outb %al, %dx
37         #### DBG
38         call ser_print_num
39         mov $58, %al
40         call ser_putchar
41         mov $32, %al
42         call ser_putchar
43         xor %eax, %eax
44         ####
45         inc %dx
46         # red
47         movb (%si), %al
48         inc %si
49         shr $2, %al
50         outb %al, %dx
51         #### DBG
52         call ser_print_num
53         mov $32, %al
54         call ser_putchar
55         xor %eax, %eax
56         ####
57         # green
58         movb (%si), %al
59         inc %si
60         shr $2, %al
61         outb %al, %dx
62         #### DBG
63         call ser_print_num
64         mov $32, %al
65         call ser_putchar
66         xor %eax, %eax
67         ####
68         # blue
69         movb (%si), %al
70         inc %si
71         shr $2, %al
72         outb %al, %dx
73         #### DBG
74         call ser_print_num
75         mov $32, %al
76         call ser_putchar
77         mov $10, %al
78         call ser_putchar
79         xor %eax, %eax
80         ####
81         add $1, %cl
82         jnc 0b
83
84         # copy pixels
85         pushw $0xa000
86         pop %es
87         xor %di, %di
88         mov $logo_pix, %eax
89         shr $4, %eax
90         mov %ax, %ds
91         xor %si, %si
92         mov $16000, %ecx
93         rep movsl
94
95         cli
96         hlt
97
98         # expects string pointer in ds:si
99 ser_print_str:
100         pusha
101
102 0:      mov (%si), %al
103         cmp $0, %al
104         jz .Lend
105         call ser_putchar
106         inc %si
107         jmp 0b
108
109 .Lend:  popa
110         ret
111
112
113         # expects number in eax
114 ser_print_num:
115         # save registers
116         pusha
117
118         movw $numbuf + 16, %si
119         movb $0, (%si)
120         mov $10, %ebx
121 .Lconvloop:
122         xor %edx, %edx
123         div %ebx
124         add $48, %dl
125         dec %si
126         mov %dl, (%si)
127         cmp $0, %eax
128         jnz .Lconvloop
129
130         call ser_print_str
131
132         # restore regs
133         popa
134         ret
135
136 numbuf: .space 16
137
138 logo_pal:
139         .incbin "logo.pal"
140
141         .align 16
142 logo_pix:
143         .incbin "logo.raw"