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
68 loading_msg: .asciz "\nLoad "
69 driveno_msg: .asciz "Drv:"
71 .global sect_per_track
72 sect_per_track: .short 18
74 num_cylinders: .short 80
84 movb drive_number, %dl
101 mov %ax, num_cylinders
104 mov %cx, sect_per_track
126 # read_sectors(first, num)
131 mov ARG_SIDX(%bp), %ax
140 1: cmp ARG_NSECT(%bp), %cx
153 movw $3, read_retries
156 # calculate the track (sidx / sectors_per_track)
160 mov sect_per_track, %cx
168 # cylinder (track/heads) in ch [0-7] and cl[6,7]<-[8,9]
178 # sector num cl[0-5] is sidx % sectors_per_track + 1
183 # ah = 2 (read), al = 1 sectors
185 movb drive_number, %dl
189 # abort after 3 attempts
193 # error detected, reset controller and retry
206 # increment es:bx accordingly (advance es if bx overflows)
218 str_read_error: .asciz "rderr:"
221 mov $str_read_error, %si
229 # expects string pointer in ds:si
243 # expects character in al
266 # expects number in eax
272 movw $scratchbuf + scratchbuf_size, %si
290 .set UART_DATA, 0x3f8
291 .set UART_DIVLO, 0x3f8
292 .set UART_DIVHI, 0x3f9
293 .set UART_FIFO, 0x3fa
294 .set UART_LCTL, 0x3fb
295 .set UART_MCTL, 0x3fc
296 .set UART_LSTAT, 0x3fd
297 .set DIV_9600, 115200 / 9600
300 .set FIFO_ENABLE_CLEAR, 0x07
301 .set MCTL_DTR_RTS_OUT2, 0x0b
302 .set LST_TREG_EMPTY, 0x20
319 # clear and enable fifo
320 mov $FIFO_ENABLE_CLEAR, %al
324 mov $MCTL_DTR_RTS_OUT2, %al
329 # expects a character in al
341 # wait until the transmit register is empty
344 and $LST_TREG_EMPTY, %al