Subversion Repositories Kolibri OS

Rev

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