Subversion Repositories Kolibri OS

Rev

Rev 3539 | Rev 3711 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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