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