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 .set drive_number, 0x7bec
24 movb drive_number, %dl
27 # load initial GDT/IDT
34 # inter-segment jump to set cs selector to segment 1
38 # set all data selectors to segment 2
63 hello: .asciz "Switched to 32bit\n"
75 gdt: # 0: null segment
78 # 1: code - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:code/non-conf/rd
81 # 2: data - base:0, lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw
84 # 3: dummy TSS - base:tss, lim:103, type avail 32bit TSS, byte-granular
93 # trap gate 13: general protection fault
96 # type: trap, present, default
103 gpf_msg: .asciz "GPF "
117 ena20_msg: .asciz "A20 line enabled\n"
118 foo_msg: .asciz "Foo\n"
133 # keep trying ... we can't do anything useful without A20 anyway
140 # CF = 1 if A20 test fails (not enabled)
144 movl $0xbaadf00d, (%ebx)
145 movl $0xaabbcc42, (%edx)
146 subl $0xbaadf00d, (%ebx)
149 ena20_fast_msg: .asciz "Attempting fast A20 enable\n"
152 mov $ena20_fast_msg, %esi
160 .set KBC_DATA_PORT, 0x60
161 .set KBC_CMD_PORT, 0x64
162 .set KBC_STATUS_PORT, 0x64
163 .set KBC_CMD_RD_OUTPORT, 0xd0
164 .set KBC_CMD_WR_OUTPORT, 0xd1
166 .set KBC_STAT_OUT_RDY, 0x01
167 .set KBC_STAT_IN_FULL, 0x02
169 ena20_kbd_msg: .asciz "Attempting KBD A20 enable\n"
171 # enable A20 line through the keyboard controller
173 mov $ena20_kbd_msg, %esi
177 mov $KBC_CMD_WR_OUTPORT, %al
178 out %al, $KBC_CMD_PORT
181 out %al, $KBC_DATA_PORT
184 # wait until the keyboard controller is ready to accept another byte
186 in $KBC_STATUS_PORT, %al
187 and $KBC_STAT_IN_FULL, %al
191 # better print routines, since we're not constrainted by the 512b of
215 # this looks retarded. in nasm: [ebx * 2 + edx]
216 mov %al, (%edx, %ebx, 2)
217 movb $7, 1(%edx, %ebx, 2)
226 # expects string pointer in esi
236 # expects number in eax
241 mov $numbuf + 16, %esi
271 # move 80 * 24 lines from b8050 -> b8000
276 # clear last line (b8780)
291 .set UART_DATA, 0x3f8
292 .set UART_LSTAT, 0x3fd
293 .set LST_TREG_EMPTY, 0x20
306 # wait until the transmit register is empty
309 and $LST_TREG_EMPTY, %al
372 # calc src scanline address -> bx
393 # calc src x offset -> si
412 mov %gs:(%bx, %si), %al
441 # expects string pointer in ds:si