Subversion Repositories Kolibri OS

Rev

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

Rev 5645 Rev 5984
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
2
;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved.
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved.
4
;; PROGRAMMING:
4
;; PROGRAMMING:
5
;; Ivan Poddubny
5
;; Ivan Poddubny
6
;; Marat Zakiyanov (Mario79)
6
;; Marat Zakiyanov (Mario79)
7
;; VaStaNi
7
;; VaStaNi
8
;; Trans
8
;; Trans
9
;; Mihail Semenyako (mike.dld)
9
;; Mihail Semenyako (mike.dld)
10
;; Sergey Kuzmin (Wildwest)
10
;; Sergey Kuzmin (Wildwest)
11
;; Andrey Halyavin (halyavin)
11
;; Andrey Halyavin (halyavin)
12
;; Mihail Lisovin (Mihasik)
12
;; Mihail Lisovin (Mihasik)
13
;; Andrey Ignatiev (andrew_programmer)
13
;; Andrey Ignatiev (andrew_programmer)
14
;; NoName
14
;; NoName
15
;; Evgeny Grechnikov (Diamond)
15
;; Evgeny Grechnikov (Diamond)
16
;; Iliya Mihailov (Ghost)
16
;; Iliya Mihailov (Ghost)
17
;; Sergey Semyonov (Serge)
17
;; Sergey Semyonov (Serge)
18
;; Johnny_B
18
;; Johnny_B
19
;; SPraid (simba)
19
;; SPraid (simba)
20
;; Hidnplayr
20
;; Hidnplayr
21
;; Alexey Teplov ()
21
;; Alexey Teplov ()
22
;; Rus
22
;; Rus
23
;; Nable
23
;; Nable
24
;; shurf
24
;; shurf
25
;; Alver
25
;; Alver
26
;; Maxis
26
;; Maxis
27
;; Galkov
27
;; Galkov
28
;; CleverMouse
28
;; CleverMouse
29
;; tsdima
29
;; tsdima
30
;; turbanoff
30
;; turbanoff
31
;; Asper
31
;; Asper
32
;; art_zh
32
;; art_zh
33
;;
33
;;
34
;; Data in this file was originally part of MenuetOS project which is
34
;; Data in this file was originally part of MenuetOS project which is
35
;; distributed under the terms of GNU GPL. It is modified and redistributed as
35
;; distributed under the terms of GNU GPL. It is modified and redistributed as
36
;; part of KolibriOS project under the terms of GNU GPL.
36
;; part of KolibriOS project under the terms of GNU GPL.
37
;;
37
;;
38
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
38
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
39
;; PROGRAMMING:
39
;; PROGRAMMING:
40
;;
40
;;
41
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
41
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
42
;; - main os coding/design
42
;; - main os coding/design
43
;; Jan-Michael Brummer, BUZZ2@gmx.de
43
;; Jan-Michael Brummer, BUZZ2@gmx.de
44
;; Felix Kaiser, info@felix-kaiser.de
44
;; Felix Kaiser, info@felix-kaiser.de
45
;; Paolo Minazzi, paolo.minazzi@inwind.it
45
;; Paolo Minazzi, paolo.minazzi@inwind.it
46
;; quickcode@mail.ru
46
;; quickcode@mail.ru
47
;; Alexey, kgaz@crosswinds.net
47
;; Alexey, kgaz@crosswinds.net
48
;; Juan M. Caravaca, bitrider@wanadoo.es
48
;; Juan M. Caravaca, bitrider@wanadoo.es
49
;; kristol@nic.fi
49
;; kristol@nic.fi
50
;; Mike Hibbett, mikeh@oceanfree.net
50
;; Mike Hibbett, mikeh@oceanfree.net
51
;; Lasse Kuusijarvi, kuusijar@lut.fi
51
;; Lasse Kuusijarvi, kuusijar@lut.fi
52
;; Jarek Pelczar, jarekp3@wp.pl
52
;; Jarek Pelczar, jarekp3@wp.pl
53
;;
53
;;
54
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
54
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
55
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
55
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
56
;; consequences of using it or for whether it serves any particular purpose or
56
;; consequences of using it or for whether it serves any particular purpose or
57
;; works at all, unless he says so in writing. Refer to the GNU General Public
57
;; works at all, unless he says so in writing. Refer to the GNU General Public
58
;; License (the "GPL") for full details.
58
;; License (the "GPL") for full details.
59
;
59
;
60
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
60
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
61
;; but only under the conditions described in the GPL. A copy of this license
61
;; but only under the conditions described in the GPL. A copy of this license
62
;; is supposed to have been given to you along with KolibriOS so you can know
62
;; is supposed to have been given to you along with KolibriOS so you can know
63
;; your rights and responsibilities. It should be in a file named COPYING.
63
;; your rights and responsibilities. It should be in a file named COPYING.
64
;; Among other things, the copyright notice and this notice must be preserved
64
;; Among other things, the copyright notice and this notice must be preserved
65
;; on all copies.
65
;; on all copies.
66
;;
66
;;
67
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68
 
68
 
69
format binary as "mnt"
69
format binary as "mnt"
70
 
70
 
71
include 'macros.inc'
71
include 'macros.inc'
72
include 'struct.inc'
72
include 'struct.inc'
73
 
73
 
74
$Revision: 5645 $
74
$Revision: 5984 $
75
 
75
 
76
 
76
 
77
USE_COM_IRQ     equ 1      ; make irq 3 and irq 4 available for PCI devices
77
USE_COM_IRQ     equ 1      ; make irq 3 and irq 4 available for PCI devices
78
VESA_1_2_VIDEO  equ 0      ; enable vesa 1.2 bank switch functions
78
VESA_1_2_VIDEO  equ 0      ; enable vesa 1.2 bank switch functions
79
 
79
 
80
; Enabling the next line will enable serial output console
80
; Enabling the next line will enable serial output console
81
;debug_com_base  equ 0x3f8  ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used
81
;debug_com_base  equ 0x3f8  ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used
82
 
82
 
83
include "proc32.inc"
83
include "proc32.inc"
84
include "kglobals.inc"
84
include "kglobals.inc"
85
include "lang.inc"
85
include "lang.inc"
86
include "encoding.inc"
86
include "encoding.inc"
87
 
87
 
88
include "const.inc"
88
include "const.inc"
89
 
89
 
90
iglobal
90
iglobal
91
; The following variable, if equal to 1, duplicates debug output to the screen.
91
; The following variable, if equal to 1, duplicates debug output to the screen.
92
debug_direct_print db 0
92
debug_direct_print db 0
93
; Start the first app (LAUNCHER) after kernel is loaded? (1=yes, 2 or 0=no)
93
; Start the first app (LAUNCHER) after kernel is loaded? (1=yes, 2 or 0=no)
94
launcher_start db 1
94
launcher_start db 1
95
endg
95
endg
96
 
96
 
97
max_processes    equ   255
97
max_processes    equ   255
98
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
98
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
99
 
99
 
100
os_stack       equ  (os_data_l-gdts)    ; GDTs
100
os_stack       equ  (os_data_l-gdts)    ; GDTs
101
os_code        equ  (os_code_l-gdts)
101
os_code        equ  (os_code_l-gdts)
102
graph_data     equ  (3+graph_data_l-gdts)
102
graph_data     equ  (3+graph_data_l-gdts)
103
tss0           equ  (tss0_l-gdts)
103
tss0           equ  (tss0_l-gdts)
104
app_code       equ  (3+app_code_l-gdts)
104
app_code       equ  (3+app_code_l-gdts)
105
app_data       equ  (3+app_data_l-gdts)
105
app_data       equ  (3+app_data_l-gdts)
106
app_tls        equ  (3+tls_data_l-gdts)
106
app_tls        equ  (3+tls_data_l-gdts)
107
pci_code_sel   equ  (pci_code_32-gdts)
107
pci_code_sel   equ  (pci_code_32-gdts)
108
pci_data_sel   equ  (pci_data_32-gdts)
108
pci_data_sel   equ  (pci_data_32-gdts)
109
 
109
 
110
 
110
 
111
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112
;;
112
;;
113
;;   Included files:
113
;;   Included files:
114
;;
114
;;
115
;;   Kernel16.inc
115
;;   Kernel16.inc
116
;;    - Booteng.inc   English text for bootup
116
;;    - Booteng.inc   English text for bootup
117
;;    - Bootcode.inc  Hardware setup
117
;;    - Bootcode.inc  Hardware setup
118
;;    - Pci16.inc     PCI functions
118
;;    - Pci16.inc     PCI functions
119
;;
119
;;
120
;;   Kernel32.inc
120
;;   Kernel32.inc
121
;;    - Sys32.inc     Process management
121
;;    - Sys32.inc     Process management
122
;;    - Shutdown.inc  Shutdown and restart
122
;;    - Shutdown.inc  Shutdown and restart
123
;;    - Fat32.inc     Read / write hd
123
;;    - Fat32.inc     Read / write hd
124
;;    - Vesa12.inc    Vesa 1.2 driver
124
;;    - Vesa12.inc    Vesa 1.2 driver
125
;;    - Vesa20.inc    Vesa 2.0 driver
125
;;    - Vesa20.inc    Vesa 2.0 driver
126
;;    - Vga.inc       VGA driver
126
;;    - Vga.inc       VGA driver
127
;;    - Stack.inc     Network interface
127
;;    - Stack.inc     Network interface
128
;;    - Mouse.inc     Mouse pointer
128
;;    - Mouse.inc     Mouse pointer
129
;;    - Scincode.inc  Window skinning
129
;;    - Scincode.inc  Window skinning
130
;;    - Pci32.inc     PCI functions
130
;;    - Pci32.inc     PCI functions
131
;;
131
;;
132
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
132
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
133
 
133
 
134
 
134
 
135
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
135
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136
;;                                                                      ;;
136
;;                                                                      ;;
137
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
137
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
138
;;                                                                      ;;
138
;;                                                                      ;;
139
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
139
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
140
 
140
 
141
use16
141
use16
142
                  org   0x0
142
                  org   0x0
143
        jmp     start_of_code
143
        jmp     start_of_code
144
 
144
 
145
if lang eq sp
145
if lang eq sp
146
include "kernelsp.inc"  ; spanish kernel messages
146
include "kernelsp.inc"  ; spanish kernel messages
147
else if lang eq et
147
else if lang eq et
148
version db    'Kolibri OS  versioon 0.7.7.0+    ',13,10,13,10,0
148
version db    'Kolibri OS  versioon 0.7.7.0+    ',13,10,13,10,0
149
else
149
else
150
version db    'Kolibri OS  version 0.7.7.0+     ',13,10,13,10,0
150
version db    'Kolibri OS  version 0.7.7.0+     ',13,10,13,10,0
151
end if
151
end if
152
 
152
 
153
include "boot/bootstr.inc"     ; language-independent boot messages
153
include "boot/bootstr.inc"     ; language-independent boot messages
154
include "boot/preboot.inc"
154
include "boot/preboot.inc"
155
 
155
 
156
if lang eq ge
156
if lang eq ge
157
include "boot/bootge.inc"     ; german system boot messages
157
include "boot/bootge.inc"     ; german system boot messages
158
else if lang eq sp
158
else if lang eq sp
159
include "boot/bootsp.inc"     ; spanish system boot messages
159
include "boot/bootsp.inc"     ; spanish system boot messages
160
else if lang eq ru
160
else if lang eq ru
161
include "boot/bootru.inc"      ; russian system boot messages
161
include "boot/bootru.inc"      ; russian system boot messages
162
include "boot/ru.inc"          ; Russian font
162
include "boot/ru.inc"          ; Russian font
163
else if lang eq et
163
else if lang eq et
164
include "boot/bootet.inc"      ; estonian system boot messages
164
include "boot/bootet.inc"      ; estonian system boot messages
165
include "boot/et.inc"          ; Estonian font
165
include "boot/et.inc"          ; Estonian font
166
else
166
else
167
include "boot/booten.inc"      ; english system boot messages
167
include "boot/booten.inc"      ; english system boot messages
168
end if
168
end if
169
 
169
 
170
include "boot/bootcode.inc"    ; 16 bit system boot code
170
include "boot/bootcode.inc"    ; 16 bit system boot code
171
include "bus/pci/pci16.inc"
171
include "bus/pci/pci16.inc"
172
include "detect/biosdisk.inc"
172
include "detect/biosdisk.inc"
173
 
173
 
174
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
174
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
175
;;                                                                      ;;
175
;;                                                                      ;;
176
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
176
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
177
;;                                                                      ;;
177
;;                                                                      ;;
178
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
179
 
179
 
180
 
180
 
181
; CR0 Flags - Protected mode and Paging
181
; CR0 Flags - Protected mode and Paging
182
 
182
 
183
        mov     ecx, CR0_PE
183
        mov     ecx, CR0_PE
184
 
184
 
185
; Enabling 32 bit protected mode
185
; Enabling 32 bit protected mode
186
 
186
 
187
        sidt    [cs:old_ints_h]
187
        sidt    [cs:old_ints_h]
188
 
188
 
189
        cli                             ; disable all irqs
189
        cli                             ; disable all irqs
190
        cld
190
        cld
191
        mov     al, 255                 ; mask all irqs
191
        mov     al, 255                 ; mask all irqs
192
        out     0xa1, al
192
        out     0xa1, al
193
        out     0x21, al
193
        out     0x21, al
194
   l.5:
194
   l.5:
195
        in      al, 0x64                ; Enable A20
195
        in      al, 0x64                ; Enable A20
196
        test    al, 2
196
        test    al, 2
197
        jnz     l.5
197
        jnz     l.5
198
        mov     al, 0xD1
198
        mov     al, 0xD1
199
        out     0x64, al
199
        out     0x64, al
200
   l.6:
200
   l.6:
201
        in      al, 0x64
201
        in      al, 0x64
202
        test    al, 2
202
        test    al, 2
203
        jnz     l.6
203
        jnz     l.6
204
        mov     al, 0xDF
204
        mov     al, 0xDF
205
        out     0x60, al
205
        out     0x60, al
206
   l.7:
206
   l.7:
207
        in      al, 0x64
207
        in      al, 0x64
208
        test    al, 2
208
        test    al, 2
209
        jnz     l.7
209
        jnz     l.7
210
        mov     al, 0xFF
210
        mov     al, 0xFF
211
        out     0x64, al
211
        out     0x64, al
212
 
212
 
213
        lgdt    [cs:tmp_gdt]            ; Load GDT
213
        lgdt    [cs:tmp_gdt]            ; Load GDT
214
        mov     eax, cr0                ; protected mode
214
        mov     eax, cr0                ; protected mode
215
        or      eax, ecx
215
        or      eax, ecx
216
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
216
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
217
        mov     cr0, eax
217
        mov     cr0, eax
218
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
218
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
219
 
219
 
220
align 8
220
align 8
221
tmp_gdt:
221
tmp_gdt:
222
 
222
 
223
        dw     23
223
        dw     23
224
        dd     tmp_gdt+0x10000
224
        dd     tmp_gdt+0x10000
225
        dw     0
225
        dw     0
226
 
226
 
227
        dw     0xffff
227
        dw     0xffff
228
        dw     0x0000
228
        dw     0x0000
229
        db     0x00
229
        db     0x00
230
        dw     11011111b *256 +10011010b
230
        dw     11011111b *256 +10011010b
231
        db     0x00
231
        db     0x00
232
 
232
 
233
        dw     0xffff
233
        dw     0xffff
234
        dw     0x0000
234
        dw     0x0000
235
        db     0x00
235
        db     0x00
236
        dw     11011111b *256 +10010010b
236
        dw     11011111b *256 +10010010b
237
        db     0x00
237
        db     0x00
238
 
238
 
239
include "data16.inc"
239
include "data16.inc"
240
 
240
 
241
if ~ lang eq sp
241
if ~ lang eq sp
242
diff16 "end of bootcode",0,$+0x10000
242
diff16 "end of bootcode",0,$+0x10000
243
end if
243
end if
244
 
244
 
245
use32
245
use32
246
org $+0x10000
246
org $+0x10000
247
 
247
 
248
align 4
248
align 4
249
B32:
249
B32:
250
        mov     ax, os_stack       ; Selector for os
250
        mov     ax, os_stack       ; Selector for os
251
        mov     ds, ax
251
        mov     ds, ax
252
        mov     es, ax
252
        mov     es, ax
253
        mov     fs, ax
253
        mov     fs, ax
254
        mov     gs, ax
254
        mov     gs, ax
255
        mov     ss, ax
255
        mov     ss, ax
256
        mov     esp, 0x006CC00       ; Set stack
256
        mov     esp, 0x006CC00       ; Set stack
257
 
257
 
258
; CLEAR 0x280000 - HEAP_BASE
258
; CLEAR 0x280000 - HEAP_BASE
259
 
259
 
260
        xor     eax, eax
260
        xor     eax, eax
261
        mov     edi, CLEAN_ZONE
261
        mov     edi, CLEAN_ZONE
262
        mov     ecx, (HEAP_BASE-OS_BASE-CLEAN_ZONE) / 4
262
        mov     ecx, (HEAP_BASE-OS_BASE-CLEAN_ZONE) / 4
263
        cld
263
        cld
264
        rep stosd
264
        rep stosd
265
 
265
 
266
; CLEAR KERNEL UNDEFINED GLOBALS
266
; CLEAR KERNEL UNDEFINED GLOBALS
267
        mov     edi, endofcode-OS_BASE
267
        mov     edi, endofcode-OS_BASE
268
        mov     ecx, 0x90000
268
        mov     ecx, 0x90000
269
        sub     ecx, edi
269
        sub     ecx, edi
270
        shr     ecx, 2
270
        shr     ecx, 2
271
        rep stosd
271
        rep stosd
272
 
272
 
273
; SAVE & CLEAR 0-0xffff
273
; SAVE & CLEAR 0-0xffff
274
 
274
 
275
        mov     edi, 0x1000
275
        mov     edi, 0x1000
276
        mov     ecx, 0x8000 / 4
276
        mov     ecx, 0x8000 / 4
277
        rep stosd
277
        rep stosd
278
        mov     edi, 0xa000
278
        mov     edi, 0xa000
279
        mov     ecx, 0x6000 / 4
279
        mov     ecx, 0x6000 / 4
280
        rep stosd
280
        rep stosd
281
 
281
 
282
        call    test_cpu
282
        call    test_cpu
283
        bts     [cpu_caps-OS_BASE], CAPS_TSC    ;force use rdtsc
283
        bts     [cpu_caps-OS_BASE], CAPS_TSC    ;force use rdtsc
284
 
284
 
285
        call    check_acpi
285
        call    check_acpi
286
        call    init_hpet
286
        call    init_hpet
287
        call    init_BIOS32
287
        call    init_BIOS32
288
; MEMORY MODEL
288
; MEMORY MODEL
289
        call    mem_test
289
        call    mem_test
290
        call    init_mem
290
        call    init_mem
291
        call    init_page_map
291
        call    init_page_map
292
 
292
 
293
; ENABLE PAGING
293
; ENABLE PAGING
294
 
294
 
295
        mov     eax, sys_proc-OS_BASE+PROC.pdt_0
295
        mov     eax, sys_proc-OS_BASE+PROC.pdt_0
296
        mov     cr3, eax
296
        mov     cr3, eax
297
 
297
 
298
        mov     eax, cr0
298
        mov     eax, cr0
299
        or      eax, CR0_PG+CR0_WP
299
        or      eax, CR0_PG+CR0_WP
300
        mov     cr0, eax
300
        mov     cr0, eax
301
 
301
 
302
        lgdt    [gdts]
302
        lgdt    [gdts]
303
        jmp     pword os_code:high_code
303
        jmp     pword os_code:high_code
304
 
304
 
305
align 4
305
align 4
306
bios32_entry    dd ?
306
bios32_entry    dd ?
307
tmp_page_tabs   dd ?
307
tmp_page_tabs   dd ?
308
 
308
 
309
use16
309
use16
310
org $-0x10000
310
org $-0x10000
311
include "boot/shutdown.inc" ; shutdown or restart
311
include "boot/shutdown.inc" ; shutdown or restart
312
org $+0x10000
312
org $+0x10000
313
 
313
 
314
ap_init16:
314
ap_init16:
315
        cli
315
        cli
316
        lgdt    [cs:gdts_ap-ap_init16]
316
        lgdt    [cs:gdts_ap-ap_init16]
317
        mov     eax, [cs:cr3_ap-ap_init16]
317
        mov     eax, [cs:cr3_ap-ap_init16]
318
        mov     cr3, eax
318
        mov     cr3, eax
319
        mov     eax, [cs:cr4_ap-ap_init16]
319
        mov     eax, [cs:cr4_ap-ap_init16]
320
        mov     cr4, eax
320
        mov     cr4, eax
321
        mov     eax, CR0_PE+CR0_PG+CR0_WP
321
        mov     eax, CR0_PE+CR0_PG+CR0_WP
322
        mov     cr0, eax
322
        mov     cr0, eax
323
        jmp     pword os_code:ap_init_high
323
        jmp     pword os_code:ap_init_high
324
align 16
324
align 16
325
gdts_ap:
325
gdts_ap:
326
        dw     gdte-gdts-1
326
        dw     gdte-gdts-1
327
        dd     gdts
327
        dd     gdts
328
        dw     0
328
        dw     0
329
cr3_ap  dd     ?
329
cr3_ap  dd     ?
330
cr4_ap  dd     ?
330
cr4_ap  dd     ?
331
ap_init16_size = $ - ap_init16
331
ap_init16_size = $ - ap_init16
332
use32
332
use32
333
 
333
 
334
__DEBUG__ fix 1
334
__DEBUG__ fix 1
335
__DEBUG_LEVEL__ fix 1
335
__DEBUG_LEVEL__ fix 1
336
include 'init.inc'
336
include 'init.inc'
337
 
337
 
338
org OS_BASE+$
338
org OS_BASE+$
339
 
339
 
340
include 'fdo.inc'
340
include 'fdo.inc'
341
 
341
 
342
align 4
342
align 4
343
high_code:
343
high_code:
344
        mov     ax, os_stack
344
        mov     ax, os_stack
345
        mov     bx, app_data
345
        mov     bx, app_data
346
        mov     cx, app_tls
346
        mov     cx, app_tls
347
        mov     ss, ax
347
        mov     ss, ax
348
        add     esp, OS_BASE
348
        add     esp, OS_BASE
349
 
349
 
350
        mov     ds, bx
350
        mov     ds, bx
351
        mov     es, bx
351
        mov     es, bx
352
        mov     fs, cx
352
        mov     fs, cx
353
        mov     gs, bx
353
        mov     gs, bx
354
 
354
 
355
        xor     eax, eax
355
        xor     eax, eax
356
        mov     ebx, 0xFFFFF000+PG_SHARED+PG_NOCACHE+PG_UWR
356
        mov     ebx, 0xFFFFF000+PG_SHARED+PG_NOCACHE+PG_UWR
357
        bt      [cpu_caps], CAPS_PAT
357
        bt      [cpu_caps], CAPS_PAT
358
        setc    al
358
        setc    al
359
        shl     eax, 7
359
        shl     eax, 7
360
        or      ebx, eax
360
        or      ebx, eax
361
 
361
 
362
        mov     eax, PG_GLOBAL
362
        mov     eax, PG_GLOBAL
363
        bt      [cpu_caps], CAPS_PGE
363
        bt      [cpu_caps], CAPS_PGE
364
        jnc     @F
364
        jnc     @F
365
 
365
 
366
        or      [sys_proc+PROC.pdt_0+(OS_BASE shr 20)], eax
366
        or      [sys_proc+PROC.pdt_0+(OS_BASE shr 20)], eax
367
        or      ebx, eax
367
        or      ebx, eax
368
 
368
 
369
        mov     eax, cr4
369
        mov     eax, cr4
370
        or      eax, CR4_PGE
370
        or      eax, CR4_PGE
371
        mov     cr4, eax
371
        mov     cr4, eax
372
@@:
372
@@:
373
        mov     [pte_valid_mask], ebx
373
        mov     [pte_valid_mask], ebx
374
 
374
 
375
        xor     eax, eax
375
        xor     eax, eax
376
        mov     dword [sys_proc+PROC.pdt_0], eax
376
        mov     dword [sys_proc+PROC.pdt_0], eax
377
        mov     dword [sys_proc+PROC.pdt_0+4], eax
377
        mov     dword [sys_proc+PROC.pdt_0+4], eax
378
 
378
 
379
        mov     eax, cr3
379
        mov     eax, cr3
380
        mov     cr3, eax          ; flush TLB
380
        mov     cr3, eax          ; flush TLB
381
 
381
 
382
        mov     ecx, pg_data.mutex
382
        mov     ecx, pg_data.mutex
383
        call    mutex_init
383
        call    mutex_init
384
 
384
 
385
        mov     ecx, disk_list_mutex
385
        mov     ecx, disk_list_mutex
386
        call    mutex_init
386
        call    mutex_init
387
 
387
 
388
        mov     ecx, keyboard_list_mutex
388
        mov     ecx, keyboard_list_mutex
389
        call    mutex_init
389
        call    mutex_init
390
 
390
 
391
        mov     ecx, unpack_mutex
391
        mov     ecx, unpack_mutex
392
        call    mutex_init
392
        call    mutex_init
393
 
393
 
394
        mov     ecx, application_table_mutex
394
        mov     ecx, application_table_mutex
395
        call    mutex_init
395
        call    mutex_init
396
 
396
 
397
        mov     ecx, ide_mutex
397
        mov     ecx, ide_mutex
398
        call    mutex_init
398
        call    mutex_init
399
        mov     ecx, ide_channel1_mutex
399
        mov     ecx, ide_channel1_mutex
400
        call    mutex_init
400
        call    mutex_init
401
        mov     ecx, ide_channel2_mutex
401
        mov     ecx, ide_channel2_mutex
402
        call    mutex_init
402
        call    mutex_init
403
        mov     ecx, ide_channel3_mutex
403
        mov     ecx, ide_channel3_mutex
404
        call    mutex_init
404
        call    mutex_init
405
        mov     ecx, ide_channel4_mutex
405
        mov     ecx, ide_channel4_mutex
406
        call    mutex_init
406
        call    mutex_init
407
        mov     ecx, ide_channel5_mutex
407
        mov     ecx, ide_channel5_mutex
408
        call    mutex_init
408
        call    mutex_init
409
        mov     ecx, ide_channel6_mutex
409
        mov     ecx, ide_channel6_mutex
410
        call    mutex_init
410
        call    mutex_init
411
;-----------------------------------------------------------------------------
411
;-----------------------------------------------------------------------------
412
; SAVE REAL MODE VARIABLES
412
; SAVE REAL MODE VARIABLES
413
;-----------------------------------------------------------------------------
413
;-----------------------------------------------------------------------------
414
; --------------- APM ---------------------
414
; --------------- APM ---------------------
415
 
415
 
416
; init selectors
416
; init selectors
417
        mov     ebx, [BOOT_VARS+BOOT_APM_ENTRY]        ; offset of APM entry point
417
        mov     ebx, [BOOT_VARS+BOOT_APM_ENTRY]        ; offset of APM entry point
418
        movzx   eax, word [BOOT_VARS+BOOT_APM_CODE_32] ; real-mode segment base address of
418
        movzx   eax, word [BOOT_VARS+BOOT_APM_CODE_32] ; real-mode segment base address of
419
                                                                                ; protected-mode 32-bit code segment
419
                                                                                ; protected-mode 32-bit code segment
420
        movzx   ecx, word [BOOT_VARS+BOOT_APM_CODE_16]; real-mode segment base address of
420
        movzx   ecx, word [BOOT_VARS+BOOT_APM_CODE_16]; real-mode segment base address of
421
                                                                                ; protected-mode 16-bit code segment
421
                                                                                ; protected-mode 16-bit code segment
422
        movzx   edx, word [BOOT_VARS+BOOT_APM_DATA_16]; real-mode segment base address of
422
        movzx   edx, word [BOOT_VARS+BOOT_APM_DATA_16]; real-mode segment base address of
423
                                                                                ; protected-mode 16-bit data segment
423
                                                                                ; protected-mode 16-bit data segment
424
 
424
 
425
        shl     eax, 4
425
        shl     eax, 4
426
        mov     [dword apm_code_32 + 2], ax
426
        mov     [dword apm_code_32 + 2], ax
427
        shr     eax, 16
427
        shr     eax, 16
428
        mov     [dword apm_code_32 + 4], al
428
        mov     [dword apm_code_32 + 4], al
429
 
429
 
430
        shl     ecx, 4
430
        shl     ecx, 4
431
        mov     [dword apm_code_16 + 2], cx
431
        mov     [dword apm_code_16 + 2], cx
432
        shr     ecx, 16
432
        shr     ecx, 16
433
        mov     [dword apm_code_16 + 4], cl
433
        mov     [dword apm_code_16 + 4], cl
434
 
434
 
435
        shl     edx, 4
435
        shl     edx, 4
436
        mov     [dword apm_data_16 + 2], dx
436
        mov     [dword apm_data_16 + 2], dx
437
        shr     edx, 16
437
        shr     edx, 16
438
        mov     [dword apm_data_16 + 4], dl
438
        mov     [dword apm_data_16 + 4], dl
439
 
439
 
440
        mov     dword[apm_entry], ebx
440
        mov     dword[apm_entry], ebx
441
        mov     word [apm_entry + 4], apm_code_32 - gdts
441
        mov     word [apm_entry + 4], apm_code_32 - gdts
442
 
442
 
443
        mov     eax, [BOOT_VARS + BOOT_APM_VERSION] ; version & flags
443
        mov     eax, [BOOT_VARS + BOOT_APM_VERSION] ; version & flags
444
        mov     [apm_vf], eax
444
        mov     [apm_vf], eax
445
; -----------------------------------------
445
; -----------------------------------------
446
        mov     al, [BOOT_VARS+BOOT_DMA]            ; DMA access
446
        mov     al, [BOOT_VARS+BOOT_DMA]            ; DMA access
447
        mov     [allow_dma_access], al
447
        mov     [allow_dma_access], al
448
        movzx   eax, byte [BOOT_VARS+BOOT_BPP]      ; bpp
448
        movzx   eax, byte [BOOT_VARS+BOOT_BPP]      ; bpp
449
        mov     [_display.bits_per_pixel], eax
449
        mov     [_display.bits_per_pixel], eax
450
        mov     [_display.vrefresh], 60
450
        mov     [_display.vrefresh], 60
451
        mov     al, [BOOT_VARS+BOOT_DEBUG_PRINT]    ; If nonzero, duplicates debug output to the screen
451
        mov     al, [BOOT_VARS+BOOT_DEBUG_PRINT]    ; If nonzero, duplicates debug output to the screen
452
        mov     [debug_direct_print], al
452
        mov     [debug_direct_print], al
453
        mov     al, [BOOT_VARS+BOOT_LAUNCHER_START] ; Start the first app (LAUNCHER) after kernel is loaded?
453
        mov     al, [BOOT_VARS+BOOT_LAUNCHER_START] ; Start the first app (LAUNCHER) after kernel is loaded?
454
        mov     [launcher_start], al
454
        mov     [launcher_start], al
455
        movzx   eax, word [BOOT_VARS+BOOT_X_RES]; X max
455
        movzx   eax, word [BOOT_VARS+BOOT_X_RES]; X max
456
        mov     [_display.width], eax
456
        mov     [_display.width], eax
457
        mov     [display_width_standard], eax
457
        mov     [display_width_standard], eax
458
        dec     eax
458
        dec     eax
459
        mov     [screen_workarea.right], eax
459
        mov     [screen_workarea.right], eax
460
        movzx   eax, word [BOOT_VARS+BOOT_Y_RES]; Y max
460
        movzx   eax, word [BOOT_VARS+BOOT_Y_RES]; Y max
461
        mov     [_display.height], eax
461
        mov     [_display.height], eax
462
        mov     [display_height_standard], eax
462
        mov     [display_height_standard], eax
463
        dec     eax
463
        dec     eax
464
        mov     [screen_workarea.bottom], eax
464
        mov     [screen_workarea.bottom], eax
465
        movzx   eax, word [BOOT_VARS+BOOT_VESA_MODE] ; screen mode
465
        movzx   eax, word [BOOT_VARS+BOOT_VESA_MODE] ; screen mode
466
        mov     dword [SCR_MODE], eax
466
        mov     dword [SCR_MODE], eax
467
;        mov     eax, [BOOT_VAR+0x9014]             ; Vesa 1.2 bnk sw add
467
;        mov     eax, [BOOT_VAR+0x9014]             ; Vesa 1.2 bnk sw add
468
;        mov     [BANK_SWITCH], eax
468
;        mov     [BANK_SWITCH], eax
469
        mov     eax, 640 *4                         ; Bytes PerScanLine
469
        mov     eax, 640 *4                         ; Bytes PerScanLine
470
        cmp     [SCR_MODE], word 0x13               ; 320x200
470
        cmp     [SCR_MODE], word 0x13               ; 320x200
471
        je      @f
471
        je      @f
472
        cmp     [SCR_MODE], word 0x12               ; VGA 640x480
472
        cmp     [SCR_MODE], word 0x12               ; VGA 640x480
473
        je      @f
473
        je      @f
474
        movzx   eax, word[BOOT_VARS+BOOT_PITCH]      ; for other modes
474
        movzx   eax, word[BOOT_VARS+BOOT_PITCH]      ; for other modes
475
@@:
475
@@:
476
        mov     [_display.lfb_pitch], eax
476
        mov     [_display.lfb_pitch], eax
477
        mov     eax, [_display.width]
477
        mov     eax, [_display.width]
478
        mul     [_display.height]
478
        mul     [_display.height]
479
        mov     [_display.win_map_size], eax
479
        mov     [_display.win_map_size], eax
480
 
480
 
481
        call    calculate_fast_getting_offset_for_WinMapAddress
481
        call    calculate_fast_getting_offset_for_WinMapAddress
482
; for Qemu or non standart video cards
482
; for Qemu or non standart video cards
483
; Unfortunately [BytesPerScanLine] does not always
483
; Unfortunately [BytesPerScanLine] does not always
484
;                             equal to [_display.width] * [ScreenBPP] / 8
484
;                             equal to [_display.width] * [ScreenBPP] / 8
485
        call    calculate_fast_getting_offset_for_LFB
485
        call    calculate_fast_getting_offset_for_LFB
486
 
486
 
487
        mov     esi, BOOT_VARS+0x9080
487
        mov     esi, BOOT_VARS+0x9080
488
        movzx   ecx, byte [esi-1]
488
        movzx   ecx, byte [esi-1]
489
        mov     [NumBiosDisks], ecx
489
        mov     [NumBiosDisks], ecx
490
        mov     edi, BiosDisksData
490
        mov     edi, BiosDisksData
491
        rep movsd
491
        rep movsd
492
 
492
 
493
setvideomode:
493
setvideomode:
494
 
494
 
495
        mov     eax, [BOOT_VARS+BOOT_LFB]
495
        mov     eax, [BOOT_VARS+BOOT_LFB]
496
        mov     [LFBAddress], eax
496
        mov     [LFBAddress], eax
497
 
497
 
498
        cmp     word [SCR_MODE], 0x0012                 ; VGA (640x480 16 colors)
498
        cmp     word [SCR_MODE], 0x0012                 ; VGA (640x480 16 colors)
499
        je      .vga
499
        je      .vga
500
        cmp     word [SCR_MODE], 0x0013                 ; MCGA (320*200 256 colors)
500
        cmp     word [SCR_MODE], 0x0013                 ; MCGA (320*200 256 colors)
501
        je      .32bpp
501
        je      .32bpp
502
        cmp     byte [_display.bits_per_pixel], 32
502
        cmp     byte [_display.bits_per_pixel], 32
503
        je      .32bpp
503
        je      .32bpp
504
        cmp     byte [_display.bits_per_pixel], 24
504
        cmp     byte [_display.bits_per_pixel], 24
505
        je      .24bpp
505
        je      .24bpp
506
        cmp     byte [_display.bits_per_pixel], 16
506
        cmp     byte [_display.bits_per_pixel], 16
507
        je      .16bpp
507
        je      .16bpp
508
;        cmp     byte [_display.bits_per_pixel], 15
508
;        cmp     byte [_display.bits_per_pixel], 15
509
;        je      .15bpp
509
;        je      .15bpp
510
 
510
 
511
  .vga:
511
  .vga:
512
        mov     [PUTPIXEL], VGA_putpixel
512
        mov     [PUTPIXEL], VGA_putpixel
513
        mov     [GETPIXEL], Vesa20_getpixel32           ; Conversion buffer is 32 bpp
513
        mov     [GETPIXEL], Vesa20_getpixel32           ; Conversion buffer is 32 bpp
514
        mov     [_display.bytes_per_pixel], 4           ; Conversion buffer is 32 bpp
514
        mov     [_display.bytes_per_pixel], 4           ; Conversion buffer is 32 bpp
515
        jmp     .finish
515
        jmp     .finish
516
 
516
 
517
;  .15bpp:
517
;  .15bpp:
518
;        mov     [PUTPIXEL], Vesa20_putpixel15
518
;        mov     [PUTPIXEL], Vesa20_putpixel15
519
;        mov     [GETPIXEL], Vesa20_getpixel15
519
;        mov     [GETPIXEL], Vesa20_getpixel15
520
;        mov     [_display.bytes_per_pixel], 2
520
;        mov     [_display.bytes_per_pixel], 2
521
;        jmp     .finish
521
;        jmp     .finish
522
 
522
 
523
  .16bpp:
523
  .16bpp:
524
        mov     [PUTPIXEL], Vesa20_putpixel16
524
        mov     [PUTPIXEL], Vesa20_putpixel16
525
        mov     [GETPIXEL], Vesa20_getpixel16
525
        mov     [GETPIXEL], Vesa20_getpixel16
526
        mov     [_display.bytes_per_pixel], 2
526
        mov     [_display.bytes_per_pixel], 2
527
        jmp     .finish
527
        jmp     .finish
528
 
528
 
529
  .24bpp:
529
  .24bpp:
530
        mov     [PUTPIXEL], Vesa20_putpixel24
530
        mov     [PUTPIXEL], Vesa20_putpixel24
531
        mov     [GETPIXEL], Vesa20_getpixel24
531
        mov     [GETPIXEL], Vesa20_getpixel24
532
        mov     [_display.bytes_per_pixel], 3
532
        mov     [_display.bytes_per_pixel], 3
533
        jmp     .finish
533
        jmp     .finish
534
 
534
 
535
  .32bpp:
535
  .32bpp:
536
        mov     [PUTPIXEL], Vesa20_putpixel32
536
        mov     [PUTPIXEL], Vesa20_putpixel32
537
        mov     [GETPIXEL], Vesa20_getpixel32
537
        mov     [GETPIXEL], Vesa20_getpixel32
538
        mov     [_display.bytes_per_pixel], 4
538
        mov     [_display.bytes_per_pixel], 4
539
;        jmp     .finish
539
;        jmp     .finish
540
 
540
 
541
  .finish:
541
  .finish:
542
        mov     [MOUSE_PICTURE], mousepointer
542
        mov     [MOUSE_PICTURE], mousepointer
543
        mov     [_display.check_mouse], check_mouse_area_for_putpixel
543
        mov     [_display.check_mouse], check_mouse_area_for_putpixel
544
        mov     [_display.check_m_pixel], check_mouse_area_for_getpixel
544
        mov     [_display.check_m_pixel], check_mouse_area_for_getpixel
545
 
545
 
546
; -------- Fast System Call init ----------
546
; -------- Fast System Call init ----------
547
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
547
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
548
        bt      [cpu_caps], CAPS_SEP
548
        bt      [cpu_caps], CAPS_SEP
549
        jnc     .SEnP  ; SysEnter not Present
549
        jnc     .SEnP  ; SysEnter not Present
550
        xor     edx, edx
550
        xor     edx, edx
551
        mov     ecx, MSR_SYSENTER_CS
551
        mov     ecx, MSR_SYSENTER_CS
552
        mov     eax, os_code
552
        mov     eax, os_code
553
        wrmsr
553
        wrmsr
554
        mov     ecx, MSR_SYSENTER_ESP
554
        mov     ecx, MSR_SYSENTER_ESP
555
;           mov eax, sysenter_stack ; Check it
555
;           mov eax, sysenter_stack ; Check it
556
        xor     eax, eax
556
        xor     eax, eax
557
        wrmsr
557
        wrmsr
558
        mov     ecx, MSR_SYSENTER_EIP
558
        mov     ecx, MSR_SYSENTER_EIP
559
        mov     eax, sysenter_entry
559
        mov     eax, sysenter_entry
560
        wrmsr
560
        wrmsr
561
.SEnP:
561
.SEnP:
562
; AMD SYSCALL/SYSRET
562
; AMD SYSCALL/SYSRET
563
        cmp     byte[cpu_vendor], 'A'
563
        cmp     byte[cpu_vendor], 'A'
564
        jne     .noSYSCALL
564
        jne     .noSYSCALL
565
        mov     eax, 0x80000001
565
        mov     eax, 0x80000001
566
        cpuid
566
        cpuid
567
        test    edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
567
        test    edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
568
        jz      .noSYSCALL
568
        jz      .noSYSCALL
569
        mov     ecx, MSR_AMD_EFER
569
        mov     ecx, MSR_AMD_EFER
570
        rdmsr
570
        rdmsr
571
        or      eax, 1 ; bit_0 - System Call Extension (SCE)
571
        or      eax, 1 ; bit_0 - System Call Extension (SCE)
572
        wrmsr
572
        wrmsr
573
 
573
 
574
        ; !!!! It`s dirty hack, fix it !!!
574
        ; !!!! It`s dirty hack, fix it !!!
575
        ; Bits of EDX :
575
        ; Bits of EDX :
576
        ; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
576
        ; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
577
        ;  and the contents of this field, plus 8, are copied into the SS register.
577
        ;  and the contents of this field, plus 8, are copied into the SS register.
578
        ; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
578
        ; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
579
        ;  and the contents of this field, plus 8, are copied into the SS register.
579
        ;  and the contents of this field, plus 8, are copied into the SS register.
580
 
580
 
581
        ; mov   edx, (os_code + 16) * 65536 + os_code
581
        ; mov   edx, (os_code + 16) * 65536 + os_code
582
        mov     edx, 0x1B0008
582
        mov     edx, 0x1B0008
583
 
583
 
584
        mov     eax, syscall_entry
584
        mov     eax, syscall_entry
585
        mov     ecx, MSR_AMD_STAR
585
        mov     ecx, MSR_AMD_STAR
586
        wrmsr
586
        wrmsr
587
.noSYSCALL:
587
.noSYSCALL:
588
; -----------------------------------------
588
; -----------------------------------------
589
        stdcall alloc_page
589
        stdcall alloc_page
590
        stdcall map_page, tss-0xF80, eax, PG_SWR
590
        stdcall map_page, tss-0xF80, eax, PG_SWR
591
        stdcall alloc_page
591
        stdcall alloc_page
592
        stdcall map_page, tss+0x80, eax, PG_SWR
592
        stdcall map_page, tss+0x80, eax, PG_SWR
593
        stdcall alloc_page
593
        stdcall alloc_page
594
        stdcall map_page, tss+0x1080, eax, PG_SWR
594
        stdcall map_page, tss+0x1080, eax, PG_SWR
595
 
595
 
596
; LOAD IDT
596
; LOAD IDT
597
 
597
 
598
        call    build_interrupt_table ;lidt is executed
598
        call    build_interrupt_table ;lidt is executed
599
          ;lidt [idtreg]
599
          ;lidt [idtreg]
600
 
600
 
601
        call    init_kernel_heap
601
        call    init_kernel_heap
602
        stdcall kernel_alloc, (RING0_STACK_SIZE+512) * 2
602
        stdcall kernel_alloc, (RING0_STACK_SIZE+512) * 2
603
        mov     [os_stack_seg], eax
603
        mov     [os_stack_seg], eax
604
 
604
 
605
        lea     esp, [eax+RING0_STACK_SIZE]
605
        lea     esp, [eax+RING0_STACK_SIZE]
606
 
606
 
607
        mov     [tss._ss0], os_stack
607
        mov     [tss._ss0], os_stack
608
        mov     [tss._esp0], esp
608
        mov     [tss._esp0], esp
609
        mov     [tss._esp], esp
609
        mov     [tss._esp], esp
610
        mov     [tss._cs], os_code
610
        mov     [tss._cs], os_code
611
        mov     [tss._ss], os_stack
611
        mov     [tss._ss], os_stack
612
        mov     [tss._ds], app_data
612
        mov     [tss._ds], app_data
613
        mov     [tss._es], app_data
613
        mov     [tss._es], app_data
614
        mov     [tss._fs], app_data
614
        mov     [tss._fs], app_data
615
        mov     [tss._gs], app_data
615
        mov     [tss._gs], app_data
616
        mov     [tss._io], 128
616
        mov     [tss._io], 128
617
;Add IO access table - bit array of permitted ports
617
;Add IO access table - bit array of permitted ports
618
        mov     edi, tss._io_map_0
618
        mov     edi, tss._io_map_0
619
        xor     eax, eax
619
        xor     eax, eax
620
        not     eax
620
        not     eax
621
        mov     ecx, 8192/4
621
        mov     ecx, 8192/4
622
        rep stosd                    ; access to 4096*8=65536 ports
622
        rep stosd                    ; access to 4096*8=65536 ports
623
 
623
 
624
        mov     ax, tss0
624
        mov     ax, tss0
625
        ltr     ax
625
        ltr     ax
626
 
626
 
627
        mov     [LFBSize], 0xC00000
627
        mov     [LFBSize], 0xC00000
628
        call    init_LFB
628
        call    init_LFB
629
        call    init_fpu
629
        call    init_fpu
630
        call    init_malloc
630
        call    init_malloc
631
 
631
 
632
        stdcall alloc_kernel_space, 0x50000         ; FIXME check size
632
        stdcall alloc_kernel_space, 0x50000         ; FIXME check size
633
        mov     [default_io_map], eax
633
        mov     [default_io_map], eax
634
 
634
 
635
        add     eax, 0x2000
635
        add     eax, 0x2000
636
        mov     [ipc_tmp], eax
636
        mov     [ipc_tmp], eax
637
        mov     ebx, 0x1000
637
        mov     ebx, 0x1000
638
 
638
 
639
        add     eax, 0x40000
639
        add     eax, 0x40000
640
        mov     [proc_mem_map], eax
640
        mov     [proc_mem_map], eax
641
 
641
 
642
        add     eax, 0x8000
642
        add     eax, 0x8000
643
        mov     [proc_mem_pdir], eax
643
        mov     [proc_mem_pdir], eax
644
 
644
 
645
        add     eax, ebx
645
        add     eax, ebx
646
        mov     [proc_mem_tab], eax
646
        mov     [proc_mem_tab], eax
647
 
647
 
648
        add     eax, ebx
648
        add     eax, ebx
649
        mov     [tmp_task_ptab], eax
649
        mov     [tmp_task_ptab], eax
650
 
650
 
651
        add     eax, ebx
651
        add     eax, ebx
652
        mov     [ipc_pdir], eax
652
        mov     [ipc_pdir], eax
653
 
653
 
654
        add     eax, ebx
654
        add     eax, ebx
655
        mov     [ipc_ptab], eax
655
        mov     [ipc_ptab], eax
656
 
656
 
657
        stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
657
        stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
658
                (unpack.lc+unpack.lp)))*4
658
                (unpack.lc+unpack.lp)))*4
659
 
659
 
660
        mov     [unpack.p], eax
660
        mov     [unpack.p], eax
661
 
661
 
662
        call    init_events
662
        call    init_events
663
        mov     eax, srv.fd-SRV.fd
663
        mov     eax, srv.fd-SRV.fd
664
        mov     [srv.fd], eax
664
        mov     [srv.fd], eax
665
        mov     [srv.bk], eax
665
        mov     [srv.bk], eax
666
 
666
 
667
;Set base of graphic segment to linear address of LFB
667
;Set base of graphic segment to linear address of LFB
668
        mov     eax, [LFBAddress]         ; set for gs
668
        mov     eax, [LFBAddress]         ; set for gs
669
        mov     [graph_data_l+2], ax
669
        mov     [graph_data_l+2], ax
670
        shr     eax, 16
670
        shr     eax, 16
671
        mov     [graph_data_l+4], al
671
        mov     [graph_data_l+4], al
672
        mov     [graph_data_l+7], ah
672
        mov     [graph_data_l+7], ah
673
 
673
 
674
        stdcall kernel_alloc, [_display.win_map_size]
674
        stdcall kernel_alloc, [_display.win_map_size]
675
        mov     [_display.win_map], eax
675
        mov     [_display.win_map], eax
676
 
676
 
677
        xor     eax, eax
677
        xor     eax, eax
678
        inc     eax
678
        inc     eax
679
 
679
 
680
; set background
680
; set background
681
 
681
 
682
        mov     [BgrDrawMode], eax
682
        mov     [BgrDrawMode], eax
683
        mov     [BgrDataWidth], eax
683
        mov     [BgrDataWidth], eax
684
        mov     [BgrDataHeight], eax
684
        mov     [BgrDataHeight], eax
685
        mov     [mem_BACKGROUND], 4
685
        mov     [mem_BACKGROUND], 4
686
        mov     [img_background], static_background_data
686
        mov     [img_background], static_background_data
687
 
687
 
688
; set clipboard
688
; set clipboard
689
 
689
 
690
        xor     eax, eax
690
        xor     eax, eax
691
        mov     [clipboard_slots], eax
691
        mov     [clipboard_slots], eax
692
        mov     [clipboard_write_lock], eax
692
        mov     [clipboard_write_lock], eax
693
        stdcall kernel_alloc, 4096
693
        stdcall kernel_alloc, 4096
694
        test    eax, eax
694
        test    eax, eax
695
        jnz     @f
695
        jnz     @f
696
 
696
 
697
        dec     eax
697
        dec     eax
698
@@:
698
@@:
699
        mov     [clipboard_main_list], eax
699
        mov     [clipboard_main_list], eax
700
 
700
 
701
        mov     eax, [hpet_base]
701
        mov     eax, [hpet_base]
702
        test    eax, eax
702
        test    eax, eax
703
        jz      @F
703
        jz      @F
704
        DEBUGF  1, "K : HPET base %x\n", eax
-
 
705
        mov     eax, [hpet_period]
-
 
706
        DEBUGF  1, "K : HPET period %d\n", eax
-
 
707
        mov     eax, [hpet_timers]
-
 
708
        DEBUGF  1, "K : HPET timers %d\n", eax
-
 
709
 
-
 
710
        mov     eax, [hpet_base]
704
        mov     eax, [hpet_base]
711
        stdcall map_io_mem, [hpet_base], 1024, PG_GLOBAL+PAT_UC+PG_SWR
705
        stdcall map_io_mem, [hpet_base], 1024, PG_GLOBAL+PAT_UC+PG_SWR
712
        mov     [hpet_base], eax
706
        mov     [hpet_base], eax
713
 
-
 
714
        mov     eax, [eax]
707
        mov     eax, [eax]
715
        DEBUGF  1, "K : HPET caps %x\n", eax
708
        DEBUGF  1, "K : HPET caps %x\n", eax
716
 
-
 
717
@@:
709
@@:
718
; SET UP OS TASK
710
; SET UP OS TASK
719
 
711
 
720
        mov     esi, boot_setostask
712
        mov     esi, boot_setostask
721
        call    boot_log
713
        call    boot_log
722
 
714
 
723
        mov     eax, sys_proc
715
        mov     eax, sys_proc
724
        lea     edi, [eax+PROC.heap_lock]
716
        lea     edi, [eax+PROC.heap_lock]
725
        mov     ecx, (PROC.ht_free-PROC.heap_lock)/4
717
        mov     ecx, (PROC.ht_free-PROC.heap_lock)/4
726
 
718
 
727
        list_init eax
719
        list_init eax
728
        add     eax, PROC.thr_list
720
        add     eax, PROC.thr_list
729
        list_init eax
721
        list_init eax
730
 
722
 
731
        xor     eax, eax
723
        xor     eax, eax
732
        cld
724
        cld
733
        rep stosd
725
        rep stosd
734
 
726
 
735
        mov     [edi], dword (PROC.pdt_0 - PROC.htab)/4 - 3
727
        mov     [edi], dword (PROC.pdt_0 - PROC.htab)/4 - 3
736
        mov     [edi+4], dword 3           ;reserve handles for stdin stdout and stderr
728
        mov     [edi+4], dword 3           ;reserve handles for stdin stdout and stderr
737
        mov     ecx, (PROC.pdt_0 - PROC.htab)/4
729
        mov     ecx, (PROC.pdt_0 - PROC.htab)/4
738
        add     edi, 8
730
        add     edi, 8
739
        inc     eax
731
        inc     eax
740
@@:
732
@@:
741
        stosd
733
        stosd
742
        inc     eax
734
        inc     eax
743
        cmp     eax, ecx
735
        cmp     eax, ecx
744
        jbe     @B
736
        jbe     @B
745
 
737
 
746
        mov     [sys_proc+PROC.pdt_0_phys], sys_proc-OS_BASE+PROC.pdt_0
738
        mov     [sys_proc+PROC.pdt_0_phys], sys_proc-OS_BASE+PROC.pdt_0
747
 
739
 
748
        mov     eax, -1
740
        mov     eax, -1
749
        mov     edi, thr_slot_map+4
741
        mov     edi, thr_slot_map+4
750
        mov     [edi-4], dword 0xFFFFFFF8
742
        mov     [edi-4], dword 0xFFFFFFF8
751
        stosd
743
        stosd
752
        stosd
744
        stosd
753
        stosd
745
        stosd
754
        stosd
746
        stosd
755
        stosd
747
        stosd
756
        stosd
748
        stosd
757
        stosd
749
        stosd
758
 
750
 
759
        mov     [current_process], sys_proc
751
        mov     [current_process], sys_proc
760
 
752
 
761
        mov     edx, SLOT_BASE+256*1
753
        mov     edx, SLOT_BASE+256*1
762
        mov     ebx, [os_stack_seg]
754
        mov     ebx, [os_stack_seg]
763
        add     ebx, 0x2000
755
        add     ebx, 0x2000
764
        call    setup_os_slot
756
        call    setup_os_slot
765
        mov     dword [edx], 'IDLE'
757
        mov     dword [edx], 'IDLE'
766
        sub     [edx+APPDATA.saved_esp], 4
758
        sub     [edx+APPDATA.saved_esp], 4
767
        mov     eax, [edx+APPDATA.saved_esp]
759
        mov     eax, [edx+APPDATA.saved_esp]
768
        mov     dword [eax], idle_thread
760
        mov     dword [eax], idle_thread
769
        mov     ecx, IDLE_PRIORITY
761
        mov     ecx, IDLE_PRIORITY
770
        call    scheduler_add_thread
762
        call    scheduler_add_thread
771
 
763
 
772
        mov     edx, SLOT_BASE+256*2
764
        mov     edx, SLOT_BASE+256*2
773
        mov     ebx, [os_stack_seg]
765
        mov     ebx, [os_stack_seg]
774
        call    setup_os_slot
766
        call    setup_os_slot
775
        mov     dword [edx], 'OS'
767
        mov     dword [edx], 'OS'
776
        xor     ecx, ecx
768
        xor     ecx, ecx
777
        call    scheduler_add_thread
769
        call    scheduler_add_thread
778
 
770
 
779
        mov     dword [CURRENT_TASK], 2
771
        mov     dword [CURRENT_TASK], 2
780
        mov     dword [TASK_COUNT], 2
772
        mov     dword [TASK_COUNT], 2
781
        mov     dword [current_slot], SLOT_BASE + 256*2
773
        mov     dword [current_slot], SLOT_BASE + 256*2
782
        mov     dword [TASK_BASE], CURRENT_TASK + 32*2
774
        mov     dword [TASK_BASE], CURRENT_TASK + 32*2
783
 
775
 
784
; Move other CPUs to deep sleep, if it is useful
776
; Move other CPUs to deep sleep, if it is useful
785
uglobal
777
uglobal
786
use_mwait_for_idle db 0
778
use_mwait_for_idle db 0
787
endg
779
endg
788
        cmp     [cpu_vendor+8], 'ntel'
780
        cmp     [cpu_vendor+8], 'ntel'
789
        jnz     .no_wake_cpus
781
        jnz     .no_wake_cpus
790
        bt      [cpu_caps+4], CAPS_MONITOR-32
782
        bt      [cpu_caps+4], CAPS_MONITOR-32
791
        jnc     .no_wake_cpus
783
        jnc     .no_wake_cpus
792
        dbgstr 'using mwait for idle loop'
784
        dbgstr 'using mwait for idle loop'
793
        inc     [use_mwait_for_idle]
785
        inc     [use_mwait_for_idle]
794
        mov     ebx, [cpu_count]
786
        mov     ebx, [cpu_count]
795
        cmp     ebx, 1
787
        cmp     ebx, 1
796
        jbe     .no_wake_cpus
788
        jbe     .no_wake_cpus
797
        call    create_trampoline_pgmap
789
        call    create_trampoline_pgmap
798
        mov     [cr3_ap+OS_BASE], eax
790
        mov     [cr3_ap+OS_BASE], eax
799
        mov     eax, cr4
791
        mov     eax, cr4
800
        mov     [cr4_ap+OS_BASE], eax
792
        mov     [cr4_ap+OS_BASE], eax
801
        mov     esi, OS_BASE + ap_init16
793
        mov     esi, OS_BASE + ap_init16
802
        mov     edi, OS_BASE + 8000h
794
        mov     edi, OS_BASE + 8000h
803
        mov     ecx, (ap_init16_size + 3) / 4
795
        mov     ecx, (ap_init16_size + 3) / 4
804
        rep movsd
796
        rep movsd
805
        stdcall map_io_mem, [acpi_lapic_base], 0x1000, PG_GLOBAL+PG_NOCACHE+PG_SWR
797
        stdcall map_io_mem, [acpi_lapic_base], 0x1000, PG_GLOBAL+PG_NOCACHE+PG_SWR
806
        mov     [LAPIC_BASE], eax
798
        mov     [LAPIC_BASE], eax
807
        lea     edi, [eax+300h]
799
        lea     edi, [eax+300h]
808
        mov     esi, smpt+4
800
        mov     esi, smpt+4
809
        dec     ebx
801
        dec     ebx
810
.wake_cpus_loop:
802
.wake_cpus_loop:
811
        lodsd
803
        lodsd
812
        push    esi
804
        push    esi
813
        xor     esi, esi
805
        xor     esi, esi
814
        inc     esi
806
        inc     esi
815
        shl     eax, 24
807
        shl     eax, 24
816
        mov     [edi+10h], eax
808
        mov     [edi+10h], eax
817
; assert INIT IPI
809
; assert INIT IPI
818
        mov     dword [edi], 0C500h
810
        mov     dword [edi], 0C500h
819
        call    delay_ms
811
        call    delay_ms
820
@@:
812
@@:
821
        test    dword [edi], 1000h
813
        test    dword [edi], 1000h
822
        jnz     @b
814
        jnz     @b
823
; deassert INIT IPI
815
; deassert INIT IPI
824
        mov     dword [edi], 8500h
816
        mov     dword [edi], 8500h
825
        call    delay_ms
817
        call    delay_ms
826
@@:
818
@@:
827
        test    dword [edi], 1000h
819
        test    dword [edi], 1000h
828
        jnz     @b
820
        jnz     @b
829
; send STARTUP IPI
821
; send STARTUP IPI
830
        mov     dword [edi], 600h + (8000h shr 12)
822
        mov     dword [edi], 600h + (8000h shr 12)
831
        call    delay_ms
823
        call    delay_ms
832
@@:
824
@@:
833
        test    dword [edi], 1000h
825
        test    dword [edi], 1000h
834
        jnz     @b
826
        jnz     @b
835
        pop     esi
827
        pop     esi
836
        dec     ebx
828
        dec     ebx
837
        jnz     .wake_cpus_loop
829
        jnz     .wake_cpus_loop
838
        mov     eax, [cpu_count]
830
        mov     eax, [cpu_count]
839
        dec     eax
831
        dec     eax
840
@@:
832
@@:
841
        cmp     [ap_initialized], eax
833
        cmp     [ap_initialized], eax
842
        jnz     @b
834
        jnz     @b
843
        mov     eax, [cr3_ap+OS_BASE]
835
        mov     eax, [cr3_ap+OS_BASE]
844
        call    free_page
836
        call    free_page
845
.no_wake_cpus:
837
.no_wake_cpus:
846
 
838
 
847
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
839
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
848
        mov     esi, boot_initirq
840
        mov     esi, boot_initirq
849
        call    boot_log
841
        call    boot_log
850
        call    init_irqs
842
        call    init_irqs
851
 
843
 
852
        mov     esi, boot_picinit
844
        mov     esi, boot_picinit
853
        call    boot_log
845
        call    boot_log
854
        call    PIC_init
846
        call    PIC_init
855
 
847
 
856
        mov     esi, boot_v86machine
848
        mov     esi, boot_v86machine
857
        call    boot_log
849
        call    boot_log
858
; Initialize system V86 machine
850
; Initialize system V86 machine
859
        call    init_sys_v86
851
        call    init_sys_v86
860
 
852
 
861
        mov     esi, boot_inittimer
853
        mov     esi, boot_inittimer
862
        call    boot_log
854
        call    boot_log
863
; Initialize system timer (IRQ0)
855
; Initialize system timer (IRQ0)
864
        call    PIT_init
856
        call    PIT_init
865
 
857
 
866
; Register ramdisk file system
858
; Register ramdisk file system
867
        cmp     [boot_dev+OS_BASE+0x10000], 1
859
        cmp     [boot_dev+OS_BASE+0x10000], 1
868
        je      @f
860
        je      @f
869
 
861
 
870
        call    register_ramdisk
862
        call    register_ramdisk
871
;--------------------------------------
863
;--------------------------------------
872
@@:
864
@@:
873
        mov     esi, boot_initapic
865
        mov     esi, boot_initapic
874
        call    boot_log
866
        call    boot_log
875
; Try to Initialize APIC
867
; Try to Initialize APIC
876
        call    APIC_init
868
        call    APIC_init
877
 
869
 
878
        mov     esi, boot_enableirq
870
        mov     esi, boot_enableirq
879
        call    boot_log
871
        call    boot_log
880
; Enable timer IRQ (IRQ0) and co-processor IRQ (IRQ13)
872
; Enable timer IRQ (IRQ0) and co-processor IRQ (IRQ13)
881
; they are used: when partitions are scanned, hd_read relies on timer
873
; they are used: when partitions are scanned, hd_read relies on timer
882
        call    unmask_timer
874
        call    unmask_timer
883
        stdcall enable_irq, 2               ; @#$%! PIC
875
        stdcall enable_irq, 2               ; @#$%! PIC
884
        stdcall enable_irq, 13              ; co-processor
876
        stdcall enable_irq, 13              ; co-processor
885
 
877
 
886
; Setup serial output console (if enabled)
878
; Setup serial output console (if enabled)
887
if defined debug_com_base
879
if defined debug_com_base
888
 
880
 
889
        ; reserve port so nobody else will use it
881
        ; reserve port so nobody else will use it
890
        xor     ebx, ebx
882
        xor     ebx, ebx
891
        mov     ecx, debug_com_base
883
        mov     ecx, debug_com_base
892
        mov     edx, debug_com_base+7
884
        mov     edx, debug_com_base+7
893
        call    r_f_port_area
885
        call    r_f_port_area
894
 
886
 
895
        ; enable Divisor latch
887
        ; enable Divisor latch
896
        mov     dx, debug_com_base+3
888
        mov     dx, debug_com_base+3
897
        mov     al, 1 shl 7
889
        mov     al, 1 shl 7
898
        out     dx, al
890
        out     dx, al
899
 
891
 
900
        ; Set speed to 115200 baud (max speed)
892
        ; Set speed to 115200 baud (max speed)
901
        mov     dx, debug_com_base
893
        mov     dx, debug_com_base
902
        mov     al, 0x01
894
        mov     al, 0x01
903
        out     dx, al
895
        out     dx, al
904
 
896
 
905
        mov     dx, debug_com_base+1
897
        mov     dx, debug_com_base+1
906
        mov     al, 0x00
898
        mov     al, 0x00
907
        out     dx, al
899
        out     dx, al
908
 
900
 
909
        ; No parity, 8bits words, one stop bit, dlab bit back to 0
901
        ; No parity, 8bits words, one stop bit, dlab bit back to 0
910
        mov     dx, debug_com_base+3
902
        mov     dx, debug_com_base+3
911
        mov     al, 3
903
        mov     al, 3
912
        out     dx, al
904
        out     dx, al
913
 
905
 
914
        ; disable interrupts
906
        ; disable interrupts
915
        mov     dx, debug_com_base+1
907
        mov     dx, debug_com_base+1
916
        mov     al, 0
908
        mov     al, 0
917
        out     dx, al
909
        out     dx, al
918
 
910
 
919
        ; clear +  enable fifo (64 bits)
911
        ; clear +  enable fifo (64 bits)
920
        mov     dx, debug_com_base+2
912
        mov     dx, debug_com_base+2
921
        mov     al, 0x7 + 1 shl 5
913
        mov     al, 0x7 + 1 shl 5
922
        out     dx, al
914
        out     dx, al
923
 
915
 
924
end if
916
end if
925
 
917
 
926
 
918
 
927
;-----------------------------------------------------------------------------
919
;-----------------------------------------------------------------------------
928
; show SVN version of kernel on the message board
920
; show SVN version of kernel on the message board
929
;-----------------------------------------------------------------------------
921
;-----------------------------------------------------------------------------
930
        mov     eax, [version_inf.rev]
922
        mov     eax, [version_inf.rev]
931
        DEBUGF  1, "K : kernel SVN r%d\n", eax
923
        DEBUGF  1, "K : kernel SVN r%d\n", eax
932
;-----------------------------------------------------------------------------
924
;-----------------------------------------------------------------------------
933
; show CPU count on the message board
925
; show CPU count on the message board
934
;-----------------------------------------------------------------------------
926
;-----------------------------------------------------------------------------
935
        mov     eax, [cpu_count]
927
        mov     eax, [cpu_count]
936
        test    eax, eax
928
        test    eax, eax
937
        jnz     @F
929
        jnz     @F
938
        mov     al, 1                             ; at least one CPU
930
        mov     al, 1                             ; at least one CPU
939
@@:
931
@@:
940
        DEBUGF  1, "K : %d CPU detected\n", eax
932
        DEBUGF  1, "K : %d CPU detected\n", eax
941
;-----------------------------------------------------------------------------
933
;-----------------------------------------------------------------------------
942
; detect Floppy drives
934
; detect Floppy drives
943
;-----------------------------------------------------------------------------
935
;-----------------------------------------------------------------------------
944
        mov     esi, boot_detectfloppy
936
        mov     esi, boot_detectfloppy
945
        call    boot_log
937
        call    boot_log
946
include 'detect/dev_fd.inc'
938
include 'detect/dev_fd.inc'
947
;-----------------------------------------------------------------------------
939
;-----------------------------------------------------------------------------
948
; create pci-devices list
940
; create pci-devices list
949
;-----------------------------------------------------------------------------
941
;-----------------------------------------------------------------------------
950
        mov     [pci_access_enabled], 1
942
        mov     [pci_access_enabled], 1
951
        call    pci_enum
943
        call    pci_enum
952
;-----------------------------------------------------------------------------
944
;-----------------------------------------------------------------------------
953
; initialisation IDE ATA code
945
; initialisation IDE ATA code
954
;-----------------------------------------------------------------------------
946
;-----------------------------------------------------------------------------
955
include 'detect/init_ata.inc'
947
include 'detect/init_ata.inc'
956
;-----------------------------------------------------------------------------
948
;-----------------------------------------------------------------------------
957
if 0
949
if 0
958
        mov     ax, [OS_BASE+0x10000+bx_from_load]
950
        mov     ax, [OS_BASE+0x10000+bx_from_load]
959
        cmp     ax, 'r1'; if using not ram disk, then load librares and parameters {SPraid.simba}
951
        cmp     ax, 'r1'; if using not ram disk, then load librares and parameters {SPraid.simba}
960
        je      no_lib_load
952
        je      no_lib_load
961
 
953
 
962
        mov     esi, boot_loadlibs
954
        mov     esi, boot_loadlibs
963
        call    boot_log
955
        call    boot_log
964
; LOADING LIBRARES
956
; LOADING LIBRARES
965
        stdcall dll.Load, @IMPORT           ; loading librares for kernel (.obj files)
957
        stdcall dll.Load, @IMPORT           ; loading librares for kernel (.obj files)
966
        call    load_file_parse_table       ; prepare file parse table
958
        call    load_file_parse_table       ; prepare file parse table
967
        call    set_kernel_conf             ; configure devices and gui
959
        call    set_kernel_conf             ; configure devices and gui
968
no_lib_load:
960
no_lib_load:
969
end if
961
end if
970
 
962
 
971
; Display APIC status
963
; Display APIC status
972
        mov     esi, boot_APIC_found
964
        mov     esi, boot_APIC_found
973
        cmp     [irq_mode], IRQ_APIC
965
        cmp     [irq_mode], IRQ_APIC
974
        je      @f
966
        je      @f
975
        mov     esi, boot_APIC_nfound
967
        mov     esi, boot_APIC_nfound
976
@@:
968
@@:
977
        call    boot_log
969
        call    boot_log
978
 
970
 
979
; PRINT AMOUNT OF MEMORY
971
; PRINT AMOUNT OF MEMORY
980
        mov     esi, boot_memdetect
972
        mov     esi, boot_memdetect
981
        call    boot_log
973
        call    boot_log
982
 
974
 
983
        movzx   ecx, word [boot_y]
975
        movzx   ecx, word [boot_y]
984
        if lang eq ru
976
        if lang eq ru
985
        or      ecx, (10+30*6) shl 16
977
        or      ecx, (10+30*6) shl 16
986
        else if lang eq sp
978
        else if lang eq sp
987
        or      ecx, (10+33*6) shl 16
979
        or      ecx, (10+33*6) shl 16
988
        else
980
        else
989
        or      ecx, (10+29*6) shl 16
981
        or      ecx, (10+29*6) shl 16
990
        end if
982
        end if
991
        sub     ecx, 10
983
        sub     ecx, 10
992
        mov     edx, 0xFFFFFF
984
        mov     edx, 0xFFFFFF
993
        mov     ebx, [MEM_AMOUNT]
985
        mov     ebx, [MEM_AMOUNT]
994
        shr     ebx, 20
986
        shr     ebx, 20
995
        xor     edi, edi
987
        xor     edi, edi
996
        mov     eax, 0x00040000
988
        mov     eax, 0x00040000
997
        inc     edi
989
        inc     edi
998
        call    display_number_force
990
        call    display_number_force
999
 
991
 
1000
; BUILD SCHEDULER
992
; BUILD SCHEDULER
1001
 
993
 
1002
;        call    build_scheduler; sys32.inc
994
;        call    build_scheduler; sys32.inc
1003
 
995
 
1004
;        mov     esi, boot_devices
996
;        mov     esi, boot_devices
1005
;        call    boot_log
997
;        call    boot_log
1006
 
998
 
1007
        call    clear_pci_ide_interrupts
999
        call    clear_pci_ide_interrupts
1008
 
1000
 
1009
include "detect/vortex86.inc"                     ; Vortex86 SoC detection code
1001
include "detect/vortex86.inc"                     ; Vortex86 SoC detection code
1010
 
1002
 
1011
        stdcall load_pe_driver, szVidintel, 0
1003
        stdcall load_pe_driver, szVidintel, 0
1012
 
1004
 
1013
        call    usb_init
1005
        call    usb_init
1014
 
1006
 
1015
; SET PRELIMINARY WINDOW STACK AND POSITIONS
1007
; SET PRELIMINARY WINDOW STACK AND POSITIONS
1016
 
1008
 
1017
        mov     esi, boot_windefs
1009
        mov     esi, boot_windefs
1018
        call    boot_log
1010
        call    boot_log
1019
        call    set_window_defaults
1011
        call    set_window_defaults
1020
 
1012
 
1021
; SET BACKGROUND DEFAULTS
1013
; SET BACKGROUND DEFAULTS
1022
 
1014
 
1023
        mov     esi, boot_bgr
1015
        mov     esi, boot_bgr
1024
        call    boot_log
1016
        call    boot_log
1025
        call    init_background
1017
        call    init_background
1026
        call    calculatebackground
1018
        call    calculatebackground
1027
 
1019
 
1028
; RESERVE SYSTEM IRQ'S JA PORT'S
1020
; RESERVE SYSTEM IRQ'S JA PORT'S
1029
 
1021
 
1030
        mov     esi, boot_resirqports
1022
        mov     esi, boot_resirqports
1031
        call    boot_log
1023
        call    boot_log
1032
        call    reserve_irqs_ports
1024
        call    reserve_irqs_ports
1033
 
1025
 
1034
        call    init_display
1026
        call    init_display
1035
        mov     eax, [def_cursor]
1027
        mov     eax, [def_cursor]
1036
        mov     [SLOT_BASE+APPDATA.cursor+256], eax
1028
        mov     [SLOT_BASE+APPDATA.cursor+256], eax
1037
        mov     [SLOT_BASE+APPDATA.cursor+256*2], eax
1029
        mov     [SLOT_BASE+APPDATA.cursor+256*2], eax
1038
 
1030
 
1039
; PRINT CPU FREQUENCY
1031
; PRINT CPU FREQUENCY
1040
 
1032
 
1041
        mov     esi, boot_cpufreq
1033
        mov     esi, boot_cpufreq
1042
        call    boot_log
1034
        call    boot_log
-
 
1035
 
-
 
1036
        cli
-
 
1037
        mov     ebx, [hpet_base]
-
 
1038
        test    ebx, ebx
-
 
1039
        jz      @F
-
 
1040
        mov     ebx, [ebx+0xF0]
-
 
1041
 
-
 
1042
        rdtsc
-
 
1043
        mov     ecx, 1000
-
 
1044
        sub     eax, [hpet_tsc_start]
-
 
1045
        sbb     edx, [hpet_tsc_start+4]
-
 
1046
        shld    edx, eax, 10
-
 
1047
        shl     eax, 10
-
 
1048
        mov     esi, eax
-
 
1049
        mov     eax, edx
-
 
1050
        mul     ecx
-
 
1051
        xchg    eax, esi
-
 
1052
        mul     ecx
-
 
1053
        adc     edx, esi
-
 
1054
        div     ebx
-
 
1055
        mul     ecx
-
 
1056
        div     [hpet_period]
1043
 
1057
        mul     ecx
-
 
1058
        DEBUGF  1, "K : cpu frequency %u Hz\n", eax
-
 
1059
        jmp     .next
1044
        cli                         ;FIXME check IF
1060
@@:
1045
        rdtsc
1061
        rdtsc
1046
        mov     ecx, eax
1062
        mov     ecx, eax
1047
        mov     esi, 250            ; wait 1/4 a second
1063
        mov     esi, 250            ; wait 1/4 a second
1048
        call    delay_ms
1064
        call    delay_ms
1049
        rdtsc
1065
        rdtsc
1050
        sti
1066
        sti
1051
 
1067
 
1052
        sub     eax, ecx
1068
        sub     eax, ecx
1053
        xor     edx, edx
1069
        xor     edx, edx
1054
        shld    edx, eax, 2
1070
        shld    edx, eax, 2
1055
        shl     eax, 2
1071
        shl     eax, 2
-
 
1072
.next:
1056
        mov     dword [cpu_freq], eax
1073
        mov     dword [cpu_freq], eax
1057
        mov     dword [cpu_freq+4], edx
1074
        mov     dword [cpu_freq+4], edx
1058
        mov     ebx, 1000000
1075
        mov     ebx, 1000000
1059
        div     ebx
1076
        div     ebx
1060
        mov     ebx, eax
1077
        mov     ebx, eax
1061
 
1078
 
1062
        movzx   ecx, word [boot_y]
1079
        movzx   ecx, word [boot_y]
1063
        if lang eq ru
1080
        if lang eq ru
1064
        add     ecx, (10+19*6) shl 16 - 10
1081
        add     ecx, (10+19*6) shl 16 - 10
1065
        else if lang eq sp
1082
        else if lang eq sp
1066
        add     ecx, (10+25*6) shl 16 - 10
1083
        add     ecx, (10+25*6) shl 16 - 10
1067
        else
1084
        else
1068
        add     ecx, (10+17*6) shl 16 - 10
1085
        add     ecx, (10+17*6) shl 16 - 10
1069
        end if
1086
        end if
1070
 
1087
 
1071
        mov     edx, 0xFFFFFF
1088
        mov     edx, 0xFFFFFF
1072
        xor     edi, edi
1089
        xor     edi, edi
1073
        mov     eax, 0x00040000
1090
        mov     eax, 0x00040000
1074
        inc     edi
1091
        inc     edi
1075
        call    display_number_force
1092
        call    display_number_force
1076
 
1093
 
1077
; SET VARIABLES
1094
; SET VARIABLES
1078
 
1095
 
1079
        call    set_variables
1096
        call    set_variables
1080
 
1097
 
1081
; STACK AND FDC
1098
; STACK AND FDC
1082
 
1099
 
1083
        call    stack_init
1100
        call    stack_init
1084
        call    fdc_init
1101
        call    fdc_init
1085
 
1102
 
1086
; PALETTE FOR 320x200 and 640x480 16 col
1103
; PALETTE FOR 320x200 and 640x480 16 col
1087
 
1104
 
1088
        cmp     [SCR_MODE], word 0x12
1105
        cmp     [SCR_MODE], word 0x12
1089
        jne     no_pal_vga
1106
        jne     no_pal_vga
1090
        mov     esi, boot_pal_vga
1107
        mov     esi, boot_pal_vga
1091
        call    boot_log
1108
        call    boot_log
1092
        call    paletteVGA
1109
        call    paletteVGA
1093
      no_pal_vga:
1110
      no_pal_vga:
1094
 
1111
 
1095
        cmp     [SCR_MODE], word 0x13
1112
        cmp     [SCR_MODE], word 0x13
1096
        jne     no_pal_ega
1113
        jne     no_pal_ega
1097
        mov     esi, boot_pal_ega
1114
        mov     esi, boot_pal_ega
1098
        call    boot_log
1115
        call    boot_log
1099
        call    palette320x200
1116
        call    palette320x200
1100
      no_pal_ega:
1117
      no_pal_ega:
1101
 
1118
 
1102
; LOAD DEFAULT SKIN
1119
; LOAD DEFAULT SKIN
1103
 
1120
 
1104
        call    load_default_skin
1121
        call    load_default_skin
1105
 
1122
 
1106
;protect io permission map
1123
; Protect I/O permission map
1107
 
1124
 
1108
        mov     esi, [default_io_map]
1125
        mov     esi, [default_io_map]
1109
        stdcall map_page, esi, [SLOT_BASE+256+APPDATA.io_map], PG_READ
1126
        stdcall map_page, esi, [SLOT_BASE+256+APPDATA.io_map], PG_READ
1110
        add     esi, 0x1000
1127
        add     esi, 0x1000
1111
        stdcall map_page, esi, [SLOT_BASE+256+APPDATA.io_map+4], PG_READ
1128
        stdcall map_page, esi, [SLOT_BASE+256+APPDATA.io_map+4], PG_READ
1112
 
1129
 
1113
        stdcall map_page, tss._io_map_0, \
1130
        stdcall map_page, tss._io_map_0, \
1114
                [SLOT_BASE+256+APPDATA.io_map], PG_READ
1131
                [SLOT_BASE+256+APPDATA.io_map], PG_READ
1115
        stdcall map_page, tss._io_map_1, \
1132
        stdcall map_page, tss._io_map_1, \
1116
                [SLOT_BASE+256+APPDATA.io_map+4], PG_READ
1133
                [SLOT_BASE+256+APPDATA.io_map+4], PG_READ
1117
 
1134
 
1118
; SET KEYBOARD PARAMETERS
1135
; SET KEYBOARD PARAMETERS
1119
        mov     al, 0xf6       ; reset keyboard, scan enabled
1136
        mov     al, 0xf6       ; reset keyboard, scan enabled
1120
        call    kb_write_wait_ack
1137
        call    kb_write_wait_ack
1121
        test    ah, ah
1138
        test    ah, ah
1122
        jnz     .no_keyboard
1139
        jnz     .no_keyboard
1123
 
1140
 
1124
iglobal
1141
iglobal
1125
align 4
1142
align 4
1126
ps2_keyboard_functions:
1143
ps2_keyboard_functions:
1127
        dd      .end - $
1144
        dd      .end - $
1128
        dd      0       ; no close
1145
        dd      0       ; no close
1129
        dd      ps2_set_lights
1146
        dd      ps2_set_lights
1130
.end:
1147
.end:
1131
endg
1148
endg
1132
        stdcall register_keyboard, ps2_keyboard_functions, 0
1149
        stdcall register_keyboard, ps2_keyboard_functions, 0
1133
       ; mov   al, 0xED       ; Keyboard LEDs - only for testing!
1150
       ; mov   al, 0xED       ; Keyboard LEDs - only for testing!
1134
       ; call  kb_write_wait_ack
1151
       ; call  kb_write_wait_ack
1135
       ; mov   al, 111b
1152
       ; mov   al, 111b
1136
       ; call  kb_write_wait_ack
1153
       ; call  kb_write_wait_ack
1137
 
1154
 
1138
        mov     al, 0xF3     ; set repeat rate & delay
1155
        mov     al, 0xF3     ; set repeat rate & delay
1139
        call    kb_write_wait_ack
1156
        call    kb_write_wait_ack
1140
        mov     al, 0; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
1157
        mov     al, 0; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
1141
        call    kb_write_wait_ack
1158
        call    kb_write_wait_ack
1142
     ;// mike.dld [
1159
     ;// mike.dld [
1143
        call    set_lights
1160
        call    set_lights
1144
     ;// mike.dld ]
1161
     ;// mike.dld ]
1145
        stdcall attach_int_handler, 1, irq1, 0
1162
        stdcall attach_int_handler, 1, irq1, 0
1146
        DEBUGF  1, "K : IRQ1 return code %x\n", eax
1163
        DEBUGF  1, "K : IRQ1 return code %x\n", eax
1147
.no_keyboard:
1164
.no_keyboard:
1148
 
1165
 
1149
; Load PS/2 mouse driver
1166
; Load PS/2 mouse driver
1150
 
1167
 
1151
        stdcall load_pe_driver, szPS2MDriver, 0
1168
        stdcall load_pe_driver, szPS2MDriver, 0
1152
 
1169
 
1153
        mov     esi, boot_setmouse
1170
        mov     esi, boot_setmouse
1154
        call    boot_log
1171
        call    boot_log
1155
        call    setmouse
1172
        call    setmouse
1156
 
1173
 
1157
; LOAD FIRST APPLICATION
1174
; LOAD FIRST APPLICATION
1158
        cmp     byte [launcher_start], 1        ; Check if starting LAUNCHER is selected on blue screen (1 = yes)
1175
        cmp     byte [launcher_start], 1        ; Check if starting LAUNCHER is selected on blue screen (1 = yes)
1159
        jnz     first_app_found
1176
        jnz     first_app_found
1160
 
1177
 
1161
        cli
1178
        cli
1162
        mov     ebp, firstapp
1179
        mov     ebp, firstapp
1163
        call    fs_execute_from_sysdir
1180
        call    fs_execute_from_sysdir
1164
        test    eax, eax
1181
        test    eax, eax
1165
        jns     first_app_found
1182
        jns     first_app_found
1166
 
1183
 
1167
        mov     esi, boot_failed
1184
        mov     esi, boot_failed
1168
        call    boot_log
1185
        call    boot_log
1169
 
1186
 
1170
        mov     eax, 0xDEADBEEF      ; otherwise halt
1187
        mov     eax, 0xDEADBEEF      ; otherwise halt
1171
        hlt
1188
        hlt
1172
 
1189
 
1173
first_app_found:
1190
first_app_found:
1174
 
1191
 
1175
; START MULTITASKING
1192
; START MULTITASKING
1176
 
1193
 
1177
; A 'All set - press ESC to start' messages if need
1194
; A 'All set - press ESC to start' messages if need
1178
if preboot_blogesc
1195
if preboot_blogesc
1179
        mov     esi, boot_tasking
1196
        mov     esi, boot_tasking
1180
        call    boot_log
1197
        call    boot_log
1181
.bll1:
1198
.bll1:
1182
        in      al, 0x60        ; wait for ESC key press
1199
        in      al, 0x60        ; wait for ESC key press
1183
        cmp     al, 129
1200
        cmp     al, 129
1184
        jne     .bll1
1201
        jne     .bll1
1185
end if
1202
end if
1186
 
1203
 
1187
        mov     [timer_ticks_enable], 1         ; for cd driver
1204
        mov     [timer_ticks_enable], 1         ; for cd driver
1188
 
1205
 
1189
        sti
1206
        sti
1190
 
1207
 
1191
        call    mtrr_validate
1208
        call    mtrr_validate
1192
 
1209
 
1193
        jmp     osloop
1210
        jmp     osloop
1194
 
1211
 
1195
 
1212
 
1196
        ; Fly :)
1213
        ; Fly :)
1197
 
1214
 
1198
uglobal
1215
uglobal
1199
align 4
1216
align 4
1200
ap_initialized  dd      0
1217
ap_initialized  dd      0
1201
endg
1218
endg
1202
 
1219
 
1203
ap_init_high:
1220
ap_init_high:
1204
        mov     ax, os_stack
1221
        mov     ax, os_stack
1205
        mov     bx, app_data
1222
        mov     bx, app_data
1206
        mov     cx, app_tls
1223
        mov     cx, app_tls
1207
        mov     ss, ax
1224
        mov     ss, ax
1208
        mov     ds, bx
1225
        mov     ds, bx
1209
        mov     es, bx
1226
        mov     es, bx
1210
        mov     fs, cx
1227
        mov     fs, cx
1211
        mov     gs, bx
1228
        mov     gs, bx
1212
        xor     esp, esp
1229
        xor     esp, esp
1213
        mov     eax, sys_proc-OS_BASE+PROC.pdt_0
1230
        mov     eax, sys_proc-OS_BASE+PROC.pdt_0
1214
        mov     cr3, eax
1231
        mov     cr3, eax
1215
        lock inc [ap_initialized]
1232
        lock inc [ap_initialized]
1216
        jmp     idle_loop
1233
        jmp     idle_loop
1217
 
1234
 
1218
 
1235
 
1219
include 'unpacker.inc'
1236
include 'unpacker.inc'
1220
 
1237
 
1221
align 4
1238
align 4
1222
boot_log:
1239
boot_log:
1223
        pushad
1240
        pushad
1224
 
1241
 
1225
        mov     ebx, 10*65536
1242
        mov     ebx, 10*65536
1226
        mov     bx, word [boot_y]
1243
        mov     bx, word [boot_y]
1227
        add     [boot_y], dword 10
1244
        add     [boot_y], dword 10
1228
        mov     ecx, 0x80ffffff; ASCIIZ string with white color
1245
        mov     ecx, 0x80ffffff; ASCIIZ string with white color
1229
        xor     edi, edi
1246
        xor     edi, edi
1230
        mov     edx, esi
1247
        mov     edx, esi
1231
        inc     edi
1248
        inc     edi
1232
        call    dtext
1249
        call    dtext
1233
 
1250
 
1234
        mov     [novesachecksum], 1000
1251
        mov     [novesachecksum], 1000
1235
        call    checkVga_N13
1252
        call    checkVga_N13
1236
 
1253
 
1237
        popad
1254
        popad
1238
 
1255
 
1239
        ret
1256
        ret
1240
 
1257
 
1241
; in: edx -> APPDATA for OS/IDLE slot
1258
; in: edx -> APPDATA for OS/IDLE slot
1242
; in: ebx = stack base
1259
; in: ebx = stack base
1243
proc setup_os_slot
1260
proc setup_os_slot
1244
        xor     eax, eax
1261
        xor     eax, eax
1245
        mov     ecx, 256/4
1262
        mov     ecx, 256/4
1246
        mov     edi, edx
1263
        mov     edi, edx
1247
        rep stosd
1264
        rep stosd
1248
 
1265
 
1249
        mov     eax, tss+0x80
1266
        mov     eax, tss+0x80
1250
        call    get_pg_addr
1267
        call    get_pg_addr
1251
        inc     eax
1268
        inc     eax
1252
        mov     [edx+APPDATA.io_map], eax
1269
        mov     [edx+APPDATA.io_map], eax
1253
        mov     eax, tss+0x1080
1270
        mov     eax, tss+0x1080
1254
        call    get_pg_addr
1271
        call    get_pg_addr
1255
        inc     eax
1272
        inc     eax
1256
        mov     [edx+APPDATA.io_map+4], eax
1273
        mov     [edx+APPDATA.io_map+4], eax
1257
 
1274
 
1258
        mov     dword [edx+APPDATA.pl0_stack], ebx
1275
        mov     dword [edx+APPDATA.pl0_stack], ebx
1259
        lea     edi, [ebx+0x2000-512]
1276
        lea     edi, [ebx+0x2000-512]
1260
        mov     dword [edx+APPDATA.fpu_state], edi
1277
        mov     dword [edx+APPDATA.fpu_state], edi
1261
        mov     dword [edx+APPDATA.saved_esp0], edi
1278
        mov     dword [edx+APPDATA.saved_esp0], edi
1262
        mov     dword [edx+APPDATA.saved_esp], edi
1279
        mov     dword [edx+APPDATA.saved_esp], edi
1263
        mov     dword [edx+APPDATA.terminate_protection], 1 ; make unkillable
1280
        mov     dword [edx+APPDATA.terminate_protection], 1 ; make unkillable
1264
 
1281
 
1265
        mov     esi, fpu_data
1282
        mov     esi, fpu_data
1266
        mov     ecx, 512/4
1283
        mov     ecx, 512/4
1267
        cld
1284
        cld
1268
        rep movsd
1285
        rep movsd
1269
 
1286
 
1270
        lea     eax, [edx+APP_OBJ_OFFSET]
1287
        lea     eax, [edx+APP_OBJ_OFFSET]
1271
        mov     dword [edx+APPDATA.fd_obj], eax
1288
        mov     dword [edx+APPDATA.fd_obj], eax
1272
        mov     dword [edx+APPDATA.bk_obj], eax
1289
        mov     dword [edx+APPDATA.bk_obj], eax
1273
 
1290
 
1274
        mov     dword [edx+APPDATA.cur_dir], sysdir_path
1291
        mov     dword [edx+APPDATA.cur_dir], sysdir_path
1275
 
1292
 
1276
        mov     [edx + APPDATA.process], sys_proc
1293
        mov     [edx + APPDATA.process], sys_proc
1277
 
1294
 
1278
        lea     ebx, [edx+APPDATA.list]
1295
        lea     ebx, [edx+APPDATA.list]
1279
        lea     ecx, [sys_proc+PROC.thr_list]
1296
        lea     ecx, [sys_proc+PROC.thr_list]
1280
        list_add_tail ebx, ecx
1297
        list_add_tail ebx, ecx
1281
 
1298
 
1282
        mov     eax, edx
1299
        mov     eax, edx
1283
        shr     eax, 3
1300
        shr     eax, 3
1284
        add     eax, CURRENT_TASK - (SLOT_BASE shr 3)
1301
        add     eax, CURRENT_TASK - (SLOT_BASE shr 3)
1285
        mov     [eax+TASKDATA.wnd_number], dh
1302
        mov     [eax+TASKDATA.wnd_number], dh
1286
        mov     byte [eax+TASKDATA.pid], dh
1303
        mov     byte [eax+TASKDATA.pid], dh
1287
 
1304
 
1288
        ret
1305
        ret
1289
endp
1306
endp
1290
 
1307
 
1291
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1308
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1292
;                                                                    ;
1309
;                                                                    ;
1293
;                    MAIN OS LOOP START                              ;
1310
;                    MAIN OS LOOP START                              ;
1294
;                                                                    ;
1311
;                                                                    ;
1295
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1312
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1296
align 32
1313
align 32
1297
osloop:
1314
osloop:
1298
        mov     edx, osloop_has_work?
1315
        mov     edx, osloop_has_work?
1299
        xor     ecx, ecx
1316
        xor     ecx, ecx
1300
        call    Wait_events
1317
        call    Wait_events
1301
        xor     eax, eax
1318
        xor     eax, eax
1302
        xchg    eax, [osloop_nonperiodic_work]
1319
        xchg    eax, [osloop_nonperiodic_work]
1303
        test    eax, eax
1320
        test    eax, eax
1304
        jz      .no_periodic
1321
        jz      .no_periodic
1305
 
1322
 
1306
        call    __sys_draw_pointer
1323
        call    __sys_draw_pointer
1307
        call    window_check_events
1324
        call    window_check_events
1308
        call    mouse_check_events
1325
        call    mouse_check_events
1309
        call    checkmisc
1326
        call    checkmisc
1310
        call    checkVga_N13
1327
        call    checkVga_N13
1311
;--------------------------------------
1328
;--------------------------------------
1312
.no_periodic:
1329
.no_periodic:
1313
        call    stack_handler
1330
        call    stack_handler
1314
        call    check_fdd_motor_status
1331
        call    check_fdd_motor_status
1315
        call    check_ATAPI_device_event
1332
        call    check_ATAPI_device_event
1316
        call    check_lights_state
1333
        call    check_lights_state
1317
        call    check_timers
1334
        call    check_timers
1318
 
1335
 
1319
        jmp     osloop
1336
        jmp     osloop
1320
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1337
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1321
;                                                                    ;
1338
;                                                                    ;
1322
;                      MAIN OS LOOP END                              ;
1339
;                      MAIN OS LOOP END                              ;
1323
;                                                                    ;
1340
;                                                                    ;
1324
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1341
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1325
proc osloop_has_work?
1342
proc osloop_has_work?
1326
        cmp     [osloop_nonperiodic_work], 0
1343
        cmp     [osloop_nonperiodic_work], 0
1327
        jnz     .yes
1344
        jnz     .yes
1328
        call    stack_handler_has_work?
1345
        call    stack_handler_has_work?
1329
        jnz     .yes
1346
        jnz     .yes
1330
        call    check_fdd_motor_status_has_work?
1347
        call    check_fdd_motor_status_has_work?
1331
        jnz     .yes
1348
        jnz     .yes
1332
        call    check_ATAPI_device_event_has_work?
1349
        call    check_ATAPI_device_event_has_work?
1333
        jnz     .yes
1350
        jnz     .yes
1334
        call    check_lights_state_has_work?
1351
        call    check_lights_state_has_work?
1335
        jnz     .yes
1352
        jnz     .yes
1336
        call    check_timers_has_work?
1353
        call    check_timers_has_work?
1337
        jnz     .yes
1354
        jnz     .yes
1338
.no:
1355
.no:
1339
        xor     eax, eax
1356
        xor     eax, eax
1340
        ret
1357
        ret
1341
.yes:
1358
.yes:
1342
        xor     eax, eax
1359
        xor     eax, eax
1343
        inc     eax
1360
        inc     eax
1344
        ret
1361
        ret
1345
endp
1362
endp
1346
 
1363
 
1347
proc wakeup_osloop
1364
proc wakeup_osloop
1348
        mov     [osloop_nonperiodic_work], 1
1365
        mov     [osloop_nonperiodic_work], 1
1349
        ret
1366
        ret
1350
endp
1367
endp
1351
 
1368
 
1352
uglobal
1369
uglobal
1353
align 4
1370
align 4
1354
osloop_nonperiodic_work dd      ?
1371
osloop_nonperiodic_work dd      ?
1355
endg
1372
endg
1356
 
1373
 
1357
uglobal
1374
uglobal
1358
align 64
1375
align 64
1359
idle_addr       rb      64
1376
idle_addr       rb      64
1360
endg
1377
endg
1361
 
1378
 
1362
idle_thread:
1379
idle_thread:
1363
        sti
1380
        sti
1364
 
1381
 
1365
; The following code can be executed by all CPUs in the system.
1382
; The following code can be executed by all CPUs in the system.
1366
; All other parts of the kernel do not expect multi-CPU.
1383
; All other parts of the kernel do not expect multi-CPU.
1367
; Also, APs don't even have a stack here.
1384
; Also, APs don't even have a stack here.
1368
; Beware. Don't do anything here. Anything at all.
1385
; Beware. Don't do anything here. Anything at all.
1369
idle_loop:
1386
idle_loop:
1370
        cmp     [use_mwait_for_idle], 0
1387
        cmp     [use_mwait_for_idle], 0
1371
        jnz     idle_loop_mwait
1388
        jnz     idle_loop_mwait
1372
 
1389
 
1373
idle_loop_hlt:
1390
idle_loop_hlt:
1374
        hlt
1391
        hlt
1375
        jmp     idle_loop_hlt
1392
        jmp     idle_loop_hlt
1376
 
1393
 
1377
idle_loop_mwait:
1394
idle_loop_mwait:
1378
        mov     eax, idle_addr
1395
        mov     eax, idle_addr
1379
        xor     ecx, ecx
1396
        xor     ecx, ecx
1380
        xor     edx, edx
1397
        xor     edx, edx
1381
        monitor
1398
        monitor
1382
        xor     ecx, ecx
1399
        xor     ecx, ecx
1383
        mov     eax, 20h        ; or 10h
1400
        mov     eax, 20h        ; or 10h
1384
        mwait
1401
        mwait
1385
        jmp     idle_loop_mwait
1402
        jmp     idle_loop_mwait
1386
 
1403
 
1387
 
1404
 
1388
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1405
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1389
;                                                                      ;
1406
;                                                                      ;
1390
;                   INCLUDED SYSTEM FILES                              ;
1407
;                   INCLUDED SYSTEM FILES                              ;
1391
;                                                                      ;
1408
;                                                                      ;
1392
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1409
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1393
 
1410
 
1394
 
1411
 
1395
include "kernel32.inc"
1412
include "kernel32.inc"
1396
 
1413
 
1397
 
1414
 
1398
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1415
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1399
;                                                                      ;
1416
;                                                                      ;
1400
;                       KERNEL FUNCTIONS                               ;
1417
;                       KERNEL FUNCTIONS                               ;
1401
;                                                                      ;
1418
;                                                                      ;
1402
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1419
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1403
 
1420
 
1404
reserve_irqs_ports:
1421
reserve_irqs_ports:
1405
 
1422
 
1406
 
1423
 
1407
; RESERVE PORTS
1424
; RESERVE PORTS
1408
        mov     eax, RESERVED_PORTS
1425
        mov     eax, RESERVED_PORTS
1409
        mov     ecx, 1
1426
        mov     ecx, 1
1410
 
1427
 
1411
        mov     [eax], dword 4
1428
        mov     [eax], dword 4
1412
 
1429
 
1413
        mov     [eax+16], ecx
1430
        mov     [eax+16], ecx
1414
        mov     [eax+16+4], dword 0
1431
        mov     [eax+16+4], dword 0
1415
        mov     [eax+16+8], dword 0x2D
1432
        mov     [eax+16+8], dword 0x2D
1416
 
1433
 
1417
        mov     [eax+32], ecx
1434
        mov     [eax+32], ecx
1418
        mov     [eax+32+4], dword 0x30
1435
        mov     [eax+32+4], dword 0x30
1419
        mov     [eax+32+8], dword 0x4D
1436
        mov     [eax+32+8], dword 0x4D
1420
 
1437
 
1421
        mov     [eax+48], ecx
1438
        mov     [eax+48], ecx
1422
        mov     [eax+48+4], dword 0x50
1439
        mov     [eax+48+4], dword 0x50
1423
        mov     [eax+48+8], dword 0xDF
1440
        mov     [eax+48+8], dword 0xDF
1424
 
1441
 
1425
        mov     [eax+64], ecx
1442
        mov     [eax+64], ecx
1426
        mov     [eax+64+4], dword 0xE5
1443
        mov     [eax+64+4], dword 0xE5
1427
        mov     [eax+64+8], dword 0xFF
1444
        mov     [eax+64+8], dword 0xFF
1428
 
1445
 
1429
        ret
1446
        ret
1430
 
1447
 
1431
 
1448
 
1432
iglobal
1449
iglobal
1433
  process_number dd 0x2
1450
  process_number dd 0x2
1434
endg
1451
endg
1435
 
1452
 
1436
set_variables:
1453
set_variables:
1437
 
1454
 
1438
        mov     ecx, 0x16                    ; flush port 0x60
1455
        mov     ecx, 0x16                    ; flush port 0x60
1439
.fl60:
1456
.fl60:
1440
        in      al, 0x60
1457
        in      al, 0x60
1441
        loop    .fl60
1458
        loop    .fl60
1442
        push    eax
1459
        push    eax
1443
 
1460
 
1444
        mov     ax, [BOOT_VARS+BOOT_Y_RES]
1461
        mov     ax, [BOOT_VARS+BOOT_Y_RES]
1445
        shr     ax, 1
1462
        shr     ax, 1
1446
        shl     eax, 16
1463
        shl     eax, 16
1447
        mov     ax, [BOOT_VARS+BOOT_X_RES]
1464
        mov     ax, [BOOT_VARS+BOOT_X_RES]
1448
        shr     ax, 1
1465
        shr     ax, 1
1449
        mov     [MOUSE_X], eax
1466
        mov     [MOUSE_X], eax
1450
        call    wakeup_osloop
1467
        call    wakeup_osloop
1451
 
1468
 
1452
        xor     eax, eax
1469
        xor     eax, eax
1453
        mov     [BTN_ADDR], dword BUTTON_INFO ; address of button list
1470
        mov     [BTN_ADDR], dword BUTTON_INFO ; address of button list
1454
 
1471
 
1455
        mov     byte [KEY_COUNT], al              ; keyboard buffer
1472
        mov     byte [KEY_COUNT], al              ; keyboard buffer
1456
        mov     byte [BTN_COUNT], al              ; button buffer
1473
        mov     byte [BTN_COUNT], al              ; button buffer
1457
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1474
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1458
 
1475
 
1459
        pop     eax
1476
        pop     eax
1460
        ret
1477
        ret
1461
 
1478
 
1462
align 4
1479
align 4
1463
;input  eax=43,bl-byte of output, ecx - number of port
1480
;input  eax=43,bl-byte of output, ecx - number of port
1464
sys_outport:
1481
sys_outport:
1465
 
1482
 
1466
        mov     edi, ecx   ; separate flag for read / write
1483
        mov     edi, ecx   ; separate flag for read / write
1467
        and     ecx, 65535
1484
        and     ecx, 65535
1468
 
1485
 
1469
        mov     eax, [RESERVED_PORTS]
1486
        mov     eax, [RESERVED_PORTS]
1470
        test    eax, eax
1487
        test    eax, eax
1471
        jnz     .sopl8
1488
        jnz     .sopl8
1472
        inc     eax
1489
        inc     eax
1473
        mov     [esp+32], eax
1490
        mov     [esp+32], eax
1474
        ret
1491
        ret
1475
 
1492
 
1476
  .sopl8:
1493
  .sopl8:
1477
        mov     edx, [TASK_BASE]
1494
        mov     edx, [TASK_BASE]
1478
        mov     edx, [edx+0x4]
1495
        mov     edx, [edx+0x4]
1479
    ;and   ecx,65535
1496
    ;and   ecx,65535
1480
    ;cld - set on interrupt 0x40
1497
    ;cld - set on interrupt 0x40
1481
  .sopl1:
1498
  .sopl1:
1482
 
1499
 
1483
        mov     esi, eax
1500
        mov     esi, eax
1484
        shl     esi, 4
1501
        shl     esi, 4
1485
        add     esi, RESERVED_PORTS
1502
        add     esi, RESERVED_PORTS
1486
        cmp     edx, [esi+0]
1503
        cmp     edx, [esi+0]
1487
        jne     .sopl2
1504
        jne     .sopl2
1488
        cmp     ecx, [esi+4]
1505
        cmp     ecx, [esi+4]
1489
        jb      .sopl2
1506
        jb      .sopl2
1490
        cmp     ecx, [esi+8]
1507
        cmp     ecx, [esi+8]
1491
        jg      .sopl2
1508
        jg      .sopl2
1492
.sopl3:
1509
.sopl3:
1493
 
1510
 
1494
        test    edi, 0x80000000; read ?
1511
        test    edi, 0x80000000; read ?
1495
        jnz     .sopl4
1512
        jnz     .sopl4
1496
 
1513
 
1497
        mov     eax, ebx
1514
        mov     eax, ebx
1498
        mov     dx, cx   ; write
1515
        mov     dx, cx   ; write
1499
        out     dx, al
1516
        out     dx, al
1500
        and     [esp+32], dword 0
1517
        and     [esp+32], dword 0
1501
        ret
1518
        ret
1502
 
1519
 
1503
        .sopl2:
1520
        .sopl2:
1504
 
1521
 
1505
        dec     eax
1522
        dec     eax
1506
        jnz     .sopl1
1523
        jnz     .sopl1
1507
        inc     eax
1524
        inc     eax
1508
        mov     [esp+32], eax
1525
        mov     [esp+32], eax
1509
        ret
1526
        ret
1510
 
1527
 
1511
 
1528
 
1512
  .sopl4:
1529
  .sopl4:
1513
 
1530
 
1514
        mov     dx, cx   ; read
1531
        mov     dx, cx   ; read
1515
        in      al, dx
1532
        in      al, dx
1516
        and     eax, 0xff
1533
        and     eax, 0xff
1517
        and     [esp+32], dword 0
1534
        and     [esp+32], dword 0
1518
        mov     [esp+20], eax
1535
        mov     [esp+20], eax
1519
        ret
1536
        ret
1520
 
1537
 
1521
display_number:
1538
display_number:
1522
;It is not optimization
1539
;It is not optimization
1523
        mov     eax, ebx
1540
        mov     eax, ebx
1524
        mov     ebx, ecx
1541
        mov     ebx, ecx
1525
        mov     ecx, edx
1542
        mov     ecx, edx
1526
        mov     edx, esi
1543
        mov     edx, esi
1527
        mov     esi, edi
1544
        mov     esi, edi
1528
; eax = print type, al=0 -> ebx is number
1545
; eax = print type, al=0 -> ebx is number
1529
;                   al=1 -> ebx is pointer
1546
;                   al=1 -> ebx is pointer
1530
;                   ah=0 -> display decimal
1547
;                   ah=0 -> display decimal
1531
;                   ah=1 -> display hexadecimal
1548
;                   ah=1 -> display hexadecimal
1532
;                   ah=2 -> display binary
1549
;                   ah=2 -> display binary
1533
;                   eax bits 16-21 = number of digits to display (0-32)
1550
;                   eax bits 16-21 = number of digits to display (0-32)
1534
;                   eax bits 22-31 = reserved
1551
;                   eax bits 22-31 = reserved
1535
;
1552
;
1536
; ebx = number or pointer
1553
; ebx = number or pointer
1537
; ecx = x shl 16 + y
1554
; ecx = x shl 16 + y
1538
; edx = color
1555
; edx = color
1539
        xor     edi, edi
1556
        xor     edi, edi
1540
display_number_force:
1557
display_number_force:
1541
        push    eax
1558
        push    eax
1542
        and     eax, 0x3fffffff
1559
        and     eax, 0x3fffffff
1543
        cmp     eax, 0xffff     ; length > 0 ?
1560
        cmp     eax, 0xffff     ; length > 0 ?
1544
        pop     eax
1561
        pop     eax
1545
        jge     cont_displ
1562
        jge     cont_displ
1546
        ret
1563
        ret
1547
   cont_displ:
1564
   cont_displ:
1548
        push    eax
1565
        push    eax
1549
        and     eax, 0x3fffffff
1566
        and     eax, 0x3fffffff
1550
        cmp     eax, 61*0x10000  ; length <= 60 ?
1567
        cmp     eax, 61*0x10000  ; length <= 60 ?
1551
        pop     eax
1568
        pop     eax
1552
        jb      cont_displ2
1569
        jb      cont_displ2
1553
        ret
1570
        ret
1554
   cont_displ2:
1571
   cont_displ2:
1555
 
1572
 
1556
        pushad
1573
        pushad
1557
 
1574
 
1558
        cmp     al, 1            ; ecx is a pointer ?
1575
        cmp     al, 1            ; ecx is a pointer ?
1559
        jne     displnl1
1576
        jne     displnl1
1560
        mov     ebp, ebx
1577
        mov     ebp, ebx
1561
        add     ebp, 4
1578
        add     ebp, 4
1562
        mov     ebp, [ebp+std_application_base_address]
1579
        mov     ebp, [ebp+std_application_base_address]
1563
        mov     ebx, [ebx+std_application_base_address]
1580
        mov     ebx, [ebx+std_application_base_address]
1564
 displnl1:
1581
 displnl1:
1565
        sub     esp, 64
1582
        sub     esp, 64
1566
 
1583
 
1567
        test    ah, ah            ; DECIMAL
1584
        test    ah, ah            ; DECIMAL
1568
        jnz     no_display_desnum
1585
        jnz     no_display_desnum
1569
        shr     eax, 16
1586
        shr     eax, 16
1570
        and     eax, 0xC03f
1587
        and     eax, 0xC03f
1571
;     and   eax,0x3f
1588
;     and   eax,0x3f
1572
        push    eax
1589
        push    eax
1573
        and     eax, 0x3f
1590
        and     eax, 0x3f
1574
        mov     edi, esp
1591
        mov     edi, esp
1575
        add     edi, 4+64-1
1592
        add     edi, 4+64-1
1576
        mov     ecx, eax
1593
        mov     ecx, eax
1577
        mov     eax, ebx
1594
        mov     eax, ebx
1578
        mov     ebx, 10
1595
        mov     ebx, 10
1579
 d_desnum:
1596
 d_desnum:
1580
        xor     edx, edx
1597
        xor     edx, edx
1581
        call    division_64_bits
1598
        call    division_64_bits
1582
        div     ebx
1599
        div     ebx
1583
        add     dl, 48
1600
        add     dl, 48
1584
        mov     [edi], dl
1601
        mov     [edi], dl
1585
        dec     edi
1602
        dec     edi
1586
        loop    d_desnum
1603
        loop    d_desnum
1587
        pop     eax
1604
        pop     eax
1588
        call    normalize_number
1605
        call    normalize_number
1589
        call    draw_num_text
1606
        call    draw_num_text
1590
        add     esp, 64
1607
        add     esp, 64
1591
        popad
1608
        popad
1592
        ret
1609
        ret
1593
   no_display_desnum:
1610
   no_display_desnum:
1594
 
1611
 
1595
        cmp     ah, 0x01         ; HEXADECIMAL
1612
        cmp     ah, 0x01         ; HEXADECIMAL
1596
        jne     no_display_hexnum
1613
        jne     no_display_hexnum
1597
        shr     eax, 16
1614
        shr     eax, 16
1598
        and     eax, 0xC03f
1615
        and     eax, 0xC03f
1599
;     and   eax,0x3f
1616
;     and   eax,0x3f
1600
        push    eax
1617
        push    eax
1601
        and     eax, 0x3f
1618
        and     eax, 0x3f
1602
        mov     edi, esp
1619
        mov     edi, esp
1603
        add     edi, 4+64-1
1620
        add     edi, 4+64-1
1604
        mov     ecx, eax
1621
        mov     ecx, eax
1605
        mov     eax, ebx
1622
        mov     eax, ebx
1606
        mov     ebx, 16
1623
        mov     ebx, 16
1607
   d_hexnum:
1624
   d_hexnum:
1608
        xor     edx, edx
1625
        xor     edx, edx
1609
        call    division_64_bits
1626
        call    division_64_bits
1610
        div     ebx
1627
        div     ebx
1611
   hexletters = __fdo_hexdigits
1628
   hexletters = __fdo_hexdigits
1612
        add     edx, hexletters
1629
        add     edx, hexletters
1613
        mov     dl, [edx]
1630
        mov     dl, [edx]
1614
        mov     [edi], dl
1631
        mov     [edi], dl
1615
        dec     edi
1632
        dec     edi
1616
        loop    d_hexnum
1633
        loop    d_hexnum
1617
        pop     eax
1634
        pop     eax
1618
        call    normalize_number
1635
        call    normalize_number
1619
        call    draw_num_text
1636
        call    draw_num_text
1620
        add     esp, 64
1637
        add     esp, 64
1621
        popad
1638
        popad
1622
        ret
1639
        ret
1623
   no_display_hexnum:
1640
   no_display_hexnum:
1624
 
1641
 
1625
        cmp     ah, 0x02         ; BINARY
1642
        cmp     ah, 0x02         ; BINARY
1626
        jne     no_display_binnum
1643
        jne     no_display_binnum
1627
        shr     eax, 16
1644
        shr     eax, 16
1628
        and     eax, 0xC03f
1645
        and     eax, 0xC03f
1629
;     and   eax,0x3f
1646
;     and   eax,0x3f
1630
        push    eax
1647
        push    eax
1631
        and     eax, 0x3f
1648
        and     eax, 0x3f
1632
        mov     edi, esp
1649
        mov     edi, esp
1633
        add     edi, 4+64-1
1650
        add     edi, 4+64-1
1634
        mov     ecx, eax
1651
        mov     ecx, eax
1635
        mov     eax, ebx
1652
        mov     eax, ebx
1636
        mov     ebx, 2
1653
        mov     ebx, 2
1637
   d_binnum:
1654
   d_binnum:
1638
        xor     edx, edx
1655
        xor     edx, edx
1639
        call    division_64_bits
1656
        call    division_64_bits
1640
        div     ebx
1657
        div     ebx
1641
        add     dl, 48
1658
        add     dl, 48
1642
        mov     [edi], dl
1659
        mov     [edi], dl
1643
        dec     edi
1660
        dec     edi
1644
        loop    d_binnum
1661
        loop    d_binnum
1645
        pop     eax
1662
        pop     eax
1646
        call    normalize_number
1663
        call    normalize_number
1647
        call    draw_num_text
1664
        call    draw_num_text
1648
        add     esp, 64
1665
        add     esp, 64
1649
        popad
1666
        popad
1650
        ret
1667
        ret
1651
   no_display_binnum:
1668
   no_display_binnum:
1652
 
1669
 
1653
        add     esp, 64
1670
        add     esp, 64
1654
        popad
1671
        popad
1655
        ret
1672
        ret
1656
 
1673
 
1657
normalize_number:
1674
normalize_number:
1658
        test    ah, 0x80
1675
        test    ah, 0x80
1659
        jz      .continue
1676
        jz      .continue
1660
        mov     ecx, 48
1677
        mov     ecx, 48
1661
        and     eax, 0x3f
1678
        and     eax, 0x3f
1662
@@:
1679
@@:
1663
        inc     edi
1680
        inc     edi
1664
        cmp     [edi], cl
1681
        cmp     [edi], cl
1665
        jne     .continue
1682
        jne     .continue
1666
        dec     eax
1683
        dec     eax
1667
        cmp     eax, 1
1684
        cmp     eax, 1
1668
        ja      @r
1685
        ja      @r
1669
        mov     al, 1
1686
        mov     al, 1
1670
.continue:
1687
.continue:
1671
        and     eax, 0x3f
1688
        and     eax, 0x3f
1672
        ret
1689
        ret
1673
 
1690
 
1674
division_64_bits:
1691
division_64_bits:
1675
        test    [esp+1+4], byte 0x40
1692
        test    [esp+1+4], byte 0x40
1676
        jz      .continue
1693
        jz      .continue
1677
        push    eax
1694
        push    eax
1678
        mov     eax, ebp
1695
        mov     eax, ebp
1679
        div     ebx
1696
        div     ebx
1680
        mov     ebp, eax
1697
        mov     ebp, eax
1681
        pop     eax
1698
        pop     eax
1682
.continue:
1699
.continue:
1683
        ret
1700
        ret
1684
 
1701
 
1685
draw_num_text:
1702
draw_num_text:
1686
        mov     esi, eax
1703
        mov     esi, eax
1687
        mov     edx, 64+4
1704
        mov     edx, 64+4
1688
        sub     edx, eax
1705
        sub     edx, eax
1689
        add     edx, esp
1706
        add     edx, esp
1690
        mov     ebx, [esp+64+32-8+4]
1707
        mov     ebx, [esp+64+32-8+4]
1691
; add window start x & y
1708
; add window start x & y
1692
        mov     ecx, [TASK_BASE]
1709
        mov     ecx, [TASK_BASE]
1693
 
1710
 
1694
        mov     edi, [CURRENT_TASK]
1711
        mov     edi, [CURRENT_TASK]
1695
        shl     edi, 8
1712
        shl     edi, 8
1696
 
1713
 
1697
        mov     eax, [ecx-twdw+WDATA.box.left]
1714
        mov     eax, [ecx-twdw+WDATA.box.left]
1698
        add     eax, [edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1715
        add     eax, [edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1699
        shl     eax, 16
1716
        shl     eax, 16
1700
        add     eax, [ecx-twdw+WDATA.box.top]
1717
        add     eax, [ecx-twdw+WDATA.box.top]
1701
        add     eax, [edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1718
        add     eax, [edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1702
        add     ebx, eax
1719
        add     ebx, eax
1703
        mov     ecx, [esp+64+32-12+4]
1720
        mov     ecx, [esp+64+32-12+4]
1704
        and     ecx, not 0x80000000     ; force counted string
1721
        and     ecx, not 0x80000000     ; force counted string
1705
        mov     eax, [esp+64+8]         ; background color (if given)
1722
        mov     eax, [esp+64+8]         ; background color (if given)
1706
        mov     edi, [esp+64+4]
1723
        mov     edi, [esp+64+4]
1707
        jmp     dtext
1724
        jmp     dtext
1708
;-----------------------------------------------------------------------------
1725
;-----------------------------------------------------------------------------
1709
iglobal
1726
iglobal
1710
midi_base dw 0
1727
midi_base dw 0
1711
endg
1728
endg
1712
;-----------------------------------------------------------------------------
1729
;-----------------------------------------------------------------------------
1713
align 4
1730
align 4
1714
sys_setup:
1731
sys_setup:
1715
;  1 = roland mpu midi base , base io address
1732
;  1 = roland mpu midi base , base io address
1716
;  2 = keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1733
;  2 = keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1717
;  3 = not used
1734
;  3 = not used
1718
;  4 = not used
1735
;  4 = not used
1719
;  5 = system language, 1eng 2fi 3ger 4rus
1736
;  5 = system language, 1eng 2fi 3ger 4rus
1720
;  6 = not used
1737
;  6 = not used
1721
;  7 = not used
1738
;  7 = not used
1722
;  8 = not used
1739
;  8 = not used
1723
;  9 = not used
1740
;  9 = not used
1724
; 10 = not used
1741
; 10 = not used
1725
; 11 = enable lba read
1742
; 11 = enable lba read
1726
; 12 = enable pci access
1743
; 12 = enable pci access
1727
;-----------------------------------------------------------------------------
1744
;-----------------------------------------------------------------------------
1728
        and     [esp+32], dword 0
1745
        and     [esp+32], dword 0
1729
; F.21.1 - set MPU MIDI base port
1746
; F.21.1 - set MPU MIDI base port
1730
        dec     ebx
1747
        dec     ebx
1731
        jnz     @f
1748
        jnz     @f
1732
 
1749
 
1733
        cmp     ecx, 0x100
1750
        cmp     ecx, 0x100
1734
        jb      @f
1751
        jb      @f
1735
 
1752
 
1736
        mov     esi, 65535
1753
        mov     esi, 65535
1737
        cmp     esi, ecx
1754
        cmp     esi, ecx
1738
        jb      @f
1755
        jb      @f
1739
 
1756
 
1740
        mov     [midi_base], cx
1757
        mov     [midi_base], cx
1741
        mov     word [mididp], cx
1758
        mov     word [mididp], cx
1742
        inc     cx
1759
        inc     cx
1743
        mov     word [midisp], cx
1760
        mov     word [midisp], cx
1744
        ret
1761
        ret
1745
;--------------------------------------
1762
;--------------------------------------
1746
@@:
1763
@@:
1747
; F.21.2 - set keyboard layout
1764
; F.21.2 - set keyboard layout
1748
        dec     ebx
1765
        dec     ebx
1749
        jnz     @f
1766
        jnz     @f
1750
 
1767
 
1751
        mov     edi, [TASK_BASE]
1768
        mov     edi, [TASK_BASE]
1752
        mov     eax, [edi+TASKDATA.mem_start]
1769
        mov     eax, [edi+TASKDATA.mem_start]
1753
        add     eax, edx
1770
        add     eax, edx
1754
; 1 = normal layout
1771
; 1 = normal layout
1755
        dec     ecx
1772
        dec     ecx
1756
        jnz     .shift
1773
        jnz     .shift
1757
 
1774
 
1758
        mov     ebx, keymap
1775
        mov     ebx, keymap
1759
        mov     ecx, 128
1776
        mov     ecx, 128
1760
        call    memmove
1777
        call    memmove
1761
        ret
1778
        ret
1762
;--------------------------------------
1779
;--------------------------------------
1763
.shift:
1780
.shift:
1764
; 2 = layout at pressed Shift
1781
; 2 = layout at pressed Shift
1765
        dec     ecx
1782
        dec     ecx
1766
        jnz     .alt
1783
        jnz     .alt
1767
 
1784
 
1768
        mov     ebx, keymap_shift
1785
        mov     ebx, keymap_shift
1769
        mov     ecx, 128
1786
        mov     ecx, 128
1770
        call    memmove
1787
        call    memmove
1771
        ret
1788
        ret
1772
;--------------------------------------
1789
;--------------------------------------
1773
.alt:
1790
.alt:
1774
; 3 = layout at pressed Alt
1791
; 3 = layout at pressed Alt
1775
        dec     ecx
1792
        dec     ecx
1776
        jnz     .country
1793
        jnz     .country
1777
 
1794
 
1778
        mov     ebx, keymap_alt
1795
        mov     ebx, keymap_alt
1779
        mov     ecx, 128
1796
        mov     ecx, 128
1780
        call    memmove
1797
        call    memmove
1781
        ret
1798
        ret
1782
;--------------------------------------
1799
;--------------------------------------
1783
.country:
1800
.country:
1784
; country identifier
1801
; country identifier
1785
        sub     ecx, 6
1802
        sub     ecx, 6
1786
        jnz     .error
1803
        jnz     .error
1787
 
1804
 
1788
        mov     word [keyboard], dx
1805
        mov     word [keyboard], dx
1789
        ret
1806
        ret
1790
;--------------------------------------
1807
;--------------------------------------
1791
@@:
1808
@@:
1792
; F.21.5 - set system language
1809
; F.21.5 - set system language
1793
        sub     ebx, 3
1810
        sub     ebx, 3
1794
        jnz     @f
1811
        jnz     @f
1795
 
1812
 
1796
        mov     [syslang], ecx
1813
        mov     [syslang], ecx
1797
        ret
1814
        ret
1798
;--------------------------------------
1815
;--------------------------------------
1799
@@:
1816
@@:
1800
; F.21.11 - enable/disable low-level access to HD
1817
; F.21.11 - enable/disable low-level access to HD
1801
        and     ecx, 1
1818
        and     ecx, 1
1802
        sub     ebx, 6
1819
        sub     ebx, 6
1803
        jnz     @f
1820
        jnz     @f
1804
 
1821
 
1805
        mov     [lba_read_enabled], ecx
1822
        mov     [lba_read_enabled], ecx
1806
        ret
1823
        ret
1807
;--------------------------------------
1824
;--------------------------------------
1808
@@:
1825
@@:
1809
; F.21.12 - enable/disable low-level access to PCI
1826
; F.21.12 - enable/disable low-level access to PCI
1810
        dec     ebx
1827
        dec     ebx
1811
        jnz     .error
1828
        jnz     .error
1812
 
1829
 
1813
        mov     [pci_access_enabled], ecx
1830
        mov     [pci_access_enabled], ecx
1814
        ret
1831
        ret
1815
;--------------------------------------
1832
;--------------------------------------
1816
.error:
1833
.error:
1817
        or      [esp+32], dword -1
1834
        or      [esp+32], dword -1
1818
        ret
1835
        ret
1819
;-----------------------------------------------------------------------------
1836
;-----------------------------------------------------------------------------
1820
align 4
1837
align 4
1821
sys_getsetup:
1838
sys_getsetup:
1822
;  1 = roland mpu midi base , base io address
1839
;  1 = roland mpu midi base , base io address
1823
;  2 = keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1840
;  2 = keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1824
;  3 = not used
1841
;  3 = not used
1825
;  4 = not used
1842
;  4 = not used
1826
;  5 = system language, 1eng 2fi 3ger 4rus
1843
;  5 = system language, 1eng 2fi 3ger 4rus
1827
;  6 = not used
1844
;  6 = not used
1828
;  7 = not used
1845
;  7 = not used
1829
;  8 = not used
1846
;  8 = not used
1830
;  9 = get hs timer tic
1847
;  9 = get hs timer tic
1831
; 10 = not used
1848
; 10 = not used
1832
; 11 = get the state "lba read"
1849
; 11 = get the state "lba read"
1833
; 12 = get the state "pci access"
1850
; 12 = get the state "pci access"
1834
;-----------------------------------------------------------------------------
1851
;-----------------------------------------------------------------------------
1835
; F.26.1 - get MPU MIDI base port
1852
; F.26.1 - get MPU MIDI base port
1836
        dec     ebx
1853
        dec     ebx
1837
        jnz     @f
1854
        jnz     @f
1838
 
1855
 
1839
        movzx   eax, [midi_base]
1856
        movzx   eax, [midi_base]
1840
        mov     [esp+32], eax
1857
        mov     [esp+32], eax
1841
        ret
1858
        ret
1842
;--------------------------------------
1859
;--------------------------------------
1843
@@:
1860
@@:
1844
; F.26.2 - get keyboard layout
1861
; F.26.2 - get keyboard layout
1845
        dec     ebx
1862
        dec     ebx
1846
        jnz     @f
1863
        jnz     @f
1847
 
1864
 
1848
        mov     edi, [TASK_BASE]
1865
        mov     edi, [TASK_BASE]
1849
        mov     ebx, [edi+TASKDATA.mem_start]
1866
        mov     ebx, [edi+TASKDATA.mem_start]
1850
        add     ebx, edx
1867
        add     ebx, edx
1851
; 1 = normal layout
1868
; 1 = normal layout
1852
        dec     ecx
1869
        dec     ecx
1853
        jnz     .shift
1870
        jnz     .shift
1854
 
1871
 
1855
        mov     eax, keymap
1872
        mov     eax, keymap
1856
        mov     ecx, 128
1873
        mov     ecx, 128
1857
        call    memmove
1874
        call    memmove
1858
        ret
1875
        ret
1859
;--------------------------------------
1876
;--------------------------------------
1860
.shift:
1877
.shift:
1861
; 2 = layout with pressed Shift
1878
; 2 = layout with pressed Shift
1862
        dec     ecx
1879
        dec     ecx
1863
        jnz     .alt
1880
        jnz     .alt
1864
 
1881
 
1865
        mov     eax, keymap_shift
1882
        mov     eax, keymap_shift
1866
        mov     ecx, 128
1883
        mov     ecx, 128
1867
        call    memmove
1884
        call    memmove
1868
        ret
1885
        ret
1869
;--------------------------------------
1886
;--------------------------------------
1870
.alt:
1887
.alt:
1871
; 3 = layout with pressed Alt
1888
; 3 = layout with pressed Alt
1872
        dec     ecx
1889
        dec     ecx
1873
        jne     .country
1890
        jne     .country
1874
 
1891
 
1875
        mov     eax, keymap_alt
1892
        mov     eax, keymap_alt
1876
        mov     ecx, 128
1893
        mov     ecx, 128
1877
        call    memmove
1894
        call    memmove
1878
        ret
1895
        ret
1879
;--------------------------------------
1896
;--------------------------------------
1880
.country:
1897
.country:
1881
; 9 = country identifier
1898
; 9 = country identifier
1882
        sub     ecx, 6
1899
        sub     ecx, 6
1883
        jnz     .error
1900
        jnz     .error
1884
 
1901
 
1885
        movzx   eax, word [keyboard]
1902
        movzx   eax, word [keyboard]
1886
        mov     [esp+32], eax
1903
        mov     [esp+32], eax
1887
        ret
1904
        ret
1888
;--------------------------------------
1905
;--------------------------------------
1889
@@:
1906
@@:
1890
; F.26.5 - get system language
1907
; F.26.5 - get system language
1891
        sub     ebx, 3
1908
        sub     ebx, 3
1892
        jnz     @f
1909
        jnz     @f
1893
 
1910
 
1894
        mov     eax, [syslang]
1911
        mov     eax, [syslang]
1895
        mov     [esp+32], eax
1912
        mov     [esp+32], eax
1896
        ret
1913
        ret
1897
;--------------------------------------
1914
;--------------------------------------
1898
@@:
1915
@@:
1899
; F.26.9 - get the value of the time counter
1916
; F.26.9 - get the value of the time counter
1900
        sub     ebx, 4
1917
        sub     ebx, 4
1901
        jnz     @f
1918
        jnz     @f
1902
 
1919
 
1903
        mov     eax, [timer_ticks]
1920
        mov     eax, [timer_ticks]
1904
        mov     [esp+32], eax
1921
        mov     [esp+32], eax
1905
        ret
1922
        ret
1906
;--------------------------------------
1923
;--------------------------------------
1907
@@:
1924
@@:
-
 
1925
; F.26.10 - get the time from kernel launch in nanoseconds
-
 
1926
        sub     ebx, 1
-
 
1927
        jnz     @f
-
 
1928
 
-
 
1929
        call    get_clock_ns
-
 
1930
        mov     [esp+24], edx
-
 
1931
        mov     [esp+32], eax
-
 
1932
        ret
-
 
1933
;--------------------------------------
-
 
1934
@@:
1908
; F.26.11 - Find out whether low-level HD access is enabled
1935
; F.26.11 - Find out whether low-level HD access is enabled
1909
        sub     ebx, 2
1936
        sub     ebx, 1
1910
        jnz     @f
1937
        jnz     @f
1911
 
1938
 
1912
        mov     eax, [lba_read_enabled]
1939
        mov     eax, [lba_read_enabled]
1913
        mov     [esp+32], eax
1940
        mov     [esp+32], eax
1914
        ret
1941
        ret
1915
;--------------------------------------
1942
;--------------------------------------
1916
@@:
1943
@@:
1917
; F.26.12 - Find out whether low-level PCI access is enabled
1944
; F.26.12 - Find out whether low-level PCI access is enabled
1918
        dec     ebx
1945
        dec     ebx
1919
        jnz     .error
1946
        jnz     .error
1920
 
1947
 
1921
        mov     eax, [pci_access_enabled]
1948
        mov     eax, [pci_access_enabled]
1922
        mov     [esp+32], eax
1949
        mov     [esp+32], eax
1923
        ret
1950
        ret
1924
;--------------------------------------
1951
;--------------------------------------
1925
.error:
1952
.error:
1926
        or      [esp+32], dword -1
1953
        or      [esp+32], dword -1
1927
        ret
1954
        ret
1928
;-----------------------------------------------------------------------------
1955
;-----------------------------------------------------------------------------
1929
get_timer_ticks:
1956
get_timer_ticks:
1930
        mov     eax, [timer_ticks]
1957
        mov     eax, [timer_ticks]
1931
        ret
1958
        ret
1932
;-----------------------------------------------------------------------------
1959
;-----------------------------------------------------------------------------
1933
iglobal
1960
iglobal
1934
align 4
1961
align 4
1935
mousefn dd msscreen, mswin, msbutton, msset
1962
mousefn dd msscreen
-
 
1963
        dd mswin
-
 
1964
        dd msbutton
-
 
1965
        dd msbuttonExt
1936
        dd app_load_cursor
1966
        dd app_load_cursor
1937
        dd app_set_cursor
1967
        dd app_set_cursor
1938
        dd app_delete_cursor
1968
        dd app_delete_cursor
1939
        dd msz
1969
        dd msz
1940
endg
1970
endg
1941
;-----------------------------------------------------------------------------
1971
;-----------------------------------------------------------------------------
1942
readmousepos:
1972
readmousepos:
1943
 
1973
 
1944
; eax=0 screen relative
1974
; eax=0 screen relative
1945
; eax=1 window relative
1975
; eax=1 window relative
1946
; eax=2 buttons pressed
1976
; eax=2 buttons pressed
1947
; eax=3 set mouse pos   ; reserved
1977
; eax=3 buttons pressed ext
1948
; eax=4 load cursor
1978
; eax=4 load cursor
1949
; eax=5 set cursor
1979
; eax=5 set cursor
1950
; eax=6 delete cursor   ; reserved
1980
; eax=6 delete cursor
1951
; eax=7 get mouse_z
1981
; eax=7 get mouse_z
1952
 
1982
 
1953
        cmp     ebx, 7
1983
        cmp     ebx, 7
1954
        ja      msset
1984
        ja      @f
1955
        jmp     [mousefn+ebx*4]
1985
        jmp     [mousefn+ebx*4]
-
 
1986
 
1956
msscreen:
1987
msscreen:
1957
        mov     eax, [MOUSE_X]
1988
        mov     eax, [MOUSE_X]
1958
        shl     eax, 16
1989
        shl     eax, 16
1959
        mov     ax, [MOUSE_Y]
1990
        mov     ax, [MOUSE_Y]
1960
        mov     [esp+36-4], eax
1991
        mov     [esp+36-4], eax
-
 
1992
@@:
1961
        ret
1993
        ret
-
 
1994
 
1962
mswin:
1995
mswin:
1963
        mov     eax, [MOUSE_X]
1996
        mov     eax, [MOUSE_X]
1964
        shl     eax, 16
1997
        shl     eax, 16
1965
        mov     ax, [MOUSE_Y]
1998
        mov     ax, [MOUSE_Y]
1966
        mov     esi, [TASK_BASE]
1999
        mov     esi, [TASK_BASE]
1967
        mov     bx, word [esi-twdw+WDATA.box.left]
2000
        mov     bx, word [esi-twdw+WDATA.box.left]
1968
        shl     ebx, 16
2001
        shl     ebx, 16
1969
        mov     bx, word [esi-twdw+WDATA.box.top]
2002
        mov     bx, word [esi-twdw+WDATA.box.top]
1970
        sub     eax, ebx
2003
        sub     eax, ebx
1971
 
-
 
1972
        mov     edi, [CURRENT_TASK]
2004
        mov     edi, [CURRENT_TASK]
1973
        shl     edi, 8
2005
        shl     edi, 8
1974
        sub     ax, word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
2006
        sub     ax, word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1975
        rol     eax, 16
2007
        rol     eax, 16
1976
        sub     ax, word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
2008
        sub     ax, word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1977
        rol     eax, 16
2009
        rol     eax, 16
1978
        mov     [esp+36-4], eax
2010
        mov     [esp+36-4], eax
1979
        ret
2011
        ret
-
 
2012
 
1980
msbutton:
2013
msbutton:
1981
        movzx   eax, byte [BTN_DOWN]
2014
        movzx   eax, byte [BTN_DOWN]
1982
        mov     [esp+36-4], eax
2015
        mov     [esp+36-4], eax
1983
        ret
2016
        ret
1984
msz:
2017
 
1985
        mov     edi, [TASK_COUNT]
-
 
1986
        movzx   edi, word [WIN_POS + edi*2]
-
 
1987
        cmp     edi, [CURRENT_TASK]
-
 
1988
        jne     @f
2018
msbuttonExt:
1989
        mov     ax, [MOUSE_SCROLL_H]
-
 
1990
        shl     eax, 16
-
 
1991
        mov     ax, [MOUSE_SCROLL_V]
2019
        mov     eax, [BTN_DOWN]
1992
        mov     [esp+36-4], eax
2020
        mov     [esp+36-4], eax
1993
        and     [MOUSE_SCROLL_H], word 0
-
 
1994
        and     [MOUSE_SCROLL_V], word 0
-
 
1995
        ret
-
 
1996
       @@:
-
 
1997
        and     [esp+36-4], dword 0
-
 
1998
;           ret
-
 
1999
msset:
-
 
2000
        ret
2021
        ret
2001
 
2022
 
2002
app_load_cursor:
2023
app_load_cursor:
2003
        cmp     ecx, OS_BASE
2024
        cmp     ecx, OS_BASE
2004
        jae     msset
2025
        jae     @f
2005
        stdcall load_cursor, ecx, edx
2026
        stdcall load_cursor, ecx, edx
2006
        mov     [esp+36-4], eax
2027
        mov     [esp+36-4], eax
-
 
2028
@@:
2007
        ret
2029
        ret
2008
 
2030
 
2009
app_set_cursor:
2031
app_set_cursor:
2010
        stdcall set_cursor, ecx
2032
        stdcall set_cursor, ecx
2011
        mov     [esp+36-4], eax
2033
        mov     [esp+36-4], eax
2012
        ret
2034
        ret
2013
 
2035
 
2014
app_delete_cursor:
2036
app_delete_cursor:
2015
        stdcall delete_cursor, ecx
2037
        stdcall delete_cursor, ecx
2016
        mov     [esp+36-4], eax
2038
        mov     [esp+36-4], eax
2017
        ret
2039
        ret
-
 
2040
 
-
 
2041
msz:
-
 
2042
        mov     edi, [TASK_COUNT]
-
 
2043
        movzx   edi, word [WIN_POS + edi*2]
-
 
2044
        cmp     edi, [CURRENT_TASK]
-
 
2045
        jne     @f
-
 
2046
        mov     ax, [MOUSE_SCROLL_H]
-
 
2047
        shl     eax, 16
-
 
2048
        mov     ax, [MOUSE_SCROLL_V]
-
 
2049
        mov     [esp+36-4], eax
-
 
2050
        and     [MOUSE_SCROLL_H], word 0
-
 
2051
        and     [MOUSE_SCROLL_V], word 0
-
 
2052
        ret
-
 
2053
@@:
-
 
2054
        and     [esp+36-4], dword 0
-
 
2055
        ret
2018
 
2056
 
2019
is_input:
2057
is_input:
2020
 
2058
 
2021
        push    edx
2059
        push    edx
2022
        mov     dx, word [midisp]
2060
        mov     dx, word [midisp]
2023
        in      al, dx
2061
        in      al, dx
2024
        and     al, 0x80
2062
        and     al, 0x80
2025
        pop     edx
2063
        pop     edx
2026
        ret
2064
        ret
2027
 
2065
 
2028
is_output:
2066
is_output:
2029
 
2067
 
2030
        push    edx
2068
        push    edx
2031
        mov     dx, word [midisp]
2069
        mov     dx, word [midisp]
2032
        in      al, dx
2070
        in      al, dx
2033
        and     al, 0x40
2071
        and     al, 0x40
2034
        pop     edx
2072
        pop     edx
2035
        ret
2073
        ret
2036
 
2074
 
2037
 
2075
 
2038
get_mpu_in:
2076
get_mpu_in:
2039
 
2077
 
2040
        push    edx
2078
        push    edx
2041
        mov     dx, word [mididp]
2079
        mov     dx, word [mididp]
2042
        in      al, dx
2080
        in      al, dx
2043
        pop     edx
2081
        pop     edx
2044
        ret
2082
        ret
2045
 
2083
 
2046
 
2084
 
2047
put_mpu_out:
2085
put_mpu_out:
2048
 
2086
 
2049
        push    edx
2087
        push    edx
2050
        mov     dx, word [mididp]
2088
        mov     dx, word [mididp]
2051
        out     dx, al
2089
        out     dx, al
2052
        pop     edx
2090
        pop     edx
2053
        ret
2091
        ret
2054
 
2092
 
2055
 
2093
 
2056
 
2094
 
2057
align 4
2095
align 4
2058
 
2096
 
2059
sys_midi:
2097
sys_midi:
2060
        cmp     [mididp], 0
2098
        cmp     [mididp], 0
2061
        jnz     sm0
2099
        jnz     sm0
2062
        mov     [esp+36], dword 1
2100
        mov     [esp+36], dword 1
2063
        ret
2101
        ret
2064
sm0:
2102
sm0:
2065
        and     [esp+36], dword 0
2103
        and     [esp+36], dword 0
2066
        dec     ebx
2104
        dec     ebx
2067
        jnz     smn1
2105
        jnz     smn1
2068
 ;    call setuart
2106
 ;    call setuart
2069
su1:
2107
su1:
2070
        call    is_output
2108
        call    is_output
2071
        test    al, al
2109
        test    al, al
2072
        jnz     su1
2110
        jnz     su1
2073
        mov     dx, word [midisp]
2111
        mov     dx, word [midisp]
2074
        mov     al, 0xff
2112
        mov     al, 0xff
2075
        out     dx, al
2113
        out     dx, al
2076
su2:
2114
su2:
2077
        mov     dx, word [midisp]
2115
        mov     dx, word [midisp]
2078
        mov     al, 0xff
2116
        mov     al, 0xff
2079
        out     dx, al
2117
        out     dx, al
2080
        call    is_input
2118
        call    is_input
2081
        test    al, al
2119
        test    al, al
2082
        jnz     su2
2120
        jnz     su2
2083
        call    get_mpu_in
2121
        call    get_mpu_in
2084
        cmp     al, 0xfe
2122
        cmp     al, 0xfe
2085
        jnz     su2
2123
        jnz     su2
2086
su3:
2124
su3:
2087
        call    is_output
2125
        call    is_output
2088
        test    al, al
2126
        test    al, al
2089
        jnz     su3
2127
        jnz     su3
2090
        mov     dx, word [midisp]
2128
        mov     dx, word [midisp]
2091
        mov     al, 0x3f
2129
        mov     al, 0x3f
2092
        out     dx, al
2130
        out     dx, al
2093
        ret
2131
        ret
2094
smn1:
2132
smn1:
2095
        dec     ebx
2133
        dec     ebx
2096
        jnz     smn2
2134
        jnz     smn2
2097
sm10:
2135
sm10:
2098
        call    get_mpu_in
2136
        call    get_mpu_in
2099
        call    is_output
2137
        call    is_output
2100
        test    al, al
2138
        test    al, al
2101
        jnz     sm10
2139
        jnz     sm10
2102
        mov     al, bl
2140
        mov     al, bl
2103
        call    put_mpu_out
2141
        call    put_mpu_out
2104
        smn2:
2142
        smn2:
2105
        ret
2143
        ret
2106
 
2144
 
2107
detect_devices:
2145
detect_devices:
2108
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2146
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2109
;include 'detect/commouse.inc'
2147
;include 'detect/commouse.inc'
2110
;include 'detect/ps2mouse.inc'
2148
;include 'detect/ps2mouse.inc'
2111
;include 'detect/dev_fd.inc'
2149
;include 'detect/dev_fd.inc'
2112
;include 'detect/dev_hdcd.inc'
2150
;include 'detect/dev_hdcd.inc'
2113
;include 'detect/sear_par.inc'
2151
;include 'detect/sear_par.inc'
2114
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2152
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2115
        ret
2153
        ret
2116
 
2154
 
2117
sys_end:
2155
sys_end:
2118
;--------------------------------------
2156
;--------------------------------------
2119
        cmp     [_display.select_cursor], 0
2157
        cmp     [_display.select_cursor], 0
2120
        je      @f
2158
        je      @f
2121
; restore default cursor before killing
2159
; restore default cursor before killing
2122
        pusha
2160
        pusha
2123
        mov     ecx, [current_slot]
2161
        mov     ecx, [current_slot]
2124
        call    restore_default_cursor_before_killing
2162
        call    restore_default_cursor_before_killing
2125
        popa
2163
        popa
2126
@@:
2164
@@:
2127
;--------------------------------------
2165
;--------------------------------------
2128
; kill all sockets this process owns
2166
; kill all sockets this process owns
2129
        pusha
2167
        pusha
2130
        mov     edx, [TASK_BASE]
2168
        mov     edx, [TASK_BASE]
2131
        mov     edx, [edx+TASKDATA.pid]
2169
        mov     edx, [edx+TASKDATA.pid]
2132
        call    SOCKET_process_end
2170
        call    SOCKET_process_end
2133
        popa
2171
        popa
2134
;--------------------------------------
2172
;--------------------------------------
2135
        mov     ecx, [current_slot]
2173
        mov     ecx, [current_slot]
2136
        mov     eax, [ecx+APPDATA.tls_base]
2174
        mov     eax, [ecx+APPDATA.tls_base]
2137
        test    eax, eax
2175
        test    eax, eax
2138
        jz      @F
2176
        jz      @F
2139
 
2177
 
2140
        stdcall user_free, eax
2178
        stdcall user_free, eax
2141
@@:
2179
@@:
2142
 
2180
 
2143
        mov     eax, [TASK_BASE]
2181
        mov     eax, [TASK_BASE]
2144
        mov     [eax+TASKDATA.state], 3; terminate this program
2182
        mov     [eax+TASKDATA.state], 3; terminate this program
2145
        call    wakeup_osloop
2183
        call    wakeup_osloop
2146
 
2184
 
2147
.waitterm:            ; wait here for termination
2185
.waitterm:            ; wait here for termination
2148
        call    change_task
2186
        call    change_task
2149
        jmp     .waitterm
2187
        jmp     .waitterm
2150
;------------------------------------------------------------------------------
2188
;------------------------------------------------------------------------------
2151
align 4
2189
align 4
2152
restore_default_cursor_before_killing:
2190
restore_default_cursor_before_killing:
2153
        pushfd
2191
        pushfd
2154
        cli
2192
        cli
2155
        mov     eax, [def_cursor]
2193
        mov     eax, [def_cursor]
2156
        mov     [ecx+APPDATA.cursor], eax
2194
        mov     [ecx+APPDATA.cursor], eax
2157
 
2195
 
2158
        movzx   eax, word [MOUSE_Y]
2196
        movzx   eax, word [MOUSE_Y]
2159
        movzx   ebx, word [MOUSE_X]
2197
        movzx   ebx, word [MOUSE_X]
2160
        mov     eax, [d_width_calc_area + eax*4]
2198
        mov     eax, [d_width_calc_area + eax*4]
2161
 
2199
 
2162
        add     eax, [_display.win_map]
2200
        add     eax, [_display.win_map]
2163
        movzx   edx, byte [ebx+eax]
2201
        movzx   edx, byte [ebx+eax]
2164
        shl     edx, 8
2202
        shl     edx, 8
2165
        mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
2203
        mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
2166
 
2204
 
2167
        cmp     esi, [current_cursor]
2205
        cmp     esi, [current_cursor]
2168
        je      @f
2206
        je      @f
2169
 
2207
 
2170
        push    esi
2208
        push    esi
2171
        call    [_display.select_cursor]
2209
        call    [_display.select_cursor]
2172
        mov     [current_cursor], esi
2210
        mov     [current_cursor], esi
2173
@@:
2211
@@:
2174
        mov     [redrawmouse_unconditional], 1
2212
        mov     [redrawmouse_unconditional], 1
2175
        call    wakeup_osloop
2213
        call    wakeup_osloop
2176
        popfd
2214
        popfd
2177
        ret
2215
        ret
2178
;------------------------------------------------------------------------------
2216
;------------------------------------------------------------------------------
2179
iglobal
2217
iglobal
2180
align 4
2218
align 4
2181
sys_system_table:
2219
sys_system_table:
2182
        dd      sysfn_deactivate        ; 1 = deactivate window
2220
        dd      sysfn_deactivate        ; 1 = deactivate window
2183
        dd      sysfn_terminate         ; 2 = terminate thread
2221
        dd      sysfn_terminate         ; 2 = terminate thread
2184
        dd      sysfn_activate          ; 3 = activate window
2222
        dd      sysfn_activate          ; 3 = activate window
2185
        dd      sysfn_getidletime       ; 4 = get idle time
2223
        dd      sysfn_getidletime       ; 4 = get idle time
2186
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
2224
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
2187
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
2225
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
2188
        dd      sysfn_getactive         ; 7 = get active window
2226
        dd      sysfn_getactive         ; 7 = get active window
2189
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
2227
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
2190
        dd      sysfn_shutdown          ; 9 = shutdown with parameter
2228
        dd      sysfn_shutdown          ; 9 = shutdown with parameter
2191
        dd      sysfn_minimize          ; 10 = minimize window
2229
        dd      sysfn_minimize          ; 10 = minimize window
2192
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
2230
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
2193
        dd      sysfn_lastkey           ; 12 = get last pressed key
2231
        dd      sysfn_lastkey           ; 12 = get last pressed key
2194
        dd      sysfn_getversion        ; 13 = get kernel version
2232
        dd      sysfn_getversion        ; 13 = get kernel version
2195
        dd      sysfn_waitretrace       ; 14 = wait retrace
2233
        dd      sysfn_waitretrace       ; 14 = wait retrace
2196
        dd      sysfn_centermouse       ; 15 = center mouse cursor
2234
        dd      sysfn_centermouse       ; 15 = center mouse cursor
2197
        dd      sysfn_getfreemem        ; 16 = get free memory size
2235
        dd      sysfn_getfreemem        ; 16 = get free memory size
2198
        dd      sysfn_getallmem         ; 17 = get total memory size
2236
        dd      sysfn_getallmem         ; 17 = get total memory size
2199
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
2237
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
2200
                                        ;                 instead of slot
2238
                                        ;                 instead of slot
2201
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
2239
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
2202
        dd      sysfn_meminfo           ; 20 = get extended memory info
2240
        dd      sysfn_meminfo           ; 20 = get extended memory info
2203
        dd      sysfn_pid_to_slot       ; 21 = get slot number for pid
2241
        dd      sysfn_pid_to_slot       ; 21 = get slot number for pid
2204
        dd      sysfn_min_rest_window   ; 22 = minimize and restore any window
2242
        dd      sysfn_min_rest_window   ; 22 = minimize and restore any window
2205
        dd      sysfn_min_windows       ; 23 = minimize all windows
2243
        dd      sysfn_min_windows       ; 23 = minimize all windows
2206
        dd      sysfn_set_screen_sizes  ; 24 = set screen sizes for Vesa
2244
        dd      sysfn_set_screen_sizes  ; 24 = set screen sizes for Vesa
-
 
2245
 
-
 
2246
        dd      sysfn_zmodif            ; 25 = get/set window z modifier  ;Fantomer
2207
sysfn_num = ($ - sys_system_table)/4
2247
sysfn_num = ($ - sys_system_table)/4
2208
endg
2248
endg
2209
;------------------------------------------------------------------------------
2249
;------------------------------------------------------------------------------
2210
sys_system:
2250
sys_system:
2211
        dec     ebx
2251
        dec     ebx
2212
        cmp     ebx, sysfn_num
2252
        cmp     ebx, sysfn_num
2213
        jae     @f
2253
        jae     @f
2214
        jmp     dword [sys_system_table + ebx*4]
2254
        jmp     dword [sys_system_table + ebx*4]
2215
@@:
2255
@@:
2216
        ret
2256
        ret
2217
;------------------------------------------------------------------------------
2257
;------------------------------------------------------------------------------
2218
sysfn_shutdown:          ; 18.9 = system shutdown
2258
sysfn_shutdown:          ; 18.9 = system shutdown
2219
        cmp     ecx, 1
2259
        cmp     ecx, 1
2220
        jl      exit_for_anyone
2260
        jl      exit_for_anyone
2221
        cmp     ecx, 4
2261
        cmp     ecx, 4
2222
        jg      exit_for_anyone
2262
        jg      exit_for_anyone
2223
        mov     [BOOT_VARS+0x9030], cl
2263
        mov     [BOOT_VARS+0x9030], cl
2224
 
2264
 
2225
        mov     eax, [TASK_COUNT]
2265
        mov     eax, [TASK_COUNT]
2226
        mov     [SYS_SHUTDOWN], al
2266
        mov     [SYS_SHUTDOWN], al
2227
        mov     [shutdown_processes], eax
2267
        mov     [shutdown_processes], eax
2228
        call    wakeup_osloop
2268
        call    wakeup_osloop
2229
        and     dword [esp+32], 0
2269
        and     dword [esp+32], 0
2230
 exit_for_anyone:
2270
 exit_for_anyone:
2231
        ret
2271
        ret
2232
  uglobal
2272
  uglobal
2233
   shutdown_processes:
2273
   shutdown_processes:
2234
                       dd 0x0
2274
                       dd 0x0
2235
  endg
2275
  endg
2236
;------------------------------------------------------------------------------
2276
;------------------------------------------------------------------------------
2237
sysfn_terminate:        ; 18.2 = TERMINATE
2277
sysfn_terminate:        ; 18.2 = TERMINATE
2238
        push    ecx
2278
        push    ecx
2239
        cmp     ecx, 2
2279
        cmp     ecx, 2
2240
        jb      noprocessterminate
2280
        jb      noprocessterminate
2241
        mov     edx, [TASK_COUNT]
2281
        mov     edx, [TASK_COUNT]
2242
        cmp     ecx, edx
2282
        cmp     ecx, edx
2243
        ja      noprocessterminate
2283
        ja      noprocessterminate
2244
        mov     eax, [TASK_COUNT]
2284
        mov     eax, [TASK_COUNT]
2245
        shl     ecx, 5
2285
        shl     ecx, 5
2246
        mov     edx, [ecx+CURRENT_TASK+TASKDATA.pid]
2286
        mov     edx, [ecx+CURRENT_TASK+TASKDATA.pid]
2247
        add     ecx, CURRENT_TASK+TASKDATA.state
2287
        add     ecx, CURRENT_TASK+TASKDATA.state
2248
        cmp     byte [ecx], 9
2288
        cmp     byte [ecx], 9
2249
        jz      noprocessterminate
2289
        jz      noprocessterminate
2250
        push    ecx edx
2290
        push    ecx edx
2251
        lea     edx, [(ecx-(CURRENT_TASK and 1FFFFFFFh)-TASKDATA.state)*8+SLOT_BASE]
2291
        lea     edx, [(ecx-(CURRENT_TASK and 1FFFFFFFh)-TASKDATA.state)*8+SLOT_BASE]
2252
        call    request_terminate
2292
        call    request_terminate
2253
        pop     edx ecx
2293
        pop     edx ecx
2254
        test    eax, eax
2294
        test    eax, eax
2255
        jz      noprocessterminate
2295
        jz      noprocessterminate
2256
;--------------------------------------
2296
;--------------------------------------
2257
; terminate all network sockets it used
2297
; terminate all network sockets it used
2258
        pusha
2298
        pusha
2259
        mov     eax, edx
2299
        mov     eax, edx
2260
        call    SOCKET_process_end
2300
        call    SOCKET_process_end
2261
        popa
2301
        popa
2262
;--------------------------------------
2302
;--------------------------------------
2263
        cmp     [_display.select_cursor], 0
2303
        cmp     [_display.select_cursor], 0
2264
        je      .restore_end
2304
        je      .restore_end
2265
; restore default cursor before killing
2305
; restore default cursor before killing
2266
        pusha
2306
        pusha
2267
        mov     ecx, [esp+32]
2307
        mov     ecx, [esp+32]
2268
        shl     ecx, 8
2308
        shl     ecx, 8
2269
        add     ecx, SLOT_BASE
2309
        add     ecx, SLOT_BASE
2270
        mov     eax, [def_cursor]
2310
        mov     eax, [def_cursor]
2271
        cmp     [ecx+APPDATA.cursor], eax
2311
        cmp     [ecx+APPDATA.cursor], eax
2272
        je      @f
2312
        je      @f
2273
        call    restore_default_cursor_before_killing
2313
        call    restore_default_cursor_before_killing
2274
@@:
2314
@@:
2275
        popa
2315
        popa
2276
.restore_end:
2316
.restore_end:
2277
;--------------------------------------
2317
;--------------------------------------
2278
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2318
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2279
        mov     [ecx], byte 3; clear possible i40's
2319
        mov     [ecx], byte 3; clear possible i40's
2280
        call    wakeup_osloop
2320
        call    wakeup_osloop
2281
     ;call MEM_Heap_UnLock
2321
     ;call MEM_Heap_UnLock
2282
 
2322
 
2283
        cmp     edx, [application_table_owner]; clear app table stat
2323
        cmp     edx, [application_table_owner]; clear app table stat
2284
        jne     noatsc
2324
        jne     noatsc
2285
        call    unlock_application_table
2325
        call    unlock_application_table
2286
noatsc:
2326
noatsc:
2287
noprocessterminate:
2327
noprocessterminate:
2288
        add     esp, 4
2328
        add     esp, 4
2289
        ret
2329
        ret
2290
;------------------------------------------------------------------------------
2330
;------------------------------------------------------------------------------
2291
sysfn_terminate2:
2331
sysfn_terminate2:
2292
;lock application_table_status mutex
2332
;lock application_table_status mutex
2293
.table_status:
2333
.table_status:
2294
        call    lock_application_table
2334
        call    lock_application_table
2295
        mov     eax, ecx
2335
        mov     eax, ecx
2296
        call    pid_to_slot
2336
        call    pid_to_slot
2297
        test    eax, eax
2337
        test    eax, eax
2298
        jz      .not_found
2338
        jz      .not_found
2299
        mov     ecx, eax
2339
        mov     ecx, eax
2300
        cli
2340
        cli
2301
        call    sysfn_terminate
2341
        call    sysfn_terminate
2302
        call    unlock_application_table
2342
        call    unlock_application_table
2303
        sti
2343
        sti
2304
        and     dword [esp+32], 0
2344
        and     dword [esp+32], 0
2305
        ret
2345
        ret
2306
.not_found:
2346
.not_found:
2307
        call    unlock_application_table
2347
        call    unlock_application_table
2308
        or      dword [esp+32], -1
2348
        or      dword [esp+32], -1
2309
        ret
2349
        ret
2310
;------------------------------------------------------------------------------
2350
;------------------------------------------------------------------------------
2311
sysfn_deactivate:         ; 18.1 = DEACTIVATE WINDOW
2351
sysfn_deactivate:         ; 18.1 = DEACTIVATE WINDOW
2312
        cmp     ecx, 2
2352
        cmp     ecx, 2
2313
        jb      .nowindowdeactivate
2353
        jb      .nowindowdeactivate
2314
        cmp     ecx, [TASK_COUNT]
2354
        cmp     ecx, [TASK_COUNT]
2315
        ja      .nowindowdeactivate
2355
        ja      .nowindowdeactivate
2316
 
2356
 
2317
        movzx   esi, word [WIN_STACK + ecx*2]
2357
        movzx   esi, word [WIN_STACK + ecx*2]
2318
        cmp     esi, 1
2358
        cmp     esi, 1
2319
        je      .nowindowdeactivate ; already deactive
2359
        je      .nowindowdeactivate ; already deactive
2320
 
2360
 
2321
        mov     edi, ecx
2361
        mov     edi, ecx
2322
        shl     edi, 5
2362
        shl     edi, 5
2323
        add     edi, window_data
2363
        add     edi, window_data
2324
        movzx   esi, word [WIN_STACK + ecx * 2]
2364
        movzx   esi, word [WIN_STACK + ecx * 2]
2325
        lea     esi, [WIN_POS + esi * 2]
2365
        lea     esi, [WIN_POS + esi * 2]
2326
        call    window._.window_deactivate
2366
        call    window._.window_deactivate
2327
 
2367
 
2328
        call    syscall_display_settings._.calculate_whole_screen
2368
        call    syscall_display_settings._.calculate_whole_screen
2329
        call    syscall_display_settings._.redraw_whole_screen
2369
        call    syscall_display_settings._.redraw_whole_screen
2330
.nowindowdeactivate:
2370
.nowindowdeactivate:
2331
        ret
2371
        ret
2332
;------------------------------------------------------------------------------
2372
;------------------------------------------------------------------------------
2333
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2373
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2334
        cmp     ecx, 2
2374
        cmp     ecx, 2
2335
        jb      .nowindowactivate
2375
        jb      .nowindowactivate
2336
        cmp     ecx, [TASK_COUNT]
2376
        cmp     ecx, [TASK_COUNT]
2337
        ja      .nowindowactivate
2377
        ja      .nowindowactivate
2338
;-------------------------------------
2378
;-------------------------------------
2339
@@:
2379
@@:
2340
; If the window is captured and moved by the user,
2380
; If the window is captured and moved by the user,
2341
; then you can't change the position in window stack!!!
2381
; then you can't change the position in window stack!!!
2342
        mov     al, [mouse.active_sys_window.action]
2382
        mov     al, [mouse.active_sys_window.action]
2343
        and     al, WINDOW_MOVE_AND_RESIZE_FLAGS
2383
        and     al, WINDOW_MOVE_AND_RESIZE_FLAGS
2344
        test    al, al
2384
        test    al, al
2345
        jz      @f
2385
        jz      @f
2346
        call    change_task
2386
        call    change_task
2347
        jmp     @b
2387
        jmp     @b
2348
@@:
2388
@@:
2349
;-------------------------------------
2389
;-------------------------------------
2350
        mov     [window_minimize], 2; restore window if minimized
2390
        mov     [window_minimize], 2; restore window if minimized
2351
        call    wakeup_osloop
2391
        call    wakeup_osloop
2352
 
2392
 
2353
        movzx   esi, word [WIN_STACK + ecx*2]
2393
        movzx   esi, word [WIN_STACK + ecx*2]
2354
        cmp     esi, [TASK_COUNT]
2394
        cmp     esi, [TASK_COUNT]
2355
        je      .nowindowactivate; already active
2395
        je      .nowindowactivate; already active
2356
 
2396
 
2357
        mov     edi, ecx
2397
        mov     edi, ecx
2358
        shl     edi, 5
2398
        shl     edi, 5
2359
        add     edi, window_data
2399
        add     edi, window_data
2360
        movzx   esi, word [WIN_STACK + ecx * 2]
2400
        movzx   esi, word [WIN_STACK + ecx * 2]
2361
        lea     esi, [WIN_POS + esi * 2]
2401
        lea     esi, [WIN_POS + esi * 2]
2362
        call    waredraw
2402
        call    waredraw
2363
.nowindowactivate:
2403
.nowindowactivate:
2364
        ret
2404
        ret
2365
;------------------------------------------------------------------------------
2405
;------------------------------------------------------------------------------
-
 
2406
align 4
-
 
2407
sysfn_zmodif:
-
 
2408
;18,25,1 - get z_modif
-
 
2409
;18,25,2 - set z_modif
-
 
2410
;edx = -1(for current task) or TID
-
 
2411
;esi(for 2) = new value z_modif
-
 
2412
;return:
-
 
2413
;1:   eax = z_modif
-
 
2414
;2: eax=0(fail),1(success) for set z_modif
-
 
2415
 
-
 
2416
        cmp     edx, -1
-
 
2417
        jne     @f
-
 
2418
        mov     edx, [CURRENT_TASK]
-
 
2419
     @@:
-
 
2420
        cmp     edx, [TASK_COUNT]
-
 
2421
        ja      .fail
-
 
2422
        cmp     edx, 1
-
 
2423
        je      .fail
-
 
2424
 
-
 
2425
        mov     eax, edx
-
 
2426
        shl     edx, 5
-
 
2427
 
-
 
2428
        cmp     [edx + CURRENT_TASK + TASKDATA.state], 9
-
 
2429
        je      .fail
-
 
2430
 
-
 
2431
        cmp     ecx, 1
-
 
2432
        jnz     .set_zmod
-
 
2433
 
-
 
2434
        mov     al, [edx + window_data + WDATA.z_modif]
-
 
2435
        jmp     .exit
-
 
2436
 
-
 
2437
.set_zmod:
-
 
2438
        cmp     ecx, 2
-
 
2439
        jnz     .fail
-
 
2440
 
-
 
2441
        mov     ebx, esi
-
 
2442
        mov     esi, eax
-
 
2443
 
-
 
2444
        cmp     bl, ZPOS_ALWAYS_TOP
-
 
2445
        jg      .fail
-
 
2446
 
-
 
2447
        mov     [edx + window_data + WDATA.z_modif], bl
-
 
2448
 
-
 
2449
        mov     eax, [edx + window_data + WDATA.box.left]
-
 
2450
        mov     ebx, [edx + window_data + WDATA.box.top]
-
 
2451
        mov     ecx, [edx + window_data + WDATA.box.width]
-
 
2452
        mov     edx, [edx + window_data + WDATA.box.height]
-
 
2453
        add     ecx, eax
-
 
2454
        add     edx, ebx
-
 
2455
        call    window._.set_screen
-
 
2456
        call    window._.set_top_wnd
-
 
2457
        call    window._.redraw_top_wnd
-
 
2458
 
-
 
2459
        shl     esi, 5
-
 
2460
        mov     [esi + window_data + WDATA.fl_redraw], 1
-
 
2461
 
-
 
2462
 
-
 
2463
        mov     eax, 1
-
 
2464
        jmp     .exit
-
 
2465
.fail:
-
 
2466
        xor     eax, eax
-
 
2467
.exit:
-
 
2468
        mov     [esp+32], eax
-
 
2469
        ret
-
 
2470
 
-
 
2471
;------------------------------------------------------------------------------
2366
sysfn_getidletime:              ; 18.4 = GET IDLETIME
2472
sysfn_getidletime:              ; 18.4 = GET IDLETIME
2367
        mov     eax, [CURRENT_TASK+32+TASKDATA.cpu_usage]
2473
        mov     eax, [CURRENT_TASK+32+TASKDATA.cpu_usage]
2368
        mov     [esp+32], eax
2474
        mov     [esp+32], eax
2369
        ret
2475
        ret
2370
;------------------------------------------------------------------------------
2476
;------------------------------------------------------------------------------
2371
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
2477
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
2372
        mov     eax, dword [cpu_freq]
2478
        mov     eax, dword [cpu_freq]
2373
        mov     [esp+32], eax
2479
        mov     [esp+32], eax
2374
        ret
2480
        ret
2375
;------------------------------------------------------------------------------
2481
;------------------------------------------------------------------------------
2376
get_cpu_freq:
2482
get_cpu_freq:
2377
        mov     eax, dword [cpu_freq]
2483
        mov     eax, dword [cpu_freq]
2378
        mov     edx, dword [cpu_freq+4]
2484
        mov     edx, dword [cpu_freq+4]
2379
        ret
2485
        ret
2380
;  SAVE ramdisk to /hd/1/menuet.img
2486
;  SAVE ramdisk to /hd/1/menuet.img
2381
;!!!!!!!!!!!!!!!!!!!!!!!!
2487
;!!!!!!!!!!!!!!!!!!!!!!!!
2382
   include 'blkdev/rdsave.inc'
2488
   include 'blkdev/rdsave.inc'
2383
;!!!!!!!!!!!!!!!!!!!!!!!!
2489
;!!!!!!!!!!!!!!!!!!!!!!!!
2384
;------------------------------------------------------------------------------
2490
;------------------------------------------------------------------------------
2385
align 4
2491
align 4
2386
sysfn_getactive:        ; 18.7 = get active window
2492
sysfn_getactive:        ; 18.7 = get active window
2387
        mov     eax, [TASK_COUNT]
2493
        mov     eax, [TASK_COUNT]
2388
        movzx   eax, word [WIN_POS + eax*2]
2494
        movzx   eax, word [WIN_POS + eax*2]
2389
        mov     [esp+32], eax
2495
        mov     [esp+32], eax
2390
        ret
2496
        ret
2391
;------------------------------------------------------------------------------
2497
;------------------------------------------------------------------------------
2392
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2498
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2393
;     cmp  ecx,1
2499
;     cmp  ecx,1
2394
        dec     ecx
2500
        dec     ecx
2395
        jnz     nogetsoundflag
2501
        jnz     nogetsoundflag
2396
        movzx   eax, byte [sound_flag]; get sound_flag
2502
        movzx   eax, byte [sound_flag]; get sound_flag
2397
        mov     [esp+32], eax
2503
        mov     [esp+32], eax
2398
        ret
2504
        ret
2399
 nogetsoundflag:
2505
 nogetsoundflag:
2400
;     cmp  ecx,2
2506
;     cmp  ecx,2
2401
        dec     ecx
2507
        dec     ecx
2402
        jnz     nosoundflag
2508
        jnz     nosoundflag
2403
        xor     byte [sound_flag], 1
2509
        xor     byte [sound_flag], 1
2404
 nosoundflag:
2510
 nosoundflag:
2405
        ret
2511
        ret
2406
;------------------------------------------------------------------------------
2512
;------------------------------------------------------------------------------
2407
sysfn_minimize:         ; 18.10 = minimize window
2513
sysfn_minimize:         ; 18.10 = minimize window
2408
        mov     [window_minimize], 1
2514
        mov     [window_minimize], 1
2409
        call    wakeup_osloop
2515
        call    wakeup_osloop
2410
        ret
2516
        ret
2411
;------------------------------------------------------------------------------
2517
;------------------------------------------------------------------------------
2412
align 4
2518
align 4
2413
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2519
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2414
        dec     ecx
2520
        dec     ecx
2415
        jnz     .exit
2521
        jnz     .exit
2416
.small_table:
2522
.small_table:
2417
        mov     edi, edx
2523
        mov     edi, edx
2418
        mov     esi, DRIVE_DATA
2524
        mov     esi, DRIVE_DATA
2419
        mov     ecx, DRIVE_DATA_SIZE ;10
2525
        mov     ecx, DRIVE_DATA_SIZE ;10
2420
        cld
2526
        cld
2421
        rep movsb
2527
        rep movsb
2422
.exit:
2528
.exit:
2423
        ret
2529
        ret
2424
;------------------------------------------------------------------------------
2530
;------------------------------------------------------------------------------
2425
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2531
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2426
        and     dword [esp+32], 0
2532
        and     dword [esp+32], 0
2427
        ret
2533
        ret
2428
;------------------------------------------------------------------------------
2534
;------------------------------------------------------------------------------
2429
sysfn_getversion:       ; 18.13 = get kernel ID and version
2535
sysfn_getversion:       ; 18.13 = get kernel ID and version
2430
        mov     edi, ecx
2536
        mov     edi, ecx
2431
        mov     esi, version_inf
2537
        mov     esi, version_inf
2432
        mov     ecx, version_end-version_inf
2538
        mov     ecx, version_end-version_inf
2433
        rep movsb
2539
        rep movsb
2434
        ret
2540
        ret
2435
;------------------------------------------------------------------------------
2541
;------------------------------------------------------------------------------
2436
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2542
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2437
     ;wait retrace functions
2543
     ;wait retrace functions
2438
 sys_wait_retrace:
2544
 sys_wait_retrace:
2439
        mov     edx, 0x3da
2545
        mov     edx, 0x3da
2440
 WaitRetrace_loop:
2546
 WaitRetrace_loop:
2441
        in      al, dx
2547
        in      al, dx
2442
        test    al, 1000b
2548
        test    al, 1000b
2443
        jz      WaitRetrace_loop
2549
        jz      WaitRetrace_loop
2444
        and     [esp+32], dword 0
2550
        and     [esp+32], dword 0
2445
        ret
2551
        ret
2446
;------------------------------------------------------------------------------
2552
;------------------------------------------------------------------------------
2447
align 4
2553
align 4
2448
sysfn_centermouse:      ; 18.15 = mouse centered
2554
sysfn_centermouse:      ; 18.15 = mouse centered
2449
; removed here by 
-
 
2450
;     call  mouse_centered
-
 
2451
;* mouse centered - start code- Mario79
-
 
2452
;mouse_centered:
-
 
2453
;        push  eax
-
 
2454
        mov     eax, [_display.width]
2555
        mov     eax, [_display.width]
2455
        shr     eax, 1
2556
        shr     eax, 1
2456
        mov     [MOUSE_X], ax
2557
        mov     [MOUSE_X], ax
2457
        mov     eax, [_display.height]
2558
        mov     eax, [_display.height]
2458
        shr     eax, 1
2559
        shr     eax, 1
2459
        mov     [MOUSE_Y], ax
2560
        mov     [MOUSE_Y], ax
2460
        call    wakeup_osloop
2561
        call    wakeup_osloop
2461
;        ret
-
 
2462
;* mouse centered - end code- Mario79
-
 
2463
        xor     eax, eax
2562
        xor     eax, eax
2464
        and     [esp+32], eax
2563
        and     [esp+32], eax
2465
;        pop   eax
-
 
2466
        ret
2564
        ret
2467
;------------------------------------------------------------------------------
2565
;------------------------------------------------------------------------------
2468
align 4
-
 
2469
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2566
sysfn_mouse_acceleration:       ; 18.19 = set/get mouse features
-
 
2567
        cmp     ecx, 8
-
 
2568
        jnc     @f
2470
        test    ecx, ecx; get mouse speed factor
2569
        jmp     dword [.table+ecx*4]
2471
        jnz     .set_mouse_acceleration
2570
.get_mouse_acceleration:
2472
        xor     eax, eax
2571
        xor     eax, eax
2473
        mov     ax, [mouse_speed_factor]
2572
        mov     ax, [mouse_speed_factor]
2474
        mov     [esp+32], eax
2573
        mov     [esp+32], eax
2475
        ret
2574
        ret
2476
 .set_mouse_acceleration:
2575
.set_mouse_acceleration:
2477
;     cmp  ecx,1  ; set mouse speed factor
-
 
2478
        dec     ecx
-
 
2479
        jnz     .get_mouse_delay
-
 
2480
        mov     [mouse_speed_factor], dx
2576
        mov     [mouse_speed_factor], dx
2481
        ret
2577
        ret
2482
 .get_mouse_delay:
2578
.get_mouse_delay:
2483
;     cmp  ecx,2  ; get mouse delay
-
 
2484
        dec     ecx
2579
        xor     eax, eax
2485
        jnz     .set_mouse_delay
-
 
2486
        mov     eax, [mouse_delay]
2580
        mov     al, [mouse_delay]
2487
        mov     [esp+32], eax
2581
        mov     [esp+32], eax
2488
        ret
2582
        ret
2489
 .set_mouse_delay:
2583
.set_mouse_delay:
2490
;     cmp  ecx,3  ; set mouse delay
-
 
2491
        dec     ecx
-
 
2492
        jnz     .set_pointer_position
-
 
2493
        mov     [mouse_delay], edx
2584
        mov     [mouse_delay], dl
-
 
2585
@@:
2494
        ret
2586
        ret
2495
 .set_pointer_position:
2587
.set_pointer_position:
2496
;     cmp  ecx,4  ; set mouse pointer position
-
 
2497
        dec     ecx
-
 
2498
        jnz     .set_mouse_button
-
 
2499
        cmp     dx, word[_display.height]
2588
        cmp     dx, word[_display.height]
2500
        jae     .end
2589
        jae     @b
2501
        rol     edx, 16
2590
        rol     edx, 16
2502
        cmp     dx, word[_display.width]
2591
        cmp     dx, word[_display.width]
2503
        jae     .end
2592
        jae     @b
2504
        mov     [MOUSE_X], edx
2593
        mov     [MOUSE_X], edx
2505
        mov     [mouse_active], 1
2594
        mov     [mouse_active], 1
2506
        call    wakeup_osloop
2595
        jmp     wakeup_osloop
2507
        ret
-
 
2508
 .set_mouse_button:
2596
.set_mouse_button:
2509
;     cmp   ecx,5  ; set mouse button features
-
 
2510
        dec     ecx
-
 
2511
        jnz     .end
-
 
2512
        mov     [BTN_DOWN], dl
2597
        mov     [BTN_DOWN], edx
2513
        mov     [mouse_active], 1
2598
        mov     [mouse_active], 1
2514
        call    wakeup_osloop
2599
        jmp     wakeup_osloop
2515
 .end:
2600
.get_doubleclick_delay:
-
 
2601
        xor     eax, eax
-
 
2602
        mov     al, [mouse_doubleclick_delay]
-
 
2603
        mov     [esp+32], eax
2516
        ret
2604
        ret
-
 
2605
.set_doubleclick_delay:
-
 
2606
        mov     [mouse_doubleclick_delay], dl
-
 
2607
        ret
-
 
2608
align 4
-
 
2609
.table:
-
 
2610
dd      .get_mouse_acceleration
-
 
2611
dd      .set_mouse_acceleration
-
 
2612
dd      .get_mouse_delay
-
 
2613
dd      .set_mouse_delay
-
 
2614
dd      .set_pointer_position
-
 
2615
dd      .set_mouse_button
-
 
2616
dd      .get_doubleclick_delay
-
 
2617
dd      .set_doubleclick_delay
2517
;------------------------------------------------------------------------------
2618
;------------------------------------------------------------------------------
2518
sysfn_getfreemem:
2619
sysfn_getfreemem:
2519
        mov     eax, [pg_data.pages_free]
2620
        mov     eax, [pg_data.pages_free]
2520
        shl     eax, 2
2621
        shl     eax, 2
2521
        mov     [esp+32], eax
2622
        mov     [esp+32], eax
2522
        ret
2623
        ret
2523
;------------------------------------------------------------------------------
2624
;------------------------------------------------------------------------------
2524
sysfn_getallmem:
2625
sysfn_getallmem:
2525
        mov     eax, [MEM_AMOUNT]
2626
        mov     eax, [MEM_AMOUNT]
2526
        shr     eax, 10
2627
        shr     eax, 10
2527
        mov     [esp+32], eax
2628
        mov     [esp+32], eax
2528
        ret
2629
        ret
2529
;------------------------------------------------------------------------------
2630
;------------------------------------------------------------------------------
2530
sysfn_pid_to_slot:
2631
sysfn_pid_to_slot:
2531
        mov     eax, ecx
2632
        mov     eax, ecx
2532
        call    pid_to_slot
2633
        call    pid_to_slot
2533
        mov     [esp+32], eax
2634
        mov     [esp+32], eax
2534
        ret
2635
        ret
2535
;------------------------------------------------------------------------------
2636
;------------------------------------------------------------------------------
2536
sysfn_min_rest_window:
2637
sysfn_min_rest_window:
2537
        pushad
2638
        pushad
2538
        mov     eax, edx ; ebx - operating
2639
        mov     eax, edx ; ebx - operating
2539
        shr     ecx, 1
2640
        shr     ecx, 1
2540
        jnc     @f
2641
        jnc     @f
2541
        call    pid_to_slot
2642
        call    pid_to_slot
2542
@@:
2643
@@:
2543
        or      eax, eax ; eax - number of slot
2644
        or      eax, eax ; eax - number of slot
2544
        jz      .error
2645
        jz      .error
2545
        cmp     eax, 255    ; varify maximal slot number
2646
        cmp     eax, 255    ; varify maximal slot number
2546
        ja      .error
2647
        ja      .error
2547
        movzx   eax, word [WIN_STACK + eax*2]
2648
        movzx   eax, word [WIN_STACK + eax*2]
2548
        shr     ecx, 1
2649
        shr     ecx, 1
2549
        jc      .restore
2650
        jc      .restore
2550
 ; .minimize:
2651
 ; .minimize:
2551
        call    minimize_window
2652
        call    minimize_window
2552
        jmp     .exit
2653
        jmp     .exit
2553
.restore:
2654
.restore:
2554
        call    restore_minimized_window
2655
        call    restore_minimized_window
2555
.exit:
2656
.exit:
2556
        popad
2657
        popad
2557
        xor     eax, eax
2658
        xor     eax, eax
2558
        mov     [esp+32], eax
2659
        mov     [esp+32], eax
2559
        ret
2660
        ret
2560
.error:
2661
.error:
2561
        popad
2662
        popad
2562
        xor     eax, eax
2663
        xor     eax, eax
2563
        dec     eax
2664
        dec     eax
2564
        mov     [esp+32], eax
2665
        mov     [esp+32], eax
2565
        ret
2666
        ret
2566
;------------------------------------------------------------------------------
2667
;------------------------------------------------------------------------------
2567
sysfn_min_windows:
2668
sysfn_min_windows:
2568
        call    minimize_all_window
2669
        call    minimize_all_window
2569
        mov     [esp+32], eax
2670
        mov     [esp+32], eax
2570
        call    change_task
2671
        call    change_task
2571
        ret
2672
        ret
2572
;------------------------------------------------------------------------------
2673
;------------------------------------------------------------------------------
2573
sysfn_set_screen_sizes:
2674
sysfn_set_screen_sizes:
2574
        cmp     [SCR_MODE], word 0x13
2675
        cmp     [SCR_MODE], word 0x13
2575
        jbe     .exit
2676
        jbe     .exit
2576
 
2677
 
2577
        cmp     [_display.select_cursor], select_cursor
2678
        cmp     [_display.select_cursor], select_cursor
2578
        jne     .exit
2679
        jne     .exit
2579
 
2680
 
2580
        cmp     ecx, [display_width_standard]
2681
        cmp     ecx, [display_width_standard]
2581
        ja      .exit
2682
        ja      .exit
2582
 
2683
 
2583
        cmp     edx, [display_height_standard]
2684
        cmp     edx, [display_height_standard]
2584
        ja      .exit
2685
        ja      .exit
2585
 
2686
 
2586
        pushfd
2687
        pushfd
2587
        cli
2688
        cli
2588
        mov     eax, ecx
2689
        mov     eax, ecx
2589
        mov     ecx, [_display.lfb_pitch]
2690
        mov     ecx, [_display.lfb_pitch]
2590
        mov     [_display.width], eax
2691
        mov     [_display.width], eax
2591
        dec     eax
2692
        dec     eax
2592
        mov     [_display.height], edx
2693
        mov     [_display.height], edx
2593
        dec     edx
2694
        dec     edx
2594
; eax - new Screen_Max_X
2695
; eax - new Screen_Max_X
2595
; edx - new Screen_Max_Y
2696
; edx - new Screen_Max_Y
2596
        mov     [do_not_touch_winmap], 1
2697
        mov     [do_not_touch_winmap], 1
2597
        call    set_screen
2698
        call    set_screen
2598
        mov     [do_not_touch_winmap], 0
2699
        mov     [do_not_touch_winmap], 0
2599
        popfd
2700
        popfd
2600
        call    change_task
2701
        call    change_task
2601
.exit:
2702
.exit:
2602
        ret
2703
        ret
2603
;------------------------------------------------------------------------------
2704
;------------------------------------------------------------------------------
2604
uglobal
2705
uglobal
2605
screen_workarea RECT
2706
screen_workarea RECT
2606
display_width_standard dd 0
2707
display_width_standard dd 0
2607
display_height_standard dd 0
2708
display_height_standard dd 0
2608
do_not_touch_winmap db 0
2709
do_not_touch_winmap db 0
2609
window_minimize db 0
2710
window_minimize db 0
2610
sound_flag      db 0
2711
sound_flag      db 0
2611
 
2712
 
2612
endg
2713
endg
2613
 
2714
 
2614
UID_NONE=0
2715
UID_NONE=0
2615
UID_MENUETOS=1   ;official
2716
UID_MENUETOS=1   ;official
2616
UID_KOLIBRI=2    ;russian
2717
UID_KOLIBRI=2    ;russian
2617
 
2718
 
2618
iglobal
2719
iglobal
2619
version_inf:
2720
version_inf:
2620
        db 0,7,7,0  ; version 0.7.7.0
2721
        db 0,7,7,0  ; version 0.7.7.0
2621
        db 0
2722
        db 0
2622
.rev    dd __REV__
2723
.rev    dd __REV__
2623
version_end:
2724
version_end:
2624
endg
2725
endg
2625
;------------------------------------------------------------------------------
2726
;------------------------------------------------------------------------------
2626
align 4
2727
align 4
2627
sys_cachetodiskette:
2728
sys_cachetodiskette:
2628
        cmp     ebx, 1
2729
        cmp     ebx, 1
2629
        jb      .no_floppy_save
2730
        jb      .no_floppy_save
2630
        cmp     ebx, 2
2731
        cmp     ebx, 2
2631
        ja      .no_floppy_save
2732
        ja      .no_floppy_save
2632
        call    save_image
2733
        call    save_image
2633
        mov     [esp + 32], eax
2734
        mov     [esp + 32], eax
2634
        ret
2735
        ret
2635
.no_floppy_save:
2736
.no_floppy_save:
2636
        mov     [esp + 32], dword 1
2737
        mov     [esp + 32], dword 1
2637
        ret
2738
        ret
2638
;------------------------------------------------------------------------------
2739
;------------------------------------------------------------------------------
2639
uglobal
2740
uglobal
2640
;  bgrchanged  dd  0x0
2741
;  bgrchanged  dd  0x0
2641
align 4
2742
align 4
2642
bgrlockpid dd 0
2743
bgrlockpid dd 0
2643
bgrlock db 0
2744
bgrlock db 0
2644
endg
2745
endg
2645
;------------------------------------------------------------------------------
2746
;------------------------------------------------------------------------------
2646
align 4
2747
align 4
2647
sys_background:
2748
sys_background:
2648
        cmp     ebx, 1                     ; BACKGROUND SIZE
2749
        cmp     ebx, 1                     ; BACKGROUND SIZE
2649
        jnz     nosb1
2750
        jnz     nosb1
2650
        test    ecx, ecx
2751
        test    ecx, ecx
2651
        jz      sbgrr
2752
        jz      sbgrr
2652
 
2753
 
2653
        test    edx, edx
2754
        test    edx, edx
2654
        jz      sbgrr
2755
        jz      sbgrr
2655
;--------------------------------------
2756
;--------------------------------------
2656
align 4
2757
align 4
2657
@@:
2758
@@:
2658
;;Maxis use atomic bts for mutexes  4.4.2009
2759
;;Maxis use atomic bts for mutexes  4.4.2009
2659
        bts     dword [bgrlock], 0
2760
        bts     dword [bgrlock], 0
2660
        jnc     @f
2761
        jnc     @f
2661
        call    change_task
2762
        call    change_task
2662
        jmp     @b
2763
        jmp     @b
2663
;--------------------------------------
2764
;--------------------------------------
2664
align 4
2765
align 4
2665
@@:
2766
@@:
2666
        mov     [BgrDataWidth], ecx
2767
        mov     [BgrDataWidth], ecx
2667
        mov     [BgrDataHeight], edx
2768
        mov     [BgrDataHeight], edx
2668
;    mov   [bgrchanged],1
2769
;    mov   [bgrchanged],1
2669
 
2770
 
2670
        pushad
2771
        pushad
2671
; return memory for old background
2772
; return memory for old background
2672
        mov     eax, [img_background]
2773
        mov     eax, [img_background]
2673
        cmp     eax, static_background_data
2774
        cmp     eax, static_background_data
2674
        jz      @f
2775
        jz      @f
2675
        stdcall kernel_free, eax
2776
        stdcall kernel_free, eax
2676
;--------------------------------------
2777
;--------------------------------------
2677
align 4
2778
align 4
2678
@@:
2779
@@:
2679
; calculate RAW size
2780
; calculate RAW size
2680
        xor     eax, eax
2781
        xor     eax, eax
2681
        inc     eax
2782
        inc     eax
2682
        cmp     [BgrDataWidth], eax
2783
        cmp     [BgrDataWidth], eax
2683
        jae     @f
2784
        jae     @f
2684
        mov     [BgrDataWidth], eax
2785
        mov     [BgrDataWidth], eax
2685
;--------------------------------------
2786
;--------------------------------------
2686
align 4
2787
align 4
2687
@@:
2788
@@:
2688
        cmp     [BgrDataHeight], eax
2789
        cmp     [BgrDataHeight], eax
2689
        jae     @f
2790
        jae     @f
2690
        mov     [BgrDataHeight], eax
2791
        mov     [BgrDataHeight], eax
2691
;--------------------------------------
2792
;--------------------------------------
2692
align 4
2793
align 4
2693
@@:
2794
@@:
2694
        mov     eax, [BgrDataWidth]
2795
        mov     eax, [BgrDataWidth]
2695
        imul    eax, [BgrDataHeight]
2796
        imul    eax, [BgrDataHeight]
2696
        lea     eax, [eax*3]
2797
        lea     eax, [eax*3]
2697
; it is reserved with aligned to the boundary of 4 KB pages,
2798
; it is reserved with aligned to the boundary of 4 KB pages,
2698
; otherwise there may be exceptions a page fault for vesa20_drawbackground_tiled
2799
; otherwise there may be exceptions a page fault for vesa20_drawbackground_tiled
2699
; because the 32 bit read is used for  high performance: "mov eax,[esi]"
2800
; because the 32 bit read is used for  high performance: "mov eax,[esi]"
2700
        shr     eax, 12
2801
        shr     eax, 12
2701
        inc     eax
2802
        inc     eax
2702
        shl     eax, 12
2803
        shl     eax, 12
2703
        mov     [mem_BACKGROUND], eax
2804
        mov     [mem_BACKGROUND], eax
2704
; get memory for new background
2805
; get memory for new background
2705
        stdcall kernel_alloc, eax
2806
        stdcall kernel_alloc, eax
2706
        test    eax, eax
2807
        test    eax, eax
2707
        jz      .memfailed
2808
        jz      .memfailed
2708
        mov     [img_background], eax
2809
        mov     [img_background], eax
2709
        jmp     .exit
2810
        jmp     .exit
2710
;--------------------------------------
2811
;--------------------------------------
2711
align 4
2812
align 4
2712
.memfailed:
2813
.memfailed:
2713
; revert to static monotone data
2814
; revert to static monotone data
2714
        mov     [img_background], static_background_data
2815
        mov     [img_background], static_background_data
2715
        xor     eax, eax
2816
        xor     eax, eax
2716
        inc     eax
2817
        inc     eax
2717
        mov     [BgrDataWidth], eax
2818
        mov     [BgrDataWidth], eax
2718
        mov     [BgrDataHeight], eax
2819
        mov     [BgrDataHeight], eax
2719
        mov     [mem_BACKGROUND], 4
2820
        mov     [mem_BACKGROUND], 4
2720
;--------------------------------------
2821
;--------------------------------------
2721
align 4
2822
align 4
2722
.exit:
2823
.exit:
2723
        popad
2824
        popad
2724
        mov     [bgrlock], 0
2825
        mov     [bgrlock], 0
2725
;--------------------------------------
2826
;--------------------------------------
2726
align 4
2827
align 4
2727
sbgrr:
2828
sbgrr:
2728
        ret
2829
        ret
2729
;------------------------------------------------------------------------------
2830
;------------------------------------------------------------------------------
2730
align 4
2831
align 4
2731
nosb1:
2832
nosb1:
2732
        cmp     ebx, 2                     ; SET PIXEL
2833
        cmp     ebx, 2                     ; SET PIXEL
2733
        jnz     nosb2
2834
        jnz     nosb2
2734
 
2835
 
2735
        mov     eax, [img_background]
2836
        mov     eax, [img_background]
2736
        test    ecx, ecx
2837
        test    ecx, ecx
2737
        jz      @f
2838
        jz      @f
2738
        cmp     eax, static_background_data
2839
        cmp     eax, static_background_data
2739
        jz      .ret
2840
        jz      .ret
2740
;--------------------------------------
2841
;--------------------------------------
2741
align 4
2842
align 4
2742
@@:
2843
@@:
2743
        mov     ebx, [mem_BACKGROUND]
2844
        mov     ebx, [mem_BACKGROUND]
2744
        add     ebx, 4095
2845
        add     ebx, 4095
2745
        and     ebx, -4096
2846
        and     ebx, -4096
2746
        sub     ebx, 4
2847
        sub     ebx, 4
2747
        cmp     ecx, ebx
2848
        cmp     ecx, ebx
2748
        ja      .ret
2849
        ja      .ret
2749
 
2850
 
2750
        mov     ebx, [eax+ecx]
2851
        mov     ebx, [eax+ecx]
2751
        and     ebx, 0xFF000000;255*256*256*256
2852
        and     ebx, 0xFF000000;255*256*256*256
2752
        and     edx, 0x00FFFFFF;255*256*256+255*256+255
2853
        and     edx, 0x00FFFFFF;255*256*256+255*256+255
2753
        add     edx, ebx
2854
        add     edx, ebx
2754
        mov     [eax+ecx], edx
2855
        mov     [eax+ecx], edx
2755
;--------------------------------------
2856
;--------------------------------------
2756
align 4
2857
align 4
2757
.ret:
2858
.ret:
2758
        ret
2859
        ret
2759
;------------------------------------------------------------------------------
2860
;------------------------------------------------------------------------------
2760
align 4
2861
align 4
2761
nosb2:
2862
nosb2:
2762
        cmp     ebx, 3                     ; DRAW BACKGROUND
2863
        cmp     ebx, 3                     ; DRAW BACKGROUND
2763
        jnz     nosb3
2864
        jnz     nosb3
2764
;--------------------------------------
2865
;--------------------------------------
2765
align 4
2866
align 4
2766
draw_background_temp:
2867
draw_background_temp:
2767
        mov     [background_defined], 1
2868
        mov     [background_defined], 1
2768
        call    force_redraw_background
2869
        call    force_redraw_background
2769
;--------------------------------------
2870
;--------------------------------------
2770
align 4
2871
align 4
2771
nosb31:
2872
nosb31:
2772
        ret
2873
        ret
2773
;------------------------------------------------------------------------------
2874
;------------------------------------------------------------------------------
2774
align 4
2875
align 4
2775
nosb3:
2876
nosb3:
2776
        cmp     ebx, 4                     ; TILED / STRETCHED
2877
        cmp     ebx, 4                     ; TILED / STRETCHED
2777
        jnz     nosb4
2878
        jnz     nosb4
2778
        cmp     ecx, [BgrDrawMode]
2879
        cmp     ecx, [BgrDrawMode]
2779
        je      nosb41
2880
        je      nosb41
2780
        mov     [BgrDrawMode], ecx
2881
        mov     [BgrDrawMode], ecx
2781
;--------------------------------------
2882
;--------------------------------------
2782
align 4
2883
align 4
2783
nosb41:
2884
nosb41:
2784
        ret
2885
        ret
2785
;------------------------------------------------------------------------------
2886
;------------------------------------------------------------------------------
2786
align 4
2887
align 4
2787
nosb4:
2888
nosb4:
2788
        cmp     ebx, 5                     ; BLOCK MOVE TO BGR
2889
        cmp     ebx, 5                     ; BLOCK MOVE TO BGR
2789
        jnz     nosb5
2890
        jnz     nosb5
2790
        cmp     [img_background], static_background_data
2891
        cmp     [img_background], static_background_data
2791
        jnz     @f
2892
        jnz     @f
2792
        test    edx, edx
2893
        test    edx, edx
2793
        jnz     .fin
2894
        jnz     .fin
2794
        cmp     esi, 4
2895
        cmp     esi, 4
2795
        ja      .fin
2896
        ja      .fin
2796
;--------------------------------------
2897
;--------------------------------------
2797
align 4
2898
align 4
2798
@@:
2899
@@:
2799
  ; bughere
2900
  ; bughere
2800
        mov     eax, ecx
2901
        mov     eax, ecx
2801
        mov     ebx, edx
2902
        mov     ebx, edx
2802
        add     ebx, [img_background];IMG_BACKGROUND
2903
        add     ebx, [img_background];IMG_BACKGROUND
2803
        mov     ecx, esi
2904
        mov     ecx, esi
2804
        call    memmove
2905
        call    memmove
2805
;--------------------------------------
2906
;--------------------------------------
2806
align 4
2907
align 4
2807
.fin:
2908
.fin:
2808
        ret
2909
        ret
2809
;------------------------------------------------------------------------------
2910
;------------------------------------------------------------------------------
2810
align 4
2911
align 4
2811
nosb5:
2912
nosb5:
2812
        cmp     ebx, 6
2913
        cmp     ebx, 6
2813
        jnz     nosb6
2914
        jnz     nosb6
2814
;--------------------------------------
2915
;--------------------------------------
2815
align 4
2916
align 4
2816
;;Maxis use atomic bts for mutex 4.4.2009
2917
;;Maxis use atomic bts for mutex 4.4.2009
2817
@@:
2918
@@:
2818
        bts     dword [bgrlock], 0
2919
        bts     dword [bgrlock], 0
2819
        jnc     @f
2920
        jnc     @f
2820
        call    change_task
2921
        call    change_task
2821
        jmp     @b
2922
        jmp     @b
2822
;--------------------------------------
2923
;--------------------------------------
2823
align 4
2924
align 4
2824
@@:
2925
@@:
2825
        mov     eax, [CURRENT_TASK]
2926
        mov     eax, [CURRENT_TASK]
2826
        mov     [bgrlockpid], eax
2927
        mov     [bgrlockpid], eax
2827
        cmp     [img_background], static_background_data
2928
        cmp     [img_background], static_background_data
2828
        jz      .nomem
2929
        jz      .nomem
2829
        stdcall user_alloc, [mem_BACKGROUND]
2930
        stdcall user_alloc, [mem_BACKGROUND]
2830
        mov     [esp+32], eax
2931
        mov     [esp+32], eax
2831
        test    eax, eax
2932
        test    eax, eax
2832
        jz      .nomem
2933
        jz      .nomem
2833
        mov     ebx, eax
2934
        mov     ebx, eax
2834
        shr     ebx, 12
2935
        shr     ebx, 12
2835
        or      dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2936
        or      dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2836
        mov     esi, [img_background]
2937
        mov     esi, [img_background]
2837
        shr     esi, 12
2938
        shr     esi, 12
2838
        mov     ecx, [mem_BACKGROUND]
2939
        mov     ecx, [mem_BACKGROUND]
2839
        add     ecx, 0xFFF
2940
        add     ecx, 0xFFF
2840
        shr     ecx, 12
2941
        shr     ecx, 12
2841
;--------------------------------------
2942
;--------------------------------------
2842
align 4
2943
align 4
2843
.z:
2944
.z:
2844
        mov     eax, [page_tabs+ebx*4]
2945
        mov     eax, [page_tabs+ebx*4]
2845
        test    al, 1
2946
        test    al, 1
2846
        jz      @f
2947
        jz      @f
2847
        call    free_page
2948
        call    free_page
2848
;--------------------------------------
2949
;--------------------------------------
2849
align 4
2950
align 4
2850
@@:
2951
@@:
2851
        mov     eax, [page_tabs+esi*4]
2952
        mov     eax, [page_tabs+esi*4]
2852
        or      al, PG_UWR
2953
        or      al, PG_UWR
2853
        mov     [page_tabs+ebx*4], eax
2954
        mov     [page_tabs+ebx*4], eax
2854
        mov     eax, ebx
2955
        mov     eax, ebx
2855
        shl     eax, 12
2956
        shl     eax, 12
2856
        invlpg  [eax]
2957
        invlpg  [eax]
2857
        inc     ebx
2958
        inc     ebx
2858
        inc     esi
2959
        inc     esi
2859
        loop    .z
2960
        loop    .z
2860
        ret
2961
        ret
2861
;--------------------------------------
2962
;--------------------------------------
2862
align 4
2963
align 4
2863
.nomem:
2964
.nomem:
2864
        and     [bgrlockpid], 0
2965
        and     [bgrlockpid], 0
2865
        mov     [bgrlock], 0
2966
        mov     [bgrlock], 0
2866
;------------------------------------------------------------------------------
2967
;------------------------------------------------------------------------------
2867
align 4
2968
align 4
2868
nosb6:
2969
nosb6:
2869
        cmp     ebx, 7
2970
        cmp     ebx, 7
2870
        jnz     nosb7
2971
        jnz     nosb7
2871
        cmp     [bgrlock], 0
2972
        cmp     [bgrlock], 0
2872
        jz      .err
2973
        jz      .err
2873
        mov     eax, [CURRENT_TASK]
2974
        mov     eax, [CURRENT_TASK]
2874
        cmp     [bgrlockpid], eax
2975
        cmp     [bgrlockpid], eax
2875
        jnz     .err
2976
        jnz     .err
2876
        mov     eax, ecx
2977
        mov     eax, ecx
2877
        mov     ebx, ecx
2978
        mov     ebx, ecx
2878
        shr     eax, 12
2979
        shr     eax, 12
2879
        mov     ecx, [page_tabs+(eax-1)*4]
2980
        mov     ecx, [page_tabs+(eax-1)*4]
2880
        test    cl, USED_BLOCK+DONT_FREE_BLOCK
2981
        test    cl, USED_BLOCK+DONT_FREE_BLOCK
2881
        jz      .err
2982
        jz      .err
2882
        jnp     .err
2983
        jnp     .err
2883
        push    eax
2984
        push    eax
2884
        shr     ecx, 12
2985
        shr     ecx, 12
2885
        dec     ecx
2986
        dec     ecx
2886
;--------------------------------------
2987
;--------------------------------------
2887
align 4
2988
align 4
2888
@@:
2989
@@:
2889
        and     dword [page_tabs+eax*4], 0
2990
        and     dword [page_tabs+eax*4], 0
2890
        mov     edx, eax
2991
        mov     edx, eax
2891
        shl     edx, 12
2992
        shl     edx, 12
2892
        push    eax
2993
        push    eax
2893
        invlpg  [edx]
2994
        invlpg  [edx]
2894
        pop     eax
2995
        pop     eax
2895
        inc     eax
2996
        inc     eax
2896
        loop    @b
2997
        loop    @b
2897
        pop     eax
2998
        pop     eax
2898
        and     dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2999
        and     dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2899
        stdcall user_free, ebx
3000
        stdcall user_free, ebx
2900
        mov     [esp+32], eax
3001
        mov     [esp+32], eax
2901
        and     [bgrlockpid], 0
3002
        and     [bgrlockpid], 0
2902
        mov     [bgrlock], 0
3003
        mov     [bgrlock], 0
2903
        ret
3004
        ret
2904
;--------------------------------------
3005
;--------------------------------------
2905
align 4
3006
align 4
2906
.err:
3007
.err:
2907
        and     dword [esp+32], 0
3008
        and     dword [esp+32], 0
2908
        ret
3009
        ret
2909
;------------------------------------------------------------------------------
3010
;------------------------------------------------------------------------------
2910
align 4
3011
align 4
2911
nosb7:
3012
nosb7:
2912
        cmp     ebx, 8
3013
        cmp     ebx, 8
2913
        jnz     nosb8
3014
        jnz     nosb8
2914
 
3015
 
2915
        mov     ecx, [current_slot]
3016
        mov     ecx, [current_slot]
2916
        xor     eax, eax
3017
        xor     eax, eax
2917
        xchg    eax, [ecx+APPDATA.draw_bgr_x]
3018
        xchg    eax, [ecx+APPDATA.draw_bgr_x]
2918
        mov     [esp + 32], eax ; eax = [left]*65536 + [right]
3019
        mov     [esp + 32], eax ; eax = [left]*65536 + [right]
2919
        xor     eax, eax
3020
        xor     eax, eax
2920
        xchg    eax, [ecx+APPDATA.draw_bgr_y]
3021
        xchg    eax, [ecx+APPDATA.draw_bgr_y]
2921
        mov     [esp + 20], eax ; ebx = [top]*65536 + [bottom]
3022
        mov     [esp + 20], eax ; ebx = [top]*65536 + [bottom]
2922
        ret
3023
        ret
2923
;------------------------------------------------------------------------------
3024
;------------------------------------------------------------------------------
2924
align 4
3025
align 4
2925
nosb8:
3026
nosb8:
2926
        cmp     ebx, 9
3027
        cmp     ebx, 9
2927
        jnz     nosb9
3028
        jnz     nosb9
2928
; ecx = [left]*65536 + [right]
3029
; ecx = [left]*65536 + [right]
2929
; edx = [top]*65536 + [bottom]
3030
; edx = [top]*65536 + [bottom]
2930
        mov     eax, [_display.width]
3031
        mov     eax, [_display.width]
2931
        mov     ebx, [_display.height]
3032
        mov     ebx, [_display.height]
2932
        dec     eax
3033
        dec     eax
2933
        dec     ebx
3034
        dec     ebx
2934
; check [right]
3035
; check [right]
2935
        cmp     cx, ax
3036
        cmp     cx, ax
2936
        ja      .exit
3037
        ja      .exit
2937
; check [left]
3038
; check [left]
2938
        ror     ecx, 16
3039
        ror     ecx, 16
2939
        cmp     cx, ax
3040
        cmp     cx, ax
2940
        ja      .exit
3041
        ja      .exit
2941
; check [bottom]
3042
; check [bottom]
2942
        cmp     dx, bx
3043
        cmp     dx, bx
2943
        ja      .exit
3044
        ja      .exit
2944
; check [top]
3045
; check [top]
2945
        ror     edx, 16
3046
        ror     edx, 16
2946
        cmp     dx, bx
3047
        cmp     dx, bx
2947
        ja      .exit
3048
        ja      .exit
2948
 
3049
 
2949
        movzx   eax, cx  ; [left]
3050
        movzx   eax, cx  ; [left]
2950
        movzx   ebx, dx  ; [top]
3051
        movzx   ebx, dx  ; [top]
2951
 
3052
 
2952
        shr     ecx, 16 ; [right]
3053
        shr     ecx, 16 ; [right]
2953
        shr     edx, 16 ; [bottom]
3054
        shr     edx, 16 ; [bottom]
2954
 
3055
 
2955
        mov     [background_defined], 1
3056
        mov     [background_defined], 1
2956
 
3057
 
2957
        mov     [draw_data+32 + RECT.left], eax
3058
        mov     [draw_data+32 + RECT.left], eax
2958
        mov     [draw_data+32 + RECT.top], ebx
3059
        mov     [draw_data+32 + RECT.top], ebx
2959
 
3060
 
2960
        mov     [draw_data+32 + RECT.right], ecx
3061
        mov     [draw_data+32 + RECT.right], ecx
2961
        mov     [draw_data+32 + RECT.bottom], edx
3062
        mov     [draw_data+32 + RECT.bottom], edx
2962
 
3063
 
2963
        inc     byte[REDRAW_BACKGROUND]
3064
        inc     byte[REDRAW_BACKGROUND]
2964
        call    wakeup_osloop
3065
        call    wakeup_osloop
2965
;--------------------------------------
3066
;--------------------------------------
2966
align 4
3067
align 4
2967
.exit:
3068
.exit:
2968
        ret
3069
        ret
2969
;------------------------------------------------------------------------------
3070
;------------------------------------------------------------------------------
2970
align 4
3071
align 4
2971
nosb9:
3072
nosb9:
2972
        ret
3073
        ret
2973
;------------------------------------------------------------------------------
3074
;------------------------------------------------------------------------------
2974
align 4
3075
align 4
2975
uglobal
3076
uglobal
2976
  BG_Rect_X_left_right  dd   0x0
3077
  BG_Rect_X_left_right  dd   0x0
2977
  BG_Rect_Y_top_bottom  dd   0x0
3078
  BG_Rect_Y_top_bottom  dd   0x0
2978
endg
3079
endg
2979
;------------------------------------------------------------------------------
3080
;------------------------------------------------------------------------------
2980
align 4
3081
align 4
2981
force_redraw_background:
3082
force_redraw_background:
2982
        and     [draw_data+32 + RECT.left], 0
3083
        and     [draw_data+32 + RECT.left], 0
2983
        and     [draw_data+32 + RECT.top], 0
3084
        and     [draw_data+32 + RECT.top], 0
2984
        push    eax ebx
3085
        push    eax ebx
2985
        mov     eax, [_display.width]
3086
        mov     eax, [_display.width]
2986
        mov     ebx, [_display.height]
3087
        mov     ebx, [_display.height]
2987
        dec     eax
3088
        dec     eax
2988
        dec     ebx
3089
        dec     ebx
2989
        mov     [draw_data+32 + RECT.right], eax
3090
        mov     [draw_data+32 + RECT.right], eax
2990
        mov     [draw_data+32 + RECT.bottom], ebx
3091
        mov     [draw_data+32 + RECT.bottom], ebx
2991
        pop     ebx eax
3092
        pop     ebx eax
2992
        inc     byte[REDRAW_BACKGROUND]
3093
        inc     byte[REDRAW_BACKGROUND]
2993
        call    wakeup_osloop
3094
        call    wakeup_osloop
2994
        ret
3095
        ret
2995
;------------------------------------------------------------------------------
3096
;------------------------------------------------------------------------------
2996
align 4
3097
align 4
2997
sys_getbackground:
3098
sys_getbackground:
2998
;    cmp   eax,1                                  ; SIZE
3099
;    cmp   eax,1                                  ; SIZE
2999
        dec     ebx
3100
        dec     ebx
3000
        jnz     nogb1
3101
        jnz     nogb1
3001
        mov     eax, [BgrDataWidth]
3102
        mov     eax, [BgrDataWidth]
3002
        shl     eax, 16
3103
        shl     eax, 16
3003
        mov     ax, word [BgrDataHeight]
3104
        mov     ax, word [BgrDataHeight]
3004
        mov     [esp+32], eax
3105
        mov     [esp+32], eax
3005
        ret
3106
        ret
3006
;------------------------------------------------------------------------------
3107
;------------------------------------------------------------------------------
3007
align 4
3108
align 4
3008
nogb1:
3109
nogb1:
3009
;    cmp   eax,2                                  ; PIXEL
3110
;    cmp   eax,2                                  ; PIXEL
3010
        dec     ebx
3111
        dec     ebx
3011
        jnz     nogb2
3112
        jnz     nogb2
3012
 
3113
 
3013
        mov     eax, [img_background]
3114
        mov     eax, [img_background]
3014
        test    ecx, ecx
3115
        test    ecx, ecx
3015
        jz      @f
3116
        jz      @f
3016
        cmp     eax, static_background_data
3117
        cmp     eax, static_background_data
3017
        jz      .ret
3118
        jz      .ret
3018
;--------------------------------------
3119
;--------------------------------------
3019
align 4
3120
align 4
3020
@@:
3121
@@:
3021
        mov     ebx, [mem_BACKGROUND]
3122
        mov     ebx, [mem_BACKGROUND]
3022
        add     ebx, 4095
3123
        add     ebx, 4095
3023
        and     ebx, -4096
3124
        and     ebx, -4096
3024
        sub     ebx, 4
3125
        sub     ebx, 4
3025
        cmp     ecx, ebx
3126
        cmp     ecx, ebx
3026
        ja      .ret
3127
        ja      .ret
3027
 
3128
 
3028
        mov     eax, [ecx+eax]
3129
        mov     eax, [ecx+eax]
3029
 
3130
 
3030
        and     eax, 0xFFFFFF
3131
        and     eax, 0xFFFFFF
3031
        mov     [esp+32], eax
3132
        mov     [esp+32], eax
3032
;--------------------------------------
3133
;--------------------------------------
3033
align 4
3134
align 4
3034
.ret:
3135
.ret:
3035
        ret
3136
        ret
3036
;------------------------------------------------------------------------------
3137
;------------------------------------------------------------------------------
3037
align 4
3138
align 4
3038
nogb2:
3139
nogb2:
3039
 
3140
 
3040
;    cmp   eax,4                                  ; TILED / STRETCHED
3141
;    cmp   eax,4                                  ; TILED / STRETCHED
3041
        dec     ebx
3142
        dec     ebx
3042
        dec     ebx
3143
        dec     ebx
3043
        jnz     nogb4
3144
        jnz     nogb4
3044
        mov     eax, [BgrDrawMode]
3145
        mov     eax, [BgrDrawMode]
3045
;--------------------------------------
3146
;--------------------------------------
3046
align 4
3147
align 4
3047
nogb4:
3148
nogb4:
3048
        mov     [esp+32], eax
3149
        mov     [esp+32], eax
3049
        ret
3150
        ret
3050
;------------------------------------------------------------------------------
3151
;------------------------------------------------------------------------------
3051
align 4
3152
align 4
3052
sys_getkey:
3153
sys_getkey:
3053
        mov     [esp + 32], dword 1
3154
        mov     [esp + 32], dword 1
3054
        ; test main buffer
3155
        ; test main buffer
3055
        mov     ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
3156
        mov     ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
3056
        movzx   ecx, word [WIN_STACK + ebx * 2]
3157
        movzx   ecx, word [WIN_STACK + ebx * 2]
3057
        mov     edx, [TASK_COUNT]
3158
        mov     edx, [TASK_COUNT]
3058
        cmp     ecx, edx
3159
        cmp     ecx, edx
3059
        jne     .finish
3160
        jne     .finish
3060
        cmp     [KEY_COUNT], byte 0
3161
        cmp     [KEY_COUNT], byte 0
3061
        je      .finish
3162
        je      .finish
3062
        movzx   ax, byte [KEY_BUFF + 120 + 2]
3163
        movzx   ax, byte [KEY_BUFF + 120 + 2]
3063
        shl     eax, 8
3164
        shl     eax, 8
3064
        mov     al, byte [KEY_BUFF]
3165
        mov     al, byte [KEY_BUFF]
3065
        shl     eax, 8
3166
        shl     eax, 8
3066
        push    eax
3167
        push    eax
3067
        dec     byte [KEY_COUNT]
3168
        dec     byte [KEY_COUNT]
3068
        and     byte [KEY_COUNT], 127
3169
        and     byte [KEY_COUNT], 127
3069
        movzx   ecx, byte [KEY_COUNT]
3170
        movzx   ecx, byte [KEY_COUNT]
3070
        add     ecx, 2
3171
        add     ecx, 2
3071
        mov     eax, KEY_BUFF + 1
3172
        mov     eax, KEY_BUFF + 1
3072
        mov     ebx, KEY_BUFF
3173
        mov     ebx, KEY_BUFF
3073
        call    memmove
3174
        call    memmove
3074
        add     eax, 120 + 2
3175
        add     eax, 120 + 2
3075
        add     ebx, 120 + 2
3176
        add     ebx, 120 + 2
3076
        call    memmove
3177
        call    memmove
3077
        pop     eax
3178
        pop     eax
3078
;--------------------------------------
3179
;--------------------------------------
3079
align 4
3180
align 4
3080
.ret_eax:
3181
.ret_eax:
3081
        mov     [esp + 32], eax
3182
        mov     [esp + 32], eax
3082
        ret
3183
        ret
3083
;--------------------------------------
3184
;--------------------------------------
3084
align 4
3185
align 4
3085
.finish:
3186
.finish:
3086
; test hotkeys buffer
3187
; test hotkeys buffer
3087
        mov     ecx, hotkey_buffer
3188
        mov     ecx, hotkey_buffer
3088
;--------------------------------------
3189
;--------------------------------------
3089
align 4
3190
align 4
3090
@@:
3191
@@:
3091
        cmp     [ecx], ebx
3192
        cmp     [ecx], ebx
3092
        jz      .found
3193
        jz      .found
3093
        add     ecx, 8
3194
        add     ecx, 8
3094
        cmp     ecx, hotkey_buffer + 120 * 8
3195
        cmp     ecx, hotkey_buffer + 120 * 8
3095
        jb      @b
3196
        jb      @b
3096
        ret
3197
        ret
3097
;--------------------------------------
3198
;--------------------------------------
3098
align 4
3199
align 4
3099
.found:
3200
.found:
3100
        mov     ax, [ecx + 6]
3201
        mov     ax, [ecx + 6]
3101
        shl     eax, 16
3202
        shl     eax, 16
3102
        mov     ah, [ecx + 4]
3203
        mov     ah, [ecx + 4]
3103
        mov     al, 2
3204
        mov     al, 2
3104
        and     dword [ecx + 4], 0
3205
        and     dword [ecx + 4], 0
3105
        and     dword [ecx], 0
3206
        and     dword [ecx], 0
3106
        jmp     .ret_eax
3207
        jmp     .ret_eax
3107
;------------------------------------------------------------------------------
3208
;------------------------------------------------------------------------------
3108
align 4
3209
align 4
3109
sys_getbutton:
3210
sys_getbutton:
3110
        mov     ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
3211
        mov     ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
3111
        mov     [esp + 32], dword 1
3212
        mov     [esp + 32], dword 1
3112
        movzx   ecx, word [WIN_STACK + ebx * 2]
3213
        movzx   ecx, word [WIN_STACK + ebx * 2]
3113
        mov     edx, [TASK_COUNT] ; less than 256 processes
3214
        mov     edx, [TASK_COUNT] ; less than 256 processes
3114
        cmp     ecx, edx
3215
        cmp     ecx, edx
3115
        jne     .exit
3216
        jne     .exit
3116
        movzx   eax, byte [BTN_COUNT]
3217
        movzx   eax, byte [BTN_COUNT]
3117
        test    eax, eax
3218
        test    eax, eax
3118
        jz      .exit
3219
        jz      .exit
3119
        mov     eax, [BTN_BUFF]
3220
        mov     eax, [BTN_BUFF]
3120
        and     al, 0xFE                                    ; delete left button bit
3221
        and     al, 0xFE                                    ; delete left button bit
3121
        mov     [BTN_COUNT], byte 0
3222
        mov     [BTN_COUNT], byte 0
3122
        mov     [esp + 32], eax
3223
        mov     [esp + 32], eax
3123
;--------------------------------------
3224
;--------------------------------------
3124
align 4
3225
align 4
3125
.exit:
3226
.exit:
3126
        ret
3227
        ret
3127
;------------------------------------------------------------------------------
3228
;------------------------------------------------------------------------------
3128
align 4
3229
align 4
3129
sys_cpuusage:
3230
sys_cpuusage:
3130
 
3231
 
3131
;  RETURN:
3232
;  RETURN:
3132
;
3233
;
3133
;  +00 dword     process cpu usage
3234
;  +00 dword     process cpu usage
3134
;  +04  word     position in windowing stack
3235
;  +04  word     position in windowing stack
3135
;  +06  word     windowing stack value at current position (cpu nro)
3236
;  +06  word     windowing stack value at current position (cpu nro)
3136
;  +10 12 bytes  name
3237
;  +10 12 bytes  name
3137
;  +22 dword     start in mem
3238
;  +22 dword     start in mem
3138
;  +26 dword     used mem
3239
;  +26 dword     used mem
3139
;  +30 dword     PID , process idenfification number
3240
;  +30 dword     PID , process idenfification number
3140
;
3241
;
3141
 
3242
 
3142
        cmp     ecx, -1 ; who am I ?
3243
        cmp     ecx, -1 ; who am I ?
3143
        jne     .no_who_am_i
3244
        jne     .no_who_am_i
3144
        mov     ecx, [CURRENT_TASK]
3245
        mov     ecx, [CURRENT_TASK]
3145
  .no_who_am_i:
3246
  .no_who_am_i:
3146
        cmp     ecx, max_processes
3247
        cmp     ecx, max_processes
3147
        ja      .nofillbuf
3248
        ja      .nofillbuf
3148
 
3249
 
3149
; +4: word: position of the window of thread in the window stack
3250
; +4: word: position of the window of thread in the window stack
3150
        mov     ax, [WIN_STACK + ecx * 2]
3251
        mov     ax, [WIN_STACK + ecx * 2]
3151
        mov     [ebx+4], ax
3252
        mov     [ebx+4], ax
3152
; +6: word: number of the thread slot, which window has in the window stack
3253
; +6: word: number of the thread slot, which window has in the window stack
3153
;           position ecx (has no relation to the specific thread)
3254
;           position ecx (has no relation to the specific thread)
3154
        mov     ax, [WIN_POS + ecx * 2]
3255
        mov     ax, [WIN_POS + ecx * 2]
3155
        mov     [ebx+6], ax
3256
        mov     [ebx+6], ax
3156
 
3257
 
3157
        shl     ecx, 5
3258
        shl     ecx, 5
3158
 
3259
 
3159
; +0: dword: memory usage
3260
; +0: dword: memory usage
3160
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
3261
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
3161
        mov     [ebx], eax
3262
        mov     [ebx], eax
3162
; +10: 11 bytes: name of the process
3263
; +10: 11 bytes: name of the process
3163
        push    ecx
3264
        push    ecx
3164
        lea     eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
3265
        lea     eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
3165
        add     ebx, 10
3266
        add     ebx, 10
3166
        mov     ecx, 11
3267
        mov     ecx, 11
3167
        call    memmove
3268
        call    memmove
3168
        pop     ecx
3269
        pop     ecx
3169
 
3270
 
3170
; +22: address of the process in memory
3271
; +22: address of the process in memory
3171
; +26: size of used memory - 1
3272
; +26: size of used memory - 1
3172
        push    edi
3273
        push    edi
3173
        lea     edi, [ebx+12]
3274
        lea     edi, [ebx+12]
3174
        xor     eax, eax
3275
        xor     eax, eax
3175
        mov     edx, 0x100000*16
3276
        mov     edx, 0x100000*16
3176
        cmp     ecx, 1 shl 5
3277
        cmp     ecx, 1 shl 5
3177
        je      .os_mem
3278
        je      .os_mem
3178
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.process]
3279
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.process]
3179
        mov     edx, [edx+PROC.mem_used]
3280
        mov     edx, [edx+PROC.mem_used]
3180
        mov     eax, std_application_base_address
3281
        mov     eax, std_application_base_address
3181
.os_mem:
3282
.os_mem:
3182
        stosd
3283
        stosd
3183
        lea     eax, [edx-1]
3284
        lea     eax, [edx-1]
3184
        stosd
3285
        stosd
3185
 
3286
 
3186
; +30: PID/TID
3287
; +30: PID/TID
3187
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
3288
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
3188
        stosd
3289
        stosd
3189
 
3290
 
3190
    ; window position and size
3291
    ; window position and size
3191
        push    esi
3292
        push    esi
3192
        lea     esi, [ecx + window_data + WDATA.box]
3293
        lea     esi, [ecx + window_data + WDATA.box]
3193
        movsd
3294
        movsd
3194
        movsd
3295
        movsd
3195
        movsd
3296
        movsd
3196
        movsd
3297
        movsd
3197
 
3298
 
3198
    ; Process state (+50)
3299
    ; Process state (+50)
3199
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
3300
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
3200
        stosd
3301
        stosd
3201
 
3302
 
3202
    ; Window client area box
3303
    ; Window client area box
3203
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
3304
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
3204
        movsd
3305
        movsd
3205
        movsd
3306
        movsd
3206
        movsd
3307
        movsd
3207
        movsd
3308
        movsd
3208
 
3309
 
3209
    ; Window state
3310
    ; Window state
3210
        mov     al, [ecx+window_data+WDATA.fl_wstate]
3311
        mov     al, [ecx+window_data+WDATA.fl_wstate]
3211
        stosb
3312
        stosb
3212
 
3313
 
3213
    ; Event mask (+71)
3314
    ; Event mask (+71)
3214
        mov     EAX, dword [ECX+CURRENT_TASK+TASKDATA.event_mask]
3315
        mov     EAX, dword [ECX+CURRENT_TASK+TASKDATA.event_mask]
3215
        stosd
3316
        stosd
3216
 
3317
 
3217
    ; Keyboard mode (+75)
3318
    ; Keyboard mode (+75)
3218
        mov     al, byte [ecx*8 + SLOT_BASE + APPDATA.keyboard_mode]
3319
        mov     al, byte [ecx*8 + SLOT_BASE + APPDATA.keyboard_mode]
3219
        stosb
3320
        stosb
3220
 
3321
 
3221
        pop     esi
3322
        pop     esi
3222
        pop     edi
3323
        pop     edi
3223
 
3324
 
3224
.nofillbuf:
3325
.nofillbuf:
3225
    ; return number of processes
3326
    ; return number of processes
3226
 
3327
 
3227
        mov     eax, [TASK_COUNT]
3328
        mov     eax, [TASK_COUNT]
3228
        mov     [esp+32], eax
3329
        mov     [esp+32], eax
3229
        ret
3330
        ret
3230
 
3331
 
3231
align 4
3332
align 4
3232
sys_clock:
3333
sys_clock:
3233
        cli
3334
        cli
3234
  ; Mikhail Lisovin  xx Jan 2005
3335
  ; Mikhail Lisovin  xx Jan 2005
3235
  @@:
3336
  @@:
3236
        mov     al, 10
3337
        mov     al, 10
3237
        out     0x70, al
3338
        out     0x70, al
3238
        in      al, 0x71
3339
        in      al, 0x71
3239
        test    al, al
3340
        test    al, al
3240
        jns     @f
3341
        jns     @f
3241
        mov     esi, 1
3342
        mov     esi, 1
3242
        call    delay_ms
3343
        call    delay_ms
3243
        jmp     @b
3344
        jmp     @b
3244
  @@:
3345
  @@:
3245
  ; end Lisovin's fix
3346
  ; end Lisovin's fix
3246
 
3347
 
3247
        xor     al, al        ; seconds
3348
        xor     al, al        ; seconds
3248
        out     0x70, al
3349
        out     0x70, al
3249
        in      al, 0x71
3350
        in      al, 0x71
3250
        movzx   ecx, al
3351
        movzx   ecx, al
3251
        mov     al, 02        ; minutes
3352
        mov     al, 02        ; minutes
3252
        shl     ecx, 16
3353
        shl     ecx, 16
3253
        out     0x70, al
3354
        out     0x70, al
3254
        in      al, 0x71
3355
        in      al, 0x71
3255
        movzx   edx, al
3356
        movzx   edx, al
3256
        mov     al, 04        ; hours
3357
        mov     al, 04        ; hours
3257
        shl     edx, 8
3358
        shl     edx, 8
3258
        out     0x70, al
3359
        out     0x70, al
3259
        in      al, 0x71
3360
        in      al, 0x71
3260
        add     ecx, edx
3361
        add     ecx, edx
3261
        movzx   edx, al
3362
        movzx   edx, al
3262
        add     ecx, edx
3363
        add     ecx, edx
3263
        sti
3364
        sti
3264
        mov     [esp + 32], ecx
3365
        mov     [esp + 32], ecx
3265
        ret
3366
        ret
3266
 
3367
 
3267
 
3368
 
3268
align 4
3369
align 4
3269
 
3370
 
3270
sys_date:
3371
sys_date:
3271
 
3372
 
3272
        cli
3373
        cli
3273
  @@:
3374
  @@:
3274
        mov     al, 10
3375
        mov     al, 10
3275
        out     0x70, al
3376
        out     0x70, al
3276
        in      al, 0x71
3377
        in      al, 0x71
3277
        test    al, al
3378
        test    al, al
3278
        jns     @f
3379
        jns     @f
3279
        mov     esi, 1
3380
        mov     esi, 1
3280
        call    delay_ms
3381
        call    delay_ms
3281
        jmp     @b
3382
        jmp     @b
3282
  @@:
3383
  @@:
3283
 
3384
 
3284
        mov     ch, 0
3385
        mov     ch, 0
3285
        mov     al, 7           ; date
3386
        mov     al, 7           ; date
3286
        out     0x70, al
3387
        out     0x70, al
3287
        in      al, 0x71
3388
        in      al, 0x71
3288
        mov     cl, al
3389
        mov     cl, al
3289
        mov     al, 8           ; month
3390
        mov     al, 8           ; month
3290
        shl     ecx, 16
3391
        shl     ecx, 16
3291
        out     0x70, al
3392
        out     0x70, al
3292
        in      al, 0x71
3393
        in      al, 0x71
3293
        mov     ch, al
3394
        mov     ch, al
3294
        mov     al, 9           ; year
3395
        mov     al, 9           ; year
3295
        out     0x70, al
3396
        out     0x70, al
3296
        in      al, 0x71
3397
        in      al, 0x71
3297
        mov     cl, al
3398
        mov     cl, al
3298
        sti
3399
        sti
3299
        mov     [esp+32], ecx
3400
        mov     [esp+32], ecx
3300
        ret
3401
        ret
3301
 
3402
 
3302
 
3403
 
3303
; redraw status
3404
; redraw status
3304
 
3405
 
3305
sys_redrawstat:
3406
sys_redrawstat:
3306
        cmp     ebx, 1
3407
        cmp     ebx, 1
3307
        jne     no_widgets_away
3408
        jne     no_widgets_away
3308
        ; buttons away
3409
        ; buttons away
3309
        mov     ecx, [CURRENT_TASK]
3410
        mov     ecx, [CURRENT_TASK]
3310
  sys_newba2:
3411
  sys_newba2:
3311
        mov     edi, [BTN_ADDR]
3412
        mov     edi, [BTN_ADDR]
3312
        cmp     [edi], dword 0  ; empty button list ?
3413
        cmp     [edi], dword 0  ; empty button list ?
3313
        je      end_of_buttons_away
3414
        je      end_of_buttons_away
3314
        movzx   ebx, word [edi]
3415
        movzx   ebx, word [edi]
3315
        inc     ebx
3416
        inc     ebx
3316
        mov     eax, edi
3417
        mov     eax, edi
3317
  sys_newba:
3418
  sys_newba:
3318
        dec     ebx
3419
        dec     ebx
3319
        jz      end_of_buttons_away
3420
        jz      end_of_buttons_away
3320
 
3421
 
3321
        add     eax, 0x10
3422
        add     eax, 0x10
3322
        cmp     cx, [eax]
3423
        cmp     cx, [eax]
3323
        jnz     sys_newba
3424
        jnz     sys_newba
3324
 
3425
 
3325
        push    eax ebx ecx
3426
        push    eax ebx ecx
3326
        mov     ecx, ebx
3427
        mov     ecx, ebx
3327
        inc     ecx
3428
        inc     ecx
3328
        shl     ecx, 4
3429
        shl     ecx, 4
3329
        mov     ebx, eax
3430
        mov     ebx, eax
3330
        add     eax, 0x10
3431
        add     eax, 0x10
3331
        call    memmove
3432
        call    memmove
3332
        dec     dword [edi]
3433
        dec     dword [edi]
3333
        pop     ecx ebx eax
3434
        pop     ecx ebx eax
3334
 
3435
 
3335
        jmp     sys_newba2
3436
        jmp     sys_newba2
3336
 
3437
 
3337
  end_of_buttons_away:
3438
  end_of_buttons_away:
3338
 
3439
 
3339
        ret
3440
        ret
3340
 
3441
 
3341
  no_widgets_away:
3442
  no_widgets_away:
3342
 
3443
 
3343
        cmp     ebx, 2
3444
        cmp     ebx, 2
3344
        jnz     srl1
3445
        jnz     srl1
3345
 
3446
 
3346
        mov     edx, [TASK_BASE]      ; return whole screen draw area for this app
3447
        mov     edx, [TASK_BASE]      ; return whole screen draw area for this app
3347
        add     edx, draw_data - CURRENT_TASK
3448
        add     edx, draw_data - CURRENT_TASK
3348
        mov     [edx + RECT.left], 0
3449
        mov     [edx + RECT.left], 0
3349
        mov     [edx + RECT.top], 0
3450
        mov     [edx + RECT.top], 0
3350
        mov     eax, [_display.width]
3451
        mov     eax, [_display.width]
3351
        dec     eax
3452
        dec     eax
3352
        mov     [edx + RECT.right], eax
3453
        mov     [edx + RECT.right], eax
3353
        mov     eax, [_display.height]
3454
        mov     eax, [_display.height]
3354
        dec     eax
3455
        dec     eax
3355
        mov     [edx + RECT.bottom], eax
3456
        mov     [edx + RECT.bottom], eax
3356
 
3457
 
3357
  srl1:
3458
  srl1:
3358
        ret
3459
        ret
3359
 
3460
 
3360
;ok - 100% work
3461
;ok - 100% work
3361
;nt - not tested
3462
;nt - not tested
3362
;---------------------------------------------------------------------------------------------
3463
;---------------------------------------------------------------------------------------------
3363
;eax
3464
;eax
3364
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3465
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3365
;1 - change task. Ret nothing. Block. ok.
3466
;1 - change task. Ret nothing. Block. ok.
3366
;2 - performance control
3467
;2 - performance control
3367
; ebx
3468
; ebx
3368
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3469
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3369
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3470
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3370
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3471
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3371
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3472
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3372
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3473
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3373
;eax
3474
;eax
3374
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3475
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3375
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3476
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3376
;---------------------------------------------------------------------------------------------
3477
;---------------------------------------------------------------------------------------------
3377
iglobal
3478
iglobal
3378
align 4
3479
align 4
3379
sheduler:
3480
sheduler:
3380
        dd      sys_sheduler.00
3481
        dd      sys_sheduler.00
3381
        dd      change_task
3482
        dd      change_task
3382
        dd      sys_sheduler.02
3483
        dd      sys_sheduler.02
3383
        dd      sys_sheduler.03
3484
        dd      sys_sheduler.03
3384
        dd      sys_sheduler.04
3485
        dd      sys_sheduler.04
3385
endg
3486
endg
3386
sys_sheduler:
3487
sys_sheduler:
3387
;rewritten by   29.12.2009
3488
;rewritten by   29.12.2009
3388
        jmp     dword [sheduler+ebx*4]
3489
        jmp     dword [sheduler+ebx*4]
3389
;.shed_counter:
3490
;.shed_counter:
3390
.00:
3491
.00:
3391
        mov     eax, [context_counter]
3492
        mov     eax, [context_counter]
3392
        mov     [esp+32], eax
3493
        mov     [esp+32], eax
3393
        ret
3494
        ret
3394
 
3495
 
3395
.02:
3496
.02:
3396
;.perf_control:
3497
;.perf_control:
3397
        inc     ebx                     ;before ebx=2, ebx=3
3498
        inc     ebx                     ;before ebx=2, ebx=3
3398
        cmp     ebx, ecx                ;if ecx=3, ebx=3
3499
        cmp     ebx, ecx                ;if ecx=3, ebx=3
3399
        jz      cache_disable
3500
        jz      cache_disable
3400
 
3501
 
3401
        dec     ebx                     ;ebx=2
3502
        dec     ebx                     ;ebx=2
3402
        cmp     ebx, ecx                ;
3503
        cmp     ebx, ecx                ;
3403
        jz      cache_enable            ;if ecx=2 and ebx=2
3504
        jz      cache_enable            ;if ecx=2 and ebx=2
3404
 
3505
 
3405
        dec     ebx                     ;ebx=1
3506
        dec     ebx                     ;ebx=1
3406
        cmp     ebx, ecx
3507
        cmp     ebx, ecx
3407
        jz      is_cache_enabled        ;if ecx=1 and ebx=1
3508
        jz      is_cache_enabled        ;if ecx=1 and ebx=1
3408
 
3509
 
3409
        dec     ebx
3510
        dec     ebx
3410
        test    ebx, ecx                ;ebx=0 and ecx=0
3511
        test    ebx, ecx                ;ebx=0 and ecx=0
3411
        jz      modify_pce              ;if ecx=0
3512
        jz      modify_pce              ;if ecx=0
3412
 
3513
 
3413
        ret
3514
        ret
3414
 
3515
 
3415
.03:
3516
.03:
3416
;.rdmsr_instr:
3517
;.rdmsr_instr:
3417
;now counter in ecx
3518
;now counter in ecx
3418
;(edx:eax) esi:edi => edx:esi
3519
;(edx:eax) esi:edi => edx:esi
3419
        mov     eax, esi
3520
        mov     eax, esi
3420
        mov     ecx, edx
3521
        mov     ecx, edx
3421
        rdmsr
3522
        rdmsr
3422
        mov     [esp+32], eax
3523
        mov     [esp+32], eax
3423
        mov     [esp+20], edx           ;ret in ebx?
3524
        mov     [esp+20], edx           ;ret in ebx?
3424
        ret
3525
        ret
3425
 
3526
 
3426
.04:
3527
.04:
3427
;.wrmsr_instr:
3528
;.wrmsr_instr:
3428
;now counter in ecx
3529
;now counter in ecx
3429
;(edx:eax) esi:edi => edx:esi
3530
;(edx:eax) esi:edi => edx:esi
3430
        ; Fast Call MSR can't be destroy
3531
        ; Fast Call MSR can't be destroy
3431
        ; Но MSR_AMD_EFER можно изменять, т.к. в этом регистре лиш
3532
        ; Но MSR_AMD_EFER можно изменять, т.к. в этом регистре лиш
3432
        ; включаются/выключаются расширенные возможности
3533
        ; включаются/выключаются расширенные возможности
3433
        cmp     edx, MSR_SYSENTER_CS
3534
        cmp     edx, MSR_SYSENTER_CS
3434
        je      @f
3535
        je      @f
3435
        cmp     edx, MSR_SYSENTER_ESP
3536
        cmp     edx, MSR_SYSENTER_ESP
3436
        je      @f
3537
        je      @f
3437
        cmp     edx, MSR_SYSENTER_EIP
3538
        cmp     edx, MSR_SYSENTER_EIP
3438
        je      @f
3539
        je      @f
3439
        cmp     edx, MSR_AMD_STAR
3540
        cmp     edx, MSR_AMD_STAR
3440
        je      @f
3541
        je      @f
3441
 
3542
 
3442
        mov     eax, esi
3543
        mov     eax, esi
3443
        mov     ecx, edx
3544
        mov     ecx, edx
3444
        wrmsr
3545
        wrmsr
3445
        ; mov   [esp + 32], eax
3546
        ; mov   [esp + 32], eax
3446
        ; mov   [esp + 20], edx ;ret in ebx?
3547
        ; mov   [esp + 20], edx ;ret in ebx?
3447
@@:
3548
@@:
3448
        ret
3549
        ret
3449
 
3550
 
3450
cache_disable:
3551
cache_disable:
3451
        mov     eax, cr0
3552
        mov     eax, cr0
3452
        or      eax, 01100000000000000000000000000000b
3553
        or      eax, 01100000000000000000000000000000b
3453
        mov     cr0, eax
3554
        mov     cr0, eax
3454
        wbinvd  ;set MESI
3555
        wbinvd  ;set MESI
3455
        ret
3556
        ret
3456
 
3557
 
3457
cache_enable:
3558
cache_enable:
3458
        mov     eax, cr0
3559
        mov     eax, cr0
3459
        and     eax, 10011111111111111111111111111111b
3560
        and     eax, 10011111111111111111111111111111b
3460
        mov     cr0, eax
3561
        mov     cr0, eax
3461
        ret
3562
        ret
3462
 
3563
 
3463
is_cache_enabled:
3564
is_cache_enabled:
3464
        mov     eax, cr0
3565
        mov     eax, cr0
3465
        mov     ebx, eax
3566
        mov     ebx, eax
3466
        and     eax, 01100000000000000000000000000000b
3567
        and     eax, 01100000000000000000000000000000b
3467
        jz      cache_disabled
3568
        jz      cache_disabled
3468
        mov     [esp+32], ebx
3569
        mov     [esp+32], ebx
3469
cache_disabled:
3570
cache_disabled:
3470
        mov     dword [esp+32], eax;0
3571
        mov     dword [esp+32], eax;0
3471
        ret
3572
        ret
3472
 
3573
 
3473
modify_pce:
3574
modify_pce:
3474
        mov     eax, cr4
3575
        mov     eax, cr4
3475
;       mov ebx,0
3576
;       mov ebx,0
3476
;       or  bx,100000000b ;pce
3577
;       or  bx,100000000b ;pce
3477
;       xor eax,ebx ;invert pce
3578
;       xor eax,ebx ;invert pce
3478
        bts     eax, 8;pce=cr4[8]
3579
        bts     eax, 8;pce=cr4[8]
3479
        mov     cr4, eax
3580
        mov     cr4, eax
3480
        mov     [esp+32], eax
3581
        mov     [esp+32], eax
3481
        ret
3582
        ret
3482
;---------------------------------------------------------------------------------------------
3583
;---------------------------------------------------------------------------------------------
3483
 
3584
 
3484
 
3585
 
3485
iglobal
3586
iglobal
3486
  cpustring db 'CPU',0
3587
  cpustring db 'CPU',0
3487
endg
3588
endg
3488
 
3589
 
3489
uglobal
3590
uglobal
3490
background_defined    db    0    ; diamond, 11.04.2006
3591
background_defined    db    0    ; diamond, 11.04.2006
3491
endg
3592
endg
3492
;-----------------------------------------------------------------------------
3593
;-----------------------------------------------------------------------------
3493
align 4
3594
align 4
3494
checkmisc:
3595
checkmisc:
3495
        cmp     [ctrl_alt_del], 1
3596
        cmp     [ctrl_alt_del], 1
3496
        jne     nocpustart
3597
        jne     nocpustart
3497
 
3598
 
3498
        mov     ebp, cpustring
3599
        mov     ebp, cpustring
3499
        call    fs_execute_from_sysdir
3600
        call    fs_execute_from_sysdir
3500
 
3601
 
3501
        mov     [ctrl_alt_del], 0
3602
        mov     [ctrl_alt_del], 0
3502
;--------------------------------------
3603
;--------------------------------------
3503
align 4
3604
align 4
3504
nocpustart:
3605
nocpustart:
3505
        cmp     [mouse_active], 1
3606
        cmp     [mouse_active], 1
3506
        jne     mouse_not_active
3607
        jne     mouse_not_active
3507
        mov     [mouse_active], 0
3608
        mov     [mouse_active], 0
3508
 
3609
 
3509
        xor     edi, edi
3610
        xor     edi, edi
3510
        mov     ebx, CURRENT_TASK
3611
        mov     ebx, CURRENT_TASK
3511
 
3612
 
3512
        mov     ecx, [TASK_COUNT]
3613
        mov     ecx, [TASK_COUNT]
3513
        movzx   eax, word [WIN_POS + ecx*2]     ; active window
3614
        movzx   eax, word [WIN_POS + ecx*2]     ; active window
3514
        shl     eax, 8
3615
        shl     eax, 8
3515
        push    eax
3616
        push    eax
3516
 
3617
 
3517
        movzx   eax, word [MOUSE_X]
3618
        movzx   eax, word [MOUSE_X]
3518
        movzx   edx, word [MOUSE_Y]
3619
        movzx   edx, word [MOUSE_Y]
3519
;--------------------------------------
3620
;--------------------------------------
3520
align 4
3621
align 4
3521
.set_mouse_event:
3622
.set_mouse_event:
3522
        add     edi, 256
3623
        add     edi, 256
3523
        add     ebx, 32
3624
        add     ebx, 32
3524
        test    [ebx+TASKDATA.event_mask], 0x80000000
3625
        test    [ebx+TASKDATA.event_mask], 0x80000000
3525
        jz      .pos_filter
3626
        jz      .pos_filter
3526
 
3627
 
3527
        cmp     edi, [esp]                      ; skip if filtration active
3628
        cmp     edi, [esp]                      ; skip if filtration active
3528
        jne     .skip
3629
        jne     .skip
3529
;--------------------------------------
3630
;--------------------------------------
3530
align 4
3631
align 4
3531
.pos_filter:
3632
.pos_filter:
3532
        test    [ebx+TASKDATA.event_mask], 0x40000000
3633
        test    [ebx+TASKDATA.event_mask], 0x40000000
3533
        jz      .set
3634
        jz      .set
3534
 
3635
 
3535
        mov     esi, [ebx-twdw+WDATA.box.left]
3636
        mov     esi, [ebx-twdw+WDATA.box.left]
3536
        cmp     eax, esi
3637
        cmp     eax, esi
3537
        jb      .skip
3638
        jb      .skip
3538
        add     esi, [ebx-twdw+WDATA.box.width]
3639
        add     esi, [ebx-twdw+WDATA.box.width]
3539
        cmp     eax, esi
3640
        cmp     eax, esi
3540
        ja      .skip
3641
        ja      .skip
3541
 
3642
 
3542
        mov     esi, [ebx-twdw+WDATA.box.top]
3643
        mov     esi, [ebx-twdw+WDATA.box.top]
3543
        cmp     edx, esi
3644
        cmp     edx, esi
3544
        jb      .skip
3645
        jb      .skip
3545
        add     esi, [ebx-twdw+WDATA.box.height]
3646
        add     esi, [ebx-twdw+WDATA.box.height]
3546
        cmp     edx, esi
3647
        cmp     edx, esi
3547
        ja      .skip
3648
        ja      .skip
3548
;--------------------------------------
3649
;--------------------------------------
3549
align 4
3650
align 4
3550
.set:
3651
.set:
3551
        or      [edi+SLOT_BASE+APPDATA.event_mask], 100000b  ; set event 6
3652
        or      [edi+SLOT_BASE+APPDATA.event_mask], 100000b  ; set event 6
3552
;--------------------------------------
3653
;--------------------------------------
3553
align 4
3654
align 4
3554
.skip:
3655
.skip:
3555
        loop    .set_mouse_event
3656
        loop    .set_mouse_event
3556
 
3657
 
3557
        pop     eax
3658
        pop     eax
3558
;--------------------------------------
3659
;--------------------------------------
3559
align 4
3660
align 4
3560
mouse_not_active:
3661
mouse_not_active:
3561
        cmp     byte[REDRAW_BACKGROUND], 0         ; background update ?
3662
        cmp     byte[REDRAW_BACKGROUND], 0         ; background update ?
3562
        jz      nobackgr
3663
        jz      nobackgr
3563
 
3664
 
3564
        cmp     [background_defined], 0
3665
        cmp     [background_defined], 0
3565
        jz      nobackgr
3666
        jz      nobackgr
3566
;--------------------------------------
3667
;--------------------------------------
3567
align 4
3668
align 4
3568
backgr:
3669
backgr:
3569
        mov     eax, [draw_data+32 + RECT.left]
3670
        mov     eax, [draw_data+32 + RECT.left]
3570
        shl     eax, 16
3671
        shl     eax, 16
3571
        add     eax, [draw_data+32 + RECT.right]
3672
        add     eax, [draw_data+32 + RECT.right]
3572
        mov     [BG_Rect_X_left_right], eax ; [left]*65536 + [right]
3673
        mov     [BG_Rect_X_left_right], eax ; [left]*65536 + [right]
3573
 
3674
 
3574
        mov     eax, [draw_data+32 + RECT.top]
3675
        mov     eax, [draw_data+32 + RECT.top]
3575
        shl     eax, 16
3676
        shl     eax, 16
3576
        add     eax, [draw_data+32 + RECT.bottom]
3677
        add     eax, [draw_data+32 + RECT.bottom]
3577
        mov     [BG_Rect_Y_top_bottom], eax ; [top]*65536 + [bottom]
3678
        mov     [BG_Rect_Y_top_bottom], eax ; [top]*65536 + [bottom]
3578
 
3679
 
3579
        call    drawbackground
3680
        call    drawbackground
3580
;        DEBUGF  1, "K : drawbackground\n"
3681
;        DEBUGF  1, "K : drawbackground\n"
3581
;        DEBUGF  1, "K : backg x %x\n",[BG_Rect_X_left_right]
3682
;        DEBUGF  1, "K : backg x %x\n",[BG_Rect_X_left_right]
3582
;        DEBUGF  1, "K : backg y %x\n",[BG_Rect_Y_top_bottom]
3683
;        DEBUGF  1, "K : backg y %x\n",[BG_Rect_Y_top_bottom]
3583
;--------- set event 5 start ----------
3684
;--------- set event 5 start ----------
3584
        push    ecx edi
3685
        push    ecx edi
3585
        xor     edi, edi
3686
        xor     edi, edi
3586
        mov     ecx, [TASK_COUNT]
3687
        mov     ecx, [TASK_COUNT]
3587
;--------------------------------------
3688
;--------------------------------------
3588
align 4
3689
align 4
3589
set_bgr_event:
3690
set_bgr_event:
3590
        add     edi, 256
3691
        add     edi, 256
3591
        mov     eax, [BG_Rect_X_left_right]
3692
        mov     eax, [BG_Rect_X_left_right]
3592
        mov     edx, [BG_Rect_Y_top_bottom]
3693
        mov     edx, [BG_Rect_Y_top_bottom]
3593
        cmp     [edi+SLOT_BASE+APPDATA.draw_bgr_x], 0
3694
        cmp     [edi+SLOT_BASE+APPDATA.draw_bgr_x], 0
3594
        jz      .set
3695
        jz      .set
3595
.join:
3696
.join:
3596
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_x], ax
3697
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_x], ax
3597
        jae     @f
3698
        jae     @f
3598
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_x], ax
3699
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_x], ax
3599
@@:
3700
@@:
3600
        shr     eax, 16
3701
        shr     eax, 16
3601
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_x+2], ax
3702
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_x+2], ax
3602
        jbe     @f
3703
        jbe     @f
3603
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_x+2], ax
3704
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_x+2], ax
3604
@@:
3705
@@:
3605
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3706
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3606
        jae     @f
3707
        jae     @f
3607
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3708
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3608
@@:
3709
@@:
3609
        shr     edx, 16
3710
        shr     edx, 16
3610
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_y+2], dx
3711
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_y+2], dx
3611
        jbe     @f
3712
        jbe     @f
3612
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_y+2], dx
3713
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_y+2], dx
3613
@@:
3714
@@:
3614
        jmp     .common
3715
        jmp     .common
3615
.set:
3716
.set:
3616
        mov     [edi+SLOT_BASE+APPDATA.draw_bgr_x], eax
3717
        mov     [edi+SLOT_BASE+APPDATA.draw_bgr_x], eax
3617
        mov     [edi+SLOT_BASE+APPDATA.draw_bgr_y], edx
3718
        mov     [edi+SLOT_BASE+APPDATA.draw_bgr_y], edx
3618
.common:
3719
.common:
3619
        or      [edi+SLOT_BASE+APPDATA.event_mask], 10000b  ; set event 5
3720
        or      [edi+SLOT_BASE+APPDATA.event_mask], 10000b  ; set event 5
3620
        loop    set_bgr_event
3721
        loop    set_bgr_event
3621
        pop     edi ecx
3722
        pop     edi ecx
3622
;--------- set event 5 stop -----------
3723
;--------- set event 5 stop -----------
3623
        dec     byte[REDRAW_BACKGROUND]    ; got new update request?
3724
        dec     byte[REDRAW_BACKGROUND]    ; got new update request?
3624
        jnz     backgr
3725
        jnz     backgr
3625
 
3726
 
3626
        xor     eax, eax
3727
        xor     eax, eax
3627
        mov     [draw_data+32 + RECT.left], eax
3728
        mov     [draw_data+32 + RECT.left], eax
3628
        mov     [draw_data+32 + RECT.top], eax
3729
        mov     [draw_data+32 + RECT.top], eax
3629
        mov     [draw_data+32 + RECT.right], eax
3730
        mov     [draw_data+32 + RECT.right], eax
3630
        mov     [draw_data+32 + RECT.bottom], eax
3731
        mov     [draw_data+32 + RECT.bottom], eax
3631
;--------------------------------------
3732
;--------------------------------------
3632
align 4
3733
align 4
3633
nobackgr:
3734
nobackgr:
3634
; system shutdown request
3735
; system shutdown request
3635
        cmp     [SYS_SHUTDOWN], byte 0
3736
        cmp     [SYS_SHUTDOWN], byte 0
3636
        je      noshutdown
3737
        je      noshutdown
3637
 
3738
 
3638
        mov     edx, [shutdown_processes]
3739
        mov     edx, [shutdown_processes]
3639
 
3740
 
3640
        cmp     [SYS_SHUTDOWN], dl
3741
        cmp     [SYS_SHUTDOWN], dl
3641
        jne     noshutdown
3742
        jne     noshutdown
3642
 
3743
 
3643
        lea     ecx, [edx-1]
3744
        lea     ecx, [edx-1]
3644
        mov     edx, OS_BASE+0x3040
3745
        mov     edx, OS_BASE+0x3040
3645
        jecxz   no_mark_system_shutdown
3746
        jecxz   no_mark_system_shutdown
3646
;--------------------------------------
3747
;--------------------------------------
3647
align 4
3748
align 4
3648
markz:
3749
markz:
3649
        push    ecx edx
3750
        push    ecx edx
3650
        cmp     [edx+TASKDATA.state], 9
3751
        cmp     [edx+TASKDATA.state], 9
3651
        jz      .nokill
3752
        jz      .nokill
3652
        lea     edx, [(edx-(CURRENT_TASK and 1FFFFFFFh))*8+SLOT_BASE]
3753
        lea     edx, [(edx-(CURRENT_TASK and 1FFFFFFFh))*8+SLOT_BASE]
3653
        cmp     [edx+APPDATA.process], sys_proc
3754
        cmp     [edx+APPDATA.process], sys_proc
3654
        jz      .nokill
3755
        jz      .nokill
3655
        call    request_terminate
3756
        call    request_terminate
3656
        jmp     .common
3757
        jmp     .common
3657
.nokill:
3758
.nokill:
3658
        dec     byte [SYS_SHUTDOWN]
3759
        dec     byte [SYS_SHUTDOWN]
3659
        xor     eax, eax
3760
        xor     eax, eax
3660
.common:
3761
.common:
3661
        pop     edx ecx
3762
        pop     edx ecx
3662
        test    eax, eax
3763
        test    eax, eax
3663
        jz      @f
3764
        jz      @f
3664
        mov     [edx+TASKDATA.state], byte 3
3765
        mov     [edx+TASKDATA.state], byte 3
3665
@@:
3766
@@:
3666
        add     edx, 0x20
3767
        add     edx, 0x20
3667
        loop    markz
3768
        loop    markz
3668
        call    wakeup_osloop
3769
        call    wakeup_osloop
3669
;--------------------------------------
3770
;--------------------------------------
3670
align 4
3771
align 4
3671
@@:
3772
@@:
3672
no_mark_system_shutdown:
3773
no_mark_system_shutdown:
3673
        dec     byte [SYS_SHUTDOWN]
3774
        dec     byte [SYS_SHUTDOWN]
3674
        je      system_shutdown
3775
        je      system_shutdown
3675
;--------------------------------------
3776
;--------------------------------------
3676
align 4
3777
align 4
3677
noshutdown:
3778
noshutdown:
3678
        mov     eax, [TASK_COUNT]           ; termination
3779
        mov     eax, [TASK_COUNT]           ; termination
3679
        mov     ebx, TASK_DATA+TASKDATA.state
3780
        mov     ebx, TASK_DATA+TASKDATA.state
3680
        mov     esi, 1
3781
        mov     esi, 1
3681
;--------------------------------------
3782
;--------------------------------------
3682
align 4
3783
align 4
3683
newct:
3784
newct:
3684
        mov     cl, [ebx]
3785
        mov     cl, [ebx]
3685
        cmp     cl, byte 3
3786
        cmp     cl, byte 3
3686
        jz      .terminate
3787
        jz      .terminate
3687
 
3788
 
3688
        cmp     cl, byte 4
3789
        cmp     cl, byte 4
3689
        jnz     .noterminate
3790
        jnz     .noterminate
3690
.terminate:
3791
.terminate:
3691
        pushad
3792
        pushad
3692
        mov     ecx, eax
3793
        mov     ecx, eax
3693
        shl     ecx, 8
3794
        shl     ecx, 8
3694
        add     ecx, SLOT_BASE
3795
        add     ecx, SLOT_BASE
3695
        call    restore_default_cursor_before_killing
3796
        call    restore_default_cursor_before_killing
3696
        popad
3797
        popad
3697
 
3798
 
3698
        pushad
3799
        pushad
3699
        call    terminate
3800
        call    terminate
3700
        popad
3801
        popad
3701
        cmp     byte [SYS_SHUTDOWN], 0
3802
        cmp     byte [SYS_SHUTDOWN], 0
3702
        jz      .noterminate
3803
        jz      .noterminate
3703
        dec     byte [SYS_SHUTDOWN]
3804
        dec     byte [SYS_SHUTDOWN]
3704
        je      system_shutdown
3805
        je      system_shutdown
3705
 
3806
 
3706
.noterminate:
3807
.noterminate:
3707
        add     ebx, 0x20
3808
        add     ebx, 0x20
3708
        inc     esi
3809
        inc     esi
3709
        dec     eax
3810
        dec     eax
3710
        jnz     newct
3811
        jnz     newct
3711
        ret
3812
        ret
3712
;-----------------------------------------------------------------------------
3813
;-----------------------------------------------------------------------------
3713
align 4
3814
align 4
3714
redrawscreen:
3815
redrawscreen:
3715
; eax , if process window_data base is eax, do not set flag/limits
3816
; eax , if process window_data base is eax, do not set flag/limits
3716
 
3817
 
3717
        pushad
3818
        pushad
3718
        push    eax
3819
        push    eax
3719
 
3820
 
3720
;;;         mov   ebx,2
3821
;;;         mov   ebx,2
3721
;;;         call  delay_hs
3822
;;;         call  delay_hs
3722
 
3823
 
3723
         ;mov   ecx,0               ; redraw flags for apps
3824
         ;mov   ecx,0               ; redraw flags for apps
3724
        xor     ecx, ecx
3825
        xor     ecx, ecx
3725
;--------------------------------------
3826
;--------------------------------------
3726
align 4
3827
align 4
3727
newdw2:
3828
newdw2:
3728
        inc     ecx
3829
        inc     ecx
3729
        push    ecx
3830
        push    ecx
3730
 
3831
 
3731
        mov     eax, ecx
3832
        mov     eax, ecx
3732
        shl     eax, 5
3833
        shl     eax, 5
3733
        add     eax, window_data
3834
        add     eax, window_data
3734
 
3835
 
3735
        cmp     eax, [esp+4]
3836
        cmp     eax, [esp+4]
3736
        je      not_this_task
3837
        je      not_this_task
3737
                                   ; check if window in redraw area
3838
                                   ; check if window in redraw area
3738
        mov     edi, eax
3839
        mov     edi, eax
3739
 
3840
 
3740
        cmp     ecx, 1             ; limit for background
3841
        cmp     ecx, 1             ; limit for background
3741
        jz      bgli
3842
        jz      bgli
-
 
3843
 
-
 
3844
        mov     eax, [esp+4]        ;if upper in z-position - no redraw
-
 
3845
        test    eax, eax
-
 
3846
        jz      @f
-
 
3847
        mov     al, [eax + WDATA.z_modif]
-
 
3848
        cmp     [edi + WDATA.z_modif], al
-
 
3849
        jg      ricino
-
 
3850
      @@:
3742
 
3851
 
3743
        mov     eax, [edi + WDATA.box.left]
3852
        mov     eax, [edi + WDATA.box.left]
3744
        mov     ebx, [edi + WDATA.box.top]
3853
        mov     ebx, [edi + WDATA.box.top]
3745
 
3854
 
3746
        mov     ecx, [draw_limits.bottom] ; ecx = area y end     ebx = window y start
3855
        mov     ecx, [draw_limits.bottom] ; ecx = area y end     ebx = window y start
3747
        cmp     ecx, ebx
3856
        cmp     ecx, ebx
3748
        jb      ricino
3857
        jb      ricino
3749
 
3858
 
3750
        mov     ecx, [draw_limits.right] ; ecx = area x end     eax = window x start
3859
        mov     ecx, [draw_limits.right] ; ecx = area x end     eax = window x start
3751
        cmp     ecx, eax
3860
        cmp     ecx, eax
3752
        jb      ricino
3861
        jb      ricino
3753
 
3862
 
3754
        mov     eax, [edi + WDATA.box.left]
3863
        mov     eax, [edi + WDATA.box.left]
3755
        mov     ebx, [edi + WDATA.box.top]
3864
        mov     ebx, [edi + WDATA.box.top]
3756
        mov     ecx, [edi + WDATA.box.width]
3865
        mov     ecx, [edi + WDATA.box.width]
3757
        mov     edx, [edi + WDATA.box.height]
3866
        mov     edx, [edi + WDATA.box.height]
3758
        add     ecx, eax
3867
        add     ecx, eax
3759
        add     edx, ebx
3868
        add     edx, ebx
3760
 
3869
 
3761
        mov     eax, [draw_limits.top]  ; eax = area y start     edx = window y end
3870
        mov     eax, [draw_limits.top]  ; eax = area y start     edx = window y end
3762
        cmp     edx, eax
3871
        cmp     edx, eax
3763
        jb      ricino
3872
        jb      ricino
3764
 
3873
 
3765
        mov     eax, [draw_limits.left]  ; eax = area x start     ecx = window x end
3874
        mov     eax, [draw_limits.left]  ; eax = area x start     ecx = window x end
3766
        cmp     ecx, eax
3875
        cmp     ecx, eax
3767
        jb      ricino
3876
        jb      ricino
3768
;--------------------------------------
3877
;--------------------------------------
3769
align 4
3878
align 4
3770
bgli:
3879
bgli:
3771
        cmp     dword[esp], 1
3880
        cmp     dword[esp], 1
3772
        jnz     .az
3881
        jnz     .az
3773
 
3882
 
3774
        cmp     byte[REDRAW_BACKGROUND], 0
3883
        cmp     byte[REDRAW_BACKGROUND], 0
3775
        jz      .az
3884
        jz      .az
3776
 
3885
 
3777
        mov     dl, 0
3886
        mov     dl, 0
3778
        lea     eax, [edi+draw_data-window_data]
3887
        lea     eax, [edi+draw_data-window_data]
3779
        mov     ebx, [draw_limits.left]
3888
        mov     ebx, [draw_limits.left]
3780
        cmp     ebx, [eax+RECT.left]
3889
        cmp     ebx, [eax+RECT.left]
3781
        jae     @f
3890
        jae     @f
3782
 
3891
 
3783
        mov     [eax+RECT.left], ebx
3892
        mov     [eax+RECT.left], ebx
3784
        mov     dl, 1
3893
        mov     dl, 1
3785
;--------------------------------------
3894
;--------------------------------------
3786
align 4
3895
align 4
3787
@@:
3896
@@:
3788
        mov     ebx, [draw_limits.top]
3897
        mov     ebx, [draw_limits.top]
3789
        cmp     ebx, [eax+RECT.top]
3898
        cmp     ebx, [eax+RECT.top]
3790
        jae     @f
3899
        jae     @f
3791
 
3900
 
3792
        mov     [eax+RECT.top], ebx
3901
        mov     [eax+RECT.top], ebx
3793
        mov     dl, 1
3902
        mov     dl, 1
3794
;--------------------------------------
3903
;--------------------------------------
3795
align 4
3904
align 4
3796
@@:
3905
@@:
3797
        mov     ebx, [draw_limits.right]
3906
        mov     ebx, [draw_limits.right]
3798
        cmp     ebx, [eax+RECT.right]
3907
        cmp     ebx, [eax+RECT.right]
3799
        jbe     @f
3908
        jbe     @f
3800
 
3909
 
3801
        mov     [eax+RECT.right], ebx
3910
        mov     [eax+RECT.right], ebx
3802
        mov     dl, 1
3911
        mov     dl, 1
3803
;--------------------------------------
3912
;--------------------------------------
3804
align 4
3913
align 4
3805
@@:
3914
@@:
3806
        mov     ebx, [draw_limits.bottom]
3915
        mov     ebx, [draw_limits.bottom]
3807
        cmp     ebx, [eax+RECT.bottom]
3916
        cmp     ebx, [eax+RECT.bottom]
3808
        jbe     @f
3917
        jbe     @f
3809
 
3918
 
3810
        mov     [eax+RECT.bottom], ebx
3919
        mov     [eax+RECT.bottom], ebx
3811
        mov     dl, 1
3920
        mov     dl, 1
3812
;--------------------------------------
3921
;--------------------------------------
3813
align 4
3922
align 4
3814
@@:
3923
@@:
3815
        add     byte[REDRAW_BACKGROUND], dl
3924
        add     byte[REDRAW_BACKGROUND], dl
3816
        call    wakeup_osloop
3925
        call    wakeup_osloop
3817
        jmp     newdw8
3926
        jmp     newdw8
3818
;--------------------------------------
3927
;--------------------------------------
3819
align 4
3928
align 4
3820
.az:
3929
.az:
3821
        mov     eax, edi
3930
        mov     eax, edi
3822
        add     eax, draw_data-window_data
3931
        add     eax, draw_data-window_data
3823
 
3932
 
3824
        mov     ebx, [draw_limits.left]        ; set limits
3933
        mov     ebx, [draw_limits.left]        ; set limits
3825
        mov     [eax + RECT.left], ebx
3934
        mov     [eax + RECT.left], ebx
3826
        mov     ebx, [draw_limits.top]
3935
        mov     ebx, [draw_limits.top]
3827
        mov     [eax + RECT.top], ebx
3936
        mov     [eax + RECT.top], ebx
3828
        mov     ebx, [draw_limits.right]
3937
        mov     ebx, [draw_limits.right]
3829
        mov     [eax + RECT.right], ebx
3938
        mov     [eax + RECT.right], ebx
3830
        mov     ebx, [draw_limits.bottom]
3939
        mov     ebx, [draw_limits.bottom]
3831
        mov     [eax + RECT.bottom], ebx
3940
        mov     [eax + RECT.bottom], ebx
3832
 
3941
 
3833
        sub     eax, draw_data-window_data
3942
        sub     eax, draw_data-window_data
3834
 
3943
 
3835
        cmp     dword [esp], 1
3944
        cmp     dword [esp], 1
3836
        jne     nobgrd
3945
        jne     nobgrd
3837
        inc     byte[REDRAW_BACKGROUND]
3946
        inc     byte[REDRAW_BACKGROUND]
3838
        call    wakeup_osloop
3947
        call    wakeup_osloop
3839
;--------------------------------------
3948
;--------------------------------------
3840
align 4
3949
align 4
3841
newdw8:
3950
newdw8:
3842
nobgrd:
3951
nobgrd:
3843
;--------------------------------------
3952
;--------------------------------------
3844
        push    eax  edi ebp
3953
        push    eax  edi ebp
3845
        mov     edi, [esp+12]
3954
        mov     edi, [esp+12]
3846
        cmp     edi, 1
3955
        cmp     edi, 1
3847
        je      .found
3956
        je      .found
3848
 
3957
 
3849
        mov     eax, [draw_limits.left]
3958
        mov     eax, [draw_limits.left]
3850
        mov     ebx, [draw_limits.top]
3959
        mov     ebx, [draw_limits.top]
3851
        mov     ecx, [draw_limits.right]
3960
        mov     ecx, [draw_limits.right]
3852
        sub     ecx, eax
3961
        sub     ecx, eax
3853
        test    ecx, ecx
3962
        test    ecx, ecx
3854
        jz      .not_found
3963
        jz      .not_found
3855
 
3964
 
3856
        mov     edx, [draw_limits.bottom]
3965
        mov     edx, [draw_limits.bottom]
3857
        sub     edx, ebx
3966
        sub     edx, ebx
3858
        test    edx, edx
3967
        test    edx, edx
3859
        jz      .not_found
3968
        jz      .not_found
3860
 
3969
 
3861
; eax - x, ebx - y
3970
; eax - x, ebx - y
3862
; ecx - size x, edx - size y
3971
; ecx - size x, edx - size y
3863
        add     ebx, edx
3972
        add     ebx, edx
3864
;--------------------------------------
3973
;--------------------------------------
3865
align 4
3974
align 4
3866
.start_y:
3975
.start_y:
3867
        push    ecx
3976
        push    ecx
3868
;--------------------------------------
3977
;--------------------------------------
3869
align 4
3978
align 4
3870
.start_x:
3979
.start_x:
3871
        add     eax, ecx
3980
        add     eax, ecx
3872
        mov     ebp, [d_width_calc_area + ebx*4]
3981
        mov     ebp, [d_width_calc_area + ebx*4]
3873
        add     ebp, [_display.win_map]
3982
        add     ebp, [_display.win_map]
3874
        movzx   ebp, byte[eax+ebp] ; get value for current point
3983
        movzx   ebp, byte[eax+ebp] ; get value for current point
3875
        cmp     ebp, edi
3984
        cmp     ebp, edi
3876
        jne     @f
3985
        jne     @f
3877
 
3986
 
3878
        pop     ecx
3987
        pop     ecx
3879
        jmp     .found
3988
        jmp     .found
3880
;--------------------------------------
3989
;--------------------------------------
3881
align 4
3990
align 4
3882
@@:
3991
@@:
3883
        sub     eax, ecx
3992
        sub     eax, ecx
3884
 
3993
 
3885
        dec     ecx
3994
        dec     ecx
3886
        jnz     .start_x
3995
        jnz     .start_x
3887
 
3996
 
3888
        pop     ecx
3997
        pop     ecx
3889
        dec     ebx
3998
        dec     ebx
3890
        dec     edx
3999
        dec     edx
3891
        jnz     .start_y
4000
        jnz     .start_y
3892
;--------------------------------------
4001
;--------------------------------------
3893
align 4
4002
align 4
3894
.not_found:
4003
.not_found:
3895
        pop     ebp edi eax
4004
        pop     ebp edi eax
3896
        jmp     ricino
4005
        jmp     ricino
3897
;--------------------------------------
4006
;--------------------------------------
3898
align 4
4007
align 4
3899
.found:
4008
.found:
3900
        pop     ebp edi eax
4009
        pop     ebp edi eax
3901
 
4010
 
3902
        mov     [eax + WDATA.fl_redraw], byte 1  ; mark as redraw
4011
        mov     [eax + WDATA.fl_redraw], byte 1  ; mark as redraw
3903
;--------------------------------------
4012
;--------------------------------------
3904
align 4
4013
align 4
3905
ricino:
4014
ricino:
3906
not_this_task:
4015
not_this_task:
3907
        pop     ecx
4016
        pop     ecx
3908
 
4017
 
3909
        cmp     ecx, [TASK_COUNT]
4018
        cmp     ecx, [TASK_COUNT]
3910
        jle     newdw2
4019
        jle     newdw2
3911
 
4020
 
3912
        pop     eax
4021
        pop     eax
3913
        popad
4022
        popad
3914
        ret
4023
        ret
3915
;-----------------------------------------------------------------------------
4024
;-----------------------------------------------------------------------------
3916
align 4
4025
align 4
3917
calculatebackground:   ; background
4026
calculatebackground:   ; background
3918
        mov     edi, [_display.win_map]              ; set os to use all pixels
4027
        mov     edi, [_display.win_map]              ; set os to use all pixels
3919
        mov     eax, 0x01010101
4028
        mov     eax, 0x01010101
3920
        mov     ecx, [_display.win_map_size]
4029
        mov     ecx, [_display.win_map_size]
3921
        shr     ecx, 2
4030
        shr     ecx, 2
3922
        rep stosd
4031
        rep stosd
3923
 
4032
 
3924
        mov     byte[REDRAW_BACKGROUND], 0            ; do not draw background!
4033
        mov     byte[REDRAW_BACKGROUND], 0            ; do not draw background!
3925
        ret
4034
        ret
3926
;-----------------------------------------------------------------------------
4035
;-----------------------------------------------------------------------------
3927
uglobal
4036
uglobal
3928
  imax    dd 0x0
4037
  imax    dd 0x0
3929
endg
4038
endg
3930
;-----------------------------------------------------------------------------
4039
;-----------------------------------------------------------------------------
3931
align 4
4040
align 4
3932
delay_ms:     ; delay in 1/1000 sec
4041
delay_ms:     ; delay in 1/1000 sec
3933
        push    eax
4042
        push    eax
3934
        push    ecx
4043
        push    ecx
3935
 
4044
 
3936
        mov     ecx, esi
4045
        mov     ecx, esi
3937
        ; 
4046
        ; 
3938
        imul    ecx, 33941
4047
        imul    ecx, 33941
3939
        shr     ecx, 9
4048
        shr     ecx, 9
3940
        ; 
4049
        ; 
3941
 
4050
 
3942
        in      al, 0x61
4051
        in      al, 0x61
3943
        and     al, 0x10
4052
        and     al, 0x10
3944
        mov     ah, al
4053
        mov     ah, al
3945
        cld
4054
        cld
3946
;--------------------------------------
4055
;--------------------------------------
3947
align 4
4056
align 4
3948
cnt1:
4057
cnt1:
3949
        in      al, 0x61
4058
        in      al, 0x61
3950
        and     al, 0x10
4059
        and     al, 0x10
3951
        cmp     al, ah
4060
        cmp     al, ah
3952
        jz      cnt1
4061
        jz      cnt1
3953
 
4062
 
3954
        mov     ah, al
4063
        mov     ah, al
3955
        loop    cnt1
4064
        loop    cnt1
3956
 
4065
 
3957
        pop     ecx
4066
        pop     ecx
3958
        pop     eax
4067
        pop     eax
3959
        ret
4068
        ret
3960
;-----------------------------------------------------------------------------
4069
;-----------------------------------------------------------------------------
3961
align 4
4070
align 4
3962
set_app_param:
4071
set_app_param:
3963
        mov     edi, [TASK_BASE]
4072
        mov     edi, [TASK_BASE]
3964
        mov     eax, ebx
4073
        mov     eax, ebx
3965
        btr     eax, 3                           ; move MOUSE_FILTRATION
4074
        btr     eax, 3                           ; move MOUSE_FILTRATION
3966
        mov     ebx, [current_slot]              ; bit into event_filter
4075
        mov     ebx, [current_slot]              ; bit into event_filter
3967
        setc    byte [ebx+APPDATA.event_filter]
4076
        setc    byte [ebx+APPDATA.event_filter]
3968
        xchg    eax, [edi + TASKDATA.event_mask] ; set new event mask
4077
        xchg    eax, [edi + TASKDATA.event_mask] ; set new event mask
3969
        mov     [esp+32], eax                    ; return old mask value
4078
        mov     [esp+32], eax                    ; return old mask value
3970
        ret
4079
        ret
3971
;-----------------------------------------------------------------------------
4080
;-----------------------------------------------------------------------------
3972
 
4081
 
3973
; this is for syscall
4082
; this is for syscall
3974
proc delay_hs_unprotected
4083
proc delay_hs_unprotected
3975
        call    unprotect_from_terminate
4084
        call    unprotect_from_terminate
3976
        call    delay_hs
4085
        call    delay_hs
3977
        call    protect_from_terminate
4086
        call    protect_from_terminate
3978
        ret
4087
        ret
3979
endp
4088
endp
3980
 
4089
 
3981
if 1
4090
if 1
3982
align 4
4091
align 4
3983
delay_hs:     ; delay in 1/100 secs
4092
delay_hs:     ; delay in 1/100 secs
3984
; ebx = delay time
4093
; ebx = delay time
3985
 
4094
 
3986
        pushad
4095
        pushad
3987
        push    ebx
4096
        push    ebx
3988
        xor     esi, esi
4097
        xor     esi, esi
3989
        mov     ecx, MANUAL_DESTROY
4098
        mov     ecx, MANUAL_DESTROY
3990
        call    create_event
4099
        call    create_event
3991
        test    eax, eax
4100
        test    eax, eax
3992
        jz      .done
4101
        jz      .done
3993
 
4102
 
3994
        mov     ebx, edx
4103
        mov     ebx, edx
3995
        mov     ecx, [esp]
4104
        mov     ecx, [esp]
3996
        push    edx
4105
        push    edx
3997
        push    eax
4106
        push    eax
3998
        call    wait_event_timeout
4107
        call    wait_event_timeout
3999
        pop     eax
4108
        pop     eax
4000
        pop     ebx
4109
        pop     ebx
4001
        call    destroy_event
4110
        call    destroy_event
4002
.done:
4111
.done:
4003
        add     esp, 4
4112
        add     esp, 4
4004
        popad
4113
        popad
4005
        ret
4114
        ret
4006
 
4115
 
4007
else
4116
else
4008
 
4117
 
4009
align 4
4118
align 4
4010
delay_hs:     ; delay in 1/100 secs
4119
delay_hs:     ; delay in 1/100 secs
4011
; ebx = delay time
4120
; ebx = delay time
4012
        push    ecx
4121
        push    ecx
4013
        push    edx
4122
        push    edx
4014
 
4123
 
4015
        mov     edx, [timer_ticks]
4124
        mov     edx, [timer_ticks]
4016
;--------------------------------------
4125
;--------------------------------------
4017
align 4
4126
align 4
4018
newtic:
4127
newtic:
4019
        mov     ecx, [timer_ticks]
4128
        mov     ecx, [timer_ticks]
4020
        sub     ecx, edx
4129
        sub     ecx, edx
4021
        cmp     ecx, ebx
4130
        cmp     ecx, ebx
4022
        jae     zerodelay
4131
        jae     zerodelay
4023
 
4132
 
4024
        call    change_task
4133
        call    change_task
4025
 
4134
 
4026
        jmp     newtic
4135
        jmp     newtic
4027
;--------------------------------------
4136
;--------------------------------------
4028
align 4
4137
align 4
4029
zerodelay:
4138
zerodelay:
4030
        pop     edx
4139
        pop     edx
4031
        pop     ecx
4140
        pop     ecx
4032
        ret
4141
        ret
4033
end if
4142
end if
4034
 
4143
 
4035
;-----------------------------------------------------------------------------
4144
;-----------------------------------------------------------------------------
4036
align 16        ;very often call this subrutine
4145
align 16        ;very often call this subrutine
4037
memmove:       ; memory move in bytes
4146
memmove:       ; memory move in bytes
4038
; eax = from
4147
; eax = from
4039
; ebx = to
4148
; ebx = to
4040
; ecx = no of bytes
4149
; ecx = no of bytes
4041
        test    ecx, ecx
4150
        test    ecx, ecx
4042
        jle     .ret
4151
        jle     .ret
4043
 
4152
 
4044
        push    esi edi ecx
4153
        push    esi edi ecx
4045
 
4154
 
4046
        mov     edi, ebx
4155
        mov     edi, ebx
4047
        mov     esi, eax
4156
        mov     esi, eax
4048
 
4157
 
4049
        test    ecx, not 11b
4158
        test    ecx, not 11b
4050
        jz      @f
4159
        jz      @f
4051
 
4160
 
4052
        push    ecx
4161
        push    ecx
4053
        shr     ecx, 2
4162
        shr     ecx, 2
4054
        rep movsd
4163
        rep movsd
4055
        pop     ecx
4164
        pop     ecx
4056
        and     ecx, 11b
4165
        and     ecx, 11b
4057
        jz      .finish
4166
        jz      .finish
4058
;--------------------------------------
4167
;--------------------------------------
4059
align 4
4168
align 4
4060
@@:
4169
@@:
4061
        rep movsb
4170
        rep movsb
4062
;--------------------------------------
4171
;--------------------------------------
4063
align 4
4172
align 4
4064
.finish:
4173
.finish:
4065
        pop     ecx edi esi
4174
        pop     ecx edi esi
4066
;--------------------------------------
4175
;--------------------------------------
4067
align 4
4176
align 4
4068
.ret:
4177
.ret:
4069
        ret
4178
        ret
4070
;-----------------------------------------------------------------------------
4179
;-----------------------------------------------------------------------------
4071
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
4180
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
4072
;align 4
4181
;align 4
4073
;
4182
;
4074
;read_floppy_file:
4183
;read_floppy_file:
4075
;
4184
;
4076
;; as input
4185
;; as input
4077
;;
4186
;;
4078
;; eax pointer to file
4187
;; eax pointer to file
4079
;; ebx file lenght
4188
;; ebx file lenght
4080
;; ecx start 512 byte block number
4189
;; ecx start 512 byte block number
4081
;; edx number of blocks to read
4190
;; edx number of blocks to read
4082
;; esi pointer to return/work area (atleast 20 000 bytes)
4191
;; esi pointer to return/work area (atleast 20 000 bytes)
4083
;;
4192
;;
4084
;;
4193
;;
4085
;; on return
4194
;; on return
4086
;;
4195
;;
4087
;; eax = 0 command succesful
4196
;; eax = 0 command succesful
4088
;;       1 no fd base and/or partition defined
4197
;;       1 no fd base and/or partition defined
4089
;;       2 yet unsupported FS
4198
;;       2 yet unsupported FS
4090
;;       3 unknown FS
4199
;;       3 unknown FS
4091
;;       4 partition not defined at hd
4200
;;       4 partition not defined at hd
4092
;;       5 file not found
4201
;;       5 file not found
4093
;; ebx = size of file
4202
;; ebx = size of file
4094
;
4203
;
4095
;     mov   edi,[TASK_BASE]
4204
;     mov   edi,[TASK_BASE]
4096
;     add   edi,0x10
4205
;     add   edi,0x10
4097
;     add   esi,[edi]
4206
;     add   esi,[edi]
4098
;     add   eax,[edi]
4207
;     add   eax,[edi]
4099
;
4208
;
4100
;     pushad
4209
;     pushad
4101
;     mov  edi,esi
4210
;     mov  edi,esi
4102
;     add  edi,1024
4211
;     add  edi,1024
4103
;     mov  esi,0x100000+19*512
4212
;     mov  esi,0x100000+19*512
4104
;     sub  ecx,1
4213
;     sub  ecx,1
4105
;     shl  ecx,9
4214
;     shl  ecx,9
4106
;     add  esi,ecx
4215
;     add  esi,ecx
4107
;     shl  edx,9
4216
;     shl  edx,9
4108
;     mov  ecx,edx
4217
;     mov  ecx,edx
4109
;     cld
4218
;     cld
4110
;     rep  movsb
4219
;     rep  movsb
4111
;     popad
4220
;     popad
4112
;
4221
;
4113
;     mov   [esp+36],eax
4222
;     mov   [esp+36],eax
4114
;     mov   [esp+24],ebx
4223
;     mov   [esp+24],ebx
4115
;     ret
4224
;     ret
4116
 
4225
 
4117
 
4226
 
4118
 
4227
 
4119
align 4
4228
align 4
4120
set_io_access_rights:
4229
set_io_access_rights:
4121
        push    edi eax
4230
        push    edi eax
4122
        mov     edi, tss._io_map_0
4231
        mov     edi, tss._io_map_0
4123
;     mov   ecx,eax
4232
;     mov   ecx,eax
4124
;     and   ecx,7    ; offset in byte
4233
;     and   ecx,7    ; offset in byte
4125
;     shr   eax,3    ; number of byte
4234
;     shr   eax,3    ; number of byte
4126
;     add   edi,eax
4235
;     add   edi,eax
4127
;     mov   ebx,1
4236
;     mov   ebx,1
4128
;     shl   ebx,cl
4237
;     shl   ebx,cl
4129
        test    ebp, ebp
4238
        test    ebp, ebp
4130
;     cmp   ebp,0                ; enable access - ebp = 0
4239
;     cmp   ebp,0                ; enable access - ebp = 0
4131
        jnz     .siar1
4240
        jnz     .siar1
4132
;     not   ebx
4241
;     not   ebx
4133
;     and   [edi],byte bl
4242
;     and   [edi],byte bl
4134
        btr     [edi], eax
4243
        btr     [edi], eax
4135
        pop     eax edi
4244
        pop     eax edi
4136
        ret
4245
        ret
4137
.siar1:
4246
.siar1:
4138
        bts     [edi], eax
4247
        bts     [edi], eax
4139
  ;  or    [edi],byte bl        ; disable access - ebp = 1
4248
  ;  or    [edi],byte bl        ; disable access - ebp = 1
4140
        pop     eax edi
4249
        pop     eax edi
4141
        ret
4250
        ret
4142
;reserve/free group of ports
4251
;reserve/free group of ports
4143
;  * eax = 46 - number function
4252
;  * eax = 46 - number function
4144
;  * ebx = 0 - reserve, 1 - free
4253
;  * ebx = 0 - reserve, 1 - free
4145
;  * ecx = number start arrea of ports
4254
;  * ecx = number start arrea of ports
4146
;  * edx = number end arrea of ports (include last number of port)
4255
;  * edx = number end arrea of ports (include last number of port)
4147
;Return value:
4256
;Return value:
4148
;  * eax = 0 - succesful
4257
;  * eax = 0 - succesful
4149
;  * eax = 1 - error
4258
;  * eax = 1 - error
4150
;  * The system has reserve this ports:
4259
;  * The system has reserve this ports:
4151
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
4260
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
4152
;destroys eax,ebx, ebp
4261
;destroys eax,ebx, ebp
4153
r_f_port_area:
4262
r_f_port_area:
4154
 
4263
 
4155
        test    ebx, ebx
4264
        test    ebx, ebx
4156
        jnz     free_port_area
4265
        jnz     free_port_area
4157
;     je    r_port_area
4266
;     je    r_port_area
4158
;     jmp   free_port_area
4267
;     jmp   free_port_area
4159
 
4268
 
4160
;   r_port_area:
4269
;   r_port_area:
4161
 
4270
 
4162
;     pushad
4271
;     pushad
4163
 
4272
 
4164
        cmp     ecx, edx      ; beginning > end ?
4273
        cmp     ecx, edx      ; beginning > end ?
4165
        ja      rpal1
4274
        ja      rpal1
4166
        cmp     edx, 65536
4275
        cmp     edx, 65536
4167
        jae     rpal1
4276
        jae     rpal1
4168
        mov     eax, [RESERVED_PORTS]
4277
        mov     eax, [RESERVED_PORTS]
4169
        test    eax, eax      ; no reserved areas ?
4278
        test    eax, eax      ; no reserved areas ?
4170
        je      rpal2
4279
        je      rpal2
4171
        cmp     eax, 255      ; max reserved
4280
        cmp     eax, 255      ; max reserved
4172
        jae     rpal1
4281
        jae     rpal1
4173
 rpal3:
4282
 rpal3:
4174
        mov     ebx, eax
4283
        mov     ebx, eax
4175
        shl     ebx, 4
4284
        shl     ebx, 4
4176
        add     ebx, RESERVED_PORTS
4285
        add     ebx, RESERVED_PORTS
4177
        cmp     ecx, [ebx+8]
4286
        cmp     ecx, [ebx+8]
4178
        ja      rpal4
4287
        ja      rpal4
4179
        cmp     edx, [ebx+4]
4288
        cmp     edx, [ebx+4]
4180
        jae     rpal1
4289
        jae     rpal1
4181
;     jb    rpal4
4290
;     jb    rpal4
4182
;     jmp   rpal1
4291
;     jmp   rpal1
4183
 rpal4:
4292
 rpal4:
4184
        dec     eax
4293
        dec     eax
4185
        jnz     rpal3
4294
        jnz     rpal3
4186
        jmp     rpal2
4295
        jmp     rpal2
4187
   rpal1:
4296
   rpal1:
4188
;     popad
4297
;     popad
4189
;     mov   eax,1
4298
;     mov   eax,1
4190
        xor     eax, eax
4299
        xor     eax, eax
4191
        inc     eax
4300
        inc     eax
4192
        ret
4301
        ret
4193
   rpal2:
4302
   rpal2:
4194
;     popad
4303
;     popad
4195
     ; enable port access at port IO map
4304
     ; enable port access at port IO map
4196
        cli
4305
        cli
4197
        pushad                        ; start enable io map
4306
        pushad                        ; start enable io map
4198
 
4307
 
4199
        cmp     edx, 65536;16384
4308
        cmp     edx, 65536;16384
4200
        jae     no_unmask_io; jge
4309
        jae     no_unmask_io; jge
4201
        mov     eax, ecx
4310
        mov     eax, ecx
4202
;       push    ebp
4311
;       push    ebp
4203
        xor     ebp, ebp               ; enable - eax = port
4312
        xor     ebp, ebp               ; enable - eax = port
4204
new_port_access:
4313
new_port_access:
4205
;     pushad
4314
;     pushad
4206
        call    set_io_access_rights
4315
        call    set_io_access_rights
4207
;     popad
4316
;     popad
4208
        inc     eax
4317
        inc     eax
4209
        cmp     eax, edx
4318
        cmp     eax, edx
4210
        jbe     new_port_access
4319
        jbe     new_port_access
4211
;       pop     ebp
4320
;       pop     ebp
4212
no_unmask_io:
4321
no_unmask_io:
4213
        popad                         ; end enable io map
4322
        popad                         ; end enable io map
4214
        sti
4323
        sti
4215
 
4324
 
4216
        mov     eax, [RESERVED_PORTS]
4325
        mov     eax, [RESERVED_PORTS]
4217
        add     eax, 1
4326
        add     eax, 1
4218
        mov     [RESERVED_PORTS], eax
4327
        mov     [RESERVED_PORTS], eax
4219
        shl     eax, 4
4328
        shl     eax, 4
4220
        add     eax, RESERVED_PORTS
4329
        add     eax, RESERVED_PORTS
4221
        mov     ebx, [TASK_BASE]
4330
        mov     ebx, [TASK_BASE]
4222
        mov     ebx, [ebx+TASKDATA.pid]
4331
        mov     ebx, [ebx+TASKDATA.pid]
4223
        mov     [eax], ebx
4332
        mov     [eax], ebx
4224
        mov     [eax+4], ecx
4333
        mov     [eax+4], ecx
4225
        mov     [eax+8], edx
4334
        mov     [eax+8], edx
4226
 
4335
 
4227
        xor     eax, eax
4336
        xor     eax, eax
4228
        ret
4337
        ret
4229
 
4338
 
4230
free_port_area:
4339
free_port_area:
4231
 
4340
 
4232
;     pushad
4341
;     pushad
4233
        mov     eax, [RESERVED_PORTS]; no reserved areas ?
4342
        mov     eax, [RESERVED_PORTS]; no reserved areas ?
4234
        test    eax, eax
4343
        test    eax, eax
4235
        jz      frpal2
4344
        jz      frpal2
4236
        mov     ebx, [TASK_BASE]
4345
        mov     ebx, [TASK_BASE]
4237
        mov     ebx, [ebx+TASKDATA.pid]
4346
        mov     ebx, [ebx+TASKDATA.pid]
4238
   frpal3:
4347
   frpal3:
4239
        mov     edi, eax
4348
        mov     edi, eax
4240
        shl     edi, 4
4349
        shl     edi, 4
4241
        add     edi, RESERVED_PORTS
4350
        add     edi, RESERVED_PORTS
4242
        cmp     ebx, [edi]
4351
        cmp     ebx, [edi]
4243
        jne     frpal4
4352
        jne     frpal4
4244
        cmp     ecx, [edi+4]
4353
        cmp     ecx, [edi+4]
4245
        jne     frpal4
4354
        jne     frpal4
4246
        cmp     edx, [edi+8]
4355
        cmp     edx, [edi+8]
4247
        jne     frpal4
4356
        jne     frpal4
4248
        jmp     frpal1
4357
        jmp     frpal1
4249
   frpal4:
4358
   frpal4:
4250
        dec     eax
4359
        dec     eax
4251
        jnz     frpal3
4360
        jnz     frpal3
4252
   frpal2:
4361
   frpal2:
4253
;     popad
4362
;     popad
4254
        inc     eax
4363
        inc     eax
4255
        ret
4364
        ret
4256
   frpal1:
4365
   frpal1:
4257
        push    ecx
4366
        push    ecx
4258
        mov     ecx, 256
4367
        mov     ecx, 256
4259
        sub     ecx, eax
4368
        sub     ecx, eax
4260
        shl     ecx, 4
4369
        shl     ecx, 4
4261
        mov     esi, edi
4370
        mov     esi, edi
4262
        add     esi, 16
4371
        add     esi, 16
4263
        cld
4372
        cld
4264
        rep movsb
4373
        rep movsb
4265
 
4374
 
4266
        dec     dword [RESERVED_PORTS]
4375
        dec     dword [RESERVED_PORTS]
4267
;popad
4376
;popad
4268
;disable port access at port IO map
4377
;disable port access at port IO map
4269
 
4378
 
4270
;     pushad                        ; start disable io map
4379
;     pushad                        ; start disable io map
4271
        pop     eax     ;start port
4380
        pop     eax     ;start port
4272
        cmp     edx, 65536;16384
4381
        cmp     edx, 65536;16384
4273
        jge     no_mask_io
4382
        jge     no_mask_io
4274
 
4383
 
4275
;     mov   eax,ecx
4384
;     mov   eax,ecx
4276
        xor     ebp, ebp
4385
        xor     ebp, ebp
4277
        inc     ebp
4386
        inc     ebp
4278
new_port_access_disable:
4387
new_port_access_disable:
4279
;     pushad
4388
;     pushad
4280
;     mov   ebp,1                  ; disable - eax = port
4389
;     mov   ebp,1                  ; disable - eax = port
4281
        call    set_io_access_rights
4390
        call    set_io_access_rights
4282
;     popad
4391
;     popad
4283
        inc     eax
4392
        inc     eax
4284
        cmp     eax, edx
4393
        cmp     eax, edx
4285
        jbe     new_port_access_disable
4394
        jbe     new_port_access_disable
4286
no_mask_io:
4395
no_mask_io:
4287
;     popad                         ; end disable io map
4396
;     popad                         ; end disable io map
4288
        xor     eax, eax
4397
        xor     eax, eax
4289
        ret
4398
        ret
4290
;-----------------------------------------------------------------------------
4399
;-----------------------------------------------------------------------------
4291
align 4
4400
align 4
4292
drawbackground:
4401
drawbackground:
4293
dbrv20:
4402
dbrv20:
4294
        cmp     [BgrDrawMode], dword 1
4403
        cmp     [BgrDrawMode], dword 1
4295
        jne     bgrstr
4404
        jne     bgrstr
4296
        call    vesa20_drawbackground_tiled
4405
        call    vesa20_drawbackground_tiled
4297
;        call    [draw_pointer]
4406
;        call    [draw_pointer]
4298
        call    __sys_draw_pointer
4407
        call    __sys_draw_pointer
4299
        ret
4408
        ret
4300
;--------------------------------------
4409
;--------------------------------------
4301
align 4
4410
align 4
4302
bgrstr:
4411
bgrstr:
4303
        call    vesa20_drawbackground_stretch
4412
        call    vesa20_drawbackground_stretch
4304
;        call    [draw_pointer]
4413
;        call    [draw_pointer]
4305
        call    __sys_draw_pointer
4414
        call    __sys_draw_pointer
4306
        ret
4415
        ret
4307
;-----------------------------------------------------------------------------
4416
;-----------------------------------------------------------------------------
4308
align 4
4417
align 4
4309
syscall_putimage:                       ; PutImage
4418
syscall_putimage:                       ; PutImage
4310
sys_putimage:
4419
sys_putimage:
4311
        test    ecx, 0x80008000
4420
        test    ecx, 0x80008000
4312
        jnz     .exit
4421
        jnz     .exit
4313
        test    ecx, 0x0000FFFF
4422
        test    ecx, 0x0000FFFF
4314
        jz      .exit
4423
        jz      .exit
4315
        test    ecx, 0xFFFF0000
4424
        test    ecx, 0xFFFF0000
4316
        jnz     @f
4425
        jnz     @f
4317
;--------------------------------------
4426
;--------------------------------------
4318
align 4
4427
align 4
4319
.exit:
4428
.exit:
4320
        ret
4429
        ret
4321
;--------------------------------------
4430
;--------------------------------------
4322
align 4
4431
align 4
4323
@@:
4432
@@:
4324
        mov     edi, [current_slot]
4433
        mov     edi, [current_slot]
4325
        add     dx, word[edi+APPDATA.wnd_clientbox.top]
4434
        add     dx, word[edi+APPDATA.wnd_clientbox.top]
4326
        rol     edx, 16
4435
        rol     edx, 16
4327
        add     dx, word[edi+APPDATA.wnd_clientbox.left]
4436
        add     dx, word[edi+APPDATA.wnd_clientbox.left]
4328
        rol     edx, 16
4437
        rol     edx, 16
4329
;--------------------------------------
4438
;--------------------------------------
4330
align 4
4439
align 4
4331
.forced:
4440
.forced:
4332
        push    ebp esi 0
4441
        push    ebp esi 0
4333
        mov     ebp, putimage_get24bpp
4442
        mov     ebp, putimage_get24bpp
4334
        mov     esi, putimage_init24bpp
4443
        mov     esi, putimage_init24bpp
4335
;--------------------------------------
4444
;--------------------------------------
4336
align 4
4445
align 4
4337
sys_putimage_bpp:
4446
sys_putimage_bpp:
4338
        call    vesa20_putimage
4447
        call    vesa20_putimage
4339
        pop     ebp esi ebp
4448
        pop     ebp esi ebp
4340
        ret
4449
        ret
4341
;        jmp     [draw_pointer]
4450
;        jmp     [draw_pointer]
4342
;-----------------------------------------------------------------------------
4451
;-----------------------------------------------------------------------------
4343
align 4
4452
align 4
4344
sys_putimage_palette:
4453
sys_putimage_palette:
4345
; ebx = pointer to image
4454
; ebx = pointer to image
4346
; ecx = [xsize]*65536 + [ysize]
4455
; ecx = [xsize]*65536 + [ysize]
4347
; edx = [xstart]*65536 + [ystart]
4456
; edx = [xstart]*65536 + [ystart]
4348
; esi = number of bits per pixel, must be 8, 24 or 32
4457
; esi = number of bits per pixel, must be 8, 24 or 32
4349
; edi = pointer to palette
4458
; edi = pointer to palette
4350
; ebp = row delta
4459
; ebp = row delta
4351
        mov     eax, [CURRENT_TASK]
4460
        mov     eax, [CURRENT_TASK]
4352
        shl     eax, 8
4461
        shl     eax, 8
4353
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4462
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4354
        rol     edx, 16
4463
        rol     edx, 16
4355
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4464
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4356
        rol     edx, 16
4465
        rol     edx, 16
4357
;--------------------------------------
4466
;--------------------------------------
4358
align 4
4467
align 4
4359
.forced:
4468
.forced:
4360
        cmp     esi, 1
4469
        cmp     esi, 1
4361
        jnz     @f
4470
        jnz     @f
4362
        push    edi
4471
        push    edi
4363
        mov     eax, [edi+4]
4472
        mov     eax, [edi+4]
4364
        sub     eax, [edi]
4473
        sub     eax, [edi]
4365
        push    eax
4474
        push    eax
4366
        push    dword [edi]
4475
        push    dword [edi]
4367
        push    0ffffff80h
4476
        push    0ffffff80h
4368
        mov     edi, esp
4477
        mov     edi, esp
4369
        call    put_mono_image
4478
        call    put_mono_image
4370
        add     esp, 12
4479
        add     esp, 12
4371
        pop     edi
4480
        pop     edi
4372
        ret
4481
        ret
4373
;--------------------------------------
4482
;--------------------------------------
4374
align 4
4483
align 4
4375
@@:
4484
@@:
4376
        cmp     esi, 2
4485
        cmp     esi, 2
4377
        jnz     @f
4486
        jnz     @f
4378
        push    edi
4487
        push    edi
4379
        push    0ffffff80h
4488
        push    0ffffff80h
4380
        mov     edi, esp
4489
        mov     edi, esp
4381
        call    put_2bit_image
4490
        call    put_2bit_image
4382
        pop     eax
4491
        pop     eax
4383
        pop     edi
4492
        pop     edi
4384
        ret
4493
        ret
4385
;--------------------------------------
4494
;--------------------------------------
4386
align 4
4495
align 4
4387
@@:
4496
@@:
4388
        cmp     esi, 4
4497
        cmp     esi, 4
4389
        jnz     @f
4498
        jnz     @f
4390
        push    edi
4499
        push    edi
4391
        push    0ffffff80h
4500
        push    0ffffff80h
4392
        mov     edi, esp
4501
        mov     edi, esp
4393
        call    put_4bit_image
4502
        call    put_4bit_image
4394
        pop     eax
4503
        pop     eax
4395
        pop     edi
4504
        pop     edi
4396
        ret
4505
        ret
4397
;--------------------------------------
4506
;--------------------------------------
4398
align 4
4507
align 4
4399
@@:
4508
@@:
4400
        push    ebp esi ebp
4509
        push    ebp esi ebp
4401
        cmp     esi, 8
4510
        cmp     esi, 8
4402
        jnz     @f
4511
        jnz     @f
4403
        mov     ebp, putimage_get8bpp
4512
        mov     ebp, putimage_get8bpp
4404
        mov     esi, putimage_init8bpp
4513
        mov     esi, putimage_init8bpp
4405
        jmp     sys_putimage_bpp
4514
        jmp     sys_putimage_bpp
4406
;--------------------------------------
4515
;--------------------------------------
4407
align 4
4516
align 4
4408
@@:
4517
@@:
4409
        cmp     esi, 9
4518
        cmp     esi, 9
4410
        jnz     @f
4519
        jnz     @f
4411
        mov     ebp, putimage_get9bpp
4520
        mov     ebp, putimage_get9bpp
4412
        mov     esi, putimage_init9bpp
4521
        mov     esi, putimage_init9bpp
4413
        jmp     sys_putimage_bpp
4522
        jmp     sys_putimage_bpp
4414
;--------------------------------------
4523
;--------------------------------------
4415
align 4
4524
align 4
4416
@@:
4525
@@:
4417
        cmp     esi, 15
4526
        cmp     esi, 15
4418
        jnz     @f
4527
        jnz     @f
4419
        mov     ebp, putimage_get15bpp
4528
        mov     ebp, putimage_get15bpp
4420
        mov     esi, putimage_init15bpp
4529
        mov     esi, putimage_init15bpp
4421
        jmp     sys_putimage_bpp
4530
        jmp     sys_putimage_bpp
4422
;--------------------------------------
4531
;--------------------------------------
4423
align 4
4532
align 4
4424
@@:
4533
@@:
4425
        cmp     esi, 16
4534
        cmp     esi, 16
4426
        jnz     @f
4535
        jnz     @f
4427
        mov     ebp, putimage_get16bpp
4536
        mov     ebp, putimage_get16bpp
4428
        mov     esi, putimage_init16bpp
4537
        mov     esi, putimage_init16bpp
4429
        jmp     sys_putimage_bpp
4538
        jmp     sys_putimage_bpp
4430
;--------------------------------------
4539
;--------------------------------------
4431
align 4
4540
align 4
4432
@@:
4541
@@:
4433
        cmp     esi, 24
4542
        cmp     esi, 24
4434
        jnz     @f
4543
        jnz     @f
4435
        mov     ebp, putimage_get24bpp
4544
        mov     ebp, putimage_get24bpp
4436
        mov     esi, putimage_init24bpp
4545
        mov     esi, putimage_init24bpp
4437
        jmp     sys_putimage_bpp
4546
        jmp     sys_putimage_bpp
4438
;--------------------------------------
4547
;--------------------------------------
4439
align 4
4548
align 4
4440
@@:
4549
@@:
4441
        cmp     esi, 32
4550
        cmp     esi, 32
4442
        jnz     @f
4551
        jnz     @f
4443
        mov     ebp, putimage_get32bpp
4552
        mov     ebp, putimage_get32bpp
4444
        mov     esi, putimage_init32bpp
4553
        mov     esi, putimage_init32bpp
4445
        jmp     sys_putimage_bpp
4554
        jmp     sys_putimage_bpp
4446
;--------------------------------------
4555
;--------------------------------------
4447
align 4
4556
align 4
4448
@@:
4557
@@:
4449
        pop     ebp esi ebp
4558
        pop     ebp esi ebp
4450
        ret
4559
        ret
4451
;-----------------------------------------------------------------------------
4560
;-----------------------------------------------------------------------------
4452
align 4
4561
align 4
4453
put_mono_image:
4562
put_mono_image:
4454
        push    ebp esi ebp
4563
        push    ebp esi ebp
4455
        mov     ebp, putimage_get1bpp
4564
        mov     ebp, putimage_get1bpp
4456
        mov     esi, putimage_init1bpp
4565
        mov     esi, putimage_init1bpp
4457
        jmp     sys_putimage_bpp
4566
        jmp     sys_putimage_bpp
4458
;-----------------------------------------------------------------------------
4567
;-----------------------------------------------------------------------------
4459
align 4
4568
align 4
4460
put_2bit_image:
4569
put_2bit_image:
4461
        push    ebp esi ebp
4570
        push    ebp esi ebp
4462
        mov     ebp, putimage_get2bpp
4571
        mov     ebp, putimage_get2bpp
4463
        mov     esi, putimage_init2bpp
4572
        mov     esi, putimage_init2bpp
4464
        jmp     sys_putimage_bpp
4573
        jmp     sys_putimage_bpp
4465
;-----------------------------------------------------------------------------
4574
;-----------------------------------------------------------------------------
4466
align 4
4575
align 4
4467
put_4bit_image:
4576
put_4bit_image:
4468
        push    ebp esi ebp
4577
        push    ebp esi ebp
4469
        mov     ebp, putimage_get4bpp
4578
        mov     ebp, putimage_get4bpp
4470
        mov     esi, putimage_init4bpp
4579
        mov     esi, putimage_init4bpp
4471
        jmp     sys_putimage_bpp
4580
        jmp     sys_putimage_bpp
4472
;-----------------------------------------------------------------------------
4581
;-----------------------------------------------------------------------------
4473
align 4
4582
align 4
4474
putimage_init24bpp:
4583
putimage_init24bpp:
4475
        lea     eax, [eax*3]
4584
        lea     eax, [eax*3]
4476
putimage_init8bpp:
4585
putimage_init8bpp:
4477
putimage_init9bpp:
4586
putimage_init9bpp:
4478
        ret
4587
        ret
4479
;-----------------------------------------------------------------------------
4588
;-----------------------------------------------------------------------------
4480
align 16
4589
align 16
4481
putimage_get24bpp:
4590
putimage_get24bpp:
4482
        movzx   eax, byte [esi+2]
4591
        movzx   eax, byte [esi+2]
4483
        shl     eax, 16
4592
        shl     eax, 16
4484
        mov     ax, [esi]
4593
        mov     ax, [esi]
4485
        add     esi, 3
4594
        add     esi, 3
4486
        ret     4
4595
        ret     4
4487
;-----------------------------------------------------------------------------
4596
;-----------------------------------------------------------------------------
4488
align 16
4597
align 16
4489
putimage_get8bpp:
4598
putimage_get8bpp:
4490
        movzx   eax, byte [esi]
4599
        movzx   eax, byte [esi]
4491
        push    edx
4600
        push    edx
4492
        mov     edx, [esp+8]
4601
        mov     edx, [esp+8]
4493
        mov     eax, [edx+eax*4]
4602
        mov     eax, [edx+eax*4]
4494
        pop     edx
4603
        pop     edx
4495
        inc     esi
4604
        inc     esi
4496
        ret     4
4605
        ret     4
4497
;-----------------------------------------------------------------------------
4606
;-----------------------------------------------------------------------------
4498
align 16
4607
align 16
4499
putimage_get9bpp:
4608
putimage_get9bpp:
4500
        lodsb
4609
        lodsb
4501
        mov     ah, al
4610
        mov     ah, al
4502
        shl     eax, 8
4611
        shl     eax, 8
4503
        mov     al, ah
4612
        mov     al, ah
4504
        ret     4
4613
        ret     4
4505
;-----------------------------------------------------------------------------
4614
;-----------------------------------------------------------------------------
4506
align 4
4615
align 4
4507
putimage_init1bpp:
4616
putimage_init1bpp:
4508
        add     eax, ecx
4617
        add     eax, ecx
4509
        push    ecx
4618
        push    ecx
4510
        add     eax, 7
4619
        add     eax, 7
4511
        add     ecx, 7
4620
        add     ecx, 7
4512
        shr     eax, 3
4621
        shr     eax, 3
4513
        shr     ecx, 3
4622
        shr     ecx, 3
4514
        sub     eax, ecx
4623
        sub     eax, ecx
4515
        pop     ecx
4624
        pop     ecx
4516
        ret
4625
        ret
4517
;-----------------------------------------------------------------------------
4626
;-----------------------------------------------------------------------------
4518
align 16
4627
align 16
4519
putimage_get1bpp:
4628
putimage_get1bpp:
4520
        push    edx
4629
        push    edx
4521
        mov     edx, [esp+8]
4630
        mov     edx, [esp+8]
4522
        mov     al, [edx]
4631
        mov     al, [edx]
4523
        add     al, al
4632
        add     al, al
4524
        jnz     @f
4633
        jnz     @f
4525
        lodsb
4634
        lodsb
4526
        adc     al, al
4635
        adc     al, al
4527
@@:
4636
@@:
4528
        mov     [edx], al
4637
        mov     [edx], al
4529
        sbb     eax, eax
4638
        sbb     eax, eax
4530
        and     eax, [edx+8]
4639
        and     eax, [edx+8]
4531
        add     eax, [edx+4]
4640
        add     eax, [edx+4]
4532
        pop     edx
4641
        pop     edx
4533
        ret     4
4642
        ret     4
4534
;-----------------------------------------------------------------------------
4643
;-----------------------------------------------------------------------------
4535
align 4
4644
align 4
4536
putimage_init2bpp:
4645
putimage_init2bpp:
4537
        add     eax, ecx
4646
        add     eax, ecx
4538
        push    ecx
4647
        push    ecx
4539
        add     ecx, 3
4648
        add     ecx, 3
4540
        add     eax, 3
4649
        add     eax, 3
4541
        shr     ecx, 2
4650
        shr     ecx, 2
4542
        shr     eax, 2
4651
        shr     eax, 2
4543
        sub     eax, ecx
4652
        sub     eax, ecx
4544
        pop     ecx
4653
        pop     ecx
4545
        ret
4654
        ret
4546
;-----------------------------------------------------------------------------
4655
;-----------------------------------------------------------------------------
4547
align 16
4656
align 16
4548
putimage_get2bpp:
4657
putimage_get2bpp:
4549
        push    edx
4658
        push    edx
4550
        mov     edx, [esp+8]
4659
        mov     edx, [esp+8]
4551
        mov     al, [edx]
4660
        mov     al, [edx]
4552
        mov     ah, al
4661
        mov     ah, al
4553
        shr     al, 6
4662
        shr     al, 6
4554
        shl     ah, 2
4663
        shl     ah, 2
4555
        jnz     .nonewbyte
4664
        jnz     .nonewbyte
4556
        lodsb
4665
        lodsb
4557
        mov     ah, al
4666
        mov     ah, al
4558
        shr     al, 6
4667
        shr     al, 6
4559
        shl     ah, 2
4668
        shl     ah, 2
4560
        add     ah, 1
4669
        add     ah, 1
4561
.nonewbyte:
4670
.nonewbyte:
4562
        mov     [edx], ah
4671
        mov     [edx], ah
4563
        mov     edx, [edx+4]
4672
        mov     edx, [edx+4]
4564
        movzx   eax, al
4673
        movzx   eax, al
4565
        mov     eax, [edx+eax*4]
4674
        mov     eax, [edx+eax*4]
4566
        pop     edx
4675
        pop     edx
4567
        ret     4
4676
        ret     4
4568
;-----------------------------------------------------------------------------
4677
;-----------------------------------------------------------------------------
4569
align 4
4678
align 4
4570
putimage_init4bpp:
4679
putimage_init4bpp:
4571
        add     eax, ecx
4680
        add     eax, ecx
4572
        push    ecx
4681
        push    ecx
4573
        add     ecx, 1
4682
        add     ecx, 1
4574
        add     eax, 1
4683
        add     eax, 1
4575
        shr     ecx, 1
4684
        shr     ecx, 1
4576
        shr     eax, 1
4685
        shr     eax, 1
4577
        sub     eax, ecx
4686
        sub     eax, ecx
4578
        pop     ecx
4687
        pop     ecx
4579
        ret
4688
        ret
4580
;-----------------------------------------------------------------------------
4689
;-----------------------------------------------------------------------------
4581
align 16
4690
align 16
4582
putimage_get4bpp:
4691
putimage_get4bpp:
4583
        push    edx
4692
        push    edx
4584
        mov     edx, [esp+8]
4693
        mov     edx, [esp+8]
4585
        add     byte [edx], 80h
4694
        add     byte [edx], 80h
4586
        jc      @f
4695
        jc      @f
4587
        movzx   eax, byte [edx+1]
4696
        movzx   eax, byte [edx+1]
4588
        mov     edx, [edx+4]
4697
        mov     edx, [edx+4]
4589
        and     eax, 0x0F
4698
        and     eax, 0x0F
4590
        mov     eax, [edx+eax*4]
4699
        mov     eax, [edx+eax*4]
4591
        pop     edx
4700
        pop     edx
4592
        ret     4
4701
        ret     4
4593
@@:
4702
@@:
4594
        movzx   eax, byte [esi]
4703
        movzx   eax, byte [esi]
4595
        add     esi, 1
4704
        add     esi, 1
4596
        mov     [edx+1], al
4705
        mov     [edx+1], al
4597
        shr     eax, 4
4706
        shr     eax, 4
4598
        mov     edx, [edx+4]
4707
        mov     edx, [edx+4]
4599
        mov     eax, [edx+eax*4]
4708
        mov     eax, [edx+eax*4]
4600
        pop     edx
4709
        pop     edx
4601
        ret     4
4710
        ret     4
4602
;-----------------------------------------------------------------------------
4711
;-----------------------------------------------------------------------------
4603
align 4
4712
align 4
4604
putimage_init32bpp:
4713
putimage_init32bpp:
4605
        shl     eax, 2
4714
        shl     eax, 2
4606
        ret
4715
        ret
4607
;-----------------------------------------------------------------------------
4716
;-----------------------------------------------------------------------------
4608
align 16
4717
align 16
4609
putimage_get32bpp:
4718
putimage_get32bpp:
4610
        lodsd
4719
        lodsd
4611
        ret     4
4720
        ret     4
4612
;-----------------------------------------------------------------------------
4721
;-----------------------------------------------------------------------------
4613
align 4
4722
align 4
4614
putimage_init15bpp:
4723
putimage_init15bpp:
4615
putimage_init16bpp:
4724
putimage_init16bpp:
4616
        add     eax, eax
4725
        add     eax, eax
4617
        ret
4726
        ret
4618
;-----------------------------------------------------------------------------
4727
;-----------------------------------------------------------------------------
4619
align 16
4728
align 16
4620
putimage_get15bpp:
4729
putimage_get15bpp:
4621
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
4730
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
4622
        push    ecx edx
4731
        push    ecx edx
4623
        movzx   eax, word [esi]
4732
        movzx   eax, word [esi]
4624
        add     esi, 2
4733
        add     esi, 2
4625
        mov     ecx, eax
4734
        mov     ecx, eax
4626
        mov     edx, eax
4735
        mov     edx, eax
4627
        and     eax, 0x1F
4736
        and     eax, 0x1F
4628
        and     ecx, 0x1F shl 5
4737
        and     ecx, 0x1F shl 5
4629
        and     edx, 0x1F shl 10
4738
        and     edx, 0x1F shl 10
4630
        shl     eax, 3
4739
        shl     eax, 3
4631
        shl     ecx, 6
4740
        shl     ecx, 6
4632
        shl     edx, 9
4741
        shl     edx, 9
4633
        or      eax, ecx
4742
        or      eax, ecx
4634
        or      eax, edx
4743
        or      eax, edx
4635
        pop     edx ecx
4744
        pop     edx ecx
4636
        ret     4
4745
        ret     4
4637
;-----------------------------------------------------------------------------
4746
;-----------------------------------------------------------------------------
4638
align 16
4747
align 16
4639
putimage_get16bpp:
4748
putimage_get16bpp:
4640
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
4749
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
4641
        push    ecx edx
4750
        push    ecx edx
4642
        movzx   eax, word [esi]
4751
        movzx   eax, word [esi]
4643
        add     esi, 2
4752
        add     esi, 2
4644
        mov     ecx, eax
4753
        mov     ecx, eax
4645
        mov     edx, eax
4754
        mov     edx, eax
4646
        and     eax, 0x1F
4755
        and     eax, 0x1F
4647
        and     ecx, 0x3F shl 5
4756
        and     ecx, 0x3F shl 5
4648
        and     edx, 0x1F shl 11
4757
        and     edx, 0x1F shl 11
4649
        shl     eax, 3
4758
        shl     eax, 3
4650
        shl     ecx, 5
4759
        shl     ecx, 5
4651
        shl     edx, 8
4760
        shl     edx, 8
4652
        or      eax, ecx
4761
        or      eax, ecx
4653
        or      eax, edx
4762
        or      eax, edx
4654
        pop     edx ecx
4763
        pop     edx ecx
4655
        ret     4
4764
        ret     4
4656
;-----------------------------------------------------------------------------
4765
;-----------------------------------------------------------------------------
4657
;align 4
4766
;align 4
4658
; eax x beginning
4767
; eax x beginning
4659
; ebx y beginning
4768
; ebx y beginning
4660
; ecx x end
4769
; ecx x end
4661
        ; edx y end
4770
        ; edx y end
4662
; edi color
4771
; edi color
4663
;__sys_drawbar:
4772
;__sys_drawbar:
4664
;        mov     esi, [current_slot]
4773
;        mov     esi, [current_slot]
4665
;        add     eax, [esi+APPDATA.wnd_clientbox.left]
4774
;        add     eax, [esi+APPDATA.wnd_clientbox.left]
4666
;        add     ecx, [esi+APPDATA.wnd_clientbox.left]
4775
;        add     ecx, [esi+APPDATA.wnd_clientbox.left]
4667
;        add     ebx, [esi+APPDATA.wnd_clientbox.top]
4776
;        add     ebx, [esi+APPDATA.wnd_clientbox.top]
4668
;        add     edx, [esi+APPDATA.wnd_clientbox.top]
4777
;        add     edx, [esi+APPDATA.wnd_clientbox.top]
4669
;--------------------------------------
4778
;--------------------------------------
4670
;align 4
4779
;align 4
4671
;.forced:
4780
;.forced:
4672
;        call    vesa20_drawbar
4781
;        call    vesa20_drawbar
4673
;        call    [draw_pointer]
4782
;        call    [draw_pointer]
4674
;        ret
4783
;        ret
4675
;-----------------------------------------------------------------------------
4784
;-----------------------------------------------------------------------------
4676
align 4
4785
align 4
4677
kb_write_wait_ack:
4786
kb_write_wait_ack:
4678
 
4787
 
4679
        push    ecx edx
4788
        push    ecx edx
4680
 
4789
 
4681
        mov     dl, al
4790
        mov     dl, al
4682
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
4791
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
4683
.wait_output_ready:
4792
.wait_output_ready:
4684
        in      al, 0x64
4793
        in      al, 0x64
4685
        test    al, 2
4794
        test    al, 2
4686
        jz      @f
4795
        jz      @f
4687
        loop    .wait_output_ready
4796
        loop    .wait_output_ready
4688
        mov     ah, 1
4797
        mov     ah, 1
4689
        jmp     .nothing
4798
        jmp     .nothing
4690
@@:
4799
@@:
4691
        mov     al, dl
4800
        mov     al, dl
4692
        out     0x60, al
4801
        out     0x60, al
4693
        mov     ecx, 0xfffff; last 0xffff, new value in view of fast CPU's
4802
        mov     ecx, 0xfffff; last 0xffff, new value in view of fast CPU's
4694
.wait_ack:
4803
.wait_ack:
4695
        in      al, 0x64
4804
        in      al, 0x64
4696
        test    al, 1
4805
        test    al, 1
4697
        jnz     @f
4806
        jnz     @f
4698
        loop    .wait_ack
4807
        loop    .wait_ack
4699
        mov     ah, 1
4808
        mov     ah, 1
4700
        jmp     .nothing
4809
        jmp     .nothing
4701
@@:
4810
@@:
4702
        in      al, 0x60
4811
        in      al, 0x60
4703
        xor     ah, ah
4812
        xor     ah, ah
4704
 
4813
 
4705
.nothing:
4814
.nothing:
4706
        pop     edx ecx
4815
        pop     edx ecx
4707
 
4816
 
4708
        ret
4817
        ret
4709
;-----------------------------------------------------------------------------
4818
;-----------------------------------------------------------------------------
4710
 
4819
 
4711
setmouse:  ; set mousepicture -pointer
4820
setmouse:  ; set mousepicture -pointer
4712
           ; ps2 mouse enable
4821
           ; ps2 mouse enable
4713
 
4822
 
4714
;        mov     [MOUSE_PICTURE], dword mousepointer
4823
;        mov     [MOUSE_PICTURE], dword mousepointer
4715
 
4824
 
4716
        cli
4825
        cli
4717
 
4826
 
4718
        ret
4827
        ret
4719
 
4828
 
4720
if used _rdtsc
4829
if used _rdtsc
4721
_rdtsc:
4830
_rdtsc:
4722
        bt      [cpu_caps], CAPS_TSC
4831
        bt      [cpu_caps], CAPS_TSC
4723
        jnc     ret_rdtsc
4832
        jnc     ret_rdtsc
4724
        rdtsc
4833
        rdtsc
4725
        ret
4834
        ret
4726
   ret_rdtsc:
4835
   ret_rdtsc:
4727
        mov     edx, 0xffffffff
4836
        mov     edx, 0xffffffff
4728
        mov     eax, 0xffffffff
4837
        mov     eax, 0xffffffff
4729
        ret
4838
        ret
4730
end if
4839
end if
4731
 
4840
 
4732
sys_msg_board_str:
4841
sys_msg_board_str:
4733
 
4842
 
4734
        pushad
4843
        pushad
4735
   @@:
4844
   @@:
4736
        cmp     [esi], byte 0
4845
        cmp     [esi], byte 0
4737
        je      @f
4846
        je      @f
4738
        mov     ebx, 1
4847
        mov     ebx, 1
4739
        movzx   ecx, byte [esi]
4848
        movzx   ecx, byte [esi]
4740
        call    sys_msg_board
4849
        call    sys_msg_board
4741
        inc     esi
4850
        inc     esi
4742
        jmp     @b
4851
        jmp     @b
4743
   @@:
4852
   @@:
4744
        popad
4853
        popad
4745
        ret
4854
        ret
4746
 
4855
 
4747
sys_msg_board_byte:
4856
sys_msg_board_byte:
4748
; in: al = byte to display
4857
; in: al = byte to display
4749
; out: nothing
4858
; out: nothing
4750
; destroys: nothing
4859
; destroys: nothing
4751
        pushad
4860
        pushad
4752
        mov     ecx, 2
4861
        mov     ecx, 2
4753
        shl     eax, 24
4862
        shl     eax, 24
4754
        jmp     @f
4863
        jmp     @f
4755
 
4864
 
4756
sys_msg_board_word:
4865
sys_msg_board_word:
4757
; in: ax = word to display
4866
; in: ax = word to display
4758
; out: nothing
4867
; out: nothing
4759
; destroys: nothing
4868
; destroys: nothing
4760
        pushad
4869
        pushad
4761
        mov     ecx, 4
4870
        mov     ecx, 4
4762
        shl     eax, 16
4871
        shl     eax, 16
4763
        jmp     @f
4872
        jmp     @f
4764
 
4873
 
4765
sys_msg_board_dword:
4874
sys_msg_board_dword:
4766
; in: eax = dword to display
4875
; in: eax = dword to display
4767
; out: nothing
4876
; out: nothing
4768
; destroys: nothing
4877
; destroys: nothing
4769
        pushad
4878
        pushad
4770
        mov     ecx, 8
4879
        mov     ecx, 8
4771
@@:
4880
@@:
4772
        push    ecx
4881
        push    ecx
4773
        rol     eax, 4
4882
        rol     eax, 4
4774
        push    eax
4883
        push    eax
4775
        and     al, 0xF
4884
        and     al, 0xF
4776
        cmp     al, 10
4885
        cmp     al, 10
4777
        sbb     al, 69h
4886
        sbb     al, 69h
4778
        das
4887
        das
4779
        mov     cl, al
4888
        mov     cl, al
4780
        xor     ebx, ebx
4889
        xor     ebx, ebx
4781
        inc     ebx
4890
        inc     ebx
4782
        call    sys_msg_board
4891
        call    sys_msg_board
4783
        pop     eax
4892
        pop     eax
4784
        pop     ecx
4893
        pop     ecx
4785
        loop    @b
4894
        loop    @b
4786
        popad
4895
        popad
4787
        ret
4896
        ret
4788
 
4897
 
4789
msg_board_data_size = 65536 ; Must be power of two
4898
msg_board_data_size = 65536 ; Must be power of two
4790
 
4899
 
4791
uglobal
4900
uglobal
4792
  msg_board_data  rb msg_board_data_size
4901
  msg_board_data  rb msg_board_data_size
4793
  msg_board_count dd 0x0
4902
  msg_board_count dd 0x0
4794
endg
4903
endg
4795
 
4904
 
4796
sys_msg_board:
4905
sys_msg_board:
4797
 
4906
 
4798
; ebx=1 : write :  bl byte to write
4907
; ebx=1 : write :  bl byte to write
4799
; ebx=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4908
; ebx=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4800
 
4909
 
4801
        push    eax ebx                 ; Save eax and ebx, since we're restoring their order required.
4910
        push    eax ebx                 ; Save eax and ebx, since we're restoring their order required.
4802
        mov     eax, ebx
4911
        mov     eax, ebx
4803
        mov     ebx, ecx
4912
        mov     ebx, ecx
4804
 
4913
 
4805
        mov     ecx, [msg_board_count]
4914
        mov     ecx, [msg_board_count]
4806
        cmp     eax, 1
4915
        cmp     eax, 1
4807
        jne     .smbl1
4916
        jne     .smbl1
4808
 
4917
 
4809
if defined debug_com_base
4918
if defined debug_com_base
4810
 
4919
 
4811
        push    dx ax
4920
        push    dx ax
4812
 
4921
 
4813
       @@:                              ; Wait for empty transmit register  (yes, this slows down system..)
4922
       @@:                              ; Wait for empty transmit register  (yes, this slows down system..)
4814
        mov     dx, debug_com_base+5
4923
        mov     dx, debug_com_base+5
4815
        in      al, dx
4924
        in      al, dx
4816
        test    al, 1 shl 5
4925
        test    al, 1 shl 5
4817
        jz      @r
4926
        jz      @r
4818
 
4927
 
4819
        mov     dx, debug_com_base      ; Output the byte
4928
        mov     dx, debug_com_base      ; Output the byte
4820
        mov     al, bl
4929
        mov     al, bl
4821
        out     dx, al
4930
        out     dx, al
4822
 
4931
 
4823
        pop     ax dx
4932
        pop     ax dx
4824
 
4933
 
4825
end if
4934
end if
4826
 
4935
 
4827
        mov     [msg_board_data+ecx], bl
4936
        mov     [msg_board_data+ecx], bl
4828
; // if debug_direct_print == 1
4937
; // if debug_direct_print == 1
4829
        cmp     byte [debug_direct_print], 1
4938
        cmp     byte [debug_direct_print], 1
4830
        jnz     @f
4939
        jnz     @f
4831
        pusha
4940
        pusha
4832
iglobal
4941
iglobal
4833
msg_board_pos   dd      (42*6)*65536+10 ; for printing debug output on the screen
4942
msg_board_pos   dd      (42*6)*65536+10 ; for printing debug output on the screen
4834
endg
4943
endg
4835
        lea     edx, [msg_board_data+ecx]
4944
        lea     edx, [msg_board_data+ecx]
4836
        mov     ecx, 0x40FFFFFF
4945
        mov     ecx, 0x40FFFFFF
4837
        mov     ebx, [msg_board_pos]
4946
        mov     ebx, [msg_board_pos]
4838
        mov     edi, 1
4947
        mov     edi, 1
4839
        mov     esi, 1
4948
        mov     esi, 1
4840
        call    dtext
4949
        call    dtext
4841
        popa
4950
        popa
4842
        add     word [msg_board_pos+2], 6
4951
        add     word [msg_board_pos+2], 6
4843
        cmp     bl, 10
4952
        cmp     bl, 10
4844
        jnz     @f
4953
        jnz     @f
4845
        mov     word [msg_board_pos+2], (42*6)
4954
        mov     word [msg_board_pos+2], (42*6)
4846
        add     word [msg_board_pos], 10
4955
        add     word [msg_board_pos], 10
4847
        mov     ax, word [_display.width]
4956
        mov     ax, word [_display.width]
4848
        cmp     word [msg_board_pos], ax
4957
        cmp     word [msg_board_pos], ax
4849
        jb      @f
4958
        jb      @f
4850
        mov     word [msg_board_pos], 10
4959
        mov     word [msg_board_pos], 10
4851
@@:
4960
@@:
4852
; // end if
4961
; // end if
4853
 
4962
 
4854
if 0
4963
if 0
4855
        pusha
4964
        pusha
4856
        mov     al, bl
4965
        mov     al, bl
4857
        mov     edx, 402h
4966
        mov     edx, 402h
4858
        out     dx, al
4967
        out     dx, al
4859
        popa
4968
        popa
4860
end if
4969
end if
4861
        inc     ecx
4970
        inc     ecx
4862
        and     ecx, msg_board_data_size - 1
4971
        and     ecx, msg_board_data_size - 1
4863
        mov     [msg_board_count], ecx
4972
        mov     [msg_board_count], ecx
4864
 
4973
 
4865
        pop     ebx eax
4974
        pop     ebx eax
4866
        ret
4975
        ret
4867
.smbl1:
4976
.smbl1:
4868
        cmp     eax, 2
4977
        cmp     eax, 2
4869
        jne     .smbl2
4978
        jne     .smbl2
4870
        test    ecx, ecx
4979
        test    ecx, ecx
4871
        jz      .smbl21
4980
        jz      .smbl21
4872
 
4981
 
4873
        add     esp, 8                  ; Returning data in ebx and eax, so no need to restore them.
4982
        add     esp, 8                  ; Returning data in ebx and eax, so no need to restore them.
4874
        mov     eax, msg_board_data+1
4983
        mov     eax, msg_board_data+1
4875
        mov     ebx, msg_board_data
4984
        mov     ebx, msg_board_data
4876
        movzx   edx, byte [ebx]
4985
        movzx   edx, byte [ebx]
4877
        call    memmove
4986
        call    memmove
4878
        dec     [msg_board_count]
4987
        dec     [msg_board_count]
4879
        mov     [esp + 32], edx ;eax
4988
        mov     [esp + 32], edx ;eax
4880
        mov     [esp + 20], dword 1
4989
        mov     [esp + 20], dword 1
4881
        ret
4990
        ret
4882
.smbl21:
4991
.smbl21:
4883
        mov     [esp+32], ecx
4992
        mov     [esp+32], ecx
4884
        mov     [esp+20], ecx
4993
        mov     [esp+20], ecx
4885
.smbl2:
4994
.smbl2:
4886
        pop     ebx eax
4995
        pop     ebx eax
4887
        ret
4996
        ret
4888
 
4997
 
4889
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4998
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4890
;; 66 sys function.                                                ;;
4999
;; 66 sys function.                                                ;;
4891
;; in eax=66,ebx in [0..5],ecx,edx                                 ;;
5000
;; in eax=66,ebx in [0..5],ecx,edx                                 ;;
4892
;; out eax                                                         ;;
5001
;; out eax                                                         ;;
4893
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5002
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4894
iglobal
5003
iglobal
4895
align 4
5004
align 4
4896
f66call:
5005
f66call:
4897
           dd sys_process_def.1   ; 1 = set keyboard mode
5006
           dd sys_process_def.1   ; 1 = set keyboard mode
4898
           dd sys_process_def.2   ; 2 = get keyboard mode
5007
           dd sys_process_def.2   ; 2 = get keyboard mode
4899
           dd sys_process_def.3   ; 3 = get keyboard ctrl, alt, shift
5008
           dd sys_process_def.3   ; 3 = get keyboard ctrl, alt, shift
4900
           dd sys_process_def.4   ; 4 = set system-wide hotkey
5009
           dd sys_process_def.4   ; 4 = set system-wide hotkey
4901
           dd sys_process_def.5   ; 5 = delete installed hotkey
5010
           dd sys_process_def.5   ; 5 = delete installed hotkey
4902
           dd sys_process_def.6   ; 6 = disable input, work only hotkeys
5011
           dd sys_process_def.6   ; 6 = disable input, work only hotkeys
4903
           dd sys_process_def.7   ; 7 = enable input, opposition to f.66.6
5012
           dd sys_process_def.7   ; 7 = enable input, opposition to f.66.6
4904
endg
5013
endg
4905
;-----------------------------------------------------------------------------
5014
;-----------------------------------------------------------------------------
4906
align 4
5015
align 4
4907
sys_process_def:
5016
sys_process_def:
4908
        dec     ebx
5017
        dec     ebx
4909
        cmp     ebx, 7
5018
        cmp     ebx, 7
4910
        jae     .not_support    ;if >=8 then or eax,-1
5019
        jae     .not_support    ;if >=8 then or eax,-1
4911
 
5020
 
4912
        mov     edi, [CURRENT_TASK]
5021
        mov     edi, [CURRENT_TASK]
4913
        jmp     dword [f66call+ebx*4]
5022
        jmp     dword [f66call+ebx*4]
4914
 
5023
 
4915
.not_support:
5024
.not_support:
4916
        or      eax, -1
5025
        or      eax, -1
4917
        ret
5026
        ret
4918
;-----------------------------------------------------------------------------
5027
;-----------------------------------------------------------------------------
4919
align 4
5028
align 4
4920
.1:
5029
.1:
4921
        shl     edi, 8
5030
        shl     edi, 8
4922
        mov     [edi+SLOT_BASE + APPDATA.keyboard_mode], cl
5031
        mov     [edi+SLOT_BASE + APPDATA.keyboard_mode], cl
4923
 
5032
 
4924
        ret
5033
        ret
4925
;-----------------------------------------------------------------------------
5034
;-----------------------------------------------------------------------------
4926
align 4
5035
align 4
4927
.2:                             ; 2 = get keyboard mode
5036
.2:                             ; 2 = get keyboard mode
4928
        shl     edi, 8
5037
        shl     edi, 8
4929
        movzx   eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
5038
        movzx   eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4930
        mov     [esp+32], eax
5039
        mov     [esp+32], eax
4931
        ret
5040
        ret
4932
;-----------------------------------------------------------------------------
5041
;-----------------------------------------------------------------------------
4933
align 4
5042
align 4
4934
.3:                             ;3 = get keyboard ctrl, alt, shift
5043
.3:                             ;3 = get keyboard ctrl, alt, shift
4935
        mov     eax, [kb_state]
5044
        mov     eax, [kb_state]
4936
        mov     [esp+32], eax
5045
        mov     [esp+32], eax
4937
        ret
5046
        ret
4938
;-----------------------------------------------------------------------------
5047
;-----------------------------------------------------------------------------
4939
align 4
5048
align 4
4940
.4:
5049
.4:
4941
        mov     eax, hotkey_list
5050
        mov     eax, hotkey_list
4942
@@:
5051
@@:
4943
        cmp     dword [eax+8], 0
5052
        cmp     dword [eax+8], 0
4944
        jz      .found_free
5053
        jz      .found_free
4945
        add     eax, 16
5054
        add     eax, 16
4946
        cmp     eax, hotkey_list+16*256
5055
        cmp     eax, hotkey_list+16*256
4947
        jb      @b
5056
        jb      @b
4948
        mov     dword [esp+32], 1
5057
        mov     dword [esp+32], 1
4949
        ret
5058
        ret
4950
.found_free:
5059
.found_free:
4951
        mov     [eax+8], edi
5060
        mov     [eax+8], edi
4952
        mov     [eax+4], edx
5061
        mov     [eax+4], edx
4953
        movzx   ecx, cl
5062
        movzx   ecx, cl
4954
        lea     ecx, [hotkey_scancodes+ecx*4]
5063
        lea     ecx, [hotkey_scancodes+ecx*4]
4955
        mov     edx, [ecx]
5064
        mov     edx, [ecx]
4956
        mov     [eax], edx
5065
        mov     [eax], edx
4957
        mov     [ecx], eax
5066
        mov     [ecx], eax
4958
        mov     [eax+12], ecx
5067
        mov     [eax+12], ecx
4959
        test    edx, edx
5068
        test    edx, edx
4960
        jz      @f
5069
        jz      @f
4961
        mov     [edx+12], eax
5070
        mov     [edx+12], eax
4962
@@:
5071
@@:
4963
        and     dword [esp+32], 0
5072
        and     dword [esp+32], 0
4964
        ret
5073
        ret
4965
;-----------------------------------------------------------------------------
5074
;-----------------------------------------------------------------------------
4966
align 4
5075
align 4
4967
.5:
5076
.5:
4968
        movzx   ebx, cl
5077
        movzx   ebx, cl
4969
        lea     ebx, [hotkey_scancodes+ebx*4]
5078
        lea     ebx, [hotkey_scancodes+ebx*4]
4970
        mov     eax, [ebx]
5079
        mov     eax, [ebx]
4971
.scan:
5080
.scan:
4972
        test    eax, eax
5081
        test    eax, eax
4973
        jz      .notfound
5082
        jz      .notfound
4974
        cmp     [eax+8], edi
5083
        cmp     [eax+8], edi
4975
        jnz     .next
5084
        jnz     .next
4976
        cmp     [eax+4], edx
5085
        cmp     [eax+4], edx
4977
        jz      .found
5086
        jz      .found
4978
.next:
5087
.next:
4979
        mov     eax, [eax]
5088
        mov     eax, [eax]
4980
        jmp     .scan
5089
        jmp     .scan
4981
.notfound:
5090
.notfound:
4982
        mov     dword [esp+32], 1
5091
        mov     dword [esp+32], 1
4983
        ret
5092
        ret
4984
.found:
5093
.found:
4985
        mov     ecx, [eax]
5094
        mov     ecx, [eax]
4986
        jecxz   @f
5095
        jecxz   @f
4987
        mov     edx, [eax+12]
5096
        mov     edx, [eax+12]
4988
        mov     [ecx+12], edx
5097
        mov     [ecx+12], edx
4989
@@:
5098
@@:
4990
        mov     ecx, [eax+12]
5099
        mov     ecx, [eax+12]
4991
        mov     edx, [eax]
5100
        mov     edx, [eax]
4992
        mov     [ecx], edx
5101
        mov     [ecx], edx
4993
        xor     edx, edx
5102
        xor     edx, edx
4994
        mov     [eax+4], edx
5103
        mov     [eax+4], edx
4995
        mov     [eax+8], edx
5104
        mov     [eax+8], edx
4996
        mov     [eax+12], edx
5105
        mov     [eax+12], edx
4997
        mov     [eax], edx
5106
        mov     [eax], edx
4998
        mov     [esp+32], edx
5107
        mov     [esp+32], edx
4999
        ret
5108
        ret
5000
;-----------------------------------------------------------------------------
5109
;-----------------------------------------------------------------------------
5001
align 4
5110
align 4
5002
.6:
5111
.6:
5003
        pushfd
5112
        pushfd
5004
        cli
5113
        cli
5005
        mov     eax, [PID_lock_input]
5114
        mov     eax, [PID_lock_input]
5006
        test    eax, eax
5115
        test    eax, eax
5007
        jnz     @f
5116
        jnz     @f
5008
; get current PID
5117
; get current PID
5009
        mov     eax, [CURRENT_TASK]
5118
        mov     eax, [CURRENT_TASK]
5010
        shl     eax, 5
5119
        shl     eax, 5
5011
        mov     eax, [eax+CURRENT_TASK+TASKDATA.pid]
5120
        mov     eax, [eax+CURRENT_TASK+TASKDATA.pid]
5012
; set current PID for lock input
5121
; set current PID for lock input
5013
        mov     [PID_lock_input], eax
5122
        mov     [PID_lock_input], eax
5014
@@:
5123
@@:
5015
        popfd
5124
        popfd
5016
        ret
5125
        ret
5017
;-----------------------------------------------------------------------------
5126
;-----------------------------------------------------------------------------
5018
align 4
5127
align 4
5019
.7:
5128
.7:
5020
        mov     eax, [PID_lock_input]
5129
        mov     eax, [PID_lock_input]
5021
        test    eax, eax
5130
        test    eax, eax
5022
        jz      @f
5131
        jz      @f
5023
; get current PID
5132
; get current PID
5024
        mov     ebx, [CURRENT_TASK]
5133
        mov     ebx, [CURRENT_TASK]
5025
        shl     ebx, 5
5134
        shl     ebx, 5
5026
        mov     ebx, [ebx+CURRENT_TASK+TASKDATA.pid]
5135
        mov     ebx, [ebx+CURRENT_TASK+TASKDATA.pid]
5027
; compare current lock input with current PID
5136
; compare current lock input with current PID
5028
        cmp     ebx, eax
5137
        cmp     ebx, eax
5029
        jne     @f
5138
        jne     @f
5030
 
5139
 
5031
        xor     eax, eax
5140
        xor     eax, eax
5032
        mov     [PID_lock_input], eax
5141
        mov     [PID_lock_input], eax
5033
@@:
5142
@@:
5034
        ret
5143
        ret
5035
;-----------------------------------------------------------------------------
5144
;-----------------------------------------------------------------------------
5036
uglobal
5145
uglobal
5037
  PID_lock_input dd 0x0
5146
  PID_lock_input dd 0x0
5038
endg
5147
endg
5039
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5148
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5040
;; 61 sys function.                                                ;;
5149
;; 61 sys function.                                                ;;
5041
;; in eax=61,ebx in [1..3]                                         ;;
5150
;; in eax=61,ebx in [1..3]                                         ;;
5042
;; out eax                                                         ;;
5151
;; out eax                                                         ;;
5043
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5152
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5044
iglobal
5153
iglobal
5045
align 4
5154
align 4
5046
f61call:
5155
f61call:
5047
           dd sys_gs.1   ; resolution
5156
           dd sys_gs.1   ; resolution
5048
           dd sys_gs.2   ; bits per pixel
5157
           dd sys_gs.2   ; bits per pixel
5049
           dd sys_gs.3   ; bytes per scanline
5158
           dd sys_gs.3   ; bytes per scanline
5050
endg
5159
endg
5051
 
5160
 
5052
 
5161
 
5053
align 4
5162
align 4
5054
 
5163
 
5055
sys_gs:                         ; direct screen access
5164
sys_gs:                         ; direct screen access
5056
        dec     ebx
5165
        dec     ebx
5057
        cmp     ebx, 2
5166
        cmp     ebx, 2
5058
        ja      .not_support
5167
        ja      .not_support
5059
        jmp     dword [f61call+ebx*4]
5168
        jmp     dword [f61call+ebx*4]
5060
.not_support:
5169
.not_support:
5061
        or      [esp+32], dword -1
5170
        or      [esp+32], dword -1
5062
        ret
5171
        ret
5063
 
5172
 
5064
 
5173
 
5065
.1:                             ; resolution
5174
.1:                             ; resolution
5066
        mov     eax, [_display.width]
5175
        mov     eax, [_display.width]
5067
        shl     eax, 16
5176
        shl     eax, 16
5068
        mov     ax, word [_display.height]
5177
        mov     ax, word [_display.height]
5069
        mov     [esp+32], eax
5178
        mov     [esp+32], eax
5070
        ret
5179
        ret
5071
.2:                             ; bits per pixel
5180
.2:                             ; bits per pixel
5072
        mov     eax, [_display.bits_per_pixel]
5181
        mov     eax, [_display.bits_per_pixel]
5073
        mov     [esp+32], eax
5182
        mov     [esp+32], eax
5074
        ret
5183
        ret
5075
.3:                             ; bytes per scanline
5184
.3:                             ; bytes per scanline
5076
        mov     eax, [_display.lfb_pitch]
5185
        mov     eax, [_display.lfb_pitch]
5077
        mov     [esp+32], eax
5186
        mov     [esp+32], eax
5078
        ret
5187
        ret
5079
 
5188
 
5080
align 4  ;  system functions
5189
align 4  ;  system functions
5081
 
5190
 
5082
syscall_setpixel:                       ; SetPixel
5191
syscall_setpixel:                       ; SetPixel
5083
 
5192
 
5084
        mov     eax, ebx
5193
        mov     eax, ebx
5085
        mov     ebx, ecx
5194
        mov     ebx, ecx
5086
        mov     ecx, edx
5195
        mov     ecx, edx
5087
        mov     edx, [TASK_BASE]
5196
        mov     edx, [TASK_BASE]
5088
        add     eax, [edx-twdw+WDATA.box.left]
5197
        add     eax, [edx-twdw+WDATA.box.left]
5089
        add     ebx, [edx-twdw+WDATA.box.top]
5198
        add     ebx, [edx-twdw+WDATA.box.top]
5090
        mov     edi, [current_slot]
5199
        mov     edi, [current_slot]
5091
        add     eax, [edi+APPDATA.wnd_clientbox.left]
5200
        add     eax, [edi+APPDATA.wnd_clientbox.left]
5092
        add     ebx, [edi+APPDATA.wnd_clientbox.top]
5201
        add     ebx, [edi+APPDATA.wnd_clientbox.top]
5093
        xor     edi, edi ; no force
5202
        xor     edi, edi ; no force
5094
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 save to mouseunder area
5203
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 save to mouseunder area
5095
;        jmp     [putpixel]
5204
;        jmp     [putpixel]
5096
        jmp     __sys_putpixel
5205
        jmp     __sys_putpixel
5097
 
5206
 
5098
align 4
5207
align 4
5099
 
5208
 
5100
syscall_writetext:                      ; WriteText
5209
syscall_writetext:                      ; WriteText
5101
 
5210
 
5102
        mov     eax, [TASK_BASE]
5211
        mov     eax, [TASK_BASE]
5103
        mov     ebp, [eax-twdw+WDATA.box.left]
5212
        mov     ebp, [eax-twdw+WDATA.box.left]
5104
        push    esi
5213
        push    esi
5105
        mov     esi, [current_slot]
5214
        mov     esi, [current_slot]
5106
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5215
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5107
        shl     ebp, 16
5216
        shl     ebp, 16
5108
        add     ebp, [eax-twdw+WDATA.box.top]
5217
        add     ebp, [eax-twdw+WDATA.box.top]
5109
        add     bp, word[esi+APPDATA.wnd_clientbox.top]
5218
        add     bp, word[esi+APPDATA.wnd_clientbox.top]
5110
        pop     esi
5219
        pop     esi
5111
        test    ecx, 0x08000000  ; redirect the output to the user area
5220
        test    ecx, 0x08000000  ; redirect the output to the user area
5112
        jnz     @f
5221
        jnz     @f
5113
        add     ebx, ebp
5222
        add     ebx, ebp
5114
align 4
5223
align 4
5115
@@:
5224
@@:
5116
        mov     eax, edi
5225
        mov     eax, edi
5117
        test    ecx, 0x08000000  ; redirect the output to the user area
5226
        test    ecx, 0x08000000  ; redirect the output to the user area
5118
        jnz     dtext
5227
        jnz     dtext
5119
        xor     edi, edi
5228
        xor     edi, edi
5120
        jmp     dtext
5229
        jmp     dtext
5121
 
5230
 
5122
align 4
5231
align 4
5123
 
5232
 
5124
syscall_drawrect:                       ; DrawRect
5233
syscall_drawrect:                       ; DrawRect
5125
 
5234
 
5126
        mov     edi, edx ; color + gradient
5235
        mov     edi, edx ; color + gradient
5127
        and     edi, 0x80FFFFFF
5236
        and     edi, 0x80FFFFFF
5128
        test    bx, bx  ; x.size
5237
        test    bx, bx  ; x.size
5129
        je      .drectr
5238
        je      .drectr
5130
        test    cx, cx ; y.size
5239
        test    cx, cx ; y.size
5131
        je      .drectr
5240
        je      .drectr
5132
 
5241
 
5133
        mov     eax, ebx ; bad idea
5242
        mov     eax, ebx ; bad idea
5134
        mov     ebx, ecx
5243
        mov     ebx, ecx
5135
 
5244
 
5136
        movzx   ecx, ax ; ecx - x.size
5245
        movzx   ecx, ax ; ecx - x.size
5137
        shr     eax, 16 ; eax - x.coord
5246
        shr     eax, 16 ; eax - x.coord
5138
        movzx   edx, bx ; edx - y.size
5247
        movzx   edx, bx ; edx - y.size
5139
        shr     ebx, 16 ; ebx - y.coord
5248
        shr     ebx, 16 ; ebx - y.coord
5140
        mov     esi, [current_slot]
5249
        mov     esi, [current_slot]
5141
 
5250
 
5142
        add     eax, [esi + APPDATA.wnd_clientbox.left]
5251
        add     eax, [esi + APPDATA.wnd_clientbox.left]
5143
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
5252
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
5144
        add     ecx, eax
5253
        add     ecx, eax
5145
        add     edx, ebx
5254
        add     edx, ebx
5146
;        jmp     [drawbar]
5255
;        jmp     [drawbar]
5147
        jmp     vesa20_drawbar
5256
        jmp     vesa20_drawbar
5148
.drectr:
5257
.drectr:
5149
        ret
5258
        ret
5150
 
5259
 
5151
align 4
5260
align 4
5152
syscall_getscreensize:                  ; GetScreenSize
5261
syscall_getscreensize:                  ; GetScreenSize
5153
        mov     ax, word [_display.width]
5262
        mov     ax, word [_display.width]
5154
        dec     ax
5263
        dec     ax
5155
        shl     eax, 16
5264
        shl     eax, 16
5156
        mov     ax, word [_display.height]
5265
        mov     ax, word [_display.height]
5157
        dec     ax
5266
        dec     ax
5158
        mov     [esp + 32], eax
5267
        mov     [esp + 32], eax
5159
        ret
5268
        ret
5160
;-----------------------------------------------------------------------------
5269
;-----------------------------------------------------------------------------
5161
align 4
5270
align 4
5162
syscall_cdaudio:
5271
syscall_cdaudio:
5163
; ECX - position of CD/DVD-drive
5272
; ECX - position of CD/DVD-drive
5164
; from 0=Primary Master to 3=Secondary Slave for first IDE contr.
5273
; from 0=Primary Master to 3=Secondary Slave for first IDE contr.
5165
; from 4=Primary Master to 7=Secondary Slave for second IDE contr.
5274
; from 4=Primary Master to 7=Secondary Slave for second IDE contr.
5166
; from 8=Primary Master to 11=Secondary Slave for third IDE contr.
5275
; from 8=Primary Master to 11=Secondary Slave for third IDE contr.
5167
        cmp     ecx, 11
5276
        cmp     ecx, 11
5168
        ja      .exit
5277
        ja      .exit
5169
 
5278
 
5170
        mov     eax, ecx
5279
        mov     eax, ecx
5171
        shr     eax, 2
5280
        shr     eax, 2
5172
        lea     eax, [eax*5]
5281
        lea     eax, [eax*5]
5173
        mov     al, [eax+DRIVE_DATA+1]
5282
        mov     al, [eax+DRIVE_DATA+1]
5174
 
5283
 
5175
        push    ecx ebx
5284
        push    ecx ebx
5176
        mov     ebx, ecx
5285
        mov     ebx, ecx
5177
        and     ebx, 11b
5286
        and     ebx, 11b
5178
        shl     ebx, 1
5287
        shl     ebx, 1
5179
        mov     cl, 6
5288
        mov     cl, 6
5180
        sub     cl, bl
5289
        sub     cl, bl
5181
        shr     al, cl
5290
        shr     al, cl
5182
        test    al, 2 ; it's not an ATAPI device
5291
        test    al, 2 ; it's not an ATAPI device
5183
        pop     ebx ecx
5292
        pop     ebx ecx
5184
 
5293
 
5185
        jz      .exit
5294
        jz      .exit
5186
 
5295
 
5187
        cmp     ebx, 4
5296
        cmp     ebx, 4
5188
        je      .eject
5297
        je      .eject
5189
 
5298
 
5190
        cmp     ebx, 5
5299
        cmp     ebx, 5
5191
        je      .load
5300
        je      .load
5192
;--------------------------------------
5301
;--------------------------------------
5193
.exit:
5302
.exit:
5194
        ret
5303
        ret
5195
;--------------------------------------
5304
;--------------------------------------
5196
.load:
5305
.load:
5197
        call    .reserve
5306
        call    .reserve
5198
        call    LoadMedium
5307
        call    LoadMedium
5199
        jmp     .free
5308
        jmp     .free
5200
;--------------------------------------
5309
;--------------------------------------
5201
.eject:
5310
.eject:
5202
        call    .reserve
5311
        call    .reserve
5203
        call    clear_CD_cache
5312
        call    clear_CD_cache
5204
        call    allow_medium_removal
5313
        call    allow_medium_removal
5205
        call    EjectMedium
5314
        call    EjectMedium
5206
        jmp     .free
5315
        jmp     .free
5207
;--------------------------------------
5316
;--------------------------------------
5208
.reserve:
5317
.reserve:
5209
        call    reserve_cd
5318
        call    reserve_cd
5210
 
5319
 
5211
        mov     ebx, ecx
5320
        mov     ebx, ecx
5212
        inc     ebx
5321
        inc     ebx
5213
        mov     [cdpos], ebx
5322
        mov     [cdpos], ebx
5214
 
5323
 
5215
        mov     eax, ecx
5324
        mov     eax, ecx
5216
        shr     eax, 1
5325
        shr     eax, 1
5217
        and     eax, 1
5326
        and     eax, 1
5218
        inc     eax
5327
        inc     eax
5219
        mov     [ChannelNumber], ax
5328
        mov     [ChannelNumber], ax
5220
        mov     eax, ecx
5329
        mov     eax, ecx
5221
        and     eax, 1
5330
        and     eax, 1
5222
        mov     [DiskNumber], al
5331
        mov     [DiskNumber], al
5223
        call    reserve_cd_channel
5332
        call    reserve_cd_channel
5224
        ret
5333
        ret
5225
;--------------------------------------
5334
;--------------------------------------
5226
.free:
5335
.free:
5227
        call    free_cd_channel
5336
        call    free_cd_channel
5228
        and     [cd_status], 0
5337
        and     [cd_status], 0
5229
        ret
5338
        ret
5230
;-----------------------------------------------------------------------------
5339
;-----------------------------------------------------------------------------
5231
align 4
5340
align 4
5232
syscall_getpixel_WinMap:                       ; GetPixel WinMap
5341
syscall_getpixel_WinMap:                       ; GetPixel WinMap
5233
        cmp     ebx, [_display.width]
5342
        cmp     ebx, [_display.width]
5234
        jb      @f
5343
        jb      @f
5235
        cmp     ecx, [_display.height]
5344
        cmp     ecx, [_display.height]
5236
        jb      @f
5345
        jb      @f
5237
        xor     eax, eax
5346
        xor     eax, eax
5238
        jmp     .store
5347
        jmp     .store
5239
;--------------------------------------
5348
;--------------------------------------
5240
align 4
5349
align 4
5241
@@:
5350
@@:
5242
        mov     eax, [d_width_calc_area + ecx*4]
5351
        mov     eax, [d_width_calc_area + ecx*4]
5243
        add     eax, [_display.win_map]
5352
        add     eax, [_display.win_map]
5244
        movzx   eax, byte[eax+ebx]        ; get value for current point
5353
        movzx   eax, byte[eax+ebx]        ; get value for current point
5245
;--------------------------------------
5354
;--------------------------------------
5246
align 4
5355
align 4
5247
.store:
5356
.store:
5248
        mov     [esp + 32], eax
5357
        mov     [esp + 32], eax
5249
        ret
5358
        ret
5250
;-----------------------------------------------------------------------------
5359
;-----------------------------------------------------------------------------
5251
align 4
5360
align 4
5252
syscall_getpixel:                       ; GetPixel
5361
syscall_getpixel:                       ; GetPixel
5253
        mov     ecx, [_display.width]
5362
        mov     ecx, [_display.width]
5254
        xor     edx, edx
5363
        xor     edx, edx
5255
        mov     eax, ebx
5364
        mov     eax, ebx
5256
        div     ecx
5365
        div     ecx
5257
        mov     ebx, edx
5366
        mov     ebx, edx
5258
        xchg    eax, ebx
5367
        xchg    eax, ebx
5259
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5368
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5260
        call    dword [GETPIXEL]; eax - x, ebx - y
5369
        call    dword [GETPIXEL]; eax - x, ebx - y
5261
        mov     [esp + 32], ecx
5370
        mov     [esp + 32], ecx
5262
        ret
5371
        ret
5263
;-----------------------------------------------------------------------------
5372
;-----------------------------------------------------------------------------
5264
align 4
5373
align 4
5265
syscall_getarea:
5374
syscall_getarea:
5266
;eax = 36
5375
;eax = 36
5267
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5376
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5268
;ecx = [size x]*65536 + [size y]
5377
;ecx = [size x]*65536 + [size y]
5269
;edx = [start x]*65536 + [start y]
5378
;edx = [start x]*65536 + [start y]
5270
        pushad
5379
        pushad
5271
        mov     edi, ebx
5380
        mov     edi, ebx
5272
        mov     eax, edx
5381
        mov     eax, edx
5273
        shr     eax, 16
5382
        shr     eax, 16
5274
        mov     ebx, edx
5383
        mov     ebx, edx
5275
        and     ebx, 0xffff
5384
        and     ebx, 0xffff
5276
        dec     eax
5385
        dec     eax
5277
        dec     ebx
5386
        dec     ebx
5278
     ; eax - x, ebx - y
5387
     ; eax - x, ebx - y
5279
        mov     edx, ecx
5388
        mov     edx, ecx
5280
 
5389
 
5281
        shr     ecx, 16
5390
        shr     ecx, 16
5282
        and     edx, 0xffff
5391
        and     edx, 0xffff
5283
        mov     esi, ecx
5392
        mov     esi, ecx
5284
     ; ecx - size x, edx - size y
5393
     ; ecx - size x, edx - size y
5285
 
5394
 
5286
        mov     ebp, edx
5395
        mov     ebp, edx
5287
        dec     ebp
5396
        dec     ebp
5288
        lea     ebp, [ebp*3]
5397
        lea     ebp, [ebp*3]
5289
 
5398
 
5290
        imul    ebp, esi
5399
        imul    ebp, esi
5291
 
5400
 
5292
        mov     esi, ecx
5401
        mov     esi, ecx
5293
        dec     esi
5402
        dec     esi
5294
        lea     esi, [esi*3]
5403
        lea     esi, [esi*3]
5295
 
5404
 
5296
        add     ebp, esi
5405
        add     ebp, esi
5297
        add     ebp, edi
5406
        add     ebp, edi
5298
 
5407
 
5299
        add     ebx, edx
5408
        add     ebx, edx
5300
;--------------------------------------
5409
;--------------------------------------
5301
align 4
5410
align 4
5302
.start_y:
5411
.start_y:
5303
        push    ecx edx
5412
        push    ecx edx
5304
;--------------------------------------
5413
;--------------------------------------
5305
align 4
5414
align 4
5306
.start_x:
5415
.start_x:
5307
        push    eax ebx ecx
5416
        push    eax ebx ecx
5308
        add     eax, ecx
5417
        add     eax, ecx
5309
 
5418
 
5310
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5419
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5311
        call    dword [GETPIXEL]; eax - x, ebx - y
5420
        call    dword [GETPIXEL]; eax - x, ebx - y
5312
 
5421
 
5313
        mov     [ebp], cx
5422
        mov     [ebp], cx
5314
        shr     ecx, 16
5423
        shr     ecx, 16
5315
        mov     [ebp+2], cl
5424
        mov     [ebp+2], cl
5316
 
5425
 
5317
        pop     ecx ebx eax
5426
        pop     ecx ebx eax
5318
        sub     ebp, 3
5427
        sub     ebp, 3
5319
        dec     ecx
5428
        dec     ecx
5320
        jnz     .start_x
5429
        jnz     .start_x
5321
        pop     edx ecx
5430
        pop     edx ecx
5322
        dec     ebx
5431
        dec     ebx
5323
        dec     edx
5432
        dec     edx
5324
        jnz     .start_y
5433
        jnz     .start_y
5325
        popad
5434
        popad
5326
        ret
5435
        ret
5327
;-----------------------------------------------------------------------------
5436
;-----------------------------------------------------------------------------
5328
align 4
5437
align 4
5329
syscall_putarea_backgr:
5438
syscall_putarea_backgr:
5330
;eax = 25
5439
;eax = 25
5331
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5440
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5332
;ecx = [size x]*65536 + [size y]
5441
;ecx = [size x]*65536 + [size y]
5333
;edx = [start x]*65536 + [start y]
5442
;edx = [start x]*65536 + [start y]
5334
        pushad
5443
        pushad
5335
        mov     edi, ebx
5444
        mov     edi, ebx
5336
        mov     eax, edx
5445
        mov     eax, edx
5337
        shr     eax, 16
5446
        shr     eax, 16
5338
        mov     ebx, edx
5447
        mov     ebx, edx
5339
        and     ebx, 0xffff
5448
        and     ebx, 0xffff
5340
        dec     eax
5449
        dec     eax
5341
        dec     ebx
5450
        dec     ebx
5342
; eax - x, ebx - y
5451
; eax - x, ebx - y
5343
        mov     edx, ecx
5452
        mov     edx, ecx
5344
        shr     ecx, 16
5453
        shr     ecx, 16
5345
        and     edx, 0xffff
5454
        and     edx, 0xffff
5346
        mov     esi, ecx
5455
        mov     esi, ecx
5347
; ecx - size x, edx - size y
5456
; ecx - size x, edx - size y
5348
        mov     ebp, edx
5457
        mov     ebp, edx
5349
        dec     ebp
5458
        dec     ebp
5350
        shl     ebp, 2
5459
        shl     ebp, 2
5351
 
5460
 
5352
        imul    ebp, esi
5461
        imul    ebp, esi
5353
 
5462
 
5354
        mov     esi, ecx
5463
        mov     esi, ecx
5355
        dec     esi
5464
        dec     esi
5356
        shl     esi, 2
5465
        shl     esi, 2
5357
 
5466
 
5358
        add     ebp, esi
5467
        add     ebp, esi
5359
        add     ebp, edi
5468
        add     ebp, edi
5360
 
5469
 
5361
        add     ebx, edx
5470
        add     ebx, edx
5362
;--------------------------------------
5471
;--------------------------------------
5363
align 4
5472
align 4
5364
.start_y:
5473
.start_y:
5365
        push    ecx edx
5474
        push    ecx edx
5366
;--------------------------------------
5475
;--------------------------------------
5367
align 4
5476
align 4
5368
.start_x:
5477
.start_x:
5369
        push    eax ecx
5478
        push    eax ecx
5370
        add     eax, ecx
5479
        add     eax, ecx
5371
 
5480
 
5372
        mov     ecx, [ebp]
5481
        mov     ecx, [ebp]
5373
        rol     ecx, 8
5482
        rol     ecx, 8
5374
        test    cl, cl        ; transparensy = 0
5483
        test    cl, cl        ; transparensy = 0
5375
        jz      .no_put
5484
        jz      .no_put
5376
 
5485
 
5377
        xor     cl, cl
5486
        xor     cl, cl
5378
        ror     ecx, 8
5487
        ror     ecx, 8
5379
 
5488
 
5380
        pushad
5489
        pushad
5381
        mov     edx, [d_width_calc_area + ebx*4]
5490
        mov     edx, [d_width_calc_area + ebx*4]
5382
        add     edx, [_display.win_map]
5491
        add     edx, [_display.win_map]
5383
        movzx   edx, byte [eax+edx]
5492
        movzx   edx, byte [eax+edx]
5384
        cmp     dl, byte 1
5493
        cmp     dl, byte 1
5385
        jne     @f
5494
        jne     @f
5386
 
5495
 
5387
        call    dword [PUTPIXEL]; eax - x, ebx - y
5496
        call    dword [PUTPIXEL]; eax - x, ebx - y
5388
;--------------------------------------
5497
;--------------------------------------
5389
align 4
5498
align 4
5390
@@:
5499
@@:
5391
        popad
5500
        popad
5392
;--------------------------------------
5501
;--------------------------------------
5393
align 4
5502
align 4
5394
.no_put:
5503
.no_put:
5395
        pop     ecx eax
5504
        pop     ecx eax
5396
 
5505
 
5397
        sub     ebp, 4
5506
        sub     ebp, 4
5398
        dec     ecx
5507
        dec     ecx
5399
        jnz     .start_x
5508
        jnz     .start_x
5400
 
5509
 
5401
        pop     edx ecx
5510
        pop     edx ecx
5402
        dec     ebx
5511
        dec     ebx
5403
        dec     edx
5512
        dec     edx
5404
        jnz     .start_y
5513
        jnz     .start_y
5405
 
5514
 
5406
        popad
5515
        popad
5407
        ret
5516
        ret
5408
;-----------------------------------------------------------------------------
5517
;-----------------------------------------------------------------------------
5409
align 4
5518
align 4
5410
syscall_drawline:                       ; DrawLine
5519
syscall_drawline:                       ; DrawLine
5411
 
5520
 
5412
        mov     edi, [TASK_BASE]
5521
        mov     edi, [TASK_BASE]
5413
        movzx   eax, word[edi-twdw+WDATA.box.left]
5522
        movzx   eax, word[edi-twdw+WDATA.box.left]
5414
        mov     ebp, eax
5523
        mov     ebp, eax
5415
        mov     esi, [current_slot]
5524
        mov     esi, [current_slot]
5416
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5525
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5417
        add     ax, word[esi+APPDATA.wnd_clientbox.left]
5526
        add     ax, word[esi+APPDATA.wnd_clientbox.left]
5418
        add     ebp, ebx
5527
        add     ebp, ebx
5419
        shl     eax, 16
5528
        shl     eax, 16
5420
        movzx   ebx, word[edi-twdw+WDATA.box.top]
5529
        movzx   ebx, word[edi-twdw+WDATA.box.top]
5421
        add     eax, ebp
5530
        add     eax, ebp
5422
        mov     ebp, ebx
5531
        mov     ebp, ebx
5423
        add     ebp, [esi+APPDATA.wnd_clientbox.top]
5532
        add     ebp, [esi+APPDATA.wnd_clientbox.top]
5424
        add     bx, word[esi+APPDATA.wnd_clientbox.top]
5533
        add     bx, word[esi+APPDATA.wnd_clientbox.top]
5425
        add     ebp, ecx
5534
        add     ebp, ecx
5426
        shl     ebx, 16
5535
        shl     ebx, 16
5427
        xor     edi, edi
5536
        xor     edi, edi
5428
        add     ebx, ebp
5537
        add     ebx, ebp
5429
        mov     ecx, edx
5538
        mov     ecx, edx
5430
;        jmp     [draw_line]
5539
;        jmp     [draw_line]
5431
        jmp     __sys_draw_line
5540
        jmp     __sys_draw_line
5432
 
5541
 
5433
 
5542
 
5434
align 4
5543
align 4
5435
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
5544
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
5436
 
5545
 
5437
        call    r_f_port_area
5546
        call    r_f_port_area
5438
        mov     [esp+32], eax
5547
        mov     [esp+32], eax
5439
        ret
5548
        ret
5440
 
5549
 
5441
align 4
5550
align 4
5442
syscall_threads:                        ; CreateThreads
5551
syscall_threads:                        ; CreateThreads
5443
;
5552
;
5444
;   ecx=thread entry point
5553
;   ecx=thread entry point
5445
;   edx=thread stack pointer
5554
;   edx=thread stack pointer
5446
;
5555
;
5447
; on return : eax = pid
5556
; on return : eax = pid
5448
 
5557
 
5449
        xor     ebx, ebx
5558
        xor     ebx, ebx
5450
        call    new_sys_threads
5559
        call    new_sys_threads
5451
 
5560
 
5452
        mov     [esp+32], eax
5561
        mov     [esp+32], eax
5453
        ret
5562
        ret
5454
 
5563
 
5455
align 4
5564
align 4
5456
 
5565
 
5457
paleholder:
5566
paleholder:
5458
        ret
5567
        ret
5459
;------------------------------------------------------------------------------
5568
;------------------------------------------------------------------------------
5460
align 4
5569
align 4
5461
calculate_fast_getting_offset_for_WinMapAddress:
5570
calculate_fast_getting_offset_for_WinMapAddress:
5462
; calculate data area for fast getting offset to _WinMapAddress
5571
; calculate data area for fast getting offset to _WinMapAddress
5463
        xor     eax, eax
5572
        xor     eax, eax
5464
        mov     ecx, [_display.height]
5573
        mov     ecx, [_display.height]
5465
        mov     edi, d_width_calc_area
5574
        mov     edi, d_width_calc_area
5466
        cld
5575
        cld
5467
@@:
5576
@@:
5468
        stosd
5577
        stosd
5469
        add     eax, [_display.width]
5578
        add     eax, [_display.width]
5470
        dec     ecx
5579
        dec     ecx
5471
        jnz     @r
5580
        jnz     @r
5472
        ret
5581
        ret
5473
;------------------------------------------------------------------------------
5582
;------------------------------------------------------------------------------
5474
align 4
5583
align 4
5475
calculate_fast_getting_offset_for_LFB:
5584
calculate_fast_getting_offset_for_LFB:
5476
; calculate data area for fast getting offset to LFB
5585
; calculate data area for fast getting offset to LFB
5477
        xor     eax, eax
5586
        xor     eax, eax
5478
        mov     ecx, [_display.height]
5587
        mov     ecx, [_display.height]
5479
        mov     edi, BPSLine_calc_area
5588
        mov     edi, BPSLine_calc_area
5480
        cld
5589
        cld
5481
@@:
5590
@@:
5482
        stosd
5591
        stosd
5483
        add     eax, [_display.lfb_pitch]
5592
        add     eax, [_display.lfb_pitch]
5484
        dec     ecx
5593
        dec     ecx
5485
        jnz     @r
5594
        jnz     @r
5486
        ret
5595
        ret
5487
;------------------------------------------------------------------------------
5596
;------------------------------------------------------------------------------
5488
align 4
5597
align 4
5489
set_screen:
5598
set_screen:
5490
; in:
5599
; in:
5491
; eax - new Screen_Max_X
5600
; eax - new Screen_Max_X
5492
; ecx - new BytesPerScanLine
5601
; ecx - new BytesPerScanLine
5493
; edx - new Screen_Max_Y
5602
; edx - new Screen_Max_Y
5494
 
5603
 
5495
        pushfd
5604
        pushfd
5496
        cli
5605
        cli
5497
 
5606
 
5498
        mov     [_display.lfb_pitch], ecx
5607
        mov     [_display.lfb_pitch], ecx
5499
 
5608
 
5500
        mov     [screen_workarea.right], eax
5609
        mov     [screen_workarea.right], eax
5501
        mov     [screen_workarea.bottom], edx
5610
        mov     [screen_workarea.bottom], edx
5502
 
5611
 
5503
        push    ebx
5612
        push    ebx
5504
        push    esi
5613
        push    esi
5505
        push    edi
5614
        push    edi
5506
 
5615
 
5507
        pushad
5616
        pushad
5508
 
5617
 
5509
        cmp     [do_not_touch_winmap], 1
5618
        cmp     [do_not_touch_winmap], 1
5510
        je      @f
5619
        je      @f
5511
 
5620
 
5512
        stdcall kernel_free, [_display.win_map]
5621
        stdcall kernel_free, [_display.win_map]
5513
 
5622
 
5514
        mov     eax, [_display.width]
5623
        mov     eax, [_display.width]
5515
        mul     [_display.height]
5624
        mul     [_display.height]
5516
        mov     [_display.win_map_size], eax
5625
        mov     [_display.win_map_size], eax
5517
 
5626
 
5518
        stdcall kernel_alloc, eax
5627
        stdcall kernel_alloc, eax
5519
        mov     [_display.win_map], eax
5628
        mov     [_display.win_map], eax
5520
        test    eax, eax
5629
        test    eax, eax
5521
        jz      .epic_fail
5630
        jz      .epic_fail
5522
; store for f.18.24
5631
; store for f.18.24
5523
        mov     eax, [_display.width]
5632
        mov     eax, [_display.width]
5524
        mov     [display_width_standard], eax
5633
        mov     [display_width_standard], eax
5525
 
5634
 
5526
        mov     eax, [_display.height]
5635
        mov     eax, [_display.height]
5527
        mov     [display_height_standard], eax
5636
        mov     [display_height_standard], eax
5528
@@:
5637
@@:
5529
        call    calculate_fast_getting_offset_for_WinMapAddress
5638
        call    calculate_fast_getting_offset_for_WinMapAddress
5530
; for Qemu or non standart video cards
5639
; for Qemu or non standart video cards
5531
; Unfortunately [BytesPerScanLine] does not always
5640
; Unfortunately [BytesPerScanLine] does not always
5532
;                             equal to [_display.width] * [ScreenBPP] / 8
5641
;                             equal to [_display.width] * [ScreenBPP] / 8
5533
        call    calculate_fast_getting_offset_for_LFB
5642
        call    calculate_fast_getting_offset_for_LFB
5534
        popad
5643
        popad
5535
 
5644
 
5536
        call    repos_windows
5645
        call    repos_windows
5537
        xor     eax, eax
5646
        xor     eax, eax
5538
        xor     ebx, ebx
5647
        xor     ebx, ebx
5539
        mov     ecx, [_display.width]
5648
        mov     ecx, [_display.width]
5540
        mov     edx, [_display.height]
5649
        mov     edx, [_display.height]
5541
        dec     ecx
5650
        dec     ecx
5542
        dec     edx
5651
        dec     edx
5543
        call    calculatescreen
5652
        call    calculatescreen
5544
        pop     edi
5653
        pop     edi
5545
        pop     esi
5654
        pop     esi
5546
        pop     ebx
5655
        pop     ebx
5547
 
5656
 
5548
        popfd
5657
        popfd
5549
        ret
5658
        ret
5550
 
5659
 
5551
.epic_fail:
5660
.epic_fail:
5552
        hlt                     ; Houston, we've had a problem
5661
        hlt                     ; Houston, we've had a problem
5553
 
5662
 
5554
; --------------- APM ---------------------
5663
; --------------- APM ---------------------
5555
uglobal
5664
uglobal
5556
apm_entry       dp      0
5665
apm_entry       dp      0
5557
apm_vf          dd      0
5666
apm_vf          dd      0
5558
endg
5667
endg
5559
 
5668
 
5560
align 4
5669
align 4
5561
sys_apm:
5670
sys_apm:
5562
        xor     eax, eax
5671
        xor     eax, eax
5563
        cmp     word [apm_vf], ax       ; Check APM BIOS enable
5672
        cmp     word [apm_vf], ax       ; Check APM BIOS enable
5564
        jne     @f
5673
        jne     @f
5565
        inc     eax
5674
        inc     eax
5566
        or      dword [esp + 44], eax   ; error
5675
        or      dword [esp + 44], eax   ; error
5567
        add     eax, 7
5676
        add     eax, 7
5568
        mov     dword [esp + 32], eax   ; 32-bit protected-mode interface not supported
5677
        mov     dword [esp + 32], eax   ; 32-bit protected-mode interface not supported
5569
        ret
5678
        ret
5570
 
5679
 
5571
@@:
5680
@@:
5572
;       xchg    eax, ecx
5681
;       xchg    eax, ecx
5573
;       xchg    ebx, ecx
5682
;       xchg    ebx, ecx
5574
 
5683
 
5575
        cmp     dx, 3
5684
        cmp     dx, 3
5576
        ja      @f
5685
        ja      @f
5577
        and     [esp + 44], byte 0xfe    ; emulate func 0..3 as func 0
5686
        and     [esp + 44], byte 0xfe    ; emulate func 0..3 as func 0
5578
        mov     eax, [apm_vf]
5687
        mov     eax, [apm_vf]
5579
        mov     [esp + 32], eax
5688
        mov     [esp + 32], eax
5580
        shr     eax, 16
5689
        shr     eax, 16
5581
        mov     [esp + 28], eax
5690
        mov     [esp + 28], eax
5582
        ret
5691
        ret
5583
 
5692
 
5584
@@:
5693
@@:
5585
 
5694
 
5586
        mov     esi, [master_tab+(OS_BASE shr 20)]
5695
        mov     esi, [master_tab+(OS_BASE shr 20)]
5587
        xchg    [master_tab], esi
5696
        xchg    [master_tab], esi
5588
        push    esi
5697
        push    esi
5589
        mov     edi, cr3
5698
        mov     edi, cr3
5590
        mov     cr3, edi                ;flush TLB
5699
        mov     cr3, edi                ;flush TLB
5591
 
5700
 
5592
        call    pword [apm_entry]       ;call APM BIOS
5701
        call    pword [apm_entry]       ;call APM BIOS
5593
 
5702
 
5594
        xchg    eax, [esp]
5703
        xchg    eax, [esp]
5595
        mov     [master_tab], eax
5704
        mov     [master_tab], eax
5596
        mov     eax, cr3
5705
        mov     eax, cr3
5597
        mov     cr3, eax
5706
        mov     cr3, eax
5598
        pop     eax
5707
        pop     eax
5599
 
5708
 
5600
        mov     [esp + 4 ], edi
5709
        mov     [esp + 4 ], edi
5601
        mov     [esp + 8], esi
5710
        mov     [esp + 8], esi
5602
        mov     [esp + 20], ebx
5711
        mov     [esp + 20], ebx
5603
        mov     [esp + 24], edx
5712
        mov     [esp + 24], edx
5604
        mov     [esp + 28], ecx
5713
        mov     [esp + 28], ecx
5605
        mov     [esp + 32], eax
5714
        mov     [esp + 32], eax
5606
        setc    al
5715
        setc    al
5607
        and     [esp + 44], byte 0xfe
5716
        and     [esp + 44], byte 0xfe
5608
        or      [esp + 44], al
5717
        or      [esp + 44], al
5609
        ret
5718
        ret
5610
; -----------------------------------------
5719
; -----------------------------------------
5611
 
5720
 
5612
align 4
5721
align 4
5613
 
5722
 
5614
undefined_syscall:                      ; Undefined system call
5723
undefined_syscall:                      ; Undefined system call
5615
        mov     [esp + 32], dword -1
5724
        mov     [esp + 32], dword -1
5616
        ret
5725
        ret
5617
 
5726
 
5618
align 4
5727
align 4
5619
system_shutdown:          ; shut down the system
5728
system_shutdown:          ; shut down the system
5620
 
5729
 
5621
        cmp     byte [BOOT_VARS+0x9030], 1
5730
        cmp     byte [BOOT_VARS+0x9030], 1
5622
        jne     @F
5731
        jne     @F
5623
        ret
5732
        ret
5624
@@:
5733
@@:
5625
        call    stop_all_services
5734
        call    stop_all_services
5626
 
5735
 
5627
yes_shutdown_param:
5736
yes_shutdown_param:
5628
; Shutdown other CPUs, if initialized
5737
; Shutdown other CPUs, if initialized
5629
        cmp     [ap_initialized], 0
5738
        cmp     [ap_initialized], 0
5630
        jz      .no_shutdown_cpus
5739
        jz      .no_shutdown_cpus
5631
        mov     edi, [LAPIC_BASE]
5740
        mov     edi, [LAPIC_BASE]
5632
        add     edi, 300h
5741
        add     edi, 300h
5633
        mov     esi, smpt+4
5742
        mov     esi, smpt+4
5634
        mov     ebx, [cpu_count]
5743
        mov     ebx, [cpu_count]
5635
        dec     ebx
5744
        dec     ebx
5636
.shutdown_cpus_loop:
5745
.shutdown_cpus_loop:
5637
        lodsd
5746
        lodsd
5638
        push    esi
5747
        push    esi
5639
        xor     esi, esi
5748
        xor     esi, esi
5640
        inc     esi
5749
        inc     esi
5641
        shl     eax, 24
5750
        shl     eax, 24
5642
        mov     [edi+10h], eax
5751
        mov     [edi+10h], eax
5643
; assert INIT IPI
5752
; assert INIT IPI
5644
        mov     dword [edi], 0C500h
5753
        mov     dword [edi], 0C500h
5645
        call    delay_ms
5754
        call    delay_ms
5646
@@:
5755
@@:
5647
        test    dword [edi], 1000h
5756
        test    dword [edi], 1000h
5648
        jnz     @b
5757
        jnz     @b
5649
; deassert INIT IPI
5758
; deassert INIT IPI
5650
        mov     dword [edi], 8500h
5759
        mov     dword [edi], 8500h
5651
        call    delay_ms
5760
        call    delay_ms
5652
@@:
5761
@@:
5653
        test    dword [edi], 1000h
5762
        test    dword [edi], 1000h
5654
        jnz     @b
5763
        jnz     @b
5655
; don't send STARTUP IPI: let other CPUs be in wait-for-startup state
5764
; don't send STARTUP IPI: let other CPUs be in wait-for-startup state
5656
        pop     esi
5765
        pop     esi
5657
        dec     ebx
5766
        dec     ebx
5658
        jnz     .shutdown_cpus_loop
5767
        jnz     .shutdown_cpus_loop
5659
.no_shutdown_cpus:
5768
.no_shutdown_cpus:
5660
 
5769
 
5661
        cli
5770
        cli
5662
 
5771
 
5663
if ~ defined extended_primary_loader
5772
if ~ defined extended_primary_loader
5664
; load kernel.mnt to 0x7000:0
5773
; load kernel.mnt to 0x7000:0
5665
        mov     ebx, kernel_file_load
5774
        mov     ebx, kernel_file_load
5666
        pushad
5775
        pushad
5667
        call    file_system_lfn
5776
        call    file_system_lfn
5668
        popad
5777
        popad
5669
 
5778
 
5670
        mov     esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5779
        mov     esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5671
        mov     edi, OS_BASE+0x40000
5780
        mov     edi, OS_BASE+0x40000
5672
        mov     ecx, 1000
5781
        mov     ecx, 1000
5673
        rep movsb
5782
        rep movsb
5674
end if
5783
end if
5675
 
5784
 
5676
;        mov     esi, BOOT_VAR    ; restore 0x0 - 0xffff
5785
;        mov     esi, BOOT_VAR    ; restore 0x0 - 0xffff
5677
;        mov     edi, OS_BASE
5786
;        mov     edi, OS_BASE
5678
;        mov     ecx, 0x10000/4
5787
;        mov     ecx, 0x10000/4
5679
;        cld
5788
;        cld
5680
;        rep movsd
5789
;        rep movsd
5681
 
5790
 
5682
        call    IRQ_mask_all
5791
        call    IRQ_mask_all
5683
 
5792
 
5684
        cmp     byte [OS_BASE + 0x9030], 2
5793
        cmp     byte [OS_BASE + 0x9030], 2
5685
        jnz     no_acpi_power_off
5794
        jnz     no_acpi_power_off
5686
 
5795
 
5687
; scan for RSDP
5796
; scan for RSDP
5688
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
5797
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
5689
        movzx   eax, word [OS_BASE + 0x40E]
5798
        movzx   eax, word [OS_BASE + 0x40E]
5690
        shl     eax, 4
5799
        shl     eax, 4
5691
        jz      @f
5800
        jz      @f
5692
        mov     ecx, 1024/16
5801
        mov     ecx, 1024/16
5693
        call    scan_rsdp
5802
        call    scan_rsdp
5694
        jnc     .rsdp_found
5803
        jnc     .rsdp_found
5695
@@:
5804
@@:
5696
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
5805
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
5697
        mov     eax, 0xE0000
5806
        mov     eax, 0xE0000
5698
        mov     ecx, 0x2000
5807
        mov     ecx, 0x2000
5699
        call    scan_rsdp
5808
        call    scan_rsdp
5700
        jc      no_acpi_power_off
5809
        jc      no_acpi_power_off
5701
.rsdp_found:
5810
.rsdp_found:
5702
        mov     esi, [eax+16]   ; esi contains physical address of the RSDT
5811
        mov     esi, [eax+16]   ; esi contains physical address of the RSDT
5703
        mov     ebp, [ipc_tmp]
5812
        mov     ebp, [ipc_tmp]
5704
        stdcall map_page, ebp, esi, PG_READ
5813
        stdcall map_page, ebp, esi, PG_READ
5705
        lea     eax, [esi+1000h]
5814
        lea     eax, [esi+1000h]
5706
        lea     edx, [ebp+1000h]
5815
        lea     edx, [ebp+1000h]
5707
        stdcall map_page, edx, eax, PG_READ
5816
        stdcall map_page, edx, eax, PG_READ
5708
        and     esi, 0xFFF
5817
        and     esi, 0xFFF
5709
        add     esi, ebp
5818
        add     esi, ebp
5710
        cmp     dword [esi], 'RSDT'
5819
        cmp     dword [esi], 'RSDT'
5711
        jnz     no_acpi_power_off
5820
        jnz     no_acpi_power_off
5712
        mov     ecx, [esi+4]
5821
        mov     ecx, [esi+4]
5713
        sub     ecx, 24h
5822
        sub     ecx, 24h
5714
        jbe     no_acpi_power_off
5823
        jbe     no_acpi_power_off
5715
        shr     ecx, 2
5824
        shr     ecx, 2
5716
        add     esi, 24h
5825
        add     esi, 24h
5717
.scan_fadt:
5826
.scan_fadt:
5718
        lodsd
5827
        lodsd
5719
        mov     ebx, eax
5828
        mov     ebx, eax
5720
        lea     eax, [ebp+2000h]
5829
        lea     eax, [ebp+2000h]
5721
        stdcall map_page, eax, ebx, PG_READ
5830
        stdcall map_page, eax, ebx, PG_READ
5722
        lea     eax, [ebp+3000h]
5831
        lea     eax, [ebp+3000h]
5723
        add     ebx, 0x1000
5832
        add     ebx, 0x1000
5724
        stdcall map_page, eax, ebx, PG_READ
5833
        stdcall map_page, eax, ebx, PG_READ
5725
        and     ebx, 0xFFF
5834
        and     ebx, 0xFFF
5726
        lea     ebx, [ebx+ebp+2000h]
5835
        lea     ebx, [ebx+ebp+2000h]
5727
        cmp     dword [ebx], 'FACP'
5836
        cmp     dword [ebx], 'FACP'
5728
        jz      .fadt_found
5837
        jz      .fadt_found
5729
        loop    .scan_fadt
5838
        loop    .scan_fadt
5730
        jmp     no_acpi_power_off
5839
        jmp     no_acpi_power_off
5731
.fadt_found:
5840
.fadt_found:
5732
; ebx is linear address of FADT
5841
; ebx is linear address of FADT
5733
        mov     edi, [ebx+40] ; physical address of the DSDT
5842
        mov     edi, [ebx+40] ; physical address of the DSDT
5734
        lea     eax, [ebp+4000h]
5843
        lea     eax, [ebp+4000h]
5735
        stdcall map_page, eax, edi, PG_READ
5844
        stdcall map_page, eax, edi, PG_READ
5736
        lea     eax, [ebp+5000h]
5845
        lea     eax, [ebp+5000h]
5737
        lea     esi, [edi+0x1000]
5846
        lea     esi, [edi+0x1000]
5738
        stdcall map_page, eax, esi, PG_READ
5847
        stdcall map_page, eax, esi, PG_READ
5739
        and     esi, 0xFFF
5848
        and     esi, 0xFFF
5740
        sub     edi, esi
5849
        sub     edi, esi
5741
        cmp     dword [esi+ebp+4000h], 'DSDT'
5850
        cmp     dword [esi+ebp+4000h], 'DSDT'
5742
        jnz     no_acpi_power_off
5851
        jnz     no_acpi_power_off
5743
        mov     eax, [esi+ebp+4004h] ; DSDT length
5852
        mov     eax, [esi+ebp+4004h] ; DSDT length
5744
        sub     eax, 36+4
5853
        sub     eax, 36+4
5745
        jbe     no_acpi_power_off
5854
        jbe     no_acpi_power_off
5746
        add     esi, 36
5855
        add     esi, 36
5747
.scan_dsdt:
5856
.scan_dsdt:
5748
        cmp     dword [esi+ebp+4000h], '_S5_'
5857
        cmp     dword [esi+ebp+4000h], '_S5_'
5749
        jnz     .scan_dsdt_cont
5858
        jnz     .scan_dsdt_cont
5750
        cmp     byte [esi+ebp+4000h+4], 12h ; DefPackage opcode
5859
        cmp     byte [esi+ebp+4000h+4], 12h ; DefPackage opcode
5751
        jnz     .scan_dsdt_cont
5860
        jnz     .scan_dsdt_cont
5752
        mov     dl, [esi+ebp+4000h+6]
5861
        mov     dl, [esi+ebp+4000h+6]
5753
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
5862
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
5754
                      ; ...in theory; in practice, VirtualBox has 2 bytes
5863
                      ; ...in theory; in practice, VirtualBox has 2 bytes
5755
        ja      .scan_dsdt_cont
5864
        ja      .scan_dsdt_cont
5756
        cmp     dl, 1
5865
        cmp     dl, 1
5757
        jb      .scan_dsdt_cont
5866
        jb      .scan_dsdt_cont
5758
        lea     esi, [esi+ebp+4000h+7]
5867
        lea     esi, [esi+ebp+4000h+7]
5759
        xor     ecx, ecx
5868
        xor     ecx, ecx
5760
        cmp     byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx
5869
        cmp     byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx
5761
        jz      @f
5870
        jz      @f
5762
        cmp     byte [esi], 0xA
5871
        cmp     byte [esi], 0xA
5763
        jnz     no_acpi_power_off
5872
        jnz     no_acpi_power_off
5764
        inc     esi
5873
        inc     esi
5765
        mov     cl, [esi]
5874
        mov     cl, [esi]
5766
@@:
5875
@@:
5767
        inc     esi
5876
        inc     esi
5768
        cmp     dl, 2
5877
        cmp     dl, 2
5769
        jb      @f
5878
        jb      @f
5770
        cmp     byte [esi], 0
5879
        cmp     byte [esi], 0
5771
        jz      @f
5880
        jz      @f
5772
        cmp     byte [esi], 0xA
5881
        cmp     byte [esi], 0xA
5773
        jnz     no_acpi_power_off
5882
        jnz     no_acpi_power_off
5774
        inc     esi
5883
        inc     esi
5775
        mov     ch, [esi]
5884
        mov     ch, [esi]
5776
@@:
5885
@@:
5777
        jmp     do_acpi_power_off
5886
        jmp     do_acpi_power_off
5778
.scan_dsdt_cont:
5887
.scan_dsdt_cont:
5779
        inc     esi
5888
        inc     esi
5780
        cmp     esi, 0x1000
5889
        cmp     esi, 0x1000
5781
        jb      @f
5890
        jb      @f
5782
        sub     esi, 0x1000
5891
        sub     esi, 0x1000
5783
        add     edi, 0x1000
5892
        add     edi, 0x1000
5784
        push    eax
5893
        push    eax
5785
        lea     eax, [ebp+4000h]
5894
        lea     eax, [ebp+4000h]
5786
        stdcall map_page, eax, edi, PG_READ
5895
        stdcall map_page, eax, edi, PG_READ
5787
        push    PG_READ
5896
        push    PG_READ
5788
        lea     eax, [edi+1000h]
5897
        lea     eax, [edi+1000h]
5789
        push    eax
5898
        push    eax
5790
        lea     eax, [ebp+5000h]
5899
        lea     eax, [ebp+5000h]
5791
        push    eax
5900
        push    eax
5792
        stdcall map_page
5901
        stdcall map_page
5793
        pop     eax
5902
        pop     eax
5794
@@:
5903
@@:
5795
        dec     eax
5904
        dec     eax
5796
        jnz     .scan_dsdt
5905
        jnz     .scan_dsdt
5797
        jmp     no_acpi_power_off
5906
        jmp     no_acpi_power_off
5798
do_acpi_power_off:
5907
do_acpi_power_off:
5799
        mov     edx, [ebx+48]
5908
        mov     edx, [ebx+48]
5800
        test    edx, edx
5909
        test    edx, edx
5801
        jz      .nosmi
5910
        jz      .nosmi
5802
        mov     al, [ebx+52]
5911
        mov     al, [ebx+52]
5803
        out     dx, al
5912
        out     dx, al
5804
        mov     edx, [ebx+64]
5913
        mov     edx, [ebx+64]
5805
@@:
5914
@@:
5806
        in      ax, dx
5915
        in      ax, dx
5807
        test    al, 1
5916
        test    al, 1
5808
        jz      @b
5917
        jz      @b
5809
.nosmi:
5918
.nosmi:
5810
        and     cx, 0x0707
5919
        and     cx, 0x0707
5811
        shl     cx, 2
5920
        shl     cx, 2
5812
        or      cx, 0x2020
5921
        or      cx, 0x2020
5813
        mov     edx, [ebx+64]
5922
        mov     edx, [ebx+64]
5814
        in      ax, dx
5923
        in      ax, dx
5815
        and     ax, 203h
5924
        and     ax, 203h
5816
        or      ah, cl
5925
        or      ah, cl
5817
        out     dx, ax
5926
        out     dx, ax
5818
        mov     edx, [ebx+68]
5927
        mov     edx, [ebx+68]
5819
        test    edx, edx
5928
        test    edx, edx
5820
        jz      @f
5929
        jz      @f
5821
        in      ax, dx
5930
        in      ax, dx
5822
        and     ax, 203h
5931
        and     ax, 203h
5823
        or      ah, ch
5932
        or      ah, ch
5824
        out     dx, ax
5933
        out     dx, ax
5825
@@:
5934
@@:
5826
        jmp     $
5935
        jmp     $
5827
 
5936
 
5828
 
5937
 
5829
scan_rsdp:
5938
scan_rsdp:
5830
        add     eax, OS_BASE
5939
        add     eax, OS_BASE
5831
.s:
5940
.s:
5832
        cmp     dword [eax], 'RSD '
5941
        cmp     dword [eax], 'RSD '
5833
        jnz     .n
5942
        jnz     .n
5834
        cmp     dword [eax+4], 'PTR '
5943
        cmp     dword [eax+4], 'PTR '
5835
        jnz     .n
5944
        jnz     .n
5836
        xor     edx, edx
5945
        xor     edx, edx
5837
        xor     esi, esi
5946
        xor     esi, esi
5838
@@:
5947
@@:
5839
        add     dl, [eax+esi]
5948
        add     dl, [eax+esi]
5840
        inc     esi
5949
        inc     esi
5841
        cmp     esi, 20
5950
        cmp     esi, 20
5842
        jnz     @b
5951
        jnz     @b
5843
        test    dl, dl
5952
        test    dl, dl
5844
        jz      .ok
5953
        jz      .ok
5845
.n:
5954
.n:
5846
        add     eax, 10h
5955
        add     eax, 10h
5847
        loop    .s
5956
        loop    .s
5848
        stc
5957
        stc
5849
.ok:
5958
.ok:
5850
        ret
5959
        ret
5851
 
5960
 
5852
no_acpi_power_off:
5961
no_acpi_power_off:
5853
        call    create_trampoline_pgmap
5962
        call    create_trampoline_pgmap
5854
        mov     cr3, eax
5963
        mov     cr3, eax
5855
        jmp     become_real+0x10000
5964
        jmp     become_real+0x10000
5856
iglobal
5965
iglobal
5857
align 4
5966
align 4
5858
realmode_gdt:
5967
realmode_gdt:
5859
; selector 0 - not used
5968
; selector 0 - not used
5860
        dw      23
5969
        dw      23
5861
        dd      realmode_gdt-OS_BASE
5970
        dd      realmode_gdt-OS_BASE
5862
        dw      0
5971
        dw      0
5863
; selector 8 - code from 1000:0000 to 1000:FFFF
5972
; selector 8 - code from 1000:0000 to 1000:FFFF
5864
        dw      0FFFFh
5973
        dw      0FFFFh
5865
        dw      0
5974
        dw      0
5866
        db      1
5975
        db      1
5867
        db      10011011b
5976
        db      10011011b
5868
        db      00000000b
5977
        db      00000000b
5869
        db      0
5978
        db      0
5870
; selector 10h - data from 1000:0000 to 1000:FFFF
5979
; selector 10h - data from 1000:0000 to 1000:FFFF
5871
        dw      0FFFFh
5980
        dw      0FFFFh
5872
        dw      0
5981
        dw      0
5873
        db      1
5982
        db      1
5874
        db      10010011b
5983
        db      10010011b
5875
        db      00000000b
5984
        db      00000000b
5876
        db      0
5985
        db      0
5877
endg
5986
endg
5878
 
5987
 
5879
if ~ lang eq sp
5988
if ~ lang eq sp
5880
diff16 "end of .text segment",0,$
5989
diff16 "end of .text segment",0,$
5881
end if
5990
end if
5882
 
5991
 
5883
include "data32.inc"
5992
include "data32.inc"
5884
 
5993
 
5885
__REV__ = __REV
5994
__REV__ = __REV
5886
 
5995
 
5887
if ~ lang eq sp
5996
if ~ lang eq sp
5888
diff16 "end of kernel code",0,$
5997
diff16 "end of kernel code",0,$
5889
end if
5998
end if