Subversion Repositories Kolibri OS

Rev

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

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