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
51 mov $_boot2_size, %eax
59 # set es to the start of the destination buffer to allow reading in
71 loading_msg: .asciz "\nLoad "
72 driveno_msg: .asciz "Drv:"
74 sect_per_track: .short 18
75 num_cylinders: .short 80
83 movb drive_number, %dl
100 mov %ax, num_cylinders
103 mov %cx, sect_per_track
121 # read_sectors(first, num)
126 mov ARG_SIDX(%bp), %ax
135 1: cmp ARG_NSECT(%bp), %cx
148 movw $3, read_retries
151 # calculate the track (sidx / sectors_per_track)
155 mov sect_per_track, %cx
163 # cylinder (track/heads) in ch [0-7] and cl[6,7]<-[8,9]
173 # sector num cl[0-5] is sidx % sectors_per_track + 1
178 # ah = 2 (read), al = 1 sectors
180 movb drive_number, %dl
184 # abort after 3 attempts
188 # error detected, reset controller and retry
201 # increment es:bx accordingly (advance es if bx overflows)
213 str_read_error: .asciz "rderr:"
216 mov $str_read_error, %si
224 # expects string pointer in ds:si
238 # expects character in al
261 # expects number in eax
267 movw $scratchbuf + scratchbuf_size, %si
285 .set UART_DATA, 0x3f8
286 .set UART_DIVLO, 0x3f8
287 .set UART_DIVHI, 0x3f9
288 .set UART_FIFO, 0x3fa
289 .set UART_LCTL, 0x3fb
290 .set UART_MCTL, 0x3fc
291 .set UART_LSTAT, 0x3fd
292 .set DIV_9600, 115200 / 9600
295 .set FIFO_ENABLE_CLEAR, 0x07
296 .set MCTL_DTR_RTS_OUT2, 0x0b
297 .set LST_TREG_EMPTY, 0x20
314 # clear and enable fifo
315 mov $FIFO_ENABLE_CLEAR, %al
319 mov $MCTL_DTR_RTS_OUT2, %al
324 # expects a character in al
336 # wait until the transmit register is empty
339 and $LST_TREG_EMPTY, %al