Subversion Repositories Kolibri OS

Rev

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