Subversion Repositories Kolibri OS

Rev

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