Removed from redundant files from the mm directory
[reactos.git] / reactos / loaders / boot / bootbk.asm
1 ;
2 ; File:
3 ; boot.asm
4 ; Description:
5 ; DOS-C boot
6 ;
7 ; Copyright (c) 1997;
8 ; Svante Frey
9 ; All Rights Reserved
10 ;
11 ; This file is part of DOS-C.
12 ;
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.
17 ;
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.
22 ;
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.
27 ;
28 ; $Logfile: C:/dos-c/src/boot/boot.asv $
29 ;
30 ; $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/loaders/boot/Attic/bootbk.asm,v 1.4 2000/06/25 03:59:14 dwelch Exp $
31 ;
32 ; $Log: bootbk.asm,v $
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
39 ; information
40 ; Added code to support MmSafeCopy{To/From}User interface work
41 ; (untested)
42 ; Added Event member of the PHYSICAL_PAGE structure to implement Philip
43 ; Susi's suggestion
44 ; Reworked section page-in code (not really tested)
45 ; Replaced inline string functions with gcc builtins to make debugging easier
46 ;
47 ; Revision 1.3 1998/08/25 04:40:47 rex
48 ; Release cleanup
49 ;
50 ; Revision 1.1.1.2 1998/08/25 04:27:38 rex
51 ; A much Needed Update
52 ;
53 ;
54 ; Rev 1.5 10 Jan 1997 4:58:06 patv
55 ; Corrected copyright
56 ;
57 ; Rev 1.4 10 Jan 1997 4:52:50 patv
58 ; Re-written to support C drive and eliminate restrictions on IPL.SYS
59 ;
60 ; Rev 1.3 29 Aug 1996 13:06:50 patv
61 ; Bug fixes for v0.91b
62 ;
63 ; Rev 1.2 01 Sep 1995 17:56:44 patv
64 ; First GPL release.
65 ;
66 ; Rev 1.1 30 Jul 1995 20:37:38 patv
67 ; Initialized stack before use.
68 ;
69 ; Rev 1.0 02 Jul 1995 10:57:52 patv
70 ; Initial revision.
71 ;
72
73 .text
74
75 BASE equ 0
76
77
78 org BASE
79 Entry: jmp real_start
80
81 ; bp is initialized to 7c00h
82 oem equ [bp+3]
83 bytesPerSector equ [bp+0bh]
84 sectPerCluster equ [bp+0dh]
85 resSectors equ [bp+0eh]
86 nFats equ [bp+10h]
87 nRootDir equ [bp+11h]
88 nSectors equ [bp+13h]
89 MID equ [bp+15h]
90 sectPerFat equ [bp+16h]
91 sectPerTrack equ [bp+18h]
92 nHeads equ [bp+1ah]
93 nHidden equ [bp+1ch]
94 nSectorHuge equ [bp+20h]
95 drive equ [bp+24h]
96 extBoot equ [bp+26h]
97 volid equ [bp+27h]
98 vollabel equ [bp+2bh]
99 filesys equ [bp+36h]
100
101 LOADSEG equ 2000h
102
103 FATBUF equ 4000h ; offset of temporary buffer for FAT
104 ; chain
105 RETRYCOUNT equ 5 ; number of retries on disk errors
106
107 ; Some extra variables that are created on the stack frame
108
109 fat_start equ [bp-4] ; first FAT sector
110 root_dir_start equ [bp-8] ; first root directory sector
111 data_start equ [bp-12] ; first data sector
112
113
114 ;
115 ; Include macros for filesystem access
116 ;
117 include boot.inc
118
119 ;
120 ;
121 ;
122 org BASE+3eh
123
124 tempbuf equ [bp+3eh]
125 load_seg dw LOADSEG
126
127 real_start: cli
128 cld
129 mov ax, cs
130 mov ss, ax ; initialize stack
131 mov bp, 7c00h
132 lea sp, [bp-20h]
133 sti
134
135 mov es, ax
136 mov ds, ax
137 mov drive, dl ; BIOS passes drive number in DL
138
139 GETDRIVEPARMS
140
141 FINDFILE ; locate file in root directory
142 jc boot_error ; fail if not found
143
144 GETFATCHAIN ; read FAT chain
145 LOADFILE ; load file (jumps to boot_sucess if successful)
146
147 boot_error: mov cx, ERRMSGLEN
148 mov si, offset errmsg+7c00h
149
150 next_char: lodsb ; print error message
151 mov ah, 0eh
152 xor bh, bh
153 int 10h
154 loop next_char
155
156 xor ah, ah
157 int 16h ; wait for keystroke
158 int 19h ; invoke bootstrap loader
159
160 boot_success: mov dl, drive
161
162 db 0eah ; far jump to LOADSEG:0000
163 dw 0
164 dw LOADSEG
165
166
167 ; readDisk: Reads a number of sectors into memory.
168 ;
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).
173 ;
174 ; Returns: CF set on error
175 ; ES:BX points one byte after the last byte read.
176
177 readDisk proc
178 push si
179 read_next: push dx
180 push ax
181
182 ;
183 ; translate sector number to BIOS parameters
184 ;
185
186 ;
187 ; abs = sector offset in track
188 ; + head * sectPerTrack offset in cylinder
189 ; + track * sectPerTrack * nHeads offset in platter
190 ;
191 ; t1 = abs / sectPerTrack (ax has t1)
192 ; sector = abs mod sectPerTrack (cx has sector)
193 ;
194 div word ptr sectPerTrack
195 mov cx, dx
196
197 ;
198 ; t1 = head + track * nHeads
199 ;
200 ; track = t1 / nHeads (ax has track)
201 ; head = t1 mod nHeads (dl has head)
202 ;
203 xor dx, dx
204 div word ptr nHeads
205
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
210 ; 5-0: sector
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 ptr sectPerTrack
216 sub dl, cl
217 inc cl ; sector offset from 1
218 or cx, ax ; merge cylinder into sector
219 mov al, dl ; al has # of sectors left
220
221 ; Calculate how many sectors can be transfered in this read
222 ; due to dma boundary conditions.
223 push dx
224
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
231
232 xor dx, dx ; convert to sectors
233 div word ptr bytesPerSector
234
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
238
239 ax_min_1: pop dx
240
241 ; Check that request sectors do not exceed track boundary
242 mov si, sectPerTrack
243 inc si
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
247 mov ax, di
248 cmp si, di ; see if asked <= available
249 jge ax_min_2
250 mov ax, si ; get what can be xfered
251
252 ax_min_2: mov si, RETRYCOUNT
253 mov ah, 2
254 mov dl, drive
255
256 retry: push ax
257 int 13h
258 pop ax
259 jnc read_ok
260 push ax
261 xor ax, ax ; reset the drive
262 int 13h
263 pop ax
264 dec si
265 jnz retry
266 stc
267 pop ax
268 pop dx
269 pop si
270 ret
271
272 read_next_jmp: jmp short read_next
273 read_ok: xor ah, ah
274 mov si, ax ; AX = SI = number of sectors read
275 mul word ptr bytesPerSector ; AX = number of bytes read
276 add bx, ax ; add number of bytes read to BX
277 jnc no_incr_es ; if overflow...
278
279 mov ax, es
280 add ah, 10h ; ...add 1000h to ES
281 mov es, ax
282
283 no_incr_es: pop ax
284 pop dx ; DX:AX = last sector number
285
286 add ax, si
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
290
291 clc
292 pop si
293 ret
294 readDisk endp
295
296 errmsg db "Boot error"
297 ERRMSGLEN equ $ - errmsg
298
299
300 ;filename db "OSLDR BIN"
301 filename db "KERNEL BIN"
302
303 org BASE+01feh
304 sign dw 0aa55h
305
306 TEXT ENDS
307 end
308
309