11 ; This file is part of DOS-C.
13 ; DOS-C is free software; you can redistribute it and/or
14 ; modify it under the terms of the GNU General Public License
15 ; as published by the Free Software Foundation; either version
16 ; 2, or (at your option) any later version.
18 ; DOS-C is distributed in the hope that it will be useful, but
19 ; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
21 ; the GNU General Public License for more details.
23 ; You should have received a copy of the GNU General Public
24 ; License along with DOS-C; see the file COPYING. If not,
25 ; write to the Free Software Foundation, 675 Mass Ave,
26 ; Cambridge, MA 02139, USA.
30 ; Rev 1.5 10 Jan 1997 4:58:06 patv
33 ; Rev 1.4 10 Jan 1997 4:52:50 patv
34 ; Re-written to support C drive and eliminate restrictions on IPL.SYS
36 ; Rev 1.3 29 Aug 1996 13:06:50 patv
37 ; Bug fixes for v0.91b
39 ; Rev 1.2 01 Sep 1995 17:56:44 patv
42 ; Rev 1.1 30 Jul 1995 20:37:38 patv
43 ; Initialized stack before use.
45 ; Rev 1.0 02 Jul 1995 10:57:52 patv
54 ; bp is initialized to 7c00h
56 %define bytesPerSector [bp+0bh]
57 %define sectPerCluster [bp+0dh]
58 %define resSectors [bp+0eh]
59 %define nFats [bp+10h]
60 %define nRootDir [bp+11h]
61 %define nSectors [bp+13h]
63 %define sectPerFat [bp+16h]
64 %define sectPerTrack [bp+18h]
65 %define nHeads [bp+1ah]
66 %define nHidden [bp+1ch]
67 %define nHidden_hi [bp+1eh]
68 %define nSectorHuge [bp+20h]
69 %define drive [bp+24h]
70 %define extBoot [bp+26h]
71 %define volid [bp+27h]
72 %define vollabel [bp+2bh]
77 FATBUF equ 4000h ; offset of temporary buffer for FAT
79 RETRYCOUNT equ 5 ; number of retries on disk errors
81 ; Some extra variables that are created on the stack frame
83 %define fat_start [bp-4] ; first FAT sector
84 %define fat_start_hi [bp-2]
85 %define root_dir_start [bp-8] ; first root directory sector
86 %define root_dir_start_hi [bp-6]
87 %define data_start [bp-12] ; first data sector
88 %define data_start_hi [bp-10]
91 ; Include macros for filesystem access
100 %define tempbuf [bp+3eh]
106 mov ss, ax ; initialize stack
113 mov drive, dl ; BIOS passes drive number in DL
117 FINDFILE ; locate file in root directory
118 jc boot_error ; fail if not found
120 GETFATCHAIN ; read FAT chain
121 LOADFILE ; load file (jumps to boot_sucess if successful)
123 boot_error: mov cx, ERRMSGLEN
126 next_char: lodsb ; print error message
133 int 16h ; wait for keystroke
134 int 19h ; invoke bootstrap loader
136 boot_success: mov dl, drive
138 db 0eah ; far jump to LOADSEG:0000
143 ; readDisk: Reads a number of sectors into memory.
145 ; Call with: DX:AX = 32-bit DOS sector number
146 ; DI = number of sectors to read
147 ; ES:BX = destination buffer
148 ; ES must be 64k aligned (1000h, 2000h etc).
150 ; Returns: CF set on error
151 ; ES:BX points one byte after the last byte read.
159 ; translate sector number to BIOS parameters
163 ; abs = sector offset in track
164 ; + head * sectPerTrack offset in cylinder
165 ; + track * sectPerTrack * nHeads offset in platter
167 ; t1 = abs / sectPerTrack (ax has t1)
168 ; sector = abs mod sectPerTrack (cx has sector)
170 div word sectPerTrack
174 ; t1 = head + track * nHeads
176 ; track = t1 / nHeads (ax has track)
177 ; head = t1 mod nHeads (dl has head)
182 ; the following manipulations are necessary in order to
183 ; properly place parameters into registers.
184 ; ch = cylinder number low 8 bits
185 ; cl = 7-6: cylinder high two bits
187 mov dh, dl ; save head into dh for bios
188 ror ah, 1 ; move track high bits into
189 ror ah, 1 ; bits 7-6 (assumes top = 0)
190 xchg al, ah ; swap for later
191 mov dl, byte sectPerTrack
193 inc cl ; sector offset from 1
194 or cx, ax ; merge cylinder into sector
195 mov al, dl ; al has # of sectors left
197 ; Calculate how many sectors can be transfered in this read
198 ; due to dma boundary conditions.
201 mov si, di ; temp register save
202 ; this computes remaining bytes because of modulo 65536
203 ; nature of dma boundary condition
204 mov ax, bx ; get offset pointer
205 neg ax ; and convert to bytes
206 jz ax_min_1 ; started at seg:0, skip ahead
208 xor dx, dx ; convert to sectors
209 div word bytesPerSector
211 cmp ax, di ; check remainder vs. asked
212 jb ax_min_1 ; less, skip ahead
213 mov si, ax ; transfer only what we can
217 ; Check that request sectors do not exceed track boundary
220 mov ax, cx ; get the sector/cyl byte
221 and ax, 03fh ; and mask out sector
222 sub si, ax ; si has how many we can read
224 cmp si, di ; see if asked <= available
226 mov ax, si ; get what can be xfered
228 ax_min_2: mov si, RETRYCOUNT
237 xor ax, ax ; reset the drive
248 read_next_jmp: jmp short read_next
250 mov si, ax ; AX = SI = number of sectors read
251 mul word bytesPerSector ; AX = number of bytes read
252 add bx, ax ; add number of bytes read to BX
253 jnc no_incr_es ; if overflow...
256 add ah, 10h ; ...add 1000h to ES
260 pop dx ; DX:AX = last sector number
263 adc dx, 0 ; DX:AX = next sector to read
264 sub di, si ; if there is anything left to read,
265 jg read_next_jmp ; continue
271 errmsg db "Boot error"
272 ERRMSGLEN equ $ - errmsg
275 ;filename db "OSLDR BIN"
276 filename db "KERNEL BIN"
278 TIMES 510-($-$$) DB 0