Subversion Repositories Kolibri OS

Rev

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

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