Subversion Repositories Kolibri OS

Rev

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