second stage boot loader now loads the main program
[bootcensus] / src / startup.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         .code32
18         .section .startup,"ax"
19
20         .extern _bss_start
21         .extern _bss_end
22
23         # zero the BSS section
24         xor %eax, %eax
25         mov _bss_start, %edi
26         mov _bss_size, %ecx
27         jz skip_bss_zero
28         shr $4, %ecx
29         rep stosl
30 skip_bss_zero:
31
32
33 logohack:
34         # copy palette
35         mov $logo_pal, %esi
36         xor %cl, %cl
37
38 0:      xor %eax, %eax
39         mov $0x3c8, %dx
40         movb %cl, %al
41         outb %al, %dx
42         inc %dx
43         # red
44         movb (%esi), %al
45         inc %esi
46         shr $2, %al
47         outb %al, %dx
48         # green
49         movb (%esi), %al
50         inc %esi
51         shr $2, %al
52         outb %al, %dx
53         # blue
54         movb (%esi), %al
55         inc %esi
56         shr $2, %al
57         outb %al, %dx
58         add $1, %cl
59         jnc 0b
60
61         # copy pixels
62         mov $sintab, %ebp
63         mov $logo_pix, %esi
64 frameloop:
65         mov $0xa0000, %edi
66         movl $0, yval
67 yloop:
68         movl $0, xval
69 xloop:
70         # calc src scanline address -> ebx
71         xor %ecx, %ecx
72         mov yval, %ebx
73         shl $2, %ebx
74         add frameno, %ebx
75         and $0xff, %ebx
76         mov (%ebp, %ebx), %cl
77         shr $5, %ecx
78
79         mov yval, %eax
80         add %ecx, %eax
81         # bounds check
82         cmp $200, %eax
83         jl 0f
84         mov $199, %eax
85
86 0:      mov %eax, %ebx
87         shl $8, %eax
88         shl $6, %ebx
89         add %eax, %ebx
90
91         # calc src x offset -> eax
92         xor %ecx, %ecx
93         mov xval, %eax
94         shl $2, %eax
95         add frameno, %eax
96         and $0xff, %eax
97         mov (%ebp, %eax), %cl
98         shr $5, %ecx
99
100         mov xval, %eax
101         add %ecx, %eax
102         # bounds check
103         cmp $320, %eax
104         jl 0f
105         mov $319, %eax
106
107 0:      add %eax, %ebx
108         mov (%ebx, %esi), %al
109
110         mov %al, (%edi)
111         inc %edi
112
113         incl xval
114         cmpl $320, xval
115         jnz xloop
116
117         incl yval
118         cmpl $200, yval
119         jnz yloop
120
121         incl frameno
122
123         # wait vsync
124         mov $0x3da, %dx
125 0:      in %dx, %al
126         and $8, %al
127         jnz 0b
128 0:      in %dx, %al
129         and $8, %al
130         jz 0b
131         jmp frameloop
132
133 xval: .long 0
134 yval: .long 0
135 frameno: .long 0
136
137 logo_pal:
138         .incbin "logo.pal"
139
140         .align 16
141 logo_pix:
142         .incbin "logo.raw"
143
144 sintab:
145         .byte 127
146         .byte 130
147         .byte 133
148         .byte 136
149         .byte 139
150         .byte 143
151         .byte 146
152         .byte 149
153         .byte 152
154         .byte 155
155         .byte 158
156         .byte 161
157         .byte 164
158         .byte 167
159         .byte 170
160         .byte 173
161         .byte 176
162         .byte 179
163         .byte 182
164         .byte 184
165         .byte 187
166         .byte 190
167         .byte 193
168         .byte 195
169         .byte 198
170         .byte 200
171         .byte 203
172         .byte 205
173         .byte 208
174         .byte 210
175         .byte 213
176         .byte 215
177         .byte 217
178         .byte 219
179         .byte 221
180         .byte 224
181         .byte 226
182         .byte 228
183         .byte 229
184         .byte 231
185         .byte 233
186         .byte 235
187         .byte 236
188         .byte 238
189         .byte 239
190         .byte 241
191         .byte 242
192         .byte 244
193         .byte 245
194         .byte 246
195         .byte 247
196         .byte 248
197         .byte 249
198         .byte 250
199         .byte 251
200         .byte 251
201         .byte 252
202         .byte 253
203         .byte 253
204         .byte 254
205         .byte 254
206         .byte 254
207         .byte 254
208         .byte 254
209         .byte 255
210         .byte 254
211         .byte 254
212         .byte 254
213         .byte 254
214         .byte 254
215         .byte 253
216         .byte 253
217         .byte 252
218         .byte 251
219         .byte 251
220         .byte 250
221         .byte 249
222         .byte 248
223         .byte 247
224         .byte 246
225         .byte 245
226         .byte 244
227         .byte 242
228         .byte 241
229         .byte 239
230         .byte 238
231         .byte 236
232         .byte 235
233         .byte 233
234         .byte 231
235         .byte 229
236         .byte 228
237         .byte 226
238         .byte 224
239         .byte 221
240         .byte 219
241         .byte 217
242         .byte 215
243         .byte 213
244         .byte 210
245         .byte 208
246         .byte 205
247         .byte 203
248         .byte 200
249         .byte 198
250         .byte 195
251         .byte 193
252         .byte 190
253         .byte 187
254         .byte 184
255         .byte 182
256         .byte 179
257         .byte 176
258         .byte 173
259         .byte 170
260         .byte 167
261         .byte 164
262         .byte 161
263         .byte 158
264         .byte 155
265         .byte 152
266         .byte 149
267         .byte 146
268         .byte 143
269         .byte 139
270         .byte 136
271         .byte 133
272         .byte 130
273         .byte 127
274         .byte 124
275         .byte 121
276         .byte 118
277         .byte 115
278         .byte 111
279         .byte 108
280         .byte 105
281         .byte 102
282         .byte 99
283         .byte 96
284         .byte 93
285         .byte 90
286         .byte 87
287         .byte 84
288         .byte 81
289         .byte 78
290         .byte 75
291         .byte 72
292         .byte 70
293         .byte 67
294         .byte 64
295         .byte 61
296         .byte 59
297         .byte 56
298         .byte 54
299         .byte 51
300         .byte 49
301         .byte 46
302         .byte 44
303         .byte 41
304         .byte 39
305         .byte 37
306         .byte 35
307         .byte 33
308         .byte 30
309         .byte 28
310         .byte 26
311         .byte 25
312         .byte 23
313         .byte 21
314         .byte 19
315         .byte 18
316         .byte 16
317         .byte 15
318         .byte 13
319         .byte 12
320         .byte 10
321         .byte 9
322         .byte 8
323         .byte 7
324         .byte 6
325         .byte 5
326         .byte 4
327         .byte 3
328         .byte 3
329         .byte 2
330         .byte 1
331         .byte 1
332         .byte 0
333         .byte 0
334         .byte 0
335         .byte 0
336         .byte 0
337         .byte 0
338         .byte 0
339         .byte 0
340         .byte 0
341         .byte 0
342         .byte 0
343         .byte 1
344         .byte 1
345         .byte 2
346         .byte 3
347         .byte 3
348         .byte 4
349         .byte 5
350         .byte 6
351         .byte 7
352         .byte 8
353         .byte 9
354         .byte 10
355         .byte 12
356         .byte 13
357         .byte 15
358         .byte 16
359         .byte 18
360         .byte 19
361         .byte 21
362         .byte 23
363         .byte 25
364         .byte 26
365         .byte 28
366         .byte 30
367         .byte 33
368         .byte 35
369         .byte 37
370         .byte 39
371         .byte 41
372         .byte 44
373         .byte 46
374         .byte 49
375         .byte 51
376         .byte 54
377         .byte 56
378         .byte 59
379         .byte 61
380         .byte 64
381         .byte 67
382         .byte 70
383         .byte 72
384         .byte 75
385         .byte 78
386         .byte 81
387         .byte 84
388         .byte 87
389         .byte 90
390         .byte 93
391         .byte 96
392         .byte 99
393         .byte 102
394         .byte 105
395         .byte 108
396         .byte 111
397         .byte 115
398         .byte 118
399         .byte 121
400         .byte 124