Subversion Repositories Kolibri OS

Rev

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