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/>.
20 .set stack_top, 0x7be0
21 .set read_retries, 0x7be8
22 .set drive_number, 0x7bec
24 .set scratchbuf, 0x7bf0
25 .set scratchbuf_size, 16
29 # move stack to just below the code
33 # use the code segment for data access
47 # load the second stage boot loader and jump to it
48 mov $_boot2_size, %eax
58 # set es to the start of the destination buffer to allow reading in
70 loading_msg: .asciz "\nLoad "
71 driveno_msg: .asciz "Drive: "
73 sect_per_track: .short 18
74 num_cylinders: .short 80
82 movb drive_number, %dl
99 mov %ax, num_cylinders
102 mov %cx, sect_per_track
120 # read_sectors(first, num)
125 mov ARG_SIDX(%bp), %ax
134 1: cmp ARG_NSECT(%bp), %cx
147 movw $3, read_retries
150 # calculate the track (sidx / sectors_per_track)
154 mov sect_per_track, %cx
162 # cylinder (track/heads) in ch [0-7] and cl[6,7]<-[8,9]
172 # sector num cl[0-5] is sidx % sectors_per_track + 1
177 # ah = 2 (read), al = 1 sectors
179 movb drive_number, %dl
183 # abort after 3 attempts
187 # error detected, reset controller and retry
200 # increment es:bx accordingly (advance es if bx overflows)
212 str_read_error: .asciz "rderr: "
215 mov $str_read_error, %si
223 # expects string pointer in ds:si
237 # expects character in al
253 # expects number in eax
259 movw $scratchbuf + scratchbuf_size, %si
277 .set UART_DATA, 0x3f8
278 .set UART_DIVLO, 0x3f8
279 .set UART_DIVHI, 0x3f9
280 .set UART_FIFO, 0x3fa
281 .set UART_LCTL, 0x3fb
282 .set UART_MCTL, 0x3fc
283 .set UART_LSTAT, 0x3fd
284 .set DIV_9600, 115200 / 9600
287 .set FIFO_ENABLE, 0x01
288 .set FIFO_SEND_CLEAR, 0x04
289 .set FIFO_RECV_CLEAR, 0x02
293 .set LST_TREG_EMPTY, 0x20
310 # clear and enable fifo
311 mov $FIFO_ENABLE, %al
312 or $FIFO_SEND_CLEAR, %al
313 or $FIFO_RECV_CLEAR, %al
324 # expects a character in al
337 # wait until the transmit register is empty
340 and $LST_TREG_EMPTY, %al