Subversion Repositories Kolibri OS

Rev

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

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