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