Subversion Repositories Kolibri OS

Rev

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