Subversion Repositories Kolibri OS

Rev

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