Subversion Repositories Kolibri OS

Rev

Rev 89 | Rev 134 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 89 Rev 103
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                        ;;
2
;;                                                        ;;
3
;;  BOOTCODE.INC                                          ;;
3
;;  BOOTCODE.INC                                          ;;
4
;;                                                        ;;
4
;;                                                        ;;
5
;;  KolibriOS 16-bit loader,                              ;;
5
;;  KolibriOS 16-bit loader,                              ;;
6
;;                        based on bootcode for MenuetOS  ;;
6
;;                        based on bootcode for MenuetOS  ;;
7
;;                                                        ;;
7
;;                                                        ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 
9
 
10
 
10
 
11
 
11
 
12
;==========================================================================
12
;==========================================================================
13
;
13
;
14
;                           16 BIT FUNCTIONS
14
;                           16 BIT FUNCTIONS
15
;
15
;
16
;==========================================================================
16
;==========================================================================
17
 
17
 
18
putchar:
18
putchar:
19
; in: al=character
19
; in: al=character
20
    mov    ah, 0Eh
20
    mov    ah, 0Eh
21
    mov    bh, 0
21
    mov    bh, 0
22
    int    10h
22
    int    10h
23
    ret
23
    ret
24
 
24
 
25
print:
25
print:
26
; in: si->string
26
; in: si->string
27
    mov    al, 186
27
    mov    al, 186
28
    call    putchar
28
    call    putchar
29
    mov    al, ' '
29
    mov    al, ' '
30
    call    putchar
30
    call    putchar
31
 
31
 
32
printplain:
32
printplain:
33
; in: si->string
33
; in: si->string
34
    pusha
34
    pusha
35
    lodsb
35
    lodsb
36
@@:
36
@@:
37
    call    putchar
37
    call    putchar
38
    lodsb
38
    lodsb
39
    cmp    al, 0
39
    cmp    al, 0
40
    jnz    @b
40
    jnz    @b
41
    popa
41
    popa
42
    ret
42
    ret
43
 
43
 
44
; Now int 16 is used for keyboard support.
44
; Now int 16 is used for keyboard support.
45
; This is shorter, simpler and more reliable.
45
; This is shorter, simpler and more reliable.
46
if 0
46
if 0
47
getkey:      push  ecx
47
getkey:      push  ecx
48
             push  edx
48
             push  edx
49
             add   ebx,0x0101
49
             add   ebx,0x0101
50
             xor   eax,eax
50
             xor   eax,eax
51
 
51
 
52
           gk1:
52
           gk1:
53
             in    al,0x60
53
             in    al,0x60
54
             mov   cl,al
54
             mov   cl,al
55
           gk0:
55
           gk0:
56
             in    al,0x60
56
             in    al,0x60
57
             cmp   al,cl
57
             cmp   al,cl
58
             je    gk0
58
             je    gk0
59
             cmp   ax,11
59
             cmp   ax,11
60
             jg    gk0
60
             jg    gk0
61
             gk0_1:
61
             gk0_1:
62
             mov   cl,al
62
             mov   cl,al
63
 
63
 
64
;             add   al,47
64
;             add   al,47
65
;             mov   [ds:keyinbs-0x10000],al
65
;             mov   [ds:keyinbs-0x10000],al
66
;             mov   si,keyinbs-0x10000
66
;             mov   si,keyinbs-0x10000
67
;             call  printplain
67
;             call  printplain
68
 
68
 
69
           gk12:
69
           gk12:
70
             in    al,0x60
70
             in    al,0x60
71
             cmp   al,cl
71
             cmp   al,cl
72
             je    gk12
72
             je    gk12
73
             cmp   ax,240
73
             cmp   ax,240
74
             jne   gk13
74
             jne   gk13
75
             mov   al,cl
75
             mov   al,cl
76
             jmp   gk14
76
             jmp   gk14
77
           gk13:
77
           gk13:
78
             add   cl,128
78
             add   cl,128
79
             cmp   al,cl
79
             cmp   al,cl
80
             jne   gk1
80
             jne   gk1
81
             sub   al,128
81
             sub   al,128
82
           gk14:
82
           gk14:
83
 
83
 
84
             movzx edx,bl
84
             movzx edx,bl
85
             cmp   eax,edx
85
             cmp   eax,edx
86
             jb    gk1
86
             jb    gk1
87
             movzx edx,bh
87
             movzx edx,bh
88
             cmp   eax,edx
88
             cmp   eax,edx
89
             jg    gk1
89
             jg    gk1
90
             test  ebx,0x010000
90
             test  ebx,0x010000
91
             jnz   gk3
91
             jnz   gk3
92
             mov   cx,0x1000
92
             mov   cx,0x1000
93
             mov   dx,cx
93
             mov   dx,cx
94
             add   eax,47
94
             add   eax,47
95
             mov   cx,ax
95
             mov   cx,ax
96
             cmp   cx,58
96
             cmp   cx,58
97
             jb    gk_nozero
97
             jb    gk_nozero
98
             sub   cx,10
98
             sub   cx,10
99
           gk_nozero:
99
           gk_nozero:
100
             mov   [ds:keyin-0x10000],cl
100
             mov   [ds:keyin-0x10000],cl
101
             mov   si,keyin-0x10000
101
             mov   si,keyin-0x10000
102
             call  printplain
102
             call  printplain
103
           gk3:
103
           gk3:
104
             sub   eax,48
104
             sub   eax,48
105
             pop   edx
105
             pop   edx
106
             pop   ecx
106
             pop   ecx
107
             ret
107
             ret
108
end if
108
end if
109
 
109
 
110
getkey:
110
getkey:
111
; get number in range [bl,bh] (bl,bh in ['0'..'9'])
111
; get number in range [bl,bh] (bl,bh in ['0'..'9'])
112
; in: bx=range
112
; in: bx=range
113
; out: ax=digit (1..9, 10 for 0)
113
; out: ax=digit (1..9, 10 for 0)
114
    mov    ah, 0
114
    mov    ah, 0
115
    int    16h
115
    int    16h
116
    cmp    al, bl
116
    cmp    al, bl
117
    jb    getkey
117
    jb    getkey
118
    cmp    al, bh
118
    cmp    al, bh
119
    ja    getkey
119
    ja    getkey
120
    push    ax
120
    push    ax
121
    call    putchar
121
    call    putchar
122
    pop    ax
122
    pop    ax
123
    and    ax, 0Fh
123
    and    ax, 0Fh
124
    jnz    @f
124
    jnz    @f
125
    mov    al, 10
125
    mov    al, 10
126
@@:
126
@@:
127
    ret
127
    ret
128
 
128
 
129
setcursor:
129
setcursor:
130
; in: dl=column, dh=row
130
; in: dl=column, dh=row
131
    mov    ah, 2
131
    mov    ah, 2
132
    mov    bh, 0
132
    mov    bh, 0
133
    int    10h
133
    int    10h
134
    ret
134
    ret
135
 
135
 
136
macro _setcursor row,column
136
macro _setcursor row,column
137
{
137
{
138
    mov    dx, row*256 + column
138
    mov    dx, row*256 + column
139
    call    setcursor
139
    call    setcursor
140
}
140
}
141
 
141
 
142
pagetable_set:
142
pagetable_set:
-
 
143
;eax - physical address
-
 
144
;es:di - page table
-
 
145
;ecx - number of pages to map
143
    or    al, 7
146
    or    al, 7
144
@@:
147
@@:
145
    stosd
148
    stosd
146
    add    eax, 1000h
149
    add    eax, 1000h
147
    loop    @b
150
    loop    @b
148
    ret
151
    ret
149
 
152
 
150
; 16-bit data
153
; 16-bit data
151
; videomodes table
154
; videomodes table
152
		org $+0x10000
155
		org $+0x10000
153
gr_table:
156
gr_table:
154
    dw      0x112+0100000000000000b ,  640 ,  480        ; 1
157
    dw      0x112+0100000000000000b ,  640 ,  480        ; 1
155
    dw      0x115+0100000000000000b ,  800 ,  600        ; 2
158
    dw      0x115+0100000000000000b ,  800 ,  600        ; 2
156
    dw      0x118+0100000000000000b , 1024 ,  768        ; 3
159
    dw      0x118+0100000000000000b , 1024 ,  768        ; 3
157
    dw      0x11B+0100000000000000b , 1280 , 1024        ; 4
160
    dw      0x11B+0100000000000000b , 1280 , 1024        ; 4
158
    dw      0x112 ,  640 , 480                ; 5
161
    dw      0x112 ,  640 , 480                ; 5
159
    dw      0x115 ,  800 , 600                ; 6
162
    dw      0x115 ,  800 , 600                ; 6
160
    dw      0x118 , 1024 , 768                ; 7
163
    dw      0x118 , 1024 , 768                ; 7
161
    dw      0x11B , 1280 ,1024                ; 8
164
    dw      0x11B , 1280 ,1024                ; 8
162
    dw    0x13, 640, 480                    ; 9
165
    dw    0x13, 640, 480                    ; 9
163
    dw    0x12, 640, 480                    ; 0
166
    dw    0x12, 640, 480                    ; 0
164
 
167
 
165
; table for move to extended memory (int 15h, ah=87h)
168
; table for move to extended memory (int 15h, ah=87h)
166
       movedesc:
169
       movedesc:
167
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
170
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
168
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
171
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
169
 
172
 
170
        db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
173
        db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
171
        db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
174
        db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
172
 
175
 
173
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
176
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
174
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
177
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
175
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
178
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
176
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
179
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
177
        	org $-0x10000
180
        	org $-0x10000
178
 
181
 
179
;=========================================================================
182
;=========================================================================
180
;
183
;
181
;                           16 BIT CODE
184
;                           16 BIT CODE
182
;
185
;
183
;=========================================================================
186
;=========================================================================
184
 
187
 
185
 
188
 
186
start_of_code:
189
start_of_code:
187
    cld
190
    cld
188
; \begin{diamond}[02.12.2005]
191
; \begin{diamond}[02.12.2005]
189
    cmp    ax, 'KL'
192
    cmp    ax, 'KL'
190
    jnz    @f
193
    jnz    @f
191
    mov    word [cs:cfgmanager.loader_block-0x10000], si
194
    mov    word [cs:cfgmanager.loader_block-0x10000], si
192
    mov    word [cs:cfgmanager.loader_block+2-0x10000], ds
195
    mov    word [cs:cfgmanager.loader_block+2-0x10000], ds
193
@@:
196
@@:
194
; \end{diamond}[02.12.2005]
197
; \end{diamond}[02.12.2005]
195
 
198
 
196
; set up stack
199
; set up stack
197
    mov    ax, 3000h
200
    mov    ax, 3000h
198
    mov    ss, ax
201
    mov    ss, ax
199
    mov    sp, 0EC00h
202
    mov    sp, 0EC00h
200
; set up segment registers
203
; set up segment registers
201
    push    cs
204
    push    cs
202
    pop    ds
205
    pop    ds
203
    push    cs
206
    push    cs
204
    pop    es
207
    pop    es
205
 
208
 
206
; set videomode
209
; set videomode
207
    mov    ax, 3
210
    mov    ax, 3
208
        int  0x10
211
        int  0x10
209
 
212
 
210
 ; Load & set russian VGA font (RU.INC)
213
 ; Load & set russian VGA font (RU.INC)
211
        mov  bp,RU_FNT1-10000h   ; RU_FNT1 - First part
214
        mov  bp,RU_FNT1-10000h   ; RU_FNT1 - First part
212
          mov  bx,1000h            ; 768 bytes
215
          mov  bx,1000h            ; 768 bytes
213
          mov  cx,30h              ; 48 symbols
216
          mov  cx,30h              ; 48 symbols
214
          mov  dx,80h              ; 128 - position of first symbol
217
          mov  dx,80h              ; 128 - position of first symbol
215
        mov  ax,1100h
218
        mov  ax,1100h
216
          int  10h
219
          int  10h
217
 
220
 
218
        mov  bp,RU_FNT2-10000h   ; RU_FNT2 -Second part
221
        mov  bp,RU_FNT2-10000h   ; RU_FNT2 -Second part
219
        mov  bx,1000h            ; 512 bytes
222
        mov  bx,1000h            ; 512 bytes
220
        mov  cx,20h              ; 32 symbols
223
        mov  cx,20h              ; 32 symbols
221
        mov  dx,0E0h             ; 224 - position of first symbol
224
        mov  dx,0E0h             ; 224 - position of first symbol
222
        mov  ax,1100h
225
        mov  ax,1100h
223
          int  10h
226
          int  10h
224
 ; End set VGA russian font
227
 ; End set VGA russian font
225
 
228
 
226
; draw frames
229
; draw frames
227
    push    0xb800
230
    push    0xb800
228
    pop    es
231
    pop    es
229
    xor    di, di
232
    xor    di, di
230
;        mov  si,d80x25-0x10000
233
;        mov  si,d80x25-0x10000
231
;        mov  cx,80*25
234
;        mov  cx,80*25
232
;        mov  ah,1*16+15
235
;        mov  ah,1*16+15
233
;       dfl1:
236
;       dfl1:
234
;        lodsb
237
;        lodsb
235
;        stosw
238
;        stosw
236
;        loop dfl1
239
;        loop dfl1
237
    mov    ah, 1*16+15
240
    mov    ah, 1*16+15
238
; draw top
241
; draw top
239
    mov    si, d80x25_top - 0x10000
242
    mov    si, d80x25_top - 0x10000
240
    mov    cx, d80x25_top_num * 80
243
    mov    cx, d80x25_top_num * 80
241
@@:
244
@@:
242
    lodsb
245
    lodsb
243
    stosw
246
    stosw
244
    loop    @b
247
    loop    @b
245
; draw spaces
248
; draw spaces
246
    mov    si, space_msg - 0x10000
249
    mov    si, space_msg - 0x10000
247
    mov    cx, 25 - d80x25_top_num - d80x25_bottom_num
250
    mov    cx, 25 - d80x25_top_num - d80x25_bottom_num
248
dfl1:
251
dfl1:
249
    push    cx
252
    push    cx
250
    push    si
253
    push    si
251
    mov    cx, 80
254
    mov    cx, 80
252
@@:
255
@@:
253
    lodsb
256
    lodsb
254
    stosw
257
    stosw
255
    loop    @b
258
    loop    @b
256
    pop    si
259
    pop    si
257
    pop    cx
260
    pop    cx
258
    loop    dfl1
261
    loop    dfl1
259
; draw bottom
262
; draw bottom
260
    mov    si, d80x25_bottom - 0x10000
263
    mov    si, d80x25_bottom - 0x10000
261
    mov    cx, d80x25_bottom_num * 80
264
    mov    cx, d80x25_bottom_num * 80
262
@@:
265
@@:
263
    lodsb
266
    lodsb
264
    stosw
267
    stosw
265
    loop    @b
268
    loop    @b
266
 
269
 
267
    mov    byte [space_msg-0x10000+80], 0    ; now space_msg is null terminated
270
    mov    byte [space_msg-0x10000+80], 0    ; now space_msg is null terminated
268
 
271
 
269
    _setcursor d80x25_top_num,0
272
    _setcursor d80x25_top_num,0
270
 
273
 
271
 
274
 
272
; TEST FOR 386+
275
; TEST FOR 386+
273
 
276
 
274
    mov    bx, 0x4000
277
    mov    bx, 0x4000
275
        pushf
278
        pushf
276
        pop     ax
279
        pop     ax
277
        mov     dx,ax
280
        mov     dx,ax
278
        xor     ax,bx
281
        xor     ax,bx
279
        push    ax
282
        push    ax
280
        popf
283
        popf
281
        pushf
284
        pushf
282
        pop     ax
285
        pop     ax
283
        and     ax,bx
286
        and     ax,bx
284
        and     dx,bx
287
        and     dx,bx
285
        cmp     ax,dx
288
        cmp     ax,dx
286
        jnz     cpugood
289
        jnz     cpugood
287
        mov     si,not386-0x10000
290
        mov     si,not386-0x10000
288
sayerr:
291
sayerr:
289
        call    print
292
        call    print
290
        jmp     $
293
        jmp     $
291
     cpugood:
294
     cpugood:
292
 
295
 
293
; set up esp
296
; set up esp
294
    movzx    esp, sp
297
    movzx    esp, sp
295
 
298
 
296
; FLUSH 8042 KEYBOARD CONTROLLER
299
; FLUSH 8042 KEYBOARD CONTROLLER
297
 
300
 
298
;// mike.dld [
301
;// mike.dld [
299
 ;       mov     al,0xED
302
 ;       mov     al,0xED
300
 ;       out     0x60,al
303
 ;       out     0x60,al
301
 ;       or      cx,-1
304
 ;       or      cx,-1
302
 ;     @@:
305
 ;     @@:
303
 ;       in      al,0x64
306
 ;       in      al,0x64
304
 ;       test    al,2
307
 ;       test    al,2
305
 ;       jz      @f
308
 ;       jz      @f
306
 ;       loop    @b
309
 ;       loop    @b
307
 ;     @@:
310
 ;     @@:
308
 ;       mov     al,0
311
 ;       mov     al,0
309
 ;       out     0x60,al
312
 ;       out     0x60,al
310
 ;       or      cx,-1
313
 ;       or      cx,-1
311
 ;     @@:
314
 ;     @@:
312
 ;       in      al,0x64
315
 ;       in      al,0x64
313
 ;       test    al,2
316
 ;       test    al,2
314
 ;       jz      @f
317
 ;       jz      @f
315
 ;       loop    @b
318
 ;       loop    @b
316
 ;     @@:
319
 ;     @@:
317
;// mike.dld ]
320
;// mike.dld ]
318
 
321
 
319
;       mov     ecx,10000
322
;       mov     ecx,10000
320
;      fl1:
323
;      fl1:
321
;       in      al,0x64
324
;       in      al,0x64
322
;       loop    fl1
325
;       loop    fl1
323
;       test    al,1
326
;       test    al,1
324
;       jz      fl2
327
;       jz      fl2
325
;       in      al,0x60
328
;       in      al,0x60
326
;       jmp     fl1
329
;       jmp     fl1
327
;      fl2:
330
;      fl2:
328
 
331
 
329
;****************************************************************
332
;****************************************************************
330
; The function is modified Mario79
333
; The function is modified Mario79
331
;*****************************************************************
334
;*****************************************************************
332
; wait_kbd:        ; variant 1
335
; wait_kbd:        ; variant 1
333
;       mov      cx,2500h  ;çàäåðæêà ïîðÿäêà 10 ìñåê
336
;       mov      cx,2500h  ;çàäåðæêà ïîðÿäêà 10 ìñåê
334
; test_kbd:
337
; test_kbd:
335
;       in       al,64h    ;÷èòàåì ñîñòîÿíèå êëàâèàòóðû
338
;       in       al,64h    ;÷èòàåì ñîñòîÿíèå êëàâèàòóðû
336
;       test     al,2      ;ïðîâåðêà áèòà ãîòîâíîñòè
339
;       test     al,2      ;ïðîâåðêà áèòà ãîòîâíîñòè
337
;       loopnz   test_kbd
340
;       loopnz   test_kbd
338
 
341
 
339
    mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
342
    mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
340
    out   0x60,al
343
    out   0x60,al
341
    xor   cx,cx
344
    xor   cx,cx
342
wait_loop:       ; variant 2
345
wait_loop:       ; variant 2
343
; reading state of port of 8042 controller
346
; reading state of port of 8042 controller
344
        in      al,64h 
347
        in      al,64h 
345
        and     al,00000010b  ; ready flag
348
        and     al,00000010b  ; ready flag
346
; wait until 8042 controller is ready 
349
; wait until 8042 controller is ready 
347
        loopnz  wait_loop
350
        loopnz  wait_loop
348
 
351
 
349
; --------------- APM ---------------------
352
; --------------- APM ---------------------
350
    push    0
353
    push    0
351
    pop    es
354
    pop    es
352
    mov    word [es : 0x9044], 0        ; ver = 0.0 (APM not found)
355
    mov    word [es : 0x9044], 0        ; ver = 0.0 (APM not found)
353
    mov    ax, 0x5300
356
    mov    ax, 0x5300
354
    xor    bx, bx
357
    xor    bx, bx
355
    int    0x15
358
    int    0x15
356
    jc    apm_end                ; APM not found
359
    jc    apm_end                ; APM not found
357
    test    cx, 2
360
    test    cx, 2
358
    jz    apm_end                ; APM 32-bit protected-mode interface not supported
361
    jz    apm_end                ; APM 32-bit protected-mode interface not supported
359
    mov    [es : 0x9044], ax        ; Save APM Version
362
    mov    [es : 0x9044], ax        ; Save APM Version
360
    mov    [es : 0x9046], cx        ; Save APM flags
363
    mov    [es : 0x9046], cx        ; Save APM flags
361
    
364
    
362
    ; Write APM ver ----
365
    ; Write APM ver ----
363
    and    ax, 0xf0f
366
    and    ax, 0xf0f
364
    add    ax, '00'
367
    add    ax, '00'
365
    mov    si, msg_apm - 0x10000
368
    mov    si, msg_apm - 0x10000
366
    mov    [si + 5], ah
369
    mov    [si + 5], ah
367
    mov    [si + 7], al
370
    mov    [si + 7], al
368
    _setcursor 0, 3
371
    _setcursor 0, 3
369
    call    printplain
372
    call    printplain
370
    _setcursor d80x25_top_num,0
373
    _setcursor d80x25_top_num,0
371
    ; ------------------
374
    ; ------------------
372
    
375
    
373
    mov    ax, 0x5304            ; Disconnect interface
376
    mov    ax, 0x5304            ; Disconnect interface
374
    xor    bx, bx
377
    xor    bx, bx
375
    int    0x15
378
    int    0x15
376
    mov    ax, 0x5303            ; Connect 32 bit mode interface
379
    mov    ax, 0x5303            ; Connect 32 bit mode interface
377
    xor    bx, bx
380
    xor    bx, bx
378
    int    0x15
381
    int    0x15
379
    ; init selectors
382
    ; init selectors
380
    movzx    eax, ax ; real-mode segment base address of protected-mode 32-bit code segment
383
    movzx    eax, ax ; real-mode segment base address of protected-mode 32-bit code segment
381
    shl    eax, 4
384
    shl    eax, 4
382
    mov    [apm_code_32 - 0x10000 + 2], ax
385
    mov    [apm_code_32 - 0x10000 + 2], ax
383
    shr    eax, 16
386
    shr    eax, 16
384
    mov    [apm_code_32 - 0x10000 + 4], al
387
    mov    [apm_code_32 - 0x10000 + 4], al
385
    movzx    ecx, cx ; real-mode segment base address of protected-mode 16-bit code segment
388
    movzx    ecx, cx ; real-mode segment base address of protected-mode 16-bit code segment
386
    shl    ecx, 4
389
    shl    ecx, 4
387
    mov    [apm_code_16 - 0x10000 + 2], cx
390
    mov    [apm_code_16 - 0x10000 + 2], cx
388
    shr    ecx, 16
391
    shr    ecx, 16
389
    mov    [apm_code_16 - 0x10000 + 4], cl
392
    mov    [apm_code_16 - 0x10000 + 4], cl
390
    movzx    edx, dx ; real-mode segment base address of protected-mode 16-bit data segment
393
    movzx    edx, dx ; real-mode segment base address of protected-mode 16-bit data segment
391
    shl    edx, 4
394
    shl    edx, 4
392
    mov    [apm_data_16 - 0x10000 + 2], dx
395
    mov    [apm_data_16 - 0x10000 + 2], dx
393
    shr    edx, 16
396
    shr    edx, 16
394
    mov    [apm_data_16 - 0x10000 + 4], dl
397
    mov    [apm_data_16 - 0x10000 + 4], dl
395
    mov    [es : 0x9040], ebx              ; offset of APM entry point
398
    mov    [es : 0x9040], ebx              ; offset of APM entry point
396
apm_end:
399
apm_end:
397
; -----------------------------------------        
400
; -----------------------------------------        
398
 
401
 
399
; DISPLAY VESA INFORMATION
402
; DISPLAY VESA INFORMATION
400
 
403
 
401
    push    0
404
    push    0
402
    pop    es
405
    pop    es
403
        mov     ax,0x4f00
406
        mov     ax,0x4f00
404
        mov     di,0xa000
407
        mov     di,0xa000
405
        int     0x10
408
        int     0x10
406
        cmp     ax,0x004f
409
        cmp     ax,0x004f
407
        mov    si, novesa-0x10000
410
        mov    si, novesa-0x10000
408
        jnz    @f
411
        jnz    @f
409
        mov     ax,[es:di+4]
412
        mov     ax,[es:di+4]
410
        add     ax,'0'*256+'0'
413
        add     ax,'0'*256+'0'
411
        mov    si,vervesa-0x10000
414
        mov    si,vervesa-0x10000
412
        mov     [si+vervesa_off], ah
415
        mov     [si+vervesa_off], ah
413
        mov     [si+vervesa_off+2], al
416
        mov     [si+vervesa_off+2], al
414
@@:     call    print
417
@@:     call    print
415
 
418
 
416
; \begin{diamond}[30.11.2005]
419
; \begin{diamond}[30.11.2005]
417
cfgmanager:
420
cfgmanager:
418
; settings:
421
; settings:
419
; a) preboot_graph = graphical mode
422
; a) preboot_graph = graphical mode
420
;    preboot_gprobe = probe this mode?
423
;    preboot_gprobe = probe this mode?
421
; b) preboot_mtrr = use hardware acceleration?
424
; b) preboot_mtrr = use hardware acceleration?
422
; c) preboot_vrrm = use VRR?
425
; c) preboot_vrrm = use VRR?
423
; d) preboot_device = from what boot?
426
; d) preboot_device = from what boot?
424
    mov    di, preboot_graph-0x10000
427
    mov    di, preboot_graph-0x10000
425
; check bootloader block
428
; check bootloader block
426
    cmp    [.loader_block-0x10000], 0
429
    cmp    [.loader_block-0x10000], 0
427
    jz    .noloaderblock
430
    jz    .noloaderblock
428
    les    bx, [.loader_block-0x10000]
431
    les    bx, [.loader_block-0x10000]
429
    cmp    byte [es:bx], 1
432
    cmp    byte [es:bx], 1
430
    mov    si, loader_block_error-0x10000
433
    mov    si, loader_block_error-0x10000
431
    jnz    sayerr
434
    jnz    sayerr
432
    test    byte [es:bx+1], 1
435
    test    byte [es:bx+1], 1
433
    jz    @f
436
    jz    @f
434
; image in memory present
437
; image in memory present
435
    cmp    [di+preboot_device-preboot_graph], 0
438
    cmp    [di+preboot_device-preboot_graph], 0
436
    jnz    @f
439
    jnz    @f
437
    mov    [di+preboot_device-preboot_graph], 3
440
    mov    [di+preboot_device-preboot_graph], 3
438
@@:
441
@@:
439
.noloaderblock:
442
.noloaderblock:
440
; determine default settings
443
; determine default settings
441
    mov    [.bSettingsChanged-0x10000], 0
444
    mov    [.bSettingsChanged-0x10000], 0
442
    cmp    byte [di], 0
445
    cmp    byte [di], 0
443
    jnz    .preboot_gr_end
446
    jnz    .preboot_gr_end
444
    mov    [di+preboot_gprobe-preboot_graph], 0
447
    mov    [di+preboot_gprobe-preboot_graph], 0
445
    mov    al, [vervesa+vervesa_off-0x10000]
448
    mov    al, [vervesa+vervesa_off-0x10000]
446
    cmp    al, 'x'
449
    cmp    al, 'x'
447
    jz    .novesa
450
    jz    .novesa
448
    cmp    al, '1'
451
    cmp    al, '1'
449
    jz    .vesa12
452
    jz    .vesa12
450
    mov    [di+preboot_gprobe-preboot_graph], 2
453
    mov    [di+preboot_gprobe-preboot_graph], 2
451
    mov    al, 3
454
    mov    al, 3
452
    jmp    @f
455
    jmp    @f
453
.vesa12:
456
.vesa12:
454
    mov    al, 7
457
    mov    al, 7
455
    jmp    @f
458
    jmp    @f
456
.novesa:
459
.novesa:
457
    mov    al, 10
460
    mov    al, 10
458
@@:
461
@@:
459
    mov    [di], al
462
    mov    [di], al
460
.preboot_gr_end:
463
.preboot_gr_end:
461
    cmp    [di+preboot_mtrr-preboot_graph], 1
464
    cmp    [di+preboot_mtrr-preboot_graph], 1
462
    adc    [di+preboot_mtrr-preboot_graph], 0
465
    adc    [di+preboot_mtrr-preboot_graph], 0
463
    cmp    [di+preboot_vrrm-preboot_graph], 1
466
    cmp    [di+preboot_vrrm-preboot_graph], 1
464
    adc    [di+preboot_vrrm-preboot_graph], 0
467
    adc    [di+preboot_vrrm-preboot_graph], 0
465
    cmp    [di+preboot_device-preboot_graph], 1
468
    cmp    [di+preboot_device-preboot_graph], 1
466
    adc    [di+preboot_device-preboot_graph], 0
469
    adc    [di+preboot_device-preboot_graph], 0
467
; notify user
470
; notify user
468
    mov    si, linef-0x10000
471
    mov    si, linef-0x10000
469
    call    print
472
    call    print
470
    mov    si, start_msg-0x10000
473
    mov    si, start_msg-0x10000
471
    call    print
474
    call    print
472
    mov    si, time_msg-0x10000
475
    mov    si, time_msg-0x10000
473
    call    print
476
    call    print
474
; get start time
477
; get start time
475
    call    .gettime
478
    call    .gettime
476
    mov    [.starttime-0x10000], eax
479
    mov    [.starttime-0x10000], eax
477
    mov    word [.timer-0x10000], .newtimer
480
    mov    word [.timer-0x10000], .newtimer
478
    mov    word [.timer-0x10000+2], cs
481
    mov    word [.timer-0x10000+2], cs
479
.printcfg:
482
.printcfg:
480
    _setcursor 9,0
483
    _setcursor 9,0
481
    mov    si, current_cfg_msg-0x10000
484
    mov    si, current_cfg_msg-0x10000
482
    call    print
485
    call    print
483
    mov    si, curvideo_msg-0x10000
486
    mov    si, curvideo_msg-0x10000
484
    call    print
487
    call    print
485
    mov    al, [preboot_graph-0x10000]
488
    mov    al, [preboot_graph-0x10000]
486
    cmp    al, 8
489
    cmp    al, 8
487
    ja    .pnovesa
490
    ja    .pnovesa
488
    mov    dl, al
491
    mov    dl, al
489
    and    eax, 3
492
    and    eax, 3
490
    mov    si, [modes_msg-0x10000+eax*2]
493
    mov    si, [modes_msg-0x10000+eax*2]
491
    call    printplain
494
    call    printplain
492
    mov    si, modevesa20-0x10000
495
    mov    si, modevesa20-0x10000
493
    cmp    dl, 4
496
    cmp    dl, 4
494
    jbe    @f
497
    jbe    @f
495
    mov    si, modevesa12-0x10000
498
    mov    si, modevesa12-0x10000
496
@@:
499
@@:
497
    call    printplain
500
    call    printplain
498
    cmp    dl, 4
501
    cmp    dl, 4
499
    ja    .x
502
    ja    .x
500
    mov    si, probeno_msg-0x10000
503
    mov    si, probeno_msg-0x10000
501
    cmp    [preboot_gprobe-0x10000], 2
504
    cmp    [preboot_gprobe-0x10000], 2
502
    jnz    @f
505
    jnz    @f
503
    mov    si, probeok_msg-0x10000
506
    mov    si, probeok_msg-0x10000
504
@@:
507
@@:
505
    call    printplain
508
    call    printplain
506
.x:
509
.x:
507
    jmp    .c
510
    jmp    .c
508
.pnovesa:
511
.pnovesa:
509
    cmp    al, 9
512
    cmp    al, 9
510
    mov    si, mode9-0x10000
513
    mov    si, mode9-0x10000
511
    jz    @b
514
    jz    @b
512
    mov    si, mode10-0x10000
515
    mov    si, mode10-0x10000
513
    jmp    @b
516
    jmp    @b
514
.c:
517
.c:
515
    mov    si, linef-0x10000
518
    mov    si, linef-0x10000
516
    call    printplain
519
    call    printplain
517
    mov    si, mtrr_msg-0x10000
520
    mov    si, mtrr_msg-0x10000
518
    cmp    [preboot_mtrr-0x10000], 1
521
    cmp    [preboot_mtrr-0x10000], 1
519
    call    .say_on_off
522
    call    .say_on_off
520
    mov    si, vrrm_msg-0x10000
523
    mov    si, vrrm_msg-0x10000
521
    cmp    [preboot_vrrm-0x10000], 1
524
    cmp    [preboot_vrrm-0x10000], 1
522
    call    .say_on_off
525
    call    .say_on_off
523
    mov    si, preboot_device_msg-0x10000
526
    mov    si, preboot_device_msg-0x10000
524
    call    print
527
    call    print
525
    mov    al, [preboot_device-0x10000]
528
    mov    al, [preboot_device-0x10000]
526
    and    eax, 3
529
    and    eax, 3
527
    mov    si, [preboot_device_msgs-0x10000+eax*2]
530
    mov    si, [preboot_device_msgs-0x10000+eax*2]
528
    call    printplain
531
    call    printplain
529
.wait:
532
.wait:
530
    _setcursor 25,0        ; out of screen
533
    _setcursor 25,0        ; out of screen
531
; set timer interrupt handler
534
; set timer interrupt handler
532
    cli
535
    cli
533
    push    0
536
    push    0
534
    pop    es
537
    pop    es
535
    mov    eax, [es:8*4]
538
    mov    eax, [es:8*4]
536
    mov    [.oldtimer-0x10000], eax
539
    mov    [.oldtimer-0x10000], eax
537
    mov    eax, [.timer-0x10000]
540
    mov    eax, [.timer-0x10000]
538
    mov    [es:8*4], eax
541
    mov    [es:8*4], eax
539
    sti
542
    sti
540
; wait for keypressed
543
; wait for keypressed
541
    mov    ah, 0
544
    mov    ah, 0
542
    int    16h
545
    int    16h
543
    push    ax
546
    push    ax
544
; restore timer interrupt
547
; restore timer interrupt
545
    push    0
548
    push    0
546
    pop    es
549
    pop    es
547
    mov    eax, [.oldtimer-0x10000]
550
    mov    eax, [.oldtimer-0x10000]
548
    mov    [es:8*4], eax
551
    mov    [es:8*4], eax
549
    mov    [.timer-0x10000], eax
552
    mov    [.timer-0x10000], eax
550
    _setcursor 7,0
553
    _setcursor 7,0
551
    mov    si, space_msg-0x10000
554
    mov    si, space_msg-0x10000
552
    call    printplain
555
    call    printplain
553
    pop    ax
556
    pop    ax
554
; switch on key
557
; switch on key
555
    cmp    al, 13
558
    cmp    al, 13
556
    jz    .continue
559
    jz    .continue
557
    or    al, 20h
560
    or    al, 20h
558
    cmp    al, 'a'
561
    cmp    al, 'a'
559
    jz    .change_a
562
    jz    .change_a
560
    cmp    al, 'b'
563
    cmp    al, 'b'
561
    jz    .change_b
564
    jz    .change_b
562
    cmp    al, 'c'
565
    cmp    al, 'c'
563
    jz    .change_c
566
    jz    .change_c
564
    cmp    al, 'd'
567
    cmp    al, 'd'
565
    jnz    .wait
568
    jnz    .wait
566
    _setcursor 15,0
569
    _setcursor 15,0
567
    mov     si,bdev-0x10000
570
    mov     si,bdev-0x10000
568
    call    print
571
    call    print
569
    mov     bx,'13'
572
    mov     bx,'13'
570
    call    getkey
573
    call    getkey
571
    mov    [preboot_device-0x10000], al
574
    mov    [preboot_device-0x10000], al
572
    _setcursor 13,0
575
    _setcursor 13,0
573
.d:
576
.d:
574
    mov    [.bSettingsChanged-0x10000], 1
577
    mov    [.bSettingsChanged-0x10000], 1
575
    mov    si, space_msg-0x10000
578
    mov    si, space_msg-0x10000
576
    call    printplain
579
    call    printplain
577
    _setcursor 15,0
580
    _setcursor 15,0
578
    mov    cx, 6
581
    mov    cx, 6
579
@@:
582
@@:
580
    call    printplain
583
    call    printplain
581
    loop    @b
584
    loop    @b
582
    jmp    .printcfg
585
    jmp    .printcfg
583
.change_a:
586
.change_a:
584
    _setcursor 15,0
587
    _setcursor 15,0
585
    mov    si, gr_mode-0x10000
588
    mov    si, gr_mode-0x10000
586
    call    printplain
589
    call    printplain
587
    mov     bx, '09'
590
    mov     bx, '09'
588
    call    getkey
591
    call    getkey
589
    mov    [preboot_graph-0x10000], al
592
    mov    [preboot_graph-0x10000], al
590
    cmp    al, 4
593
    cmp    al, 4
591
    ja    @f
594
    ja    @f
592
    mov    si, probetext-0x10000
595
    mov    si, probetext-0x10000
593
    call    printplain
596
    call    printplain
594
    mov    bx, '12'
597
    mov    bx, '12'
595
    call    getkey
598
    call    getkey
596
    mov    [preboot_gprobe-0x10000], al
599
    mov    [preboot_gprobe-0x10000], al
597
@@:
600
@@:
598
    _setcursor 10,0
601
    _setcursor 10,0
599
    jmp    .d
602
    jmp    .d
600
.change_b:
603
.change_b:
601
    _setcursor 15,0
604
    _setcursor 15,0
602
    mov    si, gr_acc-0x10000
605
    mov    si, gr_acc-0x10000
603
    call    print
606
    call    print
604
    mov    bx, '12'
607
    mov    bx, '12'
605
    call    getkey
608
    call    getkey
606
    mov    [preboot_mtrr-0x10000], al
609
    mov    [preboot_mtrr-0x10000], al
607
    _setcursor 11,0
610
    _setcursor 11,0
608
    jmp    .d
611
    jmp    .d
609
.change_c:
612
.change_c:
610
    _setcursor 15,0
613
    _setcursor 15,0
611
    mov    si, vrrmprint-0x10000
614
    mov    si, vrrmprint-0x10000
612
    call    print
615
    call    print
613
    mov    bx, '12'
616
    mov    bx, '12'
614
    call    getkey
617
    call    getkey
615
    mov    [preboot_vrrm-0x10000], al
618
    mov    [preboot_vrrm-0x10000], al
616
    _setcursor 12,0
619
    _setcursor 12,0
617
    jmp    .d
620
    jmp    .d
618
.say_on_off:
621
.say_on_off:
619
    pushf
622
    pushf
620
    call    print
623
    call    print
621
    mov    si, on_msg-0x10000
624
    mov    si, on_msg-0x10000
622
    popf
625
    popf
623
    jz    @f
626
    jz    @f
624
    mov    si, off_msg-0x10000
627
    mov    si, off_msg-0x10000
625
@@:    call    printplain
628
@@:    call    printplain
626
    ret
629
    ret
627
; novesa and vervesa strings are not used at the moment of executing this code
630
; novesa and vervesa strings are not used at the moment of executing this code
628
virtual at novesa
631
virtual at novesa
629
.oldtimer dd ?
632
.oldtimer dd ?
630
.starttime dd ?
633
.starttime dd ?
631
.bSettingsChanged db ?
634
.bSettingsChanged db ?
632
.timer dd ?
635
.timer dd ?
633
end virtual
636
end virtual
634
	org $+0x10000
637
	org $+0x10000
635
.loader_block dd 0
638
.loader_block dd 0
636
	org $-0x10000
639
	org $-0x10000
637
.gettime:
640
.gettime:
638
    mov    ah, 0
641
    mov    ah, 0
639
    int    1Ah
642
    int    1Ah
640
    xchg    ax, cx
643
    xchg    ax, cx
641
    shl    eax, 10h
644
    shl    eax, 10h
642
    xchg    ax, dx
645
    xchg    ax, dx
643
    ret
646
    ret
644
.newtimer:
647
.newtimer:
645
    push    ds
648
    push    ds
646
    push    cs
649
    push    cs
647
    pop    ds
650
    pop    ds
648
    pushf
651
    pushf
649
    call    [.oldtimer-0x10000]
652
    call    [.oldtimer-0x10000]
650
    pushad
653
    pushad
651
    call    .gettime
654
    call    .gettime
652
    sub    eax, [.starttime-0x10000]
655
    sub    eax, [.starttime-0x10000]
653
    sub    ax, 18*5
656
    sub    ax, 18*5
654
    jae    .timergo
657
    jae    .timergo
655
    neg    ax
658
    neg    ax
656
    add    ax, 18-1
659
    add    ax, 18-1
657
    mov    bx, 18
660
    mov    bx, 18
658
    xor    dx, dx
661
    xor    dx, dx
659
    div    bx
662
    div    bx
660
if lang eq ru
663
if lang eq ru
661
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
664
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
662
    cmp    al, 5
665
    cmp    al, 5
663
    mov    cl, ' '
666
    mov    cl, ' '
664
    jae    @f
667
    jae    @f
665
    cmp    al, 1
668
    cmp    al, 1
666
    mov    cl, 'ã'
669
    mov    cl, 'ã'
667
    jz    @f
670
    jz    @f
668
    mov    cl, 'ë'
671
    mov    cl, 'ë'
669
@@:    mov    [time_str+9-0x10000], cl
672
@@:    mov    [time_str+9-0x10000], cl
670
else
673
else
671
; wait 5/4/3/2 seconds, 1 second
674
; wait 5/4/3/2 seconds, 1 second
672
    cmp    al, 1
675
    cmp    al, 1
673
    mov    cl, 's'
676
    mov    cl, 's'
674
    ja    @f
677
    ja    @f
675
    mov    cl, ' '
678
    mov    cl, ' '
676
@@:    mov    [time_str+9-0x10000], cl
679
@@:    mov    [time_str+9-0x10000], cl
677
end if
680
end if
678
    add    al, '0'
681
    add    al, '0'
679
    mov    [time_str+1-0x10000], al
682
    mov    [time_str+1-0x10000], al
680
    mov    si, time_msg-0x10000
683
    mov    si, time_msg-0x10000
681
    _setcursor 7,0
684
    _setcursor 7,0
682
    call    print
685
    call    print
683
    _setcursor 25,0
686
    _setcursor 25,0
684
    popad
687
    popad
685
    pop    ds
688
    pop    ds
686
    iret
689
    iret
687
.timergo:
690
.timergo:
688
    push    0
691
    push    0
689
    pop    es
692
    pop    es
690
    mov    eax, [.oldtimer-0x10000]
693
    mov    eax, [.oldtimer-0x10000]
691
    mov    [es:8*4], eax
694
    mov    [es:8*4], eax
692
    mov    sp, 0EC00h
695
    mov    sp, 0EC00h
693
.continue:
696
.continue:
694
    sti
697
    sti
695
    _setcursor 6,0
698
    _setcursor 6,0
696
    mov    si, space_msg-0x10000
699
    mov    si, space_msg-0x10000
697
    call    printplain
700
    call    printplain
698
    call    printplain
701
    call    printplain
699
    _setcursor 6,0
702
    _setcursor 6,0
700
    mov    si, loading_msg-0x10000
703
    mov    si, loading_msg-0x10000
701
    call    print
704
    call    print
702
    _setcursor 15,0
705
    _setcursor 15,0
703
    cmp    [.bSettingsChanged-0x10000], 0
706
    cmp    [.bSettingsChanged-0x10000], 0
704
    jz    .load
707
    jz    .load
705
    cmp    [.loader_block-0x10000], 0
708
    cmp    [.loader_block-0x10000], 0
706
    jz    .load
709
    jz    .load
707
    les    bx, [.loader_block-0x10000]
710
    les    bx, [.loader_block-0x10000]
708
    mov    eax, [es:bx+3]
711
    mov    eax, [es:bx+3]
709
    push    ds
712
    push    ds
710
    pop    es
713
    pop    es
711
    test    eax, eax
714
    test    eax, eax
712
    jz    .load
715
    jz    .load
713
    push    eax
716
    push    eax
714
    mov    si, save_quest-0x10000
717
    mov    si, save_quest-0x10000
715
    call    print
718
    call    print
716
.waityn:
719
.waityn:
717
    mov    ah, 0
720
    mov    ah, 0
718
    int    16h
721
    int    16h
719
    or    al, 20h
722
    or    al, 20h
720
    cmp    al, 'n'
723
    cmp    al, 'n'
721
    jz    .loadc
724
    jz    .loadc
722
    cmp    al, 'y'
725
    cmp    al, 'y'
723
    jnz    .waityn
726
    jnz    .waityn
724
    call    putchar
727
    call    putchar
725
    mov    byte [space_msg-0x10000+80], 186
728
    mov    byte [space_msg-0x10000+80], 186
726
    pop    eax
729
    pop    eax
727
    push    cs
730
    push    cs
728
    push    .cont
731
    push    .cont
729
    push    eax
732
    push    eax
730
    retf
733
    retf
731
.loadc:
734
.loadc:
732
    pop    eax
735
    pop    eax
733
.cont:
736
.cont:
734
    push    cs
737
    push    cs
735
    pop    ds
738
    pop    ds
736
    mov    si, space_msg-0x10000
739
    mov    si, space_msg-0x10000
737
    mov    byte [si+80], 0
740
    mov    byte [si+80], 0
738
    _setcursor 15,0
741
    _setcursor 15,0
739
    call    printplain
742
    call    printplain
740
    _setcursor 15,0
743
    _setcursor 15,0
741
.load:
744
.load:
742
; \end{diamond}[02.12.2005]
745
; \end{diamond}[02.12.2005]
743
 
746
 
744
; ASK GRAPHICS MODE
747
; ASK GRAPHICS MODE
745
 
748
 
746
    movzx    ax, [preboot_graph-0x10000]
749
    movzx    ax, [preboot_graph-0x10000]
747
    push    0
750
    push    0
748
    pop    es
751
    pop    es
749
; address is gr_table+6*(ax-1)-0x10000
752
; address is gr_table+6*(ax-1)-0x10000
750
        add    ax, ax
753
        add    ax, ax
751
        lea    si, [gr_table-0x10000 + eax + eax*2 - 6]
754
        lea    si, [gr_table-0x10000 + eax + eax*2 - 6]
752
        mov     bx,[si+0]
755
        mov     bx,[si+0]
753
        mov     cx,[si+2]
756
        mov     cx,[si+2]
754
        mov     dx,[si+4]
757
        mov     dx,[si+4]
755
        cmp    al, 9*2
758
        cmp    al, 9*2
756
        mov    al, 32    ; BPP
759
        mov    al, 32    ; BPP
757
        jb    @f
760
        jb    @f
758
        mov    [es:0x9000], al
761
        mov    [es:0x9000], al
759
        mov    dword [es:0x9018], 0x800000
762
        mov    dword [es:0x9018], 0x800000
760
       @@:
763
       @@:
761
        mov     [es:0x9008],bx
764
        mov     [es:0x9008],bx
762
        mov     [es:0x900A],cx
765
        mov     [es:0x900A],cx
763
        mov     [es:0x900C],dx
766
        mov     [es:0x900C],dx
764
        test    bh, bh
767
        test    bh, bh
765
        jz    nov
768
        jz    nov
766
 
769
 
767
; USE DEFAULTS OR PROBE
770
; USE DEFAULTS OR PROBE
768
 
771
 
769
; bx - mode : cx - x size : dx - y size
772
; bx - mode : cx - x size : dx - y size
770
    cmp    [preboot_gprobe-0x10000], 1
773
    cmp    [preboot_gprobe-0x10000], 1
771
    jz    noprobe
774
    jz    noprobe
772
 
775
 
773
        mov     bx,0x100
776
        mov     bx,0x100
774
     newprobe:
777
     newprobe:
775
        inc     bx
778
        inc     bx
776
        cmp     bx,0x17f
779
        cmp     bx,0x17f
777
        mov    si,prnotfnd-0x10000
780
        mov    si,prnotfnd-0x10000
778
        jz    sayerr
781
        jz    sayerr
779
 
782
 
780
     probemore:
783
     probemore:
781
         push    cx
784
         push    cx
782
        mov     ax,0x4f01
785
        mov     ax,0x4f01
783
        mov     cx,bx
786
        mov     cx,bx
784
        and     cx,0xfff
787
        and     cx,0xfff
785
        mov     di,0xa000
788
        mov     di,0xa000
786
        int     0x10
789
        int     0x10
787
        pop    cx
790
        pop    cx
788
 
791
 
789
    test    byte [es:di], 80h    ; lfb?
792
    test    byte [es:di], 80h    ; lfb?
790
    jz    newprobe
793
    jz    newprobe
791
    cmp    [es:di+0x12], cx    ; x size?
794
    cmp    [es:di+0x12], cx    ; x size?
792
    jnz    newprobe
795
    jnz    newprobe
793
    cmp    [es:di+0x14], dx    ; y size?
796
    cmp    [es:di+0x14], dx    ; y size?
794
    jnz    newprobe
797
    jnz    newprobe
795
    cmp    byte [es:di+0x19], 32 ;24
798
    cmp    byte [es:di+0x19], 32 ;24
796
    jb    newprobe
799
    jb    newprobe
797
 
800
 
798
;       add     bx,0100000000000000b
801
;       add     bx,0100000000000000b
799
    or    bh, 40h
802
    or    bh, 40h
800
        mov     [es:0x9008],bx
803
        mov     [es:0x9008],bx
801
 
804
 
802
     noprobe:
805
     noprobe:
803
 
806
 
804
 
807
 
805
; FIND VESA 2.0 LFB & BPP
808
; FIND VESA 2.0 LFB & BPP
806
 
809
 
807
        mov     ax,0x4f01
810
        mov     ax,0x4f01
808
        mov     cx,bx
811
        mov     cx,bx
809
        and     cx,0xfff
812
        and     cx,0xfff
810
        mov     di,0xa000
813
        mov     di,0xa000
811
        int     0x10
814
        int     0x10
812
        ; LFB
815
        ; LFB
813
        mov     eax,[es:di+0x28]
816
        mov     eax,[es:di+0x28]
814
        mov     [es:0x9018],eax
817
        mov     [es:0x9018],eax
815
        ; ---- vbe voodoo
818
        ; ---- vbe voodoo
816
        BytesPerScanLine equ 0x10
819
        BytesPerScanLine equ 0x10
817
        mov ax, [es:di+BytesPerScanLine]
820
        mov ax, [es:di+BytesPerScanLine]
818
        mov [es:0x9001],ax
821
        mov [es:0x9001],ax
819
        ; BPP
822
        ; BPP
820
        mov     al,byte [es:di+0x19]
823
        mov     al,byte [es:di+0x19]
821
        mov     [es:0x9000],al
824
        mov     [es:0x9000],al
822
       nov:
825
       nov:
823
        cmp     al,24
826
        cmp     al,24
824
        mov    si,bt24-0x10000
827
        mov    si,bt24-0x10000
825
        jz    bppl
828
        jz    bppl
826
        cmp     al,32
829
        cmp     al,32
827
        mov     si,bt32-0x10000
830
        mov     si,bt32-0x10000
828
        jz     bppl
831
        jz     bppl
829
        mov     si,btns-0x10000
832
        mov     si,btns-0x10000
830
        jmp    sayerr
833
        jmp    sayerr
831
       bppl:
834
       bppl:
832
        call    print
835
        call    print
833
 
836
 
834
 
837
 
835
; FIND VESA 1.2 PM BANK SWITCH ADDRESS
838
; FIND VESA 1.2 PM BANK SWITCH ADDRESS
836
 
839
 
837
    push    es
840
    push    es
838
        mov     ax,0x4f0A
841
        mov     ax,0x4f0A
839
        xor    bx, bx
842
        xor    bx, bx
840
        int     0x10
843
        int     0x10
841
        xor     eax,eax
844
        xor     eax,eax
842
        mov     ax,es
845
        mov     ax,es
843
        shl     eax,4
846
        shl     eax,4
844
        movzx   ebx,di
847
        movzx   ebx,di
845
        add     eax,ebx
848
        add     eax,ebx
846
        mov     bx,[es:di]
849
        mov     bx,[es:di]
847
        add     eax,ebx
850
        add     eax,ebx
848
        pop     es
851
        pop     es
849
        mov     [es:0x9014],eax
852
        mov     [es:0x9014],eax
850
 
853
 
851
 
854
 
852
; GRAPHICS ACCELERATION
855
; GRAPHICS ACCELERATION
853
 
856
 
854
        mov     al, [preboot_mtrr-0x10000]
857
        mov     al, [preboot_mtrr-0x10000]
855
        mov     [es:0x901C],al
858
        mov     [es:0x901C],al
856
 
859
 
857
; VRR_M USE
860
; VRR_M USE
858
 
861
 
859
        mov     al,[preboot_vrrm-0x10000]
862
        mov     al,[preboot_vrrm-0x10000]
860
        mov     [es:0x9030],al
863
        mov     [es:0x9030],al
861
 
864
 
862
 
865
 
863
; MEMORY MODEL
866
; MEMORY MODEL
864
 
867
 
865
;        movzx   eax,byte [es:preboot_memory-0x10000]
868
;        movzx   eax,byte [es:preboot_memory-0x10000]
866
;        cmp     eax,0
869
;        cmp     eax,0
867
;        jne     pre_mem
870
;        jne     pre_mem
868
;;;;;;;;;;;;;;;;;;;;;;;;;
871
;;;;;;;;;;;;;;;;;;;;;;;;;
869
; mario79 - memory size ;
872
; mario79 - memory size ;
870
;;;;;;;;;;;;;;;;;;;;;;;;;
873
;;;;;;;;;;;;;;;;;;;;;;;;;
871
;           mov ax,0E801h
874
;           mov ax,0E801h
872
;;;           xor bx,bx    ; thanks to Alexei for bugfix [18.07.2004]
875
;;;           xor bx,bx    ; thanks to Alexei for bugfix [18.07.2004]
873
;           xor cx, cx
876
;           xor cx, cx
874
;           xor dx, dx
877
;           xor dx, dx
875
;           int 0x15
878
;           int 0x15
876
;           movzx ebx, dx ;bx
879
;           movzx ebx, dx ;bx
877
;           movzx eax, cx ;ax
880
;           movzx eax, cx ;ax
878
;           shl   ebx,6   ; ïåðåâîä â êèëîáàéòû (x64)
881
;           shl   ebx,6   ; ïåðåâîä â êèëîáàéòû (x64)
879
;           add   eax,ebx
882
;           add   eax,ebx
880
;           add eax, 1000h ;440h
883
;           add eax, 1000h ;440h
881
;           cmp eax,40000h ; 256?
884
;           cmp eax,40000h ; 256?
882
;           jge mem_256_z
885
;           jge mem_256_z
883
;           cmp eax,20000h ; 128?
886
;           cmp eax,20000h ; 128?
884
;           jge mem_128_z
887
;           jge mem_128_z
885
;           cmp eax,10000h ; 64?
888
;           cmp eax,10000h ; 64?
886
;           jge mem_64_z
889
;           jge mem_64_z
887
;           cmp eax,8000h ; 32?
890
;           cmp eax,8000h ; 32?
888
;           jge mem_32_z
891
;           jge mem_32_z
889
;           jmp mem_16_z
892
;           jmp mem_16_z
890
;
893
;
891
;mem_256_z: mov     si,memokz256-0x10000
894
;mem_256_z: mov     si,memokz256-0x10000
892
;           call    printplain
895
;           call    printplain
893
;           mov eax,5
896
;           mov eax,5
894
;           jmp pre_mem
897
;           jmp pre_mem
895
;mem_128_z: mov     si,memokz128-0x10000
898
;mem_128_z: mov     si,memokz128-0x10000
896
;           call    printplain
899
;           call    printplain
897
;           mov eax,4
900
;           mov eax,4
898
;           jmp pre_mem
901
;           jmp pre_mem
899
;mem_64_z:  mov     si,memokz64-0x10000
902
;mem_64_z:  mov     si,memokz64-0x10000
900
;           call    printplain
903
;           call    printplain
901
;           mov eax,3
904
;           mov eax,3
902
;           jmp pre_mem
905
;           jmp pre_mem
903
;mem_32_z:  mov     si,memokz32-0x10000
906
;mem_32_z:  mov     si,memokz32-0x10000
904
;           call    printplain
907
;           call    printplain
905
;           mov eax,2
908
;           mov eax,2
906
;           jmp pre_mem
909
;           jmp pre_mem
907
;mem_16_z:  mov     si,memokz16-0x10000
910
;mem_16_z:  mov     si,memokz16-0x10000
908
;           call    printplain
911
;           call    printplain
909
;           mov eax,1
912
;           mov eax,1
910
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
913
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
911
;      pre_mem:
914
;      pre_mem:
912
;        push    word 0x0000
915
;        push    word 0x0000
913
;        pop     es
916
;        pop     es
914
;        mov     [es:0x9030],al
917
;        mov     [es:0x9030],al
915
;        push    word 0x1000
918
;        push    word 0x1000
916
;        pop     es
919
;        pop     es
917
;        mov     si,linef-0x10000
920
;        mov     si,linef-0x10000
918
;        call    printplain
921
;        call    printplain
919
 
922
 
920
 
923
 
921
 
924
 
922
 
925
 
923
; DIRECT WRITE TO LFB, PAGING DISABLED
926
; DIRECT WRITE TO LFB, PAGING DISABLED
924
 
927
 
925
;        movzx   eax,byte [es:preboot_lfb-0x10000]
928
;        movzx   eax,byte [es:preboot_lfb-0x10000]
926
;        mov     eax,1                             ; paging disabled
929
;        mov     eax,1                             ; paging disabled
927
;        cmp     eax,0
930
;        cmp     eax,0
928
;        jne     pre_lfb
931
;        jne     pre_lfb
929
;        mov     si,gr_direct-0x10000
932
;        mov     si,gr_direct-0x10000
930
;        call    printplain
933
;        call    printplain
931
;        mov     ebx,'12'
934
;        mov     ebx,'12'
932
;        call    getkey
935
;        call    getkey
933
;      pre_lfb:
936
;      pre_lfb:
934
;        push    word 0x0000
937
;        push    word 0x0000
935
;        pop     es
938
;        pop     es
936
;        mov     [es:0x901E],al
939
;        mov     [es:0x901E],al
937
;        mov     ax,0x1000
940
;        mov     ax,0x1000
938
;        mov     es,ax
941
;        mov     es,ax
939
;        mov     si,linef-0x10000
942
;        mov     si,linef-0x10000
940
;        call    printplain
943
;        call    printplain
941
        mov     [es:0x901E],byte 1
944
        mov     [es:0x901E],byte 1
942
 
945
 
943
 
946
 
944
 
947
 
945
; BOOT DEVICE
948
; BOOT DEVICE
946
 
949
 
947
    mov    al, [preboot_device-0x10000]
950
    mov    al, [preboot_device-0x10000]
948
        dec     al
951
        dec     al
949
        mov     [boot_dev-0x10000],al
952
        mov     [boot_dev-0x10000],al
950
 
953
 
951
; READ DISKETTE TO MEMORY
954
; READ DISKETTE TO MEMORY
952
 
955
 
953
;        cmp     [boot_dev-0x10000],0
956
;        cmp     [boot_dev-0x10000],0
954
        jne     no_sys_on_floppy
957
        jne     no_sys_on_floppy
955
        mov     si,diskload-0x10000
958
        mov     si,diskload-0x10000
956
        call    print
959
        call    print
957
        xor    ax, ax            ; reset drive
960
        xor    ax, ax            ; reset drive
958
        xor    dx, dx
961
        xor    dx, dx
959
        int     0x13
962
        int     0x13
960
        mov     cx,0x0001               ; startcyl,startsector
963
        mov     cx,0x0001               ; startcyl,startsector
961
        xor    dx, dx            ; starthead,drive
964
        xor    dx, dx            ; starthead,drive
962
        push    word 80*2               ; read no of sect
965
        push    word 80*2               ; read no of sect
963
       reads:
966
       reads:
964
        pusha
967
        pusha
965
        xor     si,si
968
        xor     si,si
966
       newread:
969
       newread:
967
        mov     bx,0xa000               ; es:bx -> data area
970
        mov     bx,0xa000               ; es:bx -> data area
968
        mov     ax,0x0200+18            ; read, no of sectors to read
971
        mov     ax,0x0200+18            ; read, no of sectors to read
969
        int     0x13
972
        int     0x13
970
        test    ah, ah
973
        test    ah, ah
971
        jz      goodread
974
        jz      goodread
972
        inc    si
975
        inc    si
973
        cmp     si,10
976
        cmp     si,10
974
        jnz     newread
977
        jnz     newread
975
        mov     si,badsect-0x10000
978
        mov     si,badsect-0x10000
976
sayerr_plain:
979
sayerr_plain:
977
        call    printplain
980
        call    printplain
978
        jmp     $
981
        jmp     $
979
       goodread:
982
       goodread:
980
        ; move -> 1mb
983
        ; move -> 1mb
981
        mov     si,movedesc-0x10000
984
        mov     si,movedesc-0x10000
982
        push    es
985
        push    es
983
        push    ds
986
        push    ds
984
        pop     es
987
        pop     es
985
        mov     cx,256*18
988
        mov     cx,256*18
986
        mov     ah,0x87
989
        mov     ah,0x87
987
        int     0x15
990
        int     0x15
988
        pop    es
991
        pop    es
989
 
992
 
990
        test    ah,ah                  ; was the move successfull ?
993
        test    ah,ah                  ; was the move successfull ?
991
        je      goodmove
994
        je      goodmove
992
        mov     dx,0x3f2              ; floppy motor off
995
        mov     dx,0x3f2              ; floppy motor off
993
        mov     al,0
996
        mov     al,0
994
        out     dx,al
997
        out     dx,al
995
        mov     si,memmovefailed-0x10000
998
        mov     si,memmovefailed-0x10000
996
        jmp    sayerr_plain
999
        jmp    sayerr_plain
997
      goodmove:
1000
      goodmove:
998
 
1001
 
999
    add    dword [movedesc-0x10000+0x18+2], 512*18
1002
    add    dword [movedesc-0x10000+0x18+2], 512*18
1000
        popa
1003
        popa
1001
        inc     dh
1004
        inc     dh
1002
        cmp     dh,2
1005
        cmp     dh,2
1003
        jnz     bb2
1006
        jnz     bb2
1004
        mov     dh,0
1007
        mov     dh,0
1005
        inc     ch
1008
        inc     ch
1006
        pusha                        ; print prosentage
1009
        pusha                        ; print prosentage
1007
        mov     si,pros-0x10000
1010
        mov     si,pros-0x10000
1008
    shr    ch, 2
1011
    shr    ch, 2
1009
    mov    al, '5'
1012
    mov    al, '5'
1010
    test    ch, 1
1013
    test    ch, 1
1011
    jnz    @f
1014
    jnz    @f
1012
    mov    al, '0'
1015
    mov    al, '0'
1013
@@:
1016
@@:
1014
    mov    [si+1], al
1017
    mov    [si+1], al
1015
    shr    ch, 1
1018
    shr    ch, 1
1016
    add    ch, '0'
1019
    add    ch, '0'
1017
    mov    [si], ch
1020
    mov    [si], ch
1018
        call    printplain
1021
        call    printplain
1019
        popa
1022
        popa
1020
       bb2:
1023
       bb2:
1021
        pop     ax
1024
        pop     ax
1022
        dec     ax
1025
        dec     ax
1023
        push    ax
1026
        push    ax
1024
        jnz     reads
1027
        jnz     reads
1025
       readdone:
1028
       readdone:
1026
        pop     ax
1029
        pop     ax
1027
        mov     si,backspace2-0x10000
1030
        mov     si,backspace2-0x10000
1028
        call    printplain
1031
        call    printplain
1029
        mov     si,okt-0x10000
1032
        mov     si,okt-0x10000
1030
        call    printplain
1033
        call    printplain
1031
       no_sys_on_floppy:
1034
       no_sys_on_floppy:
1032
        xor    ax, ax        ; reset drive
1035
        xor    ax, ax        ; reset drive
1033
        xor    dx, dx
1036
        xor    dx, dx
1034
        int     0x13
1037
        int     0x13
1035
       mov dx,0x3f2 ; floppy motor off
1038
       mov dx,0x3f2 ; floppy motor off
1036
       mov al,0
1039
       mov al,0
1037
       out dx,al
1040
       out dx,al
1038
 
1041
 
1039
    push    es
1042
    push    es
1040
; PAGE TABLE
1043
; PAGE TABLE
1041
 
1044
 
1042
    push    dword [es:0x9018]
1045
    push    dword [es:0x9018]
1043
 
1046
 
1044
        map_mem equ 64                ; amount of memory to map
1047
        map_mem equ 64                ; amount of memory to map
1045
 
1048
 
1046
        push    0x6000
1049
        push    0x6000
1047
        pop    es                    ; es:di = 6000:0
1050
        pop    es                    ; es:di = 6000:0
1048
        xor     di,di
1051
        xor     di,di
1049
        mov     cx,256*map_mem         ; Map (mapmem) M
1052
        mov     cx,256*map_mem         ; Map (mapmem) M
1050
;        mov     eax,7
-
 
1051
;       pt2:
-
 
1052
;        cmp     cx,256*(map_mem-8)     ; 8 M map to LFB
-
 
1053
;        jnz     pt3
-
 
1054
;        pop     eax
-
 
1055
;        add     eax,7
-
 
1056
;       pt3:
-
 
1057
;        cmp     cx,256*(map_mem-12)    ; 12 M back to linear = physical
-
 
1058
;        jnz     pt4
-
 
1059
;        mov     eax,12*0x100000 + 7
-
 
1060
;       pt4:
-
 
1061
;        stosd
-
 
1062
;        add     eax,4096
-
 
1063
;        loop    pt2
-
 
1064
; initialize as identity mapping
1053
; initialize as identity mapping
1065
    xor    eax, eax
1054
    xor    eax, eax
1066
    call    pagetable_set
1055
    call    pagetable_set
1067
; 8M..12M map to LFB
-
 
1068
    pop    eax
-
 
1069
;    mov    cx, 256*4
-
 
1070
    mov    ch, 4
-
 
1071
    mov    di, 2000h
-
 
1072
    call    pagetable_set
-
 
1073
 
-
 
1074
    push    0x7100
-
 
1075
    pop    es
-
 
1076
        xor     di,di
-
 
1077
        mov     eax,8*0x100000
-
 
1078
        mov     cx,256*4
-
 
1079
        call    pagetable_set
1056
 
1080
        
1057
        
1081
; 4 KB PAGE DIRECTORY
1058
; 4 KB PAGE DIRECTORY
1082
 
1059
 
1083
    push    0x7F00
1060
    push    0x7F00
1084
    pop    es                ; es:di = 7F00:0
1061
    pop    es                ; es:di = 7F00:0
1085
        xor     di, di
1062
        xor     di, di
1086
        mov     cx, 64 / 4
1063
        mov     cx, 64 / 4
1087
        mov     eax, 0x60007            ; for 0 M
1064
        mov     eax, 0x60007            ; for 0 M
1088
        call    pagetable_set
1065
        call    pagetable_set
1089
        mov     dword [es:0x800],0x71007   ;map region 0x80000000-0x803FFFFF to 0x800000-0xCFFFFF
-
 
1090
        xor     si,si
1066
        xor     si,si
1091
        mov     di,second_base_address shr 20
1067
        mov     di,second_base_address shr 20
1092
        mov     cx,64/2
1068
        mov     cx,64/2
1093
        rep     movs word [es:di], [es:si]
1069
        rep     movs word [es:di], [es:si]
1094
       
1070
       
1095
        mov     eax, 0x7F000 +8+16      ; Page directory and enable caches
1071
        mov     eax, 0x7F000 +8+16      ; Page directory and enable caches
1096
        mov     cr3, eax
1072
        mov     cr3, eax
1097
 
1073
 
1098
; SET GRAPHICS
1074
; SET GRAPHICS
1099
 
1075
 
1100
    pop    es
1076
    pop    es
1101
        mov     ax,[es:0x9008]        ; vga & 320x200
1077
        mov     ax,[es:0x9008]        ; vga & 320x200
1102
        mov    bx, ax
1078
        mov    bx, ax
1103
        cmp     ax,0x13
1079
        cmp     ax,0x13
1104
        je      setgr
1080
        je      setgr
1105
        cmp     ax,0x12
1081
        cmp     ax,0x12
1106
        je      setgr
1082
        je      setgr
1107
        mov     ax,0x4f02            ; Vesa
1083
        mov     ax,0x4f02            ; Vesa
1108
       setgr:
1084
       setgr:
1109
        int     0x10
1085
        int     0x10
1110
        test    ah,ah
1086
        test    ah,ah
1111
        mov    si, fatalsel-0x10000
1087
        mov    si, fatalsel-0x10000
1112
        jnz    sayerr
1088
        jnz    sayerr
1113
; set mode 0x12 graphics registers:
1089
; set mode 0x12 graphics registers:
1114
        cmp     bx,0x12
1090
        cmp     bx,0x12
1115
        jne     gmok2
1091
        jne     gmok2
1116
 
1092
 
1117
        mov     al,0x05
1093
        mov     al,0x05
1118
        mov     dx,0x03ce
1094
        mov     dx,0x03ce
1119
        push    dx
1095
        push    dx
1120
        out     dx,al      ; select GDC mode register
1096
        out     dx,al      ; select GDC mode register
1121
        mov     al,0x02
1097
        mov     al,0x02
1122
        inc    dx
1098
        inc    dx
1123
        out     dx,al      ; set write mode 2
1099
        out     dx,al      ; set write mode 2
1124
 
1100
 
1125
        mov     al,0x02
1101
        mov     al,0x02
1126
        mov     dx,0x03c4
1102
        mov     dx,0x03c4
1127
        out     dx,al      ; select VGA sequencer map mask register
1103
        out     dx,al      ; select VGA sequencer map mask register
1128
        mov     al,0x0f
1104
        mov     al,0x0f
1129
        inc    dx
1105
        inc    dx
1130
        out     dx,al      ; set mask for all planes 0-3
1106
        out     dx,al      ; set mask for all planes 0-3
1131
 
1107
 
1132
        mov     al,0x08
1108
        mov     al,0x08
1133
        pop    dx
1109
        pop    dx
1134
        out     dx,al      ; select GDC bit mask register
1110
        out     dx,al      ; select GDC bit mask register
1135
                           ; for writes to 0x03cf
1111
                           ; for writes to 0x03cf
1136
 
1112
 
1137
       gmok2:
1113
       gmok2:
1138
        push    ds
1114
        push    ds
1139
        pop    es
1115
        pop    es