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
45 # load the second stage boot loader and jump to it
46 mov $_boot2_size, %eax
49 mov $_boot2_size, %eax
57 # set es to the start of the destination buffer to allow reading in
66 loading_msg: .asciz "\nLoad "
67 driveno_msg: .asciz "Drv:"
69 .global sect_per_track
70 sect_per_track: .short 18
72 num_cylinders: .short 80
82 movb drive_number, %dl
99 mov %ax, num_cylinders
102 mov %cx, sect_per_track
124 # read_sectors(first, num)
129 mov ARG_SIDX(%bp), %ax
138 1: cmp ARG_NSECT(%bp), %cx
151 movw $3, read_retries
154 # calculate the track (sidx / sectors_per_track)
158 mov sect_per_track, %cx
166 # cylinder (track/heads) in ch [0-7] and cl[6,7]<-[8,9]
176 # sector num cl[0-5] is sidx % sectors_per_track + 1
181 # ah = 2 (read), al = 1 sectors
183 movb drive_number, %dl
187 # abort after 3 attempts
191 # error detected, reset controller and retry
204 # increment es:bx accordingly (advance es if bx overflows)
216 str_read_error: .asciz "rderr:"
219 mov $str_read_error, %si
227 # expects string pointer in ds:si
241 # expects character in al
261 # expects number in eax
267 movw $scratchbuf + scratchbuf_size, %si