1 # pcboot - bootable PC demo/game kernel
2 # Copyright (C) 2018 John Tsiombikas <nuclear@member.fsf.org>
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.
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.
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/>.
17 # this is the second-stage boot loader
21 # make sure any BIOS call didn't re-enable interrupts
24 # just in case we were loaded from floppy, turn all floppy motors off
30 # load initial GDT/IDT
37 # inter-segment jump to set cs selector to segment 1
41 # set all data selectors to segment 2
65 hello: .asciz "Switched to 32bit\n"
77 gdt: # 0: null segment
80 # 1: code - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:code/non-conf/rd
83 # 2: data - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw
90 # trap gate 13: general protection fault
93 # type: trap, present, default
97 gpf_msg: .asciz "GP fault "
111 ena20_msg: .asciz "A20 line enabled\n"
122 # keep trying ... we can't do anything useful without A20 anyway
129 # CF = 1 if A20 test fails (not enabled)
133 movl $0xbaadf00d, (%ebx)
134 movl $0xaabbcc42, (%edx)
135 subl $0xbaadf00d, (%ebx)
138 # enable A20 line through port 0x92 (fast A20)
140 mov $ena20_fast_msg, %esi
148 ena20_fast_msg: .asciz "Attempting fast A20 enable\n"
151 # enable A20 line through the keyboard controller
152 .set KBC_DATA_PORT, 0x60
153 .set KBC_CMD_PORT, 0x64
154 .set KBC_STATUS_PORT, 0x64
155 .set KBC_CMD_RD_OUTPORT, 0xd0
156 .set KBC_CMD_WR_OUTPORT, 0xd1
158 .set KBC_STAT_OUT_RDY, 0x01
159 .set KBC_STAT_IN_FULL, 0x02
162 mov $ena20_kbd_msg, %esi
166 mov $KBC_CMD_WR_OUTPORT, %al
167 out %al, $KBC_CMD_PORT
170 out %al, $KBC_DATA_PORT
173 ena20_kbd_msg: .asciz "Attempting KBD A20 enable\n"
175 # wait until the keyboard controller is ready to accept another byte
177 in $KBC_STATUS_PORT, %al
178 and $KBC_STAT_IN_FULL, %al
182 # better print routines, since we're not constrainted by the 512b of
206 # this looks retarded. in nasm: [ebx * 2 + edx]
207 mov %al, (%edx, %ebx, 2)
208 movb $7, 1(%edx, %ebx, 2)
217 # expects string pointer in esi
227 # expects number in eax
232 mov $numbuf + 16, %esi
262 # move 80 * 24 lines from b8050 -> b8000
267 # clear last line (b8780)
282 .set UART_DATA, 0x3f8
283 .set UART_LSTAT, 0x3fd
284 .set LST_TREG_EMPTY, 0x20
297 # wait until the transmit register is empty
300 and $LST_TREG_EMPTY, %al
354 # calc src scanline address -> ebx
360 mov (%ebp, %ebx), %cl
375 # calc src x offset -> eax
381 mov (%ebp, %eax), %cl
392 mov (%ebx, %esi), %al