Subversion Repositories Kolibri OS

Rev

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

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