Subversion Repositories Kolibri OS

Rev

Rev 2259 | Rev 2434 | 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: 2268 $
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
 
2268 Serge 870
;        cmp   byte [BOOT_VAR+0x9030],1
871
;        jne   no_load_vrr_m
237 serge 872
 
2268 Serge 873
;        mov     ebp, vrr_m
874
;        call    fs_execute_from_sysdir
875
;
876
;;        cmp   eax,2                  ; if vrr_m app found (PID=2)
877
;	sub   eax,2
878
;        jz    first_app_found
879
;
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:
2268 Serge 1938
        dd      sysfn_deactivate        ; 1 = deactivate window
1055 Galkov 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
2268 Serge 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
2268 Serge 1971
;------------------------------------------------------------------------------
1055 Galkov 1972
sysfn_shutdown:          ; 18.9 = system shutdown
748 heavyiron 1973
     cmp  ecx,1
1974
     jl   exit_for_anyone
1975
     cmp  ecx,4
1976
     jg   exit_for_anyone
1977
     mov  [BOOT_VAR+0x9030],cl
1978
 
379 serge 1979
     mov  eax,[TASK_COUNT]
709 diamond 1980
     mov  [SYS_SHUTDOWN],al
1 ha 1981
     mov  [shutdown_processes],eax
684 diamond 1982
     and  dword [esp+32], 0
748 heavyiron 1983
 exit_for_anyone:
1 ha 1984
     ret
1985
  uglobal
1986
   shutdown_processes: dd 0x0
1987
  endg
2268 Serge 1988
;------------------------------------------------------------------------------
1055 Galkov 1989
sysfn_terminate:        ; 18.2 = TERMINATE
684 diamond 1990
     cmp  ecx,2
1 ha 1991
     jb   noprocessterminate
379 serge 1992
     mov  edx,[TASK_COUNT]
684 diamond 1993
     cmp  ecx,edx
75 diamond 1994
     ja   noprocessterminate
379 serge 1995
     mov  eax,[TASK_COUNT]
684 diamond 1996
     shl  ecx,5
1997
     mov  edx,[ecx+CURRENT_TASK+TASKDATA.pid]
1998
     add  ecx,CURRENT_TASK+TASKDATA.state
1999
     cmp  byte [ecx], 9
75 diamond 2000
     jz   noprocessterminate
41 mikedld 2001
 
1 ha 2002
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
1055 Galkov 2003
     mov  [ecx],byte 3       ; clear possible i40's
1 ha 2004
     ;call MEM_Heap_UnLock
2005
 
2006
     cmp  edx,[application_table_status]    ; clear app table stat
2007
     jne  noatsc
1329 Lrz 2008
     and  [application_table_status],0
1 ha 2009
   noatsc:
75 diamond 2010
   noprocessterminate:
1 ha 2011
     ret
2268 Serge 2012
;------------------------------------------------------------------------------
85 halyavin 2013
sysfn_terminate2:
2014
;lock application_table_status mutex
164 serge 2015
.table_status:
85 halyavin 2016
    cli
2017
    cmp    [application_table_status],0
1055 Galkov 2018
    je     .stf
85 halyavin 2019
    sti
2020
    call   change_task
2021
    jmp    .table_status
2022
.stf:
2023
    call   set_application_table_status
684 diamond 2024
    mov    eax,ecx
85 halyavin 2025
    call   pid_to_slot
2026
    test   eax,eax
1055 Galkov 2027
    jz     .not_found
684 diamond 2028
    mov    ecx,eax
85 halyavin 2029
    cli
2030
    call   sysfn_terminate
1329 Lrz 2031
    and    [application_table_status],0
85 halyavin 2032
    sti
684 diamond 2033
    and    dword [esp+32],0
85 halyavin 2034
    ret
2035
.not_found:
2036
    mov    [application_table_status],0
1055 Galkov 2037
    or     dword [esp+32],-1
85 halyavin 2038
    ret
2268 Serge 2039
;------------------------------------------------------------------------------
2040
sysfn_deactivate:         ; 18.1 = DEACTIVATE WINDOW
2041
	cmp	ecx,2
2042
	jb	.nowindowdeactivate
2043
	cmp	ecx,[TASK_COUNT]
2044
	ja	.nowindowdeactivate
2045
 
2046
	movzx	esi, word [WIN_STACK + ecx*2]
2047
	cmp	esi, 1
2048
	je	.nowindowdeactivate ; already deactive
85 halyavin 2049
 
2268 Serge 2050
	mov	edi, ecx
2051
	shl	edi, 5
2052
	add	edi, window_data
2053
	movzx	esi, word [WIN_STACK + ecx * 2]
2054
	lea	esi, [WIN_POS + esi * 2]
2055
	call	window._.window_deactivate
2056
 
2057
	xor	eax, eax
2058
	mov	byte[MOUSE_BACKGROUND], al
2059
	mov	byte[DONT_DRAW_MOUSE], al
2060
	mov	byte[MOUSE_DOWN], 0
2061
 
2062
	call	syscall_display_settings._.calculate_whole_screen
2063
	call	syscall_display_settings._.redraw_whole_screen
2064
.nowindowdeactivate:
2065
	ret
2066
 ;------------------------------------------------------------------------------
1055 Galkov 2067
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
684 diamond 2068
     cmp  ecx,2
105 poddubny 2069
     jb   .nowindowactivate
684 diamond 2070
     cmp  ecx,[TASK_COUNT]
105 poddubny 2071
     ja   .nowindowactivate
2072
 
2073
     mov   [window_minimize], 2   ; restore window if minimized
2074
 
684 diamond 2075
     movzx esi, word [WIN_STACK + ecx*2]
379 serge 2076
     cmp   esi, [TASK_COUNT]
105 poddubny 2077
     je    .nowindowactivate ; already active
2078
 
684 diamond 2079
     mov   edi, ecx
105 poddubny 2080
     shl   edi, 5
2081
     add   edi, window_data
684 diamond 2082
     movzx esi, word [WIN_STACK + ecx * 2]
380 serge 2083
     lea   esi, [WIN_POS + esi * 2]
105 poddubny 2084
     call  waredraw
2085
.nowindowactivate:
1 ha 2086
     ret
2268 Serge 2087
;------------------------------------------------------------------------------
1055 Galkov 2088
sysfn_getidletime:              ; 18.4 = GET IDLETIME
1 ha 2089
     mov  eax,[idleusesec]
684 diamond 2090
     mov  [esp+32], eax
1 ha 2091
     ret
2268 Serge 2092
;------------------------------------------------------------------------------
1055 Galkov 2093
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
381 serge 2094
     mov  eax,[CPU_FREQ]
684 diamond 2095
     mov  [esp+32], eax
1 ha 2096
     ret
2268 Serge 2097
;------------------------------------------------------------------------------
1 ha 2098
;  SAVE ramdisk to /hd/1/menuet.img
2099
;!!!!!!!!!!!!!!!!!!!!!!!!
2100
   include 'blkdev/rdsave.inc'
2101
;!!!!!!!!!!!!!!!!!!!!!!!!
2268 Serge 2102
;------------------------------------------------------------------------------
1232 Lrz 2103
align 4
1055 Galkov 2104
sysfn_getactive:        ; 18.7 = get active window
379 serge 2105
     mov  eax, [TASK_COUNT]
380 serge 2106
   movzx  eax, word [WIN_POS + eax*2]
684 diamond 2107
     mov  [esp+32],eax
1 ha 2108
     ret
2268 Serge 2109
;------------------------------------------------------------------------------
1055 Galkov 2110
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
1232 Lrz 2111
;     cmp  ecx,1
2112
     dec  ecx
2113
     jnz  nogetsoundflag
1 ha 2114
     movzx  eax,byte [sound_flag] ; get sound_flag
684 diamond 2115
     mov  [esp+32],eax
1 ha 2116
     ret
2117
 nogetsoundflag:
1232 Lrz 2118
;     cmp  ecx,2
2119
     dec  ecx
1 ha 2120
     jnz  nosoundflag
75 diamond 2121
     xor  byte [sound_flag], 1
2122
 nosoundflag:
41 mikedld 2123
     ret
2268 Serge 2124
;------------------------------------------------------------------------------
1055 Galkov 2125
sysfn_minimize:         ; 18.10 = minimize window
1 ha 2126
     mov   [window_minimize],1
2127
     ret
2268 Serge 2128
;------------------------------------------------------------------------------
1232 Lrz 2129
align 4
1055 Galkov 2130
sysfn_getdiskinfo:      ; 18.11 = get disk info table
1232 Lrz 2131
;     cmp  ecx,1
2132
     dec  ecx
1 ha 2133
     jnz  full_table
2134
  small_table:
2135
     call for_all_tables
75 diamond 2136
     mov ecx,10
1 ha 2137
     cld
2138
     rep movsb
2139
     ret
2140
   for_all_tables:
684 diamond 2141
     mov edi,edx
381 serge 2142
     mov esi,DRIVE_DATA
1 ha 2143
     ret
2144
  full_table:
1232 Lrz 2145
;     cmp  ecx,2
2146
     dec  ecx
1 ha 2147
     jnz  exit_for_anyone
2148
     call for_all_tables
75 diamond 2149
     mov ecx,16384
1 ha 2150
     cld
2151
     rep movsd
2152
     ret
2268 Serge 2153
;------------------------------------------------------------------------------
1055 Galkov 2154
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2155
        and     dword [esp+32], 0
2156
        ret
2268 Serge 2157
;------------------------------------------------------------------------------
1055 Galkov 2158
sysfn_getversion:       ; 18.13 = get kernel ID and version
1447 diamond 2159
     mov edi,ecx
1 ha 2160
     mov esi,version_inf
2161
     mov ecx,version_end-version_inf
2162
     rep movsb
2163
     ret
2268 Serge 2164
;------------------------------------------------------------------------------
75 diamond 2165
sysfn_waitretrace:     ; 18.14 = sys wait retrace
41 mikedld 2166
     ;wait retrace functions
2167
 sys_wait_retrace:
2168
     mov edx,0x3da
2169
 WaitRetrace_loop:
2170
     in al,dx
2171
     test al,1000b
2172
     jz WaitRetrace_loop
684 diamond 2173
     and [esp+32],dword 0
1 ha 2174
     ret
2268 Serge 2175
;------------------------------------------------------------------------------
1232 Lrz 2176
align 4
1055 Galkov 2177
sysfn_centermouse:      ; 18.15 = mouse centered
1232 Lrz 2178
; removed here by 
2179
;     call  mouse_centered
2180
;* mouse centered - start code- Mario79
2181
;mouse_centered:
2182
;        push  eax
2183
        mov   eax,[Screen_Max_X]
2184
        shr   eax,1
2185
        mov   [MOUSE_X],ax
2186
        mov   eax,[Screen_Max_Y]
2187
        shr   eax,1
2188
        mov   [MOUSE_Y],ax
2189
;        ret
2190
;* mouse centered - end code- Mario79
2191
	xor   eax,eax
2192
        and   [esp+32],eax
2193
;        pop   eax
1 ha 2194
     ret
2268 Serge 2195
;------------------------------------------------------------------------------
1232 Lrz 2196
align 4
120 mario79 2197
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
1232 Lrz 2198
     test ecx,ecx  ; get mouse speed factor
120 mario79 2199
     jnz  .set_mouse_acceleration
164 serge 2200
     xor  eax,eax
120 mario79 2201
     mov  ax,[mouse_speed_factor]
684 diamond 2202
     mov  [esp+32],eax
120 mario79 2203
     ret
2204
 .set_mouse_acceleration:
1232 Lrz 2205
;     cmp  ecx,1  ; set mouse speed factor
2206
     dec  ecx
120 mario79 2207
     jnz  .get_mouse_delay
684 diamond 2208
     mov  [mouse_speed_factor],dx
120 mario79 2209
     ret
2210
 .get_mouse_delay:
1232 Lrz 2211
;     cmp  ecx,2  ; get mouse delay
2212
     dec  ecx
120 mario79 2213
     jnz  .set_mouse_delay
2214
     mov  eax,[mouse_delay]
684 diamond 2215
     mov  [esp+32],eax
120 mario79 2216
     ret
2217
 .set_mouse_delay:
1232 Lrz 2218
;     cmp  ecx,3  ; set mouse delay
2219
     dec  ecx
120 mario79 2220
     jnz  .set_pointer_position
684 diamond 2221
     mov  [mouse_delay],edx
120 mario79 2222
     ret
2223
 .set_pointer_position:
1232 Lrz 2224
;     cmp  ecx,4  ; set mouse pointer position
2225
     dec   ecx
621 mario79 2226
     jnz  .set_mouse_button
1549 diamond 2227
     cmp   dx, word[Screen_Max_Y]
2228
     ja    .end
684 diamond 2229
     rol   edx,16
1549 diamond 2230
     cmp   dx, word[Screen_Max_X]
2231
     ja    .end
2232
     mov   [MOUSE_X], edx
621 mario79 2233
     ret
2234
 .set_mouse_button:
1232 Lrz 2235
;     cmp   ecx,5  ; set mouse button features
2236
     dec   ecx
621 mario79 2237
     jnz  .end
684 diamond 2238
     mov   [BTN_DOWN],dl
621 mario79 2239
     mov   [mouse_active],1
120 mario79 2240
 .end:
2241
     ret
2268 Serge 2242
;------------------------------------------------------------------------------
75 diamond 2243
sysfn_getfreemem:
170 serge 2244
     mov eax, [pg_data.pages_free]
2245
     shl eax, 2
684 diamond 2246
     mov [esp+32],eax
1 ha 2247
     ret
75 diamond 2248
 
2249
sysfn_getallmem:
170 serge 2250
     mov  eax,[MEM_AMOUNT]
2251
     shr eax, 10
684 diamond 2252
     mov  [esp+32],eax
32 halyavin 2253
     ret
2254
 
608 alver 2255
; // Alver, 2007-22-08 // {
2256
sysfn_pid_to_slot:
684 diamond 2257
     mov   eax, ecx
608 alver 2258
     call  pid_to_slot
684 diamond 2259
     mov   [esp+32], eax
608 alver 2260
     ret
2261
 
2262
sysfn_min_rest_window:
2263
     pushad
1055 Galkov 2264
     mov   eax, edx      ; ebx - operating
684 diamond 2265
     shr   ecx, 1
608 alver 2266
     jnc    @f
2267
     call  pid_to_slot
2268
@@:
1055 Galkov 2269
     or    eax, eax      ; eax - number of slot
608 alver 2270
     jz    .error
1055 Galkov 2271
     cmp   eax, 255         ; varify maximal slot number
608 alver 2272
     ja    .error
684 diamond 2273
     movzx eax, word [WIN_STACK + eax*2]
2274
     shr   ecx, 1
608 alver 2275
     jc    .restore
2276
 ; .minimize:
2277
     call  minimize_window
2278
     jmp   .exit
2279
.restore:
2280
     call  restore_minimized_window
2281
.exit:
2282
     popad
2283
     xor   eax, eax
684 diamond 2284
     mov   [esp+32], eax
608 alver 2285
     ret
2286
.error:
2287
     popad
2288
     xor   eax, eax
2289
     dec   eax
684 diamond 2290
     mov   [esp+32], eax
608 alver 2291
     ret
2292
; } \\ Alver, 2007-22-08 \\
2293
 
41 mikedld 2294
uglobal
2295
;// mike.dld, 2006-29-01 [
2296
screen_workarea RECT
2297
;// mike.dld, 2006-29-01 ]
1 ha 2298
window_minimize db 0
1055 Galkov 2299
sound_flag      db 0
41 mikedld 2300
endg
1 ha 2301
 
2130 serge 2302
UID_NONE=0
2303
UID_MENUETOS=1   ;official
2304
UID_KOLIBRI=2    ;russian
2305
 
41 mikedld 2306
iglobal
2307
version_inf:
1319 diamond 2308
  db 0,7,7,0  ; version 0.7.7.0
2130 serge 2309
  db 0
540 victor 2310
  dd __REV__
41 mikedld 2311
version_end:
2312
endg
1 ha 2313
 
2314
sys_cachetodiskette:
1055 Galkov 2315
        cmp     ebx, 1
2316
        jne     .no_floppy_a_save
2317
        mov     [flp_number], 1
2318
        jmp     .save_image_on_floppy
671 Ghost 2319
.no_floppy_a_save:
1055 Galkov 2320
        cmp     ebx, 2
2321
        jne     .no_floppy_b_save
2322
        mov     [flp_number], 2
671 Ghost 2323
.save_image_on_floppy:
1055 Galkov 2324
        call    save_image
2325
        mov     [esp + 32], dword 0
2326
        cmp     [FDC_Status], 0
2327
        je      .yes_floppy_save
671 Ghost 2328
.no_floppy_b_save:
1055 Galkov 2329
        mov     [esp + 32], dword 1
671 Ghost 2330
.yes_floppy_save:
1055 Galkov 2331
        ret
1 ha 2332
 
2333
uglobal
2334
;  bgrchanged  dd  0x0
1071 diamond 2335
align 4
2336
bgrlockpid dd 0
546 diamond 2337
bgrlock db 0
1 ha 2338
endg
2339
 
2340
sys_background:
2341
 
1055 Galkov 2342
    cmp   ebx,1                            ; BACKGROUND SIZE
1 ha 2343
    jnz   nosb1
1232 Lrz 2344
    test  ecx,ecx
2345
;    cmp   ecx,0
2346
    jz    sbgrr
2347
    test  edx,edx
2348
;    cmp   edx,0
2349
    jz    sbgrr
546 diamond 2350
@@:
1071 diamond 2351
;;Maxis use atomic bts for mutexes  4.4.2009
2352
        bts     dword [bgrlock], 0
2353
        jnc     @f
1055 Galkov 2354
        call    change_task
2355
        jmp     @b
546 diamond 2356
@@:
684 diamond 2357
    mov   [BgrDataWidth],ecx
2358
    mov   [BgrDataHeight],edx
1 ha 2359
;    mov   [bgrchanged],1
469 serge 2360
 
2361
    pushad
2362
; return memory for old background
1107 diamond 2363
        mov     eax, [img_background]
2364
        cmp     eax, static_background_data
2365
        jz      @f
2366
        stdcall kernel_free, eax
2367
@@:
469 serge 2368
; calculate RAW size
2369
    xor  eax,eax
2370
    inc  eax
527 diamond 2371
    cmp  [BgrDataWidth],eax
469 serge 2372
    jae   @f
527 diamond 2373
    mov [BgrDataWidth],eax
469 serge 2374
@@:
527 diamond 2375
    cmp  [BgrDataHeight],eax
469 serge 2376
    jae   @f
527 diamond 2377
    mov [BgrDataHeight],eax
469 serge 2378
@@:
527 diamond 2379
    mov  eax,[BgrDataWidth]
2380
    imul eax,[BgrDataHeight]
2381
    lea  eax,[eax*3]
469 serge 2382
    mov  [mem_BACKGROUND],eax
2383
; get memory for new background
546 diamond 2384
    stdcall kernel_alloc, eax
469 serge 2385
    test eax, eax
1107 diamond 2386
    jz .memfailed
469 serge 2387
    mov [img_background], eax
1107 diamond 2388
    jmp .exit
2389
.memfailed:
2390
; revert to static monotone data
2391
        mov     [img_background], static_background_data
2392
        xor     eax, eax
2393
        inc     eax
2394
        mov     [BgrDataWidth], eax
2395
        mov     [BgrDataHeight], eax
2396
        mov     [mem_BACKGROUND], 4
2397
.exit:
469 serge 2398
    popad
1055 Galkov 2399
        mov     [bgrlock], 0
469 serge 2400
 
1 ha 2401
  sbgrr:
2402
    ret
469 serge 2403
 
875 serge 2404
nosb1:
1 ha 2405
 
1055 Galkov 2406
    cmp   ebx,2                            ; SET PIXEL
1 ha 2407
    jnz   nosb2
875 serge 2408
 
1107 diamond 2409
    mov   eax, [img_background]
2410
    test  ecx, ecx
2411
    jz    @f
2412
    cmp   eax, static_background_data
2413
    jz    .ret
2414
@@:
875 serge 2415
    mov ebx, [mem_BACKGROUND]
2416
    add ebx, 4095
2417
    and ebx, -4096
2418
    sub ebx, 4
2419
    cmp   ecx, ebx
1107 diamond 2420
    ja   .ret
875 serge 2421
 
684 diamond 2422
    mov   ebx,[eax+ecx]
2423
    and   ebx,0xFF000000 ;255*256*256*256
2424
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2425
    add   edx,ebx
2426
    mov   [eax+ecx],edx
1107 diamond 2427
.ret:
1 ha 2428
    ret
875 serge 2429
nosb2:
1 ha 2430
 
1055 Galkov 2431
    cmp   ebx,3                            ; DRAW BACKGROUND
1 ha 2432
    jnz   nosb3
2433
draw_background_temp:
2434
;    cmp   [bgrchanged],1 ;0
2435
;    je    nosb31
2436
;draw_background_temp:
2437
;    mov   [bgrchanged],1 ;0
76 mario79 2438
    mov    [background_defined], 1
1392 diamond 2439
    mov    byte[BACKGROUND_CHANGED], 1
709 diamond 2440
    call  force_redraw_background
1 ha 2441
   nosb31:
2442
    ret
2443
  nosb3:
2444
 
1055 Galkov 2445
    cmp   ebx,4                            ; TILED / STRETCHED
1 ha 2446
    jnz   nosb4
684 diamond 2447
    cmp   ecx,[BgrDrawMode]
1055 Galkov 2448
    je    nosb41
684 diamond 2449
    mov   [BgrDrawMode],ecx
1 ha 2450
;    mov   [bgrchanged],1
2451
   nosb41:
2452
    ret
2453
  nosb4:
2454
 
1055 Galkov 2455
    cmp   ebx,5                            ; BLOCK MOVE TO BGR
1 ha 2456
    jnz   nosb5
1107 diamond 2457
    cmp   [img_background], static_background_data
2458
    jnz   @f
2459
    test  edx, edx
2460
    jnz   .fin
2461
    cmp   esi, 4
2462
    ja    .fin
2463
  @@:
1 ha 2464
  ; bughere
684 diamond 2465
    mov   eax, ecx
2466
    mov   ebx, edx
469 serge 2467
    add   ebx, [img_background]   ;IMG_BACKGROUND
684 diamond 2468
    mov   ecx, esi
1 ha 2469
    call  memmove
2470
  .fin:
2471
    ret
2472
  nosb5:
479 kastigar 2473
 
1055 Galkov 2474
        cmp     ebx, 6
2475
        jnz     nosb6
1071 diamond 2476
;;Maxis use atomic bts for mutex 4.4.2009
546 diamond 2477
@@:
1073 heavyiron 2478
        bts     dword [bgrlock], 0
1071 diamond 2479
        jnc     @f
1055 Galkov 2480
        call    change_task
2481
        jmp     @b
546 diamond 2482
@@:
1055 Galkov 2483
        mov     eax, [CURRENT_TASK]
2484
        mov     [bgrlockpid], eax
1107 diamond 2485
        cmp     [img_background], static_background_data
2486
        jz      .nomem
1055 Galkov 2487
        stdcall user_alloc, [mem_BACKGROUND]
2488
        mov     [esp+32], eax
2489
        test    eax, eax
2490
        jz      .nomem
2491
        mov     ebx, eax
2492
        shr     ebx, 12
2493
        or      dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2494
        mov     esi, [img_background]
2495
        shr     esi, 12
2496
        mov     ecx, [mem_BACKGROUND]
2497
        add     ecx, 0xFFF
2498
        shr     ecx, 12
546 diamond 2499
.z:
1055 Galkov 2500
        mov     eax, [page_tabs+ebx*4]
2501
        test    al, 1
2502
        jz      @f
2503
        call    free_page
546 diamond 2504
@@:
1055 Galkov 2505
        mov     eax, [page_tabs+esi*4]
2506
        or      al, PG_UW
2507
        mov     [page_tabs+ebx*4], eax
2508
        mov     eax, ebx
2509
        shl     eax, 12
2510
        invlpg  [eax]
2511
        inc     ebx
2512
        inc     esi
2513
        loop    .z
2514
        ret
546 diamond 2515
.nomem:
1055 Galkov 2516
        and     [bgrlockpid], 0
2517
        mov     [bgrlock], 0
546 diamond 2518
nosb6:
1055 Galkov 2519
        cmp     ebx, 7
2520
        jnz     nosb7
2521
        cmp     [bgrlock], 0
2522
        jz      .err
2523
        mov     eax, [CURRENT_TASK]
2524
        cmp     [bgrlockpid], eax
2525
        jnz     .err
2526
        mov     eax, ecx
2527
        mov     ebx, ecx
2528
        shr     eax, 12
2529
        mov     ecx, [page_tabs+(eax-1)*4]
2530
        test    cl, USED_BLOCK+DONT_FREE_BLOCK
2531
        jz      .err
2532
        jnp     .err
2533
        push    eax
2534
        shr     ecx, 12
1312 diamond 2535
        dec     ecx
546 diamond 2536
@@:
1055 Galkov 2537
        and     dword [page_tabs+eax*4], 0
2538
        mov     edx, eax
2539
        shl     edx, 12
2540
        push eax
2541
        invlpg  [edx]
2542
        pop eax
2543
        inc     eax
2544
        loop    @b
2545
        pop     eax
2546
        and     dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2547
        stdcall user_free, ebx
2548
        mov     [esp+32], eax
2549
        and     [bgrlockpid], 0
2550
        mov     [bgrlock], 0
2551
        ret
546 diamond 2552
.err:
1055 Galkov 2553
        and     dword [esp+32], 0
2554
        ret
546 diamond 2555
 
2556
nosb7:
1 ha 2557
    ret
2558
 
709 diamond 2559
force_redraw_background:
1392 diamond 2560
    and   [draw_data+32 + RECT.left], 0
2561
    and   [draw_data+32 + RECT.top], 0
709 diamond 2562
    push  eax ebx
753 serge 2563
    mov   eax,[Screen_Max_X]
2564
    mov   ebx,[Screen_Max_Y]
709 diamond 2565
    mov   [draw_data+32 + RECT.right],eax
2566
    mov   [draw_data+32 + RECT.bottom],ebx
2567
    pop   ebx eax
1392 diamond 2568
    inc   byte[REDRAW_BACKGROUND]
709 diamond 2569
    ret
479 kastigar 2570
 
1 ha 2571
align 4
2572
 
2573
sys_getbackground:
1304 Lrz 2574
;    cmp   eax,1                                  ; SIZE
2575
    dec	  ebx
1 ha 2576
    jnz   nogb1
527 diamond 2577
    mov   eax,[BgrDataWidth]
1 ha 2578
    shl   eax,16
531 diamond 2579
    mov   ax,[BgrDataHeight]
1304 Lrz 2580
    mov   [esp+32],eax
1 ha 2581
    ret
2582
 
875 serge 2583
nogb1:
1304 Lrz 2584
;    cmp   eax,2                                  ; PIXEL
2585
    dec	  ebx
1 ha 2586
    jnz   nogb2
875 serge 2587
 
1107 diamond 2588
        mov     eax, [img_background]
1304 Lrz 2589
        test    ecx, ecx
1107 diamond 2590
        jz      @f
2591
        cmp     eax, static_background_data
2592
        jz      .ret
2593
@@:
1304 Lrz 2594
    mov ebx, [mem_BACKGROUND]
2595
    add ebx, 4095
2596
    and ebx, -4096
2597
    sub ebx, 4
2598
    cmp ecx, ebx
1107 diamond 2599
    ja  .ret
875 serge 2600
 
1304 Lrz 2601
    mov   eax,[ecx+eax]
469 serge 2602
 
1 ha 2603
    and   eax, 0xFFFFFF
1304 Lrz 2604
    mov   [esp+32],eax
1107 diamond 2605
.ret:
1 ha 2606
    ret
2607
  nogb2:
2608
 
1304 Lrz 2609
;    cmp   eax,4                                  ; TILED / STRETCHED
2610
    dec   ebx
1314 diamond 2611
    dec   ebx
1 ha 2612
    jnz   nogb4
527 diamond 2613
    mov   eax,[BgrDrawMode]
1 ha 2614
  nogb4:
1304 Lrz 2615
    mov   [esp+32],eax
1 ha 2616
    ret
2617
 
2618
align 4
2619
 
2620
sys_getkey:
1055 Galkov 2621
        mov     [esp + 32],dword 1
2622
        ; test main buffer
2623
        mov     ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2624
        movzx   ecx, word [WIN_STACK + ebx * 2]
2625
        mov     edx, [TASK_COUNT]
2626
        cmp     ecx, edx
2627
        jne     .finish
2628
        cmp     [KEY_COUNT], byte 0
2629
        je      .finish
2630
        movzx   eax, byte [KEY_BUFF]
2631
        shl     eax, 8
2632
        push    eax
2633
        dec     byte [KEY_COUNT]
2634
        and     byte [KEY_COUNT], 127
2635
        movzx   ecx, byte [KEY_COUNT]
2636
        add     ecx, 2
2637
        mov     eax, KEY_BUFF + 1
2638
        mov     ebx, KEY_BUFF
2639
        call    memmove
2640
        pop     eax
92 diamond 2641
.ret_eax:
1055 Galkov 2642
        mov     [esp + 32], eax
2643
        ret
671 Ghost 2644
.finish:
92 diamond 2645
; test hotkeys buffer
1055 Galkov 2646
        mov     ecx, hotkey_buffer
92 diamond 2647
@@:
1055 Galkov 2648
        cmp     [ecx], ebx
2649
        jz      .found
2650
        add     ecx, 8
2651
        cmp     ecx, hotkey_buffer + 120 * 8
2652
        jb      @b
2653
        ret
92 diamond 2654
.found:
1055 Galkov 2655
        mov     ax, [ecx + 6]
2656
        shl     eax, 16
2657
        mov     ah, [ecx + 4]
2658
        mov     al, 2
2659
        and     dword [ecx + 4], 0
2660
        and     dword [ecx], 0
2661
        jmp     .ret_eax
1 ha 2662
 
2663
align 4
2664
 
2665
sys_getbutton:
2666
 
1055 Galkov 2667
        mov     ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2668
        mov     [esp + 32], dword 1
2669
        movzx   ecx, word [WIN_STACK + ebx * 2]
2670
        mov     edx, [TASK_COUNT] ; less than 256 processes
2671
        cmp     ecx, edx
2672
        jne     .exit
2673
        movzx   eax, byte [BTN_COUNT]
2674
        test    eax, eax
2675
        jz      .exit
2676
        mov     eax, [BTN_BUFF]
1391 mikedld 2677
        and     al, 0xFE                                    ; delete left button bit
1055 Galkov 2678
        mov     [BTN_COUNT], byte 0
2679
        mov     [esp + 32], eax
671 Ghost 2680
.exit:
1055 Galkov 2681
        ret
1 ha 2682
 
2683
 
2684
align 4
2685
 
2686
sys_cpuusage:
2687
 
2688
;  RETURN:
2689
;
2690
;  +00 dword     process cpu usage
2691
;  +04  word     position in windowing stack
2692
;  +06  word     windowing stack value at current position (cpu nro)
2693
;  +10 12 bytes  name
2694
;  +22 dword     start in mem
2695
;  +26 dword     used mem
2696
;  +30 dword     PID , process idenfification number
2697
;
2698
 
1055 Galkov 2699
    cmp  ecx,-1         ; who am I ?
684 diamond 2700
    jne  .no_who_am_i
2701
    mov  ecx,[CURRENT_TASK]
2702
  .no_who_am_i:
1055 Galkov 2703
        cmp     ecx, max_processes
2704
        ja      .nofillbuf
1 ha 2705
 
684 diamond 2706
; +4: word: position of the window of thread in the window stack
1055 Galkov 2707
        mov     ax, [WIN_STACK + ecx * 2]
2708
        mov     [ebx+4], ax
684 diamond 2709
; +6: word: number of the thread slot, which window has in the window stack
2710
;           position ecx (has no relation to the specific thread)
1055 Galkov 2711
        mov     ax, [WIN_POS + ecx * 2]
2712
        mov     [ebx+6], ax
1 ha 2713
 
1055 Galkov 2714
        shl     ecx, 5
1 ha 2715
 
684 diamond 2716
; +0: dword: memory usage
1055 Galkov 2717
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2718
        mov     [ebx], eax
684 diamond 2719
; +10: 11 bytes: name of the process
1055 Galkov 2720
        push    ecx
2721
        lea     eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2722
        add     ebx, 10
2723
        mov     ecx, 11
2724
        call    memmove
2725
        pop     ecx
1 ha 2726
 
684 diamond 2727
; +22: address of the process in memory
2728
; +26: size of used memory - 1
1055 Galkov 2729
        push    edi
2730
        lea     edi, [ebx+12]
2731
        xor     eax, eax
2732
        mov     edx, 0x100000*16
2733
        cmp     ecx, 1 shl 5
2734
        je      .os_mem
2735
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2736
        mov     eax, std_application_base_address
684 diamond 2737
.os_mem:
1055 Galkov 2738
        stosd
2739
        lea     eax, [edx-1]
2740
        stosd
1 ha 2741
 
684 diamond 2742
; +30: PID/TID
1055 Galkov 2743
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2744
        stosd
1 ha 2745
 
2746
    ; window position and size
1055 Galkov 2747
        push    esi
2748
        lea     esi, [ecx + window_data + WDATA.box]
2749
        movsd
2750
        movsd
2751
        movsd
2752
        movsd
1 ha 2753
 
2754
    ; Process state (+50)
1055 Galkov 2755
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2756
        stosd
1 ha 2757
 
138 mikedld 2758
    ; Window client area box
1055 Galkov 2759
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2760
        movsd
2761
        movsd
2762
        movsd
2763
        movsd
1 ha 2764
 
164 serge 2765
    ; Window state
1055 Galkov 2766
        mov     al, [ecx+window_data+WDATA.fl_wstate]
2767
        stosb
164 serge 2768
 
2010 serge 2769
    ; Event mask (+71)
2770
        mov     EAX, dword [ECX+CURRENT_TASK+TASKDATA.event_mask]
2771
        stosd
2772
 
1055 Galkov 2773
        pop     esi
2774
        pop     edi
138 mikedld 2775
 
684 diamond 2776
.nofillbuf:
1 ha 2777
    ; return number of processes
2778
 
379 serge 2779
    mov    eax,[TASK_COUNT]
684 diamond 2780
    mov    [esp+32],eax
1 ha 2781
    ret
2782
 
2783
align 4
2784
sys_clock:
1055 Galkov 2785
        cli
1 ha 2786
  ; Mikhail Lisovin  xx Jan 2005
1055 Galkov 2787
  @@:   mov   al, 10
2788
        out   0x70, al
2789
        in    al, 0x71
2790
        test  al, al
2791
        jns   @f
2792
        mov   esi, 1
2793
        call  delay_ms
2794
        jmp   @b
1 ha 2795
  @@:
2796
  ; end Lisovin's fix
2797
 
1055 Galkov 2798
        xor   al,al           ; seconds
2799
        out   0x70,al
2800
        in    al,0x71
2801
        movzx ecx,al
2802
        mov   al,02           ; minutes
2803
        shl   ecx,16
2804
        out   0x70,al
2805
        in    al,0x71
2806
        movzx edx,al
2807
        mov   al,04           ; hours
2808
        shl   edx,8
2809
        out   0x70,al
2810
        in    al,0x71
2811
        add   ecx,edx
2812
        movzx edx,al
2813
        add   ecx,edx
2814
        sti
2815
        mov     [esp + 32], ecx
2816
        ret
1 ha 2817
 
2818
 
2819
align 4
2820
 
2821
sys_date:
2822
 
1055 Galkov 2823
        cli
2824
  @@:   mov   al, 10
2825
        out   0x70, al
2826
        in    al, 0x71
2827
        test  al, al
2828
        jns   @f
2829
        mov   esi, 1
2830
        call  delay_ms
2831
        jmp   @b
75 diamond 2832
  @@:
2833
 
1055 Galkov 2834
        mov     ch,0
2835
        mov     al,7            ; date
2836
        out     0x70,al
2837
        in      al,0x71
2838
        mov     cl,al
2839
        mov     al,8            ; month
2840
        shl     ecx,16
2841
        out     0x70,al
2842
        in      al,0x71
2843
        mov     ch,al
2844
        mov     al,9            ; year
2845
        out     0x70,al
2846
        in      al,0x71
2847
        mov     cl,al
2848
        sti
2849
        mov     [esp+32], ecx
2850
        ret
1 ha 2851
 
2852
 
2853
; redraw status
2854
 
2855
sys_redrawstat:
1055 Galkov 2856
        cmp     ebx, 1
2857
        jne     no_widgets_away
2858
        ; buttons away
2859
        mov     ecx,[CURRENT_TASK]
1 ha 2860
  sys_newba2:
1055 Galkov 2861
        mov     edi,[BTN_ADDR]
2862
        cmp     [edi], dword 0  ; empty button list ?
2863
        je      end_of_buttons_away
2864
        movzx   ebx, word [edi]
2865
        inc     ebx
2866
        mov     eax,edi
1 ha 2867
  sys_newba:
1055 Galkov 2868
        dec     ebx
2869
        jz      end_of_buttons_away
1 ha 2870
 
1055 Galkov 2871
        add     eax, 0x10
2872
        cmp     cx, [eax]
2873
        jnz     sys_newba
1 ha 2874
 
1055 Galkov 2875
        push    eax ebx ecx
2876
        mov     ecx,ebx
2877
        inc     ecx
2878
        shl     ecx, 4
2879
        mov     ebx, eax
2880
        add     eax, 0x10
2881
        call    memmove
2882
        dec     dword [edi]
2883
        pop     ecx ebx eax
1 ha 2884
 
1055 Galkov 2885
        jmp     sys_newba2
1 ha 2886
 
2887
  end_of_buttons_away:
2888
 
1055 Galkov 2889
        ret
1 ha 2890
 
2891
  no_widgets_away:
2892
 
1055 Galkov 2893
        cmp     ebx, 2
2894
        jnz     srl1
1 ha 2895
 
1055 Galkov 2896
        mov     edx, [TASK_BASE]      ; return whole screen draw area for this app
2897
        add     edx, draw_data - CURRENT_TASK
2898
        mov     [edx + RECT.left], 0
2899
        mov     [edx + RECT.top], 0
2900
        mov     eax, [Screen_Max_X]
2901
        mov     [edx + RECT.right], eax
2902
        mov     eax, [Screen_Max_Y]
2903
        mov     [edx + RECT.bottom], eax
1 ha 2904
 
2905
  srl1:
1055 Galkov 2906
        ret
1 ha 2907
 
2908
;ok - 100% work
2909
;nt - not tested
2910
;---------------------------------------------------------------------------------------------
2911
;eax
2912
;0 - task switch counter. Ret switch counter in eax. Block. ok.
2913
;1 - change task. Ret nothing. Block. ok.
2914
;2 - performance control
2915
; ebx
2916
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
2917
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
2918
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
2919
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
2920
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
2921
;eax
2922
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2923
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2924
;---------------------------------------------------------------------------------------------
1344 Lrz 2925
iglobal
2926
align 4
2927
sheduler:
2928
	dd	sys_sheduler.00
2929
	dd	change_task
2930
	dd	sys_sheduler.02
2931
	dd	sys_sheduler.03
2932
	dd	sys_sheduler.04
2933
endg
1638 serge 2934
sys_sheduler:
1344 Lrz 2935
;rewritten by   29.12.2009
1345 Lrz 2936
	jmp	dword [sheduler+ebx*4]
1344 Lrz 2937
;.shed_counter:
2938
.00:
2939
	mov eax,[context_counter]
1345 Lrz 2940
	mov [esp+32],eax
1344 Lrz 2941
	ret
1273 Lrz 2942
 
1344 Lrz 2943
.02:
2944
;.perf_control:
1365 Lrz 2945
	inc	ebx			;before ebx=2, ebx=3
2946
        cmp	ebx,ecx			;if ecx=3, ebx=3
1638 serge 2947
        jz 	cache_disable
1365 Lrz 2948
 
2949
	dec	ebx                     ;ebx=2
2950
	cmp	ebx,ecx                 ;
2951
	jz	cache_enable		;if ecx=2 and ebx=2
2952
 
2953
	dec	ebx                     ;ebx=1
2954
	cmp	ebx,ecx
2955
	jz      is_cache_enabled	;if ecx=1 and ebx=1
2956
 
2957
	dec	ebx
2958
	test	ebx,ecx                 ;ebx=0 and ecx=0
1344 Lrz 2959
	jz 	modify_pce		;if ecx=0
1365 Lrz 2960
 
1344 Lrz 2961
	ret
1345 Lrz 2962
 
1638 serge 2963
.03:
1344 Lrz 2964
;.rdmsr_instr:
2965
;now counter in ecx
2966
;(edx:eax) esi:edi => edx:esi
2967
	mov 	eax,esi
1345 Lrz 2968
	mov	ecx,edx
1344 Lrz 2969
	rdmsr
1345 Lrz 2970
	mov 	[esp+32],eax
2971
	mov 	[esp+20],edx 		;ret in ebx?
1344 Lrz 2972
	ret
2973
 
2974
.04:
1273 Lrz 2975
;.wrmsr_instr:
2976
;now counter in ecx
2977
;(edx:eax) esi:edi => edx:esi
2978
        ; Fast Call MSR can't be destroy
2979
        ; ® MSR_AMD_EFER ¬®¦­® ¨§¬¥­ïâì, â.ª. ¢ í⮬ ॣ¨áâॠ«¨è
2980
        ; ¢ª«îç îâáï/¢ëª«îç îâáï à áè¨à¥­­ë¥ ¢®§¬®¦­®áâ¨
1345 Lrz 2981
        cmp     edx,MSR_SYSENTER_CS
1273 Lrz 2982
        je      @f
1345 Lrz 2983
        cmp     edx,MSR_SYSENTER_ESP
1273 Lrz 2984
        je      @f
1345 Lrz 2985
        cmp     edx,MSR_SYSENTER_EIP
1273 Lrz 2986
        je      @f
1345 Lrz 2987
        cmp     edx,MSR_AMD_STAR
1273 Lrz 2988
        je      @f
2989
 
1344 Lrz 2990
        mov     eax,esi
1345 Lrz 2991
	mov	ecx,edx
1273 Lrz 2992
        wrmsr
1344 Lrz 2993
        ; mov   [esp + 32], eax
2994
        ; mov   [esp + 20], edx ;ret in ebx?
1273 Lrz 2995
@@:
1344 Lrz 2996
	ret
1273 Lrz 2997
 
1 ha 2998
cache_disable:
2999
       mov eax,cr0
3000
       or  eax,01100000000000000000000000000000b
3001
       mov cr0,eax
3002
       wbinvd ;set MESI
3003
ret
3004
 
3005
cache_enable:
3006
       mov eax,cr0
3007
       and eax,10011111111111111111111111111111b
3008
       mov cr0,eax
3009
ret
3010
 
3011
is_cache_enabled:
3012
       mov eax,cr0
3013
       mov ebx,eax
3014
       and eax,01100000000000000000000000000000b
3015
       jz cache_disabled
1345 Lrz 3016
       mov [esp+32],ebx
1 ha 3017
cache_disabled:
1345 Lrz 3018
       mov dword [esp+32],eax ;0
1 ha 3019
ret
3020
 
3021
modify_pce:
3022
       mov eax,cr4
3023
;       mov ebx,0
3024
;       or  bx,100000000b ;pce
3025
;       xor eax,ebx ;invert pce
17 me_root 3026
       bts eax,8 ;pce=cr4[8]
1 ha 3027
       mov cr4,eax
1345 Lrz 3028
       mov [esp+32],eax
1 ha 3029
ret
3030
;---------------------------------------------------------------------------------------------
3031
 
3032
 
3033
; check if pixel is allowed to be drawn
3034
 
3035
checkpixel:
1055 Galkov 3036
        push eax edx
1 ha 3037
 
1055 Galkov 3038
        mov  edx,[Screen_Max_X]     ; screen x size
3039
        inc  edx
3040
        imul edx, ebx
1300 serge 3041
        add  eax, [_WinMapAddress]
3042
        mov  dl, [eax+edx] ; lea eax, [...]
1 ha 3043
 
1055 Galkov 3044
        xor  ecx, ecx
3045
        mov  eax, [CURRENT_TASK]
3046
        cmp  al, dl
3047
        setne cl
1 ha 3048
 
1055 Galkov 3049
        pop  edx eax
3050
        ret
1 ha 3051
 
3052
iglobal
521 diamond 3053
  cpustring db 'CPU',0
1 ha 3054
endg
3055
 
67 diamond 3056
uglobal
1055 Galkov 3057
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3058
endg
1 ha 3059
 
3060
align 4
3061
; check misc
3062
 
3063
checkmisc:
3064
 
3065
    cmp   [ctrl_alt_del], 1
3066
    jne   nocpustart
501 serge 3067
 
1055 Galkov 3068
        mov     ebp, cpustring
3069
        call    fs_execute_from_sysdir
501 serge 3070
 
1 ha 3071
    mov   [ctrl_alt_del], 0
465 serge 3072
 
3073
nocpustart:
1 ha 3074
    cmp   [mouse_active], 1
3075
    jne   mouse_not_active
3076
    mov   [mouse_active], 0
3077
    xor   edi, edi
1055 Galkov 3078
    mov   ecx,  [TASK_COUNT]
465 serge 3079
set_mouse_event:
1 ha 3080
    add   edi, 256
1055 Galkov 3081
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
1 ha 3082
    loop  set_mouse_event
3083
 
465 serge 3084
mouse_not_active:
1392 diamond 3085
    cmp   byte[BACKGROUND_CHANGED], 0
3086
    jz    no_set_bgr_event
473 diamond 3087
    xor   edi, edi
1392 diamond 3088
    mov   ecx, [TASK_COUNT]
473 diamond 3089
set_bgr_event:
3090
    add   edi, 256
1055 Galkov 3091
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
473 diamond 3092
    loop  set_bgr_event
1392 diamond 3093
    mov   byte[BACKGROUND_CHANGED], 0
709 diamond 3094
no_set_bgr_event:
1392 diamond 3095
    cmp   byte[REDRAW_BACKGROUND], 0               ; background update ?
3096
    jz    nobackgr
3097
    cmp    [background_defined], 0
3098
    jz    nobackgr
709 diamond 3099
;    mov   [draw_data+32 + RECT.left],dword 0
3100
;    mov   [draw_data+32 + RECT.top],dword 0
753 serge 3101
;    mov   eax,[Screen_Max_X]
3102
;    mov   ebx,[Screen_Max_Y]
709 diamond 3103
;    mov   [draw_data+32 + RECT.right],eax
3104
;    mov   [draw_data+32 + RECT.bottom],ebx
1392 diamond 3105
@@:
1 ha 3106
    call  drawbackground
1392 diamond 3107
    xor   eax, eax
3108
    xchg  al, [REDRAW_BACKGROUND]
3109
    test  al, al                                   ; got new update request?
3110
    jnz   @b
3111
    mov   [draw_data+32 + RECT.left], eax
3112
    mov   [draw_data+32 + RECT.top], eax
3113
    mov   [draw_data+32 + RECT.right], eax
3114
    mov   [draw_data+32 + RECT.bottom], eax
381 serge 3115
    mov   [MOUSE_BACKGROUND],byte 0
1 ha 3116
 
465 serge 3117
nobackgr:
1 ha 3118
 
3119
    ; system shutdown request
3120
 
381 serge 3121
    cmp  [SYS_SHUTDOWN],byte 0
1055 Galkov 3122
    je   noshutdown
1 ha 3123
 
3124
    mov  edx,[shutdown_processes]
3125
 
381 serge 3126
    cmp  [SYS_SHUTDOWN],dl
1 ha 3127
    jne  no_mark_system_shutdown
3128
 
709 diamond 3129
    lea   ecx,[edx-1]
465 serge 3130
    mov   edx,OS_BASE+0x3040
709 diamond 3131
    jecxz @f
465 serge 3132
markz:
115 poddubny 3133
    mov   [edx+TASKDATA.state],byte 3
1 ha 3134
    add   edx,0x20
3135
    loop  markz
709 diamond 3136
@@:
1 ha 3137
 
3138
  no_mark_system_shutdown:
3139
 
1300 serge 3140
    call [_display.disable_mouse]
1 ha 3141
 
381 serge 3142
    dec  byte [SYS_SHUTDOWN]
1055 Galkov 3143
    je   system_shutdown
1 ha 3144
 
465 serge 3145
noshutdown:
1 ha 3146
 
3147
 
1055 Galkov 3148
    mov   eax,[TASK_COUNT]                  ; termination
379 serge 3149
    mov   ebx,TASK_DATA+TASKDATA.state
1 ha 3150
    mov   esi,1
3151
 
465 serge 3152
newct:
1 ha 3153
    mov   cl,[ebx]
3154
    cmp   cl,byte 3
1055 Galkov 3155
    jz    terminate
1 ha 3156
    cmp   cl,byte 4
1055 Galkov 3157
    jz    terminate
1 ha 3158
 
3159
    add   ebx,0x20
3160
    inc   esi
3161
    dec   eax
3162
    jnz   newct
3163
    ret
3164
 
3165
; redraw screen
3166
 
3167
redrawscreen:
3168
 
3169
; eax , if process window_data base is eax, do not set flag/limits
3170
 
1055 Galkov 3171
         pushad
3172
         push  eax
1 ha 3173
 
684 diamond 3174
;;;         mov   ebx,2
1 ha 3175
;;;         call  delay_hs
3176
 
1055 Galkov 3177
         ;mov   ecx,0               ; redraw flags for apps
3178
         xor   ecx,ecx
1 ha 3179
       newdw2:
3180
 
1055 Galkov 3181
         inc   ecx
3182
         push  ecx
1 ha 3183
 
1055 Galkov 3184
         mov   eax,ecx
3185
         shl   eax,5
3186
         add   eax,window_data
1 ha 3187
 
1055 Galkov 3188
         cmp   eax,[esp+4]
3189
         je    not_this_task
3190
                                   ; check if window in redraw area
3191
         mov   edi,eax
1 ha 3192
 
1055 Galkov 3193
         cmp   ecx,1               ; limit for background
3194
         jz    bgli
1 ha 3195
 
1055 Galkov 3196
         mov   eax, [edi + WDATA.box.left]
3197
         mov   ebx, [edi + WDATA.box.top]
3198
         mov   ecx, [edi + WDATA.box.width]
3199
         mov   edx, [edi + WDATA.box.height]
3200
         add   ecx,eax
3201
         add   edx,ebx
1 ha 3202
 
1362 mikedld 3203
         mov   ecx,[draw_limits.bottom]   ; ecx = area y end     ebx = window y start
1055 Galkov 3204
         cmp   ecx,ebx
3205
         jb    ricino
1 ha 3206
 
1362 mikedld 3207
         mov   ecx,[draw_limits.right]   ; ecx = area x end     eax = window x start
1055 Galkov 3208
         cmp   ecx,eax
3209
         jb    ricino
1 ha 3210
 
1055 Galkov 3211
         mov   eax, [edi + WDATA.box.left]
3212
         mov   ebx, [edi + WDATA.box.top]
3213
         mov   ecx, [edi + WDATA.box.width]
3214
         mov   edx, [edi + WDATA.box.height]
3215
         add   ecx, eax
3216
         add   edx, ebx
164 serge 3217
 
1362 mikedld 3218
         mov   eax,[draw_limits.top]    ; eax = area y start     edx = window y end
1055 Galkov 3219
         cmp   edx,eax
3220
         jb    ricino
1 ha 3221
 
1362 mikedld 3222
         mov   eax,[draw_limits.left]    ; eax = area x start     ecx = window x end
1055 Galkov 3223
         cmp   ecx,eax
3224
         jb    ricino
1 ha 3225
 
1055 Galkov 3226
        bgli:
1 ha 3227
 
1474 diamond 3228
         cmp   dword[esp], 1
1055 Galkov 3229
         jnz   .az
1392 diamond 3230
;         cmp   byte[BACKGROUND_CHANGED], 0
3231
;         jnz   newdw8
3232
         cmp   byte[REDRAW_BACKGROUND], 0
1055 Galkov 3233
         jz    .az
1392 diamond 3234
         mov   dl, 0
1055 Galkov 3235
         lea   eax,[edi+draw_data-window_data]
1362 mikedld 3236
         mov   ebx,[draw_limits.left]
1055 Galkov 3237
         cmp   ebx,[eax+RECT.left]
3238
         jae   @f
3239
         mov   [eax+RECT.left],ebx
1392 diamond 3240
         mov   dl, 1
1055 Galkov 3241
        @@:
1362 mikedld 3242
         mov   ebx,[draw_limits.top]
1055 Galkov 3243
         cmp   ebx,[eax+RECT.top]
3244
         jae   @f
3245
         mov   [eax+RECT.top],ebx
1392 diamond 3246
         mov   dl, 1
1055 Galkov 3247
        @@:
1362 mikedld 3248
         mov   ebx,[draw_limits.right]
1055 Galkov 3249
         cmp   ebx,[eax+RECT.right]
3250
         jbe   @f
3251
         mov   [eax+RECT.right],ebx
1392 diamond 3252
         mov   dl, 1
1055 Galkov 3253
        @@:
1362 mikedld 3254
         mov   ebx,[draw_limits.bottom]
1055 Galkov 3255
         cmp   ebx,[eax+RECT.bottom]
3256
         jbe   @f
3257
         mov   [eax+RECT.bottom],ebx
1392 diamond 3258
         mov   dl, 1
1055 Galkov 3259
        @@:
1392 diamond 3260
         add   byte[REDRAW_BACKGROUND], dl
1055 Galkov 3261
         jmp   newdw8
3262
        .az:
1 ha 3263
 
1055 Galkov 3264
         mov   eax,edi
3265
         add   eax,draw_data-window_data
1 ha 3266
 
1362 mikedld 3267
         mov   ebx,[draw_limits.left]          ; set limits
1055 Galkov 3268
         mov   [eax + RECT.left], ebx
1362 mikedld 3269
         mov   ebx,[draw_limits.top]
1055 Galkov 3270
         mov   [eax + RECT.top], ebx
1362 mikedld 3271
         mov   ebx,[draw_limits.right]
1055 Galkov 3272
         mov   [eax + RECT.right], ebx
1362 mikedld 3273
         mov   ebx,[draw_limits.bottom]
1055 Galkov 3274
         mov   [eax + RECT.bottom], ebx
1 ha 3275
 
1055 Galkov 3276
         sub   eax,draw_data-window_data
1 ha 3277
 
1055 Galkov 3278
         cmp   dword [esp],1
3279
         jne   nobgrd
1392 diamond 3280
         inc   byte[REDRAW_BACKGROUND]
1 ha 3281
 
3282
       newdw8:
3283
       nobgrd:
3284
 
1055 Galkov 3285
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
1 ha 3286
 
3287
       ricino:
3288
 
3289
       not_this_task:
3290
 
1055 Galkov 3291
         pop   ecx
1 ha 3292
 
1055 Galkov 3293
         cmp   ecx,[TASK_COUNT]
3294
         jle   newdw2
1 ha 3295
 
1055 Galkov 3296
         pop  eax
3297
         popad
1 ha 3298
 
1055 Galkov 3299
         ret
1 ha 3300
 
3301
calculatebackground:   ; background
3302
 
1300 serge 3303
        mov   edi, [_WinMapAddress]                ; set os to use all pixels
1055 Galkov 3304
        mov   eax,0x01010101
1300 serge 3305
        mov   ecx, [_WinMapSize]
3306
        shr   ecx, 2
1055 Galkov 3307
        rep   stosd
1 ha 3308
 
1392 diamond 3309
        mov   byte[REDRAW_BACKGROUND], 0              ; do not draw background!
3310
        mov   byte[BACKGROUND_CHANGED], 0
1 ha 3311
 
1055 Galkov 3312
        ret
1 ha 3313
 
3314
uglobal
1055 Galkov 3315
  imax    dd 0x0
1 ha 3316
endg
3317
 
3318
 
3319
 
3320
delay_ms:     ; delay in 1/1000 sec
3321
 
3322
 
1055 Galkov 3323
        push  eax
3324
        push  ecx
1 ha 3325
 
1055 Galkov 3326
        mov   ecx,esi
3327
        ; 
3328
        imul  ecx, 33941
3329
        shr   ecx, 9
3330
        ; 
1 ha 3331
 
1055 Galkov 3332
        in    al,0x61
3333
        and   al,0x10
3334
        mov   ah,al
3335
        cld
1 ha 3336
 
1055 Galkov 3337
 cnt1:  in    al,0x61
3338
        and   al,0x10
3339
        cmp   al,ah
3340
        jz    cnt1
1 ha 3341
 
1055 Galkov 3342
        mov   ah,al
3343
        loop  cnt1
1 ha 3344
 
1055 Galkov 3345
        pop   ecx
3346
        pop   eax
1 ha 3347
 
1055 Galkov 3348
        ret
1 ha 3349
 
3350
 
3351
set_app_param:
1055 Galkov 3352
        mov     edi, [TASK_BASE]
1153 clevermous 3353
        mov     eax, [edi + TASKDATA.event_mask]
1055 Galkov 3354
        mov     [edi + TASKDATA.event_mask], ebx
1153 clevermous 3355
        mov     [esp+32], eax
1055 Galkov 3356
        ret
1 ha 3357
 
3358
 
3359
 
3360
delay_hs:     ; delay in 1/100 secs
684 diamond 3361
; ebx = delay time
1055 Galkov 3362
        push  ecx
3363
        push  edx
1 ha 3364
 
1055 Galkov 3365
        mov   edx,[timer_ticks]
1 ha 3366
 
3367
      newtic:
1055 Galkov 3368
        mov   ecx,[timer_ticks]
3369
        sub   ecx,edx
3370
        cmp   ecx,ebx
3371
        jae   zerodelay
1 ha 3372
 
1055 Galkov 3373
        call  change_task
1 ha 3374
 
1055 Galkov 3375
        jmp   newtic
1 ha 3376
 
3377
      zerodelay:
1055 Galkov 3378
        pop   edx
3379
        pop   ecx
1 ha 3380
 
1055 Galkov 3381
        ret
1 ha 3382
 
1276 Lrz 3383
align 16	;very often call this subrutine
1 ha 3384
memmove:       ; memory move in bytes
3385
 
3386
; eax = from
3387
; ebx = to
3388
; ecx = no of bytes
3389
    test ecx, ecx
3390
    jle  .ret
3391
 
3392
    push esi edi ecx
3393
 
3394
    mov  edi, ebx
3395
    mov  esi, eax
3396
 
3397
    test ecx, not 11b
1055 Galkov 3398
    jz   @f
1 ha 3399
 
3400
    push ecx
3401
    shr  ecx, 2
3402
    rep  movsd
3403
    pop  ecx
3404
    and  ecx, 11b
1055 Galkov 3405
    jz   .finish
1 ha 3406
  @@:
3407
    rep  movsb
3408
 
3409
  .finish:
3410
    pop  ecx edi esi
3411
  .ret:
3412
    ret
3413
 
3414
 
75 diamond 3415
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3416
;align 4
1 ha 3417
;
75 diamond 3418
;read_floppy_file:
1 ha 3419
;
75 diamond 3420
;; as input
3421
;;
3422
;; eax pointer to file
3423
;; ebx file lenght
3424
;; ecx start 512 byte block number
3425
;; edx number of blocks to read
3426
;; esi pointer to return/work area (atleast 20 000 bytes)
3427
;;
3428
;;
3429
;; on return
3430
;;
3431
;; eax = 0 command succesful
3432
;;       1 no fd base and/or partition defined
3433
;;       2 yet unsupported FS
3434
;;       3 unknown FS
3435
;;       4 partition not defined at hd
3436
;;       5 file not found
3437
;; ebx = size of file
1 ha 3438
;
379 serge 3439
;     mov   edi,[TASK_BASE]
75 diamond 3440
;     add   edi,0x10
3441
;     add   esi,[edi]
3442
;     add   eax,[edi]
1 ha 3443
;
75 diamond 3444
;     pushad
3445
;     mov  edi,esi
3446
;     add  edi,1024
3447
;     mov  esi,0x100000+19*512
3448
;     sub  ecx,1
3449
;     shl  ecx,9
3450
;     add  esi,ecx
3451
;     shl  edx,9
3452
;     mov  ecx,edx
3453
;     cld
3454
;     rep  movsb
3455
;     popad
3456
;
3457
;     mov   [esp+36],eax
3458
;     mov   [esp+24],ebx
3459
;     ret
1 ha 3460
 
3461
 
3462
 
3463
align 4
3464
set_io_access_rights:
1306 Lrz 3465
      push edi eax
3466
      mov edi, tss._io_map_0
465 serge 3467
;     mov   ecx,eax
3468
;     and   ecx,7    ; offset in byte
3469
;     shr   eax,3    ; number of byte
3470
;     add   edi,eax
3471
;     mov   ebx,1
3472
;     shl   ebx,cl
1232 Lrz 3473
     test  ebp,ebp
3474
;     cmp   ebp,0                ; enable access - ebp = 0
2106 serge 3475
     jnz   .siar1
465 serge 3476
;     not   ebx
3477
;     and   [edi],byte bl
3478
     btr [edi], eax
1306 Lrz 3479
     pop eax edi
1 ha 3480
     ret
2106 serge 3481
.siar1:
465 serge 3482
     bts [edi], eax
3483
  ;  or    [edi],byte bl        ; disable access - ebp = 1
1306 Lrz 3484
     pop eax edi
1 ha 3485
     ret
1306 Lrz 3486
;reserve/free group of ports
3487
;  * eax = 46 - number function
3488
;  * ebx = 0 - reserve, 1 - free
3489
;  * ecx = number start arrea of ports
3490
;  * edx = number end arrea of ports (include last number of port)
3491
;Return value:
1638 serge 3492
;  * eax = 0 - succesful
1306 Lrz 3493
;  * eax = 1 - error
3494
;  * The system has reserve this ports:
3495
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
3496
;destroys eax,ebx, ebp
1 ha 3497
r_f_port_area:
3498
 
1306 Lrz 3499
     test  ebx, ebx
1 ha 3500
     jnz   free_port_area
3501
;     je    r_port_area
3502
;     jmp   free_port_area
3503
 
3504
;   r_port_area:
3505
 
1306 Lrz 3506
;     pushad
1 ha 3507
 
1306 Lrz 3508
     cmp   ecx,edx            ; beginning > end ?
75 diamond 3509
     ja    rpal1
1306 Lrz 3510
     cmp   edx,65536
75 diamond 3511
     jae   rpal1
1306 Lrz 3512
     mov   eax,[RESERVED_PORTS]
3513
     test  eax,eax            ; no reserved areas ?
1 ha 3514
     je    rpal2
1306 Lrz 3515
     cmp   eax,255            ; max reserved
75 diamond 3516
     jae   rpal1
465 serge 3517
 rpal3:
1306 Lrz 3518
     mov   ebx,eax
3519
     shl   ebx,4
3520
     add   ebx,RESERVED_PORTS
3521
     cmp   ecx,[ebx+8]
75 diamond 3522
     ja    rpal4
1306 Lrz 3523
     cmp   edx,[ebx+4]
1 ha 3524
     jae   rpal1
3525
;     jb    rpal4
3526
;     jmp   rpal1
465 serge 3527
 rpal4:
1306 Lrz 3528
     dec   eax
1 ha 3529
     jnz   rpal3
3530
     jmp   rpal2
3531
   rpal1:
1306 Lrz 3532
;     popad
3533
;     mov   eax,1
3534
     xor    eax,eax
3535
     inc    eax
1 ha 3536
     ret
3537
   rpal2:
1306 Lrz 3538
;     popad
1 ha 3539
     ; enable port access at port IO map
1306 Lrz 3540
	cli
3541
	pushad                        ; start enable io map
1 ha 3542
 
1306 Lrz 3543
	cmp   edx,65536 ;16384
3544
	jae   no_unmask_io ; jge
3545
	mov   eax,ecx
3546
;	push	ebp
3547
	xor	ebp,ebp                ; enable - eax = port
3548
new_port_access:
3549
;     pushad
3550
	call	set_io_access_rights
3551
;     popad
1 ha 3552
     inc   eax
1306 Lrz 3553
     cmp   eax,edx
1 ha 3554
     jbe   new_port_access
1306 Lrz 3555
;	pop	ebp
3556
no_unmask_io:
3557
	popad                         ; end enable io map
1 ha 3558
     sti
3559
 
1306 Lrz 3560
     mov   eax,[RESERVED_PORTS]
3561
     add   eax,1
3562
     mov   [RESERVED_PORTS],eax
3563
     shl   eax,4
3564
     add   eax,RESERVED_PORTS
3565
     mov   ebx,[TASK_BASE]
3566
     mov   ebx,[ebx+TASKDATA.pid]
3567
     mov   [eax],ebx
3568
     mov   [eax+4],ecx
3569
     mov   [eax+8],edx
1 ha 3570
 
3571
     xor   eax, eax
3572
     ret
3573
 
3574
free_port_area:
3575
 
1306 Lrz 3576
;     pushad
3577
     mov   eax,[RESERVED_PORTS]     ; no reserved areas ?
3578
     test  eax,eax
3579
     jz    frpal2
3580
     mov   ebx,[TASK_BASE]
3581
     mov   ebx,[ebx+TASKDATA.pid]
1 ha 3582
   frpal3:
1306 Lrz 3583
     mov   edi,eax
1 ha 3584
     shl   edi,4
381 serge 3585
     add   edi,RESERVED_PORTS
1306 Lrz 3586
     cmp   ebx,[edi]
1 ha 3587
     jne   frpal4
1306 Lrz 3588
     cmp   ecx,[edi+4]
1 ha 3589
     jne   frpal4
1306 Lrz 3590
     cmp   edx,[edi+8]
1 ha 3591
     jne   frpal4
3592
     jmp   frpal1
3593
   frpal4:
1306 Lrz 3594
     dec   eax
1 ha 3595
     jnz   frpal3
3596
   frpal2:
1306 Lrz 3597
;     popad
3598
     inc   eax
1 ha 3599
     ret
3600
   frpal1:
1306 Lrz 3601
	push	ecx
3602
	mov   ecx,256
3603
	sub   ecx,eax
3604
	shl   ecx,4
3605
	mov   esi,edi
3606
	add   esi,16
3607
	cld
3608
	rep   movsb
1 ha 3609
 
1306 Lrz 3610
	dec   dword [RESERVED_PORTS]
3611
;popad
3612
;disable port access at port IO map
1 ha 3613
 
1306 Lrz 3614
;     pushad                        ; start disable io map
3615
     pop	eax	;start port
3616
     cmp   edx,65536 ;16384
1 ha 3617
     jge   no_mask_io
3618
 
1306 Lrz 3619
;     mov   eax,ecx
3620
	xor	ebp,ebp
3621
	inc	ebp
3622
new_port_access_disable:
3623
;     pushad
3624
;     mov   ebp,1                  ; disable - eax = port
1 ha 3625
     call  set_io_access_rights
1306 Lrz 3626
;     popad
1 ha 3627
     inc   eax
1306 Lrz 3628
     cmp   eax,edx
1 ha 3629
     jbe   new_port_access_disable
1306 Lrz 3630
no_mask_io:
3631
;     popad                         ; end disable io map
1 ha 3632
     xor   eax, eax
3633
     ret
3634
 
3635
 
2106 serge 3636
align 4
1 ha 3637
drawbackground:
33 mario79 3638
       inc   [mouse_pause]
381 serge 3639
       cmp   [SCR_MODE],word 0x12
117 mario79 3640
       je   dbrv20
1 ha 3641
     dbrv12:
381 serge 3642
       cmp  [SCR_MODE],word 0100000000000000b
1 ha 3643
       jge  dbrv20
381 serge 3644
       cmp  [SCR_MODE],word 0x13
1 ha 3645
       je   dbrv20
3646
       call  vesa12_drawbackground
33 mario79 3647
       dec   [mouse_pause]
36 mario79 3648
       call   [draw_pointer]
1 ha 3649
       ret
3650
     dbrv20:
527 diamond 3651
       cmp   [BgrDrawMode],dword 1
1 ha 3652
       jne   bgrstr
3653
       call  vesa20_drawbackground_tiled
33 mario79 3654
       dec   [mouse_pause]
36 mario79 3655
       call   [draw_pointer]
1 ha 3656
       ret
3657
     bgrstr:
3658
       call  vesa20_drawbackground_stretch
33 mario79 3659
       dec   [mouse_pause]
36 mario79 3660
       call   [draw_pointer]
1 ha 3661
       ret
3662
 
75 diamond 3663
align 4
1 ha 3664
 
1055 Galkov 3665
syscall_putimage:                       ; PutImage
1 ha 3666
sys_putimage:
53 mikedld 3667
     test  ecx,0x80008000
3668
     jnz   .exit
3669
     test  ecx,0x0000FFFF
3670
     jz    .exit
3671
     test  ecx,0xFFFF0000
3672
     jnz   @f
3673
  .exit:
3674
     ret
3675
 @@:
1055 Galkov 3676
        mov     edi,[current_slot]
3677
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
3678
        rol     edx,16
3679
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
3680
        rol     edx,16
114 mikedld 3681
  .forced:
1055 Galkov 3682
        push    ebp esi 0
3683
        mov     ebp, putimage_get24bpp
3684
        mov     esi, putimage_init24bpp
283 diamond 3685
sys_putimage_bpp:
3686
;        call    [disable_mouse] ; this will be done in xxx_putimage
117 mario79 3687
;        mov     eax, vga_putimage
1055 Galkov 3688
        cmp     [SCR_MODE], word 0x12
3689
        jz      @f   ;.doit
3690
        mov     eax, vesa12_putimage
3691
        cmp     [SCR_MODE], word 0100000000000000b
3692
        jae     @f
3693
        cmp     [SCR_MODE], word 0x13
3694
        jnz     .doit
75 diamond 3695
@@:
1055 Galkov 3696
        mov     eax, vesa20_putimage
75 diamond 3697
.doit:
1055 Galkov 3698
        inc     [mouse_pause]
3699
        call    eax
3700
        dec     [mouse_pause]
3701
        pop     ebp esi ebp
3702
        jmp     [draw_pointer]
1495 Lrz 3703
align 4
283 diamond 3704
sys_putimage_palette:
3705
; ebx = pointer to image
3706
; ecx = [xsize]*65536 + [ysize]
3707
; edx = [xstart]*65536 + [ystart]
314 diamond 3708
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 3709
; edi = pointer to palette
314 diamond 3710
; ebp = row delta
1055 Galkov 3711
        mov     eax, [CURRENT_TASK]
3712
        shl     eax, 8
3713
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
3714
        rol     edx, 16
3715
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
3716
        rol     edx, 16
283 diamond 3717
.forced:
1055 Galkov 3718
        cmp     esi, 1
3719
        jnz     @f
3720
        push    edi
3721
        mov     eax, [edi+4]
3722
        sub     eax, [edi]
3723
        push    eax
3724
        push    dword [edi]
3725
        push    0ffffff80h
3726
        mov     edi, esp
3727
        call    put_mono_image
3728
        add     esp, 12
3729
        pop     edi
3730
        ret
911 diamond 3731
@@:
1055 Galkov 3732
        cmp     esi, 2
3733
        jnz     @f
3734
        push    edi
3735
        push    0ffffff80h
3736
        mov     edi, esp
3737
        call    put_2bit_image
3738
        pop     eax
3739
        pop     edi
3740
        ret
911 diamond 3741
@@:
1055 Galkov 3742
        cmp     esi, 4
3743
        jnz     @f
3744
        push    edi
3745
        push    0ffffff80h
3746
        mov     edi, esp
3747
        call    put_4bit_image
3748
        pop     eax
3749
        pop     edi
3750
        ret
314 diamond 3751
@@:
1055 Galkov 3752
        push    ebp esi ebp
3753
        cmp     esi, 8
3754
        jnz     @f
3755
        mov     ebp, putimage_get8bpp
3756
        mov     esi, putimage_init8bpp
3757
        jmp     sys_putimage_bpp
918 diamond 3758
@@:
1055 Galkov 3759
        cmp     esi, 15
3760
        jnz     @f
3761
        mov     ebp, putimage_get15bpp
3762
        mov     esi, putimage_init15bpp
3763
        jmp     sys_putimage_bpp
906 diamond 3764
@@:
1055 Galkov 3765
        cmp     esi, 16
3766
        jnz     @f
3767
        mov     ebp, putimage_get16bpp
3768
        mov     esi, putimage_init16bpp
3769
        jmp     sys_putimage_bpp
842 diamond 3770
@@:
1055 Galkov 3771
        cmp     esi, 24
3772
        jnz     @f
3773
        mov     ebp, putimage_get24bpp
3774
        mov     esi, putimage_init24bpp
3775
        jmp     sys_putimage_bpp
314 diamond 3776
@@:
1055 Galkov 3777
        cmp     esi, 32
3778
        jnz     @f
3779
        mov     ebp, putimage_get32bpp
3780
        mov     esi, putimage_init32bpp
3781
        jmp     sys_putimage_bpp
314 diamond 3782
@@:
1055 Galkov 3783
        pop     ebp esi ebp
3784
        ret
283 diamond 3785
 
911 diamond 3786
put_mono_image:
1055 Galkov 3787
        push    ebp esi ebp
3788
        mov     ebp, putimage_get1bpp
3789
        mov     esi, putimage_init1bpp
3790
        jmp     sys_putimage_bpp
918 diamond 3791
put_2bit_image:
1055 Galkov 3792
        push    ebp esi ebp
3793
        mov     ebp, putimage_get2bpp
3794
        mov     esi, putimage_init2bpp
3795
        jmp     sys_putimage_bpp
911 diamond 3796
put_4bit_image:
1055 Galkov 3797
        push    ebp esi ebp
3798
        mov     ebp, putimage_get4bpp
3799
        mov     esi, putimage_init4bpp
3800
        jmp     sys_putimage_bpp
911 diamond 3801
 
283 diamond 3802
putimage_init24bpp:
1055 Galkov 3803
        lea     eax, [eax*3]
283 diamond 3804
putimage_init8bpp:
1055 Galkov 3805
        ret
283 diamond 3806
 
911 diamond 3807
align 16
283 diamond 3808
putimage_get24bpp:
1055 Galkov 3809
        movzx   eax, byte [esi+2]
3810
        shl     eax, 16
3811
        mov     ax, [esi]
3812
        add     esi, 3
3813
        ret     4
911 diamond 3814
align 16
283 diamond 3815
putimage_get8bpp:
1055 Galkov 3816
        movzx   eax, byte [esi]
3817
        push    edx
3818
        mov     edx, [esp+8]
3819
        mov     eax, [edx+eax*4]
3820
        pop     edx
3821
        inc     esi
3822
        ret     4
283 diamond 3823
 
911 diamond 3824
putimage_init1bpp:
1055 Galkov 3825
        add     eax, ecx
3826
        push    ecx
3827
        add     eax, 7
3828
        add     ecx, 7
3829
        shr     eax, 3
3830
        shr     ecx, 3
3831
        sub     eax, ecx
3832
        pop     ecx
3833
        ret
911 diamond 3834
align 16
3835
putimage_get1bpp:
1055 Galkov 3836
        push    edx
3837
        mov     edx, [esp+8]
3838
        mov     al, [edx]
3839
        add     al, al
3840
        jnz     @f
3841
        lodsb
3842
        adc     al, al
911 diamond 3843
@@:
1055 Galkov 3844
        mov     [edx], al
3845
        sbb     eax, eax
3846
        and     eax, [edx+8]
3847
        add     eax, [edx+4]
3848
        pop     edx
3849
        ret     4
911 diamond 3850
 
918 diamond 3851
putimage_init2bpp:
1055 Galkov 3852
        add     eax, ecx
3853
        push    ecx
3854
        add     ecx, 3
3855
        add     eax, 3
3856
        shr     ecx, 2
3857
        shr     eax, 2
3858
        sub     eax, ecx
3859
        pop     ecx
3860
        ret
918 diamond 3861
align 16
3862
putimage_get2bpp:
1055 Galkov 3863
        push    edx
3864
        mov     edx, [esp+8]
3865
        mov     al, [edx]
3866
        mov     ah, al
3867
        shr     al, 6
3868
        shl     ah, 2
3869
        jnz     .nonewbyte
3870
        lodsb
3871
        mov     ah, al
3872
        shr     al, 6
3873
        shl     ah, 2
3874
        add     ah, 1
918 diamond 3875
.nonewbyte:
1055 Galkov 3876
        mov     [edx], ah
3877
        mov     edx, [edx+4]
3878
        movzx   eax, al
3879
        mov     eax, [edx+eax*4]
3880
        pop     edx
3881
        ret     4
918 diamond 3882
 
911 diamond 3883
putimage_init4bpp:
1055 Galkov 3884
        add     eax, ecx
3885
        push    ecx
3886
        add     ecx, 1
3887
        add     eax, 1
3888
        shr     ecx, 1
3889
        shr     eax, 1
3890
        sub     eax, ecx
3891
        pop     ecx
3892
        ret
911 diamond 3893
align 16
3894
putimage_get4bpp:
1055 Galkov 3895
        push    edx
3896
        mov     edx, [esp+8]
3897
        add     byte [edx], 80h
3898
        jc      @f
3899
        movzx   eax, byte [edx+1]
3900
        mov     edx, [edx+4]
3901
        and     eax, 0x0F
3902
        mov     eax, [edx+eax*4]
3903
        pop     edx
3904
        ret     4
911 diamond 3905
@@:
1055 Galkov 3906
        movzx   eax, byte [esi]
3907
        add     esi, 1
3908
        mov     [edx+1], al
3909
        shr     eax, 4
3910
        mov     edx, [edx+4]
3911
        mov     eax, [edx+eax*4]
3912
        pop     edx
3913
        ret     4
911 diamond 3914
 
314 diamond 3915
putimage_init32bpp:
1055 Galkov 3916
        shl     eax, 2
3917
        ret
911 diamond 3918
align 16
314 diamond 3919
putimage_get32bpp:
1055 Galkov 3920
        lodsd
3921
        ret     4
314 diamond 3922
 
906 diamond 3923
putimage_init15bpp:
911 diamond 3924
putimage_init16bpp:
1055 Galkov 3925
        add     eax, eax
3926
        ret
911 diamond 3927
align 16
906 diamond 3928
putimage_get15bpp:
842 diamond 3929
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
1055 Galkov 3930
        push    ecx edx
3931
        movzx   eax, word [esi]
3932
        add     esi, 2
3933
        mov     ecx, eax
3934
        mov     edx, eax
3935
        and     eax, 0x1F
3936
        and     ecx, 0x1F shl 5
3937
        and     edx, 0x1F shl 10
3938
        shl     eax, 3
3939
        shl     ecx, 6
3940
        shl     edx, 9
3941
        or      eax, ecx
3942
        or      eax, edx
3943
        pop     edx ecx
3944
        ret     4
906 diamond 3945
 
911 diamond 3946
align 16
906 diamond 3947
putimage_get16bpp:
3948
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
1055 Galkov 3949
        push    ecx edx
3950
        movzx   eax, word [esi]
3951
        add     esi, 2
3952
        mov     ecx, eax
3953
        mov     edx, eax
3954
        and     eax, 0x1F
3955
        and     ecx, 0x3F shl 5
3956
        and     edx, 0x1F shl 11
3957
        shl     eax, 3
3958
        shl     ecx, 5
3959
        shl     edx, 8
3960
        or      eax, ecx
3961
        or      eax, edx
3962
        pop     edx ecx
3963
        ret     4
842 diamond 3964
 
1 ha 3965
; eax x beginning
3966
; ebx y beginning
3967
; ecx x end
1055 Galkov 3968
        ; edx y end
1 ha 3969
; edi color
3970
 
3971
__sys_drawbar:
1055 Galkov 3972
        mov     esi,[current_slot]
3973
        add     eax,[esi+APPDATA.wnd_clientbox.left]
3974
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
3975
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
3976
        add     edx,[esi+APPDATA.wnd_clientbox.top]
114 mikedld 3977
  .forced:
33 mario79 3978
    inc   [mouse_pause]
283 diamond 3979
;        call    [disable_mouse]
381 serge 3980
    cmp   [SCR_MODE],word 0x12
1055 Galkov 3981
    je   dbv20
1 ha 3982
   sdbv20:
381 serge 3983
    cmp  [SCR_MODE],word 0100000000000000b
1 ha 3984
    jge  dbv20
381 serge 3985
    cmp  [SCR_MODE],word 0x13
1055 Galkov 3986
    je   dbv20
1 ha 3987
    call vesa12_drawbar
33 mario79 3988
    dec   [mouse_pause]
36 mario79 3989
    call   [draw_pointer]
1 ha 3990
    ret
3991
  dbv20:
3992
    call vesa20_drawbar
33 mario79 3993
    dec   [mouse_pause]
36 mario79 3994
    call   [draw_pointer]
1 ha 3995
    ret
3996
 
3997
 
3998
 
3999
kb_read:
4000
 
1055 Galkov 4001
        push    ecx edx
1 ha 4002
 
1055 Galkov 4003
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4004
      kr_loop:
1055 Galkov 4005
        in      al,0x64
4006
        test    al,1
4007
        jnz     kr_ready
4008
        loop    kr_loop
4009
        mov     ah,1
4010
        jmp     kr_exit
1 ha 4011
      kr_ready:
1055 Galkov 4012
        push    ecx
4013
        mov     ecx,32
1 ha 4014
      kr_delay:
1055 Galkov 4015
        loop    kr_delay
4016
        pop     ecx
4017
        in      al,0x60
4018
        xor     ah,ah
1 ha 4019
      kr_exit:
4020
 
1055 Galkov 4021
        pop     edx ecx
1 ha 4022
 
1055 Galkov 4023
        ret
1 ha 4024
 
4025
 
4026
kb_write:
4027
 
1055 Galkov 4028
        push    ecx edx
1 ha 4029
 
1055 Galkov 4030
        mov     dl,al
265 diamond 4031
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4032
;      kw_loop1:
4033
;        in      al,0x64
4034
;        test    al,0x20
4035
;        jz      kw_ok1
4036
;        loop    kw_loop1
4037
;        mov     ah,1
4038
;        jmp     kw_exit
4039
;      kw_ok1:
1055 Galkov 4040
        in      al,0x60
4041
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4042
      kw_loop:
1055 Galkov 4043
        in      al,0x64
4044
        test    al,2
4045
        jz      kw_ok
4046
        loop    kw_loop
4047
        mov     ah,1
4048
        jmp     kw_exit
1 ha 4049
      kw_ok:
1055 Galkov 4050
        mov     al,dl
4051
        out     0x60,al
4052
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4053
      kw_loop3:
1055 Galkov 4054
        in      al,0x64
4055
        test    al,2
4056
        jz      kw_ok3
4057
        loop    kw_loop3
4058
        mov     ah,1
4059
        jmp     kw_exit
1 ha 4060
      kw_ok3:
1055 Galkov 4061
        mov     ah,8
1 ha 4062
      kw_loop4:
1055 Galkov 4063
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4064
      kw_loop5:
1055 Galkov 4065
        in      al,0x64
4066
        test    al,1
4067
        jnz     kw_ok4
4068
        loop    kw_loop5
4069
        dec     ah
4070
        jnz     kw_loop4
1 ha 4071
      kw_ok4:
1055 Galkov 4072
        xor     ah,ah
1 ha 4073
      kw_exit:
4074
 
1055 Galkov 4075
        pop     edx ecx
1 ha 4076
 
1055 Galkov 4077
        ret
1 ha 4078
 
4079
 
4080
kb_cmd:
4081
 
1055 Galkov 4082
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4083
      c_wait:
1055 Galkov 4084
        in      al,0x64
4085
        test    al,2
4086
        jz      c_send
4087
        loop    c_wait
4088
        jmp     c_error
1 ha 4089
      c_send:
1055 Galkov 4090
        mov     al,bl
4091
        out     0x64,al
4092
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4093
      c_accept:
1055 Galkov 4094
        in      al,0x64
4095
        test    al,2
4096
        jz      c_ok
4097
        loop    c_accept
1 ha 4098
      c_error:
1055 Galkov 4099
        mov     ah,1
4100
        jmp     c_exit
1 ha 4101
      c_ok:
1055 Galkov 4102
        xor     ah,ah
1 ha 4103
      c_exit:
1055 Galkov 4104
        ret
1 ha 4105
 
4106
 
4107
setmouse:  ; set mousepicture -pointer
1055 Galkov 4108
           ; ps2 mouse enable
1 ha 4109
 
381 serge 4110
     mov     [MOUSE_PICTURE],dword mousepointer
1 ha 4111
 
4112
     cli
4113
 
4114
     ret
4115
 
1055 Galkov 4116
if used _rdtsc
1 ha 4117
_rdtsc:
164 serge 4118
     bt [cpu_caps], CAPS_TSC
4119
     jnc ret_rdtsc
1 ha 4120
     rdtsc
4121
     ret
4122
   ret_rdtsc:
4123
     mov   edx,0xffffffff
4124
     mov   eax,0xffffffff
4125
     ret
1055 Galkov 4126
end if
1 ha 4127
 
4128
sys_msg_board_str:
4129
 
4130
     pushad
4131
   @@:
4132
     cmp    [esi],byte 0
4133
     je     @f
4134
     mov    eax,1
4135
     movzx  ebx,byte [esi]
4136
     call   sys_msg_board
4137
     inc    esi
4138
     jmp    @b
4139
   @@:
4140
     popad
4141
     ret
4142
 
709 diamond 4143
sys_msg_board_byte:
4144
; in: al = byte to display
4145
; out: nothing
4146
; destroys: nothing
1055 Galkov 4147
        pushad
4148
        mov     ecx, 2
4149
        shl     eax, 24
4150
        jmp     @f
709 diamond 4151
 
4152
sys_msg_board_word:
4153
; in: ax = word to display
4154
; out: nothing
4155
; destroys: nothing
1055 Galkov 4156
        pushad
4157
        mov     ecx, 4
4158
        shl     eax, 16
4159
        jmp     @f
709 diamond 4160
 
4161
sys_msg_board_dword:
4162
; in: eax = dword to display
4163
; out: nothing
4164
; destroys: nothing
1055 Galkov 4165
        pushad
4166
        mov     ecx, 8
709 diamond 4167
@@:
1055 Galkov 4168
        push    ecx
4169
        rol     eax, 4
4170
        push    eax
4171
        and     al, 0xF
4172
        cmp     al, 10
4173
        sbb     al, 69h
4174
        das
4175
        mov     bl, al
4176
        xor     eax, eax
4177
        inc     eax
4178
        call    sys_msg_board
4179
        pop     eax
4180
        pop     ecx
4181
        loop    @b
4182
        popad
4183
        ret
709 diamond 4184
 
1 ha 4185
uglobal
373 mikedld 4186
  msg_board_data: times 4096 db 0
1 ha 4187
  msg_board_count dd 0x0
4188
endg
4189
 
4190
sys_msg_board:
4191
 
4192
; eax=1 : write :  bl byte to write
4193
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4194
 
1055 Galkov 4195
        mov     ecx, [msg_board_count]
4196
        cmp     eax, 1
4197
        jne     .smbl1
1 ha 4198
 
1043 hidnplayr 4199
if defined debug_com_base
1 ha 4200
 
1055 Galkov 4201
        push    dx ax
1043 hidnplayr 4202
 
1055 Galkov 4203
       @@:                              ; Wait for empty transmit register  (yes, this slows down system..)
4204
        mov     dx, debug_com_base+5
4205
        in      al, dx
4206
        test    al, 1 shl 5
4207
        jz      @r
1043 hidnplayr 4208
 
1055 Galkov 4209
        mov     dx, debug_com_base      ; Output the byte
4210
        mov     al, bl
4211
        out     dx, al
1043 hidnplayr 4212
 
1055 Galkov 4213
        pop     ax dx
1043 hidnplayr 4214
 
4215
end if
4216
 
1055 Galkov 4217
        mov     [msg_board_data+ecx],bl
4218
        inc     ecx
4219
        and     ecx, 4095
4220
        mov     [msg_board_count], ecx
4221
        mov     [check_idle_semaphore], 5
4222
        ret
671 Ghost 4223
.smbl1:
1055 Galkov 4224
        cmp     eax, 2
4225
        jne     .smbl2
4226
        test    ecx, ecx
4227
        jz      .smbl21
4228
        mov     eax, msg_board_data+1
4229
        mov     ebx, msg_board_data
4230
        movzx   edx, byte [ebx]
4231
        call    memmove
4232
        dec     [msg_board_count]
4233
        mov     [esp + 36], edx ;eax
4234
        mov     [esp + 24], dword 1
4235
        ret
671 Ghost 4236
.smbl21:
1055 Galkov 4237
        mov     [esp+36], ecx
4238
        mov     [esp+24], ecx
671 Ghost 4239
.smbl2:
1055 Galkov 4240
        ret
1 ha 4241
 
1494 Lrz 4242
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4243
;; 66 sys function.                                                ;;
4244
;; in eax=66,ebx in [0..5],ecx,edx                                 ;;
4245
;; out eax                                                         ;;
4246
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4247
iglobal
4248
align 4
4249
f66call:
4250
           dd sys_process_def.1   ; 1 = set keyboard mode
4251
           dd sys_process_def.2   ; 2 = get keyboard mode
4252
           dd sys_process_def.3   ; 3 = get keyboard ctrl, alt, shift
4253
           dd sys_process_def.4
4254
           dd sys_process_def.5
4255
endg
1 ha 4256
 
4257
 
1494 Lrz 4258
 
4259
 
1 ha 4260
sys_process_def:
1494 Lrz 4261
	dec	ebx
4262
	cmp	ebx,5
4263
	jae	.not_support	;if >=6 then or eax,-1
4264
 
1055 Galkov 4265
        mov     edi, [CURRENT_TASK]
1494 Lrz 4266
	jmp	dword [f66call+ebx*4]
1 ha 4267
 
1494 Lrz 4268
.not_support:
4269
	or	eax,-1
4270
	ret
1 ha 4271
 
1494 Lrz 4272
.1:
1 ha 4273
     shl   edi,8
1494 Lrz 4274
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],cl
1 ha 4275
 
4276
     ret
4277
 
1494 Lrz 4278
.2:				; 2 = get keyboard mode
1 ha 4279
     shl   edi,8
380 serge 4280
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
1494 Lrz 4281
     mov   [esp+32],eax
1 ha 4282
     ret
4283
;     xor   eax,eax
4284
;     movzx eax,byte [shift]
4285
;     movzx ebx,byte [ctrl]
4286
;     shl   ebx,2
4287
;     add   eax,ebx
4288
;     movzx ebx,byte [alt]
4289
;     shl   ebx,3
4290
;     add   eax,ebx
1494 Lrz 4291
.3:				;3 = get keyboard ctrl, alt, shift
1 ha 4292
 ;// mike.dld [
4293
     mov   eax, [kb_state]
4294
 ;// mike.dld ]
1494 Lrz 4295
     mov   [esp+32],eax
1 ha 4296
     ret
4297
 
1494 Lrz 4298
.4:
1055 Galkov 4299
        mov     eax, hotkey_list
92 diamond 4300
@@:
1055 Galkov 4301
        cmp     dword [eax+8], 0
4302
        jz      .found_free
4303
        add     eax, 16
4304
        cmp     eax, hotkey_list+16*256
4305
        jb      @b
1494 Lrz 4306
        mov     dword [esp+32], 1
1055 Galkov 4307
        ret
92 diamond 4308
.found_free:
1055 Galkov 4309
        mov     [eax+8], edi
1494 Lrz 4310
        mov     [eax+4], edx
4311
        movzx   ecx, cl
4312
        lea     ecx, [hotkey_scancodes+ecx*4]
4313
        mov     edx, [ecx]
4314
        mov     [eax], edx
4315
        mov     [ecx], eax
4316
        mov     [eax+12], ecx
1055 Galkov 4317
        jecxz   @f
1494 Lrz 4318
        mov     [edx+12], eax
92 diamond 4319
@@:
1494 Lrz 4320
        and     dword [esp+32], 0
1055 Galkov 4321
        ret
92 diamond 4322
 
1494 Lrz 4323
.5:
4324
        movzx   ebx, cl
1055 Galkov 4325
        lea     ebx, [hotkey_scancodes+ebx*4]
4326
        mov     eax, [ebx]
92 diamond 4327
.scan:
1055 Galkov 4328
        test    eax, eax
4329
        jz      .notfound
4330
        cmp     [eax+8], edi
4331
        jnz     .next
1494 Lrz 4332
        cmp     [eax+4], edx
1055 Galkov 4333
        jz      .found
92 diamond 4334
.next:
1055 Galkov 4335
        mov     eax, [eax]
4336
        jmp     .scan
92 diamond 4337
.notfound:
1494 Lrz 4338
        mov     dword [esp+32], 1
1055 Galkov 4339
        ret
92 diamond 4340
.found:
1055 Galkov 4341
        mov     ecx, [eax]
4342
        jecxz   @f
4343
        mov     edx, [eax+12]
4344
        mov     [ecx+12], edx
92 diamond 4345
@@:
1055 Galkov 4346
        mov     ecx, [eax+12]
4347
        mov     edx, [eax]
4348
        mov     [ecx], edx
4349
        xor     edx, edx
4350
        mov     [eax+4], edx
4351
        mov     [eax+8], edx
4352
        mov     [eax+12], edx
4353
        mov     [eax], edx
1494 Lrz 4354
        mov     [esp+32], edx
1055 Galkov 4355
        ret
92 diamond 4356
 
1497 Lrz 4357
 
4358
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4359
;; 61 sys function.                                                ;;
4360
;; in eax=61,ebx in [1..3]                                         ;;
4361
;; out eax                                                         ;;
4362
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4363
iglobal
1 ha 4364
align 4
1497 Lrz 4365
f61call:
4366
           dd sys_gs.1   ; resolution
4367
           dd sys_gs.2   ; bits per pixel
4368
           dd sys_gs.3   ; bytes per scanline
4369
endg
1 ha 4370
 
1497 Lrz 4371
 
4372
align 4
4373
 
1055 Galkov 4374
sys_gs:                         ; direct screen access
1497 Lrz 4375
	dec	ebx
4376
	cmp	ebx,2
4377
	ja	.not_support
4378
	jmp	dword [f61call+ebx*4]
4379
.not_support:
4380
	or  [esp+32],dword -1
4381
        ret
1 ha 4382
 
1497 Lrz 4383
 
4384
.1:                             ; resolution
753 serge 4385
     mov  eax,[Screen_Max_X]
1 ha 4386
     shl  eax,16
753 serge 4387
     mov  ax,[Screen_Max_Y]
1 ha 4388
     add  eax,0x00010001
1497 Lrz 4389
     mov  [esp+32],eax
1 ha 4390
     ret
1497 Lrz 4391
.2:				; bits per pixel
381 serge 4392
     movzx eax,byte [ScreenBPP]
1497 Lrz 4393
     mov   [esp+32],eax
1 ha 4394
     ret
1497 Lrz 4395
.3:                             ; bytes per scanline
381 serge 4396
     mov   eax,[BytesPerScanLine]
1497 Lrz 4397
     mov   [esp+32],eax
1 ha 4398
     ret
4399
 
4400
align 4  ;  system functions
4401
 
1055 Galkov 4402
syscall_setpixel:                       ; SetPixel
1 ha 4403
 
1055 Galkov 4404
        mov     eax, ebx
4405
        mov     ebx, ecx
4406
        mov     ecx, edx
4407
        mov     edx, [TASK_BASE]
4408
        add     eax, [edx-twdw+WDATA.box.left]
4409
        add     ebx, [edx-twdw+WDATA.box.top]
4410
        mov     edi, [current_slot]
4411
        add     eax, [edi+APPDATA.wnd_clientbox.left]
4412
        add     ebx, [edi+APPDATA.wnd_clientbox.top]
4413
        xor     edi, edi ; no force
684 diamond 4414
;       mov     edi, 1
1300 serge 4415
        call    [_display.disable_mouse]
1055 Galkov 4416
        jmp     [putpixel]
1 ha 4417
 
4418
align 4
4419
 
1055 Galkov 4420
syscall_writetext:                      ; WriteText
1 ha 4421
 
1055 Galkov 4422
        mov   eax,[TASK_BASE]
4423
        mov   ebp,[eax-twdw+WDATA.box.left]
4424
        push  esi
4425
        mov   esi,[current_slot]
4426
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
4427
        shl   ebp,16
4428
        add   ebp,[eax-twdw+WDATA.box.top]
4429
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
4430
        pop   esi
4431
        add   ebx,ebp
4432
        mov   eax,edi
4433
        xor   edi,edi
4434
        jmp   dtext
1 ha 4435
 
4436
align 4
4437
 
1055 Galkov 4438
syscall_openramdiskfile:                ; OpenRamdiskFile
1 ha 4439
 
1055 Galkov 4440
        mov     eax, ebx
4441
        mov     ebx, ecx
4442
        mov     ecx, edx
4443
        mov     edx, esi
4444
        mov     esi, 12
4445
        call    fileread
4446
        mov     [esp+32], eax
4447
        ret
1 ha 4448
 
4449
align 4
4450
 
1055 Galkov 4451
syscall_drawrect:                       ; DrawRect
1 ha 4452
 
1055 Galkov 4453
        mov     edi, edx ; color + gradient
4454
        and     edi, 0x80FFFFFF
4455
        test    bx, bx  ; x.size
4456
        je      .drectr
4457
        test    cx, cx ; y.size
4458
        je      .drectr
1 ha 4459
 
1055 Galkov 4460
        mov     eax, ebx ; bad idea
4461
        mov     ebx, ecx
1 ha 4462
 
1055 Galkov 4463
        movzx   ecx, ax ; ecx - x.size
4464
        shr     eax, 16 ; eax - x.coord
4465
        movzx   edx, bx ; edx - y.size
4466
        shr     ebx, 16 ; ebx - y.coord
4467
        mov     esi, [current_slot]
1 ha 4468
 
1055 Galkov 4469
        add     eax, [esi + APPDATA.wnd_clientbox.left]
4470
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
4471
        add     ecx, eax
4472
        add     edx, ebx
4473
        jmp     [drawbar]
671 Ghost 4474
.drectr:
1055 Galkov 4475
        ret
1 ha 4476
 
4477
align 4
1055 Galkov 4478
syscall_getscreensize:                  ; GetScreenSize
4479
        mov     ax, [Screen_Max_X]
4480
        shl     eax, 16
4481
        mov     ax, [Screen_Max_Y]
4482
        mov     [esp + 32], eax
4483
        ret
1 ha 4484
 
671 Ghost 4485
align 4
4486
 
1055 Galkov 4487
syscall_cdaudio:                        ; CD
1 ha 4488
 
1290 Lrz 4489
        cmp     ebx, 4
1055 Galkov 4490
        jb      .audio
4491
        jz      .eject
1290 Lrz 4492
        cmp     ebx, 5
1055 Galkov 4493
        jnz     .ret
588 diamond 4494
.load:
1055 Galkov 4495
        call    .reserve
4496
        call    LoadMedium
1290 Lrz 4497
        ;call    .free
4498
		jmp		.free
4499
;        ret
588 diamond 4500
.eject:
1055 Galkov 4501
        call    .reserve
4502
        call    clear_CD_cache
4503
        call    allow_medium_removal
4504
        call    EjectMedium
1290 Lrz 4505
;        call    .free
4506
		jmp		.free
4507
;        ret
588 diamond 4508
.audio:
1 ha 4509
     call  sys_cd_audio
1290 Lrz 4510
     mov   [esp+36-4],eax
588 diamond 4511
.ret:
1 ha 4512
     ret
4513
 
588 diamond 4514
.reserve:
1055 Galkov 4515
        call    reserve_cd
1290 Lrz 4516
        mov     eax, ecx
1055 Galkov 4517
        shr     eax, 1
4518
        and     eax, 1
4519
        inc     eax
4520
        mov     [ChannelNumber], ax
1290 Lrz 4521
        mov     eax, ecx
1055 Galkov 4522
        and     eax, 1
4523
        mov     [DiskNumber], al
4524
        call    reserve_cd_channel
4525
        and     ebx, 3
4526
        inc     ebx
4527
        mov     [cdpos], ebx
4528
        add     ebx, ebx
4529
        mov     cl, 8
4530
        sub     cl, bl
4531
        mov     al, [DRIVE_DATA+1]
4532
        shr     al, cl
4533
        test    al, 2
1290 Lrz 4534
        jz      .free;.err
1055 Galkov 4535
        ret
588 diamond 4536
.free:
1055 Galkov 4537
        call    free_cd_channel
4538
        and     [cd_status], 0
4539
        ret
590 diamond 4540
.err:
1055 Galkov 4541
        call    .free
1290 Lrz 4542
;        pop     eax
1055 Galkov 4543
        ret
588 diamond 4544
 
1 ha 4545
align 4
4546
 
1055 Galkov 4547
syscall_getpixel:                       ; GetPixel
753 serge 4548
     mov   ecx, [Screen_Max_X]
1 ha 4549
     inc   ecx
671 Ghost 4550
     xor   edx, edx
4551
     mov   eax, ebx
1 ha 4552
     div   ecx
671 Ghost 4553
     mov   ebx, edx
4554
     xchg  eax, ebx
4555
     call  dword [GETPIXEL] ; eax - x, ebx - y
4556
     mov   [esp + 32], ecx
1 ha 4557
     ret
4558
 
921 mario79 4559
align 4
1 ha 4560
 
921 mario79 4561
syscall_getarea:
4562
;eax = 36
1055 Galkov 4563
;ebx = pointer to bufer for img BBGGRRBBGGRR...
4564
;ecx = [size x]*65536 + [size y]
4565
;edx = [start x]*65536 + [start y]
921 mario79 4566
     pushad
1055 Galkov 4567
         inc   [mouse_pause]
927 mario79 4568
; Check of use of the hardware cursor.
1300 serge 4569
      cmp  [_display.disable_mouse],__sys_disable_mouse
1055 Galkov 4570
          jne  @f
927 mario79 4571
; Since the test for the coordinates of the mouse should not be used,
4572
; then use the call [disable_mouse] is not possible!
4573
      cmp  dword [MOUSE_VISIBLE],dword 0
4574
      jne  @f
4575
      pushf
4576
      cli
4577
      call draw_mouse_under
4578
      popf
4579
      mov  [MOUSE_VISIBLE],dword 1
4580
@@:
921 mario79 4581
     mov   edi,ebx
4582
     mov   eax,edx
4583
     shr   eax,16
4584
     mov   ebx,edx
4585
     and   ebx,0xffff
939 mario79 4586
     dec   eax
1055 Galkov 4587
           dec   ebx
921 mario79 4588
     ; eax - x, ebx - y
4589
     mov   edx,ecx
1638 serge 4590
 
921 mario79 4591
     shr   ecx,16
4592
     and   edx,0xffff
4593
     mov   esi,ecx
4594
     ; ecx - size x, edx - size y
1638 serge 4595
 
1055 Galkov 4596
         mov   ebp,edx
4597
         dec   ebp
927 mario79 4598
     lea   ebp,[ebp*3]
1638 serge 4599
 
1055 Galkov 4600
         imul  ebp,esi
1638 serge 4601
 
1055 Galkov 4602
         mov   esi,ecx
4603
         dec   esi
4604
         lea   esi,[esi*3]
1638 serge 4605
 
927 mario79 4606
     add   ebp,esi
4607
     add   ebp,edi
4608
 
4609
     add   ebx,edx
1638 serge 4610
 
921 mario79 4611
.start_y:
927 mario79 4612
     push  ecx edx
921 mario79 4613
.start_x:
927 mario79 4614
     push  eax ebx ecx
921 mario79 4615
     add   eax,ecx
927 mario79 4616
 
921 mario79 4617
     call  dword [GETPIXEL] ; eax - x, ebx - y
1638 serge 4618
 
927 mario79 4619
     mov   [ebp],cx
4620
     shr   ecx,16
4621
     mov   [ebp+2],cl
921 mario79 4622
 
1055 Galkov 4623
     pop   ecx ebx eax
927 mario79 4624
     sub   ebp,3
921 mario79 4625
     dec   ecx
4626
     jnz   .start_x
1055 Galkov 4627
         pop   edx ecx
4628
         dec   ebx
921 mario79 4629
     dec   edx
4630
     jnz   .start_y
1055 Galkov 4631
     dec        [mouse_pause]
927 mario79 4632
; Check of use of the hardware cursor.
1300 serge 4633
      cmp  [_display.disable_mouse],__sys_disable_mouse
1055 Galkov 4634
          jne  @f
4635
         call  [draw_pointer]
927 mario79 4636
@@:
921 mario79 4637
     popad
4638
     ret
4639
 
1 ha 4640
align 4
4641
 
1055 Galkov 4642
syscall_drawline:                       ; DrawLine
1 ha 4643
 
1055 Galkov 4644
        mov     edi, [TASK_BASE]
4645
        movzx   eax, word[edi-twdw+WDATA.box.left]
4646
        mov     ebp, eax
4647
        mov     esi, [current_slot]
4648
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
4649
        add     ax, word[esi+APPDATA.wnd_clientbox.left]
4650
        add     ebp,ebx
4651
        shl     eax, 16
4652
        movzx   ebx, word[edi-twdw+WDATA.box.top]
4653
        add     eax, ebp
4654
        mov     ebp, ebx
4655
        add     ebp, [esi+APPDATA.wnd_clientbox.top]
4656
        add     bx, word[esi+APPDATA.wnd_clientbox.top]
4657
        add     ebp, ecx
4658
        shl     ebx, 16
4659
        xor     edi, edi
4660
        add     ebx, ebp
4661
        mov     ecx, edx
4662
        jmp     [draw_line]
1 ha 4663
 
4664
 
742 Rus 4665
 
1 ha 4666
align 4
1055 Galkov 4667
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
1 ha 4668
 
4669
     call  r_f_port_area
1306 Lrz 4670
     mov   [esp+32],eax
1 ha 4671
     ret
4672
 
4673
align 4
1055 Galkov 4674
syscall_threads:                        ; CreateThreads
1369 Lrz 4675
; eax=1 create thread
4676
;
4677
;   ebx=thread start
4678
;   ecx=thread stack value
4679
;
4680
; on return : eax = pid
1 ha 4681
 
1369 Lrz 4682
     call  new_sys_threads
4683
 
4684
     mov   [esp+32],eax
1 ha 4685
     ret
4686
 
4687
align 4
4688
 
4689
stack_driver_stat:
4690
 
1055 Galkov 4691
     call  app_stack_handler            ; Stack status
1 ha 4692
 
4693
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4694
;     call  change_task                 ; between sent packet
4695
 
1369 Lrz 4696
     mov   [esp+32],eax
1 ha 4697
     ret
4698
 
4699
align 4
4700
 
1055 Galkov 4701
socket:                                 ; Socket interface
1 ha 4702
     call  app_socket_handler
4703
 
4704
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4705
;     call  change_task                 ; between sent packet
4706
 
4707
     mov   [esp+36],eax
4708
     mov   [esp+24],ebx
4709
     ret
4710
 
4711
align 4
4712
 
1055 Galkov 4713
read_from_hd:                           ; Read from hd - fn not in use
1 ha 4714
 
379 serge 4715
     mov   edi,[TASK_BASE]
115 poddubny 4716
     add   edi,TASKDATA.mem_start
1 ha 4717
     add   eax,[edi]
4718
     add   ecx,[edi]
4719
     add   edx,[edi]
4720
     call  file_read
4721
 
4722
     mov   [esp+36],eax
4723
     mov   [esp+24],ebx
4724
 
4725
     ret
4726
 
375 Ghost 4727
paleholder:
1055 Galkov 4728
        ret
378 serge 4729
 
757 serge 4730
align 4
4731
set_screen:
1055 Galkov 4732
        cmp eax, [Screen_Max_X]
4733
        jne .set
709 diamond 4734
 
1055 Galkov 4735
        cmp edx, [Screen_Max_Y]
4736
        jne .set
4737
        ret
757 serge 4738
.set:
1055 Galkov 4739
        pushfd
4740
        cli
757 serge 4741
 
1055 Galkov 4742
        mov [Screen_Max_X], eax
4743
        mov [Screen_Max_Y], edx
1300 serge 4744
        mov [BytesPerScanLine], ecx
757 serge 4745
 
1055 Galkov 4746
        mov [screen_workarea.right],eax
4747
        mov [screen_workarea.bottom], edx
1300 serge 4748
 
1055 Galkov 4749
        push ebx
4750
        push esi
4751
        push edi
1300 serge 4752
 
4753
        pushad
4754
 
4755
        stdcall kernel_free, [_WinMapAddress]
4756
 
4757
        mov eax, [_display.width]
4758
        mul [_display.height]
4759
        mov [_WinMapSize], eax
4760
 
4761
        stdcall kernel_alloc, eax
4762
        mov [_WinMapAddress], eax
4763
        test eax, eax
4764
        jz .epic_fail
4765
 
4766
        popad
4767
 
1055 Galkov 4768
        call    repos_windows
1300 serge 4769
        xor eax, eax
4770
        xor ebx, ebx
1055 Galkov 4771
        mov     ecx, [Screen_Max_X]
4772
        mov     edx, [Screen_Max_Y]
4773
        call    calculatescreen
4774
        pop edi
4775
        pop esi
4776
        pop ebx
757 serge 4777
 
1055 Galkov 4778
        popfd
4779
        ret
757 serge 4780
 
1300 serge 4781
.epic_fail:
4782
        hlt                     ; Houston, we've had a problem
4783
 
76 mario79 4784
; --------------- APM ---------------------
1330 Lrz 4785
uglobal
4786
apm_entry	dp	0
4787
apm_vf		dd	0
4788
endg
4789
 
1 ha 4790
align 4
76 mario79 4791
sys_apm:
1330 Lrz 4792
	xor	eax,eax
4793
	cmp	word [apm_vf], ax	; Check APM BIOS enable
4794
	jne	@f
4795
	inc	eax
4796
	or	dword [esp + 44], eax	; error
4797
	add	eax,7
4798
	mov	dword [esp + 32], eax   ; 32-bit protected-mode interface not supported
4799
	ret
164 serge 4800
 
465 serge 4801
@@:
1330 Lrz 4802
;	xchg    eax, ecx
4803
;	xchg    ebx, ecx
164 serge 4804
 
1330 Lrz 4805
	cmp	dx, 3
4806
	ja	@f
4807
	and	[esp + 44], byte 0xfe    ; emulate func 0..3 as func 0
4808
	mov	eax,[apm_vf]
4809
	mov	[esp + 32], eax
4810
	shr	eax, 16
4811
	mov	[esp + 28], eax
4812
	ret
78 diamond 4813
 
465 serge 4814
@@:
4815
 
1330 Lrz 4816
	mov	esi,[master_tab+(OS_BASE shr 20)]
4817
	xchg	[master_tab], esi
4818
	push	esi
4819
	mov 	edi, cr3
4820
	mov 	cr3, edi		;flush TLB
465 serge 4821
 
1330 Lrz 4822
	call    pword [apm_entry]	;call APM BIOS
465 serge 4823
 
1330 Lrz 4824
	xchg 	eax, [esp]
4825
	mov 	[master_tab], eax
4826
	mov 	eax, cr3
4827
	mov 	cr3, eax
4828
	pop eax
465 serge 4829
 
1330 Lrz 4830
	mov	[esp + 4 ], edi
4831
	mov	[esp + 8], esi
4832
	mov	[esp + 20], ebx
4833
	mov	[esp + 24], edx
4834
	mov	[esp + 28], ecx
4835
	mov	[esp + 32], eax
4836
	setc	al
4837
	and	[esp + 44], byte 0xfe
4838
	or	[esp + 44], al
4839
	ret
76 mario79 4840
; -----------------------------------------
1 ha 4841
 
76 mario79 4842
align 4
4843
 
1055 Galkov 4844
undefined_syscall:                      ; Undefined system call
671 Ghost 4845
     mov   [esp + 32], dword -1
1 ha 4846
     ret
4847
 
465 serge 4848
align 4
1055 Galkov 4849
system_shutdown:          ; shut down the system
1 ha 4850
 
1055 Galkov 4851
           cmp byte [BOOT_VAR+0x9030], 1
4852
           jne @F
4853
           ret
465 serge 4854
@@:
1055 Galkov 4855
           call stop_all_services
4856
           push 3                ; stop playing cd
4857
           pop  eax
4858
           call sys_cd_audio
1 ha 4859
 
465 serge 4860
yes_shutdown_param:
1055 Galkov 4861
           cli
1 ha 4862
 
2010 serge 4863
if ~ defined extended_primary_loader
1055 Galkov 4864
           mov  eax, kernel_file ; load kernel.mnt to 0x7000:0
4865
           push 12
4866
           pop  esi
4867
           xor  ebx,ebx
4868
           or   ecx,-1
4869
           mov  edx, OS_BASE+0x70000
4870
           call fileread
1 ha 4871
 
1055 Galkov 4872
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
4873
           mov  edi,OS_BASE+0x40000
4874
           mov  ecx,1000
4875
           rep  movsb
2010 serge 4876
end if
1 ha 4877
 
2010 serge 4878
           mov  esi, BOOT_VAR    ; restore 0x0 - 0xffff
1055 Galkov 4879
           mov  edi, OS_BASE
4880
           mov  ecx,0x10000/4
4881
           cld
4882
           rep movsd
1 ha 4883
 
1055 Galkov 4884
           call restorefatchain
1 ha 4885
 
1638 serge 4886
	   call IRQ_mask_all
1 ha 4887
 
1085 diamond 4888
if 0
1055 Galkov 4889
           mov  word [OS_BASE+0x467+0],pr_mode_exit
4890
           mov  word [OS_BASE+0x467+2],0x1000
1 ha 4891
 
1055 Galkov 4892
           mov  al,0x0F
4893
           out  0x70,al
4894
           mov  al,0x05
4895
           out  0x71,al
1 ha 4896
 
1055 Galkov 4897
           mov  al,0xFE
4898
           out  0x64,al
709 diamond 4899
 
1055 Galkov 4900
           hlt
1085 diamond 4901
           jmp $-1
1 ha 4902
 
709 diamond 4903
else
1055 Galkov 4904
        cmp     byte [OS_BASE + 0x9030], 2
4905
        jnz     no_acpi_power_off
1 ha 4906
 
709 diamond 4907
; scan for RSDP
4908
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
1055 Galkov 4909
        movzx   eax, word [OS_BASE + 0x40E]
4910
        shl     eax, 4
4911
        jz      @f
4912
        mov     ecx, 1024/16
4913
        call    scan_rsdp
4914
        jnc     .rsdp_found
709 diamond 4915
@@:
4916
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
1055 Galkov 4917
        mov     eax, 0xE0000
4918
        mov     ecx, 0x2000
4919
        call    scan_rsdp
4920
        jc      no_acpi_power_off
709 diamond 4921
.rsdp_found:
1055 Galkov 4922
        mov     esi, [eax+16]   ; esi contains physical address of the RSDT
4923
        mov     ebp, [ipc_tmp]
4924
        stdcall map_page, ebp, esi, PG_MAP
4925
        lea     eax, [esi+1000h]
4926
        lea     edx, [ebp+1000h]
4927
        stdcall map_page, edx, eax, PG_MAP
4928
        and     esi, 0xFFF
4929
        add     esi, ebp
4930
        cmp     dword [esi], 'RSDT'
4931
        jnz     no_acpi_power_off
4932
        mov     ecx, [esi+4]
4933
        sub     ecx, 24h
4934
        jbe     no_acpi_power_off
4935
        shr     ecx, 2
4936
        add     esi, 24h
709 diamond 4937
.scan_fadt:
1055 Galkov 4938
        lodsd
4939
        mov     ebx, eax
4940
        lea     eax, [ebp+2000h]
4941
        stdcall map_page, eax, ebx, PG_MAP
4942
        lea     eax, [ebp+3000h]
4943
        add     ebx, 0x1000
4944
        stdcall map_page, eax, ebx, PG_MAP
4945
        and     ebx, 0xFFF
4946
        lea     ebx, [ebx+ebp+2000h]
4947
        cmp     dword [ebx], 'FACP'
4948
        jz      .fadt_found
4949
        loop    .scan_fadt
4950
        jmp     no_acpi_power_off
709 diamond 4951
.fadt_found:
4952
; ebx is linear address of FADT
1085 diamond 4953
        mov     edi, [ebx+40] ; physical address of the DSDT
4954
        lea     eax, [ebp+4000h]
4955
        stdcall map_page, eax, edi, PG_MAP
4956
        lea     eax, [ebp+5000h]
4957
        lea     esi, [edi+0x1000]
4958
        stdcall map_page, eax, esi, PG_MAP
4959
        and     esi, 0xFFF
4960
        sub     edi, esi
4961
        cmp     dword [esi+ebp+4000h], 'DSDT'
4962
        jnz     no_acpi_power_off
4963
        mov     eax, [esi+ebp+4004h] ; DSDT length
4964
        sub     eax, 36+4
4965
        jbe     no_acpi_power_off
4966
        add     esi, 36
4967
.scan_dsdt:
4968
        cmp     dword [esi+ebp+4000h], '_S5_'
4969
        jnz     .scan_dsdt_cont
4970
        cmp     byte [esi+ebp+4000h+4], 12h ; DefPackage opcode
4971
        jnz     .scan_dsdt_cont
4972
        mov     dl, [esi+ebp+4000h+6]
4973
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
4974
                      ; ...in theory; in practice, VirtualBox has 2 bytes
4975
        ja      .scan_dsdt_cont
4976
        cmp     dl, 1
4977
        jb      .scan_dsdt_cont
4978
        lea     esi, [esi+ebp+4000h+7]
4979
        xor     ecx, ecx
4980
        cmp     byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx
4981
        jz      @f
4982
        cmp     byte [esi], 0xA
4983
        jnz     no_acpi_power_off
4984
        inc     esi
4985
        mov     cl, [esi]
4986
@@:
4987
        inc     esi
4988
        cmp     dl, 2
4989
        jb      @f
4990
        cmp     byte [esi], 0
4991
        jz      @f
4992
        cmp     byte [esi], 0xA
4993
        jnz     no_acpi_power_off
4994
        inc     esi
4995
        mov     ch, [esi]
4996
@@:
4997
        jmp     do_acpi_power_off
4998
.scan_dsdt_cont:
4999
        inc     esi
5000
        cmp     esi, 0x1000
5001
        jb      @f
5002
        sub     esi, 0x1000
5003
        add     edi, 0x1000
5004
        push    eax
5005
        lea     eax, [ebp+4000h]
5006
        stdcall map_page, eax, edi, PG_MAP
5007
        push    PG_MAP
5008
        lea     eax, [edi+1000h]
5009
        push    eax
5010
        lea     eax, [ebp+5000h]
5011
        push    eax
5012
        stdcall map_page
5013
        pop     eax
5014
@@:
5015
        dec     eax
5016
        jnz     .scan_dsdt
5017
        jmp     no_acpi_power_off
5018
do_acpi_power_off:
1055 Galkov 5019
        mov     edx, [ebx+48]
5020
        test    edx, edx
5021
        jz      .nosmi
5022
        mov     al, [ebx+52]
5023
        out     dx, al
5024
        mov     edx, [ebx+64]
709 diamond 5025
@@:
1055 Galkov 5026
        in      ax, dx
5027
        test    al, 1
5028
        jz      @b
709 diamond 5029
.nosmi:
1085 diamond 5030
        and     cx, 0x0707
5031
        shl     cx, 2
5032
        or      cx, 0x2020
1055 Galkov 5033
        mov     edx, [ebx+64]
5034
        in      ax, dx
5035
        and     ax, 203h
1085 diamond 5036
        or      ah, cl
1055 Galkov 5037
        out     dx, ax
5038
        mov     edx, [ebx+68]
5039
        test    edx, edx
5040
        jz      @f
5041
        in      ax, dx
5042
        and     ax, 203h
1085 diamond 5043
        or      ah, ch
1055 Galkov 5044
        out     dx, ax
709 diamond 5045
@@:
1055 Galkov 5046
        jmp     $
709 diamond 5047
 
5048
 
5049
no_acpi_power_off:
1055 Galkov 5050
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5051
           mov  word [OS_BASE+0x467+2],0x1000
709 diamond 5052
 
1055 Galkov 5053
           mov  al,0x0F
5054
           out  0x70,al
5055
           mov  al,0x05
5056
           out  0x71,al
709 diamond 5057
 
1055 Galkov 5058
           mov  al,0xFE
5059
           out  0x64,al
709 diamond 5060
 
1055 Galkov 5061
           hlt
1085 diamond 5062
           jmp $-1
709 diamond 5063
 
5064
scan_rsdp:
1055 Galkov 5065
        add     eax, OS_BASE
709 diamond 5066
.s:
1055 Galkov 5067
        cmp     dword [eax], 'RSD '
5068
        jnz     .n
5069
        cmp     dword [eax+4], 'PTR '
5070
        jnz     .n
5071
        xor     edx, edx
5072
        xor     esi, esi
709 diamond 5073
@@:
1055 Galkov 5074
        add     dl, [eax+esi]
5075
        inc     esi
5076
        cmp     esi, 20
5077
        jnz     @b
5078
        test    dl, dl
5079
        jz      .ok
709 diamond 5080
.n:
1055 Galkov 5081
        add     eax, 10h
5082
        loop    .s
5083
        stc
709 diamond 5084
.ok:
1055 Galkov 5085
        ret
709 diamond 5086
end if
5087
 
465 serge 5088
include "data32.inc"
1 ha 5089
 
465 serge 5090
__REV__ = __REV
1 ha 5091
 
5092
uglobals_size = $ - endofcode
41 mikedld 5093
diff16 "end of kernel code",0,$