Subversion Repositories Kolibri OS

Rev

Rev 4265 | Rev 4288 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
3908 Serge 3
;; Copyright (C) KolibriOS team 2004-2013. 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
 
3500 Serge 69
format binary as "mnt"
70
 
426 mikedld 71
include 'macros.inc'
2434 Serge 72
include 'struct.inc'
426 mikedld 73
 
425 victor 74
$Revision: 4287 $
426 mikedld 75
 
593 mikedld 76
 
1055 Galkov 77
USE_COM_IRQ     equ 1      ; make irq 3 and irq 4 available for PCI devices
3626 Serge 78
VESA_1_2_VIDEO  equ 0      ; enable vesa 1.2 bank switch functions
566 serge 79
 
1043 hidnplayr 80
; Enabling the next line will enable serial output console
3589 Serge 81
;debug_com_base  equ 0x3f8  ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used
1043 hidnplayr 82
 
164 serge 83
include "proc32.inc"
7 me_root 84
include "kglobals.inc"
1 ha 85
include "lang.inc"
3555 Serge 86
include "encoding.inc"
1 ha 87
 
164 serge 88
include "const.inc"
3908 Serge 89
 
90
iglobal
91
; The following variable, if equal to 1, duplicates debug output to the screen.
92
debug_direct_print db 0
93
; Start the first app (LAUNCHER) after kernel is loaded? (1=yes, 2 or 0=no)
94
launcher_start db 1
95
endg
96
 
1055 Galkov 97
max_processes    equ   255
98
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
1 ha 99
 
1055 Galkov 100
os_stack       equ  (os_data_l-gdts)    ; GDTs
465 serge 101
os_code        equ  (os_code_l-gdts)
102
graph_data     equ  (3+graph_data_l-gdts)
1055 Galkov 103
tss0           equ  (tss0_l-gdts)
465 serge 104
app_code       equ  (3+app_code_l-gdts)
105
app_data       equ  (3+app_data_l-gdts)
1220 serge 106
app_tls        equ  (3+tls_data_l-gdts)
586 serge 107
pci_code_sel   equ  (pci_code_32-gdts)
108
pci_data_sel   equ  (pci_data_32-gdts)
1 ha 109
 
110
 
111
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112
;;
113
;;   Included files:
114
;;
115
;;   Kernel16.inc
116
;;    - Booteng.inc   English text for bootup
117
;;    - Bootcode.inc  Hardware setup
118
;;    - Pci16.inc     PCI functions
119
;;
120
;;   Kernel32.inc
121
;;    - Sys32.inc     Process management
122
;;    - Shutdown.inc  Shutdown and restart
123
;;    - Fat32.inc     Read / write hd
124
;;    - Vesa12.inc    Vesa 1.2 driver
125
;;    - Vesa20.inc    Vesa 2.0 driver
126
;;    - Vga.inc       VGA driver
127
;;    - Stack.inc     Network interface
128
;;    - Mouse.inc     Mouse pointer
129
;;    - Scincode.inc  Window skinning
130
;;    - Pci32.inc     PCI functions
131
;;
132
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
133
 
134
 
135
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136
;;                                                                      ;;
137
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
138
;;                                                                      ;;
139
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
140
 
141
use16
1055 Galkov 142
                  org   0x0
2434 Serge 143
        jmp     start_of_code
1 ha 144
 
3500 Serge 145
if lang eq sp
146
include "kernelsp.inc"  ; spanish kernel messages
4265 Serge 147
else if lang eq et
148
version db    'Kolibri OS  versioon 0.7.7.0+    ',13,10,13,10,0
3500 Serge 149
else
1324 Lrz 150
version db    'Kolibri OS  version 0.7.7.0+     ',13,10,13,10,0
3500 Serge 151
end if
1 ha 152
 
465 serge 153
include "boot/bootstr.inc"     ; language-independent boot messages
1 ha 154
include "boot/preboot.inc"
155
 
3500 Serge 156
if lang eq ge
157
include "boot/bootge.inc"     ; german system boot messages
158
else if lang eq sp
159
include "boot/bootsp.inc"     ; spanish system boot messages
465 serge 160
else if lang eq ru
161
include "boot/bootru.inc"      ; russian system boot messages
1055 Galkov 162
include "boot/ru.inc"          ; Russian font
465 serge 163
else if lang eq et
164
include "boot/bootet.inc"      ; estonian system boot messages
1055 Galkov 165
include "boot/et.inc"          ; Estonian font
465 serge 166
else
3500 Serge 167
include "boot/booten.inc"      ; english system boot messages
465 serge 168
end if
1 ha 169
 
465 serge 170
include "boot/bootcode.inc"    ; 16 bit system boot code
171
include "bus/pci/pci16.inc"
709 diamond 172
include "detect/biosdisk.inc"
1 ha 173
 
174
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
175
;;                                                                      ;;
176
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
177
;;                                                                      ;;
178
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
179
 
180
 
181
; CR0 Flags - Protected mode and Paging
182
 
2434 Serge 183
        mov     ecx, CR0_PE
1 ha 184
 
185
; Enabling 32 bit protected mode
186
 
1055 Galkov 187
        sidt    [cs:old_ints_h]
1 ha 188
 
1055 Galkov 189
        cli                             ; disable all irqs
190
        cld
2434 Serge 191
        mov     al, 255                 ; mask all irqs
192
        out     0xa1, al
193
        out     0x21, al
194
   l.5:
195
        in      al, 0x64                ; Enable A20
1055 Galkov 196
        test    al, 2
197
        jnz     l.5
198
        mov     al, 0xD1
199
        out     0x64, al
2434 Serge 200
   l.6:
201
        in      al, 0x64
1055 Galkov 202
        test    al, 2
203
        jnz     l.6
204
        mov     al, 0xDF
205
        out     0x60, al
2434 Serge 206
   l.7:
207
        in      al, 0x64
1055 Galkov 208
        test    al, 2
209
        jnz     l.7
210
        mov     al, 0xFF
211
        out     0x64, al
465 serge 212
 
1055 Galkov 213
        lgdt    [cs:tmp_gdt]            ; Load GDT
214
        mov     eax, cr0                ; protected mode
215
        or      eax, ecx
216
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
217
        mov     cr0, eax
218
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
1 ha 219
 
465 serge 220
align 8
221
tmp_gdt:
1 ha 222
 
1055 Galkov 223
        dw     23
224
        dd     tmp_gdt+0x10000
225
        dw     0
183 diamond 226
 
1055 Galkov 227
        dw     0xffff
228
        dw     0x0000
229
        db     0x00
230
        dw     11011111b *256 +10011010b
231
        db     0x00
375 Ghost 232
 
1055 Galkov 233
        dw     0xffff
234
        dw     0x0000
235
        db     0x00
236
        dw     11011111b *256 +10010010b
237
        db     0x00
1 ha 238
 
3500 Serge 239
include "data16.inc"
1 ha 240
 
3626 Serge 241
if ~ lang eq sp
242
diff16 "end of bootcode",0,$+0x10000
243
end if
244
 
465 serge 245
use32
246
org $+0x10000
1 ha 247
 
465 serge 248
align 4
249
B32:
2434 Serge 250
        mov     ax, os_stack       ; Selector for os
251
        mov     ds, ax
252
        mov     es, ax
253
        mov     fs, ax
254
        mov     gs, ax
255
        mov     ss, ax
256
        mov     esp, 0x006CC00       ; Set stack
1 ha 257
 
465 serge 258
; CLEAR 0x280000 - HEAP_BASE
1 ha 259
 
2434 Serge 260
        xor     eax, eax
261
        mov     edi, CLEAN_ZONE
262
        mov     ecx, (HEAP_BASE-OS_BASE-CLEAN_ZONE) / 4
263
        cld
264
        rep stosd
1 ha 265
 
465 serge 266
; CLEAR KERNEL UNDEFINED GLOBALS
2434 Serge 267
        mov     edi, endofcode-OS_BASE
268
        mov     ecx, 0x90000
269
        sub     ecx, edi
270
        shr     ecx, 2
271
        rep stosd
1 ha 272
 
465 serge 273
; SAVE & CLEAR 0-0xffff
1 ha 274
 
2434 Serge 275
        mov     edi, 0x1000
3908 Serge 276
        mov     ecx, 0x8000 / 4
2434 Serge 277
        rep stosd
3908 Serge 278
        mov     edi, 0xa000
279
        mov     ecx, 0x6000 / 4
280
        rep stosd
429 serge 281
 
2434 Serge 282
        call    test_cpu
283
        bts     [cpu_caps-OS_BASE], CAPS_TSC    ;force use rdtsc
424 spraid 284
 
2434 Serge 285
        call    check_acpi
286
        call    init_BIOS32
465 serge 287
; MEMORY MODEL
2434 Serge 288
        call    mem_test
289
        call    init_mem
290
        call    init_page_map
1 ha 291
 
465 serge 292
; ENABLE PAGING
1 ha 293
 
2434 Serge 294
        mov     eax, sys_pgdir-OS_BASE
295
        mov     cr3, eax
1 ha 296
 
2434 Serge 297
        mov     eax, cr0
298
        or      eax, CR0_PG+CR0_WP
299
        mov     cr0, eax
1 ha 300
 
2434 Serge 301
        lgdt    [gdts]
302
        jmp     pword os_code:high_code
1 ha 303
 
513 serge 304
align 4
1055 Galkov 305
bios32_entry    dd ?
306
tmp_page_tabs   dd ?
586 serge 307
 
3500 Serge 308
use16
309
org $-0x10000
310
include "boot/shutdown.inc" ; shutdown or restart
311
org $+0x10000
312
use32
498 diamond 313
 
3908 Serge 314
__DEBUG__ fix 1
465 serge 315
__DEBUG_LEVEL__ fix 1
316
include 'init.inc'
380 serge 317
 
465 serge 318
org OS_BASE+$
1 ha 319
 
2465 Serge 320
include 'fdo.inc'
321
 
465 serge 322
align 4
323
high_code:
2434 Serge 324
        mov     ax, os_stack
325
        mov     bx, app_data
326
        mov     cx, app_tls
327
        mov     ss, ax
328
        add     esp, OS_BASE
1 ha 329
 
2434 Serge 330
        mov     ds, bx
331
        mov     es, bx
332
        mov     fs, cx
333
        mov     gs, bx
1 ha 334
 
2434 Serge 335
        bt      [cpu_caps], CAPS_PGE
336
        jnc     @F
1 ha 337
 
2434 Serge 338
        or      dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL
519 serge 339
 
2434 Serge 340
        mov     ebx, cr4
341
        or      ebx, CR4_PGE
342
        mov     cr4, ebx
519 serge 343
@@:
3500 Serge 344
        xor     eax, eax
345
        mov     dword [sys_pgdir], eax
346
        mov     dword [sys_pgdir+4], eax
519 serge 347
 
3500 Serge 348
        mov     eax, cr3
349
        mov     cr3, eax          ; flush TLB
465 serge 350
 
2434 Serge 351
        mov     ecx, pg_data.mutex
352
        call    mutex_init
2130 serge 353
 
2434 Serge 354
        mov     ecx, disk_list_mutex
355
        call    mutex_init
2130 serge 356
 
2987 Serge 357
        mov     ecx, keyboard_list_mutex
358
        call    mutex_init
359
 
360
        mov     ecx, unpack_mutex
361
        call    mutex_init
362
 
3555 Serge 363
        mov     ecx, application_table_mutex
364
        call    mutex_init
365
 
3908 Serge 366
        mov     ecx, ide_mutex
367
        call    mutex_init
368
        mov     ecx, ide_channel1_mutex
369
        call    mutex_init
370
        mov     ecx, ide_channel2_mutex
371
        call    mutex_init
372
;-----------------------------------------------------------------------------
1 ha 373
; SAVE REAL MODE VARIABLES
3908 Serge 374
;-----------------------------------------------------------------------------
375
save_variables_IDE_controller:
3725 Serge 376
        xor     eax, eax
3908 Serge 377
        mov     ax, [BOOT_VARS + BOOT_IDE_INTERR_16]
378
        mov     [IDE_Interrupt], ax
379
;--------------------------------------
380
        mov     ax, [BOOT_VARS + BOOT_IDE_PI_16]
3725 Serge 381
        mov     [IDEContrProgrammingInterface], ax
3908 Serge 382
;--------------------------------------
383
        mov     ax, [BOOT_VARS + BOOT_IDE_BASE_ADDR]
1055 Galkov 384
        mov     [IDEContrRegsBaseAddr], ax
3908 Serge 385
;--------------------------------------
386
        mov     ax, [BOOT_VARS + BOOT_IDE_BAR0_16]
3725 Serge 387
        cmp     ax, 0
388
        je      @f
389
        cmp     ax, 1
3908 Serge 390
        jne     .no_PATA_BAR0
391
@@:
392
        mov     ax, 0x1F0
393
        jmp     @f
394
.no_PATA_BAR0:
395
        and     ax, 0xFFFC
396
@@:
3725 Serge 397
        mov     [StandardATABases], ax
398
        mov     [hd_address_table], eax
399
        mov     [hd_address_table+8], eax
3908 Serge 400
        mov     [IDE_BAR0_val], ax
401
;--------------------------------------
402
        mov     ax, [BOOT_VARS + BOOT_IDE_BAR1_16]
403
        cmp     ax, 0
404
        je      @f
405
        cmp     ax, 1
406
        jne     .no_PATA_BAR1
3725 Serge 407
@@:
3908 Serge 408
        mov     ax, 0x3F4
409
        jmp     @f
410
.no_PATA_BAR1:
411
        and     ax, 0xFFFC
412
@@:
3725 Serge 413
        mov     [IDE_BAR1_val], ax
3908 Serge 414
;--------------------------------------
415
        mov     ax, [BOOT_VARS + BOOT_IDE_BAR2_16]
3725 Serge 416
        cmp     ax, 0
417
        je      @f
418
        cmp     ax, 1
3908 Serge 419
        jne     .no_PATA_BAR2
420
@@:
421
        mov     ax, 0x170
422
        jmp     @f
423
.no_PATA_BAR2:
424
        and     ax, 0xFFFC
425
@@:
3725 Serge 426
        mov     [StandardATABases+2], ax
427
        mov     [hd_address_table+16], eax
428
        mov     [hd_address_table+24], eax
3908 Serge 429
        mov     [IDE_BAR2_val], ax
430
;--------------------------------------
431
        mov     ax, [BOOT_VARS + BOOT_IDE_BAR3_16]
432
        cmp     ax, 0
433
        je      @f
434
        cmp     ax, 1
435
        jne     .no_PATA_BAR3
3725 Serge 436
@@:
3908 Serge 437
        mov     ax, 0x374
438
        jmp     @f
439
.no_PATA_BAR3:
440
        and     ax, 0xFFFC
441
@@:
3725 Serge 442
        mov     [IDE_BAR3_val], ax
443
 
76 mario79 444
; --------------- APM ---------------------
465 serge 445
 
446
; init selectors
3908 Serge 447
        mov     ebx, [BOOT_VARS+BOOT_APM_ENTRY]        ; offset of APM entry point
448
        movzx   eax, word [BOOT_VARS+BOOT_APM_CODE_32] ; real-mode segment base address of
449
                                                                                ; protected-mode 32-bit code segment
450
        movzx   ecx, word [BOOT_VARS+BOOT_APM_CODE_16]; real-mode segment base address of
451
                                                                                ; protected-mode 16-bit code segment
452
        movzx   edx, word [BOOT_VARS+BOOT_APM_DATA_16]; real-mode segment base address of
2434 Serge 453
                                                                                ; protected-mode 16-bit data segment
465 serge 454
 
2434 Serge 455
        shl     eax, 4
456
        mov     [dword apm_code_32 + 2], ax
457
        shr     eax, 16
458
        mov     [dword apm_code_32 + 4], al
465 serge 459
 
2434 Serge 460
        shl     ecx, 4
461
        mov     [dword apm_code_16 + 2], cx
462
        shr     ecx, 16
463
        mov     [dword apm_code_16 + 4], cl
465 serge 464
 
2434 Serge 465
        shl     edx, 4
466
        mov     [dword apm_data_16 + 2], dx
467
        shr     edx, 16
468
        mov     [dword apm_data_16 + 4], dl
465 serge 469
 
2434 Serge 470
        mov     dword[apm_entry], ebx
471
        mov     word [apm_entry + 4], apm_code_32 - gdts
76 mario79 472
 
3908 Serge 473
        mov     eax, [BOOT_VARS + BOOT_APM_VERSION] ; version & flags
2434 Serge 474
        mov     [apm_vf], eax
76 mario79 475
; -----------------------------------------
3908 Serge 476
        mov     al, [BOOT_VARS+BOOT_DMA]            ; DMA access
2434 Serge 477
        mov     [allow_dma_access], al
3908 Serge 478
        movzx   eax, byte [BOOT_VARS+BOOT_BPP]      ; bpp
2434 Serge 479
        mov     [_display.bpp], eax
480
        mov     [_display.vrefresh], 60
3908 Serge 481
        mov     al, [BOOT_VARS+BOOT_DEBUG_PRINT]    ; If nonzero, duplicates debug output to the screen
482
        mov     [debug_direct_print], al
483
        mov     al, [BOOT_VARS+BOOT_LAUNCHER_START] ; Start the first app (LAUNCHER) after kernel is loaded?
484
        mov     [launcher_start], al
485
        movzx   eax, word [BOOT_VARS+BOOT_X_RES]; X max
2434 Serge 486
        mov     [_display.width], eax
2987 Serge 487
        mov     [display_width_standard], eax
2434 Serge 488
        dec     eax
489
        mov     [Screen_Max_X], eax
490
        mov     [screen_workarea.right], eax
3908 Serge 491
        movzx   eax, word [BOOT_VARS+BOOT_Y_RES]; Y max
2434 Serge 492
        mov     [_display.height], eax
2987 Serge 493
        mov     [display_height_standard], eax
2434 Serge 494
        dec     eax
495
        mov     [Screen_Max_Y], eax
496
        mov     [screen_workarea.bottom], eax
3908 Serge 497
        movzx   eax, word [BOOT_VARS+BOOT_VESA_MODE] ; screen mode
3626 Serge 498
        mov     dword [SCR_MODE], eax
3908 Serge 499
;        mov     eax, [BOOT_VAR+0x9014]             ; Vesa 1.2 bnk sw add
3589 Serge 500
;        mov     [BANK_SWITCH], eax
3626 Serge 501
        mov     eax, 640 *4                         ; Bytes PerScanLine
3908 Serge 502
        cmp     [SCR_MODE], word 0x13               ; 320x200
2434 Serge 503
        je      @f
3908 Serge 504
        cmp     [SCR_MODE], word 0x12               ; VGA 640x480
2434 Serge 505
        je      @f
3908 Serge 506
        movzx   eax, word[BOOT_VARS+BOOT_PITCH]      ; for other modes
3626 Serge 507
@@:
2434 Serge 508
        mov     [_display.pitch], eax
509
        mov     eax, [_display.width]
510
        mul     [_display.height]
511
        mov     [_WinMapSize], eax
1300 serge 512
 
2439 Serge 513
        call    calculate_fast_getting_offset_for_WinMapAddress
2987 Serge 514
; for Qemu or non standart video cards
3232 Serge 515
; Unfortunately [BytesPerScanLine] does not always
2987 Serge 516
;                             equal to [_display.width] * [ScreenBPP] / 8
517
        call    calculate_fast_getting_offset_for_LFB
2439 Serge 518
 
3908 Serge 519
        mov     esi, BOOT_VARS+0x9080
1055 Galkov 520
        movzx   ecx, byte [esi-1]
521
        mov     [NumBiosDisks], ecx
522
        mov     edi, BiosDisksData
2434 Serge 523
        rep movsd
1 ha 524
 
525
; GRAPHICS ADDRESSES
526
 
3908 Serge 527
        mov     eax, [BOOT_VARS+BOOT_LFB]
2434 Serge 528
        mov     [LFBAddress], eax
1 ha 529
 
2434 Serge 530
        cmp     [SCR_MODE], word 0100000000000000b
1055 Galkov 531
        jge     setvesa20
2434 Serge 532
        cmp     [SCR_MODE], word 0x13  ; EGA 320*200 256 colors
1055 Galkov 533
        je      v20ga32
534
        jmp     v20ga24
2439 Serge 535
 
2434 Serge 536
setvesa20:
537
        mov     [PUTPIXEL], dword Vesa20_putpixel24 ; Vesa 2.0
538
        mov     [GETPIXEL], dword Vesa20_getpixel24
3555 Serge 539
        cmp     byte [_display.bpp], 24
1055 Galkov 540
        jz      v20ga24
2434 Serge 541
v20ga32:
542
        mov     [PUTPIXEL], dword Vesa20_putpixel32
543
        mov     [GETPIXEL], dword Vesa20_getpixel32
544
        jmp     no_mode_0x12
545
v20ga24:
546
        cmp     [SCR_MODE], word 0x12               ; 16 C VGA 640x480
1055 Galkov 547
        jne     no_mode_0x12
2434 Serge 548
        mov     [PUTPIXEL], dword VGA_putpixel
549
        mov     [GETPIXEL], dword Vesa20_getpixel32
550
no_mode_0x12:
1 ha 551
 
2987 Serge 552
        mov     [MOUSE_PICTURE], dword mousepointer
553
        mov     [_display.check_mouse], check_mouse_area_for_putpixel
554
        mov     [_display.check_m_pixel], check_mouse_area_for_getpixel
555
 
375 Ghost 556
; -------- Fast System Call init ----------
378 serge 557
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
2434 Serge 558
        bt      [cpu_caps], CAPS_SEP
559
        jnc     .SEnP  ; SysEnter not Present
560
        xor     edx, edx
561
        mov     ecx, MSR_SYSENTER_CS
562
        mov     eax, os_code
563
        wrmsr
564
        mov     ecx, MSR_SYSENTER_ESP
434 diamond 565
;           mov eax, sysenter_stack ; Check it
2434 Serge 566
        xor     eax, eax
567
        wrmsr
568
        mov     ecx, MSR_SYSENTER_EIP
569
        mov     eax, sysenter_entry
570
        wrmsr
375 Ghost 571
.SEnP:
378 serge 572
; AMD SYSCALL/SYSRET
2434 Serge 573
        cmp     byte[cpu_vendor], 'A'
574
        jne     .noSYSCALL
575
        mov     eax, 0x80000001
576
        cpuid
577
        test    edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
578
        jz      .noSYSCALL
579
        mov     ecx, MSR_AMD_EFER
580
        rdmsr
581
        or      eax, 1 ; bit_0 - System Call Extension (SCE)
582
        wrmsr
164 serge 583
 
1055 Galkov 584
        ; !!!! It`s dirty hack, fix it !!!
585
        ; Bits of EDX :
3555 Serge 586
        ; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
1055 Galkov 587
        ;  and the contents of this field, plus 8, are copied into the SS register.
3555 Serge 588
        ; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
1055 Galkov 589
        ;  and the contents of this field, plus 8, are copied into the SS register.
375 Ghost 590
 
1055 Galkov 591
        ; mov   edx, (os_code + 16) * 65536 + os_code
2434 Serge 592
        mov     edx, 0x1B0008
375 Ghost 593
 
2434 Serge 594
        mov     eax, syscall_entry
595
        mov     ecx, MSR_AMD_STAR
596
        wrmsr
375 Ghost 597
.noSYSCALL:
598
; -----------------------------------------
1310 diamond 599
        stdcall alloc_page
600
        stdcall map_page, tss-0xF80, eax, PG_SW
601
        stdcall alloc_page
602
        stdcall map_page, tss+0x80, eax, PG_SW
603
        stdcall alloc_page
604
        stdcall map_page, tss+0x1080, eax, PG_SW
375 Ghost 605
 
465 serge 606
; LOAD IDT
378 serge 607
 
2434 Serge 608
        call    build_interrupt_table ;lidt is executed
1056 Galkov 609
          ;lidt [idtreg]
378 serge 610
 
2434 Serge 611
        call    init_kernel_heap
3555 Serge 612
        stdcall kernel_alloc, (RING0_STACK_SIZE+512) * 2
2434 Serge 613
        mov     [os_stack_seg], eax
164 serge 614
 
2434 Serge 615
        lea     esp, [eax+RING0_STACK_SIZE]
164 serge 616
 
2434 Serge 617
        mov     [tss._ss0], os_stack
618
        mov     [tss._esp0], esp
619
        mov     [tss._esp], esp
620
        mov     [tss._cs], os_code
621
        mov     [tss._ss], os_stack
622
        mov     [tss._ds], app_data
623
        mov     [tss._es], app_data
624
        mov     [tss._fs], app_data
625
        mov     [tss._gs], app_data
626
        mov     [tss._io], 128
465 serge 627
;Add IO access table - bit array of permitted ports
2434 Serge 628
        mov     edi, tss._io_map_0
629
        xor     eax, eax
630
        not     eax
631
        mov     ecx, 8192/4
632
        rep stosd                    ; access to 4096*8=65536 ports
164 serge 633
 
2434 Serge 634
        mov     ax, tss0
635
        ltr     ax
378 serge 636
 
2987 Serge 637
        mov     [LFBSize], 0xC00000
2434 Serge 638
        call    init_LFB
639
        call    init_fpu
640
        call    init_malloc
276 serge 641
 
2434 Serge 642
        stdcall alloc_kernel_space, 0x51000
643
        mov     [default_io_map], eax
465 serge 644
 
2434 Serge 645
        add     eax, 0x2000
646
        mov     [ipc_tmp], eax
647
        mov     ebx, 0x1000
164 serge 648
 
2434 Serge 649
        add     eax, 0x40000
650
        mov     [proc_mem_map], eax
164 serge 651
 
2434 Serge 652
        add     eax, 0x8000
653
        mov     [proc_mem_pdir], eax
164 serge 654
 
2434 Serge 655
        add     eax, ebx
656
        mov     [proc_mem_tab], eax
164 serge 657
 
2434 Serge 658
        add     eax, ebx
659
        mov     [tmp_task_pdir], eax
164 serge 660
 
2434 Serge 661
        add     eax, ebx
662
        mov     [tmp_task_ptab], eax
164 serge 663
 
2434 Serge 664
        add     eax, ebx
665
        mov     [ipc_pdir], eax
164 serge 666
 
2434 Serge 667
        add     eax, ebx
668
        mov     [ipc_ptab], eax
164 serge 669
 
2434 Serge 670
        stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
671
                (unpack.lc+unpack.lp)))*4
712 serge 672
 
2434 Serge 673
        mov     [unpack.p], eax
709 diamond 674
 
2434 Serge 675
        call    init_events
676
        mov     eax, srv.fd-SRV.fd
677
        mov     [srv.fd], eax
678
        mov     [srv.bk], eax
278 serge 679
 
41 mikedld 680
;Set base of graphic segment to linear address of LFB
2434 Serge 681
        mov     eax, [LFBAddress]         ; set for gs
682
        mov     [graph_data_l+2], ax
683
        shr     eax, 16
684
        mov     [graph_data_l+4], al
685
        mov     [graph_data_l+7], ah
1 ha 686
 
1300 serge 687
        stdcall kernel_alloc, [_WinMapSize]
2434 Serge 688
        mov     [_WinMapAddress], eax
1300 serge 689
 
2434 Serge 690
        xor     eax, eax
691
        inc     eax
429 serge 692
 
469 serge 693
; set background
1300 serge 694
 
2434 Serge 695
        mov     [BgrDrawMode], eax
696
        mov     [BgrDataWidth], eax
697
        mov     [BgrDataHeight], eax
698
        mov     [mem_BACKGROUND], 4
699
        mov     [img_background], static_background_data
469 serge 700
 
4265 Serge 701
; set clipboard
702
 
703
        xor     eax, eax
704
        mov     [clipboard_slots], eax
705
        mov     [clipboard_write_lock], eax
706
        stdcall kernel_alloc, 4096
707
        test    eax, eax
708
        jnz     @f
709
 
710
        dec     eax
711
@@:
712
        mov     [clipboard_main_list], eax
713
 
3500 Serge 714
; SET UP OS TASK
715
 
716
        mov     esi, boot_setostask
717
        call    boot_log
718
 
3555 Serge 719
        mov     edx, SLOT_BASE+256
720
        mov     ebx, [os_stack_seg]
721
        add     ebx, 0x2000
722
        call    setup_os_slot
723
        mov     dword [edx], 'IDLE'
724
        sub     [edx+APPDATA.saved_esp], 4
725
        mov     eax, [edx+APPDATA.saved_esp]
726
        mov     dword [eax], idle_thread
727
        mov     ecx, IDLE_PRIORITY
728
        call    scheduler_add_thread
3500 Serge 729
 
3555 Serge 730
        mov     edx, SLOT_BASE+256*2
731
        mov     ebx, [os_stack_seg]
732
        call    setup_os_slot
733
        mov     dword [edx], 'OS'
734
        xor     ecx, ecx
735
        call    scheduler_add_thread
3500 Serge 736
 
3555 Serge 737
        mov     dword [CURRENT_TASK], 2
738
        mov     dword [TASK_COUNT], 2
739
        mov     dword [current_slot], SLOT_BASE + 256*2
740
        mov     dword [TASK_BASE], CURRENT_TASK + 32*2
3500 Serge 741
 
742
 
709 diamond 743
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
2987 Serge 744
        mov     esi, boot_initirq
745
        call    boot_log
746
        call    init_irqs
709 diamond 747
 
2987 Serge 748
        mov     esi, boot_picinit
749
        call    boot_log
2434 Serge 750
        call    PIC_init
709 diamond 751
 
2987 Serge 752
        mov     esi, boot_v86machine
753
        call    boot_log
709 diamond 754
; Initialize system V86 machine
1055 Galkov 755
        call    init_sys_v86
709 diamond 756
 
2987 Serge 757
        mov     esi, boot_inittimer
758
        call    boot_log
1638 serge 759
; Initialize system timer (IRQ0)
2434 Serge 760
        call    PIT_init
725 diamond 761
 
4287 Serge 762
; Register ramdisk file system
763
        mov     esi, boot_initramdisk
764
        call    boot_log
765
        call    ramdisk_init
3626 Serge 766
 
2987 Serge 767
        mov     esi, boot_initapic
768
        call    boot_log
1638 serge 769
; Try to Initialize APIC
2434 Serge 770
        call    APIC_init
725 diamond 771
 
3500 Serge 772
        mov     esi, boot_enableirq
773
        call    boot_log
3908 Serge 774
; Enable timer IRQ (IRQ0) and co-processor IRQ (IRQ13)
725 diamond 775
; they are used: when partitions are scanned, hd_read relies on timer
2434 Serge 776
        call    unmask_timer
2141 serge 777
        stdcall enable_irq, 2               ; @#$%! PIC
778
        stdcall enable_irq, 13              ; co-processor
725 diamond 779
 
3908 Serge 780
        cmp     [IDEContrProgrammingInterface], 0
781
        je      @f
782
 
783
        mov     esi, boot_disabling_ide
2987 Serge 784
        call    boot_log
3908 Serge 785
;--------------------------------------
786
; Disable IDE interrupts, because the search
787
; for IDE partitions is in the PIO mode.
788
;--------------------------------------
789
.disable_IDE_interrupt:
790
; Disable interrupts in IDE controller for PIO
791
        mov     al, 2
792
        mov     dx, [IDE_BAR1_val] ;0x3F4
793
        add     dx, 2 ;0x3F6
1523 diamond 794
        out     dx, al
3908 Serge 795
        mov     dx, [IDE_BAR3_val] ;0x374
796
        add     dx, 2 ;0x376
1523 diamond 797
        out     dx, al
3908 Serge 798
@@:
799
;-----------------------------------------------------------------------------
256 diamond 800
;!!!!!!!!!!!!!!!!!!!!!!!!!!
2987 Serge 801
;        mov     esi, boot_detectdisks
802
;        call    boot_log
803
;include 'detect/disks.inc'
804
        mov     esi, boot_detectfloppy
805
        call    boot_log
806
include 'detect/dev_fd.inc'
807
        mov     esi, boot_detecthdcd
808
        call    boot_log
809
include 'detect/dev_hdcd.inc'
810
        mov     esi, boot_getcache
811
        call    boot_log
812
include 'detect/getcache.inc'
813
        mov     esi, boot_detectpart
814
        call    boot_log
815
include 'detect/sear_par.inc'
256 diamond 816
;!!!!!!!!!!!!!!!!!!!!!!!!!!
817
 
2987 Serge 818
        mov     esi, boot_init_sys
819
        call    boot_log
2434 Serge 820
        call    Parser_params
521 diamond 821
 
2010 serge 822
if ~ defined extended_primary_loader
823
; ramdisk image should be loaded by extended primary loader if it exists
1 ha 824
; READ RAMDISK IMAGE FROM HD
825
 
826
;!!!!!!!!!!!!!!!!!!!!!!!
827
include 'boot/rdload.inc'
828
;!!!!!!!!!!!!!!!!!!!!!!!
2010 serge 829
end if
1 ha 830
;    mov    [dma_hdd],1
831
 
1289 diamond 832
if 0
2434 Serge 833
        mov     ax, [OS_BASE+0x10000+bx_from_load]
834
        cmp     ax, 'r1'; if using not ram disk, then load librares and parameters {SPraid.simba}
835
        je      no_lib_load
2987 Serge 836
 
837
        mov     esi, boot_loadlibs
838
        call    boot_log
488 spraid 839
; LOADING LIBRARES
2434 Serge 840
        stdcall dll.Load, @IMPORT           ; loading librares for kernel (.obj files)
841
        call    load_file_parse_table       ; prepare file parse table
842
        call    set_kernel_conf             ; configure devices and gui
488 spraid 843
no_lib_load:
1289 diamond 844
end if
488 spraid 845
 
1638 serge 846
; Display APIC status
2434 Serge 847
        mov     esi, boot_APIC_found
2219 Serge 848
        cmp     [irq_mode], IRQ_APIC
2434 Serge 849
        je      @f
850
        mov     esi, boot_APIC_nfound
2219 Serge 851
@@:
2987 Serge 852
        call    boot_log
1638 serge 853
 
1 ha 854
; PRINT AMOUNT OF MEMORY
1055 Galkov 855
        mov     esi, boot_memdetect
856
        call    boot_log
1 ha 857
 
1055 Galkov 858
        movzx   ecx, word [boot_y]
2130 serge 859
        if lang eq ru
2434 Serge 860
        or      ecx, (10+30*6) shl 16
3500 Serge 861
        else if lang eq sp
862
        or      ecx, (10+33*6) shl 16
3908 Serge 863
        else
2434 Serge 864
        or      ecx, (10+29*6) shl 16
3908 Serge 865
        end if
1055 Galkov 866
        sub     ecx, 10
867
        mov     edx, 0xFFFFFF
868
        mov     ebx, [MEM_AMOUNT]
869
        shr     ebx, 20
2434 Serge 870
        xor     edi, edi
1055 Galkov 871
        mov     eax, 0x00040000
2434 Serge 872
        inc     edi
1055 Galkov 873
        call    display_number_force
41 mikedld 874
 
465 serge 875
; BUILD SCHEDULER
876
 
2987 Serge 877
;        call    build_scheduler; sys32.inc
465 serge 878
 
2987 Serge 879
;        mov     esi, boot_devices
880
;        call    boot_log
567 serge 881
 
2434 Serge 882
        mov     [pci_access_enabled], 1
3500 Serge 883
        call    pci_enum
567 serge 884
 
3555 Serge 885
        stdcall load_driver, szVidintel
886
 
887
        call    usb_init
888
 
1 ha 889
; SET PRELIMINARY WINDOW STACK AND POSITIONS
890
 
2434 Serge 891
        mov     esi, boot_windefs
892
        call    boot_log
893
        call    set_window_defaults
1 ha 894
 
895
; SET BACKGROUND DEFAULTS
896
 
2434 Serge 897
        mov     esi, boot_bgr
898
        call    boot_log
899
        call    init_background
900
        call    calculatebackground
1 ha 901
 
902
; RESERVE SYSTEM IRQ'S JA PORT'S
903
 
2434 Serge 904
        mov     esi, boot_resirqports
905
        call    boot_log
906
        call    reserve_irqs_ports
1 ha 907
 
2434 Serge 908
        call    init_display
909
        mov     eax, [def_cursor]
910
        mov     [SLOT_BASE+APPDATA.cursor+256], eax
3555 Serge 911
        mov     [SLOT_BASE+APPDATA.cursor+256*2], eax
281 serge 912
 
3555 Serge 913
; PRINT CPU FREQUENCY
281 serge 914
 
3555 Serge 915
        mov     esi, boot_cpufreq
2434 Serge 916
        call    boot_log
3555 Serge 917
 
918
        cli                         ;FIXME check IF
919
        rdtsc
2434 Serge 920
        mov     ecx, eax
921
        mov     esi, 250            ; wait 1/4 a second
922
        call    delay_ms
3555 Serge 923
        rdtsc
924
 
2434 Serge 925
        sub     eax, ecx
3500 Serge 926
        xor     edx, edx
927
        shld    edx, eax, 2
2434 Serge 928
        shl     eax, 2
3500 Serge 929
        mov     dword [cpu_freq], eax
930
        mov     dword [cpu_freq+4], edx
3555 Serge 931
        mov     ebx, 1000000
932
        div     ebx
933
        mov     ebx, eax
1 ha 934
 
1055 Galkov 935
        movzx   ecx, word [boot_y]
2130 serge 936
        if lang eq ru
3555 Serge 937
        add     ecx, (10+19*6) shl 16 - 10
3500 Serge 938
        else if lang eq sp
3555 Serge 939
        add     ecx, (10+25*6) shl 16 - 10
3908 Serge 940
        else
3555 Serge 941
        add     ecx, (10+17*6) shl 16 - 10
3908 Serge 942
        end if
3555 Serge 943
 
1055 Galkov 944
        mov     edx, 0xFFFFFF
2434 Serge 945
        xor     edi, edi
1055 Galkov 946
        mov     eax, 0x00040000
2229 Serge 947
        inc     edi
1055 Galkov 948
        call    display_number_force
1038 diamond 949
 
1 ha 950
; SET VARIABLES
951
 
2434 Serge 952
        call    set_variables
1 ha 953
 
954
; STACK AND FDC
955
 
2434 Serge 956
        call    stack_init
957
        call    fdc_init
1 ha 958
 
959
; PALETTE FOR 320x200 and 640x480 16 col
960
 
2434 Serge 961
        cmp     [SCR_MODE], word 0x12
962
        jne     no_pal_vga
963
        mov     esi, boot_pal_vga
964
        call    boot_log
965
        call    paletteVGA
1 ha 966
      no_pal_vga:
967
 
2434 Serge 968
        cmp     [SCR_MODE], word 0x13
969
        jne     no_pal_ega
970
        mov     esi, boot_pal_ega
971
        call    boot_log
972
        call    palette320x200
1 ha 973
      no_pal_ega:
974
 
975
; LOAD DEFAULT SKIN
976
 
1055 Galkov 977
        call    load_default_skin
1 ha 978
 
465 serge 979
;protect io permission map
980
 
2434 Serge 981
        mov     esi, [default_io_map]
982
        stdcall map_page, esi, [SLOT_BASE+256+APPDATA.io_map], PG_MAP
983
        add     esi, 0x1000
984
        stdcall map_page, esi, [SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
465 serge 985
 
2434 Serge 986
        stdcall map_page, tss._io_map_0, \
987
                [SLOT_BASE+256+APPDATA.io_map], PG_MAP
988
        stdcall map_page, tss._io_map_1, \
989
                [SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
465 serge 990
 
1 ha 991
; LOAD FIRST APPLICATION
3908 Serge 992
        cmp     byte [launcher_start], 1        ; Check if starting LAUNCHER is selected on blue screen (1 = yes)
993
        jnz     first_app_found
994
 
1055 Galkov 995
        cli
996
        mov     ebp, firstapp
997
        call    fs_execute_from_sysdir
3500 Serge 998
        test    eax, eax
999
        jns     first_app_found
501 serge 1000
 
1055 Galkov 1001
        mov     esi, boot_failed
1002
        call    boot_log
653 diamond 1003
 
2434 Serge 1004
        mov     eax, 0xDEADBEEF      ; otherwise halt
1055 Galkov 1005
        hlt
501 serge 1006
 
237 serge 1007
first_app_found:
501 serge 1008
 
1055 Galkov 1009
        cli
1 ha 1010
 
2141 serge 1011
; SET KEYBOARD PARAMETERS
2434 Serge 1012
        mov     al, 0xf6       ; reset keyboard, scan enabled
1013
        call    kb_write
2987 Serge 1014
        test    ah, ah
1015
        jnz     .no_keyboard
2141 serge 1016
 
1017
        ; wait until 8042 is ready
2434 Serge 1018
        xor     ecx, ecx
2141 serge 1019
      @@:
2434 Serge 1020
        in      al, 64h
1021
        and     al, 00000010b
1022
        loopnz  @b
2141 serge 1023
 
2987 Serge 1024
iglobal
1025
align 4
1026
ps2_keyboard_functions:
1027
        dd      .end - $
1028
        dd      0       ; no close
1029
        dd      ps2_set_lights
1030
.end:
1031
endg
1032
        stdcall register_keyboard, ps2_keyboard_functions, 0
2141 serge 1033
       ; mov   al, 0xED       ; Keyboard LEDs - only for testing!
1034
       ; call  kb_write
1035
       ; call  kb_read
1036
       ; mov   al, 111b
1037
       ; call  kb_write
1038
       ; call  kb_read
1039
 
2434 Serge 1040
        mov     al, 0xF3     ; set repeat rate & delay
1041
        call    kb_write
2141 serge 1042
;        call  kb_read
2434 Serge 1043
        mov     al, 0; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
1044
        call    kb_write
2141 serge 1045
;        call  kb_read
1046
     ;// mike.dld [
2434 Serge 1047
        call    set_lights
2141 serge 1048
     ;// mike.dld ]
1049
        stdcall attach_int_handler, 1, irq1, 0
3908 Serge 1050
        DEBUGF  1, "K : IRQ1 error code %x\n", eax
2987 Serge 1051
.no_keyboard:
2141 serge 1052
 
1053
; SET MOUSE
1054
 
1055
        stdcall load_driver, szPS2MDriver
1056
;        stdcall load_driver, szCOM_MDriver
1057
 
2434 Serge 1058
        mov     esi, boot_setmouse
1059
        call    boot_log
1060
        call    setmouse
2141 serge 1061
 
1043 hidnplayr 1062
; Setup serial output console (if enabled)
1063
 
1064
if defined debug_com_base
1065
 
1055 Galkov 1066
        ; enable Divisor latch
1043 hidnplayr 1067
 
1055 Galkov 1068
        mov     dx, debug_com_base+3
1069
        mov     al, 1 shl 7
1070
        out     dx, al
1043 hidnplayr 1071
 
1055 Galkov 1072
        ; Set speed to 115200 baud (max speed)
1043 hidnplayr 1073
 
1055 Galkov 1074
        mov     dx, debug_com_base
1075
        mov     al, 0x01
1076
        out     dx, al
1043 hidnplayr 1077
 
1055 Galkov 1078
        mov     dx, debug_com_base+1
1079
        mov     al, 0x00
1080
        out     dx, al
1043 hidnplayr 1081
 
1055 Galkov 1082
        ; No parity, 8bits words, one stop bit, dlab bit back to 0
1043 hidnplayr 1083
 
1055 Galkov 1084
        mov     dx, debug_com_base+3
1085
        mov     al, 3
1086
        out     dx, al
1043 hidnplayr 1087
 
1055 Galkov 1088
        ; disable interrupts
1043 hidnplayr 1089
 
1055 Galkov 1090
        mov     dx, debug_com_base+1
1091
        mov     al, 0
1092
        out     dx, al
1043 hidnplayr 1093
 
1055 Galkov 1094
        ; clear +  enable fifo (64 bits)
1043 hidnplayr 1095
 
1055 Galkov 1096
        mov     dx, debug_com_base+2
1097
        mov     al, 0x7 + 1 shl 5
1098
        out     dx, al
1043 hidnplayr 1099
 
1100
 
1101
end if
3500 Serge 1102
        mov     eax, [version_inf.rev]
1103
        DEBUGF  1, "K : kernel SVN r%d\n", eax
2987 Serge 1104
 
2441 Serge 1105
        mov     eax, [cpu_count]
1106
        test    eax, eax
1107
        jnz     @F
2442 Serge 1108
        mov     al, 1                             ; at least one CPU
2441 Serge 1109
@@:
1110
        DEBUGF  1, "K : %d CPU detected\n", eax
1043 hidnplayr 1111
 
4265 Serge 1112
include "detect/vortex86.inc"                     ; Vortex86 SoC detection code
1113
 
3725 Serge 1114
        DEBUGF  1, "K : BAR0 %x \n", [IDE_BAR0_val]:4
1115
        DEBUGF  1, "K : BAR1 %x \n", [IDE_BAR1_val]:4
1116
        DEBUGF  1, "K : BAR2 %x \n", [IDE_BAR2_val]:4
1117
        DEBUGF  1, "K : BAR3 %x \n", [IDE_BAR3_val]:4
1118
        DEBUGF  1, "K : BAR4 %x \n", [IDEContrRegsBaseAddr]:4
1119
        DEBUGF  1, "K : IDEContrProgrammingInterface %x \n", [IDEContrProgrammingInterface]:4
3908 Serge 1120
        DEBUGF  1, "K : IDE_Interrupt %x \n", [IDE_Interrupt]:4
4265 Serge 1121
 
2010 serge 1122
; START MULTITASKING
1 ha 1123
 
1638 serge 1124
; A 'All set - press ESC to start' messages if need
767 diamond 1125
if preboot_blogesc
1055 Galkov 1126
        mov     esi, boot_tasking
1127
        call    boot_log
2434 Serge 1128
.bll1:
1129
        in      al, 0x60        ; wait for ESC key press
1055 Galkov 1130
        cmp     al, 129
1131
        jne     .bll1
767 diamond 1132
end if
1133
 
3908 Serge 1134
        push    eax edx
1135
        mov     dx, [IDEContrRegsBaseAddr]
1136
        xor     eax, eax
1137
        add     dx, 2
1138
        in      al, dx
1139
        DEBUGF  1, "K : Primary Bus Master IDE Status Register %x\n", eax
1140
 
1141
        add     dx, 8
1142
        in      al, dx
1143
        DEBUGF  1, "K : Secondary Bus Master IDE Status Register %x\n", eax
1144
        pop     edx eax
1145
 
1055 Galkov 1146
        cmp     [IDEContrRegsBaseAddr], 0
1147
        setnz   [dma_hdd]
3725 Serge 1148
 
3908 Serge 1149
        cmp     [IDEContrProgrammingInterface], 0
1150
        je      set_interrupts_for_IDE_controllers.continue
1151
 
1152
        mov     ax, [IDE_Interrupt]
1153
        cmp     al, 0xff
1154
        jne     @f
1155
 
1156
        mov     [dma_hdd], 0
1157
        jmp     set_interrupts_for_IDE_controllers.end_set_interrupts
1158
@@:
1159
;-----------------------------------------------------------------------------
1160
; set interrupts for IDE Controller
1161
;-----------------------------------------------------------------------------
1162
        mov     esi, boot_set_int_IDE
1163
        call    boot_log
1164
set_interrupts_for_IDE_controllers:
1165
        mov     ax, [IDEContrProgrammingInterface]
1166
        cmp     ax, 0x0180
1167
        je      .pata_ide
1168
 
1169
        cmp     ax, 0x018a
1170
        jne     .sata_ide
1171
;--------------------------------------
1172
.pata_ide:
1173
        cmp     [IDEContrRegsBaseAddr], 0
1174
        je      .end_set_interrupts
1175
 
1176
        stdcall attach_int_handler, 14, IDE_irq_14_handler, 0
1177
        DEBUGF  1, "K : Set IDE IRQ14 return code %x\n", eax
1178
        stdcall attach_int_handler, 15, IDE_irq_15_handler, 0
1179
        DEBUGF  1, "K : Set IDE IRQ15 return code %x\n", eax
1180
        jmp     .enable_IDE_interrupt
1181
;--------------------------------------
1182
.sata_ide:
1183
        cmp     ax, 0x0185
1184
        je      .sata_ide_1
1185
 
1186
        cmp     ax, 0x018f
1187
        jne     .end_set_interrupts
1188
;--------------------------------------
1189
.sata_ide_1:
1190
        cmp     [IDEContrRegsBaseAddr], 0
1191
        je      .end_set_interrupts
1192
 
1193
        mov     ax, [IDE_Interrupt]
1194
        movzx   eax, al
1195
        stdcall attach_int_handler, eax, IDE_common_irq_handler, 0
1196
        DEBUGF  1, "K : Set IDE IRQ%d return code %x\n", [IDE_Interrupt]:1, eax
1197
;--------------------------------------
1198
.enable_IDE_interrupt:
1199
        mov     esi, boot_enabling_ide
1200
        call    boot_log
1201
; Enable interrupts in IDE controller for DMA
1202
        mov     al, 0
1203
        mov     dx, [IDE_BAR1_val] ;0x3F4
1204
        add     dx, 2 ;0x3F6
1205
        out     dx, al
1206
        mov     dx, [IDE_BAR3_val] ;0x374
1207
        add     dx, 2 ;0x376
1208
        out     dx, al
1209
;--------------------------------------
1210
.end_set_interrupts:
1211
;-----------------------------------------------------------------------------
3725 Serge 1212
        cmp     [dma_hdd], 0
1213
        je      .print_pio
1214
.print_dma:
1215
        DEBUGF  1, "K : IDE DMA mode\n"
1216
        jmp     .continue
1217
 
1218
.print_pio:
1219
        DEBUGF  1, "K : IDE PIO mode\n"
1220
.continue:
1221
 
2434 Serge 1222
        mov     [timer_ticks_enable], 1         ; for cd driver
1 ha 1223
 
1055 Galkov 1224
        sti
3555 Serge 1225
;        call    change_task
465 serge 1226
 
2434 Serge 1227
        jmp     osloop
465 serge 1228
 
1 ha 1229
 
1055 Galkov 1230
        ; Fly :)
1 ha 1231
 
465 serge 1232
include 'unpacker.inc'
1233
 
1234
align 4
1235
boot_log:
2217 Serge 1236
        pushad
465 serge 1237
 
2434 Serge 1238
        mov     ebx, 10*65536
1239
        mov     bx, word [boot_y]
1240
        add     [boot_y], dword 10
1241
        mov     ecx, 0x80ffffff; ASCIIZ string with white color
1242
        xor     edi, edi
1243
        mov     edx, esi
1244
        inc     edi
1245
        call    dtext
465 serge 1246
 
2434 Serge 1247
        mov     [novesachecksum], 1000
1248
        call    checkVga_N13
465 serge 1249
 
1276 Lrz 1250
        popad
465 serge 1251
 
1276 Lrz 1252
        ret
465 serge 1253
 
3555 Serge 1254
; in: edx -> APPDATA for OS/IDLE slot
1255
; in: ebx = stack base
1256
proc setup_os_slot
1257
        xor     eax, eax
1258
        mov     ecx, 256/4
1259
        mov     edi, edx
1260
        rep stosd
1261
 
1262
        mov     eax, tss+0x80
1263
        call    get_pg_addr
1264
        inc     eax
1265
        mov     [edx+APPDATA.io_map], eax
1266
        mov     eax, tss+0x1080
1267
        call    get_pg_addr
1268
        inc     eax
1269
        mov     [edx+APPDATA.io_map+4], eax
1270
 
1271
        mov     dword [edx+APPDATA.pl0_stack], ebx
1272
        lea     edi, [ebx+0x2000-512]
1273
        mov     dword [edx+APPDATA.fpu_state], edi
1274
        mov     dword [edx+APPDATA.saved_esp0], edi
1275
        mov     dword [edx+APPDATA.saved_esp], edi
1276
        mov     dword [edx+APPDATA.terminate_protection], 1 ; make unkillable
1277
 
1278
        mov     esi, fpu_data
1279
        mov     ecx, 512/4
1280
        cld
1281
        rep movsd
1282
 
1283
        lea     eax, [edx+APP_OBJ_OFFSET]
1284
        mov     dword [edx+APPDATA.fd_obj], eax
1285
        mov     dword [edx+APPDATA.bk_obj], eax
1286
 
1287
        mov     dword [edx+APPDATA.cur_dir], sysdir_path
1288
 
1289
        mov     [edx + APPDATA.dir_table], sys_pgdir - OS_BASE
1290
 
1291
        mov     eax, edx
1292
        shr     eax, 3
1293
        add     eax, CURRENT_TASK - (SLOT_BASE shr 3)
1294
        mov     [eax+TASKDATA.wnd_number], dh
1295
        mov     byte [eax+TASKDATA.pid], dh
1296
 
1297
        ret
1298
endp
1299
 
1 ha 1300
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1301
;                                                                    ;
33 mario79 1302
;                    MAIN OS LOOP START                              ;
1 ha 1303
;                                                                    ;
1304
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1305
align 32
1306
osloop:
3555 Serge 1307
        mov     edx, osloop_has_work?
1308
        xor     ecx, ecx
1309
        call    Wait_events
1310
        xor     eax, eax
1311
        xchg    eax, [osloop_nonperiodic_work]
1312
        test    eax, eax
1313
        jz      .no_periodic
2465 Serge 1314
;        call    [draw_pointer]
1315
        call    __sys_draw_pointer
2434 Serge 1316
        call    window_check_events
1317
        call    mouse_check_events
1318
        call    checkmisc
1319
        call    checkVga_N13
3555 Serge 1320
.no_periodic:
2434 Serge 1321
        call    stack_handler
1322
        call    check_fdd_motor_status
1323
        call    check_ATAPI_device_event
2987 Serge 1324
        call    check_lights_state
2434 Serge 1325
        call    check_timers
1326
        jmp     osloop
33 mario79 1327
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1328
;                                                                    ;
1329
;                      MAIN OS LOOP END                              ;
1330
;                                                                    ;
1331
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3555 Serge 1332
proc osloop_has_work?
1333
        cmp     [osloop_nonperiodic_work], 0
1334
        jnz     .yes
1335
        call    stack_handler_has_work?
1336
        jnz     .yes
4287 Serge 1337
        call    check_fdd_motor_status_has_work?
1338
        jnz     .yes
3555 Serge 1339
        call    check_ATAPI_device_event_has_work?
1340
        jnz     .yes
1341
        call    check_lights_state_has_work?
1342
        jnz     .yes
1343
        call    check_timers_has_work?
1344
        jnz     .yes
1345
.no:
1346
        xor     eax, eax
1055 Galkov 1347
        ret
3555 Serge 1348
.yes:
1349
        xor     eax, eax
1350
        inc     eax
1351
        ret
1352
endp
1 ha 1353
 
3555 Serge 1354
proc wakeup_osloop
1355
        mov     [osloop_nonperiodic_work], 1
1356
        ret
1357
endp
1358
 
1 ha 1359
uglobal
3555 Serge 1360
align 4
1361
osloop_nonperiodic_work dd      ?
1 ha 1362
endg
1363
 
3555 Serge 1364
align 4
1365
idle_thread:
1366
        sti
1367
idle_loop:
1368
        hlt
1369
        jmp     idle_loop
1 ha 1370
 
1371
 
3555 Serge 1372
 
1 ha 1373
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1374
;                                                                      ;
1375
;                   INCLUDED SYSTEM FILES                              ;
1376
;                                                                      ;
1377
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1378
 
1379
 
7 me_root 1380
include "kernel32.inc"
1 ha 1381
 
1382
 
1383
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1384
;                                                                      ;
1385
;                       KERNEL FUNCTIONS                               ;
1386
;                                                                      ;
1387
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1388
 
1389
reserve_irqs_ports:
1390
 
1273 Lrz 1391
 
1392
; RESERVE PORTS
2434 Serge 1393
        mov     eax, RESERVED_PORTS
1394
        mov     ecx, 1
1273 Lrz 1395
 
2434 Serge 1396
        mov     [eax], dword 4
269 serge 1397
 
2434 Serge 1398
        mov     [eax+16], ecx
1399
        mov     [eax+16+4], dword 0
3500 Serge 1400
        mov     [eax+16+8], dword 0x2D
269 serge 1401
 
2434 Serge 1402
        mov     [eax+32], ecx
1403
        mov     [eax+32+4], dword 0x30
1404
        mov     [eax+32+8], dword 0x4D
233 serge 1405
 
2434 Serge 1406
        mov     [eax+48], ecx
1407
        mov     [eax+48+4], dword 0x50
3500 Serge 1408
        mov     [eax+48+8], dword 0xDF
233 serge 1409
 
2434 Serge 1410
        mov     [eax+64], ecx
1411
        mov     [eax+64+4], dword 0xE5
1412
        mov     [eax+64+8], dword 0xFF
1273 Lrz 1413
 
1055 Galkov 1414
        ret
1 ha 1415
 
1416
 
1417
iglobal
3555 Serge 1418
  process_number dd 0x2
1 ha 1419
endg
1420
 
1421
set_variables:
1422
 
2434 Serge 1423
        mov     ecx, 0x16                    ; flush port 0x60
2141 serge 1424
.fl60:
2434 Serge 1425
        in      al, 0x60
1426
        loop    .fl60
1427
        push    eax
1 ha 1428
 
3908 Serge 1429
        mov     ax, [BOOT_VARS+BOOT_Y_RES]
2434 Serge 1430
        shr     ax, 1
1431
        shl     eax, 16
3908 Serge 1432
        mov     ax, [BOOT_VARS+BOOT_X_RES]
2434 Serge 1433
        shr     ax, 1
1434
        mov     [MOUSE_X], eax
3555 Serge 1435
        call    wakeup_osloop
41 mikedld 1436
 
2434 Serge 1437
        xor     eax, eax
1438
        mov     [BTN_ADDR], dword BUTTON_INFO ; address of button list
1 ha 1439
 
2434 Serge 1440
        mov     byte [KEY_COUNT], al              ; keyboard buffer
1441
        mov     byte [BTN_COUNT], al              ; button buffer
1267 Lrz 1442
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1443
 
2434 Serge 1444
        pop     eax
1055 Galkov 1445
        ret
1 ha 1446
 
1447
align 4
1304 Lrz 1448
;input  eax=43,bl-byte of output, ecx - number of port
1 ha 1449
sys_outport:
1450
 
2434 Serge 1451
        mov     edi, ecx   ; separate flag for read / write
1452
        and     ecx, 65535
1 ha 1453
 
2434 Serge 1454
        mov     eax, [RESERVED_PORTS]
1455
        test    eax, eax
1456
        jnz     .sopl8
1457
        inc     eax
1458
        mov     [esp+32], eax
1459
        ret
1 ha 1460
 
1304 Lrz 1461
  .sopl8:
2434 Serge 1462
        mov     edx, [TASK_BASE]
1463
        mov     edx, [edx+0x4]
1304 Lrz 1464
    ;and   ecx,65535
1465
    ;cld - set on interrupt 0x40
1466
  .sopl1:
1 ha 1467
 
2434 Serge 1468
        mov     esi, eax
1469
        shl     esi, 4
1470
        add     esi, RESERVED_PORTS
1471
        cmp     edx, [esi+0]
1472
        jne     .sopl2
1473
        cmp     ecx, [esi+4]
1474
        jb      .sopl2
1475
        cmp     ecx, [esi+8]
1476
        jg      .sopl2
1304 Lrz 1477
.sopl3:
1 ha 1478
 
2434 Serge 1479
        test    edi, 0x80000000; read ?
1480
        jnz     .sopl4
1 ha 1481
 
2434 Serge 1482
        mov     eax, ebx
1483
        mov     dx, cx   ; write
1484
        out     dx, al
1485
        and     [esp+32], dword 0
1486
        ret
1 ha 1487
 
2434 Serge 1488
        .sopl2:
1 ha 1489
 
2434 Serge 1490
        dec     eax
1491
        jnz     .sopl1
1492
        inc     eax
1493
        mov     [esp+32], eax
1494
        ret
1 ha 1495
 
1638 serge 1496
 
1304 Lrz 1497
  .sopl4:
1 ha 1498
 
2434 Serge 1499
        mov     dx, cx   ; read
1500
        in      al, dx
1501
        and     eax, 0xff
1502
        and     [esp+32], dword 0
1503
        mov     [esp+20], eax
1504
        ret
1 ha 1505
 
1506
display_number:
1369 Lrz 1507
;It is not optimization
1508
        mov     eax, ebx
1509
        mov     ebx, ecx
1510
        mov     ecx, edx
1511
        mov     edx, esi
1512
        mov     esi, edi
1 ha 1513
; eax = print type, al=0 -> ebx is number
1514
;                   al=1 -> ebx is pointer
1515
;                   ah=0 -> display decimal
1516
;                   ah=1 -> display hexadecimal
1517
;                   ah=2 -> display binary
1518
;                   eax bits 16-21 = number of digits to display (0-32)
1519
;                   eax bits 22-31 = reserved
1520
;
1521
; ebx = number or pointer
1522
; ecx = x shl 16 + y
1523
; edx = color
2434 Serge 1524
        xor     edi, edi
211 serge 1525
display_number_force:
2434 Serge 1526
        push    eax
1527
        and     eax, 0x3fffffff
1528
        cmp     eax, 0xffff     ; length > 0 ?
1529
        pop     eax
1530
        jge     cont_displ
1531
        ret
1 ha 1532
   cont_displ:
2434 Serge 1533
        push    eax
1534
        and     eax, 0x3fffffff
1535
        cmp     eax, 61*0x10000  ; length <= 60 ?
1536
        pop     eax
1537
        jb      cont_displ2
1538
        ret
1 ha 1539
   cont_displ2:
1540
 
2434 Serge 1541
        pushad
1 ha 1542
 
2434 Serge 1543
        cmp     al, 1            ; ecx is a pointer ?
1544
        jne     displnl1
1545
        mov     ebp, ebx
1546
        add     ebp, 4
1547
        mov     ebp, [ebp+std_application_base_address]
1548
        mov     ebx, [ebx+std_application_base_address]
1276 Lrz 1549
 displnl1:
2434 Serge 1550
        sub     esp, 64
1 ha 1551
 
2434 Serge 1552
        test    ah, ah            ; DECIMAL
1553
        jnz     no_display_desnum
1554
        shr     eax, 16
1555
        and     eax, 0xC03f
652 mario79 1556
;     and   eax,0x3f
2434 Serge 1557
        push    eax
1558
        and     eax, 0x3f
1559
        mov     edi, esp
1560
        add     edi, 4+64-1
1561
        mov     ecx, eax
1562
        mov     eax, ebx
1563
        mov     ebx, 10
1276 Lrz 1564
 d_desnum:
2434 Serge 1565
        xor     edx, edx
1566
        call    division_64_bits
1567
        div     ebx
1568
        add     dl, 48
1569
        mov     [edi], dl
1570
        dec     edi
1571
        loop    d_desnum
1572
        pop     eax
1573
        call    normalize_number
1574
        call    draw_num_text
1575
        add     esp, 64
1576
        popad
1577
        ret
1 ha 1578
   no_display_desnum:
1579
 
2434 Serge 1580
        cmp     ah, 0x01         ; HEXADECIMAL
1581
        jne     no_display_hexnum
1582
        shr     eax, 16
1583
        and     eax, 0xC03f
652 mario79 1584
;     and   eax,0x3f
2434 Serge 1585
        push    eax
1586
        and     eax, 0x3f
1587
        mov     edi, esp
1588
        add     edi, 4+64-1
1589
        mov     ecx, eax
1590
        mov     eax, ebx
1591
        mov     ebx, 16
1 ha 1592
   d_hexnum:
2434 Serge 1593
        xor     edx, edx
1594
        call    division_64_bits
1595
        div     ebx
1056 Galkov 1596
   hexletters = __fdo_hexdigits
2434 Serge 1597
        add     edx, hexletters
1598
        mov     dl, [edx]
1599
        mov     [edi], dl
1600
        dec     edi
1601
        loop    d_hexnum
1602
        pop     eax
1603
        call    normalize_number
1604
        call    draw_num_text
1605
        add     esp, 64
1606
        popad
1607
        ret
1 ha 1608
   no_display_hexnum:
1609
 
2434 Serge 1610
        cmp     ah, 0x02         ; BINARY
1611
        jne     no_display_binnum
1612
        shr     eax, 16
1613
        and     eax, 0xC03f
652 mario79 1614
;     and   eax,0x3f
2434 Serge 1615
        push    eax
1616
        and     eax, 0x3f
1617
        mov     edi, esp
1618
        add     edi, 4+64-1
1619
        mov     ecx, eax
1620
        mov     eax, ebx
1621
        mov     ebx, 2
1 ha 1622
   d_binnum:
2434 Serge 1623
        xor     edx, edx
1624
        call    division_64_bits
1625
        div     ebx
1626
        add     dl, 48
1627
        mov     [edi], dl
1628
        dec     edi
1629
        loop    d_binnum
1630
        pop     eax
1631
        call    normalize_number
1632
        call    draw_num_text
1633
        add     esp, 64
1634
        popad
1635
        ret
1 ha 1636
   no_display_binnum:
1637
 
2434 Serge 1638
        add     esp, 64
1639
        popad
1640
        ret
1 ha 1641
 
652 mario79 1642
normalize_number:
2434 Serge 1643
        test    ah, 0x80
1644
        jz      .continue
1645
        mov     ecx, 48
1646
        and     eax, 0x3f
652 mario79 1647
@@:
2434 Serge 1648
        inc     edi
1649
        cmp     [edi], cl
1650
        jne     .continue
1651
        dec     eax
1652
        cmp     eax, 1
1653
        ja      @r
1654
        mov     al, 1
652 mario79 1655
.continue:
2434 Serge 1656
        and     eax, 0x3f
1657
        ret
1 ha 1658
 
655 mario79 1659
division_64_bits:
2434 Serge 1660
        test    [esp+1+4], byte 0x40
1661
        jz      .continue
1662
        push    eax
1663
        mov     eax, ebp
1664
        div     ebx
1665
        mov     ebp, eax
1666
        pop     eax
655 mario79 1667
.continue:
2434 Serge 1668
        ret
652 mario79 1669
 
1 ha 1670
draw_num_text:
2434 Serge 1671
        mov     esi, eax
1672
        mov     edx, 64+4
1673
        sub     edx, eax
1674
        add     edx, esp
1675
        mov     ebx, [esp+64+32-8+4]
684 diamond 1676
; add window start x & y
2434 Serge 1677
        mov     ecx, [TASK_BASE]
465 serge 1678
 
2434 Serge 1679
        mov     edi, [CURRENT_TASK]
1680
        shl     edi, 8
465 serge 1681
 
2434 Serge 1682
        mov     eax, [ecx-twdw+WDATA.box.left]
1683
        add     eax, [edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1684
        shl     eax, 16
1685
        add     eax, [ecx-twdw+WDATA.box.top]
1686
        add     eax, [edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1687
        add     ebx, eax
1688
        mov     ecx, [esp+64+32-12+4]
1055 Galkov 1689
        and     ecx, not 0x80000000     ; force counted string
1690
        mov     eax, [esp+64+8]         ; background color (if given)
1691
        mov     edi, [esp+64+4]
2434 Serge 1692
        jmp     dtext
1 ha 1693
 
1694
align 4
1695
 
1696
sys_setup:
1697
 
1698
; 1=roland mpu midi base , base io address
1699
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1700
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1701
; 5=system language, 1eng 2fi 3ger 4rus
1702
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1703
; 8=fat32 partition in hd
1704
; 9
1705
; 10 = sound dma channel
1706
; 11 = enable lba read
1707
; 12 = enable pci access
1708
 
1709
 
2434 Serge 1710
        and     [esp+32], dword 0
1711
        dec     ebx                             ; MIDI
1712
        jnz     nsyse1
1713
        cmp     ecx, 0x100
1 ha 1714
 
2434 Serge 1715
        jb      nsyse1
1716
        mov     esi, 65535
1717
        cmp     esi, ecx
1276 Lrz 1718
 
2434 Serge 1719
        jb      nsyse1
1720
        mov     [midi_base], cx ;bx
1721
        mov     word [mididp], cx;bx
1722
        inc     cx              ;bx
1723
        mov     word [midisp], cx;bx
1724
        ret
1276 Lrz 1725
 
283 diamond 1726
iglobal
1 ha 1727
midi_base dw 0
283 diamond 1728
endg
1 ha 1729
 
1730
   nsyse1:
2434 Serge 1731
        dec     ebx                              ; KEYBOARD
1732
        jnz     nsyse2
1733
        mov     edi, [TASK_BASE]
1734
        mov     eax, [edi+TASKDATA.mem_start]
1735
        add     eax, edx
1 ha 1736
 
2434 Serge 1737
        dec     ecx
1738
        jnz     kbnobase
1739
        mov     ebx, keymap
1740
        mov     ecx, 128
1741
        call    memmove
1742
        ret
1 ha 1743
   kbnobase:
2434 Serge 1744
        dec     ecx
1745
        jnz     kbnoshift
1276 Lrz 1746
 
2434 Serge 1747
        mov     ebx, keymap_shift
1748
        mov     ecx, 128
1749
        call    memmove
1750
        ret
1 ha 1751
   kbnoshift:
2434 Serge 1752
        dec     ecx
1753
        jnz     kbnoalt
1754
        mov     ebx, keymap_alt
1755
        mov     ecx, 128
1756
        call    memmove
1757
        ret
1 ha 1758
   kbnoalt:
2434 Serge 1759
        sub     ecx, 6
1760
        jnz     kbnocountry
1761
        mov     word [keyboard], dx
1762
        ret
1 ha 1763
   kbnocountry:
2434 Serge 1764
        mov     [esp+32], dword 1
1765
        ret
1 ha 1766
   nsyse2:
2434 Serge 1767
        dec     ebx                         ; CD
1768
        jnz     nsyse4
1276 Lrz 1769
 
2434 Serge 1770
        test    ecx, ecx
1771
        jz      nosesl
1276 Lrz 1772
 
2434 Serge 1773
        cmp     ecx, 4
1774
        ja      nosesl
1775
        mov     [cd_base], cl
1276 Lrz 1776
 
2434 Serge 1777
        dec     ecx
1778
        jnz     noprma
3725 Serge 1779
        mov     eax, [hd_address_table]
3908 Serge 1780
        mov     [cdbase], eax   ;0x1f0
2434 Serge 1781
        mov     [cdid], 0xa0
3725 Serge 1782
noprma:
1276 Lrz 1783
 
2434 Serge 1784
        dec     ecx
1785
        jnz     noprsl
3725 Serge 1786
        mov     eax, [hd_address_table]
1787
        mov     [cdbase], eax   ;0x1f0
2434 Serge 1788
        mov     [cdid], 0xb0
3725 Serge 1789
noprsl:
2434 Serge 1790
        dec     ecx
1791
        jnz     nosema
3725 Serge 1792
        mov     eax, [hd_address_table+16]
1793
        mov     [cdbase], eax   ;0x170
2434 Serge 1794
        mov     [cdid], 0xa0
3725 Serge 1795
nosema:
2434 Serge 1796
        dec     ecx
1797
        jnz     nosesl
3725 Serge 1798
        mov     eax, [hd_address_table+16]
3908 Serge 1799
        mov     [cdbase], eax   ;0x170
2434 Serge 1800
        mov     [cdid], 0xb0
3725 Serge 1801
nosesl:
2434 Serge 1802
        ret
1 ha 1803
 
1276 Lrz 1804
iglobal
1 ha 1805
cd_base db 0
1806
 
1276 Lrz 1807
endg
1 ha 1808
   nsyse4:
1638 serge 1809
 
2434 Serge 1810
        sub     ebx, 2           ; SYSTEM LANGUAGE
1811
        jnz     nsyse5
1812
        mov     [syslang], ecx
1813
        ret
1 ha 1814
   nsyse5:
1638 serge 1815
 
3908 Serge 1816
        sub     ebx, 2          ; HD BASE - obsolete
2434 Serge 1817
        jnz     nsyse7
1 ha 1818
 
75 diamond 1819
   nosethd:
2434 Serge 1820
        ret
1 ha 1821
 
802 serge 1822
nsyse7:
1 ha 1823
 
3908 Serge 1824
;     cmp  eax,8                      ; HD PARTITION - obsolete
2434 Serge 1825
        dec     ebx
1826
        jnz     nsyse8
1827
        ret
1 ha 1828
 
802 serge 1829
nsyse8:
1260 Lrz 1830
;     cmp  eax,11                     ; ENABLE LBA READ
2434 Serge 1831
        and     ecx, 1
1832
        sub     ebx, 3
1833
        jnz     no_set_lba_read
1834
        mov     [lba_read_enabled], ecx
1835
        ret
1 ha 1836
 
802 serge 1837
no_set_lba_read:
1260 Lrz 1838
;     cmp  eax,12                     ; ENABLE PCI ACCESS
2434 Serge 1839
        dec     ebx
1840
        jnz     sys_setup_err
1841
        mov     [pci_access_enabled], ecx
1842
        ret
1 ha 1843
 
75 diamond 1844
sys_setup_err:
2434 Serge 1845
        or      [esp+32], dword -1
1846
        ret
1 ha 1847
 
1848
align 4
1849
 
1850
sys_getsetup:
1851
 
1852
; 1=roland mpu midi base , base io address
1853
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1854
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1855
; 5=system language, 1eng 2fi 3ger 4rus
1856
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1857
; 8=fat32 partition in hd
1858
; 9=get hs timer tic
1859
 
1276 Lrz 1860
;     cmp  eax,1
2434 Serge 1861
        dec     ebx
1862
        jnz     ngsyse1
1863
        movzx   eax, [midi_base]
1864
        mov     [esp+32], eax
1865
        ret
802 serge 1866
ngsyse1:
1276 Lrz 1867
;     cmp  eax,2
2434 Serge 1868
        dec     ebx
1869
        jnz     ngsyse2
1 ha 1870
 
2434 Serge 1871
        mov     edi, [TASK_BASE]
1872
        mov     ebx, [edi+TASKDATA.mem_start]
1873
        add     ebx, edx
1276 Lrz 1874
 
1875
;     cmp  ebx,1
2434 Serge 1876
        dec     ecx
1877
        jnz     kbnobaseret
1878
        mov     eax, keymap
1879
        mov     ecx, 128
1880
        call    memmove
1881
        ret
802 serge 1882
kbnobaseret:
1276 Lrz 1883
;     cmp  ebx,2
2434 Serge 1884
        dec     ecx
1885
        jnz     kbnoshiftret
1276 Lrz 1886
 
2434 Serge 1887
        mov     eax, keymap_shift
1888
        mov     ecx, 128
1889
        call    memmove
1890
        ret
802 serge 1891
kbnoshiftret:
1276 Lrz 1892
;     cmp  ebx,3
2434 Serge 1893
        dec     ecx
1894
        jne     kbnoaltret
1276 Lrz 1895
 
2434 Serge 1896
        mov     eax, keymap_alt
1897
        mov     ecx, 128
1898
        call    memmove
1899
        ret
802 serge 1900
kbnoaltret:
1276 Lrz 1901
;     cmp  ebx,9
2434 Serge 1902
        sub     ecx, 6
1903
        jnz     ngsyse2
1904
        movzx   eax, word [keyboard]
1905
        mov     [esp+32], eax
1906
        ret
1276 Lrz 1907
 
1908
 
802 serge 1909
ngsyse2:
1276 Lrz 1910
;         cmp  eax,3
2434 Serge 1911
        dec     ebx
1912
        jnz     ngsyse3
1913
        movzx   eax, [cd_base]
1914
        mov     [esp+32], eax
1276 Lrz 1915
        ret
802 serge 1916
ngsyse3:
1276 Lrz 1917
;         cmp  eax,5
2434 Serge 1918
        sub     ebx, 2
1919
        jnz     ngsyse5
1920
        mov     eax, [syslang]
1921
        mov     [esp+32], eax
1276 Lrz 1922
        ret
802 serge 1923
ngsyse5:
1276 Lrz 1924
;     cmp  eax,7
2434 Serge 1925
        sub     ebx, 2
1926
        jnz     ngsyse7
3908 Serge 1927
        xor     eax, eax
2434 Serge 1928
        mov     [esp+32], eax
1929
        ret
802 serge 1930
ngsyse7:
1276 Lrz 1931
;     cmp  eax,8
2434 Serge 1932
        dec     ebx
1933
        jnz     ngsyse8
1934
        mov     eax, [fat32part]
1935
        mov     [esp+32], eax
1936
        ret
802 serge 1937
ngsyse8:
1276 Lrz 1938
;     cmp  eax,9
2434 Serge 1939
        dec     ebx
1940
        jnz     ngsyse9
1941
        mov     eax, [timer_ticks];[0xfdf0]
1942
        mov     [esp+32], eax
1943
        ret
802 serge 1944
ngsyse9:
1276 Lrz 1945
;     cmp  eax,11
2434 Serge 1946
        sub     ebx, 2
1947
        jnz     ngsyse11
1948
        mov     eax, [lba_read_enabled]
1949
        mov     [esp+32], eax
1950
        ret
802 serge 1951
ngsyse11:
1276 Lrz 1952
;     cmp  eax,12
2434 Serge 1953
        dec     ebx
1954
        jnz     ngsyse12
1955
        mov     eax, [pci_access_enabled]
1956
        mov     [esp+32], eax
1957
        ret
802 serge 1958
ngsyse12:
2434 Serge 1959
        mov     [esp+32], dword 1
1960
        ret
1 ha 1961
 
1638 serge 1962
 
479 kastigar 1963
get_timer_ticks:
2434 Serge 1964
        mov     eax, [timer_ticks]
1965
        ret
479 kastigar 1966
 
283 diamond 1967
iglobal
1 ha 1968
align 4
221 serge 1969
mousefn dd msscreen, mswin, msbutton, msset
1055 Galkov 1970
        dd app_load_cursor
1971
        dd app_set_cursor
1972
        dd app_delete_cursor
1973
        dd msz
283 diamond 1974
endg
1 ha 1975
 
1976
readmousepos:
1977
 
1978
; eax=0 screen relative
1979
; eax=1 window relative
1980
; eax=2 buttons pressed
221 serge 1981
; eax=3 set mouse pos   ; reserved
1982
; eax=4 load cursor
1983
; eax=5 set cursor
1984
; eax=6 delete cursor   ; reserved
479 kastigar 1985
; eax=7 get mouse_z
1 ha 1986
 
2434 Serge 1987
        cmp     ebx, 7
1988
        ja      msset
1989
        jmp     [mousefn+ebx*4]
221 serge 1990
msscreen:
2434 Serge 1991
        mov     eax, [MOUSE_X]
1992
        shl     eax, 16
1993
        mov     ax, [MOUSE_Y]
1994
        mov     [esp+36-4], eax
1995
        ret
221 serge 1996
mswin:
2434 Serge 1997
        mov     eax, [MOUSE_X]
1998
        shl     eax, 16
1999
        mov     ax, [MOUSE_Y]
2000
        mov     esi, [TASK_BASE]
2001
        mov     bx, word [esi-twdw+WDATA.box.left]
2002
        shl     ebx, 16
2003
        mov     bx, word [esi-twdw+WDATA.box.top]
2004
        sub     eax, ebx
1 ha 2005
 
2434 Serge 2006
        mov     edi, [CURRENT_TASK]
2007
        shl     edi, 8
2008
        sub     ax, word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
2009
        rol     eax, 16
2010
        sub     ax, word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
2011
        rol     eax, 16
2012
        mov     [esp+36-4], eax
2013
        ret
221 serge 2014
msbutton:
2434 Serge 2015
        movzx   eax, byte [BTN_DOWN]
2016
        mov     [esp+36-4], eax
2017
        ret
479 kastigar 2018
msz:
2434 Serge 2019
        mov     edi, [TASK_COUNT]
2020
        movzx   edi, word [WIN_POS + edi*2]
2021
        cmp     edi, [CURRENT_TASK]
2022
        jne     @f
2023
        mov     ax, [MOUSE_SCROLL_H]
2024
        shl     eax, 16
2025
        mov     ax, [MOUSE_SCROLL_V]
2026
        mov     [esp+36-4], eax
2027
        and     [MOUSE_SCROLL_H], word 0
2028
        and     [MOUSE_SCROLL_V], word 0
2029
        ret
479 kastigar 2030
       @@:
2434 Serge 2031
        and     [esp+36-4], dword 0
1276 Lrz 2032
;           ret
221 serge 2033
msset:
2434 Serge 2034
        ret
164 serge 2035
 
221 serge 2036
app_load_cursor:
2434 Serge 2037
        cmp     ecx, OS_BASE
2038
        jae     msset
2039
        stdcall load_cursor, ecx, edx
2040
        mov     [esp+36-4], eax
2041
        ret
164 serge 2042
 
221 serge 2043
app_set_cursor:
2434 Serge 2044
        stdcall set_cursor, ecx
2045
        mov     [esp+36-4], eax
2046
        ret
1 ha 2047
 
233 serge 2048
app_delete_cursor:
2434 Serge 2049
        stdcall delete_cursor, ecx
2050
        mov     [esp+36-4], eax
2051
        ret
1 ha 2052
 
2053
is_input:
2054
 
2434 Serge 2055
        push    edx
2056
        mov     dx, word [midisp]
2057
        in      al, dx
2058
        and     al, 0x80
2059
        pop     edx
2060
        ret
1 ha 2061
 
2062
is_output:
2063
 
2434 Serge 2064
        push    edx
2065
        mov     dx, word [midisp]
2066
        in      al, dx
2067
        and     al, 0x40
2068
        pop     edx
2069
        ret
1 ha 2070
 
2071
 
2072
get_mpu_in:
2073
 
2434 Serge 2074
        push    edx
2075
        mov     dx, word [mididp]
2076
        in      al, dx
2077
        pop     edx
2078
        ret
1 ha 2079
 
2080
 
2081
put_mpu_out:
2082
 
2434 Serge 2083
        push    edx
2084
        mov     dx, word [mididp]
2085
        out     dx, al
2086
        pop     edx
2087
        ret
1 ha 2088
 
2089
 
2090
 
2091
align 4
2092
 
2093
sys_midi:
2434 Serge 2094
        cmp     [mididp], 0
2095
        jnz     sm0
2096
        mov     [esp+36], dword 1
2097
        ret
1276 Lrz 2098
sm0:
2434 Serge 2099
        and     [esp+36], dword 0
2100
        dec     ebx
2101
        jnz     smn1
1276 Lrz 2102
 ;    call setuart
2103
su1:
2434 Serge 2104
        call    is_output
2105
        test    al, al
2106
        jnz     su1
2107
        mov     dx, word [midisp]
2108
        mov     al, 0xff
2109
        out     dx, al
1276 Lrz 2110
su2:
2434 Serge 2111
        mov     dx, word [midisp]
2112
        mov     al, 0xff
2113
        out     dx, al
2114
        call    is_input
2115
        test    al, al
2116
        jnz     su2
2117
        call    get_mpu_in
2118
        cmp     al, 0xfe
2119
        jnz     su2
1276 Lrz 2120
su3:
2434 Serge 2121
        call    is_output
2122
        test    al, al
2123
        jnz     su3
2124
        mov     dx, word [midisp]
2125
        mov     al, 0x3f
2126
        out     dx, al
2127
        ret
1276 Lrz 2128
smn1:
2434 Serge 2129
        dec     ebx
2130
        jnz     smn2
1276 Lrz 2131
sm10:
2434 Serge 2132
        call    get_mpu_in
2133
        call    is_output
2134
        test    al, al
2135
        jnz     sm10
2136
        mov     al, bl
2137
        call    put_mpu_out
2138
        smn2:
2139
        ret
1 ha 2140
 
2141
detect_devices:
2142
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
769 Rus 2143
;include 'detect/commouse.inc'
479 kastigar 2144
;include 'detect/ps2mouse.inc'
1 ha 2145
;include 'detect/dev_fd.inc'
2146
;include 'detect/dev_hdcd.inc'
2147
;include 'detect/sear_par.inc'
2148
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2434 Serge 2149
        ret
1 ha 2150
 
2151
sys_end:
2434 Serge 2152
;--------------------------------------
2153
        cmp     [_display.select_cursor], 0
2154
        je      @f
2155
; restore default cursor before killing
2156
        pusha
2157
        mov     ecx, [current_slot]
2439 Serge 2158
        call    restore_default_cursor_before_killing
2434 Serge 2159
        popa
2160
@@:
2161
;--------------------------------------
3555 Serge 2162
; kill all sockets this process owns
2163
        pusha
2164
        mov     edx, [TASK_BASE]
2165
        mov     edx, [edx+TASKDATA.pid]
2166
        call    SOCKET_process_end
2167
        popa
2168
;--------------------------------------
2434 Serge 2169
        mov     ecx, [current_slot]
2170
        mov     eax, [ecx+APPDATA.tls_base]
2171
        test    eax, eax
2172
        jz      @F
1220 serge 2173
 
2434 Serge 2174
        stdcall user_free, eax
1220 serge 2175
@@:
2176
 
2434 Serge 2177
        mov     eax, [TASK_BASE]
2178
        mov     [eax+TASKDATA.state], 3; terminate this program
3555 Serge 2179
        call    wakeup_osloop
41 mikedld 2180
 
3626 Serge 2181
.waitterm:            ; wait here for termination
2182
        call    change_task
2183
        jmp     .waitterm
2439 Serge 2184
;------------------------------------------------------------------------------
2465 Serge 2185
align 4
2439 Serge 2186
restore_default_cursor_before_killing:
2987 Serge 2187
        pushfd
2188
        cli
2439 Serge 2189
        mov     eax, [def_cursor]
2190
        mov     [ecx+APPDATA.cursor], eax
1 ha 2191
 
2439 Serge 2192
        movzx   eax, word [MOUSE_Y]
2193
        movzx   ebx, word [MOUSE_X]
2465 Serge 2194
;        mov     ecx, [Screen_Max_X]
2195
;        inc     ecx
2196
;        mul     ecx
2197
        mov     eax, [d_width_calc_area + eax*4]
2198
 
2439 Serge 2199
        add     eax, [_WinMapAddress]
2200
        movzx   edx, byte [ebx+eax]
2201
        shl     edx, 8
2202
        mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
2465 Serge 2203
 
2204
        cmp     esi, [current_cursor]
2205
        je      @f
2206
 
2439 Serge 2207
        push    esi
2208
        call    [_display.select_cursor]
2209
        mov     [current_cursor], esi
2465 Serge 2210
@@:
2211
        mov     [redrawmouse_unconditional], 1
3555 Serge 2212
        call    wakeup_osloop
2987 Serge 2213
        popfd
2439 Serge 2214
        ret
2215
;------------------------------------------------------------------------------
75 diamond 2216
iglobal
170 serge 2217
align 4
75 diamond 2218
sys_system_table:
2268 Serge 2219
        dd      sysfn_deactivate        ; 1 = deactivate window
1055 Galkov 2220
        dd      sysfn_terminate         ; 2 = terminate thread
2221
        dd      sysfn_activate          ; 3 = activate window
2222
        dd      sysfn_getidletime       ; 4 = get idle time
2223
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
2224
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
2225
        dd      sysfn_getactive         ; 7 = get active window
2226
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
2227
        dd      sysfn_shutdown          ; 9 = shutdown with parameter
2228
        dd      sysfn_minimize          ; 10 = minimize window
2229
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
2230
        dd      sysfn_lastkey           ; 12 = get last pressed key
2231
        dd      sysfn_getversion        ; 13 = get kernel version
2232
        dd      sysfn_waitretrace       ; 14 = wait retrace
2233
        dd      sysfn_centermouse       ; 15 = center mouse cursor
2234
        dd      sysfn_getfreemem        ; 16 = get free memory size
2235
        dd      sysfn_getallmem         ; 17 = get total memory size
2236
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
2237
                                        ;                 instead of slot
2238
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
2239
        dd      sysfn_meminfo           ; 20 = get extended memory info
2240
        dd      sysfn_pid_to_slot       ; 21 = get slot number for pid
2241
        dd      sysfn_min_rest_window   ; 22 = minimize and restore any window
2987 Serge 2242
        dd      sysfn_min_windows       ; 23 = minimize all windows
2243
        dd      sysfn_set_screen_sizes  ; 24 = set screen sizes for Vesa
75 diamond 2244
sysfn_num = ($ - sys_system_table)/4
2245
endg
2268 Serge 2246
;------------------------------------------------------------------------------
1 ha 2247
sys_system:
1055 Galkov 2248
        dec     ebx
2249
        cmp     ebx, sysfn_num
2250
        jae     @f
2251
        jmp     dword [sys_system_table + ebx*4]
75 diamond 2252
@@:
1055 Galkov 2253
        ret
2268 Serge 2254
;------------------------------------------------------------------------------
1055 Galkov 2255
sysfn_shutdown:          ; 18.9 = system shutdown
2434 Serge 2256
        cmp     ecx, 1
2257
        jl      exit_for_anyone
2258
        cmp     ecx, 4
2259
        jg      exit_for_anyone
3908 Serge 2260
        mov     [BOOT_VARS+0x9030], cl
748 heavyiron 2261
 
2434 Serge 2262
        mov     eax, [TASK_COUNT]
2263
        mov     [SYS_SHUTDOWN], al
2264
        mov     [shutdown_processes], eax
3555 Serge 2265
        call    wakeup_osloop
2434 Serge 2266
        and     dword [esp+32], 0
748 heavyiron 2267
 exit_for_anyone:
2434 Serge 2268
        ret
1 ha 2269
  uglobal
2434 Serge 2270
   shutdown_processes:
2271
                       dd 0x0
1 ha 2272
  endg
2268 Serge 2273
;------------------------------------------------------------------------------
1055 Galkov 2274
sysfn_terminate:        ; 18.2 = TERMINATE
2987 Serge 2275
        push    ecx
2434 Serge 2276
        cmp     ecx, 2
2277
        jb      noprocessterminate
2278
        mov     edx, [TASK_COUNT]
2279
        cmp     ecx, edx
2280
        ja      noprocessterminate
2281
        mov     eax, [TASK_COUNT]
2282
        shl     ecx, 5
2283
        mov     edx, [ecx+CURRENT_TASK+TASKDATA.pid]
2284
        add     ecx, CURRENT_TASK+TASKDATA.state
2285
        cmp     byte [ecx], 9
2286
        jz      noprocessterminate
3500 Serge 2287
        push    ecx edx
2288
        lea     edx, [(ecx-(CURRENT_TASK and 1FFFFFFFh)-TASKDATA.state)*8+SLOT_BASE]
2289
        call    request_terminate
2290
        pop     edx ecx
2291
        test    eax, eax
2292
        jz      noprocessterminate
2434 Serge 2293
;--------------------------------------
3555 Serge 2294
; terminate all network sockets it used
2295
        pusha
2296
        mov     eax, edx
2297
        call    SOCKET_process_end
2298
        popa
2299
;--------------------------------------
2434 Serge 2300
        cmp     [_display.select_cursor], 0
2465 Serge 2301
        je      .restore_end
2434 Serge 2302
; restore default cursor before killing
2303
        pusha
2304
        mov     ecx, [esp+32]
2305
        shl     ecx, 8
2439 Serge 2306
        add     ecx, SLOT_BASE
2465 Serge 2307
        mov     eax, [def_cursor]
2308
        cmp     [ecx+APPDATA.cursor], eax
2309
        je      @f
2439 Serge 2310
        call    restore_default_cursor_before_killing
2465 Serge 2311
@@:
2434 Serge 2312
        popa
2465 Serge 2313
.restore_end:
2434 Serge 2314
;--------------------------------------
1 ha 2315
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2434 Serge 2316
        mov     [ecx], byte 3; clear possible i40's
3555 Serge 2317
        call    wakeup_osloop
1 ha 2318
     ;call MEM_Heap_UnLock
2319
 
3555 Serge 2320
        cmp     edx, [application_table_owner]; clear app table stat
2434 Serge 2321
        jne     noatsc
3555 Serge 2322
        call    unlock_application_table
2987 Serge 2323
noatsc:
2324
noprocessterminate:
2325
        add     esp, 4
2434 Serge 2326
        ret
2268 Serge 2327
;------------------------------------------------------------------------------
85 halyavin 2328
sysfn_terminate2:
2329
;lock application_table_status mutex
164 serge 2330
.table_status:
3555 Serge 2331
        call    lock_application_table
2434 Serge 2332
        mov     eax, ecx
2333
        call    pid_to_slot
2334
        test    eax, eax
2335
        jz      .not_found
2336
        mov     ecx, eax
2337
        cli
2338
        call    sysfn_terminate
3555 Serge 2339
        call    unlock_application_table
2434 Serge 2340
        sti
2341
        and     dword [esp+32], 0
2342
        ret
85 halyavin 2343
.not_found:
3555 Serge 2344
        call    unlock_application_table
2434 Serge 2345
        or      dword [esp+32], -1
2346
        ret
2268 Serge 2347
;------------------------------------------------------------------------------
2348
sysfn_deactivate:         ; 18.1 = DEACTIVATE WINDOW
2434 Serge 2349
        cmp     ecx, 2
2350
        jb      .nowindowdeactivate
2351
        cmp     ecx, [TASK_COUNT]
2352
        ja      .nowindowdeactivate
85 halyavin 2353
 
2434 Serge 2354
        movzx   esi, word [WIN_STACK + ecx*2]
2355
        cmp     esi, 1
2356
        je      .nowindowdeactivate ; already deactive
2268 Serge 2357
 
2434 Serge 2358
        mov     edi, ecx
2359
        shl     edi, 5
2360
        add     edi, window_data
2361
        movzx   esi, word [WIN_STACK + ecx * 2]
2362
        lea     esi, [WIN_POS + esi * 2]
2363
        call    window._.window_deactivate
2268 Serge 2364
 
2434 Serge 2365
        call    syscall_display_settings._.calculate_whole_screen
2366
        call    syscall_display_settings._.redraw_whole_screen
2268 Serge 2367
.nowindowdeactivate:
2434 Serge 2368
        ret
3500 Serge 2369
;------------------------------------------------------------------------------
1055 Galkov 2370
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2434 Serge 2371
        cmp     ecx, 2
2372
        jb      .nowindowactivate
2373
        cmp     ecx, [TASK_COUNT]
2374
        ja      .nowindowactivate
3500 Serge 2375
;-------------------------------------
2376
@@:
2377
; If the window is captured and moved by the user,
2378
; then you can't change the position in window stack!!!
2379
        mov     al, [mouse.active_sys_window.action]
2380
        and     al, WINDOW_MOVE_AND_RESIZE_FLAGS
2381
        test    al, al
2382
        jz      @f
2383
        call    change_task
2384
        jmp     @b
2385
@@:
2386
;-------------------------------------
2434 Serge 2387
        mov     [window_minimize], 2; restore window if minimized
3555 Serge 2388
        call    wakeup_osloop
105 poddubny 2389
 
2434 Serge 2390
        movzx   esi, word [WIN_STACK + ecx*2]
2391
        cmp     esi, [TASK_COUNT]
2392
        je      .nowindowactivate; already active
105 poddubny 2393
 
2434 Serge 2394
        mov     edi, ecx
2395
        shl     edi, 5
2396
        add     edi, window_data
2397
        movzx   esi, word [WIN_STACK + ecx * 2]
2398
        lea     esi, [WIN_POS + esi * 2]
2399
        call    waredraw
105 poddubny 2400
.nowindowactivate:
2434 Serge 2401
        ret
2268 Serge 2402
;------------------------------------------------------------------------------
1055 Galkov 2403
sysfn_getidletime:              ; 18.4 = GET IDLETIME
3555 Serge 2404
        mov     eax, [CURRENT_TASK+32+TASKDATA.cpu_usage]
2434 Serge 2405
        mov     [esp+32], eax
2406
        ret
2268 Serge 2407
;------------------------------------------------------------------------------
1055 Galkov 2408
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
3500 Serge 2409
        mov     eax, dword [cpu_freq]
2434 Serge 2410
        mov     [esp+32], eax
2411
        ret
2268 Serge 2412
;------------------------------------------------------------------------------
3500 Serge 2413
get_cpu_freq:
2414
        mov     eax, dword [cpu_freq]
2415
        mov     edx, dword [cpu_freq+4]
2416
        ret
1 ha 2417
;  SAVE ramdisk to /hd/1/menuet.img
2418
;!!!!!!!!!!!!!!!!!!!!!!!!
2419
   include 'blkdev/rdsave.inc'
2420
;!!!!!!!!!!!!!!!!!!!!!!!!
2268 Serge 2421
;------------------------------------------------------------------------------
1232 Lrz 2422
align 4
1055 Galkov 2423
sysfn_getactive:        ; 18.7 = get active window
2434 Serge 2424
        mov     eax, [TASK_COUNT]
2425
        movzx   eax, word [WIN_POS + eax*2]
2426
        mov     [esp+32], eax
2427
        ret
2268 Serge 2428
;------------------------------------------------------------------------------
1055 Galkov 2429
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
1232 Lrz 2430
;     cmp  ecx,1
2434 Serge 2431
        dec     ecx
2432
        jnz     nogetsoundflag
2433
        movzx   eax, byte [sound_flag]; get sound_flag
2434
        mov     [esp+32], eax
2435
        ret
1 ha 2436
 nogetsoundflag:
1232 Lrz 2437
;     cmp  ecx,2
2434 Serge 2438
        dec     ecx
2439
        jnz     nosoundflag
2440
        xor     byte [sound_flag], 1
75 diamond 2441
 nosoundflag:
2434 Serge 2442
        ret
2268 Serge 2443
;------------------------------------------------------------------------------
1055 Galkov 2444
sysfn_minimize:         ; 18.10 = minimize window
2434 Serge 2445
        mov     [window_minimize], 1
3555 Serge 2446
        call    wakeup_osloop
2434 Serge 2447
        ret
2268 Serge 2448
;------------------------------------------------------------------------------
1232 Lrz 2449
align 4
1055 Galkov 2450
sysfn_getdiskinfo:      ; 18.11 = get disk info table
1232 Lrz 2451
;     cmp  ecx,1
2434 Serge 2452
        dec     ecx
2453
        jnz     full_table
1 ha 2454
  small_table:
2434 Serge 2455
        call    for_all_tables
2456
        mov     ecx, 10
2457
        cld
2458
        rep movsb
2459
        ret
1 ha 2460
   for_all_tables:
2434 Serge 2461
        mov     edi, edx
2462
        mov     esi, DRIVE_DATA
2463
        ret
1 ha 2464
  full_table:
1232 Lrz 2465
;     cmp  ecx,2
2434 Serge 2466
        dec     ecx
2467
        jnz     exit_for_anyone
2468
        call    for_all_tables
3626 Serge 2469
        mov     ecx, DRIVE_DATA_SIZE/4
2434 Serge 2470
        cld
2471
        rep movsd
2472
        ret
2268 Serge 2473
;------------------------------------------------------------------------------
1055 Galkov 2474
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2475
        and     dword [esp+32], 0
2476
        ret
2268 Serge 2477
;------------------------------------------------------------------------------
1055 Galkov 2478
sysfn_getversion:       ; 18.13 = get kernel ID and version
2434 Serge 2479
        mov     edi, ecx
2480
        mov     esi, version_inf
2481
        mov     ecx, version_end-version_inf
2482
        rep movsb
2483
        ret
2268 Serge 2484
;------------------------------------------------------------------------------
75 diamond 2485
sysfn_waitretrace:     ; 18.14 = sys wait retrace
41 mikedld 2486
     ;wait retrace functions
2487
 sys_wait_retrace:
2434 Serge 2488
        mov     edx, 0x3da
41 mikedld 2489
 WaitRetrace_loop:
2434 Serge 2490
        in      al, dx
2491
        test    al, 1000b
2492
        jz      WaitRetrace_loop
2493
        and     [esp+32], dword 0
2494
        ret
2268 Serge 2495
;------------------------------------------------------------------------------
1232 Lrz 2496
align 4
1055 Galkov 2497
sysfn_centermouse:      ; 18.15 = mouse centered
1232 Lrz 2498
; removed here by 
2499
;     call  mouse_centered
2500
;* mouse centered - start code- Mario79
2501
;mouse_centered:
2502
;        push  eax
2434 Serge 2503
        mov     eax, [Screen_Max_X]
2504
        shr     eax, 1
2505
        mov     [MOUSE_X], ax
2506
        mov     eax, [Screen_Max_Y]
2507
        shr     eax, 1
2508
        mov     [MOUSE_Y], ax
3555 Serge 2509
        call    wakeup_osloop
1232 Lrz 2510
;        ret
2511
;* mouse centered - end code- Mario79
2434 Serge 2512
        xor     eax, eax
2513
        and     [esp+32], eax
1232 Lrz 2514
;        pop   eax
2434 Serge 2515
        ret
2268 Serge 2516
;------------------------------------------------------------------------------
1232 Lrz 2517
align 4
120 mario79 2518
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2434 Serge 2519
        test    ecx, ecx; get mouse speed factor
2520
        jnz     .set_mouse_acceleration
2521
        xor     eax, eax
2522
        mov     ax, [mouse_speed_factor]
2523
        mov     [esp+32], eax
2524
        ret
120 mario79 2525
 .set_mouse_acceleration:
1232 Lrz 2526
;     cmp  ecx,1  ; set mouse speed factor
2434 Serge 2527
        dec     ecx
2528
        jnz     .get_mouse_delay
2529
        mov     [mouse_speed_factor], dx
2530
        ret
120 mario79 2531
 .get_mouse_delay:
1232 Lrz 2532
;     cmp  ecx,2  ; get mouse delay
2434 Serge 2533
        dec     ecx
2534
        jnz     .set_mouse_delay
2535
        mov     eax, [mouse_delay]
2536
        mov     [esp+32], eax
2537
        ret
120 mario79 2538
 .set_mouse_delay:
1232 Lrz 2539
;     cmp  ecx,3  ; set mouse delay
2434 Serge 2540
        dec     ecx
2541
        jnz     .set_pointer_position
2542
        mov     [mouse_delay], edx
2543
        ret
120 mario79 2544
 .set_pointer_position:
1232 Lrz 2545
;     cmp  ecx,4  ; set mouse pointer position
2434 Serge 2546
        dec     ecx
2547
        jnz     .set_mouse_button
2548
        cmp     dx, word[Screen_Max_Y]
2549
        ja      .end
2550
        rol     edx, 16
2551
        cmp     dx, word[Screen_Max_X]
2552
        ja      .end
2553
        mov     [MOUSE_X], edx
3555 Serge 2554
        call    wakeup_osloop
2434 Serge 2555
        ret
621 mario79 2556
 .set_mouse_button:
1232 Lrz 2557
;     cmp   ecx,5  ; set mouse button features
2434 Serge 2558
        dec     ecx
2559
        jnz     .end
2560
        mov     [BTN_DOWN], dl
2561
        mov     [mouse_active], 1
3555 Serge 2562
        call    wakeup_osloop
120 mario79 2563
 .end:
2434 Serge 2564
        ret
2268 Serge 2565
;------------------------------------------------------------------------------
75 diamond 2566
sysfn_getfreemem:
2434 Serge 2567
        mov     eax, [pg_data.pages_free]
2568
        shl     eax, 2
2569
        mov     [esp+32], eax
2570
        ret
2987 Serge 2571
;------------------------------------------------------------------------------
75 diamond 2572
sysfn_getallmem:
2434 Serge 2573
        mov     eax, [MEM_AMOUNT]
2574
        shr     eax, 10
2575
        mov     [esp+32], eax
2576
        ret
2987 Serge 2577
;------------------------------------------------------------------------------
608 alver 2578
sysfn_pid_to_slot:
2434 Serge 2579
        mov     eax, ecx
2580
        call    pid_to_slot
2581
        mov     [esp+32], eax
2582
        ret
2987 Serge 2583
;------------------------------------------------------------------------------
608 alver 2584
sysfn_min_rest_window:
2434 Serge 2585
        pushad
2586
        mov     eax, edx ; ebx - operating
2587
        shr     ecx, 1
2588
        jnc     @f
2589
        call    pid_to_slot
608 alver 2590
@@:
2434 Serge 2591
        or      eax, eax ; eax - number of slot
2592
        jz      .error
2593
        cmp     eax, 255    ; varify maximal slot number
2594
        ja      .error
2595
        movzx   eax, word [WIN_STACK + eax*2]
2596
        shr     ecx, 1
2597
        jc      .restore
608 alver 2598
 ; .minimize:
2434 Serge 2599
        call    minimize_window
2600
        jmp     .exit
608 alver 2601
.restore:
2434 Serge 2602
        call    restore_minimized_window
608 alver 2603
.exit:
2434 Serge 2604
        popad
2605
        xor     eax, eax
2606
        mov     [esp+32], eax
2607
        ret
608 alver 2608
.error:
2434 Serge 2609
        popad
2610
        xor     eax, eax
2611
        dec     eax
2612
        mov     [esp+32], eax
2613
        ret
2987 Serge 2614
;------------------------------------------------------------------------------
2615
sysfn_min_windows:
2616
        call    minimize_all_window
2617
        mov     [esp+32], eax
2618
        call    change_task
2619
        ret
2620
;------------------------------------------------------------------------------
2621
sysfn_set_screen_sizes:
2622
        cmp     [SCR_MODE], word 0x13
2623
        jbe     .exit
608 alver 2624
 
2987 Serge 2625
        cmp     [_display.select_cursor], select_cursor
2626
        jne     .exit
2627
 
2628
        cmp     ecx, [display_width_standard]
2629
        ja      .exit
2630
 
2631
        cmp     edx, [display_height_standard]
2632
        ja      .exit
2633
 
2634
        pushfd
2635
        cli
2636
        mov     eax, ecx
3626 Serge 2637
        mov     ecx, [_display.pitch]
2987 Serge 2638
        mov     [_display.width], eax
2639
        dec     eax
2640
        mov     [_display.height], edx
2641
        dec     edx
2642
; eax - new Screen_Max_X
2643
; edx - new Screen_Max_Y
2644
        mov     [do_not_touch_winmap], 1
2645
        call    set_screen
2646
        mov     [do_not_touch_winmap], 0
2647
        popfd
2648
        call    change_task
2649
.exit:
2650
        ret
2651
;------------------------------------------------------------------------------
41 mikedld 2652
uglobal
2653
screen_workarea RECT
2987 Serge 2654
display_width_standard dd 0
2655
display_height_standard dd 0
2656
do_not_touch_winmap db 0
1 ha 2657
window_minimize db 0
1055 Galkov 2658
sound_flag      db 0
2987 Serge 2659
 
41 mikedld 2660
endg
1 ha 2661
 
2130 serge 2662
UID_NONE=0
2663
UID_MENUETOS=1   ;official
2664
UID_KOLIBRI=2    ;russian
2665
 
41 mikedld 2666
iglobal
2667
version_inf:
3908 Serge 2668
        db 0,7,7,0  ; version 0.7.7.0
2669
        db 0
3500 Serge 2670
.rev    dd __REV__
41 mikedld 2671
version_end:
2672
endg
2987 Serge 2673
;------------------------------------------------------------------------------
2674
align 4
1 ha 2675
sys_cachetodiskette:
1055 Galkov 2676
        cmp     ebx, 1
4287 Serge 2677
        jb      .no_floppy_save
1055 Galkov 2678
        cmp     ebx, 2
4287 Serge 2679
        ja      .no_floppy_save
1055 Galkov 2680
        call    save_image
4287 Serge 2681
        mov     [esp + 32], eax
2682
        ret
2683
.no_floppy_save:
1055 Galkov 2684
        mov     [esp + 32], dword 1
2685
        ret
2987 Serge 2686
;------------------------------------------------------------------------------
1 ha 2687
uglobal
2688
;  bgrchanged  dd  0x0
1071 diamond 2689
align 4
2690
bgrlockpid dd 0
546 diamond 2691
bgrlock db 0
1 ha 2692
endg
2987 Serge 2693
;------------------------------------------------------------------------------
2694
align 4
1 ha 2695
sys_background:
2434 Serge 2696
        cmp     ebx, 1                     ; BACKGROUND SIZE
2697
        jnz     nosb1
2698
        test    ecx, ecx
2699
        jz      sbgrr
2987 Serge 2700
 
2434 Serge 2701
        test    edx, edx
2702
        jz      sbgrr
2987 Serge 2703
;--------------------------------------
2704
align 4
546 diamond 2705
@@:
1071 diamond 2706
;;Maxis use atomic bts for mutexes  4.4.2009
2707
        bts     dword [bgrlock], 0
2708
        jnc     @f
1055 Galkov 2709
        call    change_task
2710
        jmp     @b
2987 Serge 2711
;--------------------------------------
2712
align 4
546 diamond 2713
@@:
2434 Serge 2714
        mov     [BgrDataWidth], ecx
2715
        mov     [BgrDataHeight], edx
1 ha 2716
;    mov   [bgrchanged],1
469 serge 2717
 
2434 Serge 2718
        pushad
469 serge 2719
; return memory for old background
1107 diamond 2720
        mov     eax, [img_background]
2721
        cmp     eax, static_background_data
2722
        jz      @f
2723
        stdcall kernel_free, eax
2987 Serge 2724
;--------------------------------------
2725
align 4
1107 diamond 2726
@@:
469 serge 2727
; calculate RAW size
2434 Serge 2728
        xor     eax, eax
2729
        inc     eax
2730
        cmp     [BgrDataWidth], eax
2731
        jae     @f
2732
        mov     [BgrDataWidth], eax
2987 Serge 2733
;--------------------------------------
2734
align 4
469 serge 2735
@@:
2434 Serge 2736
        cmp     [BgrDataHeight], eax
2737
        jae     @f
2738
        mov     [BgrDataHeight], eax
2987 Serge 2739
;--------------------------------------
2740
align 4
469 serge 2741
@@:
2434 Serge 2742
        mov     eax, [BgrDataWidth]
2743
        imul    eax, [BgrDataHeight]
2744
        lea     eax, [eax*3]
2465 Serge 2745
; it is reserved with aligned to the boundary of 4 KB pages,
2746
; otherwise there may be exceptions a page fault for vesa20_drawbackground_tiled
2747
; because the 32 bit read is used for  high performance: "mov eax,[esi]"
2748
        shr     eax, 12
2749
        inc     eax
2750
        shl     eax, 12
2434 Serge 2751
        mov     [mem_BACKGROUND], eax
469 serge 2752
; get memory for new background
2434 Serge 2753
        stdcall kernel_alloc, eax
2754
        test    eax, eax
2755
        jz      .memfailed
2756
        mov     [img_background], eax
2757
        jmp     .exit
2987 Serge 2758
;--------------------------------------
2759
align 4
1107 diamond 2760
.memfailed:
2761
; revert to static monotone data
2762
        mov     [img_background], static_background_data
2763
        xor     eax, eax
2764
        inc     eax
2765
        mov     [BgrDataWidth], eax
2766
        mov     [BgrDataHeight], eax
2767
        mov     [mem_BACKGROUND], 4
2987 Serge 2768
;--------------------------------------
2769
align 4
1107 diamond 2770
.exit:
2434 Serge 2771
        popad
1055 Galkov 2772
        mov     [bgrlock], 0
2987 Serge 2773
;--------------------------------------
2774
align 4
2775
sbgrr:
2434 Serge 2776
        ret
2987 Serge 2777
;------------------------------------------------------------------------------
2778
align 4
875 serge 2779
nosb1:
2434 Serge 2780
        cmp     ebx, 2                     ; SET PIXEL
2781
        jnz     nosb2
875 serge 2782
 
2434 Serge 2783
        mov     eax, [img_background]
2784
        test    ecx, ecx
2785
        jz      @f
2786
        cmp     eax, static_background_data
2787
        jz      .ret
2987 Serge 2788
;--------------------------------------
2789
align 4
1107 diamond 2790
@@:
2434 Serge 2791
        mov     ebx, [mem_BACKGROUND]
2792
        add     ebx, 4095
2793
        and     ebx, -4096
2794
        sub     ebx, 4
2795
        cmp     ecx, ebx
2796
        ja      .ret
875 serge 2797
 
2434 Serge 2798
        mov     ebx, [eax+ecx]
2799
        and     ebx, 0xFF000000;255*256*256*256
2800
        and     edx, 0x00FFFFFF;255*256*256+255*256+255
2801
        add     edx, ebx
2802
        mov     [eax+ecx], edx
2987 Serge 2803
;--------------------------------------
2804
align 4
1107 diamond 2805
.ret:
2434 Serge 2806
        ret
2987 Serge 2807
;------------------------------------------------------------------------------
2808
align 4
875 serge 2809
nosb2:
2434 Serge 2810
        cmp     ebx, 3                     ; DRAW BACKGROUND
2811
        jnz     nosb3
2987 Serge 2812
;--------------------------------------
2813
align 4
1 ha 2814
draw_background_temp:
2434 Serge 2815
        mov     [background_defined], 1
2816
        call    force_redraw_background
2987 Serge 2817
;--------------------------------------
2818
align 4
2819
nosb31:
2434 Serge 2820
        ret
2987 Serge 2821
;------------------------------------------------------------------------------
2822
align 4
2823
nosb3:
2434 Serge 2824
        cmp     ebx, 4                     ; TILED / STRETCHED
2825
        jnz     nosb4
2826
        cmp     ecx, [BgrDrawMode]
2827
        je      nosb41
2828
        mov     [BgrDrawMode], ecx
2987 Serge 2829
;--------------------------------------
2830
align 4
2831
nosb41:
2434 Serge 2832
        ret
2987 Serge 2833
;------------------------------------------------------------------------------
2834
align 4
2835
nosb4:
2434 Serge 2836
        cmp     ebx, 5                     ; BLOCK MOVE TO BGR
2837
        jnz     nosb5
2838
        cmp     [img_background], static_background_data
2839
        jnz     @f
2840
        test    edx, edx
2841
        jnz     .fin
2842
        cmp     esi, 4
2843
        ja      .fin
2987 Serge 2844
;--------------------------------------
2845
align 4
2846
@@:
1 ha 2847
  ; bughere
2434 Serge 2848
        mov     eax, ecx
2849
        mov     ebx, edx
2850
        add     ebx, [img_background];IMG_BACKGROUND
2851
        mov     ecx, esi
2852
        call    memmove
2987 Serge 2853
;--------------------------------------
2854
align 4
2855
.fin:
2434 Serge 2856
        ret
2987 Serge 2857
;------------------------------------------------------------------------------
2858
align 4
2859
nosb5:
1055 Galkov 2860
        cmp     ebx, 6
2861
        jnz     nosb6
2987 Serge 2862
;--------------------------------------
2863
align 4
1071 diamond 2864
;;Maxis use atomic bts for mutex 4.4.2009
546 diamond 2865
@@:
1073 heavyiron 2866
        bts     dword [bgrlock], 0
1071 diamond 2867
        jnc     @f
1055 Galkov 2868
        call    change_task
2869
        jmp     @b
2987 Serge 2870
;--------------------------------------
2871
align 4
546 diamond 2872
@@:
1055 Galkov 2873
        mov     eax, [CURRENT_TASK]
2874
        mov     [bgrlockpid], eax
1107 diamond 2875
        cmp     [img_background], static_background_data
2876
        jz      .nomem
1055 Galkov 2877
        stdcall user_alloc, [mem_BACKGROUND]
2878
        mov     [esp+32], eax
2879
        test    eax, eax
2880
        jz      .nomem
2881
        mov     ebx, eax
2882
        shr     ebx, 12
2883
        or      dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2884
        mov     esi, [img_background]
2885
        shr     esi, 12
2886
        mov     ecx, [mem_BACKGROUND]
2887
        add     ecx, 0xFFF
2888
        shr     ecx, 12
2987 Serge 2889
;--------------------------------------
2890
align 4
546 diamond 2891
.z:
1055 Galkov 2892
        mov     eax, [page_tabs+ebx*4]
2893
        test    al, 1
2894
        jz      @f
2895
        call    free_page
2987 Serge 2896
;--------------------------------------
2897
align 4
546 diamond 2898
@@:
1055 Galkov 2899
        mov     eax, [page_tabs+esi*4]
2900
        or      al, PG_UW
2901
        mov     [page_tabs+ebx*4], eax
2902
        mov     eax, ebx
2903
        shl     eax, 12
2904
        invlpg  [eax]
2905
        inc     ebx
2906
        inc     esi
2907
        loop    .z
2908
        ret
2987 Serge 2909
;--------------------------------------
2910
align 4
546 diamond 2911
.nomem:
1055 Galkov 2912
        and     [bgrlockpid], 0
2913
        mov     [bgrlock], 0
2987 Serge 2914
;------------------------------------------------------------------------------
2915
align 4
546 diamond 2916
nosb6:
1055 Galkov 2917
        cmp     ebx, 7
2918
        jnz     nosb7
2919
        cmp     [bgrlock], 0
2920
        jz      .err
2921
        mov     eax, [CURRENT_TASK]
2922
        cmp     [bgrlockpid], eax
2923
        jnz     .err
2924
        mov     eax, ecx
2925
        mov     ebx, ecx
2926
        shr     eax, 12
2927
        mov     ecx, [page_tabs+(eax-1)*4]
2928
        test    cl, USED_BLOCK+DONT_FREE_BLOCK
2929
        jz      .err
2930
        jnp     .err
2931
        push    eax
2932
        shr     ecx, 12
1312 diamond 2933
        dec     ecx
2987 Serge 2934
;--------------------------------------
2935
align 4
546 diamond 2936
@@:
1055 Galkov 2937
        and     dword [page_tabs+eax*4], 0
2938
        mov     edx, eax
2939
        shl     edx, 12
2434 Serge 2940
        push    eax
1055 Galkov 2941
        invlpg  [edx]
2434 Serge 2942
        pop     eax
1055 Galkov 2943
        inc     eax
2944
        loop    @b
2945
        pop     eax
2946
        and     dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2947
        stdcall user_free, ebx
2948
        mov     [esp+32], eax
2949
        and     [bgrlockpid], 0
2950
        mov     [bgrlock], 0
2951
        ret
2987 Serge 2952
;--------------------------------------
2953
align 4
546 diamond 2954
.err:
1055 Galkov 2955
        and     dword [esp+32], 0
2956
        ret
2987 Serge 2957
;------------------------------------------------------------------------------
2958
align 4
2959
nosb7:
2960
        cmp     ebx, 8
2961
        jnz     nosb8
546 diamond 2962
 
3555 Serge 2963
        mov     ecx, [current_slot]
2964
        xor     eax, eax
2965
        xchg    eax, [ecx+APPDATA.draw_bgr_x]
2987 Serge 2966
        mov     [esp + 32], eax ; eax = [left]*65536 + [right]
3555 Serge 2967
        xor     eax, eax
2968
        xchg    eax, [ecx+APPDATA.draw_bgr_y]
2987 Serge 2969
        mov     [esp + 20], eax ; ebx = [top]*65536 + [bottom]
2434 Serge 2970
        ret
2987 Serge 2971
;------------------------------------------------------------------------------
2972
align 4
2973
nosb8:
2974
        cmp     ebx, 9
2975
        jnz     nosb9
2976
; ecx = [left]*65536 + [right]
2977
; edx = [top]*65536 + [bottom]
2978
        mov     eax, [Screen_Max_X]
2979
        mov     ebx, [Screen_Max_Y]
2980
; check [right]
2981
        cmp     cx, ax
2982
        ja      .exit
2983
; check [left]
2984
        ror     ecx, 16
2985
        cmp     cx, ax
2986
        ja      .exit
2987
; check [bottom]
2988
        cmp     dx, bx
2989
        ja      .exit
2990
; check [top]
2991
        ror     edx, 16
2992
        cmp     dx, bx
2993
        ja      .exit
1 ha 2994
 
2987 Serge 2995
        movzx   eax, cx  ; [left]
2996
        movzx   ebx, dx  ; [top]
2997
 
2998
        shr     ecx, 16 ; [right]
2999
        shr     edx, 16 ; [bottom]
3000
 
3001
        mov     [background_defined], 1
3002
 
3003
        mov     [draw_data+32 + RECT.left], eax
3004
        mov     [draw_data+32 + RECT.top], ebx
3005
 
3006
        mov     [draw_data+32 + RECT.right], ecx
3007
        mov     [draw_data+32 + RECT.bottom], edx
3008
 
3009
        inc     byte[REDRAW_BACKGROUND]
3555 Serge 3010
        call    wakeup_osloop
2987 Serge 3011
;--------------------------------------
3012
align 4
3013
.exit:
3014
        ret
3015
;------------------------------------------------------------------------------
3016
align 4
3017
nosb9:
3018
        ret
3019
;------------------------------------------------------------------------------
3020
align 4
3021
uglobal
3022
  BG_Rect_X_left_right  dd   0x0
3023
  BG_Rect_Y_top_bottom  dd   0x0
3024
endg
3025
;------------------------------------------------------------------------------
3026
align 4
709 diamond 3027
force_redraw_background:
2434 Serge 3028
        and     [draw_data+32 + RECT.left], 0
3029
        and     [draw_data+32 + RECT.top], 0
3030
        push    eax ebx
3031
        mov     eax, [Screen_Max_X]
3032
        mov     ebx, [Screen_Max_Y]
3033
        mov     [draw_data+32 + RECT.right], eax
3034
        mov     [draw_data+32 + RECT.bottom], ebx
3035
        pop     ebx eax
3036
        inc     byte[REDRAW_BACKGROUND]
3555 Serge 3037
        call    wakeup_osloop
2434 Serge 3038
        ret
2987 Serge 3039
;------------------------------------------------------------------------------
1 ha 3040
align 4
3041
sys_getbackground:
1304 Lrz 3042
;    cmp   eax,1                                  ; SIZE
2434 Serge 3043
        dec     ebx
3044
        jnz     nogb1
3045
        mov     eax, [BgrDataWidth]
3046
        shl     eax, 16
3555 Serge 3047
        mov     ax, word [BgrDataHeight]
2434 Serge 3048
        mov     [esp+32], eax
3049
        ret
2987 Serge 3050
;------------------------------------------------------------------------------
3051
align 4
875 serge 3052
nogb1:
1304 Lrz 3053
;    cmp   eax,2                                  ; PIXEL
2434 Serge 3054
        dec     ebx
3055
        jnz     nogb2
875 serge 3056
 
1107 diamond 3057
        mov     eax, [img_background]
1304 Lrz 3058
        test    ecx, ecx
1107 diamond 3059
        jz      @f
3060
        cmp     eax, static_background_data
3061
        jz      .ret
2987 Serge 3062
;--------------------------------------
3063
align 4
1107 diamond 3064
@@:
2434 Serge 3065
        mov     ebx, [mem_BACKGROUND]
3066
        add     ebx, 4095
3067
        and     ebx, -4096
3068
        sub     ebx, 4
3069
        cmp     ecx, ebx
3070
        ja      .ret
875 serge 3071
 
2434 Serge 3072
        mov     eax, [ecx+eax]
469 serge 3073
 
2434 Serge 3074
        and     eax, 0xFFFFFF
3075
        mov     [esp+32], eax
2987 Serge 3076
;--------------------------------------
3077
align 4
1107 diamond 3078
.ret:
2434 Serge 3079
        ret
2987 Serge 3080
;------------------------------------------------------------------------------
3081
align 4
3082
nogb2:
1 ha 3083
 
1304 Lrz 3084
;    cmp   eax,4                                  ; TILED / STRETCHED
2434 Serge 3085
        dec     ebx
3086
        dec     ebx
3087
        jnz     nogb4
3088
        mov     eax, [BgrDrawMode]
2987 Serge 3089
;--------------------------------------
3090
align 4
3091
nogb4:
2434 Serge 3092
        mov     [esp+32], eax
3093
        ret
2987 Serge 3094
;------------------------------------------------------------------------------
1 ha 3095
align 4
3096
sys_getkey:
2434 Serge 3097
        mov     [esp + 32], dword 1
1055 Galkov 3098
        ; test main buffer
3099
        mov     ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
3100
        movzx   ecx, word [WIN_STACK + ebx * 2]
3101
        mov     edx, [TASK_COUNT]
3102
        cmp     ecx, edx
3103
        jne     .finish
3104
        cmp     [KEY_COUNT], byte 0
3105
        je      .finish
3106
        movzx   eax, byte [KEY_BUFF]
3107
        shl     eax, 8
3108
        push    eax
3109
        dec     byte [KEY_COUNT]
3110
        and     byte [KEY_COUNT], 127
3111
        movzx   ecx, byte [KEY_COUNT]
3112
        add     ecx, 2
3113
        mov     eax, KEY_BUFF + 1
3114
        mov     ebx, KEY_BUFF
3115
        call    memmove
3116
        pop     eax
2987 Serge 3117
;--------------------------------------
3118
align 4
92 diamond 3119
.ret_eax:
1055 Galkov 3120
        mov     [esp + 32], eax
3121
        ret
2987 Serge 3122
;--------------------------------------
3123
align 4
671 Ghost 3124
.finish:
92 diamond 3125
; test hotkeys buffer
1055 Galkov 3126
        mov     ecx, hotkey_buffer
2987 Serge 3127
;--------------------------------------
3128
align 4
92 diamond 3129
@@:
1055 Galkov 3130
        cmp     [ecx], ebx
3131
        jz      .found
3132
        add     ecx, 8
3133
        cmp     ecx, hotkey_buffer + 120 * 8
3134
        jb      @b
3135
        ret
2987 Serge 3136
;--------------------------------------
3137
align 4
92 diamond 3138
.found:
1055 Galkov 3139
        mov     ax, [ecx + 6]
3140
        shl     eax, 16
3141
        mov     ah, [ecx + 4]
3142
        mov     al, 2
3143
        and     dword [ecx + 4], 0
3144
        and     dword [ecx], 0
3145
        jmp     .ret_eax
2987 Serge 3146
;------------------------------------------------------------------------------
1 ha 3147
align 4
3148
sys_getbutton:
1055 Galkov 3149
        mov     ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
3150
        mov     [esp + 32], dword 1
3151
        movzx   ecx, word [WIN_STACK + ebx * 2]
3152
        mov     edx, [TASK_COUNT] ; less than 256 processes
3153
        cmp     ecx, edx
3154
        jne     .exit
3155
        movzx   eax, byte [BTN_COUNT]
3156
        test    eax, eax
3157
        jz      .exit
3158
        mov     eax, [BTN_BUFF]
1391 mikedld 3159
        and     al, 0xFE                                    ; delete left button bit
1055 Galkov 3160
        mov     [BTN_COUNT], byte 0
3161
        mov     [esp + 32], eax
2987 Serge 3162
;--------------------------------------
3163
align 4
671 Ghost 3164
.exit:
1055 Galkov 3165
        ret
2987 Serge 3166
;------------------------------------------------------------------------------
1 ha 3167
align 4
3168
sys_cpuusage:
3169
 
3170
;  RETURN:
3171
;
3172
;  +00 dword     process cpu usage
3173
;  +04  word     position in windowing stack
3174
;  +06  word     windowing stack value at current position (cpu nro)
3175
;  +10 12 bytes  name
3176
;  +22 dword     start in mem
3177
;  +26 dword     used mem
3178
;  +30 dword     PID , process idenfification number
3179
;
3180
 
2434 Serge 3181
        cmp     ecx, -1 ; who am I ?
3182
        jne     .no_who_am_i
3183
        mov     ecx, [CURRENT_TASK]
684 diamond 3184
  .no_who_am_i:
1055 Galkov 3185
        cmp     ecx, max_processes
3186
        ja      .nofillbuf
1 ha 3187
 
684 diamond 3188
; +4: word: position of the window of thread in the window stack
1055 Galkov 3189
        mov     ax, [WIN_STACK + ecx * 2]
3190
        mov     [ebx+4], ax
684 diamond 3191
; +6: word: number of the thread slot, which window has in the window stack
3192
;           position ecx (has no relation to the specific thread)
1055 Galkov 3193
        mov     ax, [WIN_POS + ecx * 2]
3194
        mov     [ebx+6], ax
1 ha 3195
 
1055 Galkov 3196
        shl     ecx, 5
1 ha 3197
 
684 diamond 3198
; +0: dword: memory usage
1055 Galkov 3199
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
3200
        mov     [ebx], eax
684 diamond 3201
; +10: 11 bytes: name of the process
1055 Galkov 3202
        push    ecx
3203
        lea     eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
3204
        add     ebx, 10
3205
        mov     ecx, 11
3206
        call    memmove
3207
        pop     ecx
1 ha 3208
 
684 diamond 3209
; +22: address of the process in memory
3210
; +26: size of used memory - 1
1055 Galkov 3211
        push    edi
3212
        lea     edi, [ebx+12]
3213
        xor     eax, eax
3214
        mov     edx, 0x100000*16
3215
        cmp     ecx, 1 shl 5
3216
        je      .os_mem
3217
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
3218
        mov     eax, std_application_base_address
684 diamond 3219
.os_mem:
1055 Galkov 3220
        stosd
3221
        lea     eax, [edx-1]
3222
        stosd
1 ha 3223
 
684 diamond 3224
; +30: PID/TID
1055 Galkov 3225
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
3226
        stosd
1 ha 3227
 
3228
    ; window position and size
1055 Galkov 3229
        push    esi
3230
        lea     esi, [ecx + window_data + WDATA.box]
3231
        movsd
3232
        movsd
3233
        movsd
3234
        movsd
1 ha 3235
 
3236
    ; Process state (+50)
1055 Galkov 3237
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
3238
        stosd
1 ha 3239
 
138 mikedld 3240
    ; Window client area box
1055 Galkov 3241
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
3242
        movsd
3243
        movsd
3244
        movsd
3245
        movsd
1 ha 3246
 
164 serge 3247
    ; Window state
1055 Galkov 3248
        mov     al, [ecx+window_data+WDATA.fl_wstate]
3249
        stosb
164 serge 3250
 
2010 serge 3251
    ; Event mask (+71)
3252
        mov     EAX, dword [ECX+CURRENT_TASK+TASKDATA.event_mask]
3253
        stosd
3254
 
4265 Serge 3255
    ; Keyboard mode (+75)
3256
        mov     al, byte [ecx*8 + SLOT_BASE + APPDATA.keyboard_mode]
4287 Serge 3257
        stosb
4265 Serge 3258
 
1055 Galkov 3259
        pop     esi
3260
        pop     edi
138 mikedld 3261
 
684 diamond 3262
.nofillbuf:
1 ha 3263
    ; return number of processes
3264
 
2434 Serge 3265
        mov     eax, [TASK_COUNT]
3266
        mov     [esp+32], eax
3267
        ret
1 ha 3268
 
3269
align 4
3270
sys_clock:
1055 Galkov 3271
        cli
1 ha 3272
  ; Mikhail Lisovin  xx Jan 2005
3273
  @@:
2434 Serge 3274
        mov     al, 10
3275
        out     0x70, al
3276
        in      al, 0x71
3277
        test    al, al
3278
        jns     @f
3279
        mov     esi, 1
3280
        call    delay_ms
3281
        jmp     @b
3282
  @@:
1 ha 3283
  ; end Lisovin's fix
3284
 
2434 Serge 3285
        xor     al, al        ; seconds
3286
        out     0x70, al
3287
        in      al, 0x71
3288
        movzx   ecx, al
3289
        mov     al, 02        ; minutes
3290
        shl     ecx, 16
3291
        out     0x70, al
3292
        in      al, 0x71
3293
        movzx   edx, al
3294
        mov     al, 04        ; hours
3295
        shl     edx, 8
3296
        out     0x70, al
3297
        in      al, 0x71
3298
        add     ecx, edx
3299
        movzx   edx, al
3300
        add     ecx, edx
1055 Galkov 3301
        sti
3302
        mov     [esp + 32], ecx
3303
        ret
1 ha 3304
 
3305
 
3306
align 4
3307
 
3308
sys_date:
3309
 
1055 Galkov 3310
        cli
75 diamond 3311
  @@:
2434 Serge 3312
        mov     al, 10
3313
        out     0x70, al
3314
        in      al, 0x71
3315
        test    al, al
3316
        jns     @f
3317
        mov     esi, 1
3318
        call    delay_ms
3319
        jmp     @b
3320
  @@:
75 diamond 3321
 
2434 Serge 3322
        mov     ch, 0
3323
        mov     al, 7           ; date
3324
        out     0x70, al
3325
        in      al, 0x71
3326
        mov     cl, al
3327
        mov     al, 8           ; month
3328
        shl     ecx, 16
3329
        out     0x70, al
3330
        in      al, 0x71
3331
        mov     ch, al
3332
        mov     al, 9           ; year
3333
        out     0x70, al
3334
        in      al, 0x71
3335
        mov     cl, al
1055 Galkov 3336
        sti
3337
        mov     [esp+32], ecx
3338
        ret
1 ha 3339
 
3340
 
3341
; redraw status
3342
 
3343
sys_redrawstat:
1055 Galkov 3344
        cmp     ebx, 1
3345
        jne     no_widgets_away
3346
        ; buttons away
2434 Serge 3347
        mov     ecx, [CURRENT_TASK]
1 ha 3348
  sys_newba2:
2434 Serge 3349
        mov     edi, [BTN_ADDR]
1055 Galkov 3350
        cmp     [edi], dword 0  ; empty button list ?
3351
        je      end_of_buttons_away
3352
        movzx   ebx, word [edi]
3353
        inc     ebx
2434 Serge 3354
        mov     eax, edi
1 ha 3355
  sys_newba:
1055 Galkov 3356
        dec     ebx
3357
        jz      end_of_buttons_away
1 ha 3358
 
1055 Galkov 3359
        add     eax, 0x10
3360
        cmp     cx, [eax]
3361
        jnz     sys_newba
1 ha 3362
 
1055 Galkov 3363
        push    eax ebx ecx
2434 Serge 3364
        mov     ecx, ebx
1055 Galkov 3365
        inc     ecx
3366
        shl     ecx, 4
3367
        mov     ebx, eax
3368
        add     eax, 0x10
3369
        call    memmove
3370
        dec     dword [edi]
3371
        pop     ecx ebx eax
1 ha 3372
 
1055 Galkov 3373
        jmp     sys_newba2
1 ha 3374
 
3375
  end_of_buttons_away:
3376
 
1055 Galkov 3377
        ret
1 ha 3378
 
3379
  no_widgets_away:
3380
 
1055 Galkov 3381
        cmp     ebx, 2
3382
        jnz     srl1
1 ha 3383
 
1055 Galkov 3384
        mov     edx, [TASK_BASE]      ; return whole screen draw area for this app
3385
        add     edx, draw_data - CURRENT_TASK
3386
        mov     [edx + RECT.left], 0
3387
        mov     [edx + RECT.top], 0
3388
        mov     eax, [Screen_Max_X]
3389
        mov     [edx + RECT.right], eax
3390
        mov     eax, [Screen_Max_Y]
3391
        mov     [edx + RECT.bottom], eax
1 ha 3392
 
3393
  srl1:
1055 Galkov 3394
        ret
1 ha 3395
 
3396
;ok - 100% work
3397
;nt - not tested
3398
;---------------------------------------------------------------------------------------------
3399
;eax
3400
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3401
;1 - change task. Ret nothing. Block. ok.
3402
;2 - performance control
3403
; ebx
3404
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3405
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3406
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3407
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3408
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3409
;eax
3410
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3411
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3412
;---------------------------------------------------------------------------------------------
1344 Lrz 3413
iglobal
3414
align 4
3415
sheduler:
2434 Serge 3416
        dd      sys_sheduler.00
3417
        dd      change_task
3418
        dd      sys_sheduler.02
3419
        dd      sys_sheduler.03
3420
        dd      sys_sheduler.04
1344 Lrz 3421
endg
1638 serge 3422
sys_sheduler:
1344 Lrz 3423
;rewritten by   29.12.2009
2434 Serge 3424
        jmp     dword [sheduler+ebx*4]
1344 Lrz 3425
;.shed_counter:
3426
.00:
2434 Serge 3427
        mov     eax, [context_counter]
3428
        mov     [esp+32], eax
3429
        ret
1273 Lrz 3430
 
1344 Lrz 3431
.02:
3432
;.perf_control:
2434 Serge 3433
        inc     ebx                     ;before ebx=2, ebx=3
3434
        cmp     ebx, ecx                ;if ecx=3, ebx=3
3435
        jz      cache_disable
1365 Lrz 3436
 
2434 Serge 3437
        dec     ebx                     ;ebx=2
3438
        cmp     ebx, ecx                ;
3439
        jz      cache_enable            ;if ecx=2 and ebx=2
1365 Lrz 3440
 
2434 Serge 3441
        dec     ebx                     ;ebx=1
3442
        cmp     ebx, ecx
3443
        jz      is_cache_enabled        ;if ecx=1 and ebx=1
1365 Lrz 3444
 
2434 Serge 3445
        dec     ebx
3446
        test    ebx, ecx                ;ebx=0 and ecx=0
3447
        jz      modify_pce              ;if ecx=0
1365 Lrz 3448
 
2434 Serge 3449
        ret
1345 Lrz 3450
 
1638 serge 3451
.03:
1344 Lrz 3452
;.rdmsr_instr:
3453
;now counter in ecx
3454
;(edx:eax) esi:edi => edx:esi
2434 Serge 3455
        mov     eax, esi
3456
        mov     ecx, edx
3457
        rdmsr
3458
        mov     [esp+32], eax
3459
        mov     [esp+20], edx           ;ret in ebx?
3460
        ret
1344 Lrz 3461
 
3462
.04:
1273 Lrz 3463
;.wrmsr_instr:
3464
;now counter in ecx
3465
;(edx:eax) esi:edi => edx:esi
3466
        ; Fast Call MSR can't be destroy
3555 Serge 3467
        ; Но MSR_AMD_EFER можно изменять, т.к. в этом регистре лиш
3468
        ; включаются/выключаются расширенные возможности
2434 Serge 3469
        cmp     edx, MSR_SYSENTER_CS
1273 Lrz 3470
        je      @f
2434 Serge 3471
        cmp     edx, MSR_SYSENTER_ESP
1273 Lrz 3472
        je      @f
2434 Serge 3473
        cmp     edx, MSR_SYSENTER_EIP
1273 Lrz 3474
        je      @f
2434 Serge 3475
        cmp     edx, MSR_AMD_STAR
1273 Lrz 3476
        je      @f
3477
 
2434 Serge 3478
        mov     eax, esi
3479
        mov     ecx, edx
1273 Lrz 3480
        wrmsr
1344 Lrz 3481
        ; mov   [esp + 32], eax
3482
        ; mov   [esp + 20], edx ;ret in ebx?
1273 Lrz 3483
@@:
2434 Serge 3484
        ret
1273 Lrz 3485
 
1 ha 3486
cache_disable:
2434 Serge 3487
        mov     eax, cr0
3488
        or      eax, 01100000000000000000000000000000b
3489
        mov     cr0, eax
3490
        wbinvd  ;set MESI
3491
        ret
1 ha 3492
 
3493
cache_enable:
2434 Serge 3494
        mov     eax, cr0
3495
        and     eax, 10011111111111111111111111111111b
3496
        mov     cr0, eax
3497
        ret
1 ha 3498
 
3499
is_cache_enabled:
2434 Serge 3500
        mov     eax, cr0
3501
        mov     ebx, eax
3502
        and     eax, 01100000000000000000000000000000b
3503
        jz      cache_disabled
3504
        mov     [esp+32], ebx
1 ha 3505
cache_disabled:
2434 Serge 3506
        mov     dword [esp+32], eax;0
3507
        ret
1 ha 3508
 
3509
modify_pce:
2434 Serge 3510
        mov     eax, cr4
1 ha 3511
;       mov ebx,0
3512
;       or  bx,100000000b ;pce
3513
;       xor eax,ebx ;invert pce
2434 Serge 3514
        bts     eax, 8;pce=cr4[8]
3515
        mov     cr4, eax
3516
        mov     [esp+32], eax
3517
        ret
1 ha 3518
;---------------------------------------------------------------------------------------------
3519
 
3520
 
3521
; check if pixel is allowed to be drawn
3522
 
2465 Serge 3523
;checkpixel:
3524
;        push    eax edx
1 ha 3525
 
2465 Serge 3526
;;        mov     edx, [Screen_Max_X] ; screen x size
3527
;;        inc     edx
3528
;;        imul    edx, ebx
3529
;        mov     edx, [d_width_calc_area + ebx*4]
3530
;        add     eax, [_WinMapAddress]
3531
;        mov     dl, [eax+edx]; lea eax, [...]
1 ha 3532
 
2465 Serge 3533
;        xor     ecx, ecx
3534
;        mov     eax, [CURRENT_TASK]
3535
;        cmp     al, dl
3536
;        setne   cl
1 ha 3537
 
2465 Serge 3538
;        pop     edx eax
3539
;        ret
1 ha 3540
 
3541
iglobal
521 diamond 3542
  cpustring db 'CPU',0
1 ha 3543
endg
3544
 
67 diamond 3545
uglobal
1055 Galkov 3546
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3547
endg
2987 Serge 3548
;-----------------------------------------------------------------------------
1 ha 3549
align 4
3550
checkmisc:
2434 Serge 3551
        cmp     [ctrl_alt_del], 1
3552
        jne     nocpustart
501 serge 3553
 
1055 Galkov 3554
        mov     ebp, cpustring
3555
        call    fs_execute_from_sysdir
501 serge 3556
 
2434 Serge 3557
        mov     [ctrl_alt_del], 0
2987 Serge 3558
;--------------------------------------
3559
align 4
465 serge 3560
nocpustart:
2434 Serge 3561
        cmp     [mouse_active], 1
3562
        jne     mouse_not_active
3563
        mov     [mouse_active], 0
1 ha 3564
 
2434 Serge 3565
        xor     edi, edi
3566
        mov     ebx, CURRENT_TASK
3567
 
3568
        mov     ecx, [TASK_COUNT]
3569
        movzx   eax, word [WIN_POS + ecx*2]     ; active window
3570
        shl     eax, 8
3571
        push    eax
3572
 
3573
        movzx   eax, word [MOUSE_X]
3574
        movzx   edx, word [MOUSE_Y]
2987 Serge 3575
;--------------------------------------
2434 Serge 3576
align 4
3577
.set_mouse_event:
3578
        add     edi, 256
3579
        add     ebx, 32
3580
        test    [ebx+TASKDATA.event_mask], 0x80000000
3581
        jz      .pos_filter
3582
 
3583
        cmp     edi, [esp]                      ; skip if filtration active
3584
        jne     .skip
2987 Serge 3585
;--------------------------------------
3586
align 4
2434 Serge 3587
.pos_filter:
3588
        test    [ebx+TASKDATA.event_mask], 0x40000000
3589
        jz      .set
3590
 
3591
        mov     esi, [ebx-twdw+WDATA.box.left]
3592
        cmp     eax, esi
3593
        jb      .skip
3594
        add     esi, [ebx-twdw+WDATA.box.width]
3595
        cmp     eax, esi
3596
        ja      .skip
3597
 
3598
        mov     esi, [ebx-twdw+WDATA.box.top]
3599
        cmp     edx, esi
3600
        jb      .skip
3601
        add     esi, [ebx-twdw+WDATA.box.height]
3602
        cmp     edx, esi
3603
        ja      .skip
2987 Serge 3604
;--------------------------------------
3605
align 4
2434 Serge 3606
.set:
2987 Serge 3607
        or      [edi+SLOT_BASE+APPDATA.event_mask], 100000b  ; set event 6
3608
;--------------------------------------
3609
align 4
2434 Serge 3610
.skip:
3611
        loop    .set_mouse_event
3612
 
3613
        pop     eax
2987 Serge 3614
;--------------------------------------
3615
align 4
465 serge 3616
mouse_not_active:
2434 Serge 3617
        cmp     byte[REDRAW_BACKGROUND], 0         ; background update ?
3618
        jz      nobackgr
2987 Serge 3619
 
2434 Serge 3620
        cmp     [background_defined], 0
3621
        jz      nobackgr
2987 Serge 3622
;--------------------------------------
3623
align 4
3555 Serge 3624
backgr:
2987 Serge 3625
        mov     eax, [draw_data+32 + RECT.left]
3626
        shl     eax, 16
3627
        add     eax, [draw_data+32 + RECT.right]
3628
        mov     [BG_Rect_X_left_right], eax ; [left]*65536 + [right]
3629
 
3630
        mov     eax, [draw_data+32 + RECT.top]
3631
        shl     eax, 16
3632
        add     eax, [draw_data+32 + RECT.bottom]
3633
        mov     [BG_Rect_Y_top_bottom], eax ; [top]*65536 + [bottom]
3634
 
2434 Serge 3635
        call    drawbackground
2987 Serge 3636
;        DEBUGF  1, "K : drawbackground\n"
3637
;        DEBUGF  1, "K : backg x %x\n",[BG_Rect_X_left_right]
3638
;        DEBUGF  1, "K : backg y %x\n",[BG_Rect_Y_top_bottom]
3639
;--------- set event 5 start ----------
3640
        push    ecx edi
3641
        xor     edi, edi
3642
        mov     ecx, [TASK_COUNT]
3643
;--------------------------------------
3644
align 4
3645
set_bgr_event:
3646
        add     edi, 256
3555 Serge 3647
        mov     eax, [BG_Rect_X_left_right]
3648
        mov     edx, [BG_Rect_Y_top_bottom]
3649
        cmp     [edi+SLOT_BASE+APPDATA.draw_bgr_x], 0
3650
        jz      .set
3651
.join:
3626 Serge 3652
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_x], ax
3653
        jae     @f
3654
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_x], ax
3655
@@:
3656
        shr     eax, 16
3555 Serge 3657
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_x+2], ax
3658
        jbe     @f
3659
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_x+2], ax
3660
@@:
3626 Serge 3661
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3555 Serge 3662
        jae     @f
3626 Serge 3663
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3555 Serge 3664
@@:
3626 Serge 3665
        shr     edx, 16
3555 Serge 3666
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_y+2], dx
3667
        jbe     @f
3668
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_y+2], dx
3669
@@:
3670
        jmp     .common
3671
.set:
3672
        mov     [edi+SLOT_BASE+APPDATA.draw_bgr_x], eax
3673
        mov     [edi+SLOT_BASE+APPDATA.draw_bgr_y], edx
3674
.common:
2987 Serge 3675
        or      [edi+SLOT_BASE+APPDATA.event_mask], 10000b  ; set event 5
3676
        loop    set_bgr_event
3677
        pop     edi ecx
3678
;--------- set event 5 stop -----------
3679
        dec     byte[REDRAW_BACKGROUND]    ; got new update request?
3555 Serge 3680
        jnz     backgr
2987 Serge 3681
 
3555 Serge 3682
        xor     eax, eax
2434 Serge 3683
        mov     [draw_data+32 + RECT.left], eax
3684
        mov     [draw_data+32 + RECT.top], eax
3685
        mov     [draw_data+32 + RECT.right], eax
3686
        mov     [draw_data+32 + RECT.bottom], eax
2987 Serge 3687
;--------------------------------------
3688
align 4
465 serge 3689
nobackgr:
2987 Serge 3690
; system shutdown request
2434 Serge 3691
        cmp     [SYS_SHUTDOWN], byte 0
3692
        je      noshutdown
1 ha 3693
 
2434 Serge 3694
        mov     edx, [shutdown_processes]
1 ha 3695
 
2434 Serge 3696
        cmp     [SYS_SHUTDOWN], dl
3500 Serge 3697
        jne     noshutdown
1 ha 3698
 
2434 Serge 3699
        lea     ecx, [edx-1]
3700
        mov     edx, OS_BASE+0x3040
3500 Serge 3701
        jecxz   no_mark_system_shutdown
2987 Serge 3702
;--------------------------------------
3703
align 4
465 serge 3704
markz:
3500 Serge 3705
        push    ecx edx
3706
        cmp     [edx+TASKDATA.state], 9
3707
        jz      .nokill
3708
        lea     edx, [(edx-(CURRENT_TASK and 1FFFFFFFh))*8+SLOT_BASE]
3709
        cmp     [edx+APPDATA.dir_table], sys_pgdir - OS_BASE
3710
        jz      .nokill
3711
        call    request_terminate
3712
        jmp     .common
3713
.nokill:
3714
        dec     byte [SYS_SHUTDOWN]
3715
        xor     eax, eax
3716
.common:
3717
        pop     edx ecx
3718
        test    eax, eax
3719
        jz      @f
2434 Serge 3720
        mov     [edx+TASKDATA.state], byte 3
3500 Serge 3721
@@:
2434 Serge 3722
        add     edx, 0x20
3723
        loop    markz
3555 Serge 3724
        call    wakeup_osloop
2987 Serge 3725
;--------------------------------------
3726
align 4
709 diamond 3727
@@:
2987 Serge 3728
no_mark_system_shutdown:
2434 Serge 3729
        dec     byte [SYS_SHUTDOWN]
3730
        je      system_shutdown
2987 Serge 3731
;--------------------------------------
3732
align 4
465 serge 3733
noshutdown:
2434 Serge 3734
        mov     eax, [TASK_COUNT]           ; termination
3735
        mov     ebx, TASK_DATA+TASKDATA.state
3736
        mov     esi, 1
2987 Serge 3737
;--------------------------------------
3738
align 4
465 serge 3739
newct:
2434 Serge 3740
        mov     cl, [ebx]
3741
        cmp     cl, byte 3
3500 Serge 3742
        jz      .terminate
2987 Serge 3743
 
2434 Serge 3744
        cmp     cl, byte 4
3500 Serge 3745
        jnz     .noterminate
3746
.terminate:
3747
        pushad
3748
        mov     ecx, eax
3749
        shl     ecx, 8
3750
        add     ecx, SLOT_BASE
3751
        call    restore_default_cursor_before_killing
3752
        popad
1 ha 3753
 
3500 Serge 3754
        pushad
3755
        call    terminate
3756
        popad
3757
        cmp     byte [SYS_SHUTDOWN], 0
3758
        jz      .noterminate
3759
        dec     byte [SYS_SHUTDOWN]
3760
        je      system_shutdown
3761
 
3762
.noterminate:
2434 Serge 3763
        add     ebx, 0x20
3764
        inc     esi
3765
        dec     eax
3766
        jnz     newct
3767
        ret
2987 Serge 3768
;-----------------------------------------------------------------------------
3769
align 4
1 ha 3770
redrawscreen:
3771
; eax , if process window_data base is eax, do not set flag/limits
3772
 
2434 Serge 3773
        pushad
3774
        push    eax
1 ha 3775
 
684 diamond 3776
;;;         mov   ebx,2
1 ha 3777
;;;         call  delay_hs
3778
 
1055 Galkov 3779
         ;mov   ecx,0               ; redraw flags for apps
2434 Serge 3780
        xor     ecx, ecx
2987 Serge 3781
;--------------------------------------
3782
align 4
3783
newdw2:
2434 Serge 3784
        inc     ecx
3785
        push    ecx
1 ha 3786
 
2434 Serge 3787
        mov     eax, ecx
3788
        shl     eax, 5
3789
        add     eax, window_data
1 ha 3790
 
2434 Serge 3791
        cmp     eax, [esp+4]
3792
        je      not_this_task
1055 Galkov 3793
                                   ; check if window in redraw area
2434 Serge 3794
        mov     edi, eax
1 ha 3795
 
2434 Serge 3796
        cmp     ecx, 1             ; limit for background
3797
        jz      bgli
1 ha 3798
 
2434 Serge 3799
        mov     eax, [edi + WDATA.box.left]
3800
        mov     ebx, [edi + WDATA.box.top]
1 ha 3801
 
2434 Serge 3802
        mov     ecx, [draw_limits.bottom] ; ecx = area y end     ebx = window y start
3803
        cmp     ecx, ebx
3804
        jb      ricino
1 ha 3805
 
2434 Serge 3806
        mov     ecx, [draw_limits.right] ; ecx = area x end     eax = window x start
3807
        cmp     ecx, eax
3808
        jb      ricino
1 ha 3809
 
2434 Serge 3810
        mov     eax, [edi + WDATA.box.left]
3811
        mov     ebx, [edi + WDATA.box.top]
3812
        mov     ecx, [edi + WDATA.box.width]
3813
        mov     edx, [edi + WDATA.box.height]
3814
        add     ecx, eax
3815
        add     edx, ebx
164 serge 3816
 
2434 Serge 3817
        mov     eax, [draw_limits.top]  ; eax = area y start     edx = window y end
3818
        cmp     edx, eax
3819
        jb      ricino
1 ha 3820
 
2434 Serge 3821
        mov     eax, [draw_limits.left]  ; eax = area x start     ecx = window x end
3822
        cmp     ecx, eax
3823
        jb      ricino
2987 Serge 3824
;--------------------------------------
3825
align 4
3826
bgli:
2434 Serge 3827
        cmp     dword[esp], 1
3828
        jnz     .az
2987 Serge 3829
 
2434 Serge 3830
        cmp     byte[REDRAW_BACKGROUND], 0
3831
        jz      .az
2987 Serge 3832
 
2434 Serge 3833
        mov     dl, 0
3834
        lea     eax, [edi+draw_data-window_data]
3835
        mov     ebx, [draw_limits.left]
3836
        cmp     ebx, [eax+RECT.left]
3837
        jae     @f
2987 Serge 3838
 
2434 Serge 3839
        mov     [eax+RECT.left], ebx
3840
        mov     dl, 1
2987 Serge 3841
;--------------------------------------
3842
align 4
3843
@@:
2434 Serge 3844
        mov     ebx, [draw_limits.top]
3845
        cmp     ebx, [eax+RECT.top]
3846
        jae     @f
2987 Serge 3847
 
2434 Serge 3848
        mov     [eax+RECT.top], ebx
3849
        mov     dl, 1
2987 Serge 3850
;--------------------------------------
3851
align 4
3852
@@:
2434 Serge 3853
        mov     ebx, [draw_limits.right]
3854
        cmp     ebx, [eax+RECT.right]
3855
        jbe     @f
2987 Serge 3856
 
2434 Serge 3857
        mov     [eax+RECT.right], ebx
3858
        mov     dl, 1
2987 Serge 3859
;--------------------------------------
3860
align 4
3861
@@:
2434 Serge 3862
        mov     ebx, [draw_limits.bottom]
3863
        cmp     ebx, [eax+RECT.bottom]
3864
        jbe     @f
2987 Serge 3865
 
2434 Serge 3866
        mov     [eax+RECT.bottom], ebx
3867
        mov     dl, 1
2987 Serge 3868
;--------------------------------------
3869
align 4
3870
@@:
2434 Serge 3871
        add     byte[REDRAW_BACKGROUND], dl
3555 Serge 3872
        call    wakeup_osloop
2434 Serge 3873
        jmp     newdw8
2987 Serge 3874
;--------------------------------------
3875
align 4
3876
.az:
2434 Serge 3877
        mov     eax, edi
3878
        add     eax, draw_data-window_data
1 ha 3879
 
2434 Serge 3880
        mov     ebx, [draw_limits.left]        ; set limits
3881
        mov     [eax + RECT.left], ebx
3882
        mov     ebx, [draw_limits.top]
3883
        mov     [eax + RECT.top], ebx
3884
        mov     ebx, [draw_limits.right]
3885
        mov     [eax + RECT.right], ebx
3886
        mov     ebx, [draw_limits.bottom]
3887
        mov     [eax + RECT.bottom], ebx
1 ha 3888
 
2434 Serge 3889
        sub     eax, draw_data-window_data
1 ha 3890
 
2434 Serge 3891
        cmp     dword [esp], 1
3892
        jne     nobgrd
3893
        inc     byte[REDRAW_BACKGROUND]
3555 Serge 3894
        call    wakeup_osloop
2987 Serge 3895
;--------------------------------------
3896
align 4
3897
newdw8:
3898
nobgrd:
4265 Serge 3899
;--------------------------------------
3900
        push    eax  edi ebp
3901
        mov     edi, [esp+12]
3902
        cmp     edi, 1
3903
        je      .found
1 ha 3904
 
4265 Serge 3905
        mov     eax, [draw_limits.left]
3906
        mov     ebx, [draw_limits.top]
3907
        mov     ecx, [draw_limits.right]
3908
        sub     ecx, eax
3909
        test    ecx, ecx
3910
        jz      .not_found
3911
 
3912
        mov     edx, [draw_limits.bottom]
3913
        sub     edx, ebx
3914
        test    edx, edx
3915
        jz      .not_found
3916
 
3917
; eax - x, ebx - y
3918
; ecx - size x, edx - size y
3919
        add     ebx, edx
3920
;--------------------------------------
3921
align 4
3922
.start_y:
3923
        push    ecx
3924
;--------------------------------------
3925
align 4
3926
.start_x:
3927
        add     eax, ecx
3928
        mov     ebp, [d_width_calc_area + ebx*4]
3929
        add     ebp, [_WinMapAddress]
3930
        movzx   ebp, byte[eax+ebp] ; get value for current point
3931
        cmp     ebp, edi
3932
        jne     @f
3933
 
3934
        pop     ecx
3935
        jmp     .found
3936
;--------------------------------------
3937
align 4
3938
@@:
3939
        sub     eax, ecx
3940
 
3941
        dec     ecx
3942
        jnz     .start_x
3943
 
3944
        pop     ecx
3945
        dec     ebx
3946
        dec     edx
3947
        jnz     .start_y
3948
;--------------------------------------
3949
align 4
3950
.not_found:
3951
        pop     ebp edi eax
3952
        jmp     ricino
3953
;--------------------------------------
3954
align 4
3955
.found:
3956
        pop     ebp edi eax
3957
 
2434 Serge 3958
        mov     [eax + WDATA.fl_redraw], byte 1  ; mark as redraw
2987 Serge 3959
;--------------------------------------
3960
align 4
3961
ricino:
3962
not_this_task:
2434 Serge 3963
        pop     ecx
1 ha 3964
 
2434 Serge 3965
        cmp     ecx, [TASK_COUNT]
3966
        jle     newdw2
1 ha 3967
 
2434 Serge 3968
        pop     eax
3969
        popad
3970
        ret
2987 Serge 3971
;-----------------------------------------------------------------------------
3972
align 4
1 ha 3973
calculatebackground:   ; background
2434 Serge 3974
        mov     edi, [_WinMapAddress]              ; set os to use all pixels
3975
        mov     eax, 0x01010101
3976
        mov     ecx, [_WinMapSize]
3977
        shr     ecx, 2
3978
        rep stosd
1 ha 3979
 
2434 Serge 3980
        mov     byte[REDRAW_BACKGROUND], 0            ; do not draw background!
1055 Galkov 3981
        ret
2987 Serge 3982
;-----------------------------------------------------------------------------
1 ha 3983
uglobal
1055 Galkov 3984
  imax    dd 0x0
1 ha 3985
endg
2987 Serge 3986
;-----------------------------------------------------------------------------
3987
align 4
1 ha 3988
delay_ms:     ; delay in 1/1000 sec
2434 Serge 3989
        push    eax
3990
        push    ecx
1 ha 3991
 
2434 Serge 3992
        mov     ecx, esi
1055 Galkov 3993
        ; 
2434 Serge 3994
        imul    ecx, 33941
3995
        shr     ecx, 9
1055 Galkov 3996
        ; 
1 ha 3997
 
2434 Serge 3998
        in      al, 0x61
3999
        and     al, 0x10
4000
        mov     ah, al
1055 Galkov 4001
        cld
2987 Serge 4002
;--------------------------------------
4003
align 4
4004
cnt1:
2434 Serge 4005
        in      al, 0x61
4006
        and     al, 0x10
4007
        cmp     al, ah
4008
        jz      cnt1
1 ha 4009
 
2434 Serge 4010
        mov     ah, al
4011
        loop    cnt1
1 ha 4012
 
2434 Serge 4013
        pop     ecx
4014
        pop     eax
1055 Galkov 4015
        ret
2987 Serge 4016
;-----------------------------------------------------------------------------
2434 Serge 4017
align 4
1 ha 4018
set_app_param:
1055 Galkov 4019
        mov     edi, [TASK_BASE]
2434 Serge 4020
        mov     eax, ebx
4021
        btr     eax, 3                           ; move MOUSE_FILTRATION
4022
        mov     ebx, [current_slot]              ; bit into event_filter
4023
        setc    byte [ebx+APPDATA.event_filter]
4024
        xchg    eax, [edi + TASKDATA.event_mask] ; set new event mask
4025
        mov     [esp+32], eax                    ; return old mask value
1055 Galkov 4026
        ret
2987 Serge 4027
;-----------------------------------------------------------------------------
3500 Serge 4028
 
4029
; this is for syscall
4030
proc delay_hs_unprotected
4031
        call    unprotect_from_terminate
4032
        call    delay_hs
4033
        call    protect_from_terminate
4034
        ret
4035
endp
4036
 
3626 Serge 4037
if 1
2987 Serge 4038
align 4
1 ha 4039
delay_hs:     ; delay in 1/100 secs
684 diamond 4040
; ebx = delay time
3626 Serge 4041
 
4042
        pushad
4043
        push    ebx
4044
        xor     esi, esi
4045
        mov     ecx, MANUAL_DESTROY
4046
        call    create_event
4047
        test    eax, eax
4048
        jz      .done
4049
 
4050
        mov     ebx, edx
4051
        mov     ecx, [esp]
4052
        push    edx
4053
        push    eax
4054
        call    wait_event_timeout
4055
        pop     eax
4056
        pop     ebx
4057
        call    destroy_event
4058
.done:
4059
        add     esp, 4
4060
        popad
4061
        ret
4062
 
4063
else
4064
 
4065
align 4
4066
delay_hs:     ; delay in 1/100 secs
4067
; ebx = delay time
2434 Serge 4068
        push    ecx
4069
        push    edx
1 ha 4070
 
2434 Serge 4071
        mov     edx, [timer_ticks]
2987 Serge 4072
;--------------------------------------
4073
align 4
4074
newtic:
2434 Serge 4075
        mov     ecx, [timer_ticks]
4076
        sub     ecx, edx
4077
        cmp     ecx, ebx
4078
        jae     zerodelay
1 ha 4079
 
2434 Serge 4080
        call    change_task
1 ha 4081
 
2434 Serge 4082
        jmp     newtic
2987 Serge 4083
;--------------------------------------
4084
align 4
4085
zerodelay:
2434 Serge 4086
        pop     edx
4087
        pop     ecx
1055 Galkov 4088
        ret
3626 Serge 4089
end if
4090
 
2987 Serge 4091
;-----------------------------------------------------------------------------
2434 Serge 4092
align 16        ;very often call this subrutine
1 ha 4093
memmove:       ; memory move in bytes
4094
; eax = from
4095
; ebx = to
4096
; ecx = no of bytes
2434 Serge 4097
        test    ecx, ecx
4098
        jle     .ret
1 ha 4099
 
2434 Serge 4100
        push    esi edi ecx
1 ha 4101
 
2434 Serge 4102
        mov     edi, ebx
4103
        mov     esi, eax
1 ha 4104
 
2434 Serge 4105
        test    ecx, not 11b
4106
        jz      @f
1 ha 4107
 
2434 Serge 4108
        push    ecx
4109
        shr     ecx, 2
4110
        rep movsd
4111
        pop     ecx
4112
        and     ecx, 11b
4113
        jz      .finish
2987 Serge 4114
;--------------------------------------
4115
align 4
4116
@@:
2434 Serge 4117
        rep movsb
2987 Serge 4118
;--------------------------------------
4119
align 4
4120
.finish:
2434 Serge 4121
        pop     ecx edi esi
2987 Serge 4122
;--------------------------------------
4123
align 4
4124
.ret:
2434 Serge 4125
        ret
2987 Serge 4126
;-----------------------------------------------------------------------------
75 diamond 4127
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
4128
;align 4
1 ha 4129
;
75 diamond 4130
;read_floppy_file:
1 ha 4131
;
75 diamond 4132
;; as input
4133
;;
4134
;; eax pointer to file
4135
;; ebx file lenght
4136
;; ecx start 512 byte block number
4137
;; edx number of blocks to read
4138
;; esi pointer to return/work area (atleast 20 000 bytes)
4139
;;
4140
;;
4141
;; on return
4142
;;
4143
;; eax = 0 command succesful
4144
;;       1 no fd base and/or partition defined
4145
;;       2 yet unsupported FS
4146
;;       3 unknown FS
4147
;;       4 partition not defined at hd
4148
;;       5 file not found
4149
;; ebx = size of file
1 ha 4150
;
379 serge 4151
;     mov   edi,[TASK_BASE]
75 diamond 4152
;     add   edi,0x10
4153
;     add   esi,[edi]
4154
;     add   eax,[edi]
1 ha 4155
;
75 diamond 4156
;     pushad
4157
;     mov  edi,esi
4158
;     add  edi,1024
4159
;     mov  esi,0x100000+19*512
4160
;     sub  ecx,1
4161
;     shl  ecx,9
4162
;     add  esi,ecx
4163
;     shl  edx,9
4164
;     mov  ecx,edx
4165
;     cld
4166
;     rep  movsb
4167
;     popad
4168
;
4169
;     mov   [esp+36],eax
4170
;     mov   [esp+24],ebx
4171
;     ret
1 ha 4172
 
4173
 
4174
 
4175
align 4
4176
set_io_access_rights:
2434 Serge 4177
        push    edi eax
4178
        mov     edi, tss._io_map_0
465 serge 4179
;     mov   ecx,eax
4180
;     and   ecx,7    ; offset in byte
4181
;     shr   eax,3    ; number of byte
4182
;     add   edi,eax
4183
;     mov   ebx,1
4184
;     shl   ebx,cl
2434 Serge 4185
        test    ebp, ebp
1232 Lrz 4186
;     cmp   ebp,0                ; enable access - ebp = 0
2434 Serge 4187
        jnz     .siar1
465 serge 4188
;     not   ebx
4189
;     and   [edi],byte bl
2434 Serge 4190
        btr     [edi], eax
4191
        pop     eax edi
4192
        ret
2106 serge 4193
.siar1:
2434 Serge 4194
        bts     [edi], eax
465 serge 4195
  ;  or    [edi],byte bl        ; disable access - ebp = 1
2434 Serge 4196
        pop     eax edi
4197
        ret
1306 Lrz 4198
;reserve/free group of ports
4199
;  * eax = 46 - number function
4200
;  * ebx = 0 - reserve, 1 - free
4201
;  * ecx = number start arrea of ports
4202
;  * edx = number end arrea of ports (include last number of port)
4203
;Return value:
1638 serge 4204
;  * eax = 0 - succesful
1306 Lrz 4205
;  * eax = 1 - error
4206
;  * The system has reserve this ports:
4207
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
4208
;destroys eax,ebx, ebp
1 ha 4209
r_f_port_area:
4210
 
2434 Serge 4211
        test    ebx, ebx
4212
        jnz     free_port_area
1 ha 4213
;     je    r_port_area
4214
;     jmp   free_port_area
4215
 
4216
;   r_port_area:
4217
 
1306 Lrz 4218
;     pushad
1 ha 4219
 
2434 Serge 4220
        cmp     ecx, edx      ; beginning > end ?
4221
        ja      rpal1
4222
        cmp     edx, 65536
4223
        jae     rpal1
4224
        mov     eax, [RESERVED_PORTS]
4225
        test    eax, eax      ; no reserved areas ?
4226
        je      rpal2
4227
        cmp     eax, 255      ; max reserved
4228
        jae     rpal1
465 serge 4229
 rpal3:
2434 Serge 4230
        mov     ebx, eax
4231
        shl     ebx, 4
4232
        add     ebx, RESERVED_PORTS
4233
        cmp     ecx, [ebx+8]
4234
        ja      rpal4
4235
        cmp     edx, [ebx+4]
4236
        jae     rpal1
1 ha 4237
;     jb    rpal4
4238
;     jmp   rpal1
465 serge 4239
 rpal4:
2434 Serge 4240
        dec     eax
4241
        jnz     rpal3
4242
        jmp     rpal2
1 ha 4243
   rpal1:
1306 Lrz 4244
;     popad
4245
;     mov   eax,1
2434 Serge 4246
        xor     eax, eax
4247
        inc     eax
4248
        ret
1 ha 4249
   rpal2:
1306 Lrz 4250
;     popad
1 ha 4251
     ; enable port access at port IO map
2434 Serge 4252
        cli
4253
        pushad                        ; start enable io map
1 ha 4254
 
2434 Serge 4255
        cmp     edx, 65536;16384
4256
        jae     no_unmask_io; jge
4257
        mov     eax, ecx
4258
;       push    ebp
4259
        xor     ebp, ebp               ; enable - eax = port
1306 Lrz 4260
new_port_access:
4261
;     pushad
2434 Serge 4262
        call    set_io_access_rights
1306 Lrz 4263
;     popad
2434 Serge 4264
        inc     eax
4265
        cmp     eax, edx
4266
        jbe     new_port_access
4267
;       pop     ebp
1306 Lrz 4268
no_unmask_io:
2434 Serge 4269
        popad                         ; end enable io map
4270
        sti
1 ha 4271
 
2434 Serge 4272
        mov     eax, [RESERVED_PORTS]
4273
        add     eax, 1
4274
        mov     [RESERVED_PORTS], eax
4275
        shl     eax, 4
4276
        add     eax, RESERVED_PORTS
4277
        mov     ebx, [TASK_BASE]
4278
        mov     ebx, [ebx+TASKDATA.pid]
4279
        mov     [eax], ebx
4280
        mov     [eax+4], ecx
4281
        mov     [eax+8], edx
1 ha 4282
 
2434 Serge 4283
        xor     eax, eax
4284
        ret
1 ha 4285
 
4286
free_port_area:
4287
 
1306 Lrz 4288
;     pushad
2434 Serge 4289
        mov     eax, [RESERVED_PORTS]; no reserved areas ?
4290
        test    eax, eax
4291
        jz      frpal2
4292
        mov     ebx, [TASK_BASE]
4293
        mov     ebx, [ebx+TASKDATA.pid]
1 ha 4294
   frpal3:
2434 Serge 4295
        mov     edi, eax
4296
        shl     edi, 4
4297
        add     edi, RESERVED_PORTS
4298
        cmp     ebx, [edi]
4299
        jne     frpal4
4300
        cmp     ecx, [edi+4]
4301
        jne     frpal4
4302
        cmp     edx, [edi+8]
4303
        jne     frpal4
4304
        jmp     frpal1
1 ha 4305
   frpal4:
2434 Serge 4306
        dec     eax
4307
        jnz     frpal3
1 ha 4308
   frpal2:
1306 Lrz 4309
;     popad
2434 Serge 4310
        inc     eax
4311
        ret
1 ha 4312
   frpal1:
2434 Serge 4313
        push    ecx
4314
        mov     ecx, 256
4315
        sub     ecx, eax
4316
        shl     ecx, 4
4317
        mov     esi, edi
4318
        add     esi, 16
4319
        cld
4320
        rep movsb
1 ha 4321
 
2434 Serge 4322
        dec     dword [RESERVED_PORTS]
1306 Lrz 4323
;popad
4324
;disable port access at port IO map
1 ha 4325
 
1306 Lrz 4326
;     pushad                        ; start disable io map
2434 Serge 4327
        pop     eax     ;start port
4328
        cmp     edx, 65536;16384
4329
        jge     no_mask_io
1 ha 4330
 
1306 Lrz 4331
;     mov   eax,ecx
2434 Serge 4332
        xor     ebp, ebp
4333
        inc     ebp
1306 Lrz 4334
new_port_access_disable:
4335
;     pushad
4336
;     mov   ebp,1                  ; disable - eax = port
2434 Serge 4337
        call    set_io_access_rights
1306 Lrz 4338
;     popad
2434 Serge 4339
        inc     eax
4340
        cmp     eax, edx
4341
        jbe     new_port_access_disable
1306 Lrz 4342
no_mask_io:
4343
;     popad                         ; end disable io map
2434 Serge 4344
        xor     eax, eax
4345
        ret
4346
;-----------------------------------------------------------------------------
2106 serge 4347
align 4
1 ha 4348
drawbackground:
2434 Serge 4349
dbrv20:
4350
        cmp     [BgrDrawMode], dword 1
4351
        jne     bgrstr
4352
        call    vesa20_drawbackground_tiled
2465 Serge 4353
;        call    [draw_pointer]
4354
        call    __sys_draw_pointer
2434 Serge 4355
        ret
4356
;--------------------------------------
75 diamond 4357
align 4
2434 Serge 4358
bgrstr:
4359
        call    vesa20_drawbackground_stretch
2465 Serge 4360
;        call    [draw_pointer]
4361
        call    __sys_draw_pointer
2434 Serge 4362
        ret
4363
;-----------------------------------------------------------------------------
4364
align 4
1055 Galkov 4365
syscall_putimage:                       ; PutImage
1 ha 4366
sys_putimage:
2434 Serge 4367
        test    ecx, 0x80008000
4368
        jnz     .exit
4369
        test    ecx, 0x0000FFFF
4370
        jz      .exit
4371
        test    ecx, 0xFFFF0000
4372
        jnz     @f
4373
;--------------------------------------
4374
align 4
4375
.exit:
4376
        ret
4377
;--------------------------------------
4378
align 4
4379
@@:
4380
        mov     edi, [current_slot]
4381
        add     dx, word[edi+APPDATA.wnd_clientbox.top]
4382
        rol     edx, 16
4383
        add     dx, word[edi+APPDATA.wnd_clientbox.left]
4384
        rol     edx, 16
4385
;--------------------------------------
4386
align 4
4387
.forced:
1055 Galkov 4388
        push    ebp esi 0
4389
        mov     ebp, putimage_get24bpp
4390
        mov     esi, putimage_init24bpp
2434 Serge 4391
;--------------------------------------
4392
align 4
283 diamond 4393
sys_putimage_bpp:
2434 Serge 4394
        call    vesa20_putimage
1055 Galkov 4395
        pop     ebp esi ebp
2434 Serge 4396
        ret
4397
;        jmp     [draw_pointer]
4398
;-----------------------------------------------------------------------------
1495 Lrz 4399
align 4
283 diamond 4400
sys_putimage_palette:
4401
; ebx = pointer to image
4402
; ecx = [xsize]*65536 + [ysize]
4403
; edx = [xstart]*65536 + [ystart]
314 diamond 4404
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 4405
; edi = pointer to palette
314 diamond 4406
; ebp = row delta
1055 Galkov 4407
        mov     eax, [CURRENT_TASK]
4408
        shl     eax, 8
4409
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4410
        rol     edx, 16
4411
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4412
        rol     edx, 16
2434 Serge 4413
;--------------------------------------
4414
align 4
283 diamond 4415
.forced:
1055 Galkov 4416
        cmp     esi, 1
4417
        jnz     @f
4418
        push    edi
4419
        mov     eax, [edi+4]
4420
        sub     eax, [edi]
4421
        push    eax
4422
        push    dword [edi]
4423
        push    0ffffff80h
4424
        mov     edi, esp
4425
        call    put_mono_image
4426
        add     esp, 12
4427
        pop     edi
4428
        ret
2434 Serge 4429
;--------------------------------------
4430
align 4
911 diamond 4431
@@:
1055 Galkov 4432
        cmp     esi, 2
4433
        jnz     @f
4434
        push    edi
4435
        push    0ffffff80h
4436
        mov     edi, esp
4437
        call    put_2bit_image
4438
        pop     eax
4439
        pop     edi
4440
        ret
2434 Serge 4441
;--------------------------------------
4442
align 4
911 diamond 4443
@@:
1055 Galkov 4444
        cmp     esi, 4
4445
        jnz     @f
4446
        push    edi
4447
        push    0ffffff80h
4448
        mov     edi, esp
4449
        call    put_4bit_image
4450
        pop     eax
4451
        pop     edi
4452
        ret
2434 Serge 4453
;--------------------------------------
4454
align 4
314 diamond 4455
@@:
1055 Galkov 4456
        push    ebp esi ebp
4457
        cmp     esi, 8
4458
        jnz     @f
4459
        mov     ebp, putimage_get8bpp
4460
        mov     esi, putimage_init8bpp
4461
        jmp     sys_putimage_bpp
2434 Serge 4462
;--------------------------------------
4463
align 4
918 diamond 4464
@@:
2987 Serge 4465
        cmp     esi, 9
4466
        jnz     @f
4467
        mov     ebp, putimage_get9bpp
4468
        mov     esi, putimage_init9bpp
4469
        jmp     sys_putimage_bpp
4470
;--------------------------------------
4471
align 4
4472
@@:
1055 Galkov 4473
        cmp     esi, 15
4474
        jnz     @f
4475
        mov     ebp, putimage_get15bpp
4476
        mov     esi, putimage_init15bpp
4477
        jmp     sys_putimage_bpp
2434 Serge 4478
;--------------------------------------
4479
align 4
906 diamond 4480
@@:
1055 Galkov 4481
        cmp     esi, 16
4482
        jnz     @f
4483
        mov     ebp, putimage_get16bpp
4484
        mov     esi, putimage_init16bpp
4485
        jmp     sys_putimage_bpp
2434 Serge 4486
;--------------------------------------
4487
align 4
842 diamond 4488
@@:
1055 Galkov 4489
        cmp     esi, 24
4490
        jnz     @f
4491
        mov     ebp, putimage_get24bpp
4492
        mov     esi, putimage_init24bpp
4493
        jmp     sys_putimage_bpp
2434 Serge 4494
;--------------------------------------
4495
align 4
314 diamond 4496
@@:
1055 Galkov 4497
        cmp     esi, 32
4498
        jnz     @f
4499
        mov     ebp, putimage_get32bpp
4500
        mov     esi, putimage_init32bpp
4501
        jmp     sys_putimage_bpp
2434 Serge 4502
;--------------------------------------
4503
align 4
314 diamond 4504
@@:
1055 Galkov 4505
        pop     ebp esi ebp
4506
        ret
2434 Serge 4507
;-----------------------------------------------------------------------------
4508
align 4
911 diamond 4509
put_mono_image:
1055 Galkov 4510
        push    ebp esi ebp
4511
        mov     ebp, putimage_get1bpp
4512
        mov     esi, putimage_init1bpp
4513
        jmp     sys_putimage_bpp
2434 Serge 4514
;-----------------------------------------------------------------------------
4515
align 4
918 diamond 4516
put_2bit_image:
1055 Galkov 4517
        push    ebp esi ebp
4518
        mov     ebp, putimage_get2bpp
4519
        mov     esi, putimage_init2bpp
4520
        jmp     sys_putimage_bpp
2434 Serge 4521
;-----------------------------------------------------------------------------
4522
align 4
911 diamond 4523
put_4bit_image:
1055 Galkov 4524
        push    ebp esi ebp
4525
        mov     ebp, putimage_get4bpp
4526
        mov     esi, putimage_init4bpp
4527
        jmp     sys_putimage_bpp
2434 Serge 4528
;-----------------------------------------------------------------------------
4529
align 4
283 diamond 4530
putimage_init24bpp:
1055 Galkov 4531
        lea     eax, [eax*3]
283 diamond 4532
putimage_init8bpp:
2987 Serge 4533
putimage_init9bpp:
1055 Galkov 4534
        ret
2434 Serge 4535
;-----------------------------------------------------------------------------
911 diamond 4536
align 16
283 diamond 4537
putimage_get24bpp:
1055 Galkov 4538
        movzx   eax, byte [esi+2]
4539
        shl     eax, 16
4540
        mov     ax, [esi]
4541
        add     esi, 3
4542
        ret     4
2434 Serge 4543
;-----------------------------------------------------------------------------
911 diamond 4544
align 16
283 diamond 4545
putimage_get8bpp:
1055 Galkov 4546
        movzx   eax, byte [esi]
4547
        push    edx
4548
        mov     edx, [esp+8]
4549
        mov     eax, [edx+eax*4]
4550
        pop     edx
4551
        inc     esi
4552
        ret     4
2434 Serge 4553
;-----------------------------------------------------------------------------
2987 Serge 4554
align 16
4555
putimage_get9bpp:
4556
        lodsb
4557
        mov     ah, al
4558
        shl     eax, 8
4559
        mov     al, ah
4560
        ret     4
4561
;-----------------------------------------------------------------------------
2434 Serge 4562
align 4
911 diamond 4563
putimage_init1bpp:
1055 Galkov 4564
        add     eax, ecx
4565
        push    ecx
4566
        add     eax, 7
4567
        add     ecx, 7
4568
        shr     eax, 3
4569
        shr     ecx, 3
4570
        sub     eax, ecx
4571
        pop     ecx
4572
        ret
2434 Serge 4573
;-----------------------------------------------------------------------------
911 diamond 4574
align 16
4575
putimage_get1bpp:
1055 Galkov 4576
        push    edx
4577
        mov     edx, [esp+8]
4578
        mov     al, [edx]
4579
        add     al, al
4580
        jnz     @f
4581
        lodsb
4582
        adc     al, al
911 diamond 4583
@@:
1055 Galkov 4584
        mov     [edx], al
4585
        sbb     eax, eax
4586
        and     eax, [edx+8]
4587
        add     eax, [edx+4]
4588
        pop     edx
4589
        ret     4
2434 Serge 4590
;-----------------------------------------------------------------------------
4591
align 4
918 diamond 4592
putimage_init2bpp:
1055 Galkov 4593
        add     eax, ecx
4594
        push    ecx
4595
        add     ecx, 3
4596
        add     eax, 3
4597
        shr     ecx, 2
4598
        shr     eax, 2
4599
        sub     eax, ecx
4600
        pop     ecx
4601
        ret
2434 Serge 4602
;-----------------------------------------------------------------------------
918 diamond 4603
align 16
4604
putimage_get2bpp:
1055 Galkov 4605
        push    edx
4606
        mov     edx, [esp+8]
4607
        mov     al, [edx]
4608
        mov     ah, al
4609
        shr     al, 6
4610
        shl     ah, 2
4611
        jnz     .nonewbyte
4612
        lodsb
4613
        mov     ah, al
4614
        shr     al, 6
4615
        shl     ah, 2
4616
        add     ah, 1
918 diamond 4617
.nonewbyte:
1055 Galkov 4618
        mov     [edx], ah
4619
        mov     edx, [edx+4]
4620
        movzx   eax, al
4621
        mov     eax, [edx+eax*4]
4622
        pop     edx
4623
        ret     4
2434 Serge 4624
;-----------------------------------------------------------------------------
4625
align 4
911 diamond 4626
putimage_init4bpp:
1055 Galkov 4627
        add     eax, ecx
4628
        push    ecx
4629
        add     ecx, 1
4630
        add     eax, 1
4631
        shr     ecx, 1
4632
        shr     eax, 1
4633
        sub     eax, ecx
4634
        pop     ecx
4635
        ret
2434 Serge 4636
;-----------------------------------------------------------------------------
911 diamond 4637
align 16
4638
putimage_get4bpp:
1055 Galkov 4639
        push    edx
4640
        mov     edx, [esp+8]
4641
        add     byte [edx], 80h
4642
        jc      @f
4643
        movzx   eax, byte [edx+1]
4644
        mov     edx, [edx+4]
4645
        and     eax, 0x0F
4646
        mov     eax, [edx+eax*4]
4647
        pop     edx
4648
        ret     4
911 diamond 4649
@@:
1055 Galkov 4650
        movzx   eax, byte [esi]
4651
        add     esi, 1
4652
        mov     [edx+1], al
4653
        shr     eax, 4
4654
        mov     edx, [edx+4]
4655
        mov     eax, [edx+eax*4]
4656
        pop     edx
4657
        ret     4
2434 Serge 4658
;-----------------------------------------------------------------------------
4659
align 4
314 diamond 4660
putimage_init32bpp:
1055 Galkov 4661
        shl     eax, 2
4662
        ret
2434 Serge 4663
;-----------------------------------------------------------------------------
911 diamond 4664
align 16
314 diamond 4665
putimage_get32bpp:
1055 Galkov 4666
        lodsd
4667
        ret     4
2434 Serge 4668
;-----------------------------------------------------------------------------
4669
align 4
906 diamond 4670
putimage_init15bpp:
911 diamond 4671
putimage_init16bpp:
1055 Galkov 4672
        add     eax, eax
4673
        ret
2434 Serge 4674
;-----------------------------------------------------------------------------
911 diamond 4675
align 16
906 diamond 4676
putimage_get15bpp:
842 diamond 4677
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
1055 Galkov 4678
        push    ecx edx
4679
        movzx   eax, word [esi]
4680
        add     esi, 2
4681
        mov     ecx, eax
4682
        mov     edx, eax
4683
        and     eax, 0x1F
4684
        and     ecx, 0x1F shl 5
4685
        and     edx, 0x1F shl 10
4686
        shl     eax, 3
4687
        shl     ecx, 6
4688
        shl     edx, 9
4689
        or      eax, ecx
4690
        or      eax, edx
4691
        pop     edx ecx
4692
        ret     4
2434 Serge 4693
;-----------------------------------------------------------------------------
911 diamond 4694
align 16
906 diamond 4695
putimage_get16bpp:
4696
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
1055 Galkov 4697
        push    ecx edx
4698
        movzx   eax, word [esi]
4699
        add     esi, 2
4700
        mov     ecx, eax
4701
        mov     edx, eax
4702
        and     eax, 0x1F
4703
        and     ecx, 0x3F shl 5
4704
        and     edx, 0x1F shl 11
4705
        shl     eax, 3
4706
        shl     ecx, 5
4707
        shl     edx, 8
4708
        or      eax, ecx
4709
        or      eax, edx
4710
        pop     edx ecx
4711
        ret     4
2434 Serge 4712
;-----------------------------------------------------------------------------
4713
;align 4
1 ha 4714
; eax x beginning
4715
; ebx y beginning
4716
; ecx x end
1055 Galkov 4717
        ; edx y end
1 ha 4718
; edi color
2434 Serge 4719
;__sys_drawbar:
4720
;        mov     esi, [current_slot]
4721
;        add     eax, [esi+APPDATA.wnd_clientbox.left]
4722
;        add     ecx, [esi+APPDATA.wnd_clientbox.left]
4723
;        add     ebx, [esi+APPDATA.wnd_clientbox.top]
4724
;        add     edx, [esi+APPDATA.wnd_clientbox.top]
4725
;--------------------------------------
4726
;align 4
4727
;.forced:
4728
;        call    vesa20_drawbar
4729
;        call    [draw_pointer]
4730
;        ret
4731
;-----------------------------------------------------------------------------
4732
align 4
1 ha 4733
kb_read:
4734
 
1055 Galkov 4735
        push    ecx edx
1 ha 4736
 
2434 Serge 4737
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
1 ha 4738
      kr_loop:
2434 Serge 4739
        in      al, 0x64
4740
        test    al, 1
1055 Galkov 4741
        jnz     kr_ready
4742
        loop    kr_loop
2434 Serge 4743
        mov     ah, 1
1055 Galkov 4744
        jmp     kr_exit
1 ha 4745
      kr_ready:
1055 Galkov 4746
        push    ecx
2434 Serge 4747
        mov     ecx, 32
1 ha 4748
      kr_delay:
1055 Galkov 4749
        loop    kr_delay
4750
        pop     ecx
2434 Serge 4751
        in      al, 0x60
4752
        xor     ah, ah
1 ha 4753
      kr_exit:
4754
 
1055 Galkov 4755
        pop     edx ecx
1 ha 4756
 
1055 Galkov 4757
        ret
2434 Serge 4758
;-----------------------------------------------------------------------------
4759
align 4
1 ha 4760
kb_write:
4761
 
1055 Galkov 4762
        push    ecx edx
1 ha 4763
 
2434 Serge 4764
        mov     dl, al
265 diamond 4765
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4766
;      kw_loop1:
4767
;        in      al,0x64
4768
;        test    al,0x20
4769
;        jz      kw_ok1
4770
;        loop    kw_loop1
4771
;        mov     ah,1
4772
;        jmp     kw_exit
4773
;      kw_ok1:
2434 Serge 4774
        in      al, 0x60
4775
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
1 ha 4776
      kw_loop:
2434 Serge 4777
        in      al, 0x64
4778
        test    al, 2
1055 Galkov 4779
        jz      kw_ok
4780
        loop    kw_loop
2434 Serge 4781
        mov     ah, 1
1055 Galkov 4782
        jmp     kw_exit
1 ha 4783
      kw_ok:
2434 Serge 4784
        mov     al, dl
4785
        out     0x60, al
4786
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
1 ha 4787
      kw_loop3:
2434 Serge 4788
        in      al, 0x64
4789
        test    al, 2
1055 Galkov 4790
        jz      kw_ok3
4791
        loop    kw_loop3
2434 Serge 4792
        mov     ah, 1
1055 Galkov 4793
        jmp     kw_exit
1 ha 4794
      kw_ok3:
2434 Serge 4795
        mov     ah, 8
1 ha 4796
      kw_loop4:
2434 Serge 4797
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
1 ha 4798
      kw_loop5:
2434 Serge 4799
        in      al, 0x64
4800
        test    al, 1
1055 Galkov 4801
        jnz     kw_ok4
4802
        loop    kw_loop5
4803
        dec     ah
4804
        jnz     kw_loop4
1 ha 4805
      kw_ok4:
2434 Serge 4806
        xor     ah, ah
1 ha 4807
      kw_exit:
4808
 
1055 Galkov 4809
        pop     edx ecx
1 ha 4810
 
1055 Galkov 4811
        ret
2434 Serge 4812
;-----------------------------------------------------------------------------
4813
align 4
1 ha 4814
kb_cmd:
4815
 
2434 Serge 4816
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
1 ha 4817
      c_wait:
2434 Serge 4818
        in      al, 0x64
4819
        test    al, 2
1055 Galkov 4820
        jz      c_send
4821
        loop    c_wait
4822
        jmp     c_error
1 ha 4823
      c_send:
2434 Serge 4824
        mov     al, bl
4825
        out     0x64, al
4826
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
1 ha 4827
      c_accept:
2434 Serge 4828
        in      al, 0x64
4829
        test    al, 2
1055 Galkov 4830
        jz      c_ok
4831
        loop    c_accept
1 ha 4832
      c_error:
2434 Serge 4833
        mov     ah, 1
1055 Galkov 4834
        jmp     c_exit
1 ha 4835
      c_ok:
2434 Serge 4836
        xor     ah, ah
1 ha 4837
      c_exit:
1055 Galkov 4838
        ret
1 ha 4839
 
4840
 
4841
setmouse:  ; set mousepicture -pointer
1055 Galkov 4842
           ; ps2 mouse enable
1 ha 4843
 
2434 Serge 4844
;        mov     [MOUSE_PICTURE], dword mousepointer
1 ha 4845
 
2434 Serge 4846
        cli
1 ha 4847
 
2434 Serge 4848
        ret
1 ha 4849
 
1055 Galkov 4850
if used _rdtsc
1 ha 4851
_rdtsc:
2434 Serge 4852
        bt      [cpu_caps], CAPS_TSC
4853
        jnc     ret_rdtsc
4854
        rdtsc
4855
        ret
1 ha 4856
   ret_rdtsc:
2434 Serge 4857
        mov     edx, 0xffffffff
4858
        mov     eax, 0xffffffff
4859
        ret
1055 Galkov 4860
end if
1 ha 4861
 
4862
sys_msg_board_str:
4863
 
2434 Serge 4864
        pushad
1 ha 4865
   @@:
2434 Serge 4866
        cmp     [esi], byte 0
4867
        je      @f
3626 Serge 4868
        mov     ebx, 1
4869
        movzx   ecx, byte [esi]
2434 Serge 4870
        call    sys_msg_board
4871
        inc     esi
4872
        jmp     @b
1 ha 4873
   @@:
2434 Serge 4874
        popad
4875
        ret
1 ha 4876
 
709 diamond 4877
sys_msg_board_byte:
4878
; in: al = byte to display
4879
; out: nothing
4880
; destroys: nothing
1055 Galkov 4881
        pushad
4882
        mov     ecx, 2
4883
        shl     eax, 24
4884
        jmp     @f
709 diamond 4885
 
4886
sys_msg_board_word:
4887
; in: ax = word to display
4888
; out: nothing
4889
; destroys: nothing
1055 Galkov 4890
        pushad
4891
        mov     ecx, 4
4892
        shl     eax, 16
4893
        jmp     @f
709 diamond 4894
 
4895
sys_msg_board_dword:
4896
; in: eax = dword to display
4897
; out: nothing
4898
; destroys: nothing
1055 Galkov 4899
        pushad
4900
        mov     ecx, 8
709 diamond 4901
@@:
1055 Galkov 4902
        push    ecx
4903
        rol     eax, 4
4904
        push    eax
4905
        and     al, 0xF
4906
        cmp     al, 10
4907
        sbb     al, 69h
4908
        das
3626 Serge 4909
        mov     cl, al
4910
        xor     ebx, ebx
4911
        inc     ebx
1055 Galkov 4912
        call    sys_msg_board
4913
        pop     eax
4914
        pop     ecx
4915
        loop    @b
4916
        popad
4917
        ret
709 diamond 4918
 
3500 Serge 4919
msg_board_data_size = 65536 ; Must be power of two
4920
 
1 ha 4921
uglobal
3500 Serge 4922
  msg_board_data  rb msg_board_data_size
1 ha 4923
  msg_board_count dd 0x0
4924
endg
4925
 
4926
sys_msg_board:
4927
 
3626 Serge 4928
; ebx=1 : write :  bl byte to write
4929
; ebx=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
1 ha 4930
 
3626 Serge 4931
        push    eax ebx                 ; Save eax and ebx, since we're restoring their order required.
4932
        mov     eax, ebx
4933
        mov     ebx, ecx
4934
 
1055 Galkov 4935
        mov     ecx, [msg_board_count]
4936
        cmp     eax, 1
4937
        jne     .smbl1
1 ha 4938
 
1043 hidnplayr 4939
if defined debug_com_base
1 ha 4940
 
1055 Galkov 4941
        push    dx ax
1043 hidnplayr 4942
 
1055 Galkov 4943
       @@:                              ; Wait for empty transmit register  (yes, this slows down system..)
4944
        mov     dx, debug_com_base+5
4945
        in      al, dx
4946
        test    al, 1 shl 5
4947
        jz      @r
1043 hidnplayr 4948
 
1055 Galkov 4949
        mov     dx, debug_com_base      ; Output the byte
4950
        mov     al, bl
4951
        out     dx, al
1043 hidnplayr 4952
 
1055 Galkov 4953
        pop     ax dx
1043 hidnplayr 4954
 
4955
end if
4956
 
2434 Serge 4957
        mov     [msg_board_data+ecx], bl
3908 Serge 4958
; // if debug_direct_print == 1
4959
        cmp     byte [debug_direct_print], 1
4960
        jnz     @f
3555 Serge 4961
        pusha
4962
iglobal
3908 Serge 4963
msg_board_pos   dd      (42*6)*65536+10 ; for printing debug output on the screen
3555 Serge 4964
endg
4965
        lea     edx, [msg_board_data+ecx]
4966
        mov     ecx, 0x40FFFFFF
4967
        mov     ebx, [msg_board_pos]
4968
        mov     edi, 1
4969
        mov     esi, 1
4970
        call    dtext
4971
        popa
4972
        add     word [msg_board_pos+2], 6
4973
        cmp     bl, 10
4974
        jnz     @f
3908 Serge 4975
        mov     word [msg_board_pos+2], (42*6)
3555 Serge 4976
        add     word [msg_board_pos], 10
3626 Serge 4977
        mov     ax, word [Screen_Max_Y]
3555 Serge 4978
        cmp     word [msg_board_pos], ax
4979
        jbe     @f
4980
        mov     word [msg_board_pos], 10
4981
@@:
3908 Serge 4982
; // end if
4983
 
3555 Serge 4984
if 0
4985
        pusha
4986
        mov     al, bl
4987
        mov     edx, 402h
4988
        out     dx, al
4989
        popa
4990
end if
1055 Galkov 4991
        inc     ecx
3500 Serge 4992
        and     ecx, msg_board_data_size - 1
1055 Galkov 4993
        mov     [msg_board_count], ecx
3626 Serge 4994
 
4995
        pop     ebx eax
1055 Galkov 4996
        ret
671 Ghost 4997
.smbl1:
1055 Galkov 4998
        cmp     eax, 2
4999
        jne     .smbl2
5000
        test    ecx, ecx
5001
        jz      .smbl21
3626 Serge 5002
 
5003
        add     esp, 8                  ; Returning data in ebx and eax, so no need to restore them.
1055 Galkov 5004
        mov     eax, msg_board_data+1
5005
        mov     ebx, msg_board_data
5006
        movzx   edx, byte [ebx]
5007
        call    memmove
5008
        dec     [msg_board_count]
3626 Serge 5009
        mov     [esp + 32], edx ;eax
5010
        mov     [esp + 20], dword 1
1055 Galkov 5011
        ret
671 Ghost 5012
.smbl21:
3626 Serge 5013
        mov     [esp+32], ecx
5014
        mov     [esp+20], ecx
671 Ghost 5015
.smbl2:
3626 Serge 5016
        pop     ebx eax
1055 Galkov 5017
        ret
1 ha 5018
 
1494 Lrz 5019
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5020
;; 66 sys function.                                                ;;
5021
;; in eax=66,ebx in [0..5],ecx,edx                                 ;;
5022
;; out eax                                                         ;;
5023
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5024
iglobal
5025
align 4
5026
f66call:
5027
           dd sys_process_def.1   ; 1 = set keyboard mode
5028
           dd sys_process_def.2   ; 2 = get keyboard mode
5029
           dd sys_process_def.3   ; 3 = get keyboard ctrl, alt, shift
2987 Serge 5030
           dd sys_process_def.4   ; 4 = set system-wide hotkey
5031
           dd sys_process_def.5   ; 5 = delete installed hotkey
5032
           dd sys_process_def.6   ; 6 = disable input, work only hotkeys
5033
           dd sys_process_def.7   ; 7 = enable input, opposition to f.66.6
1494 Lrz 5034
endg
2987 Serge 5035
;-----------------------------------------------------------------------------
5036
align 4
1 ha 5037
sys_process_def:
2434 Serge 5038
        dec     ebx
2987 Serge 5039
        cmp     ebx, 7
5040
        jae     .not_support    ;if >=8 then or eax,-1
1494 Lrz 5041
 
1055 Galkov 5042
        mov     edi, [CURRENT_TASK]
2434 Serge 5043
        jmp     dword [f66call+ebx*4]
1 ha 5044
 
1494 Lrz 5045
.not_support:
2434 Serge 5046
        or      eax, -1
5047
        ret
2987 Serge 5048
;-----------------------------------------------------------------------------
5049
align 4
1494 Lrz 5050
.1:
2434 Serge 5051
        shl     edi, 8
5052
        mov     [edi+SLOT_BASE + APPDATA.keyboard_mode], cl
1 ha 5053
 
2434 Serge 5054
        ret
2987 Serge 5055
;-----------------------------------------------------------------------------
5056
align 4
2434 Serge 5057
.2:                             ; 2 = get keyboard mode
5058
        shl     edi, 8
5059
        movzx   eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
5060
        mov     [esp+32], eax
5061
        ret
2987 Serge 5062
;-----------------------------------------------------------------------------
5063
align 4
2434 Serge 5064
.3:                             ;3 = get keyboard ctrl, alt, shift
5065
        mov     eax, [kb_state]
5066
        mov     [esp+32], eax
5067
        ret
2987 Serge 5068
;-----------------------------------------------------------------------------
5069
align 4
1494 Lrz 5070
.4:
1055 Galkov 5071
        mov     eax, hotkey_list
92 diamond 5072
@@:
1055 Galkov 5073
        cmp     dword [eax+8], 0
5074
        jz      .found_free
5075
        add     eax, 16
5076
        cmp     eax, hotkey_list+16*256
5077
        jb      @b
1494 Lrz 5078
        mov     dword [esp+32], 1
1055 Galkov 5079
        ret
92 diamond 5080
.found_free:
1055 Galkov 5081
        mov     [eax+8], edi
1494 Lrz 5082
        mov     [eax+4], edx
5083
        movzx   ecx, cl
5084
        lea     ecx, [hotkey_scancodes+ecx*4]
5085
        mov     edx, [ecx]
5086
        mov     [eax], edx
5087
        mov     [ecx], eax
5088
        mov     [eax+12], ecx
3500 Serge 5089
        test    edx, edx
5090
        jz      @f
1494 Lrz 5091
        mov     [edx+12], eax
92 diamond 5092
@@:
1494 Lrz 5093
        and     dword [esp+32], 0
1055 Galkov 5094
        ret
2987 Serge 5095
;-----------------------------------------------------------------------------
5096
align 4
1494 Lrz 5097
.5:
5098
        movzx   ebx, cl
1055 Galkov 5099
        lea     ebx, [hotkey_scancodes+ebx*4]
5100
        mov     eax, [ebx]
92 diamond 5101
.scan:
1055 Galkov 5102
        test    eax, eax
5103
        jz      .notfound
5104
        cmp     [eax+8], edi
5105
        jnz     .next
1494 Lrz 5106
        cmp     [eax+4], edx
1055 Galkov 5107
        jz      .found
92 diamond 5108
.next:
1055 Galkov 5109
        mov     eax, [eax]
5110
        jmp     .scan
92 diamond 5111
.notfound:
1494 Lrz 5112
        mov     dword [esp+32], 1
1055 Galkov 5113
        ret
92 diamond 5114
.found:
1055 Galkov 5115
        mov     ecx, [eax]
5116
        jecxz   @f
5117
        mov     edx, [eax+12]
5118
        mov     [ecx+12], edx
92 diamond 5119
@@:
1055 Galkov 5120
        mov     ecx, [eax+12]
5121
        mov     edx, [eax]
5122
        mov     [ecx], edx
5123
        xor     edx, edx
5124
        mov     [eax+4], edx
5125
        mov     [eax+8], edx
5126
        mov     [eax+12], edx
5127
        mov     [eax], edx
1494 Lrz 5128
        mov     [esp+32], edx
1055 Galkov 5129
        ret
2987 Serge 5130
;-----------------------------------------------------------------------------
5131
align 4
5132
.6:
5133
        pushfd
5134
        cli
5135
        mov     eax, [PID_lock_input]
5136
        test    eax, eax
5137
        jnz     @f
5138
; get current PID
5139
        mov     eax, [CURRENT_TASK]
5140
        shl     eax, 5
5141
        mov     eax, [eax+CURRENT_TASK+TASKDATA.pid]
5142
; set current PID for lock input
5143
        mov     [PID_lock_input], eax
5144
@@:
5145
        popfd
5146
        ret
5147
;-----------------------------------------------------------------------------
5148
align 4
5149
.7:
5150
        mov     eax, [PID_lock_input]
5151
        test    eax, eax
5152
        jz      @f
5153
; get current PID
5154
        mov     ebx, [CURRENT_TASK]
5155
        shl     ebx, 5
5156
        mov     ebx, [ebx+CURRENT_TASK+TASKDATA.pid]
5157
; compare current lock input with current PID
5158
        cmp     ebx, eax
5159
        jne     @f
92 diamond 5160
 
2987 Serge 5161
        xor     eax, eax
5162
        mov     [PID_lock_input], eax
5163
@@:
5164
        ret
5165
;-----------------------------------------------------------------------------
5166
uglobal
5167
  PID_lock_input dd 0x0
5168
endg
1497 Lrz 5169
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5170
;; 61 sys function.                                                ;;
5171
;; in eax=61,ebx in [1..3]                                         ;;
5172
;; out eax                                                         ;;
5173
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5174
iglobal
1 ha 5175
align 4
1497 Lrz 5176
f61call:
5177
           dd sys_gs.1   ; resolution
5178
           dd sys_gs.2   ; bits per pixel
5179
           dd sys_gs.3   ; bytes per scanline
5180
endg
1 ha 5181
 
1497 Lrz 5182
 
5183
align 4
5184
 
1055 Galkov 5185
sys_gs:                         ; direct screen access
2434 Serge 5186
        dec     ebx
5187
        cmp     ebx, 2
5188
        ja      .not_support
5189
        jmp     dword [f61call+ebx*4]
1497 Lrz 5190
.not_support:
2434 Serge 5191
        or      [esp+32], dword -1
1497 Lrz 5192
        ret
1 ha 5193
 
1497 Lrz 5194
 
5195
.1:                             ; resolution
2434 Serge 5196
        mov     eax, [Screen_Max_X]
5197
        shl     eax, 16
3626 Serge 5198
        mov     ax, word [Screen_Max_Y]
2434 Serge 5199
        add     eax, 0x00010001
5200
        mov     [esp+32], eax
5201
        ret
5202
.2:                             ; bits per pixel
3555 Serge 5203
        mov     eax, [_display.bpp]
2434 Serge 5204
        mov     [esp+32], eax
5205
        ret
1497 Lrz 5206
.3:                             ; bytes per scanline
3626 Serge 5207
        mov     eax, [_display.pitch]
2434 Serge 5208
        mov     [esp+32], eax
5209
        ret
1 ha 5210
 
5211
align 4  ;  system functions
5212
 
1055 Galkov 5213
syscall_setpixel:                       ; SetPixel
1 ha 5214
 
1055 Galkov 5215
        mov     eax, ebx
5216
        mov     ebx, ecx
5217
        mov     ecx, edx
5218
        mov     edx, [TASK_BASE]
5219
        add     eax, [edx-twdw+WDATA.box.left]
5220
        add     ebx, [edx-twdw+WDATA.box.top]
5221
        mov     edi, [current_slot]
5222
        add     eax, [edi+APPDATA.wnd_clientbox.left]
5223
        add     ebx, [edi+APPDATA.wnd_clientbox.top]
5224
        xor     edi, edi ; no force
2434 Serge 5225
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 save to mouseunder area
2465 Serge 5226
;        jmp     [putpixel]
5227
        jmp     __sys_putpixel
1 ha 5228
 
5229
align 4
5230
 
1055 Galkov 5231
syscall_writetext:                      ; WriteText
1 ha 5232
 
2434 Serge 5233
        mov     eax, [TASK_BASE]
5234
        mov     ebp, [eax-twdw+WDATA.box.left]
5235
        push    esi
5236
        mov     esi, [current_slot]
5237
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5238
        shl     ebp, 16
5239
        add     ebp, [eax-twdw+WDATA.box.top]
5240
        add     bp, word[esi+APPDATA.wnd_clientbox.top]
5241
        pop     esi
3500 Serge 5242
        test    ecx, 0x08000000  ; redirect the output to the user area
5243
        jnz     @f
2434 Serge 5244
        add     ebx, ebp
3500 Serge 5245
align 4
5246
@@:
2434 Serge 5247
        mov     eax, edi
2987 Serge 5248
        test    ecx, 0x08000000  ; redirect the output to the user area
5249
        jnz     dtext
2434 Serge 5250
        xor     edi, edi
5251
        jmp     dtext
1 ha 5252
 
5253
align 4
5254
 
1055 Galkov 5255
syscall_drawrect:                       ; DrawRect
1 ha 5256
 
1055 Galkov 5257
        mov     edi, edx ; color + gradient
5258
        and     edi, 0x80FFFFFF
5259
        test    bx, bx  ; x.size
5260
        je      .drectr
5261
        test    cx, cx ; y.size
5262
        je      .drectr
1 ha 5263
 
1055 Galkov 5264
        mov     eax, ebx ; bad idea
5265
        mov     ebx, ecx
1 ha 5266
 
1055 Galkov 5267
        movzx   ecx, ax ; ecx - x.size
5268
        shr     eax, 16 ; eax - x.coord
5269
        movzx   edx, bx ; edx - y.size
5270
        shr     ebx, 16 ; ebx - y.coord
5271
        mov     esi, [current_slot]
1 ha 5272
 
1055 Galkov 5273
        add     eax, [esi + APPDATA.wnd_clientbox.left]
5274
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
5275
        add     ecx, eax
5276
        add     edx, ebx
2465 Serge 5277
;        jmp     [drawbar]
5278
        jmp     vesa20_drawbar
671 Ghost 5279
.drectr:
1055 Galkov 5280
        ret
1 ha 5281
 
5282
align 4
1055 Galkov 5283
syscall_getscreensize:                  ; GetScreenSize
3626 Serge 5284
        mov     ax, word [Screen_Max_X]
1055 Galkov 5285
        shl     eax, 16
3626 Serge 5286
        mov     ax, word [Screen_Max_Y]
1055 Galkov 5287
        mov     [esp + 32], eax
5288
        ret
1 ha 5289
 
671 Ghost 5290
align 4
5291
 
1055 Galkov 5292
syscall_cdaudio:                        ; CD
1 ha 5293
 
1290 Lrz 5294
        cmp     ebx, 4
1055 Galkov 5295
        jb      .audio
5296
        jz      .eject
1290 Lrz 5297
        cmp     ebx, 5
1055 Galkov 5298
        jnz     .ret
588 diamond 5299
.load:
1055 Galkov 5300
        call    .reserve
5301
        call    LoadMedium
1290 Lrz 5302
        ;call    .free
2434 Serge 5303
        jmp     .free
1290 Lrz 5304
;        ret
588 diamond 5305
.eject:
1055 Galkov 5306
        call    .reserve
5307
        call    clear_CD_cache
5308
        call    allow_medium_removal
5309
        call    EjectMedium
1290 Lrz 5310
;        call    .free
2434 Serge 5311
        jmp     .free
1290 Lrz 5312
;        ret
588 diamond 5313
.audio:
2434 Serge 5314
        call    sys_cd_audio
5315
        mov     [esp+36-4], eax
588 diamond 5316
.ret:
2434 Serge 5317
        ret
1 ha 5318
 
588 diamond 5319
.reserve:
1055 Galkov 5320
        call    reserve_cd
1290 Lrz 5321
        mov     eax, ecx
1055 Galkov 5322
        shr     eax, 1
5323
        and     eax, 1
5324
        inc     eax
5325
        mov     [ChannelNumber], ax
1290 Lrz 5326
        mov     eax, ecx
1055 Galkov 5327
        and     eax, 1
5328
        mov     [DiskNumber], al
5329
        call    reserve_cd_channel
5330
        and     ebx, 3
5331
        inc     ebx
5332
        mov     [cdpos], ebx
5333
        add     ebx, ebx
5334
        mov     cl, 8
5335
        sub     cl, bl
5336
        mov     al, [DRIVE_DATA+1]
5337
        shr     al, cl
5338
        test    al, 2
1290 Lrz 5339
        jz      .free;.err
1055 Galkov 5340
        ret
588 diamond 5341
.free:
1055 Galkov 5342
        call    free_cd_channel
5343
        and     [cd_status], 0
5344
        ret
590 diamond 5345
.err:
1055 Galkov 5346
        call    .free
1290 Lrz 5347
;        pop     eax
1055 Galkov 5348
        ret
2987 Serge 5349
;-----------------------------------------------------------------------------
1 ha 5350
align 4
2987 Serge 5351
syscall_getpixel_WinMap:                       ; GetPixel WinMap
5352
        cmp     ebx, [Screen_Max_X]
5353
        jbe     @f
5354
        cmp     ecx, [Screen_Max_Y]
5355
        jbe     @f
5356
        xor     eax, eax
5357
        jmp     .store
5358
;--------------------------------------
5359
align 4
5360
@@:
5361
        mov     eax, [d_width_calc_area + ecx*4]
5362
        add     eax, [_WinMapAddress]
5363
        movzx   eax, byte[eax+ebx]        ; get value for current point
5364
;--------------------------------------
5365
align 4
5366
.store:
5367
        mov     [esp + 32], eax
5368
        ret
5369
;-----------------------------------------------------------------------------
5370
align 4
1055 Galkov 5371
syscall_getpixel:                       ; GetPixel
2434 Serge 5372
        mov     ecx, [Screen_Max_X]
5373
        inc     ecx
5374
        xor     edx, edx
5375
        mov     eax, ebx
5376
        div     ecx
5377
        mov     ebx, edx
5378
        xchg    eax, ebx
5379
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5380
        call    dword [GETPIXEL]; eax - x, ebx - y
5381
        mov     [esp + 32], ecx
5382
        ret
2987 Serge 5383
;-----------------------------------------------------------------------------
921 mario79 5384
align 4
5385
syscall_getarea:
5386
;eax = 36
1055 Galkov 5387
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5388
;ecx = [size x]*65536 + [size y]
5389
;edx = [start x]*65536 + [start y]
2434 Serge 5390
        pushad
5391
        mov     edi, ebx
5392
        mov     eax, edx
5393
        shr     eax, 16
5394
        mov     ebx, edx
5395
        and     ebx, 0xffff
5396
        dec     eax
5397
        dec     ebx
921 mario79 5398
     ; eax - x, ebx - y
2434 Serge 5399
        mov     edx, ecx
1638 serge 5400
 
2434 Serge 5401
        shr     ecx, 16
5402
        and     edx, 0xffff
5403
        mov     esi, ecx
921 mario79 5404
     ; ecx - size x, edx - size y
1638 serge 5405
 
2434 Serge 5406
        mov     ebp, edx
5407
        dec     ebp
5408
        lea     ebp, [ebp*3]
1638 serge 5409
 
2434 Serge 5410
        imul    ebp, esi
1638 serge 5411
 
2434 Serge 5412
        mov     esi, ecx
5413
        dec     esi
5414
        lea     esi, [esi*3]
1638 serge 5415
 
2434 Serge 5416
        add     ebp, esi
5417
        add     ebp, edi
927 mario79 5418
 
2434 Serge 5419
        add     ebx, edx
2987 Serge 5420
;--------------------------------------
5421
align 4
921 mario79 5422
.start_y:
2434 Serge 5423
        push    ecx edx
2987 Serge 5424
;--------------------------------------
5425
align 4
921 mario79 5426
.start_x:
2434 Serge 5427
        push    eax ebx ecx
5428
        add     eax, ecx
927 mario79 5429
 
2434 Serge 5430
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5431
        call    dword [GETPIXEL]; eax - x, ebx - y
1638 serge 5432
 
2434 Serge 5433
        mov     [ebp], cx
5434
        shr     ecx, 16
5435
        mov     [ebp+2], cl
921 mario79 5436
 
2434 Serge 5437
        pop     ecx ebx eax
5438
        sub     ebp, 3
5439
        dec     ecx
5440
        jnz     .start_x
5441
        pop     edx ecx
5442
        dec     ebx
5443
        dec     edx
5444
        jnz     .start_y
5445
        popad
5446
        ret
2987 Serge 5447
;-----------------------------------------------------------------------------
5448
align 4
5449
syscall_putarea_backgr:
5450
;eax = 25
5451
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5452
;ecx = [size x]*65536 + [size y]
5453
;edx = [start x]*65536 + [start y]
5454
        pushad
5455
        mov     edi, ebx
5456
        mov     eax, edx
5457
        shr     eax, 16
5458
        mov     ebx, edx
5459
        and     ebx, 0xffff
5460
        dec     eax
5461
        dec     ebx
5462
; eax - x, ebx - y
5463
        mov     edx, ecx
5464
        shr     ecx, 16
5465
        and     edx, 0xffff
5466
        mov     esi, ecx
5467
; ecx - size x, edx - size y
5468
        mov     ebp, edx
5469
        dec     ebp
5470
        shl     ebp, 2
921 mario79 5471
 
2987 Serge 5472
        imul    ebp, esi
5473
 
5474
        mov     esi, ecx
5475
        dec     esi
5476
        shl     esi, 2
5477
 
5478
        add     ebp, esi
5479
        add     ebp, edi
5480
 
5481
        add     ebx, edx
5482
;--------------------------------------
1 ha 5483
align 4
2987 Serge 5484
.start_y:
5485
        push    ecx edx
5486
;--------------------------------------
5487
align 4
5488
.start_x:
5489
        push    eax ecx
5490
        add     eax, ecx
1 ha 5491
 
2987 Serge 5492
        mov     ecx, [ebp]
5493
        rol     ecx, 8
5494
        test    cl, cl        ; transparensy = 0
5495
        jz      .no_put
5496
 
5497
        xor     cl, cl
5498
        ror     ecx, 8
5499
 
5500
        pushad
5501
        mov     edx, [d_width_calc_area + ebx*4]
5502
        add     edx, [_WinMapAddress]
5503
        movzx   edx, byte [eax+edx]
5504
        cmp     dl, byte 1
5505
        jne     @f
5506
 
5507
        call    dword [PUTPIXEL]; eax - x, ebx - y
5508
;--------------------------------------
5509
align 4
5510
@@:
5511
        popad
5512
;--------------------------------------
5513
align 4
5514
.no_put:
5515
        pop     ecx eax
5516
 
5517
        sub     ebp, 4
5518
        dec     ecx
5519
        jnz     .start_x
5520
 
5521
        pop     edx ecx
5522
        dec     ebx
5523
        dec     edx
5524
        jnz     .start_y
5525
 
5526
        popad
5527
        ret
5528
;-----------------------------------------------------------------------------
5529
align 4
1055 Galkov 5530
syscall_drawline:                       ; DrawLine
1 ha 5531
 
1055 Galkov 5532
        mov     edi, [TASK_BASE]
5533
        movzx   eax, word[edi-twdw+WDATA.box.left]
5534
        mov     ebp, eax
5535
        mov     esi, [current_slot]
5536
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5537
        add     ax, word[esi+APPDATA.wnd_clientbox.left]
2434 Serge 5538
        add     ebp, ebx
1055 Galkov 5539
        shl     eax, 16
5540
        movzx   ebx, word[edi-twdw+WDATA.box.top]
5541
        add     eax, ebp
5542
        mov     ebp, ebx
5543
        add     ebp, [esi+APPDATA.wnd_clientbox.top]
5544
        add     bx, word[esi+APPDATA.wnd_clientbox.top]
5545
        add     ebp, ecx
5546
        shl     ebx, 16
5547
        xor     edi, edi
5548
        add     ebx, ebp
5549
        mov     ecx, edx
2465 Serge 5550
;        jmp     [draw_line]
5551
        jmp     __sys_draw_line
1 ha 5552
 
5553
 
5554
align 4
1055 Galkov 5555
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
1 ha 5556
 
2434 Serge 5557
        call    r_f_port_area
5558
        mov     [esp+32], eax
5559
        ret
1 ha 5560
 
5561
align 4
1055 Galkov 5562
syscall_threads:                        ; CreateThreads
1369 Lrz 5563
;
4265 Serge 5564
;   ecx=thread entry point
5565
;   edx=thread stack pointer
1369 Lrz 5566
;
5567
; on return : eax = pid
1 ha 5568
 
4265 Serge 5569
        xor     ebx, ebx
2434 Serge 5570
        call    new_sys_threads
1369 Lrz 5571
 
2434 Serge 5572
        mov     [esp+32], eax
5573
        ret
1 ha 5574
 
5575
align 4
5576
 
375 Ghost 5577
paleholder:
1055 Galkov 5578
        ret
2439 Serge 5579
;------------------------------------------------------------------------------
757 serge 5580
align 4
2439 Serge 5581
calculate_fast_getting_offset_for_WinMapAddress:
5582
; calculate data area for fast getting offset to _WinMapAddress
2465 Serge 5583
        xor     eax, eax
2439 Serge 5584
        mov     ecx, [_display.height]
5585
        mov     edi, d_width_calc_area
5586
        cld
5587
@@:
5588
        stosd
5589
        add     eax, [_display.width]
5590
        dec     ecx
5591
        jnz     @r
5592
        ret
5593
;------------------------------------------------------------------------------
5594
align 4
2987 Serge 5595
calculate_fast_getting_offset_for_LFB:
5596
; calculate data area for fast getting offset to LFB
5597
        xor     eax, eax
5598
        mov     ecx, [_display.height]
5599
        mov     edi, BPSLine_calc_area
5600
        cld
5601
@@:
5602
        stosd
3626 Serge 5603
        add     eax, [_display.pitch]
2987 Serge 5604
        dec     ecx
5605
        jnz     @r
5606
        ret
5607
;------------------------------------------------------------------------------
5608
align 4
757 serge 5609
set_screen:
2987 Serge 5610
; in:
5611
; eax - new Screen_Max_X
5612
; ecx - new BytesPerScanLine
5613
; edx - new Screen_Max_Y
709 diamond 5614
 
1055 Galkov 5615
        pushfd
5616
        cli
757 serge 5617
 
2434 Serge 5618
        mov     [Screen_Max_X], eax
5619
        mov     [Screen_Max_Y], edx
3626 Serge 5620
        mov     [_display.pitch], ecx
757 serge 5621
 
2434 Serge 5622
        mov     [screen_workarea.right], eax
5623
        mov     [screen_workarea.bottom], edx
1300 serge 5624
 
2434 Serge 5625
        push    ebx
5626
        push    esi
5627
        push    edi
1300 serge 5628
 
5629
        pushad
5630
 
2987 Serge 5631
        cmp     [do_not_touch_winmap], 1
5632
        je      @f
5633
 
1300 serge 5634
        stdcall kernel_free, [_WinMapAddress]
5635
 
2434 Serge 5636
        mov     eax, [_display.width]
5637
        mul     [_display.height]
5638
        mov     [_WinMapSize], eax
1300 serge 5639
 
5640
        stdcall kernel_alloc, eax
2434 Serge 5641
        mov     [_WinMapAddress], eax
5642
        test    eax, eax
5643
        jz      .epic_fail
2987 Serge 5644
; store for f.18.24
5645
        mov     eax, [_display.width]
5646
        mov     [display_width_standard], eax
1300 serge 5647
 
2987 Serge 5648
        mov     eax, [_display.height]
5649
        mov     [display_height_standard], eax
5650
@@:
2439 Serge 5651
        call    calculate_fast_getting_offset_for_WinMapAddress
2987 Serge 5652
; for Qemu or non standart video cards
5653
; Unfortunately [BytesPerScanLine] does not always
5654
;                             equal to [_display.width] * [ScreenBPP] / 8
5655
        call    calculate_fast_getting_offset_for_LFB
1300 serge 5656
        popad
5657
 
1055 Galkov 5658
        call    repos_windows
2434 Serge 5659
        xor     eax, eax
5660
        xor     ebx, ebx
1055 Galkov 5661
        mov     ecx, [Screen_Max_X]
5662
        mov     edx, [Screen_Max_Y]
5663
        call    calculatescreen
2434 Serge 5664
        pop     edi
5665
        pop     esi
5666
        pop     ebx
757 serge 5667
 
1055 Galkov 5668
        popfd
5669
        ret
757 serge 5670
 
1300 serge 5671
.epic_fail:
5672
        hlt                     ; Houston, we've had a problem
5673
 
76 mario79 5674
; --------------- APM ---------------------
1330 Lrz 5675
uglobal
2434 Serge 5676
apm_entry       dp      0
5677
apm_vf          dd      0
1330 Lrz 5678
endg
5679
 
1 ha 5680
align 4
76 mario79 5681
sys_apm:
2434 Serge 5682
        xor     eax, eax
5683
        cmp     word [apm_vf], ax       ; Check APM BIOS enable
5684
        jne     @f
5685
        inc     eax
5686
        or      dword [esp + 44], eax   ; error
5687
        add     eax, 7
5688
        mov     dword [esp + 32], eax   ; 32-bit protected-mode interface not supported
5689
        ret
164 serge 5690
 
465 serge 5691
@@:
2434 Serge 5692
;       xchg    eax, ecx
5693
;       xchg    ebx, ecx
164 serge 5694
 
2434 Serge 5695
        cmp     dx, 3
5696
        ja      @f
5697
        and     [esp + 44], byte 0xfe    ; emulate func 0..3 as func 0
5698
        mov     eax, [apm_vf]
5699
        mov     [esp + 32], eax
5700
        shr     eax, 16
5701
        mov     [esp + 28], eax
5702
        ret
78 diamond 5703
 
465 serge 5704
@@:
5705
 
2434 Serge 5706
        mov     esi, [master_tab+(OS_BASE shr 20)]
5707
        xchg    [master_tab], esi
5708
        push    esi
5709
        mov     edi, cr3
5710
        mov     cr3, edi                ;flush TLB
465 serge 5711
 
2434 Serge 5712
        call    pword [apm_entry]       ;call APM BIOS
465 serge 5713
 
2434 Serge 5714
        xchg    eax, [esp]
5715
        mov     [master_tab], eax
5716
        mov     eax, cr3
5717
        mov     cr3, eax
5718
        pop     eax
465 serge 5719
 
2434 Serge 5720
        mov     [esp + 4 ], edi
5721
        mov     [esp + 8], esi
5722
        mov     [esp + 20], ebx
5723
        mov     [esp + 24], edx
5724
        mov     [esp + 28], ecx
5725
        mov     [esp + 32], eax
5726
        setc    al
5727
        and     [esp + 44], byte 0xfe
5728
        or      [esp + 44], al
5729
        ret
76 mario79 5730
; -----------------------------------------
1 ha 5731
 
76 mario79 5732
align 4
5733
 
1055 Galkov 5734
undefined_syscall:                      ; Undefined system call
2434 Serge 5735
        mov     [esp + 32], dword -1
5736
        ret
1 ha 5737
 
465 serge 5738
align 4
1055 Galkov 5739
system_shutdown:          ; shut down the system
1 ha 5740
 
3908 Serge 5741
        cmp     byte [BOOT_VARS+0x9030], 1
2434 Serge 5742
        jne     @F
5743
        ret
465 serge 5744
@@:
2434 Serge 5745
        call    stop_all_services
3626 Serge 5746
        movi    eax, 3
2434 Serge 5747
        call    sys_cd_audio
1 ha 5748
 
465 serge 5749
yes_shutdown_param:
2434 Serge 5750
        cli
1 ha 5751
 
2010 serge 5752
if ~ defined extended_primary_loader
4287 Serge 5753
; load kernel.mnt to 0x7000:0
5754
        mov     ebx, kernel_file_load
5755
        pushad
5756
        call    file_system_lfn
5757
        popad
1 ha 5758
 
2434 Serge 5759
        mov     esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5760
        mov     edi, OS_BASE+0x40000
5761
        mov     ecx, 1000
5762
        rep movsb
2010 serge 5763
end if
1 ha 5764
 
3908 Serge 5765
;        mov     esi, BOOT_VAR    ; restore 0x0 - 0xffff
5766
;        mov     edi, OS_BASE
5767
;        mov     ecx, 0x10000/4
5768
;        cld
5769
;        rep movsd
1 ha 5770
 
2434 Serge 5771
        call    IRQ_mask_all
1 ha 5772
 
1085 diamond 5773
if 0
2434 Serge 5774
        mov     word [OS_BASE+0x467+0], pr_mode_exit
5775
        mov     word [OS_BASE+0x467+2], 0x1000
1 ha 5776
 
2434 Serge 5777
        mov     al, 0x0F
5778
        out     0x70, al
5779
        mov     al, 0x05
5780
        out     0x71, al
1 ha 5781
 
2434 Serge 5782
        mov     al, 0xFE
5783
        out     0x64, al
709 diamond 5784
 
2434 Serge 5785
        hlt
5786
        jmp     $-1
1 ha 5787
 
709 diamond 5788
else
1055 Galkov 5789
        cmp     byte [OS_BASE + 0x9030], 2
5790
        jnz     no_acpi_power_off
1 ha 5791
 
709 diamond 5792
; scan for RSDP
5793
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
1055 Galkov 5794
        movzx   eax, word [OS_BASE + 0x40E]
5795
        shl     eax, 4
5796
        jz      @f
5797
        mov     ecx, 1024/16
5798
        call    scan_rsdp
5799
        jnc     .rsdp_found
709 diamond 5800
@@:
5801
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
1055 Galkov 5802
        mov     eax, 0xE0000
5803
        mov     ecx, 0x2000
5804
        call    scan_rsdp
5805
        jc      no_acpi_power_off
709 diamond 5806
.rsdp_found:
1055 Galkov 5807
        mov     esi, [eax+16]   ; esi contains physical address of the RSDT
5808
        mov     ebp, [ipc_tmp]
5809
        stdcall map_page, ebp, esi, PG_MAP
5810
        lea     eax, [esi+1000h]
5811
        lea     edx, [ebp+1000h]
5812
        stdcall map_page, edx, eax, PG_MAP
5813
        and     esi, 0xFFF
5814
        add     esi, ebp
5815
        cmp     dword [esi], 'RSDT'
5816
        jnz     no_acpi_power_off
5817
        mov     ecx, [esi+4]
5818
        sub     ecx, 24h
5819
        jbe     no_acpi_power_off
5820
        shr     ecx, 2
5821
        add     esi, 24h
709 diamond 5822
.scan_fadt:
1055 Galkov 5823
        lodsd
5824
        mov     ebx, eax
5825
        lea     eax, [ebp+2000h]
5826
        stdcall map_page, eax, ebx, PG_MAP
5827
        lea     eax, [ebp+3000h]
5828
        add     ebx, 0x1000
5829
        stdcall map_page, eax, ebx, PG_MAP
5830
        and     ebx, 0xFFF
5831
        lea     ebx, [ebx+ebp+2000h]
5832
        cmp     dword [ebx], 'FACP'
5833
        jz      .fadt_found
5834
        loop    .scan_fadt
5835
        jmp     no_acpi_power_off
709 diamond 5836
.fadt_found:
5837
; ebx is linear address of FADT
1085 diamond 5838
        mov     edi, [ebx+40] ; physical address of the DSDT
5839
        lea     eax, [ebp+4000h]
5840
        stdcall map_page, eax, edi, PG_MAP
5841
        lea     eax, [ebp+5000h]
5842
        lea     esi, [edi+0x1000]
5843
        stdcall map_page, eax, esi, PG_MAP
5844
        and     esi, 0xFFF
5845
        sub     edi, esi
5846
        cmp     dword [esi+ebp+4000h], 'DSDT'
5847
        jnz     no_acpi_power_off
5848
        mov     eax, [esi+ebp+4004h] ; DSDT length
5849
        sub     eax, 36+4
5850
        jbe     no_acpi_power_off
5851
        add     esi, 36
5852
.scan_dsdt:
5853
        cmp     dword [esi+ebp+4000h], '_S5_'
5854
        jnz     .scan_dsdt_cont
5855
        cmp     byte [esi+ebp+4000h+4], 12h ; DefPackage opcode
5856
        jnz     .scan_dsdt_cont
5857
        mov     dl, [esi+ebp+4000h+6]
5858
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
5859
                      ; ...in theory; in practice, VirtualBox has 2 bytes
5860
        ja      .scan_dsdt_cont
5861
        cmp     dl, 1
5862
        jb      .scan_dsdt_cont
5863
        lea     esi, [esi+ebp+4000h+7]
5864
        xor     ecx, ecx
5865
        cmp     byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx
5866
        jz      @f
5867
        cmp     byte [esi], 0xA
5868
        jnz     no_acpi_power_off
5869
        inc     esi
5870
        mov     cl, [esi]
5871
@@:
5872
        inc     esi
5873
        cmp     dl, 2
5874
        jb      @f
5875
        cmp     byte [esi], 0
5876
        jz      @f
5877
        cmp     byte [esi], 0xA
5878
        jnz     no_acpi_power_off
5879
        inc     esi
5880
        mov     ch, [esi]
5881
@@:
5882
        jmp     do_acpi_power_off
5883
.scan_dsdt_cont:
5884
        inc     esi
5885
        cmp     esi, 0x1000
5886
        jb      @f
5887
        sub     esi, 0x1000
5888
        add     edi, 0x1000
5889
        push    eax
5890
        lea     eax, [ebp+4000h]
5891
        stdcall map_page, eax, edi, PG_MAP
5892
        push    PG_MAP
5893
        lea     eax, [edi+1000h]
5894
        push    eax
5895
        lea     eax, [ebp+5000h]
5896
        push    eax
5897
        stdcall map_page
5898
        pop     eax
5899
@@:
5900
        dec     eax
5901
        jnz     .scan_dsdt
5902
        jmp     no_acpi_power_off
5903
do_acpi_power_off:
1055 Galkov 5904
        mov     edx, [ebx+48]
5905
        test    edx, edx
5906
        jz      .nosmi
5907
        mov     al, [ebx+52]
5908
        out     dx, al
5909
        mov     edx, [ebx+64]
709 diamond 5910
@@:
1055 Galkov 5911
        in      ax, dx
5912
        test    al, 1
5913
        jz      @b
709 diamond 5914
.nosmi:
1085 diamond 5915
        and     cx, 0x0707
5916
        shl     cx, 2
5917
        or      cx, 0x2020
1055 Galkov 5918
        mov     edx, [ebx+64]
5919
        in      ax, dx
5920
        and     ax, 203h
1085 diamond 5921
        or      ah, cl
1055 Galkov 5922
        out     dx, ax
5923
        mov     edx, [ebx+68]
5924
        test    edx, edx
5925
        jz      @f
5926
        in      ax, dx
5927
        and     ax, 203h
1085 diamond 5928
        or      ah, ch
1055 Galkov 5929
        out     dx, ax
709 diamond 5930
@@:
1055 Galkov 5931
        jmp     $
709 diamond 5932
 
5933
 
5934
no_acpi_power_off:
2434 Serge 5935
        mov     word [OS_BASE+0x467+0], pr_mode_exit
5936
        mov     word [OS_BASE+0x467+2], 0x1000
709 diamond 5937
 
2434 Serge 5938
        mov     al, 0x0F
5939
        out     0x70, al
5940
        mov     al, 0x05
5941
        out     0x71, al
709 diamond 5942
 
2434 Serge 5943
        mov     al, 0xFE
5944
        out     0x64, al
709 diamond 5945
 
2434 Serge 5946
        hlt
5947
        jmp     $-1
709 diamond 5948
 
5949
scan_rsdp:
1055 Galkov 5950
        add     eax, OS_BASE
709 diamond 5951
.s:
1055 Galkov 5952
        cmp     dword [eax], 'RSD '
5953
        jnz     .n
5954
        cmp     dword [eax+4], 'PTR '
5955
        jnz     .n
5956
        xor     edx, edx
5957
        xor     esi, esi
709 diamond 5958
@@:
1055 Galkov 5959
        add     dl, [eax+esi]
5960
        inc     esi
5961
        cmp     esi, 20
5962
        jnz     @b
5963
        test    dl, dl
5964
        jz      .ok
709 diamond 5965
.n:
1055 Galkov 5966
        add     eax, 10h
5967
        loop    .s
5968
        stc
709 diamond 5969
.ok:
1055 Galkov 5970
        ret
709 diamond 5971
end if
5972
 
3626 Serge 5973
if ~ lang eq sp
5974
diff16 "end of .text segment",0,$
5975
end if
5976
 
465 serge 5977
include "data32.inc"
1 ha 5978
 
465 serge 5979
__REV__ = __REV
1 ha 5980
 
3500 Serge 5981
if ~ lang eq sp
41 mikedld 5982
diff16 "end of kernel code",0,$
3500 Serge 5983
end if