Removed from redundant files from the mm directory
[reactos.git] / reactos / loaders / boot / boot.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/boot.asm,v 1.4 2000/06/25 03:59:14 dwelch Exp $
31 ;
32 ; $Log: boot.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:37:43 rex
48 ; new 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 section .text
74
75 org 0
76 Entry: jmp real_start
77
78 ; bp is initialized to 7c00h
79 %define oem [bp+3]
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]
86 %define MID [bp+15h]
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]
97 %define filesys 36h
98
99 LOADSEG equ 2000h
100
101 FATBUF equ 4000h ; offset of temporary buffer for FAT
102 ; chain
103 RETRYCOUNT equ 5 ; number of retries on disk errors
104
105 ; Some extra variables that are created on the stack frame
106
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]
113
114 ;
115 ; Include macros for filesystem access
116 ;
117 %include "boot.inc"
118
119 ;
120 ;
121 ;
122 TIMES 3eh-($-$$) DB 0
123
124 %define tempbuf [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, 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:
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 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 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 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 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 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
295 errmsg db "Boot error"
296 ERRMSGLEN equ $ - errmsg
297
298
299 ;filename db "OSLDR BIN"
300 filename db "KERNEL BIN"
301
302 TIMES 510-($-$$) DB 0
303 sign dw 0aa55h
304
305