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.
28 ; $Logfile: C:/dos-c/src/boot/boot.asv $
33 ; Revision 1.1.2.1 2002/11/04 22:06:55 short
34 ; branch update for HEAD-2002110401
36 ; Revision 1.2 2002/11/04 22:01:07 short
37 ; update for HEAD-2002110401
39 ; Revision 1.4 2000/06/25 03:59:14 dwelch
41 ; Removed from redundant files from the mm directory
42 ; Added some preliminary work on the pager
43 ; Fixed ntoskrnl/mm/npool.c (This may have been the cause of the
44 ; problems reported with loading win32k.sys)
45 ; Fixed problems with reporting space used to store physical page
47 ; Added code to support MmSafeCopy{To/From}User interface work
49 ; Added Event member of the PHYSICAL_PAGE structure to implement Philip
51 ; Reworked section page-in code (not really tested)
52 ; Replaced inline string functions with gcc builtins to make debugging easier
54 ; Revision 1.3 1998/08/25 04:37:43 rex
57 ; Revision 1.1.1.2 1998/08/25 04:27:38 rex
58 ; A much Needed Update
61 ; Rev 1.5 10 Jan 1997 4:58:06 patv
64 ; Rev 1.4 10 Jan 1997 4:52:50 patv
65 ; Re-written to support C drive and eliminate restrictions on IPL.SYS
67 ; Rev 1.3 29 Aug 1996 13:06:50 patv
68 ; Bug fixes for v0.91b
70 ; Rev 1.2 01 Sep 1995 17:56:44 patv
73 ; Rev 1.1 30 Jul 1995 20:37:38 patv
74 ; Initialized stack before use.
76 ; Rev 1.0 02 Jul 1995 10:57:52 patv
85 ; bp is initialized to 7c00h
87 %define bytesPerSector [bp+0bh]
88 %define sectPerCluster [bp+0dh]
89 %define resSectors [bp+0eh]
90 %define nFats [bp+10h]
91 %define nRootDir [bp+11h]
92 %define nSectors [bp+13h]
94 %define sectPerFat [bp+16h]
95 %define sectPerTrack [bp+18h]
96 %define nHeads [bp+1ah]
97 %define nHidden [bp+1ch]
98 %define nHidden_hi [bp+1eh]
99 %define nSectorHuge [bp+20h]
100 %define drive [bp+24h]
101 %define extBoot [bp+26h]
102 %define volid [bp+27h]
103 %define vollabel [bp+2bh]
108 FATBUF equ 4000h ; offset of temporary buffer for FAT
110 RETRYCOUNT equ 5 ; number of retries on disk errors
112 ; Some extra variables that are created on the stack frame
114 %define fat_start [bp-4] ; first FAT sector
115 %define fat_start_hi [bp-2]
116 %define root_dir_start [bp-8] ; first root directory sector
117 %define root_dir_start_hi [bp-6]
118 %define data_start [bp-12] ; first data sector
119 %define data_start_hi [bp-10]
122 ; Include macros for filesystem access
129 TIMES 3eh-($-$$) DB 0
131 %define tempbuf [bp+3eh]
137 mov ss, ax ; initialize stack
144 mov drive, dl ; BIOS passes drive number in DL
148 FINDFILE ; locate file in root directory
149 jc boot_error ; fail if not found
151 GETFATCHAIN ; read FAT chain
152 LOADFILE ; load file (jumps to boot_sucess if successful)
154 boot_error: mov cx, ERRMSGLEN
157 next_char: lodsb ; print error message
164 int 16h ; wait for keystroke
165 int 19h ; invoke bootstrap loader
167 boot_success: mov dl, drive
169 db 0eah ; far jump to LOADSEG:0000
174 ; readDisk: Reads a number of sectors into memory.
176 ; Call with: DX:AX = 32-bit DOS sector number
177 ; DI = number of sectors to read
178 ; ES:BX = destination buffer
179 ; ES must be 64k aligned (1000h, 2000h etc).
181 ; Returns: CF set on error
182 ; ES:BX points one byte after the last byte read.
190 ; translate sector number to BIOS parameters
194 ; abs = sector offset in track
195 ; + head * sectPerTrack offset in cylinder
196 ; + track * sectPerTrack * nHeads offset in platter
198 ; t1 = abs / sectPerTrack (ax has t1)
199 ; sector = abs mod sectPerTrack (cx has sector)
201 div word sectPerTrack
205 ; t1 = head + track * nHeads
207 ; track = t1 / nHeads (ax has track)
208 ; head = t1 mod nHeads (dl has head)
213 ; the following manipulations are necessary in order to
214 ; properly place parameters into registers.
215 ; ch = cylinder number low 8 bits
216 ; cl = 7-6: cylinder high two bits
218 mov dh, dl ; save head into dh for bios
219 ror ah, 1 ; move track high bits into
220 ror ah, 1 ; bits 7-6 (assumes top = 0)
221 xchg al, ah ; swap for later
222 mov dl, byte sectPerTrack
224 inc cl ; sector offset from 1
225 or cx, ax ; merge cylinder into sector
226 mov al, dl ; al has # of sectors left
228 ; Calculate how many sectors can be transfered in this read
229 ; due to dma boundary conditions.
232 mov si, di ; temp register save
233 ; this computes remaining bytes because of modulo 65536
234 ; nature of dma boundary condition
235 mov ax, bx ; get offset pointer
236 neg ax ; and convert to bytes
237 jz ax_min_1 ; started at seg:0, skip ahead
239 xor dx, dx ; convert to sectors
240 div word bytesPerSector
242 cmp ax, di ; check remainder vs. asked
243 jb ax_min_1 ; less, skip ahead
244 mov si, ax ; transfer only what we can
248 ; Check that request sectors do not exceed track boundary
251 mov ax, cx ; get the sector/cyl byte
252 and ax, 03fh ; and mask out sector
253 sub si, ax ; si has how many we can read
255 cmp si, di ; see if asked <= available
257 mov ax, si ; get what can be xfered
259 ax_min_2: mov si, RETRYCOUNT
268 xor ax, ax ; reset the drive
279 read_next_jmp: jmp short read_next
281 mov si, ax ; AX = SI = number of sectors read
282 mul word bytesPerSector ; AX = number of bytes read
283 add bx, ax ; add number of bytes read to BX
284 jnc no_incr_es ; if overflow...
287 add ah, 10h ; ...add 1000h to ES
291 pop dx ; DX:AX = last sector number
294 adc dx, 0 ; DX:AX = next sector to read
295 sub di, si ; if there is anything left to read,
296 jg read_next_jmp ; continue
302 errmsg db "Boot error"
303 ERRMSGLEN equ $ - errmsg
306 ;filename db "OSLDR BIN"
307 filename db "KERNEL BIN"
309 TIMES 510-($-$$) DB 0