Subversion Repositories Kolibri OS

Rev

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