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
27 # load initial GDT/IDT
34 # inter-segment jump to set cs selector to segment 1
38 # set all data selectors to segment 2
62 hello: .asciz "Switched to 32bit\n"
74 gdt: # 0: null segment
77 # 1: code - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:code/non-conf/rd
80 # 2: data - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw
87 # trap gate 13: general protection fault
90 # type: trap, present, default
94 gpf_msg: .asciz "GP fault "
108 ena20_msg: .asciz "A20 line enabled\n"
119 # keep trying ... we can't do anything useful without A20 anyway
126 # CF = 1 if A20 test fails (not enabled)
130 movl $0xbaadf00d, (%ebx)
131 movl $0xaabbcc42, (%edx)
132 subl $0xbaadf00d, (%ebx)
135 # enable A20 line through port 0x92 (fast A20)
137 mov $ena20_fast_msg, %esi
145 ena20_fast_msg: .asciz "Attempting fast A20 enable\n"
148 # enable A20 line through the keyboard controller
149 .set KBC_DATA_PORT, 0x60
150 .set KBC_CMD_PORT, 0x64
151 .set KBC_STATUS_PORT, 0x64
152 .set KBC_CMD_RD_OUTPORT, 0xd0
153 .set KBC_CMD_WR_OUTPORT, 0xd1
155 .set KBC_STAT_OUT_RDY, 0x01
156 .set KBC_STAT_IN_FULL, 0x02
159 mov $ena20_kbd_msg, %esi
163 mov $KBC_CMD_WR_OUTPORT, %al
164 out %al, $KBC_CMD_PORT
167 out %al, $KBC_DATA_PORT
170 ena20_kbd_msg: .asciz "Attempting KBD A20 enable\n"
172 # wait until the keyboard controller is ready to accept another byte
174 in $KBC_STATUS_PORT, %al
175 and $KBC_STAT_IN_FULL, %al
179 # better print routines, since we're not constrainted by the 512b of
203 # this looks retarded. in nasm: [ebx * 2 + edx]
204 mov %al, (%edx, %ebx, 2)
205 movb $7, 1(%edx, %ebx, 2)
214 # expects string pointer in esi
224 # expects number in eax
229 mov $numbuf + 16, %esi
259 # move 80 * 24 lines from b8050 -> b8000
264 # clear last line (b8780)
279 .set UART_DATA, 0x3f8
280 .set UART_LSTAT, 0x3fd
281 .set LST_TREG_EMPTY, 0x20
294 # wait until the transmit register is empty
297 and $LST_TREG_EMPTY, %al
344 # calc src scanline address -> ebx
350 mov (%ebp, %ebx), %cl
365 # calc src x offset -> eax
371 mov (%ebp, %eax), %cl
382 mov (%ebx, %esi), %al