Rev 3555 | Rev 3908 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2465 | Serge | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
431 | serge | 4 | ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
||
6 | ;; ;; |
||
7 | ;; BOOTCODE.INC ;; |
||
8 | ;; ;; |
||
9 | ;; KolibriOS 16-bit loader, ;; |
||
10 | ;; based on bootcode for MenuetOS ;; |
||
11 | ;; ;; |
||
12 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1 | ha | 13 | |
593 | mikedld | 14 | $Revision: 3725 $ |
1 | ha | 15 | |
16 | |||
17 | ;========================================================================== |
||
18 | ; |
||
19 | ; 16 BIT FUNCTIONS |
||
20 | ; |
||
21 | ;========================================================================== |
||
22 | |||
183 | diamond | 23 | |
29 | halyavin | 24 | putchar: |
25 | ; in: al=character |
||
514 | diamond | 26 | mov ah, 0Eh |
27 | mov bh, 0 |
||
28 | int 10h |
||
29 | ret |
||
1 | ha | 30 | |
29 | halyavin | 31 | print: |
32 | ; in: si->string |
||
514 | diamond | 33 | mov al, 186 |
34 | call putchar |
||
35 | mov al, ' ' |
||
36 | call putchar |
||
1 | ha | 37 | |
29 | halyavin | 38 | printplain: |
39 | ; in: si->string |
||
514 | diamond | 40 | pusha |
41 | lodsb |
||
29 | halyavin | 42 | @@: |
514 | diamond | 43 | call putchar |
44 | lodsb |
||
2434 | Serge | 45 | test al, al |
514 | diamond | 46 | jnz @b |
47 | popa |
||
48 | ret |
||
1 | ha | 49 | |
29 | halyavin | 50 | getkey: |
51 | ; get number in range [bl,bh] (bl,bh in ['0'..'9']) |
||
52 | ; in: bx=range |
||
53 | ; out: ax=digit (1..9, 10 for 0) |
||
514 | diamond | 54 | mov ah, 0 |
55 | int 16h |
||
56 | cmp al, bl |
||
57 | jb getkey |
||
58 | cmp al, bh |
||
59 | ja getkey |
||
60 | push ax |
||
61 | call putchar |
||
62 | pop ax |
||
63 | and ax, 0Fh |
||
64 | jnz @f |
||
65 | mov al, 10 |
||
29 | halyavin | 66 | @@: |
514 | diamond | 67 | ret |
1 | ha | 68 | |
29 | halyavin | 69 | setcursor: |
70 | ; in: dl=column, dh=row |
||
514 | diamond | 71 | mov ah, 2 |
72 | mov bh, 0 |
||
73 | int 10h |
||
74 | ret |
||
29 | halyavin | 75 | |
76 | macro _setcursor row,column |
||
77 | { |
||
514 | diamond | 78 | mov dx, row*256 + column |
79 | call setcursor |
||
29 | halyavin | 80 | } |
81 | |||
134 | diamond | 82 | boot_read_floppy: |
83 | push si |
||
84 | xor si, si |
||
85 | mov ah, 2 ; read |
||
86 | @@: |
||
87 | push ax |
||
88 | int 0x13 |
||
89 | pop ax |
||
90 | jnc @f |
||
91 | inc si |
||
92 | cmp si, 10 |
||
93 | jb @b |
||
2010 | serge | 94 | sayerr_badsect: |
465 | serge | 95 | mov si, badsect |
134 | diamond | 96 | sayerr_plain: |
97 | call printplain |
||
98 | jmp $ |
||
99 | @@: |
||
100 | pop si |
||
101 | ret |
||
102 | |||
795 | shurf | 103 | ; convert abs. sector number (AX) to BIOS T:H:S |
104 | ; sector number = (abs.sector%BPB_SecPerTrk)+1 |
||
105 | ; pre.track number = (abs.sector/BPB_SecPerTrk) |
||
106 | ; head number = pre.track number%BPB_NumHeads |
||
107 | ; track number = pre.track number/BPB_NumHeads |
||
108 | ; Return: cl - sector number |
||
109 | ; ch - track number |
||
110 | ; dl - drive number (0 = a:) |
||
111 | ; dh - head number |
||
112 | conv_abs_to_THS: |
||
113 | push bx |
||
2434 | Serge | 114 | mov bx, word [BPB_SecPerTrk] |
115 | xor dx, dx |
||
795 | shurf | 116 | div bx |
117 | inc dx |
||
118 | mov cl, dl ; cl = sector number |
||
2434 | Serge | 119 | mov bx, word [BPB_NumHeads] |
120 | xor dx, dx |
||
795 | shurf | 121 | div bx |
122 | ; !!!!!!! ax = track number, dx = head number |
||
2434 | Serge | 123 | mov ch, al ; ch=track number |
124 | xchg dh, dl ; dh=head number |
||
125 | mov dl, 0 ; dl=0 (drive 0 (a:)) |
||
795 | shurf | 126 | pop bx |
127 | retn |
||
128 | ; needed variables |
||
816 | Lrz | 129 | BPB_SecPerTrk dw 0 ; sectors per track |
130 | BPB_NumHeads dw 0 ; number of heads |
||
131 | BPB_FATSz16 dw 0 ; size of FAT |
||
132 | BPB_RootEntCnt dw 0 ; count of root dir. entries |
||
133 | BPB_BytsPerSec dw 0 ; bytes per sector |
||
134 | BPB_RsvdSecCnt dw 0 ; number of reserved sectors |
||
135 | BPB_TotSec16 dw 0 ; count of the sectors on the volume |
||
136 | BPB_SecPerClus db 0 ; number of sectors per cluster |
||
137 | BPB_NumFATs db 0 ; number of FAT tables |
||
138 | abs_sector_adj dw 0 ; adjustment to make abs. sector number |
||
139 | end_of_FAT dw 0 ; end of FAT table |
||
140 | FirstDataSector dw 0 ; begin of data |
||
795 | shurf | 141 | |
1 | ha | 142 | ;========================================================================= |
143 | ; |
||
144 | ; 16 BIT CODE |
||
145 | ; |
||
146 | ;========================================================================= |
||
147 | |||
2441 | Serge | 148 | include 'bootvesa.inc' ;Include source for boot vesa |
2010 | serge | 149 | if defined extended_primary_loader |
150 | include 'parsers.inc' |
||
151 | end if |
||
1 | ha | 152 | |
153 | start_of_code: |
||
2010 | serge | 154 | |
155 | if defined extended_primary_loader |
||
156 | ; save data from primary loader |
||
157 | mov word [cs:bootcallback], si |
||
158 | mov word [cs:bootcallback+2], ds |
||
159 | push cs |
||
160 | pop ds |
||
161 | mov [bootdevice], ax |
||
162 | mov [bootfs], bx |
||
163 | |||
164 | ; set up stack |
||
165 | mov ax, 3000h |
||
166 | mov ss, ax |
||
167 | mov sp, 0EC00h |
||
168 | |||
169 | ; try to load configuration file |
||
170 | mov ax, 1 |
||
171 | mov di, config_file_struct |
||
172 | call [bootcallback] |
||
514 | diamond | 173 | cld |
2010 | serge | 174 | push cs |
175 | pop es |
||
176 | ; bx=0 - ok, bx=1 - part of file loaded, assume this is ok |
||
177 | cmp bx, 1 |
||
178 | ja .config_bad |
||
179 | ; configuration file was loaded, parse |
||
180 | ; if length is too big, use first 0FFFFh bytes |
||
181 | test dx, dx |
||
182 | jz @f |
||
183 | mov ax, 0FFFFh |
||
184 | @@: |
||
185 | ; ds:si will be pointer to current data, dx = limit |
||
186 | xchg ax, dx |
||
187 | push 4000h |
||
188 | pop ds |
||
189 | xor si, si |
||
190 | .parse_loop: |
||
191 | ; skip spaces |
||
192 | cmp si, dx |
||
193 | jae .parse_done |
||
194 | lodsb |
||
195 | cmp al, ' ' |
||
196 | jbe .parse_loop |
||
197 | dec si |
||
198 | ; loop over all possible configuration values |
||
199 | mov bx, config_file_variables |
||
200 | .find_variant: |
||
201 | ; get length |
||
202 | mov cx, [es:bx] |
||
203 | ; zero length = end of list |
||
204 | jecxz .find_newline |
||
205 | ; skip over length |
||
206 | inc bx |
||
207 | inc bx |
||
208 | mov di, bx |
||
209 | ; skip over string |
||
210 | add bx, cx |
||
211 | ; test whether we have at least cx symbols left |
||
212 | mov ax, cx |
||
213 | add ax, si |
||
214 | jc .next_variant1 |
||
215 | cmp ax, dx |
||
216 | jae .next_variant1 |
||
217 | ; save current position |
||
218 | push si |
||
219 | ; compare strings |
||
220 | repz cmpsb |
||
221 | jnz .next_variant2 |
||
222 | ; strings are equal; look for "=" with possible spaces before and after |
||
223 | @@: |
||
224 | cmp si, dx |
||
225 | jae .next_variant2 |
||
226 | lodsb |
||
227 | cmp al, ' ' |
||
228 | jbe @b |
||
229 | cmp al, '=' |
||
230 | jnz .next_variant2 |
||
231 | ; ok, we found the true variant |
||
232 | ; ignore saved position on the stack |
||
233 | pop ax |
||
234 | ; call the parser |
||
235 | call word [es:bx] |
||
236 | ; line parsed, find next |
||
237 | .find_newline: |
||
238 | cmp si, dx |
||
239 | jae .parse_done |
||
240 | lodsb |
||
241 | cmp al, 13 |
||
242 | jz .parse_loop |
||
243 | cmp al, 10 |
||
244 | jz .parse_loop |
||
245 | jmp .find_newline |
||
246 | .next_variant2: |
||
247 | ; continue to the next variant, restoring current position |
||
248 | pop si |
||
249 | .next_variant1: |
||
250 | ; continue to the next variant |
||
251 | ; skip over the parser |
||
252 | inc bx |
||
253 | inc bx |
||
254 | jmp .find_variant |
||
255 | .parse_done: |
||
256 | .config_bad: |
||
257 | |||
258 | ; set up segment registers |
||
259 | push cs |
||
260 | pop ds |
||
261 | else |
||
262 | cld |
||
29 | halyavin | 263 | ; \begin{diamond}[02.12.2005] |
514 | diamond | 264 | ; if bootloader sets ax = 'KL', then ds:si points to loader block |
265 | cmp ax, 'KL' |
||
266 | jnz @f |
||
267 | mov word [cs:cfgmanager.loader_block], si |
||
268 | mov word [cs:cfgmanager.loader_block+2], ds |
||
29 | halyavin | 269 | @@: |
270 | ; \end{diamond}[02.12.2005] |
||
1 | ha | 271 | |
514 | diamond | 272 | ; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk |
273 | ; (see comment to bx_from_load) |
||
274 | cmp cx, 'HA' |
||
275 | jnz no_hd_load |
||
2434 | Serge | 276 | cmp dx, 'RD' |
514 | diamond | 277 | jnz no_hd_load |
278 | mov word [cs:bx_from_load], bx ; {SPraid}[13.03.2007] |
||
488 | spraid | 279 | no_hd_load: |
280 | |||
29 | halyavin | 281 | ; set up stack |
514 | diamond | 282 | mov ax, 3000h |
283 | mov ss, ax |
||
284 | mov sp, 0EC00h |
||
29 | halyavin | 285 | ; set up segment registers |
514 | diamond | 286 | push cs |
287 | pop ds |
||
288 | push cs |
||
289 | pop es |
||
2010 | serge | 290 | end if |
1 | ha | 291 | |
29 | halyavin | 292 | ; set videomode |
514 | diamond | 293 | mov ax, 3 |
294 | int 0x10 |
||
1 | ha | 295 | |
134 | diamond | 296 | if lang eq ru |
1 | ha | 297 | ; Load & set russian VGA font (RU.INC) |
514 | diamond | 298 | mov bp, RU_FNT1 ; RU_FNT1 - First part |
299 | mov bx, 1000h ; 768 bytes |
||
300 | mov cx, 30h ; 48 symbols |
||
301 | mov dx, 80h ; 128 - position of first symbol |
||
302 | mov ax, 1100h |
||
303 | int 10h |
||
1 | ha | 304 | |
514 | diamond | 305 | mov bp, RU_FNT2 ; RU_FNT2 -Second part |
306 | mov bx, 1000h ; 512 bytes |
||
307 | mov cx, 20h ; 32 symbols |
||
308 | mov dx, 0E0h ; 224 - position of first symbol |
||
309 | mov ax, 1100h |
||
310 | int 10h |
||
1 | ha | 311 | ; End set VGA russian font |
274 | kaitz | 312 | else if lang eq et |
514 | diamond | 313 | mov bp, ET_FNT ; ET_FNT1 |
314 | mov bx, 1000h ; |
||
315 | mov cx, 255 ; 256 symbols |
||
316 | xor dx, dx ; 0 - position of first symbol |
||
317 | mov ax, 1100h |
||
318 | int 10h |
||
134 | diamond | 319 | end if |
1 | ha | 320 | |
29 | halyavin | 321 | ; draw frames |
514 | diamond | 322 | push 0xb800 |
323 | pop es |
||
324 | xor di, di |
||
325 | mov ah, 1*16+15 |
||
465 | serge | 326 | |
29 | halyavin | 327 | ; draw top |
514 | diamond | 328 | mov si, d80x25_top |
329 | mov cx, d80x25_top_num * 80 |
||
29 | halyavin | 330 | @@: |
514 | diamond | 331 | lodsb |
332 | stosw |
||
333 | loop @b |
||
29 | halyavin | 334 | ; draw spaces |
514 | diamond | 335 | mov si, space_msg |
336 | mov dx, 25 - d80x25_top_num - d80x25_bottom_num |
||
29 | halyavin | 337 | dfl1: |
514 | diamond | 338 | push si |
339 | mov cx, 80 |
||
29 | halyavin | 340 | @@: |
514 | diamond | 341 | lodsb |
342 | stosw |
||
343 | loop @b |
||
344 | pop si |
||
345 | dec dx |
||
346 | jnz dfl1 |
||
29 | halyavin | 347 | ; draw bottom |
514 | diamond | 348 | mov si, d80x25_bottom |
349 | mov cx, d80x25_bottom_num * 80 |
||
29 | halyavin | 350 | @@: |
514 | diamond | 351 | lodsb |
352 | stosw |
||
353 | loop @b |
||
1 | ha | 354 | |
514 | diamond | 355 | mov byte [space_msg+80], 0 ; now space_msg is null terminated |
1 | ha | 356 | |
514 | diamond | 357 | _setcursor d80x25_top_num,0 |
1 | ha | 358 | |
359 | |||
360 | ; TEST FOR 386+ |
||
361 | |||
514 | diamond | 362 | mov bx, 0x4000 |
1 | ha | 363 | pushf |
364 | pop ax |
||
514 | diamond | 365 | mov dx, ax |
366 | xor ax, bx |
||
1 | ha | 367 | push ax |
368 | popf |
||
369 | pushf |
||
370 | pop ax |
||
514 | diamond | 371 | and ax, bx |
372 | and dx, bx |
||
373 | cmp ax, dx |
||
1 | ha | 374 | jnz cpugood |
514 | diamond | 375 | mov si, not386 |
40 | halyavin | 376 | sayerr: |
1 | ha | 377 | call print |
378 | jmp $ |
||
379 | cpugood: |
||
380 | |||
514 | diamond | 381 | push 0 |
465 | serge | 382 | popf |
383 | sti |
||
384 | |||
29 | halyavin | 385 | ; set up esp |
514 | diamond | 386 | movzx esp, sp |
1 | ha | 387 | |
160 | diamond | 388 | push 0 |
389 | pop es |
||
3725 | Serge | 390 | xor ax, ax |
391 | and word [es:BOOT_IDE_BASE_ADDR], ax ;0 |
||
392 | and word [es:BOOT_IDE_BAR0_16], ax ;0 |
||
393 | and word [es:BOOT_IDE_BAR1_16], ax ;0 |
||
394 | and word [es:BOOT_IDE_BAR2_16], ax ;0 |
||
395 | and word [es:BOOT_IDE_BAR3_16], ax ;0 |
||
164 | serge | 396 | ; \begin{Mario79} |
397 | ; find HDD IDE DMA PCI device |
||
160 | diamond | 398 | ; check for PCI BIOS |
399 | mov ax, 0xB101 |
||
400 | int 0x1A |
||
401 | jc .nopci |
||
402 | cmp edx, 'PCI ' |
||
403 | jnz .nopci |
||
404 | ; find PCI class code |
||
405 | ; class 1 = mass storage |
||
406 | ; subclass 1 = IDE controller |
||
407 | ; a) class 1, subclass 1, programming interface 0x80 |
||
3725 | Serge | 408 | ; This is a Parallel IDE Controller which uses IRQs 14 and 15. |
160 | diamond | 409 | mov ax, 0xB103 |
410 | mov ecx, 1*10000h + 1*100h + 0x80 |
||
3725 | Serge | 411 | mov [es:BOOT_IDE_PI_16], cx |
514 | diamond | 412 | xor si, si ; device index = 0 |
160 | diamond | 413 | int 0x1A |
3725 | Serge | 414 | jnc .found_1 ; Parallel IDE Controller |
415 | ; b) class 1, subclass 1, programming interface 0x8f |
||
160 | diamond | 416 | mov ax, 0xB103 |
3725 | Serge | 417 | mov ecx, 1*10000h + 1*100h + 0x8f |
418 | mov [es:BOOT_IDE_PI_16], cx |
||
514 | diamond | 419 | xor si, si ; device index = 0 |
160 | diamond | 420 | int 0x1A |
421 | jnc .found |
||
187 | diamond | 422 | ; c) class 1, subclass 1, programming interface 0x85 |
160 | diamond | 423 | mov ax, 0xB103 |
187 | diamond | 424 | mov ecx, 1*10000h + 1*100h + 0x85 |
3725 | Serge | 425 | mov [es:BOOT_IDE_PI_16], cx |
426 | xor si, si ; device index = 0 |
||
160 | diamond | 427 | int 0x1A |
3725 | Serge | 428 | jnc .found |
429 | ; d) class 1, subclass 1, programming interface 0x8A |
||
430 | ; This is a Parallel IDE Controller which uses IRQs 14 and 15. |
||
431 | mov ax, 0xB103 |
||
432 | mov ecx, 1*10000h + 1*100h + 0x8A |
||
433 | mov [es:BOOT_IDE_PI_16], cx |
||
434 | xor si, si ; device index = 0 |
||
435 | int 0x1A |
||
436 | jnc .found_1 ; Parallel IDE Controller |
||
437 | |||
438 | jmp .nopci |
||
439 | .found_1: |
||
440 | ; get memory base BAR4 |
||
160 | diamond | 441 | mov ax, 0xB10A |
442 | mov di, 0x20 ; memory base is config register at 0x20 |
||
3725 | Serge | 443 | push cx |
160 | diamond | 444 | int 0x1A |
3725 | Serge | 445 | jc .no_BAR4 ;.nopci |
160 | diamond | 446 | and cx, 0xFFF0 ; clear address decode type |
2441 | Serge | 447 | mov [es:BOOT_IDE_BASE_ADDR], cx |
3725 | Serge | 448 | .no_BAR4: |
449 | pop cx |
||
450 | .found: |
||
451 | ; get memory base BAR0 |
||
452 | mov ax, 0xB10A |
||
453 | mov di, 0x10 ; memory base is config register at 0x10 |
||
454 | push cx |
||
455 | int 0x1A |
||
456 | jc .no_BAR0 ;.nopci |
||
457 | mov [es:BOOT_IDE_BAR0_16], cx |
||
458 | .no_BAR0: |
||
459 | pop cx |
||
460 | ; get memory base BAR1 |
||
461 | mov ax, 0xB10A |
||
462 | mov di, 0x14 ; memory base is config register at 0x14 |
||
463 | push cx |
||
464 | int 0x1A |
||
465 | jc .no_BAR1 ;.nopci |
||
466 | mov [es:BOOT_IDE_BAR1_16], cx |
||
467 | .no_BAR1: |
||
468 | pop cx |
||
469 | ; get memory base BAR2 |
||
470 | mov ax, 0xB10A |
||
471 | mov di, 0x18 ; memory base is config register at 0x18 |
||
472 | push cx |
||
473 | int 0x1A |
||
474 | jc .no_BAR2 ;.nopci |
||
475 | mov [es:BOOT_IDE_BAR2_16], cx |
||
476 | .no_BAR2: |
||
477 | pop cx |
||
478 | ; get memory base BAR3 |
||
479 | mov ax, 0xB10A |
||
480 | mov di, 0x1C ; memory base is config register at 0x1c |
||
481 | push cx |
||
482 | int 0x1A |
||
483 | jc .no_BAR3 ;.nopci |
||
484 | mov [es:BOOT_IDE_BAR3_16], cx |
||
485 | .no_BAR3: |
||
486 | pop cx |
||
160 | diamond | 487 | .nopci: |
164 | serge | 488 | ; \end{Mario79} |
160 | diamond | 489 | |
3555 | Serge | 490 | mov al, 0xf6 ; Сброс клавиатуры, разрешить сканирование |
514 | diamond | 491 | out 0x60, al |
492 | xor cx, cx |
||
1 | ha | 493 | wait_loop: ; variant 2 |
494 | ; reading state of port of 8042 controller |
||
514 | diamond | 495 | in al, 64h |
496 | and al, 00000010b ; ready flag |
||
164 | serge | 497 | ; wait until 8042 controller is ready |
1 | ha | 498 | loopnz wait_loop |
499 | |||
713 | Lrz | 500 | ;;;/diamond today 5.02.2008 |
501 | ; set keyboard typematic rate & delay |
||
502 | mov al, 0xf3 |
||
503 | out 0x60, al |
||
504 | xor cx, cx |
||
505 | @@: |
||
506 | in al, 64h |
||
507 | test al, 2 |
||
508 | loopnz @b |
||
509 | mov al, 0 |
||
510 | out 0x60, al |
||
511 | xor cx, cx |
||
512 | @@: |
||
513 | in al, 64h |
||
514 | test al, 2 |
||
515 | loopnz @b |
||
516 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
76 | mario79 | 517 | ; --------------- APM --------------------- |
2441 | Serge | 518 | and word [es:BOOT_APM_VERSION], 0 ; ver = 0.0 (APM not found) |
514 | diamond | 519 | mov ax, 0x5300 |
520 | xor bx, bx |
||
521 | int 0x15 |
||
2441 | Serge | 522 | jc apm_end ; APM not found |
514 | diamond | 523 | test cx, 2 |
2441 | Serge | 524 | jz apm_end ; APM 32-bit protected-mode interface not supported |
525 | mov [es:BOOT_APM_VERSION], ax ; Save APM Version |
||
526 | mov [es:BOOT_APM_FLAGS], cx ; Save APM flags |
||
164 | serge | 527 | |
514 | diamond | 528 | ; Write APM ver ---- |
529 | and ax, 0xf0f |
||
530 | add ax, '00' |
||
531 | mov si, msg_apm |
||
532 | mov [si + 5], ah |
||
533 | mov [si + 7], al |
||
534 | _setcursor 0, 3 |
||
535 | call printplain |
||
536 | ; ------------------ |
||
164 | serge | 537 | |
514 | diamond | 538 | mov ax, 0x5304 ; Disconnect interface |
539 | xor bx, bx |
||
540 | int 0x15 |
||
541 | mov ax, 0x5303 ; Connect 32 bit mode interface |
||
542 | xor bx, bx |
||
543 | int 0x15 |
||
465 | serge | 544 | |
2441 | Serge | 545 | mov [es:BOOT_APM_ENTRY], ebx |
546 | mov [es:BOOT_APM_CODE_32], ax |
||
547 | mov [es:BOOT_APM_CODE_16], cx |
||
548 | mov [es:BOOT_APM_DATA_16], dx |
||
465 | serge | 549 | |
76 | mario79 | 550 | apm_end: |
437 | diamond | 551 | _setcursor d80x25_top_num, 0 |
76 | mario79 | 552 | |
2010 | serge | 553 | if ~ defined extended_primary_loader |
713 | Lrz | 554 | ;CHECK current of code |
555 | cmp [cfgmanager.loader_block], -1 |
||
556 | jz noloaderblock |
||
557 | les bx, [cfgmanager.loader_block] |
||
558 | cmp byte [es:bx], 1 |
||
559 | mov si, loader_block_error |
||
560 | jnz sayerr |
||
737 | diamond | 561 | push 0 |
562 | pop es |
||
2010 | serge | 563 | end if |
713 | Lrz | 564 | |
565 | noloaderblock: |
||
1 | ha | 566 | ; DISPLAY VESA INFORMATION |
713 | Lrz | 567 | call print_vesa_info |
568 | call calc_vmodes_table |
||
569 | call check_first_parm ;check and enable cursor_pos |
||
1 | ha | 570 | |
29 | halyavin | 571 | ; \begin{diamond}[30.11.2005] |
572 | cfgmanager: |
||
573 | ; settings: |
||
574 | ; a) preboot_graph = graphical mode |
||
575 | ; preboot_gprobe = probe this mode? |
||
713 | Lrz | 576 | ; b) preboot_dma = use DMA access? |
29 | halyavin | 577 | ; c) preboot_vrrm = use VRR? |
578 | ; d) preboot_device = from what boot? |
||
713 | Lrz | 579 | |
29 | halyavin | 580 | ; determine default settings |
2010 | serge | 581 | if ~ defined extended_primary_loader |
514 | diamond | 582 | mov [.bSettingsChanged], 0 |
2010 | serge | 583 | end if |
713 | Lrz | 584 | |
585 | ;.preboot_gr_end: |
||
726 | diamond | 586 | mov di, preboot_device |
587 | ; if image in memory is present and [preboot_device] is uninitialized, |
||
588 | ; set it to use this preloaded image |
||
589 | cmp byte [di], 0 |
||
590 | jnz .preboot_device_inited |
||
2010 | serge | 591 | if defined extended_primary_loader |
592 | inc byte [di] |
||
593 | cmp byte [bootdevice], 'f' ; floppy? |
||
594 | jz .preboot_device_inited |
||
595 | inc byte [di] |
||
596 | else |
||
726 | diamond | 597 | cmp [.loader_block], -1 |
598 | jz @f |
||
599 | les bx, [.loader_block] |
||
600 | test byte [es:bx+1], 1 |
||
601 | jz @f |
||
602 | mov byte [di], 3 |
||
603 | jmp .preboot_device_inited |
||
604 | @@: |
||
605 | ; otherwise, set [preboot_device] to 1 (default value - boot from floppy) |
||
606 | mov byte [di], 1 |
||
2010 | serge | 607 | end if |
726 | diamond | 608 | .preboot_device_inited: |
1018 | diamond | 609 | ; following 4 lines set variables to 1 if its current value is 0 |
726 | diamond | 610 | cmp byte [di+preboot_dma-preboot_device], 1 |
611 | adc byte [di+preboot_dma-preboot_device], 0 |
||
3725 | Serge | 612 | ; cmp byte [di+preboot_biosdisk-preboot_device], 1 |
613 | ; adc byte [di+preboot_biosdisk-preboot_device], 0 |
||
2268 | Serge | 614 | ;; default value for VRR is OFF |
615 | ; cmp byte [di+preboot_vrrm-preboot_device], 0 |
||
616 | ; jnz @f |
||
617 | ; mov byte [di+preboot_vrrm-preboot_device], 2 |
||
618 | ;@@: |
||
29 | halyavin | 619 | ; notify user |
713 | Lrz | 620 | _setcursor 5,2 |
621 | |||
514 | diamond | 622 | mov si, linef |
713 | Lrz | 623 | call printplain |
514 | diamond | 624 | mov si, start_msg |
625 | call print |
||
626 | mov si, time_msg |
||
627 | call print |
||
29 | halyavin | 628 | ; get start time |
514 | diamond | 629 | call .gettime |
630 | mov [.starttime], eax |
||
631 | mov word [.timer], .newtimer |
||
632 | mov word [.timer+2], cs |
||
29 | halyavin | 633 | .printcfg: |
946 | lrz | 634 | |
514 | diamond | 635 | _setcursor 9,0 |
636 | mov si, current_cfg_msg |
||
637 | call print |
||
638 | mov si, curvideo_msg |
||
639 | call print |
||
713 | Lrz | 640 | |
641 | call draw_current_vmode |
||
642 | |||
709 | diamond | 643 | mov si, usebd_msg |
644 | cmp [preboot_biosdisk], 1 |
||
645 | call .say_on_off |
||
2268 | Serge | 646 | ; mov si, vrrm_msg |
647 | ; cmp [preboot_vrrm], 1 |
||
648 | ; call .say_on_off |
||
514 | diamond | 649 | mov si, preboot_device_msg |
650 | call print |
||
651 | mov al, [preboot_device] |
||
2010 | serge | 652 | if defined extended_primary_loader |
653 | and eax, 3 |
||
654 | else |
||
545 | spraid | 655 | and eax, 7 |
2010 | serge | 656 | end if |
514 | diamond | 657 | mov si, [preboot_device_msgs+eax*2] |
658 | call printplain |
||
726 | diamond | 659 | .show_remarks: |
660 | ; show remarks in gray color |
||
661 | mov di, ((21-num_remarks)*80 + 2)*2 |
||
662 | push 0xB800 |
||
663 | pop es |
||
664 | mov cx, num_remarks |
||
665 | mov si, remarks |
||
666 | .write_remarks: |
||
667 | lodsw |
||
668 | push si |
||
669 | xchg ax, si |
||
670 | mov ah, 1*16+7 ; background: blue (1), foreground: gray (7) |
||
671 | push di |
||
672 | .write_remark: |
||
673 | lodsb |
||
674 | test al, al |
||
675 | jz @f |
||
676 | stosw |
||
677 | jmp .write_remark |
||
678 | @@: |
||
679 | pop di |
||
680 | pop si |
||
681 | add di, 80*2 |
||
682 | loop .write_remarks |
||
29 | halyavin | 683 | .wait: |
514 | diamond | 684 | _setcursor 25,0 ; out of screen |
34 | halyavin | 685 | ; set timer interrupt handler |
514 | diamond | 686 | cli |
687 | push 0 |
||
688 | pop es |
||
713 | Lrz | 689 | push dword [es:8*4] |
690 | pop dword [.oldtimer] |
||
691 | push dword [.timer] |
||
2441 | Serge | 692 | pop dword [es:8*4] |
713 | Lrz | 693 | ; mov eax, [es:8*4] |
694 | ; mov [.oldtimer], eax |
||
695 | ; mov eax, [.timer] |
||
696 | ; mov [es:8*4], eax |
||
514 | diamond | 697 | sti |
29 | halyavin | 698 | ; wait for keypressed |
2434 | Serge | 699 | xor ax, ax |
514 | diamond | 700 | int 16h |
701 | push ax |
||
29 | halyavin | 702 | ; restore timer interrupt |
713 | Lrz | 703 | ; push 0 |
704 | ; pop es |
||
514 | diamond | 705 | mov eax, [.oldtimer] |
706 | mov [es:8*4], eax |
||
707 | mov [.timer], eax |
||
946 | lrz | 708 | |
514 | diamond | 709 | _setcursor 7,0 |
710 | mov si, space_msg |
||
711 | call printplain |
||
726 | diamond | 712 | ; clear remarks and restore normal attributes |
713 | push es |
||
714 | mov di, ((21-num_remarks)*80 + 2)*2 |
||
715 | push 0xB800 |
||
716 | pop es |
||
717 | mov cx, num_remarks |
||
718 | mov ax, ' ' + (1*16 + 15)*100h |
||
719 | @@: |
||
720 | push cx |
||
721 | mov cx, 76 |
||
722 | rep stosw |
||
723 | pop cx |
||
724 | add di, 4*2 |
||
725 | loop @b |
||
726 | pop es |
||
514 | diamond | 727 | pop ax |
29 | halyavin | 728 | ; switch on key |
514 | diamond | 729 | cmp al, 13 |
730 | jz .continue |
||
731 | or al, 20h |
||
732 | cmp al, 'a' |
||
733 | jz .change_a |
||
734 | cmp al, 'b' |
||
735 | jz .change_b |
||
2268 | Serge | 736 | ; cmp al, 'c' |
737 | ; jz .change_c |
||
738 | cmp al, 'c' ; 'd' |
||
726 | diamond | 739 | jnz .show_remarks |
514 | diamond | 740 | _setcursor 15,0 |
741 | mov si, bdev |
||
742 | call print |
||
2010 | serge | 743 | if defined extended_primary_loader |
744 | mov bx, '12' |
||
745 | else |
||
545 | spraid | 746 | mov bx, '14' |
2010 | serge | 747 | end if |
514 | diamond | 748 | call getkey |
749 | mov [preboot_device], al |
||
750 | _setcursor 13,0 |
||
29 | halyavin | 751 | .d: |
2010 | serge | 752 | if ~ defined extended_primary_loader |
514 | diamond | 753 | mov [.bSettingsChanged], 1 |
2010 | serge | 754 | end if |
713 | Lrz | 755 | call clear_vmodes_table ;clear vmodes_table |
514 | diamond | 756 | jmp .printcfg |
29 | halyavin | 757 | .change_a: |
713 | Lrz | 758 | .loops: |
759 | call draw_vmodes_table |
||
816 | Lrz | 760 | _setcursor 25,0 ; out of screen |
2434 | Serge | 761 | xor ax, ax |
713 | Lrz | 762 | int 0x16 |
763 | ; call clear_table_cursor ;clear current position of cursor |
||
764 | |||
2434 | Serge | 765 | mov si, word [cursor_pos] |
713 | Lrz | 766 | |
2434 | Serge | 767 | cmp ah, 0x48;x,0x48E0 ; up |
713 | Lrz | 768 | jne .down |
2434 | Serge | 769 | cmp si, modes_table |
713 | Lrz | 770 | jbe .loops |
2434 | Serge | 771 | sub word [cursor_pos], size_of_step |
713 | Lrz | 772 | jmp .loops |
773 | |||
2434 | Serge | 774 | .down: |
775 | cmp ah, 0x50;x,0x50E0 ; down |
||
730 | diamond | 776 | jne .pgup |
2434 | Serge | 777 | cmp word[es:si+10], -1 |
2441 | Serge | 778 | je .loops |
2434 | Serge | 779 | add word [cursor_pos], size_of_step |
713 | Lrz | 780 | jmp .loops |
781 | |||
2434 | Serge | 782 | .pgup: |
783 | cmp ah, 0x49 ; page up |
||
730 | diamond | 784 | jne .pgdn |
731 | diamond | 785 | sub si, size_of_step*long_v_table |
730 | diamond | 786 | cmp si, modes_table |
787 | jae @f |
||
788 | mov si, modes_table |
||
789 | @@: |
||
790 | mov word [cursor_pos], si |
||
791 | mov si, word [home_cursor] |
||
731 | diamond | 792 | sub si, size_of_step*long_v_table |
730 | diamond | 793 | cmp si, modes_table |
794 | jae @f |
||
795 | mov si, modes_table |
||
796 | @@: |
||
797 | mov word [home_cursor], si |
||
798 | jmp .loops |
||
799 | |||
2434 | Serge | 800 | .pgdn: |
801 | cmp ah, 0x51 ; page down |
||
730 | diamond | 802 | jne .enter |
803 | mov ax, [end_cursor] |
||
731 | diamond | 804 | add si, size_of_step*long_v_table |
730 | diamond | 805 | cmp si, ax |
806 | jb @f |
||
807 | mov si, ax |
||
808 | sub si, size_of_step |
||
809 | @@: |
||
810 | mov word [cursor_pos], si |
||
811 | mov si, word [home_cursor] |
||
731 | diamond | 812 | sub ax, size_of_step*long_v_table |
813 | add si, size_of_step*long_v_table |
||
730 | diamond | 814 | cmp si, ax |
815 | jb @f |
||
816 | mov si, ax |
||
817 | @@: |
||
818 | mov word [home_cursor], si |
||
819 | jmp .loops |
||
820 | |||
2434 | Serge | 821 | .enter: |
822 | cmp al, 0x0D;x,0x1C0D ; enter |
||
713 | Lrz | 823 | jne .loops |
824 | push word [cursor_pos] |
||
746 | Lrz | 825 | pop bp |
826 | push word [es:bp] |
||
827 | pop word [x_save] |
||
828 | push word [es:bp+2] |
||
829 | pop word [y_save] |
||
816 | Lrz | 830 | push word [es:bp+6] |
749 | Lrz | 831 | pop word [number_vm] |
2434 | Serge | 832 | mov word [preboot_graph], bp ;save choose |
2441 | Serge | 833 | |
514 | diamond | 834 | jmp .d |
713 | Lrz | 835 | |
29 | halyavin | 836 | .change_b: |
514 | diamond | 837 | _setcursor 15,0 |
709 | diamond | 838 | ; mov si, ask_dma |
839 | ; call print |
||
840 | ; mov bx, '13' |
||
841 | ; call getkey |
||
842 | ; mov [preboot_dma], al |
||
843 | mov si, ask_bd |
||
514 | diamond | 844 | call print |
709 | diamond | 845 | mov bx, '12' |
514 | diamond | 846 | call getkey |
709 | diamond | 847 | mov [preboot_biosdisk], al |
514 | diamond | 848 | _setcursor 11,0 |
849 | jmp .d |
||
2268 | Serge | 850 | ;.change_c: |
851 | ; _setcursor 15,0 |
||
852 | ; mov si, vrrmprint |
||
853 | ; call print |
||
854 | ; mov bx, '12' |
||
855 | ; call getkey |
||
856 | ; mov [preboot_vrrm], al |
||
857 | ; _setcursor 12,0 |
||
858 | ; jmp .d |
||
713 | Lrz | 859 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
40 | halyavin | 860 | .say_on_off: |
514 | diamond | 861 | pushf |
862 | call print |
||
863 | mov si, on_msg |
||
864 | popf |
||
865 | jz @f |
||
866 | mov si, off_msg |
||
2434 | Serge | 867 | @@: |
868 | jmp printplain |
||
40 | halyavin | 869 | ; novesa and vervesa strings are not used at the moment of executing this code |
870 | virtual at novesa |
||
29 | halyavin | 871 | .oldtimer dd ? |
872 | .starttime dd ? |
||
2010 | serge | 873 | if ~ defined extended_primary_loader |
29 | halyavin | 874 | .bSettingsChanged db ? |
2010 | serge | 875 | end if |
34 | halyavin | 876 | .timer dd ? |
40 | halyavin | 877 | end virtual |
2010 | serge | 878 | if ~ defined extended_primary_loader |
143 | diamond | 879 | .loader_block dd -1 |
2010 | serge | 880 | end if |
29 | halyavin | 881 | .gettime: |
514 | diamond | 882 | mov ah, 0 |
883 | int 1Ah |
||
884 | xchg ax, cx |
||
885 | shl eax, 10h |
||
886 | xchg ax, dx |
||
887 | ret |
||
29 | halyavin | 888 | .newtimer: |
514 | diamond | 889 | push ds |
890 | push cs |
||
891 | pop ds |
||
892 | pushf |
||
893 | call [.oldtimer] |
||
894 | pushad |
||
895 | call .gettime |
||
896 | sub eax, [.starttime] |
||
2010 | serge | 897 | if defined extended_primary_loader |
898 | sub ax, [preboot_timeout] |
||
899 | else |
||
514 | diamond | 900 | sub ax, 18*5 |
2010 | serge | 901 | end if |
514 | diamond | 902 | jae .timergo |
903 | neg ax |
||
904 | add ax, 18-1 |
||
905 | mov bx, 18 |
||
906 | xor dx, dx |
||
907 | div bx |
||
29 | halyavin | 908 | if lang eq ru |
3555 | Serge | 909 | ; подождите 5 секунд, 4/3/2 секунды, 1 секунду |
514 | diamond | 910 | cmp al, 5 |
911 | mov cl, ' ' |
||
912 | jae @f |
||
913 | cmp al, 1 |
||
3555 | Serge | 914 | mov cl, 0xE3 ; 'у' in cp866 |
514 | diamond | 915 | jz @f |
3555 | Serge | 916 | mov cl, 0xEB ; 'ы' in cp866 |
2434 | Serge | 917 | @@: |
918 | mov [time_str+9], cl |
||
274 | kaitz | 919 | else if lang eq et |
514 | diamond | 920 | cmp al, 1 |
921 | ja @f |
||
3555 | Serge | 922 | mov byte [time_str+9], ' ' |
923 | mov byte [time_str+10], ' ' |
||
381 | serge | 924 | @@: |
3500 | Serge | 925 | else if lang eq sp |
926 | ; esperar 5/4/3/2 segundos, 1 segundo |
||
927 | cmp al, 1 |
||
928 | mov cl, 's' |
||
929 | ja @f |
||
930 | mov cl, ' ' |
||
931 | @@: |
||
932 | mov [time_str+10], cl |
||
29 | halyavin | 933 | else |
934 | ; wait 5/4/3/2 seconds, 1 second |
||
514 | diamond | 935 | cmp al, 1 |
936 | mov cl, 's' |
||
937 | ja @f |
||
938 | mov cl, ' ' |
||
2434 | Serge | 939 | @@: |
940 | mov [time_str+9], cl |
||
29 | halyavin | 941 | end if |
514 | diamond | 942 | add al, '0' |
943 | mov [time_str+1], al |
||
944 | mov si, time_msg |
||
945 | _setcursor 7,0 |
||
946 | call print |
||
947 | _setcursor 25,0 |
||
948 | popad |
||
949 | pop ds |
||
950 | iret |
||
29 | halyavin | 951 | .timergo: |
514 | diamond | 952 | push 0 |
953 | pop es |
||
954 | mov eax, [.oldtimer] |
||
955 | mov [es:8*4], eax |
||
956 | mov sp, 0EC00h |
||
29 | halyavin | 957 | .continue: |
514 | diamond | 958 | sti |
959 | _setcursor 6,0 |
||
960 | mov si, space_msg |
||
961 | call printplain |
||
962 | call printplain |
||
963 | _setcursor 6,0 |
||
964 | mov si, loading_msg |
||
965 | call print |
||
966 | _setcursor 15,0 |
||
2010 | serge | 967 | if ~ defined extended_primary_loader |
514 | diamond | 968 | cmp [.bSettingsChanged], 0 |
969 | jz .load |
||
970 | cmp [.loader_block], -1 |
||
971 | jz .load |
||
972 | les bx, [.loader_block] |
||
973 | mov eax, [es:bx+3] |
||
974 | push ds |
||
975 | pop es |
||
976 | test eax, eax |
||
977 | jz .load |
||
978 | push eax |
||
979 | mov si, save_quest |
||
980 | call print |
||
29 | halyavin | 981 | .waityn: |
514 | diamond | 982 | mov ah, 0 |
983 | int 16h |
||
984 | or al, 20h |
||
985 | cmp al, 'n' |
||
986 | jz .loadc |
||
3500 | Serge | 987 | if lang eq sp |
988 | cmp al, 's' |
||
989 | else |
||
514 | diamond | 990 | cmp al, 'y' |
3500 | Serge | 991 | end if |
514 | diamond | 992 | jnz .waityn |
993 | call putchar |
||
994 | mov byte [space_msg+80], 186 |
||
946 | lrz | 995 | |
514 | diamond | 996 | pop eax |
997 | push cs |
||
998 | push .cont |
||
999 | push eax |
||
946 | lrz | 1000 | retf ;call back |
29 | halyavin | 1001 | .loadc: |
514 | diamond | 1002 | pop eax |
29 | halyavin | 1003 | .cont: |
514 | diamond | 1004 | push cs |
1005 | pop ds |
||
1006 | mov si, space_msg |
||
1007 | mov byte [si+80], 0 |
||
1008 | _setcursor 15,0 |
||
1009 | call printplain |
||
1010 | _setcursor 15,0 |
||
29 | halyavin | 1011 | .load: |
2010 | serge | 1012 | end if |
29 | halyavin | 1013 | ; \end{diamond}[02.12.2005] |
1 | ha | 1014 | |
1015 | ; ASK GRAPHICS MODE |
||
1016 | |||
713 | Lrz | 1017 | call set_vmode |
1 | ha | 1018 | |
1019 | ; GRAPHICS ACCELERATION |
||
346 | diamond | 1020 | ; force yes |
2441 | Serge | 1021 | mov [es:BOOT_MTRR], byte 1 |
1 | ha | 1022 | |
514 | diamond | 1023 | ; DMA ACCESS TO HD |
1 | ha | 1024 | |
514 | diamond | 1025 | mov al, [preboot_dma] |
2441 | Serge | 1026 | mov [es:BOOT_DMA], al |
346 | diamond | 1027 | |
2268 | Serge | 1028 | ;; VRR_M USE |
1029 | ; |
||
1030 | ; mov al,[preboot_vrrm] |
||
1031 | ; mov [es:0x9030], al |
||
1 | ha | 1032 | |
1033 | ; BOOT DEVICE |
||
1034 | |||
514 | diamond | 1035 | mov al, [preboot_device] |
40 | halyavin | 1036 | dec al |
514 | diamond | 1037 | mov [boot_dev], al |
1 | ha | 1038 | |
1103 | diamond | 1039 | ; GET MEMORY MAP |
2010 | serge | 1040 | include '../detect/biosmem.inc' |
1103 | diamond | 1041 | |
1 | ha | 1042 | ; READ DISKETTE TO MEMORY |
1043 | |||
2434 | Serge | 1044 | cmp [boot_dev], 0 |
1 | ha | 1045 | jne no_sys_on_floppy |
2434 | Serge | 1046 | mov si, diskload |
1 | ha | 1047 | call print |
514 | diamond | 1048 | xor ax, ax ; reset drive |
1049 | xor dx, dx |
||
1 | ha | 1050 | int 0x13 |
709 | diamond | 1051 | ; do we boot from CD-ROM? |
1052 | mov ah, 41h |
||
1053 | mov bx, 55AAh |
||
1054 | xor dx, dx |
||
1055 | int 0x13 |
||
1056 | jc .nocd |
||
1057 | cmp bx, 0AA55h |
||
1058 | jnz .nocd |
||
1059 | mov ah, 48h |
||
1060 | push ds |
||
1061 | push es |
||
1062 | pop ds |
||
1063 | mov si, 0xa000 |
||
1064 | mov word [si], 30 |
||
1065 | int 0x13 |
||
1066 | pop ds |
||
1067 | jc .nocd |
||
1068 | push ds |
||
1069 | lds si, [es:si+26] |
||
1070 | test byte [ds:si+10], 40h |
||
1071 | pop ds |
||
1072 | jz .nocd |
||
1073 | ; yes - read all floppy by 18 sectors |
||
795 | shurf | 1074 | |
1075 | ; TODO: !!!! read only first sector and set variables !!!!! |
||
1076 | ; ... |
||
1077 | ; TODO: !!! then read flippy image track by track |
||
2441 | Serge | 1078 | |
816 | Lrz | 1079 | mov cx, 0x0001 ; startcyl,startsector |
709 | diamond | 1080 | .a1: |
1081 | push cx dx |
||
1082 | mov al, 18 |
||
1083 | mov bx, 0xa000 |
||
1084 | call boot_read_floppy |
||
1085 | mov si, movedesc |
||
1086 | push es |
||
1087 | push ds |
||
1088 | pop es |
||
1089 | mov cx, 256*18 |
||
1090 | mov ah, 0x87 |
||
1091 | int 0x15 |
||
1092 | pop es |
||
1093 | pop dx cx |
||
1094 | test ah, ah |
||
1095 | jnz sayerr_floppy |
||
1096 | add dword [si+8*3+2], 512*18 |
||
1097 | inc dh |
||
1098 | cmp dh, 2 |
||
1099 | jnz .a1 |
||
1100 | mov dh, 0 |
||
1101 | inc ch |
||
1102 | cmp ch, 80 |
||
1103 | jae ok_sys_on_floppy |
||
1104 | pusha |
||
1105 | mov al, ch |
||
1106 | shr ch, 2 |
||
1107 | add al, ch |
||
1108 | aam |
||
1109 | xchg al, ah |
||
1110 | add ax, '00' |
||
1111 | mov si, pros |
||
1112 | mov [si], ax |
||
1113 | call printplain |
||
1114 | popa |
||
1115 | jmp .a1 |
||
1116 | .nocd: |
||
1117 | ; no - read only used sectors from floppy |
||
134 | diamond | 1118 | ; now load floppy image to memory |
1119 | ; at first load boot sector and first FAT table |
||
795 | shurf | 1120 | |
1121 | ; read only first sector and fill variables |
||
816 | Lrz | 1122 | mov cx, 0x0001 ; first logical sector |
1123 | xor dx, dx ; head = 0, drive = 0 (a:) |
||
1124 | mov al, 1 ; read one sector |
||
1125 | mov bx, 0xB000 ; es:bx -> data area |
||
1126 | call boot_read_floppy |
||
795 | shurf | 1127 | ; fill the necessary parameters to work with a floppy |
816 | Lrz | 1128 | mov ax, word [es:bx+24] |
1129 | mov word [BPB_SecPerTrk], ax |
||
1130 | mov ax, word [es:bx+26] |
||
1131 | mov word [BPB_NumHeads], ax |
||
1132 | mov ax, word [es:bx+17] |
||
1133 | mov word [BPB_RootEntCnt], ax |
||
1134 | mov ax, word [es:bx+14] |
||
1135 | mov word [BPB_RsvdSecCnt], ax |
||
1136 | mov ax, word [es:bx+19] |
||
1137 | mov word [BPB_TotSec16], ax |
||
1138 | mov al, byte [es:bx+13] |
||
1139 | mov byte [BPB_SecPerClus], al |
||
1140 | mov al, byte [es:bx+16] |
||
1141 | mov byte [BPB_NumFATs], al |
||
925 | Lrz | 1142 | ; |
1143 | mov ax, word [es:bx+22] |
||
1144 | mov word [BPB_FATSz16], ax |
||
1145 | mov cx, word [es:bx+11] |
||
1146 | mov word [BPB_BytsPerSec], cx |
||
1147 | |||
795 | shurf | 1148 | ; count of clusters in FAT12 ((size_of_FAT*2)/3) |
925 | Lrz | 1149 | ; mov ax, word [BPB_FATSz16] |
1150 | ; mov cx, word [BPB_BytsPerSec] |
||
1151 | ;end |
||
816 | Lrz | 1152 | xor dx, dx |
1153 | mul cx |
||
1154 | shl ax, 1 |
||
1155 | mov cx, 3 |
||
1156 | div cx ; now ax - number of clusters in FAT12 |
||
1157 | mov word [end_of_FAT], ax |
||
795 | shurf | 1158 | |
1159 | ; load first FAT table |
||
816 | Lrz | 1160 | mov cx, 0x0002 ; startcyl,startsector ; TODO!!!!! |
134 | diamond | 1161 | xor dx, dx ; starthead,drive |
795 | shurf | 1162 | mov al, byte [BPB_FATSz16] ; no of sectors to read |
1163 | add bx, word [BPB_BytsPerSec] ; es:bx -> data area |
||
134 | diamond | 1164 | call boot_read_floppy |
816 | Lrz | 1165 | mov bx, 0xB000 |
795 | shurf | 1166 | |
134 | diamond | 1167 | ; and copy them to extended memory |
465 | serge | 1168 | mov si, movedesc |
816 | Lrz | 1169 | mov [si+8*2+3], bh ; from |
2441 | Serge | 1170 | |
816 | Lrz | 1171 | mov ax, word [BPB_BytsPerSec] |
1172 | shr ax, 1 ; words per sector |
||
1173 | mov cx, word [BPB_RsvdSecCnt] |
||
1174 | add cx, word [BPB_FATSz16] |
||
1175 | mul cx |
||
1176 | push ax ; save to stack count of words in boot+FAT |
||
1177 | xchg ax, cx |
||
2441 | Serge | 1178 | |
134 | diamond | 1179 | push es |
1180 | push ds |
||
1181 | pop es |
||
1182 | mov ah, 0x87 |
||
1183 | int 0x15 |
||
816 | Lrz | 1184 | pop es |
76 | mario79 | 1185 | test ah, ah |
134 | diamond | 1186 | jz @f |
1187 | sayerr_floppy: |
||
1188 | mov dx, 0x3f2 |
||
1189 | mov al, 0 |
||
1190 | out dx, al |
||
2010 | serge | 1191 | sayerr_memmove: |
465 | serge | 1192 | mov si, memmovefailed |
134 | diamond | 1193 | jmp sayerr_plain |
1194 | @@: |
||
816 | Lrz | 1195 | pop ax ; restore from stack count of words in boot+FAT |
1196 | shl ax, 1 ; make bytes count from count of words |
||
1197 | and eax, 0ffffh |
||
795 | shurf | 1198 | add dword [si+8*3+2], eax |
1199 | |||
1200 | ; copy first FAT to second copy |
||
1201 | ; TODO: BPB_NumFATs !!!!! |
||
816 | Lrz | 1202 | add bx, word [BPB_BytsPerSec] ; !!! TODO: may be need multiply by BPB_RsvdSecCnt !!! |
1203 | mov byte [si+8*2+3], bh ; bx - begin of FAT |
||
2441 | Serge | 1204 | |
816 | Lrz | 1205 | mov ax, word [BPB_BytsPerSec] |
1206 | shr ax, 1 ; words per sector |
||
1207 | mov cx, word [BPB_FATSz16] |
||
1208 | mul cx |
||
1209 | mov cx, ax ; cx - count of words in FAT |
||
795 | shurf | 1210 | |
1211 | push es |
||
1212 | push ds |
||
1213 | pop es |
||
134 | diamond | 1214 | mov ah, 0x87 |
1215 | int 0x15 |
||
1216 | pop es |
||
1217 | test ah, ah |
||
1218 | jnz sayerr_floppy |
||
2441 | Serge | 1219 | |
816 | Lrz | 1220 | mov ax, cx |
1221 | shl ax, 1 |
||
1222 | and eax, 0ffffh ; ax - count of bytes in FAT |
||
795 | shurf | 1223 | add dword [si+8*3+2], eax |
2441 | Serge | 1224 | |
795 | shurf | 1225 | ; reading RootDir |
1226 | ; TODO: BPB_NumFATs |
||
816 | Lrz | 1227 | add bx, ax |
1228 | add bx, 100h |
||
1229 | and bx, 0ff00h ; bx - place in buffer to write RootDir |
||
1230 | push bx |
||
795 | shurf | 1231 | |
816 | Lrz | 1232 | mov bx, word [BPB_BytsPerSec] |
1233 | shr bx, 5 ; divide bx by 32 |
||
1234 | mov ax, word [BPB_RootEntCnt] |
||
1235 | xor dx, dx |
||
1236 | div bx |
||
1237 | push ax ; ax - count of RootDir sectors |
||
795 | shurf | 1238 | |
816 | Lrz | 1239 | mov ax, word [BPB_FATSz16] |
1240 | xor cx, cx |
||
1241 | mov cl, byte [BPB_NumFATs] |
||
1242 | mul cx |
||
1243 | add ax, word [BPB_RsvdSecCnt] ; ax - first sector of RootDir |
||
795 | shurf | 1244 | |
816 | Lrz | 1245 | mov word [FirstDataSector], ax |
1246 | pop bx |
||
1247 | push bx |
||
1248 | add word [FirstDataSector], bx ; Begin of data region of floppy |
||
2441 | Serge | 1249 | |
795 | shurf | 1250 | ; read RootDir |
816 | Lrz | 1251 | call conv_abs_to_THS |
1252 | pop ax |
||
1253 | pop bx ; place in buffer to write |
||
1254 | push ax |
||
1255 | call boot_read_floppy ; read RootDir into buffer |
||
795 | shurf | 1256 | ; copy RootDir |
816 | Lrz | 1257 | mov byte [si+8*2+3], bh ; from buffer |
1258 | pop ax ; ax = count of RootDir sectors |
||
1259 | mov cx, word [BPB_BytsPerSec] |
||
1260 | mul cx |
||
1261 | shr ax, 1 |
||
1262 | mov cx, ax ; count of words to copy |
||
1263 | push es |
||
1264 | push ds |
||
1265 | pop es |
||
795 | shurf | 1266 | mov ah, 0x87 |
1267 | int 0x15 |
||
816 | Lrz | 1268 | pop es |
795 | shurf | 1269 | |
816 | Lrz | 1270 | mov ax, cx |
1271 | shl ax, 1 |
||
1272 | and eax, 0ffffh ; ax - count of bytes in RootDir |
||
1273 | add dword [si+8*3+2], eax ; add count of bytes copied |
||
795 | shurf | 1274 | |
1275 | ; Reading data clusters from floppy |
||
816 | Lrz | 1276 | mov byte [si+8*2+3], bh |
1277 | push bx |
||
795 | shurf | 1278 | |
816 | Lrz | 1279 | mov di, 2 ; First data cluster |
134 | diamond | 1280 | .read_loop: |
816 | Lrz | 1281 | mov bx, di |
1282 | shr bx, 1 ; bx+di = di*1.5 |
||
1283 | jnc .even |
||
1284 | test word [es:bx+di+0xB200], 0xFFF0 ; TODO: may not be 0xB200 !!! |
||
1285 | jmp @f |
||
134 | diamond | 1286 | .even: |
816 | Lrz | 1287 | test word [es:bx+di+0xB200], 0xFFF ; TODO: may not be 0xB200 !!! |
795 | shurf | 1288 | |
134 | diamond | 1289 | @@: |
816 | Lrz | 1290 | jz .skip |
795 | shurf | 1291 | ; read cluster di |
1292 | ;.read: |
||
816 | Lrz | 1293 | ;conv cluster di to abs. sector ax |
1294 | ; ax = (N-2) * BPB_SecPerClus + FirstDataSector |
||
1295 | mov ax, di |
||
1296 | sub ax, 2 |
||
1297 | xor bx, bx |
||
1298 | mov bl, byte [BPB_SecPerClus] |
||
1299 | mul bx |
||
1300 | add ax, word [FirstDataSector] |
||
1301 | call conv_abs_to_THS |
||
1302 | pop bx |
||
1303 | push bx |
||
1304 | mov al, byte [BPB_SecPerClus] ; number of sectors in cluster |
||
1305 | call boot_read_floppy |
||
76 | mario79 | 1306 | push es |
1307 | push ds |
||
1 | ha | 1308 | pop es |
134 | diamond | 1309 | pusha |
795 | shurf | 1310 | ; |
816 | Lrz | 1311 | mov ax, word [BPB_BytsPerSec] |
1312 | xor cx, cx |
||
1313 | mov cl, byte [BPB_SecPerClus] |
||
1314 | mul cx |
||
1315 | shr ax, 1 ; ax = (BPB_BytsPerSec * BPB_SecPerClus)/2 |
||
1316 | mov cx, ax ; number of words to copy (count words in cluster) |
||
795 | shurf | 1317 | ; |
816 | Lrz | 1318 | mov ah, 0x87 |
1319 | int 0x15 ; copy data |
||
134 | diamond | 1320 | test ah, ah |
1 | ha | 1321 | popa |
134 | diamond | 1322 | pop es |
1323 | jnz sayerr_floppy |
||
795 | shurf | 1324 | ; skip cluster di |
134 | diamond | 1325 | .skip: |
816 | Lrz | 1326 | mov ax, word [BPB_BytsPerSec] |
1327 | xor cx, cx |
||
1328 | mov cl, byte [BPB_SecPerClus] |
||
1329 | mul cx |
||
1330 | and eax, 0ffffh ; ax - count of bytes in cluster |
||
1331 | add dword [si+8*3+2], eax |
||
795 | shurf | 1332 | |
816 | Lrz | 1333 | mov ax, word [end_of_FAT] ; max cluster number |
134 | diamond | 1334 | pusha |
1335 | ; draw percentage |
||
795 | shurf | 1336 | ; total clusters: ax |
1337 | ; read clusters: di |
||
816 | Lrz | 1338 | xchg ax, di |
134 | diamond | 1339 | mov cx, 100 |
1340 | mul cx |
||
816 | Lrz | 1341 | div di |
134 | diamond | 1342 | aam |
1343 | xchg al, ah |
||
1344 | add ax, '00' |
||
465 | serge | 1345 | mov si, pros |
134 | diamond | 1346 | cmp [si], ax |
1347 | jz @f |
||
1348 | mov [si], ax |
||
1 | ha | 1349 | call printplain |
134 | diamond | 1350 | @@: |
1 | ha | 1351 | popa |
134 | diamond | 1352 | inc di |
816 | Lrz | 1353 | cmp di, word [end_of_FAT] ; max number of cluster |
134 | diamond | 1354 | jnz .read_loop |
816 | Lrz | 1355 | pop bx ; clear stack |
134 | diamond | 1356 | |
709 | diamond | 1357 | ok_sys_on_floppy: |
514 | diamond | 1358 | mov si, backspace2 |
1 | ha | 1359 | call printplain |
514 | diamond | 1360 | mov si, okt |
1 | ha | 1361 | call printplain |
514 | diamond | 1362 | no_sys_on_floppy: |
1363 | xor ax, ax ; reset drive |
||
1364 | xor dx, dx |
||
1 | ha | 1365 | int 0x13 |
514 | diamond | 1366 | mov dx, 0x3f2 ; floppy motor off |
1367 | mov al, 0 |
||
1368 | out dx, al |
||
1 | ha | 1369 | |
2010 | serge | 1370 | if defined extended_primary_loader |
1371 | cmp [boot_dev], 1 |
||
1372 | jne no_sys_from_primary |
||
1373 | ; load kolibri.img using callback from primary loader |
||
1374 | and word [movedesc + 24 + 2], 0 |
||
1375 | mov byte [movedesc + 24 + 4], 10h |
||
1376 | ; read in blocks of 64K until file is fully loaded |
||
1377 | mov ax, 1 |
||
1378 | .repeat: |
||
1379 | mov di, image_file_struct |
||
1380 | call [bootcallback] |
||
1381 | push cs |
||
1382 | pop ds |
||
1383 | push cs |
||
1384 | pop es |
||
1385 | cmp bx, 1 |
||
1386 | ja sayerr_badsect |
||
1387 | push bx |
||
1388 | mov si, movedesc |
||
1389 | and word [si + 16 + 2], 0 |
||
1390 | mov byte [si + 16 + 4], 4 |
||
1391 | mov ah, 87h |
||
1392 | mov cx, 8000h |
||
1393 | int 15h |
||
1394 | pop bx |
||
1395 | test ah, ah |
||
1396 | jnz sayerr_memmove |
||
1397 | inc byte [si + 24 + 4] |
||
1398 | test bx, bx |
||
1399 | jz no_sys_from_primary |
||
1400 | mov ax, 2 |
||
1401 | jmp .repeat |
||
1402 | no_sys_from_primary: |
||
1403 | end if |
||
1 | ha | 1404 | |
1405 | ; SET GRAPHICS |
||
1406 | |||
514 | diamond | 1407 | xor ax, ax |
1408 | mov es, ax |
||
164 | serge | 1409 | |
2441 | Serge | 1410 | mov ax, [es:BOOT_VESA_MODE] ; vga & 320x200 |
514 | diamond | 1411 | mov bx, ax |
1412 | cmp ax, 0x13 |
||
1 | ha | 1413 | je setgr |
514 | diamond | 1414 | cmp ax, 0x12 |
1 | ha | 1415 | je setgr |
514 | diamond | 1416 | mov ax, 0x4f02 ; Vesa |
412 | serge | 1417 | setgr: |
1 | ha | 1418 | int 0x10 |
514 | diamond | 1419 | test ah, ah |
1420 | mov si, fatalsel |
||
713 | Lrz | 1421 | jnz v_mode_error |
1 | ha | 1422 | ; set mode 0x12 graphics registers: |
514 | diamond | 1423 | cmp bx, 0x12 |
1 | ha | 1424 | jne gmok2 |
1425 | |||
514 | diamond | 1426 | mov al, 0x05 |
1427 | mov dx, 0x03ce |
||
40 | halyavin | 1428 | push dx |
514 | diamond | 1429 | out dx, al ; select GDC mode register |
1430 | mov al, 0x02 |
||
1431 | inc dx |
||
1432 | out dx, al ; set write mode 2 |
||
1 | ha | 1433 | |
514 | diamond | 1434 | mov al, 0x02 |
1435 | mov dx, 0x03c4 |
||
1436 | out dx, al ; select VGA sequencer map mask register |
||
1437 | mov al, 0x0f |
||
1438 | inc dx |
||
1439 | out dx, al ; set mask for all planes 0-3 |
||
1 | ha | 1440 | |
514 | diamond | 1441 | mov al, 0x08 |
1442 | pop dx |
||
1443 | out dx, al ; select GDC bit mask register |
||
1 | ha | 1444 | ; for writes to 0x03cf |
412 | serge | 1445 | gmok2: |
76 | mario79 | 1446 | push ds |
514 | diamond | 1447 | pop es |