removed more lfs files
[bootcensus] / src / startup.s
1 # pcboot - bootable PC demo/game kernel
2 # Copyright (C) 2018-2019  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         .extern wait_vsync
24         .extern kb_getkey
25
26         .equ STACKTOP,0x80000
27
28         # move the stack to the top of the conventional memory
29         cli
30         movl $STACKTOP, %esp
31         # push a 0 ret-addr to terminate gdb backtraces
32         pushl $0
33
34         # zero the BSS section
35         xor %eax, %eax
36         mov $_bss_start, %edi
37         mov $_bss_size, %ecx
38         cmp $0, %ecx
39         jz skip_bss_zero
40         shr $4, %ecx
41         rep stosl
42 skip_bss_zero:
43
44         call pcboot_main
45         # pcboot_main never returns
46 0:      cli
47         hlt
48         jmp 0b
49
50         # this is called once after memory init, to move the protected mode
51         # stack to the top of usable memory, to avoid interference from 16bit
52         # programs (as much as possible)
53         .global move_stack
54 move_stack:
55         # calculate the currently used lowest address of the stack (rounded
56         # down to 4-byte alignment), to see where to start copying
57         mov %esp, %esi
58         and $0xfffffffc, %esi
59         # calculate the size we need to copy
60         mov $STACKTOP, %ecx
61         sub %esi, %ecx
62         # load the destination address to edi
63         mov 4(%esp), %edi
64         sub %ecx, %edi
65         # size in longwords
66         shr $2, %ecx
67
68         # change esp to the new stack
69         mov $STACKTOP, %ecx
70         sub %esp, %ecx
71         mov 4(%esp), %eax
72         mov %eax, %esp
73         sub %ecx, %esp
74
75         rep movsd
76         ret