Subversion Repositories Kolibri OS

Rev

Rev 3296 | Rev 3325 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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