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 $
30 ; $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/loaders/boot/Attic/boot.asm,v 1.4 2000/06/25 03:59:14 dwelch Exp $
33 ; Revision 1.4 2000/06/25 03:59:14 dwelch
34 ; Removed from redundant files from the mm directory
35 ; Added some preliminary work on the pager
36 ; Fixed ntoskrnl/mm/npool.c (This may have been the cause of the
37 ; problems reported with loading win32k.sys)
38 ; Fixed problems with reporting space used to store physical page
40 ; Added code to support MmSafeCopy{To/From}User interface work
42 ; Added Event member of the PHYSICAL_PAGE structure to implement Philip
44 ; Reworked section page-in code (not really tested)
45 ; Replaced inline string functions with gcc builtins to make debugging easier
47 ; Revision 1.3 1998/08/25 04:37:43 rex
50 ; Revision 1.1.1.2 1998/08/25 04:27:38 rex
51 ; A much Needed Update
54 ; Rev 1.5 10 Jan 1997 4:58:06 patv
57 ; Rev 1.4 10 Jan 1997 4:52:50 patv
58 ; Re-written to support C drive and eliminate restrictions on IPL.SYS
60 ; Rev 1.3 29 Aug 1996 13:06:50 patv
61 ; Bug fixes for v0.91b
63 ; Rev 1.2 01 Sep 1995 17:56:44 patv
66 ; Rev 1.1 30 Jul 1995 20:37:38 patv
67 ; Initialized stack before use.
69 ; Rev 1.0 02 Jul 1995 10:57:52 patv
78 ; bp is initialized to 7c00h
80 %define bytesPerSector [bp+0bh]
81 %define sectPerCluster [bp+0dh]
82 %define resSectors [bp+0eh]
83 %define nFats [bp+10h]
84 %define nRootDir [bp+11h]
85 %define nSectors [bp+13h]
87 %define sectPerFat [bp+16h]
88 %define sectPerTrack [bp+18h]
89 %define nHeads [bp+1ah]
90 %define nHidden [bp+1ch]
91 %define nHidden_hi [bp+1eh]
92 %define nSectorHuge [bp+20h]
93 %define drive [bp+24h]
94 %define extBoot [bp+26h]
95 %define volid [bp+27h]
96 %define vollabel [bp+2bh]
101 FATBUF equ 4000h ; offset of temporary buffer for FAT
103 RETRYCOUNT equ 5 ; number of retries on disk errors
105 ; Some extra variables that are created on the stack frame
107 %define fat_start [bp-4] ; first FAT sector
108 %define fat_start_hi [bp-2]
109 %define root_dir_start [bp-8] ; first root directory sector
110 %define root_dir_start_hi [bp-6]
111 %define data_start [bp-12] ; first data sector
112 %define data_start_hi [bp-10]
115 ; Include macros for filesystem access
122 TIMES 3eh-($-$$) DB 0
124 %define tempbuf [bp+3eh]
130 mov ss, ax ; initialize stack
137 mov drive, dl ; BIOS passes drive number in DL
141 FINDFILE ; locate file in root directory
142 jc boot_error ; fail if not found
144 GETFATCHAIN ; read FAT chain
145 LOADFILE ; load file (jumps to boot_sucess if successful)
147 boot_error: mov cx, ERRMSGLEN
150 next_char: lodsb ; print error message
157 int 16h ; wait for keystroke
158 int 19h ; invoke bootstrap loader
160 boot_success: mov dl, drive
162 db 0eah ; far jump to LOADSEG:0000
167 ; readDisk: Reads a number of sectors into memory.
169 ; Call with: DX:AX = 32-bit DOS sector number
170 ; DI = number of sectors to read
171 ; ES:BX = destination buffer
172 ; ES must be 64k aligned (1000h, 2000h etc).
174 ; Returns: CF set on error
175 ; ES:BX points one byte after the last byte read.
183 ; translate sector number to BIOS parameters
187 ; abs = sector offset in track
188 ; + head * sectPerTrack offset in cylinder
189 ; + track * sectPerTrack * nHeads offset in platter
191 ; t1 = abs / sectPerTrack (ax has t1)
192 ; sector = abs mod sectPerTrack (cx has sector)
194 div word sectPerTrack
198 ; t1 = head + track * nHeads
200 ; track = t1 / nHeads (ax has track)
201 ; head = t1 mod nHeads (dl has head)
206 ; the following manipulations are necessary in order to
207 ; properly place parameters into registers.
208 ; ch = cylinder number low 8 bits
209 ; cl = 7-6: cylinder high two bits
211 mov dh, dl ; save head into dh for bios
212 ror ah, 1 ; move track high bits into
213 ror ah, 1 ; bits 7-6 (assumes top = 0)
214 xchg al, ah ; swap for later
215 mov dl, byte sectPerTrack
217 inc cl ; sector offset from 1
218 or cx, ax ; merge cylinder into sector
219 mov al, dl ; al has # of sectors left
221 ; Calculate how many sectors can be transfered in this read
222 ; due to dma boundary conditions.
225 mov si, di ; temp register save
226 ; this computes remaining bytes because of modulo 65536
227 ; nature of dma boundary condition
228 mov ax, bx ; get offset pointer
229 neg ax ; and convert to bytes
230 jz ax_min_1 ; started at seg:0, skip ahead
232 xor dx, dx ; convert to sectors
233 div word bytesPerSector
235 cmp ax, di ; check remainder vs. asked
236 jb ax_min_1 ; less, skip ahead
237 mov si, ax ; transfer only what we can
241 ; Check that request sectors do not exceed track boundary
244 mov ax, cx ; get the sector/cyl byte
245 and ax, 03fh ; and mask out sector
246 sub si, ax ; si has how many we can read
248 cmp si, di ; see if asked <= available
250 mov ax, si ; get what can be xfered
252 ax_min_2: mov si, RETRYCOUNT
261 xor ax, ax ; reset the drive
272 read_next_jmp: jmp short read_next
274 mov si, ax ; AX = SI = number of sectors read
275 mul word bytesPerSector ; AX = number of bytes read
276 add bx, ax ; add number of bytes read to BX
277 jnc no_incr_es ; if overflow...
280 add ah, 10h ; ...add 1000h to ES
284 pop dx ; DX:AX = last sector number
287 adc dx, 0 ; DX:AX = next sector to read
288 sub di, si ; if there is anything left to read,
289 jg read_next_jmp ; continue
295 errmsg db "Boot error"
296 ERRMSGLEN equ $ - errmsg
299 ;filename db "OSLDR BIN"
300 filename db "KERNEL BIN"
302 TIMES 510-($-$$) DB 0