Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
9715 Doczom 3
;; Copyright (C) KolibriOS team 2004-2022. 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: 9930 $
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
9715 Doczom 198
        mov     ecx, (HEAP_BASE - OS_BASE - CLEAN_ZONE) / 4
2288 clevermous 199
        cld
200
        rep stosd
201
 
202
; CLEAR KERNEL UNDEFINED GLOBALS
9715 Doczom 203
        mov     edi, endofcode - OS_BASE
2288 clevermous 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
9715 Doczom 219
        bts     [cpu_caps - OS_BASE], CAPS_TSC    ;force use rdtsc
2288 clevermous 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
 
9715 Doczom 230
        mov     eax, sys_proc - OS_BASE + PROC.pdt_0
2288 clevermous 231
        mov     cr3, eax
232
 
233
        mov     eax, cr0
9715 Doczom 234
        or      eax, CR0_PG + CR0_WP
2288 clevermous 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
9715 Doczom 246
        lgdt    [cs:gdts_ap - ap_init16]
247
        mov     eax, [cs:cr3_ap - ap_init16]
5033 clevermous 248
        mov     cr3, eax
9715 Doczom 249
        mov     eax, [cs:cr4_ap - ap_init16]
5033 clevermous 250
        mov     cr4, eax
9715 Doczom 251
        mov     eax, CR0_PE + CR0_PG + CR0_WP
5033 clevermous 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
9715 Doczom 286
        mov     ebx, 0xFFFFF000 + PG_SHARED + PG_NOCACHE + PG_UWR
5360 serge 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
 
9715 Doczom 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
9715 Doczom 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
 
9715 Doczom 459
        lea     esp, [eax + RING0_STACK_SIZE]
2288 clevermous 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
 
9715 Doczom 518
        stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE + (unpack.LZMA_LIT_SIZE shl \
519
                (unpack.lc + unpack.lp)))*4
2288 clevermous 520
 
521
        mov     [unpack.p], eax
522
 
523
        call    init_events
9715 Doczom 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
9926 Doczom 554
        stdcall kernel_alloc, PAGE_SIZE
4199 mario79 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
9715 Doczom 567
        stdcall map_io_mem, [hpet_base], 1024, PG_GLOBAL + PAT_UC + PG_SWR
5787 serge 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
 
9715 Doczom 578
        mov     edi, sys_proc + PROC.heap_lock
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
 
9715 Doczom 596
        mov     [sys_proc + PROC.pdt_0_phys], sys_proc - OS_BASE + PROC.pdt_0
5595 serge 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
 
9715 Doczom 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'
9715 Doczom 617
        sub     [edx + APPDATA.saved_esp], 4
618
        mov     eax, [edx + APPDATA.saved_esp]
3534 clevermous 619
        mov     dword [eax], idle_thread
620
        mov     ecx, IDLE_PRIORITY
621
        call    scheduler_add_thread
3296 clevermous 622
 
9715 Doczom 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
3296 clevermous 633
 
5033 clevermous 634
; Move other CPUs to deep sleep, if it is useful
635
uglobal
636
use_mwait_for_idle db 0
637
endg
638
        cmp     [cpu_vendor+8], 'ntel'
639
        jnz     .no_wake_cpus
640
        bt      [cpu_caps+4], CAPS_MONITOR-32
641
        jnc     .no_wake_cpus
642
        dbgstr 'using mwait for idle loop'
643
        inc     [use_mwait_for_idle]
644
        mov     ebx, [cpu_count]
645
        cmp     ebx, 1
646
        jbe     .no_wake_cpus
647
        call    create_trampoline_pgmap
9715 Doczom 648
        mov     [cr3_ap + OS_BASE], eax
5033 clevermous 649
        mov     eax, cr4
9715 Doczom 650
        mov     [cr4_ap + OS_BASE], eax
5033 clevermous 651
        mov     esi, OS_BASE + ap_init16
652
        mov     edi, OS_BASE + 8000h
653
        mov     ecx, (ap_init16_size + 3) / 4
654
        rep movsd
8119 dunkaist 655
        mov     eax, [LAPIC_BASE]
656
        test    eax, eax
657
        jnz     @f
9715 Doczom 658
        stdcall map_io_mem, [acpi_lapic_base], 0x1000, PG_GLOBAL + PG_NOCACHE + PG_SWR
5033 clevermous 659
        mov     [LAPIC_BASE], eax
8119 dunkaist 660
@@:
9715 Doczom 661
        lea     edi, [eax + APIC_ICRL]
5033 clevermous 662
        mov     esi, smpt+4
663
        dec     ebx
664
.wake_cpus_loop:
665
        lodsd
5049 clevermous 666
        push    esi
667
        xor     esi, esi
668
        inc     esi
5033 clevermous 669
        shl     eax, 24
670
        mov     [edi+10h], eax
671
; assert INIT IPI
672
        mov     dword [edi], 0C500h
5049 clevermous 673
        call    delay_ms
5033 clevermous 674
@@:
675
        test    dword [edi], 1000h
676
        jnz     @b
677
; deassert INIT IPI
678
        mov     dword [edi], 8500h
5049 clevermous 679
        call    delay_ms
5033 clevermous 680
@@:
681
        test    dword [edi], 1000h
682
        jnz     @b
683
; send STARTUP IPI
684
        mov     dword [edi], 600h + (8000h shr 12)
5049 clevermous 685
        call    delay_ms
5033 clevermous 686
@@:
687
        test    dword [edi], 1000h
688
        jnz     @b
5049 clevermous 689
        pop     esi
5033 clevermous 690
        dec     ebx
691
        jnz     .wake_cpus_loop
692
        mov     eax, [cpu_count]
693
        dec     eax
694
@@:
695
        cmp     [ap_initialized], eax
696
        jnz     @b
9715 Doczom 697
        mov     eax, [cr3_ap + OS_BASE]
5033 clevermous 698
        call    free_page
699
.no_wake_cpus:
2288 clevermous 700
 
701
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
2642 mario79 702
        mov     esi, boot_initirq
703
        call    boot_log
704
        call    init_irqs
2288 clevermous 705
 
2642 mario79 706
        mov     esi, boot_picinit
707
        call    boot_log
2288 clevermous 708
        call    PIC_init
709
 
2642 mario79 710
        mov     esi, boot_v86machine
711
        call    boot_log
2288 clevermous 712
; Initialize system V86 machine
713
        call    init_sys_v86
714
 
2642 mario79 715
        mov     esi, boot_inittimer
716
        call    boot_log
2288 clevermous 717
; Initialize system timer (IRQ0)
718
        call    PIT_init
719
 
4273 clevermous 720
; Register ramdisk file system
8091 dunkaist 721
if ~ defined extended_primary_loader
8089 dunkaist 722
        cmp     [BOOT.rd_load_from], RD_LOAD_FROM_HD    ; will be loaded later
4772 mario79 723
        je      @f
8091 dunkaist 724
end if
8089 dunkaist 725
        cmp     [BOOT.rd_load_from], RD_LOAD_FROM_NONE
726
        je      @f
727
        call    register_ramdisk
4772 mario79 728
;--------------------------------------
729
@@:
2642 mario79 730
        mov     esi, boot_initapic
731
        call    boot_log
2288 clevermous 732
; Try to Initialize APIC
733
        call    APIC_init
734
 
2642 mario79 735
        mov     esi, boot_enableirq
736
        call    boot_log
3785 mario79 737
; Enable timer IRQ (IRQ0) and co-processor IRQ (IRQ13)
2288 clevermous 738
; they are used: when partitions are scanned, hd_read relies on timer
739
        call    unmask_timer
7733 dunkaist 740
        ; Prevent duplicate timer IRQs in APIC mode
741
        cmp     [irq_mode], IRQ_APIC
742
        jz      @f
2288 clevermous 743
        stdcall enable_irq, 2               ; @#$%! PIC
7733 dunkaist 744
@@:
2288 clevermous 745
        stdcall enable_irq, 13              ; co-processor
4741 hidnplayr 746
 
747
; Setup serial output console (if enabled)
748
if defined debug_com_base
749
 
750
        ; reserve port so nobody else will use it
751
        xor     ebx, ebx
752
        mov     ecx, debug_com_base
753
        mov     edx, debug_com_base+7
754
        call    r_f_port_area
755
 
756
        ; enable Divisor latch
757
        mov     dx, debug_com_base+3
758
        mov     al, 1 shl 7
759
        out     dx, al
760
 
761
        ; Set speed to 115200 baud (max speed)
762
        mov     dx, debug_com_base
763
        mov     al, 0x01
764
        out     dx, al
765
 
766
        mov     dx, debug_com_base+1
767
        mov     al, 0x00
768
        out     dx, al
769
 
770
        ; No parity, 8bits words, one stop bit, dlab bit back to 0
771
        mov     dx, debug_com_base+3
772
        mov     al, 3
773
        out     dx, al
774
 
775
        ; disable interrupts
776
        mov     dx, debug_com_base+1
777
        mov     al, 0
778
        out     dx, al
779
 
780
        ; clear +  enable fifo (64 bits)
781
        mov     dx, debug_com_base+2
782
        mov     al, 0x7 + 1 shl 5
783
        out     dx, al
784
 
785
end if
786
 
787
 
4575 mario79 788
;-----------------------------------------------------------------------------
789
; show SVN version of kernel on the message board
790
;-----------------------------------------------------------------------------
791
        mov     eax, [version_inf.rev]
792
        DEBUGF  1, "K : kernel SVN r%d\n", eax
793
;-----------------------------------------------------------------------------
794
; show CPU count on the message board
795
;-----------------------------------------------------------------------------
796
        mov     eax, [cpu_count]
797
        test    eax, eax
798
        jnz     @F
799
        mov     al, 1                             ; at least one CPU
800
@@:
801
        DEBUGF  1, "K : %d CPU detected\n", eax
802
;-----------------------------------------------------------------------------
803
; detect Floppy drives
804
;-----------------------------------------------------------------------------
805
        mov     esi, boot_detectfloppy
806
        call    boot_log
807
include 'detect/dev_fd.inc'
808
;-----------------------------------------------------------------------------
4624 mario79 809
; create pci-devices list
4575 mario79 810
;-----------------------------------------------------------------------------
4624 mario79 811
        mov     [pci_access_enabled], 1
812
        call    pci_enum
3762 mario79 813
;-----------------------------------------------------------------------------
4624 mario79 814
; initialisation IDE ATA code
4575 mario79 815
;-----------------------------------------------------------------------------
4624 mario79 816
include 'detect/init_ata.inc'
4575 mario79 817
;-----------------------------------------------------------------------------
9183 rgimad 818
; initialisation AHCI code
819
;-----------------------------------------------------------------------------
820
        jmp     ahci_code_end
821
include 'blkdev/ahci.inc'
822
ahci_code_end:
823
        call    ahci_init
824
;-----------------------------------------------------------------------------
2288 clevermous 825
if 0
8089 dunkaist 826
        mov     ax, [BOOT.sys_disk]
2288 clevermous 827
        cmp     ax, 'r1'; if using not ram disk, then load librares and parameters {SPraid.simba}
828
        je      no_lib_load
2642 mario79 829
 
830
        mov     esi, boot_loadlibs
831
        call    boot_log
2288 clevermous 832
; LOADING LIBRARES
833
        stdcall dll.Load, @IMPORT           ; loading librares for kernel (.obj files)
834
        call    load_file_parse_table       ; prepare file parse table
835
        call    set_kernel_conf             ; configure devices and gui
836
no_lib_load:
837
end if
838
 
839
; Display APIC status
840
        mov     esi, boot_APIC_found
841
        cmp     [irq_mode], IRQ_APIC
842
        je      @f
843
        mov     esi, boot_APIC_nfound
844
@@:
2642 mario79 845
        call    boot_log
2288 clevermous 846
 
847
; PRINT AMOUNT OF MEMORY
848
        mov     esi, boot_memdetect
849
        call    boot_log
850
 
851
        movzx   ecx, word [boot_y]
852
        if lang eq ru
853
        or      ecx, (10+30*6) shl 16
3274 esevece 854
        else if lang eq sp
855
        or      ecx, (10+33*6) shl 16
856
        else
2288 clevermous 857
        or      ecx, (10+29*6) shl 16
3274 esevece 858
        end if
2288 clevermous 859
        sub     ecx, 10
860
        mov     edx, 0xFFFFFF
861
        mov     ebx, [MEM_AMOUNT]
862
        shr     ebx, 20
863
        xor     edi, edi
864
        mov     eax, 0x00040000
865
        inc     edi
866
        call    display_number_force
867
 
868
; BUILD SCHEDULER
869
 
2642 mario79 870
;        call    build_scheduler; sys32.inc
2288 clevermous 871
 
2642 mario79 872
;        mov     esi, boot_devices
873
;        call    boot_log
2288 clevermous 874
 
4297 yogev_ezra 875
include "detect/vortex86.inc"                     ; Vortex86 SoC detection code
876
 
5039 clevermous 877
        stdcall load_pe_driver, szVidintel, 0
3508 clevermous 878
 
3520 clevermous 879
        call    usb_init
880
 
2288 clevermous 881
; SET PRELIMINARY WINDOW STACK AND POSITIONS
882
 
883
        mov     esi, boot_windefs
884
        call    boot_log
885
        call    set_window_defaults
886
 
887
; SET BACKGROUND DEFAULTS
888
 
889
        mov     esi, boot_bgr
890
        call    boot_log
891
        call    init_background
892
        call    calculatebackground
893
 
894
; RESERVE SYSTEM IRQ'S JA PORT'S
895
 
896
        mov     esi, boot_resirqports
897
        call    boot_log
898
        call    reserve_irqs_ports
899
 
9930 Doczom 900
        mov     [SLOT_BASE + APPDATA.window], window_data
901
        mov     [SLOT_BASE + sizeof.APPDATA + APPDATA.window], window_data + sizeof.WDATA
902
        mov     [SLOT_BASE + sizeof.APPDATA*2 + APPDATA.window], window_data + sizeof.WDATA*2
903
        mov     [window_data + WDATA.thread], SLOT_BASE
904
        mov     [window_data + sizeof.WDATA + WDATA.thread], SLOT_BASE + sizeof.APPDATA
905
        mov     [window_data + sizeof.WDATA*2 + WDATA.thread], SLOT_BASE + sizeof.APPDATA*2
906
 
2288 clevermous 907
        call    init_display
908
        mov     eax, [def_cursor]
9930 Doczom 909
        mov     [window_data + sizeof.WDATA + WDATA.cursor], eax
910
        mov     [window_data + sizeof.WDATA*2 + WDATA.cursor], eax
2288 clevermous 911
 
3501 Serge 912
; PRINT CPU FREQUENCY
2288 clevermous 913
 
3501 Serge 914
        mov     esi, boot_cpufreq
2288 clevermous 915
        call    boot_log
3501 Serge 916
 
5792 serge 917
        cli
918
        mov     ebx, [hpet_base]
919
        test    ebx, ebx
920
        jz      @F
9715 Doczom 921
        mov     ebx, [ebx + HPET_COUNTER]
5792 serge 922
 
3501 Serge 923
        rdtsc
5792 serge 924
        mov     ecx, 1000
925
        sub     eax, [hpet_tsc_start]
9715 Doczom 926
        sbb     edx, [hpet_tsc_start + 4]
5792 serge 927
        shld    edx, eax, 10
928
        shl     eax, 10
929
        mov     esi, eax
930
        mov     eax, edx
931
        mul     ecx
932
        xchg    eax, esi
933
        mul     ecx
934
        adc     edx, esi
935
        div     ebx
936
        mul     ecx
937
        div     [hpet_period]
938
        mul     ecx
939
        DEBUGF  1, "K : cpu frequency %u Hz\n", eax
940
        jmp     .next
941
@@:
942
        rdtsc
2288 clevermous 943
        mov     ecx, eax
944
        mov     esi, 250            ; wait 1/4 a second
945
        call    delay_ms
3501 Serge 946
        rdtsc
947
 
2288 clevermous 948
        sub     eax, ecx
3481 Serge 949
        xor     edx, edx
950
        shld    edx, eax, 2
2288 clevermous 951
        shl     eax, 2
5792 serge 952
.next:
3481 Serge 953
        mov     dword [cpu_freq], eax
9715 Doczom 954
        mov     dword [cpu_freq + 4], edx
3502 Serge 955
        mov     ebx, 1000000
956
        div     ebx
3501 Serge 957
        mov     ebx, eax
2288 clevermous 958
 
959
        movzx   ecx, word [boot_y]
960
        if lang eq ru
3501 Serge 961
        add     ecx, (10+19*6) shl 16 - 10
3274 esevece 962
        else if lang eq sp
3501 Serge 963
        add     ecx, (10+25*6) shl 16 - 10
3274 esevece 964
        else
3501 Serge 965
        add     ecx, (10+17*6) shl 16 - 10
3274 esevece 966
        end if
3501 Serge 967
 
2288 clevermous 968
        mov     edx, 0xFFFFFF
969
        xor     edi, edi
970
        mov     eax, 0x00040000
971
        inc     edi
972
        call    display_number_force
973
 
974
; SET VARIABLES
975
 
976
        call    set_variables
977
 
978
; STACK AND FDC
979
 
980
        call    stack_init
981
        call    fdc_init
982
 
983
; PALETTE FOR 320x200 and 640x480 16 col
984
 
985
        cmp     [SCR_MODE], word 0x12
986
        jne     no_pal_vga
987
        mov     esi, boot_pal_vga
988
        call    boot_log
989
        call    paletteVGA
990
      no_pal_vga:
991
 
992
        cmp     [SCR_MODE], word 0x13
993
        jne     no_pal_ega
994
        mov     esi, boot_pal_ega
995
        call    boot_log
996
        call    palette320x200
997
      no_pal_ega:
998
 
999
; LOAD DEFAULT SKIN
1000
 
1001
        call    load_default_skin
1002
 
5635 hidnplayr 1003
; Protect I/O permission map
2288 clevermous 1004
 
1005
        mov     esi, [default_io_map]
9715 Doczom 1006
        stdcall map_page, esi, [SLOT_BASE + sizeof.APPDATA + APPDATA.io_map], PG_READ
2288 clevermous 1007
        add     esi, 0x1000
9715 Doczom 1008
        stdcall map_page, esi, [SLOT_BASE + sizeof.APPDATA + APPDATA.io_map + 4], PG_READ
2288 clevermous 1009
 
1010
        stdcall map_page, tss._io_map_0, \
9715 Doczom 1011
                [SLOT_BASE + sizeof.APPDATA + APPDATA.io_map], PG_READ
2288 clevermous 1012
        stdcall map_page, tss._io_map_1, \
9715 Doczom 1013
                [SLOT_BASE + sizeof.APPDATA + APPDATA.io_map + 4], PG_READ
2288 clevermous 1014
 
1015
; SET KEYBOARD PARAMETERS
1016
        mov     al, 0xf6       ; reset keyboard, scan enabled
5012 clevermous 1017
        call    kb_write_wait_ack
2601 clevermous 1018
        test    ah, ah
1019
        jnz     .no_keyboard
2288 clevermous 1020
 
2601 clevermous 1021
iglobal
1022
align 4
1023
ps2_keyboard_functions:
1024
        dd      .end - $
1025
        dd      0       ; no close
1026
        dd      ps2_set_lights
1027
.end:
1028
endg
1029
        stdcall register_keyboard, ps2_keyboard_functions, 0
2288 clevermous 1030
       ; mov   al, 0xED       ; Keyboard LEDs - only for testing!
5012 clevermous 1031
       ; call  kb_write_wait_ack
2288 clevermous 1032
       ; mov   al, 111b
5012 clevermous 1033
       ; call  kb_write_wait_ack
2288 clevermous 1034
 
1035
        mov     al, 0xF3     ; set repeat rate & delay
5012 clevermous 1036
        call    kb_write_wait_ack
2288 clevermous 1037
        mov     al, 0; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
5012 clevermous 1038
        call    kb_write_wait_ack
2288 clevermous 1039
     ;// mike.dld [
1040
        call    set_lights
1041
     ;// mike.dld ]
1042
        stdcall attach_int_handler, 1, irq1, 0
4734 mario79 1043
        DEBUGF  1, "K : IRQ1 return code %x\n", eax
2601 clevermous 1044
.no_keyboard:
2288 clevermous 1045
 
4553 hidnplayr 1046
; Load PS/2 mouse driver
2288 clevermous 1047
        mov     esi, boot_setmouse
1048
        call    boot_log
9514 rgimad 1049
        stdcall load_pe_driver, szPS2MDriver, 0
2288 clevermous 1050
 
5031 clevermous 1051
; LOAD FIRST APPLICATION
1052
        cmp     byte [launcher_start], 1        ; Check if starting LAUNCHER is selected on blue screen (1 = yes)
1053
        jnz     first_app_found
1054
 
1055
        cli
1056
        mov     ebp, firstapp
1057
        call    fs_execute_from_sysdir
1058
        test    eax, eax
1059
        jns     first_app_found
1060
 
1061
        mov     esi, boot_failed
1062
        call    boot_log
1063
 
1064
        mov     eax, 0xDEADBEEF      ; otherwise halt
1065
        hlt
1066
 
1067
first_app_found:
1068
 
2288 clevermous 1069
; START MULTITASKING
7129 dunkaist 1070
preboot_blogesc = 0       ; start immediately after bootlog
2288 clevermous 1071
 
1072
; A 'All set - press ESC to start' messages if need
1073
if preboot_blogesc
1074
        mov     esi, boot_tasking
1075
        call    boot_log
1076
.bll1:
1077
        in      al, 0x60        ; wait for ESC key press
1078
        cmp     al, 129
1079
        jne     .bll1
1080
end if
1081
 
1082
        mov     [timer_ticks_enable], 1         ; for cd driver
1083
        sti
4734 mario79 1084
 
4608 clevermous 1085
        call    mtrr_validate
1086
 
2288 clevermous 1087
        jmp     osloop
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
9715 Doczom 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
9715 Doczom 1152
        mov     [edx + APPDATA.io_map], eax
3535 clevermous 1153
        mov     eax, tss+0x1080
1154
        call    get_pg_addr
1155
        inc     eax
9715 Doczom 1156
        mov     [edx + APPDATA.io_map + 4], eax
3535 clevermous 1157
 
9715 Doczom 1158
        mov     dword [edx + APPDATA.pl0_stack], ebx
1159
        lea     edi, [ebx + RING0_STACK_SIZE]
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
3534 clevermous 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
 
9715 Doczom 1171
        lea     eax, [edx + APP_EV_OFFSET]
1172
        mov     dword [edx + APPDATA.fd_ev], eax
1173
        mov     dword [edx + APPDATA.bk_ev], eax
8087 dunkaist 1174
 
9715 Doczom 1175
        lea     eax, [edx + APP_OBJ_OFFSET]
1176
        mov     dword [edx + APPDATA.fd_obj], eax
1177
        mov     dword [edx + APPDATA.bk_obj], eax
3534 clevermous 1178
 
9715 Doczom 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
 
9715 Doczom 1183
        lea     ebx, [edx + APPDATA.list]
1184
        lea     ecx, [sys_proc + PROC.thr_list]
5130 serge 1185
        list_add_tail ebx, ecx
1186
 
9715 Doczom 1187
        mov     [edx + APPDATA.wnd_number], dh
1188
        mov     byte [edx + APPDATA.tid], dh
9930 Doczom 1189
        movzx   eax, dh
1190
        shl     eax, BSF sizeof.WDATA
1191
        add     eax, window_data
1192
        mov     [edx + APPDATA.window], eax
3534 clevermous 1193
 
1194
        ret
1195
endp
1196
 
2288 clevermous 1197
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1198
;                                                                    ;
1199
;                    MAIN OS LOOP START                              ;
1200
;                                                                    ;
1201
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1202
align 32
1203
osloop:
3534 clevermous 1204
        mov     edx, osloop_has_work?
1205
        xor     ecx, ecx
1206
        call    Wait_events
1207
        xor     eax, eax
1208
        xchg    eax, [osloop_nonperiodic_work]
1209
        test    eax, eax
1210
        jz      .no_periodic
4734 mario79 1211
 
2453 mario79 1212
        call    __sys_draw_pointer
2288 clevermous 1213
        call    window_check_events
1214
        call    mouse_check_events
1215
        call    checkmisc
1216
        call    checkVga_N13
4734 mario79 1217
;--------------------------------------
3534 clevermous 1218
.no_periodic:
2288 clevermous 1219
        call    stack_handler
1220
        call    check_fdd_motor_status
1221
        call    check_ATAPI_device_event
2601 clevermous 1222
        call    check_lights_state
2288 clevermous 1223
        call    check_timers
4734 mario79 1224
 
2288 clevermous 1225
        jmp     osloop
1226
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1227
;                                                                    ;
1228
;                      MAIN OS LOOP END                              ;
1229
;                                                                    ;
1230
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3534 clevermous 1231
proc osloop_has_work?
1232
        cmp     [osloop_nonperiodic_work], 0
1233
        jnz     .yes
1234
        call    stack_handler_has_work?
1235
        jnz     .yes
4273 clevermous 1236
        call    check_fdd_motor_status_has_work?
1237
        jnz     .yes
3534 clevermous 1238
        call    check_ATAPI_device_event_has_work?
1239
        jnz     .yes
1240
        call    check_lights_state_has_work?
1241
        jnz     .yes
1242
        call    check_timers_has_work?
1243
        jnz     .yes
1244
.no:
1245
        xor     eax, eax
2288 clevermous 1246
        ret
3534 clevermous 1247
.yes:
1248
        xor     eax, eax
1249
        inc     eax
1250
        ret
1251
endp
2288 clevermous 1252
 
3534 clevermous 1253
proc wakeup_osloop
1254
        mov     [osloop_nonperiodic_work], 1
1255
        ret
1256
endp
1257
 
2288 clevermous 1258
uglobal
3534 clevermous 1259
align 4
1260
osloop_nonperiodic_work dd      ?
2288 clevermous 1261
endg
1262
 
5033 clevermous 1263
uglobal
1264
align 64
1265
idle_addr       rb      64
1266
endg
1267
 
3534 clevermous 1268
idle_thread:
1269
        sti
5033 clevermous 1270
 
1271
; The following code can be executed by all CPUs in the system.
1272
; All other parts of the kernel do not expect multi-CPU.
1273
; Also, APs don't even have a stack here.
1274
; Beware. Don't do anything here. Anything at all.
3534 clevermous 1275
idle_loop:
5033 clevermous 1276
        cmp     [use_mwait_for_idle], 0
9911 Doczom 1277
        jnz     .mwait
5033 clevermous 1278
 
9911 Doczom 1279
.hlt:
3534 clevermous 1280
        hlt
9911 Doczom 1281
        jmp     .hlt
2288 clevermous 1282
 
9911 Doczom 1283
.mwait:
5033 clevermous 1284
        mov     eax, idle_addr
1285
        xor     ecx, ecx
1286
        xor     edx, edx
1287
        monitor
1288
        xor     ecx, ecx
1289
        mov     eax, 20h        ; or 10h
1290
        mwait
9911 Doczom 1291
        jmp     .mwait
2288 clevermous 1292
 
3534 clevermous 1293
 
2288 clevermous 1294
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1295
;                                                                      ;
1296
;                   INCLUDED SYSTEM FILES                              ;
1297
;                                                                      ;
1298
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1299
 
1300
 
1301
include "kernel32.inc"
1302
 
1303
 
1304
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1305
;                                                                      ;
1306
;                       KERNEL FUNCTIONS                               ;
1307
;                                                                      ;
1308
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1309
 
1310
reserve_irqs_ports:
1311
 
1312
 
1313
; RESERVE PORTS
1314
        mov     eax, RESERVED_PORTS
1315
        mov     ecx, 1
1316
 
1317
        mov     [eax], dword 4
1318
 
1319
        mov     [eax+16], ecx
1320
        mov     [eax+16+4], dword 0
3426 hidnplayr 1321
        mov     [eax+16+8], dword 0x2D
2288 clevermous 1322
 
1323
        mov     [eax+32], ecx
1324
        mov     [eax+32+4], dword 0x30
1325
        mov     [eax+32+8], dword 0x4D
1326
 
1327
        mov     [eax+48], ecx
1328
        mov     [eax+48+4], dword 0x50
3426 hidnplayr 1329
        mov     [eax+48+8], dword 0xDF
2288 clevermous 1330
 
1331
        mov     [eax+64], ecx
1332
        mov     [eax+64+4], dword 0xE5
1333
        mov     [eax+64+8], dword 0xFF
1334
 
1335
        ret
1336
 
1337
 
1338
iglobal
3534 clevermous 1339
  process_number dd 0x2
2288 clevermous 1340
endg
1341
 
1342
set_variables:
1343
 
1344
        mov     ecx, 0x16                    ; flush port 0x60
9911 Doczom 1345
@@:
2288 clevermous 1346
        in      al, 0x60
9911 Doczom 1347
        loop    @b
2288 clevermous 1348
        push    eax
1349
 
7132 dunkaist 1350
        mov     ax, [BOOT.y_res]
2288 clevermous 1351
        shr     ax, 1
1352
        shl     eax, 16
7132 dunkaist 1353
        mov     ax, [BOOT.x_res]
2288 clevermous 1354
        shr     ax, 1
1355
        mov     [MOUSE_X], eax
3534 clevermous 1356
        call    wakeup_osloop
2288 clevermous 1357
 
1358
        xor     eax, eax
1359
        mov     [BTN_ADDR], dword BUTTON_INFO ; address of button list
1360
 
1361
        mov     byte [KEY_COUNT], al              ; keyboard buffer
1362
        mov     byte [BTN_COUNT], al              ; button buffer
1363
 
1364
        pop     eax
1365
        ret
9488 rgimad 1366
;-----------------------------------------------------------------------------
2288 clevermous 1367
 
1368
align 4
1369
display_number:
8713 Doczom 1370
; add check pointers
1371
        test    bl, bl
1372
        jz      @f
9910 Doczom 1373
        bt      ebx, 30  ; check 30 bit
1374
        jb      @f
1375
        stdcall is_region_userspace, ecx, 4
9045 dunkaist 1376
        jz      @f
8713 Doczom 1377
        ret
1378
@@:
9910 Doczom 1379
        jz      @f
1380
        stdcall is_region_userspace, ecx, 8
1381
        jz      @f
1382
        ret
1383
@@:
8713 Doczom 1384
        test    esi, 0x08000000
1385
        jz      @f
1386
        stdcall is_region_userspace, edi, 1
9045 dunkaist 1387
        jz      @f
8713 Doczom 1388
        ret
1389
@@:
2288 clevermous 1390
;It is not optimization
1391
        mov     eax, ebx
1392
        mov     ebx, ecx
1393
        mov     ecx, edx
1394
        mov     edx, esi
1395
        mov     esi, edi
1396
; eax = print type, al=0 -> ebx is number
1397
;                   al=1 -> ebx is pointer
1398
;                   ah=0 -> display decimal
1399
;                   ah=1 -> display hexadecimal
1400
;                   ah=2 -> display binary
1401
;                   eax bits 16-21 = number of digits to display (0-32)
1402
;                   eax bits 22-31 = reserved
1403
;
1404
; ebx = number or pointer
1405
; ecx = x shl 16 + y
1406
; edx = color
1407
        xor     edi, edi
1408
display_number_force:
1409
        push    eax
1410
        and     eax, 0x3fffffff
1411
        cmp     eax, 0xffff     ; length > 0 ?
1412
        pop     eax
9911 Doczom 1413
        jge     .cont_displ
2288 clevermous 1414
        ret
9911 Doczom 1415
   .cont_displ:
2288 clevermous 1416
        push    eax
1417
        and     eax, 0x3fffffff
1418
        cmp     eax, 61*0x10000  ; length <= 60 ?
1419
        pop     eax
9911 Doczom 1420
        jb      .cont_displ2
2288 clevermous 1421
        ret
9911 Doczom 1422
   .cont_displ2:
2288 clevermous 1423
 
1424
        pushad
1425
 
1426
        cmp     al, 1            ; ecx is a pointer ?
9911 Doczom 1427
        jne     @f
2288 clevermous 1428
        mov     ebp, ebx
1429
        add     ebp, 4
9911 Doczom 1430
        mov     ebp, [ebp] ;[ebp + std_application_base_address]
1431
        mov     ebx, [ebx] ;[ebx + std_application_base_address]
1432
@@:
2288 clevermous 1433
        sub     esp, 64
1434
 
1435
        test    ah, ah            ; DECIMAL
9911 Doczom 1436
        jnz     .no_display_desnum
1437
 
2288 clevermous 1438
        shr     eax, 16
1439
        and     eax, 0xC03f
1440
;     and   eax,0x3f
1441
        push    eax
1442
        and     eax, 0x3f
1443
        mov     edi, esp
1444
        add     edi, 4+64-1
1445
        mov     ecx, eax
1446
        mov     eax, ebx
1447
        mov     ebx, 10
9911 Doczom 1448
@@:
2288 clevermous 1449
        xor     edx, edx
1450
        call    division_64_bits
1451
        div     ebx
1452
        add     dl, 48
1453
        mov     [edi], dl
1454
        dec     edi
9911 Doczom 1455
        loop    @b
1456
 
2288 clevermous 1457
        pop     eax
1458
        call    normalize_number
1459
        call    draw_num_text
1460
        add     esp, 64
1461
        popad
1462
        ret
9911 Doczom 1463
.no_display_desnum:
2288 clevermous 1464
 
1465
        cmp     ah, 0x01         ; HEXADECIMAL
9911 Doczom 1466
        jne     .no_display_hexnum
1467
 
2288 clevermous 1468
        shr     eax, 16
1469
        and     eax, 0xC03f
1470
;     and   eax,0x3f
1471
        push    eax
1472
        and     eax, 0x3f
1473
        mov     edi, esp
1474
        add     edi, 4+64-1
1475
        mov     ecx, eax
1476
        mov     eax, ebx
1477
        mov     ebx, 16
9911 Doczom 1478
@@:
2288 clevermous 1479
        xor     edx, edx
1480
        call    division_64_bits
1481
        div     ebx
9911 Doczom 1482
   ;hexletters = __fdo_hexdigits
1483
        add     edx, __fdo_hexdigits ;hexletters
2288 clevermous 1484
        mov     dl, [edx]
1485
        mov     [edi], dl
1486
        dec     edi
9911 Doczom 1487
        loop    @b
1488
 
2288 clevermous 1489
        pop     eax
1490
        call    normalize_number
1491
        call    draw_num_text
1492
        add     esp, 64
1493
        popad
1494
        ret
9911 Doczom 1495
.no_display_hexnum:
2288 clevermous 1496
 
1497
        cmp     ah, 0x02         ; BINARY
9911 Doczom 1498
        jne     .no_display_binnum
1499
 
2288 clevermous 1500
        shr     eax, 16
1501
        and     eax, 0xC03f
1502
;     and   eax,0x3f
1503
        push    eax
1504
        and     eax, 0x3f
1505
        mov     edi, esp
1506
        add     edi, 4+64-1
1507
        mov     ecx, eax
1508
        mov     eax, ebx
1509
        mov     ebx, 2
9911 Doczom 1510
@@:
2288 clevermous 1511
        xor     edx, edx
1512
        call    division_64_bits
1513
        div     ebx
1514
        add     dl, 48
1515
        mov     [edi], dl
1516
        dec     edi
9911 Doczom 1517
        loop    @b
1518
 
2288 clevermous 1519
        pop     eax
1520
        call    normalize_number
1521
        call    draw_num_text
1522
        add     esp, 64
1523
        popad
1524
        ret
9911 Doczom 1525
.no_display_binnum:
2288 clevermous 1526
 
1527
        add     esp, 64
1528
        popad
1529
        ret
1530
 
1531
normalize_number:
1532
        test    ah, 0x80
1533
        jz      .continue
1534
        mov     ecx, 48
1535
        and     eax, 0x3f
1536
@@:
1537
        inc     edi
1538
        cmp     [edi], cl
1539
        jne     .continue
1540
        dec     eax
1541
        cmp     eax, 1
1542
        ja      @r
1543
        mov     al, 1
1544
.continue:
1545
        and     eax, 0x3f
1546
        ret
1547
 
1548
division_64_bits:
1549
        test    [esp+1+4], byte 0x40
1550
        jz      .continue
1551
        push    eax
1552
        mov     eax, ebp
1553
        div     ebx
1554
        mov     ebp, eax
1555
        pop     eax
1556
.continue:
1557
        ret
1558
 
1559
draw_num_text:
1560
        mov     esi, eax
1561
        mov     edx, 64+4
1562
        sub     edx, eax
1563
        add     edx, esp
1564
        mov     ebx, [esp+64+32-8+4]
1565
; add window start x & y
1566
 
9930 Doczom 1567
        mov     ecx, [current_slot]
1568
        mov     ecx, [ecx + APPDATA.window]
2288 clevermous 1569
 
9930 Doczom 1570
        mov     eax, [ecx + WDATA.box.left]
1571
        add     eax, [ecx + WDATA.clientbox.left]
2288 clevermous 1572
        shl     eax, 16
9930 Doczom 1573
        add     eax, [ecx + WDATA.box.top]
1574
        add     eax, [ecx + WDATA.clientbox.top]
2288 clevermous 1575
        add     ebx, eax
1576
        mov     ecx, [esp+64+32-12+4]
1577
        mov     eax, [esp+64+8]         ; background color (if given)
1578
        mov     edi, [esp+64+4]
6272 pathoswith 1579
        and     ecx, 5FFFFFFFh
1580
        bt      ecx, 27
1581
        jnc     @f
1582
        mov     edi, eax
1583
@@:
2288 clevermous 1584
        jmp     dtext
4700 mario79 1585
;-----------------------------------------------------------------------------
2288 clevermous 1586
align 4
1587
sys_setup:
4700 mario79 1588
;  1 = roland mpu midi base , base io address
1589
;  2 = keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1590
;  3 = not used
1591
;  4 = not used
1592
;  5 = system language, 1eng 2fi 3ger 4rus
1593
;  6 = not used
1594
;  7 = not used
1595
;  8 = not used
1596
;  9 = not used
1597
; 10 = not used
2288 clevermous 1598
; 11 = enable lba read
1599
; 12 = enable pci access
4700 mario79 1600
;-----------------------------------------------------------------------------
9831 dunkaist 1601
        and     [esp + SYSCALL_STACK.eax], dword 0
4700 mario79 1602
; F.21.1 - set MPU MIDI base port
1603
        dec     ebx
1604
        jnz     @f
2288 clevermous 1605
 
1606
        cmp     ecx, 0x100
4700 mario79 1607
        jb      @f
2288 clevermous 1608
 
1609
        mov     esi, 65535
1610
        cmp     esi, ecx
4700 mario79 1611
        jb      @f
2288 clevermous 1612
 
4700 mario79 1613
        mov     [midi_base], cx
1614
        mov     word [mididp], cx
1615
        inc     cx
1616
        mov     word [midisp], cx
2288 clevermous 1617
        ret
4700 mario79 1618
;--------------------------------------
1619
@@:
1620
; F.21.2 - set keyboard layout
1621
        dec     ebx
1622
        jnz     @f
2288 clevermous 1623
 
9710 Doczom 1624
        mov     eax, edx
4700 mario79 1625
; 1 = normal layout
1626
        dec     ecx
1627
        jnz     .shift
2288 clevermous 1628
 
1629
        mov     ebx, keymap
1630
        mov     ecx, 128
1631
        call    memmove
1632
        ret
4700 mario79 1633
;--------------------------------------
1634
.shift:
1635
; 2 = layout at pressed Shift
2288 clevermous 1636
        dec     ecx
4700 mario79 1637
        jnz     .alt
2288 clevermous 1638
 
1639
        mov     ebx, keymap_shift
1640
        mov     ecx, 128
1641
        call    memmove
1642
        ret
4700 mario79 1643
;--------------------------------------
1644
.alt:
1645
; 3 = layout at pressed Alt
2288 clevermous 1646
        dec     ecx
4700 mario79 1647
        jnz     .country
1648
 
2288 clevermous 1649
        mov     ebx, keymap_alt
1650
        mov     ecx, 128
1651
        call    memmove
1652
        ret
4700 mario79 1653
;--------------------------------------
1654
.country:
1655
; country identifier
2288 clevermous 1656
        sub     ecx, 6
4700 mario79 1657
        jnz     .error
1658
 
2288 clevermous 1659
        mov     word [keyboard], dx
1660
        ret
4700 mario79 1661
;--------------------------------------
1662
@@:
1663
; F.21.5 - set system language
1664
        sub     ebx, 3
1665
        jnz     @f
2288 clevermous 1666
 
1667
        mov     [syslang], ecx
1668
        ret
4700 mario79 1669
;--------------------------------------
1670
@@:
1671
; F.21.11 - enable/disable low-level access to HD
1672
        and     ecx, 1
1673
        sub     ebx, 6
1674
        jnz     @f
2288 clevermous 1675
 
4700 mario79 1676
        mov     [lba_read_enabled], ecx
2288 clevermous 1677
        ret
4700 mario79 1678
;--------------------------------------
1679
@@:
1680
; F.21.12 - enable/disable low-level access to PCI
2288 clevermous 1681
        dec     ebx
4700 mario79 1682
        jnz     .error
2288 clevermous 1683
 
1684
        mov     [pci_access_enabled], ecx
1685
        ret
4700 mario79 1686
;--------------------------------------
1687
.error:
9831 dunkaist 1688
        or      [esp + SYSCALL_STACK.eax], dword -1
2288 clevermous 1689
        ret
4700 mario79 1690
;-----------------------------------------------------------------------------
2288 clevermous 1691
align 4
1692
sys_getsetup:
4700 mario79 1693
;  1 = roland mpu midi base , base io address
1694
;  2 = keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1695
;  3 = not used
1696
;  4 = not used
1697
;  5 = system language, 1eng 2fi 3ger 4rus
1698
;  6 = not used
1699
;  7 = not used
1700
;  8 = not used
1701
;  9 = get hs timer tic
1702
; 10 = not used
1703
; 11 = get the state "lba read"
1704
; 12 = get the state "pci access"
1705
;-----------------------------------------------------------------------------
1706
; F.26.1 - get MPU MIDI base port
1707
        dec     ebx
1708
        jnz     @f
2288 clevermous 1709
 
1710
        movzx   eax, [midi_base]
9831 dunkaist 1711
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 1712
        ret
4700 mario79 1713
;--------------------------------------
1714
@@:
1715
; F.26.2 - get keyboard layout
2288 clevermous 1716
        dec     ebx
4700 mario79 1717
        jnz     @f
2288 clevermous 1718
 
9710 Doczom 1719
        mov     ebx, edx
1720
        ; if given memory address belongs to kernel then error
1721
        stdcall is_region_userspace, ebx, 128
1722
        jnz     .addr_error
4700 mario79 1723
; 1 = normal layout
1724
        dec     ecx
1725
        jnz     .shift
2288 clevermous 1726
 
1727
        mov     eax, keymap
1728
        mov     ecx, 128
1729
        call    memmove
1730
        ret
4700 mario79 1731
;--------------------------------------
1732
.shift:
1733
; 2 = layout with pressed Shift
2288 clevermous 1734
        dec     ecx
4700 mario79 1735
        jnz     .alt
2288 clevermous 1736
 
1737
        mov     eax, keymap_shift
1738
        mov     ecx, 128
1739
        call    memmove
1740
        ret
4700 mario79 1741
;--------------------------------------
1742
.alt:
1743
; 3 = layout with pressed Alt
2288 clevermous 1744
        dec     ecx
4700 mario79 1745
        jne     .country
2288 clevermous 1746
 
1747
        mov     eax, keymap_alt
1748
        mov     ecx, 128
1749
        call    memmove
1750
        ret
4700 mario79 1751
;--------------------------------------
1752
.country:
1753
; 9 = country identifier
2288 clevermous 1754
        sub     ecx, 6
4700 mario79 1755
        jnz     .error
1756
 
2288 clevermous 1757
        movzx   eax, word [keyboard]
9831 dunkaist 1758
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 1759
        ret
8158 rgimad 1760
 
1761
.addr_error:    ; if given memory address is illegal
9831 dunkaist 1762
        or      dword [esp + SYSCALL_STACK.eax], -1
8158 rgimad 1763
        ret
4700 mario79 1764
;--------------------------------------
1765
@@:
1766
; F.26.5 - get system language
1767
        sub     ebx, 3
1768
        jnz     @f
2288 clevermous 1769
 
1770
        mov     eax, [syslang]
9831 dunkaist 1771
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 1772
        ret
4700 mario79 1773
;--------------------------------------
1774
@@:
1775
; F.26.9 - get the value of the time counter
4573 clevermous 1776
        sub     ebx, 4
4700 mario79 1777
        jnz     @f
1778
 
1779
        mov     eax, [timer_ticks]
9831 dunkaist 1780
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 1781
        ret
4700 mario79 1782
;--------------------------------------
1783
@@:
5794 serge 1784
; F.26.10 - get the time from kernel launch in nanoseconds
9571 Doczom 1785
        dec     ebx
5794 serge 1786
        jnz     @f
1787
 
1788
        call    get_clock_ns
9831 dunkaist 1789
        mov     [esp + SYSCALL_STACK.edx], edx
1790
        mov     [esp + SYSCALL_STACK.eax], eax
5794 serge 1791
        ret
1792
;--------------------------------------
1793
@@:
4700 mario79 1794
; F.26.11 - Find out whether low-level HD access is enabled
9571 Doczom 1795
        dec     ebx
4700 mario79 1796
        jnz     @f
1797
 
2288 clevermous 1798
        mov     eax, [lba_read_enabled]
9831 dunkaist 1799
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 1800
        ret
4700 mario79 1801
;--------------------------------------
1802
@@:
1803
; F.26.12 - Find out whether low-level PCI access is enabled
2288 clevermous 1804
        dec     ebx
4700 mario79 1805
        jnz     .error
1806
 
2288 clevermous 1807
        mov     eax, [pci_access_enabled]
9831 dunkaist 1808
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 1809
        ret
4700 mario79 1810
;--------------------------------------
1811
.error:
9831 dunkaist 1812
        or      [esp + SYSCALL_STACK.eax], dword -1
2288 clevermous 1813
        ret
4700 mario79 1814
;-----------------------------------------------------------------------------
2288 clevermous 1815
get_timer_ticks:
1816
        mov     eax, [timer_ticks]
1817
        ret
4700 mario79 1818
;-----------------------------------------------------------------------------
9911 Doczom 1819
iglobal
1820
midi_base dw 0
1821
endg
5851 pathoswith 1822
 
9911 Doczom 1823
align 4
1824
sys_midi:
1825
        cmp     word [mididp], 0
1826
        jnz     @f
1827
        mov     [esp + SYSCALL_STACK.eax], 1
1828
        ret
1829
@@:
1830
        and     [esp + SYSCALL_STACK.eax], 0
1831
        dec     ebx
1832
        jnz     .smn1
1833
 ;    call setuart
1834
@@:
1835
        call    .is_output
1836
        test    al, al
1837
        jnz     @b
1838
        mov     dx, word [midisp]
1839
        mov     al, 0xff
1840
        out     dx, al
1841
@@:
1842
        mov     dx, word [midisp]
1843
        mov     al, 0xff
1844
        out     dx, al
1845
        call    .is_input
1846
        test    al, al
1847
        jnz     @b
1848
        call    .get_mpu_in
1849
        cmp     al, 0xfe
1850
        jnz     @b
1851
@@:
1852
        call    .is_output
1853
        test    al, al
1854
        jnz     @b
1855
        mov     dx, word [midisp]
1856
        mov     al, 0x3f
1857
        out     dx, al
1858
        ret
1859
.smn1:
1860
        dec     ebx
1861
        jnz     .ret
1862
@@:
1863
        call    .get_mpu_in
1864
        call    .is_output
1865
        test    al, al
1866
        jnz     @b
1867
        mov     al, bl
1868
        call    .put_mpu_out
1869
.ret:
1870
        ret
1871
 
1872
.is_input:
2288 clevermous 1873
        push    edx
1874
        mov     dx, word [midisp]
1875
        in      al, dx
1876
        and     al, 0x80
1877
        pop     edx
1878
        ret
1879
 
9911 Doczom 1880
.is_output:
2288 clevermous 1881
        push    edx
1882
        mov     dx, word [midisp]
1883
        in      al, dx
1884
        and     al, 0x40
1885
        pop     edx
1886
        ret
1887
 
9911 Doczom 1888
.get_mpu_in:
2288 clevermous 1889
        push    edx
1890
        mov     dx, word [mididp]
1891
        in      al, dx
1892
        pop     edx
1893
        ret
1894
 
9911 Doczom 1895
.put_mpu_out:
2288 clevermous 1896
        push    edx
1897
        mov     dx, word [mididp]
1898
        out     dx, al
1899
        pop     edx
1900
        ret
1901
 
9911 Doczom 1902
;-----------------------------------------------------------------------------
2288 clevermous 1903
sys_end:
2430 mario79 1904
        cmp     [_display.select_cursor], 0
1905
        je      @f
1906
; restore default cursor before killing
1907
        pusha
1908
        mov     ecx, [current_slot]
9930 Doczom 1909
        mov     ecx, [ecx + APPDATA.window]
2435 mario79 1910
        call    restore_default_cursor_before_killing
2430 mario79 1911
        popa
1912
@@:
1913
;--------------------------------------
3545 hidnplayr 1914
; kill all sockets this process owns
1915
        pusha
9612 Doczom 1916
        mov     edx, [current_slot]
9715 Doczom 1917
        mov     edx, [edx + APPDATA.tid]
6011 hidnplayr 1918
        call    socket_process_end
3545 hidnplayr 1919
        popa
1920
;--------------------------------------
2288 clevermous 1921
        mov     ecx, [current_slot]
9715 Doczom 1922
        mov     eax, [ecx + APPDATA.tls_base]
2288 clevermous 1923
        test    eax, eax
1924
        jz      @F
1925
 
1926
        stdcall user_free, eax
1927
@@:
1928
 
9612 Doczom 1929
        mov     eax, [current_slot]
9715 Doczom 1930
        mov     [eax + APPDATA.state], TSTATE_ZOMBIE
3534 clevermous 1931
        call    wakeup_osloop
2288 clevermous 1932
 
3597 Serge 1933
.waitterm:            ; wait here for termination
1934
        call    change_task
1935
        jmp     .waitterm
2435 mario79 1936
;------------------------------------------------------------------------------
2452 mario79 1937
align 4
9930 Doczom 1938
; ecx - ptr WDATA
2435 mario79 1939
restore_default_cursor_before_killing:
2468 mario79 1940
        pushfd
1941
        cli
2435 mario79 1942
        mov     eax, [def_cursor]
9930 Doczom 1943
        mov     [ecx + WDATA.cursor], eax
2288 clevermous 1944
 
2435 mario79 1945
        movzx   eax, word [MOUSE_Y]
1946
        movzx   ebx, word [MOUSE_X]
2446 mario79 1947
        mov     eax, [d_width_calc_area + eax*4]
1948
 
5351 serge 1949
        add     eax, [_display.win_map]
9715 Doczom 1950
        movzx   edx, byte [ebx + eax]
9930 Doczom 1951
        shl     edx, BSF sizeof.WDATA
1952
        mov     esi, [window_data + edx + WDATA.cursor]
2452 mario79 1953
 
1954
        cmp     esi, [current_cursor]
1955
        je      @f
1956
 
2435 mario79 1957
        push    esi
1958
        call    [_display.select_cursor]
1959
        mov     [current_cursor], esi
2452 mario79 1960
@@:
2450 mario79 1961
        mov     [redrawmouse_unconditional], 1
3534 clevermous 1962
        call    wakeup_osloop
2468 mario79 1963
        popfd
2435 mario79 1964
        ret
1965
;------------------------------------------------------------------------------
2288 clevermous 1966
iglobal
1967
align 4
1968
sys_system_table:
1969
        dd      sysfn_deactivate        ; 1 = deactivate window
1970
        dd      sysfn_terminate         ; 2 = terminate thread
1971
        dd      sysfn_activate          ; 3 = activate window
1972
        dd      sysfn_getidletime       ; 4 = get idle time
1973
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
1974
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
1975
        dd      sysfn_getactive         ; 7 = get active window
1976
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
1977
        dd      sysfn_shutdown          ; 9 = shutdown with parameter
1978
        dd      sysfn_minimize          ; 10 = minimize window
1979
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
9268 Doczom 1980
        dd      undefined_syscall       ; 12 = get last pressed key. function removed. sysfn_lastkey
2288 clevermous 1981
        dd      sysfn_getversion        ; 13 = get kernel version
1982
        dd      sysfn_waitretrace       ; 14 = wait retrace
1983
        dd      sysfn_centermouse       ; 15 = center mouse cursor
1984
        dd      sysfn_getfreemem        ; 16 = get free memory size
1985
        dd      sysfn_getallmem         ; 17 = get total memory size
1986
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
1987
                                        ;                 instead of slot
1988
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1989
        dd      sysfn_meminfo           ; 20 = get extended memory info
1990
        dd      sysfn_pid_to_slot       ; 21 = get slot number for pid
1991
        dd      sysfn_min_rest_window   ; 22 = minimize and restore any window
2648 mario79 1992
        dd      sysfn_min_windows       ; 23 = minimize all windows
2654 mario79 1993
        dd      sysfn_set_screen_sizes  ; 24 = set screen sizes for Vesa
5836 GerdtR 1994
 
1995
        dd      sysfn_zmodif            ; 25 = get/set window z modifier  ;Fantomer
2288 clevermous 1996
sysfn_num = ($ - sys_system_table)/4
1997
endg
1998
;------------------------------------------------------------------------------
1999
sys_system:
2000
        dec     ebx
2001
        cmp     ebx, sysfn_num
2002
        jae     @f
2003
        jmp     dword [sys_system_table + ebx*4]
2004
@@:
2005
        ret
2006
;------------------------------------------------------------------------------
2007
sysfn_shutdown:          ; 18.9 = system shutdown
7122 dunkaist 2008
        cmp     ecx, SYSTEM_SHUTDOWN
9930 Doczom 2009
        jl      .exit_for_anyone
7122 dunkaist 2010
        cmp     ecx, SYSTEM_RESTART
9930 Doczom 2011
        jg      .exit_for_anyone
7132 dunkaist 2012
        mov     [BOOT.shutdown_type], cl
2288 clevermous 2013
 
8866 rgimad 2014
        mov     eax, [thread_count]
2288 clevermous 2015
        mov     [SYS_SHUTDOWN], al
2016
        mov     [shutdown_processes], eax
3534 clevermous 2017
        call    wakeup_osloop
9831 dunkaist 2018
        and     dword [esp + SYSCALL_STACK.eax], 0
9930 Doczom 2019
.exit_for_anyone:
2288 clevermous 2020
        ret
2021
  uglobal
2022
   shutdown_processes:
2023
                       dd 0x0
2024
  endg
2025
;------------------------------------------------------------------------------
8270 dunkaist 2026
; in: eax -- APPDATA ptr
2027
; out: Z/z -- is/not kernel thread
2028
is_kernel_thread:
9715 Doczom 2029
        mov     eax, [eax + APPDATA.process]
2030
        cmp     eax, [SLOT_BASE + 2*sizeof.APPDATA + APPDATA.process]       ; OS
8270 dunkaist 2031
        ret
2032
;------------------------------------------------------------------------------
2288 clevermous 2033
sysfn_terminate:        ; 18.2 = TERMINATE
2472 mario79 2034
        push    ecx
2288 clevermous 2035
        cmp     ecx, 2
9910 Doczom 2036
        jb      .noprocessterminate
8866 rgimad 2037
        mov     edx, [thread_count]
2288 clevermous 2038
        cmp     ecx, edx
9910 Doczom 2039
        ja      .noprocessterminate
8866 rgimad 2040
        mov     eax, [thread_count]
9709 Doczom 2041
        shl     ecx, BSF sizeof.APPDATA
2042
        add     ecx, SLOT_BASE
9911 Doczom 2043
 
9709 Doczom 2044
        mov     edx, [ecx + APPDATA.tid]
2045
        cmp     byte [ecx + APPDATA.state], TSTATE_FREE
9910 Doczom 2046
        jz      .noprocessterminate
8270 dunkaist 2047
        push    eax
9709 Doczom 2048
        mov     eax, ecx
8270 dunkaist 2049
        call    is_kernel_thread
2050
        pop     eax
9910 Doczom 2051
        jz      .noprocessterminate
3296 clevermous 2052
        push    ecx edx
9709 Doczom 2053
        mov     edx, ecx
3296 clevermous 2054
        call    request_terminate
2055
        pop     edx ecx
2056
        test    eax, eax
9910 Doczom 2057
        jz      .noprocessterminate
2430 mario79 2058
;--------------------------------------
3545 hidnplayr 2059
; terminate all network sockets it used
2060
        pusha
9709 Doczom 2061
        mov     eax, edx     ;TODO: check function
6011 hidnplayr 2062
        call    socket_process_end
3545 hidnplayr 2063
        popa
2064
;--------------------------------------
2430 mario79 2065
        cmp     [_display.select_cursor], 0
2452 mario79 2066
        je      .restore_end
2430 mario79 2067
; restore default cursor before killing
2068
        pusha
2069
        mov     ecx, [esp+32]
9930 Doczom 2070
        shl     ecx, BSF sizeof.WDATA
2071
        add     ecx, window_data
2452 mario79 2072
        mov     eax, [def_cursor]
9930 Doczom 2073
        cmp     [ecx + WDATA.cursor], eax
2452 mario79 2074
        je      @f
2435 mario79 2075
        call    restore_default_cursor_before_killing
2452 mario79 2076
@@:
2430 mario79 2077
        popa
2452 mario79 2078
.restore_end:
2430 mario79 2079
;--------------------------------------
2288 clevermous 2080
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
9709 Doczom 2081
        mov     [ecx + APPDATA.state], TSTATE_ZOMBIE; clear possible i40's
3534 clevermous 2082
        call    wakeup_osloop
2288 clevermous 2083
     ;call MEM_Heap_UnLock
2084
 
3534 clevermous 2085
        cmp     edx, [application_table_owner]; clear app table stat
9910 Doczom 2086
        jne     .noatsc
3534 clevermous 2087
        call    unlock_application_table
9910 Doczom 2088
.noatsc:
2089
.noprocessterminate:
2472 mario79 2090
        add     esp, 4
2288 clevermous 2091
        ret
2092
;------------------------------------------------------------------------------
2093
sysfn_terminate2:
3534 clevermous 2094
        call    lock_application_table
2288 clevermous 2095
        mov     eax, ecx
2096
        call    pid_to_slot
2097
        test    eax, eax
2098
        jz      .not_found
2099
        mov     ecx, eax
2100
        cli
2101
        call    sysfn_terminate
3534 clevermous 2102
        call    unlock_application_table
2288 clevermous 2103
        sti
9831 dunkaist 2104
        and     dword [esp + SYSCALL_STACK.eax], 0
2288 clevermous 2105
        ret
2106
.not_found:
3534 clevermous 2107
        call    unlock_application_table
9831 dunkaist 2108
        or      dword [esp + SYSCALL_STACK.eax], -1
2288 clevermous 2109
        ret
2110
;------------------------------------------------------------------------------
2111
sysfn_deactivate:         ; 18.1 = DEACTIVATE WINDOW
2112
        cmp     ecx, 2
2113
        jb      .nowindowdeactivate
8866 rgimad 2114
        cmp     ecx, [thread_count]
2288 clevermous 2115
        ja      .nowindowdeactivate
2408 Serge 2116
 
2288 clevermous 2117
        movzx   esi, word [WIN_STACK + ecx*2]
2118
        cmp     esi, 1
2119
        je      .nowindowdeactivate ; already deactive
2120
 
2121
        mov     edi, ecx
9926 Doczom 2122
        shl     edi, BSF sizeof.WDATA
2288 clevermous 2123
        add     edi, window_data
2124
        movzx   esi, word [WIN_STACK + ecx * 2]
2125
        lea     esi, [WIN_POS + esi * 2]
2126
        call    window._.window_deactivate
6800 pathoswith 2127
        call    syscall_display_settings.calculateScreen
2128
        call    syscall_display_settings.redrawScreen
2288 clevermous 2129
.nowindowdeactivate:
2130
        ret
3455 mario79 2131
;------------------------------------------------------------------------------
2288 clevermous 2132
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
5675 leency 2133
        cmp     ecx, 2
2134
        jb      .nowindowactivate
8866 rgimad 2135
        cmp     ecx, [thread_count]
2288 clevermous 2136
        ja      .nowindowactivate
3455 mario79 2137
;-------------------------------------
2138
@@:
2139
; If the window is captured and moved by the user,
2140
; then you can't change the position in window stack!!!
2141
        mov     al, [mouse.active_sys_window.action]
2142
        and     al, WINDOW_MOVE_AND_RESIZE_FLAGS
2143
        test    al, al
2144
        jz      @f
2145
        call    change_task
2146
        jmp     @b
2147
@@:
2148
;-------------------------------------
2288 clevermous 2149
        mov     [window_minimize], 2; restore window if minimized
3534 clevermous 2150
        call    wakeup_osloop
2288 clevermous 2151
 
2152
        movzx   esi, word [WIN_STACK + ecx*2]
8866 rgimad 2153
        cmp     esi, [thread_count]
2288 clevermous 2154
        je      .nowindowactivate; already active
2155
 
2156
        mov     edi, ecx
9715 Doczom 2157
        shl     edi, BSF sizeof.WDATA
2288 clevermous 2158
        add     edi, window_data
2159
        movzx   esi, word [WIN_STACK + ecx * 2]
2160
        lea     esi, [WIN_POS + esi * 2]
2161
        call    waredraw
2162
.nowindowactivate:
2163
        ret
2164
;------------------------------------------------------------------------------
5865 GerdtR 2165
align 4
5836 GerdtR 2166
sysfn_zmodif:
2167
;18,25,1 - get z_modif
2168
;18,25,2 - set z_modif
2169
;edx = -1(for current task) or TID
2170
;esi(for 2) = new value z_modif
2171
;return:
2172
;1:   eax = z_modif
2173
;2: eax=0(fail),1(success) for set z_modif
2174
 
2175
        cmp     edx, -1
2176
        jne     @f
8869 rgimad 2177
        mov     edx, [current_slot_idx]
5836 GerdtR 2178
     @@:
8866 rgimad 2179
        cmp     edx, [thread_count]
5865 GerdtR 2180
        ja      .fail
5836 GerdtR 2181
        cmp     edx, 1
5865 GerdtR 2182
        je      .fail
5836 GerdtR 2183
 
5865 GerdtR 2184
        mov     eax, edx
9715 Doczom 2185
        shl     edx, BSF sizeof.WDATA
5836 GerdtR 2186
 
9930 Doczom 2187
        test    [window_data + edx + WDATA.fl_wstate], WSTATE_USED
2188
        jz      .fail
5836 GerdtR 2189
 
2190
        cmp     ecx, 1
2191
        jnz     .set_zmod
2192
 
9715 Doczom 2193
        mov     al, [window_data + edx + WDATA.z_modif]
5865 GerdtR 2194
        jmp     .exit
5836 GerdtR 2195
 
2196
.set_zmod:
2197
        cmp     ecx, 2
5865 GerdtR 2198
        jnz     .fail
5836 GerdtR 2199
 
5865 GerdtR 2200
        mov     ebx, esi
2201
        mov     esi, eax
5836 GerdtR 2202
 
5865 GerdtR 2203
        cmp     bl, ZPOS_ALWAYS_TOP
2204
        jg      .fail
5836 GerdtR 2205
 
9715 Doczom 2206
        mov     [window_data + edx + WDATA.z_modif], bl
5836 GerdtR 2207
 
9715 Doczom 2208
        mov     eax, [window_data + edx + WDATA.box.left]
2209
        mov     ebx, [window_data + edx + WDATA.box.top]
2210
        mov     ecx, [window_data + edx + WDATA.box.width]
2211
        mov     edx, [window_data + edx + WDATA.box.height]
5836 GerdtR 2212
        add     ecx, eax
2213
        add     edx, ebx
5865 GerdtR 2214
        call    window._.set_screen
5836 GerdtR 2215
        call    window._.set_top_wnd
5865 GerdtR 2216
        call    window._.redraw_top_wnd
5836 GerdtR 2217
 
9715 Doczom 2218
        shl     esi, BSF sizeof.WDATA
9930 Doczom 2219
        mov     [esi + window_data + WDATA.fl_redraw], WSTATE_REDRAW
5865 GerdtR 2220
 
2221
 
5836 GerdtR 2222
        mov     eax, 1
5865 GerdtR 2223
        jmp     .exit
2224
.fail:
2225
        xor     eax, eax
5836 GerdtR 2226
.exit:
9831 dunkaist 2227
        mov     [esp + SYSCALL_STACK.eax], eax
5836 GerdtR 2228
        ret
2229
 
2230
;------------------------------------------------------------------------------
2288 clevermous 2231
sysfn_getidletime:              ; 18.4 = GET IDLETIME
9590 Doczom 2232
        ;mov     eax, [TASK_TABLE+32+TASKDATA.cpu_usage]
9715 Doczom 2233
        mov     eax, [SLOT_BASE + APPDATA.cpu_usage]
9831 dunkaist 2234
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2235
        ret
2236
;------------------------------------------------------------------------------
2237
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
3481 Serge 2238
        mov     eax, dword [cpu_freq]
9831 dunkaist 2239
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2240
        ret
2241
;------------------------------------------------------------------------------
3481 Serge 2242
get_cpu_freq:
2243
        mov     eax, dword [cpu_freq]
2244
        mov     edx, dword [cpu_freq+4]
2245
        ret
9268 Doczom 2246
;  SAVE ramdisk to /hd/1/kolibri.img
2288 clevermous 2247
;!!!!!!!!!!!!!!!!!!!!!!!!
2248
   include 'blkdev/rdsave.inc'
2249
;!!!!!!!!!!!!!!!!!!!!!!!!
2250
;------------------------------------------------------------------------------
2251
align 4
2252
sysfn_getactive:        ; 18.7 = get active window
8866 rgimad 2253
        mov     eax, [thread_count]
2288 clevermous 2254
        movzx   eax, word [WIN_POS + eax*2]
9831 dunkaist 2255
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2256
        ret
2257
;------------------------------------------------------------------------------
2258
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2259
;     cmp  ecx,1
2260
        dec     ecx
9911 Doczom 2261
        jnz     .set_flag
2288 clevermous 2262
        movzx   eax, byte [sound_flag]; get sound_flag
9831 dunkaist 2263
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2264
        ret
9911 Doczom 2265
.set_flag:
2288 clevermous 2266
;     cmp  ecx,2
2267
        dec     ecx
9911 Doczom 2268
        jnz     .err
2288 clevermous 2269
        xor     byte [sound_flag], 1
9911 Doczom 2270
.err:
2288 clevermous 2271
        ret
2272
;------------------------------------------------------------------------------
2273
sysfn_minimize:         ; 18.10 = minimize window
2274
        mov     [window_minimize], 1
3534 clevermous 2275
        call    wakeup_osloop
2288 clevermous 2276
        ret
2277
;------------------------------------------------------------------------------
2278
align 4
2279
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2280
        dec     ecx
4641 mario79 2281
        jnz     .exit
2282
.small_table:
8598 rgimad 2283
        stdcall is_region_userspace, edx, DRIVE_DATA_SIZE
9045 dunkaist 2284
        jnz     .exit
2288 clevermous 2285
        mov     edi, edx
2286
        mov     esi, DRIVE_DATA
4641 mario79 2287
        mov     ecx, DRIVE_DATA_SIZE ;10
2288 clevermous 2288
        cld
4641 mario79 2289
        rep movsb
2290
.exit:
2288 clevermous 2291
        ret
2292
;------------------------------------------------------------------------------
2293
sysfn_getversion:       ; 18.13 = get kernel ID and version
8247 rgimad 2294
        ; if given memory address belongs to kernel then error
9917 Doczom 2295
        stdcall is_region_userspace, ecx, version_inf.size
9045 dunkaist 2296
        jnz     .addr_error
8247 rgimad 2297
 
2288 clevermous 2298
        mov     edi, ecx
2299
        mov     esi, version_inf
9917 Doczom 2300
        mov     ecx, version_inf.size
2288 clevermous 2301
        rep movsb
2302
        ret
8247 rgimad 2303
.addr_error:    ; if given memory address is illegal
9831 dunkaist 2304
        mov     dword [esp + SYSCALL_STACK.eax], -1
8247 rgimad 2305
        ret
2288 clevermous 2306
;------------------------------------------------------------------------------
2307
sysfn_waitretrace:     ; 18.14 = sys wait retrace
9911 Doczom 2308
        ;wait retrace functions
2288 clevermous 2309
        mov     edx, 0x3da
9911 Doczom 2310
.loop:
2288 clevermous 2311
        in      al, dx
2312
        test    al, 1000b
9911 Doczom 2313
        jz      .loop
9831 dunkaist 2314
        and     [esp + SYSCALL_STACK.eax], dword 0
2288 clevermous 2315
        ret
2316
;------------------------------------------------------------------------------
2317
align 4
2318
sysfn_centermouse:      ; 18.15 = mouse centered
5350 serge 2319
        mov     eax, [_display.width]
2288 clevermous 2320
        shr     eax, 1
2321
        mov     [MOUSE_X], ax
5350 serge 2322
        mov     eax, [_display.height]
2288 clevermous 2323
        shr     eax, 1
2324
        mov     [MOUSE_Y], ax
3534 clevermous 2325
        call    wakeup_osloop
2288 clevermous 2326
        xor     eax, eax
9831 dunkaist 2327
        and     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2328
        ret
2329
;------------------------------------------------------------------------------
5851 pathoswith 2330
sysfn_mouse_acceleration:       ; 18.19 = set/get mouse features
2331
        cmp     ecx, 8
2332
        jnc     @f
9715 Doczom 2333
        jmp     dword [.table + ecx*4]
5851 pathoswith 2334
.get_mouse_acceleration:
2288 clevermous 2335
        xor     eax, eax
2336
        mov     ax, [mouse_speed_factor]
9831 dunkaist 2337
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2338
        ret
5851 pathoswith 2339
.set_mouse_acceleration:
2288 clevermous 2340
        mov     [mouse_speed_factor], dx
2341
        ret
5851 pathoswith 2342
.get_mouse_delay:
5853 pathoswith 2343
        xor     eax, eax
2344
        mov     al, [mouse_delay]
9831 dunkaist 2345
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2346
        ret
5851 pathoswith 2347
.set_mouse_delay:
5853 pathoswith 2348
        mov     [mouse_delay], dl
5851 pathoswith 2349
@@:
2288 clevermous 2350
        ret
5851 pathoswith 2351
.set_pointer_position:
5350 serge 2352
        cmp     dx, word[_display.height]
5851 pathoswith 2353
        jae     @b
2288 clevermous 2354
        rol     edx, 16
5350 serge 2355
        cmp     dx, word[_display.width]
5851 pathoswith 2356
        jae     @b
2288 clevermous 2357
        mov     [MOUSE_X], edx
4381 hidnplayr 2358
        mov     [mouse_active], 1
5851 pathoswith 2359
        jmp     wakeup_osloop
2360
.set_mouse_button:
2361
        mov     [BTN_DOWN], edx
2288 clevermous 2362
        mov     [mouse_active], 1
5851 pathoswith 2363
        jmp     wakeup_osloop
2364
.get_doubleclick_delay:
2365
        xor     eax, eax
2366
        mov     al, [mouse_doubleclick_delay]
9831 dunkaist 2367
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2368
        ret
5851 pathoswith 2369
.set_doubleclick_delay:
2370
        mov     [mouse_doubleclick_delay], dl
2371
        ret
2372
align 4
2373
.table:
2374
dd      .get_mouse_acceleration
2375
dd      .set_mouse_acceleration
2376
dd      .get_mouse_delay
2377
dd      .set_mouse_delay
2378
dd      .set_pointer_position
2379
dd      .set_mouse_button
2380
dd      .get_doubleclick_delay
2381
dd      .set_doubleclick_delay
2288 clevermous 2382
;------------------------------------------------------------------------------
2383
sysfn_getfreemem:
2384
        mov     eax, [pg_data.pages_free]
2385
        shl     eax, 2
9831 dunkaist 2386
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2387
        ret
2648 mario79 2388
;------------------------------------------------------------------------------
2288 clevermous 2389
sysfn_getallmem:
2390
        mov     eax, [MEM_AMOUNT]
2391
        shr     eax, 10
9831 dunkaist 2392
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2393
        ret
2648 mario79 2394
;------------------------------------------------------------------------------
2288 clevermous 2395
sysfn_pid_to_slot:
2396
        mov     eax, ecx
2397
        call    pid_to_slot
9831 dunkaist 2398
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2399
        ret
2648 mario79 2400
;------------------------------------------------------------------------------
2288 clevermous 2401
sysfn_min_rest_window:
2402
        pushad
2403
        mov     eax, edx ; ebx - operating
2404
        shr     ecx, 1
2405
        jnc     @f
2406
        call    pid_to_slot
2407
@@:
2408
        or      eax, eax ; eax - number of slot
2409
        jz      .error
9828 Doczom 2410
        cmp     eax, max_processes    ; varify maximal slot number
2288 clevermous 2411
        ja      .error
2412
        movzx   eax, word [WIN_STACK + eax*2]
2413
        shr     ecx, 1
2414
        jc      .restore
2415
 ; .minimize:
2416
        call    minimize_window
2417
        jmp     .exit
2418
.restore:
2419
        call    restore_minimized_window
2420
.exit:
2421
        popad
2422
        xor     eax, eax
9831 dunkaist 2423
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2424
        ret
2425
.error:
2426
        popad
2427
        xor     eax, eax
2428
        dec     eax
9831 dunkaist 2429
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2430
        ret
2648 mario79 2431
;------------------------------------------------------------------------------
2432
sysfn_min_windows:
2433
        call    minimize_all_window
9831 dunkaist 2434
        mov     [esp + SYSCALL_STACK.eax], eax
2648 mario79 2435
        call    change_task
2436
        ret
2437
;------------------------------------------------------------------------------
2654 mario79 2438
sysfn_set_screen_sizes:
2439
        cmp     [SCR_MODE], word 0x13
2440
        jbe     .exit
2441
 
2442
        cmp     [_display.select_cursor], select_cursor
2443
        jne     .exit
2444
 
2445
        cmp     ecx, [display_width_standard]
2446
        ja      .exit
2447
 
2448
        cmp     edx, [display_height_standard]
2449
        ja      .exit
2450
 
2451
        pushfd
2452
        cli
2453
        mov     eax, ecx
5351 serge 2454
        mov     ecx, [_display.lfb_pitch]
2654 mario79 2455
        mov     [_display.width], eax
2456
        dec     eax
2457
        mov     [_display.height], edx
2458
        dec     edx
2459
; eax - new Screen_Max_X
2460
; edx - new Screen_Max_Y
2461
        mov     [do_not_touch_winmap], 1
2462
        call    set_screen
2463
        mov     [do_not_touch_winmap], 0
2464
        popfd
2465
        call    change_task
2466
.exit:
2467
        ret
2468
;------------------------------------------------------------------------------
2288 clevermous 2469
uglobal
2470
screen_workarea RECT
2654 mario79 2471
display_width_standard dd 0
2472
display_height_standard dd 0
2473
do_not_touch_winmap db 0
2288 clevermous 2474
window_minimize db 0
2475
sound_flag      db 0
2654 mario79 2476
 
2288 clevermous 2477
endg
2478
 
2479
iglobal
2480
version_inf:
3454 mario79 2481
        db 0,7,7,0  ; version 0.7.7.0
2482
        db 0
2483
.rev    dd __REV__
9917 Doczom 2484
.size = $ - version_inf
2288 clevermous 2485
endg
2515 mario79 2486
;------------------------------------------------------------------------------
2487
align 4
2288 clevermous 2488
sys_cachetodiskette:
2489
        cmp     ebx, 1
4273 clevermous 2490
        jb      .no_floppy_save
2288 clevermous 2491
        cmp     ebx, 2
4273 clevermous 2492
        ja      .no_floppy_save
2288 clevermous 2493
        call    save_image
9831 dunkaist 2494
        mov     [esp + SYSCALL_STACK.eax], eax
4273 clevermous 2495
        ret
2496
.no_floppy_save:
9831 dunkaist 2497
        mov     [esp + SYSCALL_STACK.eax], dword 1
2288 clevermous 2498
        ret
2515 mario79 2499
;------------------------------------------------------------------------------
2500
align 4
2288 clevermous 2501
sys_cpuusage:
2502
 
2503
;  RETURN:
2504
;
2505
;  +00 dword     process cpu usage
2506
;  +04  word     position in windowing stack
2507
;  +06  word     windowing stack value at current position (cpu nro)
2508
;  +10 12 bytes  name
2509
;  +22 dword     start in mem
2510
;  +26 dword     used mem
2511
;  +30 dword     PID , process idenfification number
2512
;
8246 rgimad 2513
        ; if given memory address belongs to kernel then error
8329 rgimad 2514
        stdcall is_region_userspace, ebx, 0x4C
9045 dunkaist 2515
        jnz     .addr_error
2288 clevermous 2516
 
2517
        cmp     ecx, -1 ; who am I ?
2518
        jne     .no_who_am_i
8869 rgimad 2519
        mov     ecx, [current_slot_idx]
2288 clevermous 2520
  .no_who_am_i:
2521
        cmp     ecx, max_processes
2522
        ja      .nofillbuf
2523
 
2524
; +4: word: position of the window of thread in the window stack
2525
        mov     ax, [WIN_STACK + ecx * 2]
2526
        mov     [ebx+4], ax
2527
; +6: word: number of the thread slot, which window has in the window stack
2528
;           position ecx (has no relation to the specific thread)
2529
        mov     ax, [WIN_POS + ecx * 2]
2530
        mov     [ebx+6], ax
2531
 
9715 Doczom 2532
        shl     ecx, BSF sizeof.APPDATA
2288 clevermous 2533
 
2534
; +0: dword: memory usage
9590 Doczom 2535
        ;mov     eax, [ecx+TASK_TABLE+TASKDATA.cpu_usage]
9715 Doczom 2536
        mov     eax, [SLOT_BASE + ecx - sizeof.APPDATA + APPDATA.cpu_usage]
2288 clevermous 2537
        mov     [ebx], eax
2538
; +10: 11 bytes: name of the process
2539
        push    ecx
9715 Doczom 2540
        lea     eax, [SLOT_BASE + ecx + APPDATA.app_name]
2288 clevermous 2541
        add     ebx, 10
2542
        mov     ecx, 11
2543
        call    memmove
2544
        pop     ecx
2545
 
9926 Doczom 2546
        shr     ecx, (BSF sizeof.APPDATA - BSF sizeof.WDATA)
2288 clevermous 2547
; +22: address of the process in memory
2548
; +26: size of used memory - 1
2549
        push    edi
2550
        lea     edi, [ebx+12]
2551
        xor     eax, eax
2552
        mov     edx, 0x100000*16
9926 Doczom 2553
        cmp     ecx, 1 shl BSF sizeof.WDATA
2288 clevermous 2554
        je      .os_mem
9926 Doczom 2555
        mov     edx, [SLOT_BASE + ecx*(sizeof.APPDATA/sizeof.WDATA) + APPDATA.process]
9715 Doczom 2556
        mov     edx, [edx + PROC.mem_used]
2288 clevermous 2557
        mov     eax, std_application_base_address
2558
.os_mem:
2559
        stosd
2560
        lea     eax, [edx-1]
2561
        stosd
2562
 
2563
; +30: PID/TID
9926 Doczom 2564
        mov     eax, [SLOT_BASE + ecx*(sizeof.APPDATA/sizeof.WDATA) + APPDATA.tid]
2288 clevermous 2565
        stosd
2566
 
2567
    ; window position and size
2568
        push    esi
9715 Doczom 2569
        lea     esi, [window_data + ecx + WDATA.box]
2288 clevermous 2570
        movsd
2571
        movsd
2572
        movsd
2573
        movsd
2574
 
2575
    ; Process state (+50)
9926 Doczom 2576
        movzx   eax, byte [SLOT_BASE + ecx*(sizeof.APPDATA/sizeof.WDATA) + APPDATA.state]
2288 clevermous 2577
        stosd
2578
 
2579
    ; Window client area box
9926 Doczom 2580
        lea     esi, [window_data + ecx + WDATA.clientbox]
2288 clevermous 2581
        movsd
2582
        movsd
2583
        movsd
2584
        movsd
2585
 
2586
    ; Window state
9715 Doczom 2587
        mov     al, [window_data + ecx + WDATA.fl_wstate]
2288 clevermous 2588
        stosb
2589
 
2590
    ; Event mask (+71)
9926 Doczom 2591
        mov     EAX, dword [SLOT_BASE + ecx*(sizeof.APPDATA/sizeof.WDATA) + APPDATA.event_mask]
2288 clevermous 2592
        stosd
4286 Serge 2593
 
4262 0CodErr 2594
    ; Keyboard mode (+75)
9926 Doczom 2595
        mov     al, byte [SLOT_BASE + ecx*(sizeof.APPDATA/sizeof.WDATA) + APPDATA.keyboard_mode]
4286 Serge 2596
        stosb
2288 clevermous 2597
 
2598
        pop     esi
2599
        pop     edi
2600
 
2601
.nofillbuf:
2602
    ; return number of processes
2603
 
8866 rgimad 2604
        mov     eax, [thread_count]
9831 dunkaist 2605
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2606
        ret
2607
 
8246 rgimad 2608
.addr_error:    ; if given memory address is illegal
9831 dunkaist 2609
        mov     dword [esp + SYSCALL_STACK.eax], -1
8246 rgimad 2610
        ret
2611
 
2288 clevermous 2612
 
9612 Doczom 2613
; redraw status
2288 clevermous 2614
align 4
2615
sys_redrawstat:
2616
        cmp     ebx, 1
9910 Doczom 2617
        jne     .no_widgets_away
2288 clevermous 2618
        ; buttons away
8869 rgimad 2619
        mov     ecx, [current_slot_idx]
9910 Doczom 2620
.sys_newba2:
2288 clevermous 2621
        mov     edi, [BTN_ADDR]
2622
        cmp     [edi], dword 0  ; empty button list ?
9910 Doczom 2623
        je      .end_of_buttons_away
2288 clevermous 2624
        movzx   ebx, word [edi]
2625
        inc     ebx
2626
        mov     eax, edi
9910 Doczom 2627
.sys_newba:
2288 clevermous 2628
        dec     ebx
9910 Doczom 2629
        jz      .end_of_buttons_away
2288 clevermous 2630
 
2631
        add     eax, 0x10
2632
        cmp     cx, [eax]
9910 Doczom 2633
        jnz     .sys_newba
2288 clevermous 2634
 
2635
        push    eax ebx ecx
2636
        mov     ecx, ebx
2637
        inc     ecx
2638
        shl     ecx, 4
2639
        mov     ebx, eax
2640
        add     eax, 0x10
2641
        call    memmove
2642
        dec     dword [edi]
2643
        pop     ecx ebx eax
2644
 
9910 Doczom 2645
        jmp     .sys_newba2
2288 clevermous 2646
 
9910 Doczom 2647
.end_of_buttons_away:
2288 clevermous 2648
        ret
2649
 
9910 Doczom 2650
.no_widgets_away:
2288 clevermous 2651
 
2652
        cmp     ebx, 2
9910 Doczom 2653
        jnz     .srl1
2288 clevermous 2654
 
9930 Doczom 2655
        mov     edx, [current_slot]      ; return whole screen draw area for this app
2656
        mov     edx, [edx + APPDATA.window]
2657
        mov     [edx + WDATA.draw_data.left], 0
2658
        mov     [edx + WDATA.draw_data.top], 0
5350 serge 2659
        mov     eax, [_display.width]
2660
        dec     eax
9930 Doczom 2661
        mov     [edx + WDATA.draw_data.right], eax
5350 serge 2662
        mov     eax, [_display.height]
2663
        dec     eax
9930 Doczom 2664
        mov     [edx + WDATA.draw_data.bottom], eax
2288 clevermous 2665
 
9910 Doczom 2666
.srl1:
2288 clevermous 2667
        ret
2668
 
2669
;ok - 100% work
2670
;nt - not tested
2671
;---------------------------------------------------------------------------------------------
2672
;eax
2673
;0 - task switch counter. Ret switch counter in eax. Block. ok.
2674
;1 - change task. Ret nothing. Block. ok.
2675
;2 - performance control
2676
; ebx
2677
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
2678
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
2679
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
2680
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
2681
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
2682
;eax
2683
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2684
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2685
;---------------------------------------------------------------------------------------------
2686
iglobal
2687
align 4
2688
sheduler:
2689
        dd      sys_sheduler.00
2690
        dd      change_task
2691
        dd      sys_sheduler.02
2692
        dd      sys_sheduler.03
2693
        dd      sys_sheduler.04
2694
endg
2695
sys_sheduler:
2696
;rewritten by   29.12.2009
9715 Doczom 2697
        jmp     dword [sheduler + ebx*4]
2288 clevermous 2698
;.shed_counter:
2699
.00:
2700
        mov     eax, [context_counter]
9831 dunkaist 2701
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2702
        ret
2703
 
2704
.02:
2705
;.perf_control:
2706
        inc     ebx                     ;before ebx=2, ebx=3
2707
        cmp     ebx, ecx                ;if ecx=3, ebx=3
2708
        jz      cache_disable
2709
 
2710
        dec     ebx                     ;ebx=2
2711
        cmp     ebx, ecx                ;
2712
        jz      cache_enable            ;if ecx=2 and ebx=2
2713
 
2714
        dec     ebx                     ;ebx=1
2715
        cmp     ebx, ecx
2716
        jz      is_cache_enabled        ;if ecx=1 and ebx=1
2717
 
2718
        dec     ebx
2719
        test    ebx, ecx                ;ebx=0 and ecx=0
2720
        jz      modify_pce              ;if ecx=0
2721
 
2722
        ret
2723
 
2724
.03:
2725
;.rdmsr_instr:
2726
;now counter in ecx
2727
;(edx:eax) esi:edi => edx:esi
2728
        mov     eax, esi
2729
        mov     ecx, edx
2730
        rdmsr
9831 dunkaist 2731
        mov     [esp + SYSCALL_STACK.eax], eax
2732
        mov     [esp + SYSCALL_STACK.ebx], edx           ;ret in ebx?
2288 clevermous 2733
        ret
2734
 
2735
.04:
2736
;.wrmsr_instr:
2737
;now counter in ecx
2738
;(edx:eax) esi:edi => edx:esi
2739
        ; Fast Call MSR can't be destroy
3539 clevermous 2740
        ; Но MSR_AMD_EFER можно изменять, т.к. в этом регистре лиш
2741
        ; включаются/выключаются расширенные возможности
2288 clevermous 2742
        cmp     edx, MSR_SYSENTER_CS
2743
        je      @f
2744
        cmp     edx, MSR_SYSENTER_ESP
2745
        je      @f
2746
        cmp     edx, MSR_SYSENTER_EIP
2747
        je      @f
2748
        cmp     edx, MSR_AMD_STAR
2749
        je      @f
2750
 
2751
        mov     eax, esi
2752
        mov     ecx, edx
2753
        wrmsr
2754
        ; mov   [esp + 32], eax
2755
        ; mov   [esp + 20], edx ;ret in ebx?
2756
@@:
2757
        ret
2758
 
2759
cache_disable:
2760
        mov     eax, cr0
9831 dunkaist 2761
        or      eax, 01100000_00000000_00000000_00000000b
2288 clevermous 2762
        mov     cr0, eax
2763
        wbinvd  ;set MESI
2764
        ret
2765
 
2766
cache_enable:
2767
        mov     eax, cr0
9831 dunkaist 2768
        and     eax, 10011111_11111111_11111111_11111111b
2288 clevermous 2769
        mov     cr0, eax
2770
        ret
2771
 
2772
is_cache_enabled:
2773
        mov     eax, cr0
2774
        mov     ebx, eax
9831 dunkaist 2775
        and     eax, 01100000_00000000_00000000_00000000b
2288 clevermous 2776
        jz      cache_disabled
9831 dunkaist 2777
        mov     [esp + SYSCALL_STACK.eax], ebx
2288 clevermous 2778
cache_disabled:
9831 dunkaist 2779
        mov     dword [esp + SYSCALL_STACK.eax], eax;0
2288 clevermous 2780
        ret
2781
 
2782
modify_pce:
2783
        mov     eax, cr4
2784
;       mov ebx,0
2785
;       or  bx,100000000b ;pce
2786
;       xor eax,ebx ;invert pce
2787
        bts     eax, 8;pce=cr4[8]
2788
        mov     cr4, eax
9831 dunkaist 2789
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2790
        ret
2791
;---------------------------------------------------------------------------------------------
2792
 
2793
 
2794
iglobal
2795
  cpustring db 'CPU',0
2796
endg
2797
 
2798
uglobal
2799
background_defined    db    0    ; diamond, 11.04.2006
2800
endg
2513 mario79 2801
;-----------------------------------------------------------------------------
2288 clevermous 2802
align 4
2803
checkmisc:
2804
        cmp     [ctrl_alt_del], 1
9910 Doczom 2805
        jne     .nocpustart
2288 clevermous 2806
 
2807
        mov     ebp, cpustring
2808
        call    fs_execute_from_sysdir
2809
 
2810
        mov     [ctrl_alt_del], 0
2513 mario79 2811
;--------------------------------------
2812
align 4
9910 Doczom 2813
.nocpustart:
2288 clevermous 2814
        cmp     [mouse_active], 1
9910 Doczom 2815
        jne     .mouse_not_active
2288 clevermous 2816
        mov     [mouse_active], 0
2411 Serge 2817
 
2288 clevermous 2818
        xor     edi, edi
9709 Doczom 2819
        mov     ebx, window_data
2411 Serge 2820
 
8866 rgimad 2821
        mov     ecx, [thread_count]
2408 Serge 2822
        movzx   eax, word [WIN_POS + ecx*2]     ; active window
9925 Doczom 2823
        shl     eax, BSF sizeof.APPDATA
2414 Serge 2824
        push    eax
2408 Serge 2825
 
2414 Serge 2826
        movzx   eax, word [MOUSE_X]
2827
        movzx   edx, word [MOUSE_Y]
2513 mario79 2828
;--------------------------------------
2408 Serge 2829
align 4
2830
.set_mouse_event:
8093 dunkaist 2831
        add     edi, sizeof.APPDATA
9709 Doczom 2832
        add     ebx, sizeof.WDATA
9917 Doczom 2833
        test    [SLOT_BASE + edi + APPDATA.event_mask], EVM_MOUSE_FILTER
2414 Serge 2834
        jz      .pos_filter
2835
 
2836
        cmp     edi, [esp]                      ; skip if filtration active
2837
        jne     .skip
2513 mario79 2838
;--------------------------------------
2839
align 4
2414 Serge 2840
.pos_filter:
9917 Doczom 2841
        test    [SLOT_BASE + edi + APPDATA.event_mask], EVM_CURSOR_FILTER
2411 Serge 2842
        jz      .set
2288 clevermous 2843
 
9709 Doczom 2844
        mov     esi, [ebx + WDATA.box.left]
2414 Serge 2845
        cmp     eax, esi
2846
        jb      .skip
9709 Doczom 2847
        add     esi, [ebx + WDATA.box.width]
2414 Serge 2848
        cmp     eax, esi
2849
        ja      .skip
2850
 
9709 Doczom 2851
        mov     esi, [ebx + WDATA.box.top]
2414 Serge 2852
        cmp     edx, esi
2853
        jb      .skip
9709 Doczom 2854
        add     esi, [ebx + WDATA.box.height]
2414 Serge 2855
        cmp     edx, esi
2856
        ja      .skip
2513 mario79 2857
;--------------------------------------
2858
align 4
2411 Serge 2859
.set:
9715 Doczom 2860
        or      [SLOT_BASE + edi + APPDATA.occurred_events], EVENT_MOUSE
2513 mario79 2861
;--------------------------------------
2862
align 4
2411 Serge 2863
.skip:
2408 Serge 2864
        loop    .set_mouse_event
2865
 
2414 Serge 2866
        pop     eax
2513 mario79 2867
;--------------------------------------
2868
align 4
9910 Doczom 2869
.mouse_not_active:
6585 pathoswith 2870
        cmp     [REDRAW_BACKGROUND], 0  ; background update ?
2288 clevermous 2871
        jz      nobackgr
2524 mario79 2872
 
2288 clevermous 2873
        cmp     [background_defined], 0
2874
        jz      nobackgr
2513 mario79 2875
;--------------------------------------
2876
align 4
3536 clevermous 2877
backgr:
9930 Doczom 2878
        mov     eax, [background_window + WDATA.draw_data.left]
2537 mario79 2879
        shl     eax, 16
9930 Doczom 2880
        add     eax, [background_window + WDATA.draw_data.right]
2537 mario79 2881
        mov     [BG_Rect_X_left_right], eax ; [left]*65536 + [right]
2882
 
9930 Doczom 2883
        mov     eax, [background_window + WDATA.draw_data.top]
2537 mario79 2884
        shl     eax, 16
9930 Doczom 2885
        add     eax, [background_window + WDATA.draw_data.bottom]
2537 mario79 2886
        mov     [BG_Rect_Y_top_bottom], eax ; [top]*65536 + [bottom]
2887
 
2288 clevermous 2888
        call    drawbackground
2580 mario79 2889
;        DEBUGF  1, "K : drawbackground\n"
2620 mario79 2890
;        DEBUGF  1, "K : backg x %x\n",[BG_Rect_X_left_right]
2891
;        DEBUGF  1, "K : backg y %x\n",[BG_Rect_Y_top_bottom]
2513 mario79 2892
;--------- set event 5 start ----------
2893
        push    ecx edi
2894
        xor     edi, edi
8866 rgimad 2895
        mov     ecx, [thread_count]
2513 mario79 2896
;--------------------------------------
2897
align 4
2898
set_bgr_event:
9930 Doczom 2899
        add     edi, sizeof.WDATA
3536 clevermous 2900
        mov     eax, [BG_Rect_X_left_right]
2901
        mov     edx, [BG_Rect_Y_top_bottom]
9930 Doczom 2902
        cmp     [window_data + edi + WDATA.draw_bgr_x], 0
3536 clevermous 2903
        jz      .set
2904
.join:
9930 Doczom 2905
        cmp     word [window_data + edi + WDATA.draw_bgr_x], ax
3611 clevermous 2906
        jae     @f
9930 Doczom 2907
        mov     word [window_data + edi + WDATA.draw_bgr_x], ax
3611 clevermous 2908
@@:
2909
        shr     eax, 16
9930 Doczom 2910
        cmp     word [window_data + edi + WDATA.draw_bgr_x + 2], ax
3536 clevermous 2911
        jbe     @f
9930 Doczom 2912
        mov     word [window_data + edi + WDATA.draw_bgr_x + 2], ax
3536 clevermous 2913
@@:
9930 Doczom 2914
        cmp     word [window_data + edi + WDATA.draw_bgr_y], dx
3536 clevermous 2915
        jae     @f
9930 Doczom 2916
        mov     word [window_data + edi + WDATA.draw_bgr_y], dx
3536 clevermous 2917
@@:
3611 clevermous 2918
        shr     edx, 16
9930 Doczom 2919
        cmp     word [window_data + edi + WDATA.draw_bgr_y+2], dx
3536 clevermous 2920
        jbe     @f
9930 Doczom 2921
        mov     word [window_data + edi + WDATA.draw_bgr_y+2], dx
3536 clevermous 2922
@@:
2923
        jmp     .common
2924
.set:
9930 Doczom 2925
        mov     [window_data + edi + WDATA.draw_bgr_x], eax
2926
        mov     [window_data + edi + WDATA.draw_bgr_y], edx
3536 clevermous 2927
.common:
9930 Doczom 2928
        mov     eax, [window_data + edi + WDATA.thread]
2929
        test    eax, eax
2930
        jz      @f
2931
        or      [eax + APPDATA.occurred_events], EVENT_BACKGROUND
2932
@@:
2933
        sub     ecx, 1
2934
        jnz     set_bgr_event
2935
        ;loop    set_bgr_event
2513 mario79 2936
        pop     edi ecx
2937
;--------- set event 5 stop -----------
6585 pathoswith 2938
        dec     [REDRAW_BACKGROUND]     ; got new update request?
3536 clevermous 2939
        jnz     backgr
2513 mario79 2940
 
3536 clevermous 2941
        xor     eax, eax
9930 Doczom 2942
        mov     [background_window + WDATA.draw_data.left], eax
2943
        mov     [background_window + WDATA.draw_data.top], eax
2944
        mov     [background_window + WDATA.draw_data.right], eax
2945
        mov     [background_window + WDATA.draw_data.bottom], eax
2513 mario79 2946
;--------------------------------------
2947
align 4
2288 clevermous 2948
nobackgr:
2513 mario79 2949
; system shutdown request
2288 clevermous 2950
        cmp     [SYS_SHUTDOWN], byte 0
2951
        je      noshutdown
2952
 
2953
        mov     edx, [shutdown_processes]
2954
 
2955
        cmp     [SYS_SHUTDOWN], dl
3325 clevermous 2956
        jne     noshutdown
2288 clevermous 2957
 
2958
        lea     ecx, [edx-1]
9709 Doczom 2959
        mov     edx, SLOT_BASE + sizeof.APPDATA ;OS_BASE+0x3040
3325 clevermous 2960
        jecxz   no_mark_system_shutdown
2513 mario79 2961
;--------------------------------------
2962
align 4
2288 clevermous 2963
markz:
3296 clevermous 2964
        push    ecx edx
9709 Doczom 2965
        cmp     [edx + APPDATA.state], TSTATE_FREE
3325 clevermous 2966
        jz      .nokill
9715 Doczom 2967
        cmp     [edx + APPDATA.process], sys_proc
3325 clevermous 2968
        jz      .nokill
3296 clevermous 2969
        call    request_terminate
3325 clevermous 2970
        jmp     .common
2971
.nokill:
2972
        dec     byte [SYS_SHUTDOWN]
2973
        xor     eax, eax
2974
.common:
3296 clevermous 2975
        pop     edx ecx
2976
        test    eax, eax
2977
        jz      @f
9709 Doczom 2978
        mov     [edx + APPDATA.state], TSTATE_ZOMBIE
3296 clevermous 2979
@@:
9709 Doczom 2980
        add     edx, sizeof.APPDATA
2288 clevermous 2981
        loop    markz
3534 clevermous 2982
        call    wakeup_osloop
2513 mario79 2983
;--------------------------------------
2984
align 4
2288 clevermous 2985
@@:
2513 mario79 2986
no_mark_system_shutdown:
2288 clevermous 2987
        dec     byte [SYS_SHUTDOWN]
2988
        je      system_shutdown
2513 mario79 2989
;--------------------------------------
2990
align 4
2288 clevermous 2991
noshutdown:
8866 rgimad 2992
        mov     eax, [thread_count]           ; termination
9709 Doczom 2993
        mov     ebx, SLOT_BASE + sizeof.APPDATA + APPDATA.state
2288 clevermous 2994
        mov     esi, 1
2513 mario79 2995
;--------------------------------------
2996
align 4
2288 clevermous 2997
newct:
2998
        mov     cl, [ebx]
9715 Doczom 2999
        cmp     cl, TSTATE_ZOMBIE
3325 clevermous 3000
        jz      .terminate
2513 mario79 3001
 
9715 Doczom 3002
        cmp     cl, TSTATE_TERMINATING
3325 clevermous 3003
        jnz     .noterminate
3004
.terminate:
3005
        pushad
3493 mario79 3006
        mov     ecx, eax
9930 Doczom 3007
        shl     ecx, BSF sizeof.WDATA
3008
        add     ecx, window_data
3493 mario79 3009
        call    restore_default_cursor_before_killing
3010
        popad
3011
 
3012
        pushad
3325 clevermous 3013
        call    terminate
3014
        popad
3015
        cmp     byte [SYS_SHUTDOWN], 0
3016
        jz      .noterminate
3017
        dec     byte [SYS_SHUTDOWN]
3018
        je      system_shutdown
2288 clevermous 3019
 
3325 clevermous 3020
.noterminate:
9709 Doczom 3021
        add     ebx, sizeof.APPDATA
2288 clevermous 3022
        inc     esi
3023
        dec     eax
3024
        jnz     newct
3025
        ret
2513 mario79 3026
;-----------------------------------------------------------------------------
3027
align 4
2288 clevermous 3028
redrawscreen:
3029
; eax , if process window_data base is eax, do not set flag/limits
3030
 
3031
        pushad
3032
        push    eax
3033
 
3034
;;;         mov   ebx,2
3035
;;;         call  delay_hs
3036
 
3037
         ;mov   ecx,0               ; redraw flags for apps
3038
        xor     ecx, ecx
2513 mario79 3039
;--------------------------------------
3040
align 4
3041
newdw2:
2288 clevermous 3042
        inc     ecx
3043
        push    ecx
3044
 
3045
        mov     eax, ecx
9715 Doczom 3046
        shl     eax, BSF sizeof.WDATA
2288 clevermous 3047
        add     eax, window_data
3048
 
3049
        cmp     eax, [esp+4]
3050
        je      not_this_task
3051
                                   ; check if window in redraw area
3052
        mov     edi, eax
3053
 
3054
        cmp     ecx, 1             ; limit for background
3055
        jz      bgli
3056
 
5870 GerdtR 3057
        mov     eax, [esp+4]        ;if upper in z-position - no redraw
3058
        test    eax, eax
3059
        jz      @f
3060
        mov     al, [eax + WDATA.z_modif]
3061
        cmp     [edi + WDATA.z_modif], al
3062
        jg      ricino
3063
      @@:
3064
 
2288 clevermous 3065
        mov     eax, [edi + WDATA.box.left]
3066
        mov     ebx, [edi + WDATA.box.top]
3067
 
3068
        mov     ecx, [draw_limits.bottom] ; ecx = area y end     ebx = window y start
3069
        cmp     ecx, ebx
3070
        jb      ricino
3071
 
3072
        mov     ecx, [draw_limits.right] ; ecx = area x end     eax = window x start
3073
        cmp     ecx, eax
3074
        jb      ricino
3075
 
3076
        mov     eax, [edi + WDATA.box.left]
3077
        mov     ebx, [edi + WDATA.box.top]
3078
        mov     ecx, [edi + WDATA.box.width]
3079
        mov     edx, [edi + WDATA.box.height]
3080
        add     ecx, eax
3081
        add     edx, ebx
3082
 
3083
        mov     eax, [draw_limits.top]  ; eax = area y start     edx = window y end
3084
        cmp     edx, eax
3085
        jb      ricino
3086
 
3087
        mov     eax, [draw_limits.left]  ; eax = area x start     ecx = window x end
3088
        cmp     ecx, eax
3089
        jb      ricino
2513 mario79 3090
;--------------------------------------
3091
align 4
3092
bgli:
2288 clevermous 3093
        cmp     dword[esp], 1
3094
        jnz     .az
2513 mario79 3095
 
6585 pathoswith 3096
        cmp     [REDRAW_BACKGROUND], 0
2288 clevermous 3097
        jz      .az
2513 mario79 3098
 
2288 clevermous 3099
        mov     dl, 0
3100
        mov     ebx, [draw_limits.left]
9930 Doczom 3101
        cmp     ebx, [edi + WDATA.draw_data.left]
2288 clevermous 3102
        jae     @f
2513 mario79 3103
 
9930 Doczom 3104
        mov     [edi + WDATA.draw_data.left], ebx
2288 clevermous 3105
        mov     dl, 1
2513 mario79 3106
;--------------------------------------
3107
align 4
3108
@@:
2288 clevermous 3109
        mov     ebx, [draw_limits.top]
9930 Doczom 3110
        cmp     ebx, [edi + WDATA.draw_data.top]
2288 clevermous 3111
        jae     @f
2513 mario79 3112
 
9930 Doczom 3113
        mov     [edi + WDATA.draw_data.top], ebx
2288 clevermous 3114
        mov     dl, 1
2513 mario79 3115
;--------------------------------------
3116
align 4
3117
@@:
2288 clevermous 3118
        mov     ebx, [draw_limits.right]
9930 Doczom 3119
        cmp     ebx, [edi + WDATA.draw_data.right]
2288 clevermous 3120
        jbe     @f
2513 mario79 3121
 
9930 Doczom 3122
        mov     [edi + WDATA.draw_data.right], ebx
2288 clevermous 3123
        mov     dl, 1
2513 mario79 3124
;--------------------------------------
3125
align 4
3126
@@:
2288 clevermous 3127
        mov     ebx, [draw_limits.bottom]
9930 Doczom 3128
        cmp     ebx, [edi + WDATA.draw_data.bottom]
2288 clevermous 3129
        jbe     @f
2513 mario79 3130
 
9930 Doczom 3131
        mov     [edi + WDATA.draw_data.bottom], ebx
2288 clevermous 3132
        mov     dl, 1
2513 mario79 3133
;--------------------------------------
3134
align 4
3135
@@:
6585 pathoswith 3136
        add     [REDRAW_BACKGROUND], dl
3534 clevermous 3137
        call    wakeup_osloop
2288 clevermous 3138
        jmp     newdw8
2513 mario79 3139
;--------------------------------------
3140
align 4
3141
.az:
2288 clevermous 3142
        mov     eax, edi
3143
 
3144
        mov     ebx, [draw_limits.left]        ; set limits
9930 Doczom 3145
        mov     [eax + WDATA.draw_data.left], ebx
2288 clevermous 3146
        mov     ebx, [draw_limits.top]
9930 Doczom 3147
        mov     [eax + WDATA.draw_data.top], ebx
2288 clevermous 3148
        mov     ebx, [draw_limits.right]
9930 Doczom 3149
        mov     [eax + WDATA.draw_data.right], ebx
2288 clevermous 3150
        mov     ebx, [draw_limits.bottom]
9930 Doczom 3151
        mov     [eax + WDATA.draw_data.bottom], ebx
2288 clevermous 3152
 
3153
        cmp     dword [esp], 1
3154
        jne     nobgrd
6585 pathoswith 3155
        inc     [REDRAW_BACKGROUND]
3534 clevermous 3156
        call    wakeup_osloop
2513 mario79 3157
;--------------------------------------
3158
align 4
3159
newdw8:
3160
nobgrd:
3936 mario79 3161
;--------------------------------------
3162
        push    eax  edi ebp
3163
        mov     edi, [esp+12]
3164
        cmp     edi, 1
3165
        je      .found
2288 clevermous 3166
 
3936 mario79 3167
        mov     eax, [draw_limits.left]
3168
        mov     ebx, [draw_limits.top]
3169
        mov     ecx, [draw_limits.right]
3170
        sub     ecx, eax
3171
        test    ecx, ecx
3172
        jz      .not_found
3173
 
3174
        mov     edx, [draw_limits.bottom]
3175
        sub     edx, ebx
3176
        test    edx, edx
3177
        jz      .not_found
3178
 
3179
; eax - x, ebx - y
3180
; ecx - size x, edx - size y
3181
        add     ebx, edx
3182
;--------------------------------------
3183
align 4
3184
.start_y:
3185
        push    ecx
3186
;--------------------------------------
3187
align 4
3188
.start_x:
3189
        add     eax, ecx
3190
        mov     ebp, [d_width_calc_area + ebx*4]
5351 serge 3191
        add     ebp, [_display.win_map]
3936 mario79 3192
        movzx   ebp, byte[eax+ebp] ; get value for current point
3193
        cmp     ebp, edi
3194
        jne     @f
3195
 
3196
        pop     ecx
3197
        jmp     .found
3198
;--------------------------------------
3199
align 4
3200
@@:
3201
        sub     eax, ecx
3202
 
3203
        dec     ecx
9221 dunkaist 3204
        jns     .start_x
3936 mario79 3205
 
3206
        pop     ecx
3207
        dec     ebx
3208
        dec     edx
9221 dunkaist 3209
        jns     .start_y
3936 mario79 3210
;--------------------------------------
3211
align 4
3212
.not_found:
3213
        pop     ebp edi eax
3214
        jmp     ricino
3215
;--------------------------------------
3216
align 4
3217
.found:
3218
        pop     ebp edi eax
3219
 
9930 Doczom 3220
        mov     [eax + WDATA.fl_redraw], WSTATE_REDRAW  ; mark as redraw
2513 mario79 3221
;--------------------------------------
3222
align 4
3223
ricino:
3224
not_this_task:
2288 clevermous 3225
        pop     ecx
3226
 
8866 rgimad 3227
        cmp     ecx, [thread_count]
2288 clevermous 3228
        jle     newdw2
3229
 
3230
        pop     eax
3231
        popad
3232
        ret
2513 mario79 3233
;-----------------------------------------------------------------------------
3234
align 4
2288 clevermous 3235
calculatebackground:   ; background
5351 serge 3236
        mov     edi, [_display.win_map]              ; set os to use all pixels
2288 clevermous 3237
        mov     eax, 0x01010101
5351 serge 3238
        mov     ecx, [_display.win_map_size]
2288 clevermous 3239
        shr     ecx, 2
3240
        rep stosd
9930 Doczom 3241
        mov     byte[background_window + WDATA.z_modif], ZPOS_DESKTOP
6585 pathoswith 3242
        mov     [REDRAW_BACKGROUND], 0
2288 clevermous 3243
        ret
2513 mario79 3244
;-----------------------------------------------------------------------------
2288 clevermous 3245
uglobal
3246
  imax    dd 0x0
3247
endg
2513 mario79 3248
;-----------------------------------------------------------------------------
3249
align 4
2288 clevermous 3250
delay_ms:     ; delay in 1/1000 sec
8139 dunkaist 3251
        pushad
3252
 
3253
        cmp     [hpet_base], 0
3254
        jz      .no_hpet
3255
        mov     eax, esi
8176 dunkaist 3256
        mov     edx, 1_000_000 ; ms to ns
8139 dunkaist 3257
        mul     edx
3258
        mov     ebx, edx
3259
        mov     ecx, eax
3260
 
2288 clevermous 3261
        push    ecx
8139 dunkaist 3262
        call    get_clock_ns
3263
        pop     ecx
3264
        mov     edi, edx
3265
        mov     esi, eax
3266
.wait:
3267
        push    ecx
3268
        call    get_clock_ns
3269
        pop     ecx
3270
        sub     eax, esi
3271
        sbb     edx, edi
3272
        sub     eax, ecx
3273
        sbb     edx, ebx
3274
        jc      .wait
3275
        jmp     .done
2288 clevermous 3276
 
8139 dunkaist 3277
.no_hpet:
2288 clevermous 3278
        mov     ecx, esi
3279
        ; 
3280
        imul    ecx, 33941
3281
        shr     ecx, 9
3282
        ; 
3283
 
3284
        in      al, 0x61
3285
        and     al, 0x10
3286
        mov     ah, al
3287
        cld
8139 dunkaist 3288
 
3289
.cnt1:
2288 clevermous 3290
        in      al, 0x61
3291
        and     al, 0x10
3292
        cmp     al, ah
8139 dunkaist 3293
        jz      .cnt1
2288 clevermous 3294
 
3295
        mov     ah, al
8139 dunkaist 3296
        loop    .cnt1
2288 clevermous 3297
 
8139 dunkaist 3298
.done:
3299
        popad
2288 clevermous 3300
        ret
2513 mario79 3301
;-----------------------------------------------------------------------------
2411 Serge 3302
align 4
2288 clevermous 3303
set_app_param:
9612 Doczom 3304
        mov     edi, [current_slot]
9614 Doczom 3305
        xchg    ebx, [edi + APPDATA.event_mask] ; set new event mask
9897 dunkaist 3306
        mov     [esp + SYSCALL_STACK.eax], ebx  ; return old mask value
2288 clevermous 3307
        ret
2513 mario79 3308
;-----------------------------------------------------------------------------
3303 clevermous 3309
 
3310
; this is for syscall
3311
proc delay_hs_unprotected
3312
        call    unprotect_from_terminate
3313
        call    delay_hs
3314
        call    protect_from_terminate
3315
        ret
3316
endp
3317
 
3597 Serge 3318
if 1
2513 mario79 3319
align 4
2288 clevermous 3320
delay_hs:     ; delay in 1/100 secs
3321
; ebx = delay time
3595 Serge 3322
        pushad
3323
        push    ebx
3324
        xor     esi, esi
3325
        mov     ecx, MANUAL_DESTROY
3326
        call    create_event
3327
        test    eax, eax
3328
        jz      .done
2288 clevermous 3329
 
3595 Serge 3330
        mov     ebx, edx
3331
        mov     ecx, [esp]
3597 Serge 3332
        push    edx
3595 Serge 3333
        push    eax
3334
        call    wait_event_timeout
3335
        pop     eax
3597 Serge 3336
        pop     ebx
3595 Serge 3337
        call    destroy_event
3338
.done:
3339
        add     esp, 4
3340
        popad
2288 clevermous 3341
        ret
3596 Serge 3342
 
3343
else
3344
 
3345
align 4
3346
delay_hs:     ; delay in 1/100 secs
3347
; ebx = delay time
3348
        push    ecx
3349
        push    edx
3350
 
3351
        mov     edx, [timer_ticks]
3352
;--------------------------------------
3353
align 4
9910 Doczom 3354
.newtic:
3596 Serge 3355
        mov     ecx, [timer_ticks]
3356
        sub     ecx, edx
3357
        cmp     ecx, ebx
9910 Doczom 3358
        jae     .zerodelay
3596 Serge 3359
 
3360
        call    change_task
3361
 
9910 Doczom 3362
        jmp     .newtic
3596 Serge 3363
;--------------------------------------
3364
align 4
9910 Doczom 3365
.zerodelay:
3596 Serge 3366
        pop     edx
3367
        pop     ecx
3368
        ret
3369
end if
3370
 
2513 mario79 3371
;-----------------------------------------------------------------------------
2288 clevermous 3372
align 16        ;very often call this subrutine
3373
memmove:       ; memory move in bytes
3374
; eax = from
3375
; ebx = to
3376
; ecx = no of bytes
3377
        test    ecx, ecx
3378
        jle     .ret
3379
 
3380
        push    esi edi ecx
3381
 
3382
        mov     edi, ebx
3383
        mov     esi, eax
3384
 
3385
        test    ecx, not 11b
3386
        jz      @f
3387
 
3388
        push    ecx
3389
        shr     ecx, 2
3390
        rep movsd
3391
        pop     ecx
3392
        and     ecx, 11b
3393
        jz      .finish
2513 mario79 3394
;--------------------------------------
3395
align 4
3396
@@:
2288 clevermous 3397
        rep movsb
2513 mario79 3398
;--------------------------------------
3399
align 4
3400
.finish:
2288 clevermous 3401
        pop     ecx edi esi
2513 mario79 3402
;--------------------------------------
3403
align 4
3404
.ret:
2288 clevermous 3405
        ret
2513 mario79 3406
;-----------------------------------------------------------------------------
2288 clevermous 3407
 
9742 Doczom 3408
; in: eax = port
3409
;     ebp = subfunction
3410
;          0 - set access
3411
;          1 - clear access
3412
; out: not return value
2288 clevermous 3413
align 4
3414
set_io_access_rights:
3415
        push    edi eax
3416
        mov     edi, tss._io_map_0
9743 Doczom 3417
 
9742 Doczom 3418
        test    ebp, ebp         ; enable access - ebp = 0
2288 clevermous 3419
        jnz     .siar1
9743 Doczom 3420
 
2288 clevermous 3421
        btr     [edi], eax
3422
        pop     eax edi
3423
        ret
3424
.siar1:
9742 Doczom 3425
        bts     [edi], eax      ; disable access - ebp = 1
2288 clevermous 3426
        pop     eax edi
3427
        ret
9279 Doczom 3428
 
3429
align 4
9743 Doczom 3430
; @brief ReservePortArea and FreePortArea
3431
; @param edx number end arrea of ports (include last number of port)
3432
; @param ecx number start arrea of ports
3433
; @param ebx sub function 0 - reserve, 1 - free
3434
; @param eax 46 - number function
3435
; @returns  eax = 0 - succesful eax = 1 - error
3436
syscall_reserveportarea:        ; ReservePortArea and FreePortArea
9279 Doczom 3437
 
3438
        call    r_f_port_area
9831 dunkaist 3439
        mov     [esp + SYSCALL_STACK.eax], eax
9279 Doczom 3440
        ret
3441
 
2288 clevermous 3442
;reserve/free group of ports
3443
;  * eax = 46 - number function
3444
;  * ebx = 0 - reserve, 1 - free
3445
;  * ecx = number start arrea of ports
3446
;  * edx = number end arrea of ports (include last number of port)
3447
;Return value:
3448
;  * eax = 0 - succesful
3449
;  * eax = 1 - error
3450
;  * The system has reserve this ports:
3451
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
3452
;destroys eax,ebx, ebp
3453
r_f_port_area:
3454
 
3455
        test    ebx, ebx
9910 Doczom 3456
        jnz     .free_port_area
2288 clevermous 3457
 
3458
        cmp     ecx, edx      ; beginning > end ?
9917 Doczom 3459
        ja      .err
9743 Doczom 3460
        cmp     edx, 65536    ;test ebx, not 0xffff
9917 Doczom 3461
        jae     .err
2288 clevermous 3462
        mov     eax, [RESERVED_PORTS]
3463
        test    eax, eax      ; no reserved areas ?
9910 Doczom 3464
        je      .rpal2
2288 clevermous 3465
        cmp     eax, 255      ; max reserved
9917 Doczom 3466
        jae     .err
9910 Doczom 3467
 .rpal3:
2288 clevermous 3468
        mov     ebx, eax
9743 Doczom 3469
        shl     ebx, 4   ;16 byte is sizeof item in RESERVED_PORTS table
2288 clevermous 3470
        add     ebx, RESERVED_PORTS
3471
        cmp     ecx, [ebx+8]
9910 Doczom 3472
        ja      .rpal4
2288 clevermous 3473
        cmp     edx, [ebx+4]
9917 Doczom 3474
        jae     .err
9910 Doczom 3475
 .rpal4:
2288 clevermous 3476
        dec     eax
9910 Doczom 3477
        jnz     .rpal3
3478
        jmp     .rpal2
9917 Doczom 3479
.err:
2288 clevermous 3480
        xor     eax, eax
3481
        inc     eax
3482
        ret
9917 Doczom 3483
 
9910 Doczom 3484
   .rpal2:
2288 clevermous 3485
     ; enable port access at port IO map
3486
        pushad                        ; start enable io map
3487
        mov     eax, ecx
3488
        xor     ebp, ebp               ; enable - eax = port
9742 Doczom 3489
        cli
9910 Doczom 3490
.new_port_access:
2288 clevermous 3491
        call    set_io_access_rights
9742 Doczom 3492
 
2288 clevermous 3493
        inc     eax
3494
        cmp     eax, edx
9910 Doczom 3495
        jbe     .new_port_access
9917 Doczom 3496
 
9742 Doczom 3497
        sti
2288 clevermous 3498
        popad                         ; end enable io map
3499
 
3500
        mov     eax, [RESERVED_PORTS]
9742 Doczom 3501
        inc     eax
2288 clevermous 3502
        mov     [RESERVED_PORTS], eax
3503
        shl     eax, 4
3504
        add     eax, RESERVED_PORTS
9692 Doczom 3505
        mov     ebx, [current_slot]
9715 Doczom 3506
        mov     ebx, [ebx + APPDATA.tid]
9743 Doczom 3507
        mov     [eax], ebx   ; tid
3508
        mov     [eax+4], ecx ;start port
3509
        mov     [eax+8], edx ;finish port
2288 clevermous 3510
 
3511
        xor     eax, eax
3512
        ret
3513
 
9910 Doczom 3514
.free_port_area:
2288 clevermous 3515
 
3516
        mov     eax, [RESERVED_PORTS]; no reserved areas ?
3517
        test    eax, eax
9910 Doczom 3518
        jz      .frpal2
9692 Doczom 3519
        mov     ebx, [current_slot]
9715 Doczom 3520
        mov     ebx, [ebx + APPDATA.tid]
9910 Doczom 3521
   .frpal3:
2288 clevermous 3522
        mov     edi, eax
3523
        shl     edi, 4
3524
        add     edi, RESERVED_PORTS
3525
        cmp     ebx, [edi]
9910 Doczom 3526
        jne     .frpal4
2288 clevermous 3527
        cmp     ecx, [edi+4]
9910 Doczom 3528
        jne     .frpal4
2288 clevermous 3529
        cmp     edx, [edi+8]
9910 Doczom 3530
        jne     .frpal4
3531
        jmp     .frpal1
3532
   .frpal4:
2288 clevermous 3533
        dec     eax
9910 Doczom 3534
        jnz     .frpal3
3535
   .frpal2:
2288 clevermous 3536
        inc     eax
3537
        ret
9910 Doczom 3538
   .frpal1:
2288 clevermous 3539
        push    ecx
3540
        mov     ecx, 256
3541
        sub     ecx, eax
3542
        shl     ecx, 4
3543
        mov     esi, edi
3544
        add     esi, 16
3545
        cld
3546
        rep movsb
3547
 
3548
        dec     dword [RESERVED_PORTS]
3549
;disable port access at port IO map
9742 Doczom 3550
                        ; start disable io map
2288 clevermous 3551
        pop     eax     ;start port
9742 Doczom 3552
        ;cmp     edx, 65536
3553
        ;jge     no_mask_io
2288 clevermous 3554
 
3555
        xor     ebp, ebp
3556
        inc     ebp
9910 Doczom 3557
.new_port_access_disable:           ; disable - eax = port
2288 clevermous 3558
        call    set_io_access_rights
9742 Doczom 3559
 
2288 clevermous 3560
        inc     eax
3561
        cmp     eax, edx
9910 Doczom 3562
        jbe     .new_port_access_disable
9917 Doczom 3563
                                    ; end disable io map
2288 clevermous 3564
        xor     eax, eax
3565
        ret
2430 mario79 3566
;-----------------------------------------------------------------------------
2288 clevermous 3567
align 4
3568
drawbackground:
3569
        cmp     [BgrDrawMode], dword 1
9910 Doczom 3570
        jne     .bgrstr
2288 clevermous 3571
        call    vesa20_drawbackground_tiled
2453 mario79 3572
;        call    [draw_pointer]
3573
        call    __sys_draw_pointer
2288 clevermous 3574
        ret
2430 mario79 3575
;--------------------------------------
3576
align 4
9910 Doczom 3577
.bgrstr:
2288 clevermous 3578
        call    vesa20_drawbackground_stretch
2453 mario79 3579
;        call    [draw_pointer]
3580
        call    __sys_draw_pointer
2288 clevermous 3581
        ret
2430 mario79 3582
;-----------------------------------------------------------------------------
2288 clevermous 3583
align 4
3584
syscall_putimage:                       ; PutImage
8714 Doczom 3585
; add check pointer
3586
        push    ecx
3587
        mov     ax, cx
3588
        shr     ecx, 16
3589
        imul    eax, ecx
3590
        lea     eax, [eax*3]
3591
        stdcall is_region_userspace, ebx, eax
3592
        pop     ecx
9045 dunkaist 3593
        jnz     sys_putimage.exit
8714 Doczom 3594
 
2288 clevermous 3595
sys_putimage:
3596
        test    ecx, 0x80008000
3597
        jnz     .exit
3598
        test    ecx, 0x0000FFFF
3599
        jz      .exit
3600
        test    ecx, 0xFFFF0000
3601
        jnz     @f
2430 mario79 3602
;--------------------------------------
3603
align 4
3604
.exit:
2288 clevermous 3605
        ret
2430 mario79 3606
;--------------------------------------
3607
align 4
3608
@@:
9926 Doczom 3609
        mov     edi, [current_slot_idx]
3610
        shl     edi, BSF sizeof.WDATA
3611
        add     dx, word[window_data + edi + WDATA.clientbox.top]
2288 clevermous 3612
        rol     edx, 16
9926 Doczom 3613
        add     dx, word[window_data + edi + WDATA.clientbox.left]
2288 clevermous 3614
        rol     edx, 16
2430 mario79 3615
;--------------------------------------
3616
align 4
3617
.forced:
2288 clevermous 3618
        push    ebp esi 0
3619
        mov     ebp, putimage_get24bpp
3620
        mov     esi, putimage_init24bpp
2430 mario79 3621
;--------------------------------------
3622
align 4
2288 clevermous 3623
sys_putimage_bpp:
2430 mario79 3624
        call    vesa20_putimage
2288 clevermous 3625
        pop     ebp esi ebp
2430 mario79 3626
        ret
3627
;        jmp     [draw_pointer]
3628
;-----------------------------------------------------------------------------
2288 clevermous 3629
align 4
3630
sys_putimage_palette:
3631
; ebx = pointer to image
3632
; ecx = [xsize]*65536 + [ysize]
3633
; edx = [xstart]*65536 + [ystart]
3634
; esi = number of bits per pixel, must be 8, 24 or 32
3635
; edi = pointer to palette
3636
; ebp = row delta
8715 Doczom 3637
; check pointer
9910 Doczom 3638
        push    ecx esi
8715 Doczom 3639
        mov     ax, cx
3640
        shr     ecx, 16
3641
        imul    eax, ecx
9910 Doczom 3642
;        imul    eax, esi ; eax*count bit in 1 pixel
3643
;        shr     eax, 3
8715 Doczom 3644
        stdcall is_region_userspace, ebx, eax
9910 Doczom 3645
        pop     esi ecx
9045 dunkaist 3646
        jnz     sys_putimage.exit
8715 Doczom 3647
 
9926 Doczom 3648
        mov     eax, [current_slot_idx]
3649
        shl     eax, BSF sizeof.WDATA
3650
        add     dx, word [window_data + eax + WDATA.clientbox.top]
2288 clevermous 3651
        rol     edx, 16
9926 Doczom 3652
        add     dx, word [window_data + eax + WDATA.clientbox.left]
2288 clevermous 3653
        rol     edx, 16
2430 mario79 3654
;--------------------------------------
3655
align 4
2288 clevermous 3656
.forced:
3657
        cmp     esi, 1
3658
        jnz     @f
3659
        push    edi
3660
        mov     eax, [edi+4]
3661
        sub     eax, [edi]
3662
        push    eax
3663
        push    dword [edi]
3664
        push    0ffffff80h
3665
        mov     edi, esp
3666
        call    put_mono_image
3667
        add     esp, 12
3668
        pop     edi
3669
        ret
2430 mario79 3670
;--------------------------------------
3671
align 4
2288 clevermous 3672
@@:
3673
        cmp     esi, 2
3674
        jnz     @f
3675
        push    edi
3676
        push    0ffffff80h
3677
        mov     edi, esp
3678
        call    put_2bit_image
3679
        pop     eax
3680
        pop     edi
3681
        ret
2430 mario79 3682
;--------------------------------------
3683
align 4
2288 clevermous 3684
@@:
3685
        cmp     esi, 4
3686
        jnz     @f
3687
        push    edi
3688
        push    0ffffff80h
3689
        mov     edi, esp
3690
        call    put_4bit_image
3691
        pop     eax
3692
        pop     edi
3693
        ret
2430 mario79 3694
;--------------------------------------
3695
align 4
2288 clevermous 3696
@@:
3697
        push    ebp esi ebp
3698
        cmp     esi, 8
3699
        jnz     @f
3700
        mov     ebp, putimage_get8bpp
3701
        mov     esi, putimage_init8bpp
3702
        jmp     sys_putimage_bpp
2430 mario79 3703
;--------------------------------------
3704
align 4
2288 clevermous 3705
@@:
2727 dunkaist 3706
        cmp     esi, 9
3707
        jnz     @f
3708
        mov     ebp, putimage_get9bpp
3709
        mov     esi, putimage_init9bpp
3710
        jmp     sys_putimage_bpp
3711
;--------------------------------------
3712
align 4
3713
@@:
2288 clevermous 3714
        cmp     esi, 15
3715
        jnz     @f
3716
        mov     ebp, putimage_get15bpp
3717
        mov     esi, putimage_init15bpp
3718
        jmp     sys_putimage_bpp
2430 mario79 3719
;--------------------------------------
3720
align 4
2288 clevermous 3721
@@:
3722
        cmp     esi, 16
3723
        jnz     @f
3724
        mov     ebp, putimage_get16bpp
3725
        mov     esi, putimage_init16bpp
3726
        jmp     sys_putimage_bpp
2430 mario79 3727
;--------------------------------------
3728
align 4
2288 clevermous 3729
@@:
3730
        cmp     esi, 24
3731
        jnz     @f
3732
        mov     ebp, putimage_get24bpp
3733
        mov     esi, putimage_init24bpp
3734
        jmp     sys_putimage_bpp
2430 mario79 3735
;--------------------------------------
3736
align 4
2288 clevermous 3737
@@:
3738
        cmp     esi, 32
3739
        jnz     @f
3740
        mov     ebp, putimage_get32bpp
3741
        mov     esi, putimage_init32bpp
3742
        jmp     sys_putimage_bpp
2430 mario79 3743
;--------------------------------------
3744
align 4
2288 clevermous 3745
@@:
3746
        pop     ebp esi ebp
3747
        ret
2430 mario79 3748
;-----------------------------------------------------------------------------
3749
align 4
2288 clevermous 3750
put_mono_image:
3751
        push    ebp esi ebp
3752
        mov     ebp, putimage_get1bpp
3753
        mov     esi, putimage_init1bpp
3754
        jmp     sys_putimage_bpp
2430 mario79 3755
;-----------------------------------------------------------------------------
3756
align 4
2288 clevermous 3757
put_2bit_image:
3758
        push    ebp esi ebp
3759
        mov     ebp, putimage_get2bpp
3760
        mov     esi, putimage_init2bpp
3761
        jmp     sys_putimage_bpp
2430 mario79 3762
;-----------------------------------------------------------------------------
3763
align 4
2288 clevermous 3764
put_4bit_image:
3765
        push    ebp esi ebp
3766
        mov     ebp, putimage_get4bpp
3767
        mov     esi, putimage_init4bpp
3768
        jmp     sys_putimage_bpp
2430 mario79 3769
;-----------------------------------------------------------------------------
3770
align 4
2288 clevermous 3771
putimage_init24bpp:
3772
        lea     eax, [eax*3]
3773
putimage_init8bpp:
2727 dunkaist 3774
putimage_init9bpp:
2288 clevermous 3775
        ret
2430 mario79 3776
;-----------------------------------------------------------------------------
2288 clevermous 3777
align 16
3778
putimage_get24bpp:
3779
        movzx   eax, byte [esi+2]
3780
        shl     eax, 16
3781
        mov     ax, [esi]
3782
        add     esi, 3
3783
        ret     4
2430 mario79 3784
;-----------------------------------------------------------------------------
2288 clevermous 3785
align 16
3786
putimage_get8bpp:
3787
        movzx   eax, byte [esi]
3788
        push    edx
3789
        mov     edx, [esp+8]
9715 Doczom 3790
        mov     eax, [edx + eax*4]
2288 clevermous 3791
        pop     edx
3792
        inc     esi
3793
        ret     4
2430 mario79 3794
;-----------------------------------------------------------------------------
2727 dunkaist 3795
align 16
3796
putimage_get9bpp:
3797
        lodsb
3798
        mov     ah, al
3799
        shl     eax, 8
3800
        mov     al, ah
3801
        ret     4
3802
;-----------------------------------------------------------------------------
2430 mario79 3803
align 4
2288 clevermous 3804
putimage_init1bpp:
3805
        add     eax, ecx
3806
        push    ecx
3807
        add     eax, 7
3808
        add     ecx, 7
3809
        shr     eax, 3
3810
        shr     ecx, 3
3811
        sub     eax, ecx
3812
        pop     ecx
3813
        ret
2430 mario79 3814
;-----------------------------------------------------------------------------
2288 clevermous 3815
align 16
3816
putimage_get1bpp:
3817
        push    edx
3818
        mov     edx, [esp+8]
3819
        mov     al, [edx]
3820
        add     al, al
3821
        jnz     @f
3822
        lodsb
3823
        adc     al, al
3824
@@:
3825
        mov     [edx], al
3826
        sbb     eax, eax
3827
        and     eax, [edx+8]
3828
        add     eax, [edx+4]
3829
        pop     edx
3830
        ret     4
2430 mario79 3831
;-----------------------------------------------------------------------------
3832
align 4
2288 clevermous 3833
putimage_init2bpp:
3834
        add     eax, ecx
3835
        push    ecx
3836
        add     ecx, 3
3837
        add     eax, 3
3838
        shr     ecx, 2
3839
        shr     eax, 2
3840
        sub     eax, ecx
3841
        pop     ecx
3842
        ret
2430 mario79 3843
;-----------------------------------------------------------------------------
2288 clevermous 3844
align 16
3845
putimage_get2bpp:
3846
        push    edx
3847
        mov     edx, [esp+8]
3848
        mov     al, [edx]
3849
        mov     ah, al
3850
        shr     al, 6
3851
        shl     ah, 2
3852
        jnz     .nonewbyte
3853
        lodsb
3854
        mov     ah, al
3855
        shr     al, 6
3856
        shl     ah, 2
3857
        add     ah, 1
3858
.nonewbyte:
3859
        mov     [edx], ah
3860
        mov     edx, [edx+4]
3861
        movzx   eax, al
9715 Doczom 3862
        mov     eax, [edx + eax*4]
2288 clevermous 3863
        pop     edx
3864
        ret     4
2430 mario79 3865
;-----------------------------------------------------------------------------
3866
align 4
2288 clevermous 3867
putimage_init4bpp:
3868
        add     eax, ecx
3869
        push    ecx
3870
        add     ecx, 1
9268 Doczom 3871
        inc     eax      ;add   eax, 1
2288 clevermous 3872
        shr     ecx, 1
3873
        shr     eax, 1
3874
        sub     eax, ecx
3875
        pop     ecx
3876
        ret
2430 mario79 3877
;-----------------------------------------------------------------------------
2288 clevermous 3878
align 16
3879
putimage_get4bpp:
3880
        push    edx
3881
        mov     edx, [esp+8]
3882
        add     byte [edx], 80h
3883
        jc      @f
3884
        movzx   eax, byte [edx+1]
3885
        mov     edx, [edx+4]
3886
        and     eax, 0x0F
9715 Doczom 3887
        mov     eax, [edx + eax*4]
2288 clevermous 3888
        pop     edx
3889
        ret     4
3890
@@:
3891
        movzx   eax, byte [esi]
3892
        add     esi, 1
3893
        mov     [edx+1], al
3894
        shr     eax, 4
3895
        mov     edx, [edx+4]
9715 Doczom 3896
        mov     eax, [edx + eax*4]
2288 clevermous 3897
        pop     edx
3898
        ret     4
2430 mario79 3899
;-----------------------------------------------------------------------------
3900
align 4
2288 clevermous 3901
putimage_init32bpp:
3902
        shl     eax, 2
3903
        ret
2430 mario79 3904
;-----------------------------------------------------------------------------
2288 clevermous 3905
align 16
3906
putimage_get32bpp:
3907
        lodsd
3908
        ret     4
2430 mario79 3909
;-----------------------------------------------------------------------------
3910
align 4
2288 clevermous 3911
putimage_init15bpp:
3912
putimage_init16bpp:
3913
        add     eax, eax
3914
        ret
2430 mario79 3915
;-----------------------------------------------------------------------------
2288 clevermous 3916
align 16
3917
putimage_get15bpp:
3918
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
3919
        push    ecx edx
3920
        movzx   eax, word [esi]
3921
        add     esi, 2
3922
        mov     ecx, eax
3923
        mov     edx, eax
3924
        and     eax, 0x1F
3925
        and     ecx, 0x1F shl 5
3926
        and     edx, 0x1F shl 10
3927
        shl     eax, 3
3928
        shl     ecx, 6
3929
        shl     edx, 9
3930
        or      eax, ecx
3931
        or      eax, edx
3932
        pop     edx ecx
3933
        ret     4
2430 mario79 3934
;-----------------------------------------------------------------------------
2288 clevermous 3935
align 16
3936
putimage_get16bpp:
3937
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
3938
        push    ecx edx
3939
        movzx   eax, word [esi]
3940
        add     esi, 2
3941
        mov     ecx, eax
3942
        mov     edx, eax
3943
        and     eax, 0x1F
3944
        and     ecx, 0x3F shl 5
3945
        and     edx, 0x1F shl 11
3946
        shl     eax, 3
3947
        shl     ecx, 5
3948
        shl     edx, 8
3949
        or      eax, ecx
3950
        or      eax, edx
3951
        pop     edx ecx
3952
        ret     4
2430 mario79 3953
;-----------------------------------------------------------------------------
3954
;align 4
2288 clevermous 3955
; eax x beginning
3956
; ebx y beginning
3957
; ecx x end
3958
        ; edx y end
3959
; edi color
2430 mario79 3960
;__sys_drawbar:
9926 Doczom 3961
;        mov     esi, [current_slot_idx]
3962
;        shl     esi, BSF sizeof.WDATA
3963
;        add     eax, [window_data+esi+WDATA.clientbox.left]
3964
;        add     ecx, [window_data+esi+WDATA.clientbox.left]
3965
;        add     ebx, [window_data+esi+WDATA.clientbox.top]
3966
;        add     edx, [window_data+esi+WDATA.clientbox.top]
2430 mario79 3967
;--------------------------------------
3968
;align 4
3969
;.forced:
3970
;        call    vesa20_drawbar
2407 mario79 3971
;        call    [draw_pointer]
3972
;        ret
2430 mario79 3973
;-----------------------------------------------------------------------------
2288 clevermous 3974
if used _rdtsc
3975
_rdtsc:
3976
        bt      [cpu_caps], CAPS_TSC
9910 Doczom 3977
        jnc     .ret_rdtsc
2288 clevermous 3978
        rdtsc
3979
        ret
9910 Doczom 3980
   .ret_rdtsc:
2288 clevermous 3981
        mov     edx, 0xffffffff
3982
        mov     eax, 0xffffffff
3983
        ret
3984
end if
3985
 
3986
sys_msg_board_str:
3987
 
3988
        pushad
3989
   @@:
3990
        cmp     [esi], byte 0
3991
        je      @f
3614 shikhin 3992
        mov     ebx, 1
3993
        movzx   ecx, byte [esi]
2288 clevermous 3994
        call    sys_msg_board
3995
        inc     esi
3996
        jmp     @b
3997
   @@:
3998
        popad
3999
        ret
4000
 
4001
sys_msg_board_byte:
4002
; in: al = byte to display
4003
; out: nothing
4004
; destroys: nothing
4005
        pushad
4006
        mov     ecx, 2
4007
        shl     eax, 24
4008
        jmp     @f
4009
 
4010
sys_msg_board_word:
4011
; in: ax = word to display
4012
; out: nothing
4013
; destroys: nothing
4014
        pushad
4015
        mov     ecx, 4
4016
        shl     eax, 16
4017
        jmp     @f
4018
 
4019
sys_msg_board_dword:
4020
; in: eax = dword to display
4021
; out: nothing
4022
; destroys: nothing
4023
        pushad
4024
        mov     ecx, 8
4025
@@:
4026
        push    ecx
4027
        rol     eax, 4
4028
        push    eax
4029
        and     al, 0xF
4030
        cmp     al, 10
4031
        sbb     al, 69h
4032
        das
3614 shikhin 4033
        mov     cl, al
4034
        xor     ebx, ebx
4035
        inc     ebx
2288 clevermous 4036
        call    sys_msg_board
4037
        pop     eax
4038
        pop     ecx
4039
        loop    @b
4040
        popad
4041
        ret
4042
 
3392 clevermous 4043
msg_board_data_size = 65536 ; Must be power of two
4044
 
2288 clevermous 4045
uglobal
6501 pathoswith 4046
msg_board_data  rb  msg_board_data_size
4047
msg_board_count dd  ?
2288 clevermous 4048
endg
4049
 
6501 pathoswith 4050
iglobal
4051
msg_board_pos   dd  42*6*65536+10 ; for printing debug output on the screen
4052
endg
4053
 
2288 clevermous 4054
sys_msg_board:
6501 pathoswith 4055
; ebx=1 -> write, cl = byte to write
4056
; ebx=2 -> read, ecx=0 -> no data, ecx=1 -> data in al
4057
        push    eax ebx
3614 shikhin 4058
        mov     eax, ebx
4059
        mov     ebx, ecx
2288 clevermous 4060
        mov     ecx, [msg_board_count]
4061
        cmp     eax, 1
6501 pathoswith 4062
        jne     .read
2288 clevermous 4063
 
4064
if defined debug_com_base
4065
        push    dx ax
6501 pathoswith 4066
@@: ; wait for empty transmit register
2288 clevermous 4067
        mov     dx, debug_com_base+5
4068
        in      al, dx
4069
        test    al, 1 shl 5
4070
        jz      @r
4071
        mov     dx, debug_com_base      ; Output the byte
4072
        mov     al, bl
4073
        out     dx, al
4074
        pop     ax dx
4075
end if
4076
 
4077
        mov     [msg_board_data+ecx], bl
3777 yogev_ezra 4078
        cmp     byte [debug_direct_print], 1
6501 pathoswith 4079
        jnz     .end
3507 clevermous 4080
        pusha
4081
        lea     edx, [msg_board_data+ecx]
4082
        mov     ecx, 0x40FFFFFF
4083
        mov     ebx, [msg_board_pos]
4084
        mov     edi, 1
9268 Doczom 4085
        mov     esi, edi ;1
3507 clevermous 4086
        call    dtext
4087
        popa
4088
        add     word [msg_board_pos+2], 6
6501 pathoswith 4089
        cmp     word [msg_board_pos+2], 105*6
4090
        jnc     @f
3507 clevermous 4091
        cmp     bl, 10
6501 pathoswith 4092
        jnz     .end
4093
@@:
4094
        mov     word [msg_board_pos+2], 42*6
3507 clevermous 4095
        add     word [msg_board_pos], 10
6501 pathoswith 4096
        mov     eax, [_display.height]
4097
        sub     eax, 10
4098
        cmp     ax, word [msg_board_pos]
4099
        jnc     @f
3507 clevermous 4100
        mov     word [msg_board_pos], 10
4101
@@:
3534 clevermous 4102
        pusha
6501 pathoswith 4103
        mov     eax, [msg_board_pos]
4104
        movzx   ebx, ax
4105
        shr     eax, 16
4106
        mov     edx, 105*6
4107
        xor     ecx, ecx
4108
        mov     edi, 1
4109
        mov     esi, 9
4110
@@:
4111
        call    hline
4112
        inc     ebx
4113
        dec     esi
4114
        jnz     @b
3534 clevermous 4115
        popa
6501 pathoswith 4116
.end:
2288 clevermous 4117
        inc     ecx
3392 clevermous 4118
        and     ecx, msg_board_data_size - 1
2288 clevermous 4119
        mov     [msg_board_count], ecx
6501 pathoswith 4120
.ret:
3614 shikhin 4121
        pop     ebx eax
2288 clevermous 4122
        ret
6501 pathoswith 4123
 
4124
.read:
2288 clevermous 4125
        cmp     eax, 2
6501 pathoswith 4126
        jne     .ret
9897 dunkaist 4127
        add     esp, 8  ; returning data in ebx and eax, so no need to restore them
2288 clevermous 4128
        test    ecx, ecx
9897 dunkaist 4129
        jnz     @f
4130
        mov     [esp + SYSCALL_STACK.eax], ecx
4131
        mov     [esp + SYSCALL_STACK.ebx], ecx
4132
        ret
4133
@@:
2288 clevermous 4134
        mov     eax, msg_board_data+1
4135
        mov     ebx, msg_board_data
4136
        movzx   edx, byte [ebx]
4137
        call    memmove
4138
        dec     [msg_board_count]
9897 dunkaist 4139
        mov     [esp + SYSCALL_STACK.eax], edx
4140
        mov     [esp + SYSCALL_STACK.ebx], 1
2288 clevermous 4141
        ret
4142
 
4143
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4144
;; 61 sys function.                                                ;;
4145
;; in eax=61,ebx in [1..3]                                         ;;
4146
;; out eax                                                         ;;
4147
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4148
iglobal
4149
align 4
4150
f61call:
4151
           dd sys_gs.1   ; resolution
4152
           dd sys_gs.2   ; bits per pixel
4153
           dd sys_gs.3   ; bytes per scanline
4154
endg
4155
 
4156
 
4157
align 4
4158
 
4159
sys_gs:                         ; direct screen access
4160
        dec     ebx
4161
        cmp     ebx, 2
4162
        ja      .not_support
9715 Doczom 4163
        jmp     dword [f61call + ebx*4]
2288 clevermous 4164
.not_support:
9831 dunkaist 4165
        or      [esp + SYSCALL_STACK.eax], dword -1
2288 clevermous 4166
        ret
4167
 
4168
 
4169
.1:                             ; resolution
5350 serge 4170
        mov     eax, [_display.width]
2288 clevermous 4171
        shl     eax, 16
5350 serge 4172
        mov     ax, word [_display.height]
9831 dunkaist 4173
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4174
        ret
4175
.2:                             ; bits per pixel
5154 hidnplayr 4176
        mov     eax, [_display.bits_per_pixel]
9831 dunkaist 4177
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4178
        ret
4179
.3:                             ; bytes per scanline
5351 serge 4180
        mov     eax, [_display.lfb_pitch]
9831 dunkaist 4181
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4182
        ret
4183
 
4184
align 4
4185
syscall_getscreensize:                  ; GetScreenSize
5350 serge 4186
        mov     ax, word [_display.width]
4187
        dec     ax
2288 clevermous 4188
        shl     eax, 16
5350 serge 4189
        mov     ax, word [_display.height]
4190
        dec     ax
9831 dunkaist 4191
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4192
        ret
4700 mario79 4193
;-----------------------------------------------------------------------------
2288 clevermous 4194
align 4
4713 mario79 4195
syscall_cdaudio:
4711 mario79 4196
; ECX - position of CD/DVD-drive
4197
; from 0=Primary Master to 3=Secondary Slave for first IDE contr.
4198
; from 4=Primary Master to 7=Secondary Slave for second IDE contr.
4199
; from 8=Primary Master to 11=Secondary Slave for third IDE contr.
4200
        cmp     ecx, 11
4201
        ja      .exit
4202
 
4203
        mov     eax, ecx
4204
        shr     eax, 2
4205
        lea     eax, [eax*5]
9715 Doczom 4206
        mov     al, [eax + DRIVE_DATA + 1]
4711 mario79 4207
 
4208
        push    ecx ebx
4209
        mov     ebx, ecx
4210
        and     ebx, 11b
4211
        shl     ebx, 1
4212
        mov     cl, 6
4213
        sub     cl, bl
4214
        shr     al, cl
4215
        test    al, 2 ; it's not an ATAPI device
4216
        pop     ebx ecx
4217
 
4218
        jz      .exit
4219
 
4700 mario79 4220
        cmp     ebx, 4
4221
        je      .eject
2288 clevermous 4222
 
4223
        cmp     ebx, 5
4700 mario79 4224
        je      .load
4711 mario79 4225
;--------------------------------------
4226
.exit:
4700 mario79 4227
        ret
4228
;--------------------------------------
2288 clevermous 4229
.load:
4230
        call    .reserve
4231
        call    LoadMedium
4232
        jmp     .free
4700 mario79 4233
;--------------------------------------
2288 clevermous 4234
.eject:
4235
        call    .reserve
4236
        call    clear_CD_cache
4237
        call    allow_medium_removal
4238
        call    EjectMedium
4239
        jmp     .free
4700 mario79 4240
;--------------------------------------
2288 clevermous 4241
.reserve:
4242
        call    reserve_cd
4700 mario79 4243
 
4244
        mov     ebx, ecx
4245
        inc     ebx
4246
        mov     [cdpos], ebx
4247
 
2288 clevermous 4248
        mov     eax, ecx
4249
        shr     eax, 1
4250
        and     eax, 1
4251
        inc     eax
6464 pathoswith 4252
        mov     [ChannelNumber], al
2288 clevermous 4253
        mov     eax, ecx
4254
        and     eax, 1
4255
        mov     [DiskNumber], al
4256
        call    reserve_cd_channel
4257
        ret
4700 mario79 4258
;--------------------------------------
2288 clevermous 4259
.free:
4260
        call    free_cd_channel
4261
        and     [cd_status], 0
4262
        ret
2511 mario79 4263
;-----------------------------------------------------------------------------
2288 clevermous 4264
align 4
2511 mario79 4265
syscall_getpixel_WinMap:                       ; GetPixel WinMap
5350 serge 4266
        cmp     ebx, [_display.width]
4267
        jb      @f
4268
        cmp     ecx, [_display.height]
4269
        jb      @f
2511 mario79 4270
        xor     eax, eax
4271
        jmp     .store
4272
;--------------------------------------
4273
align 4
4274
@@:
4275
        mov     eax, [d_width_calc_area + ecx*4]
5351 serge 4276
        add     eax, [_display.win_map]
2511 mario79 4277
        movzx   eax, byte[eax+ebx]        ; get value for current point
4278
;--------------------------------------
4279
align 4
4280
.store:
9831 dunkaist 4281
        mov     [esp + SYSCALL_STACK.eax], eax
2511 mario79 4282
        ret
4283
;-----------------------------------------------------------------------------
4284
align 4
2288 clevermous 4285
syscall_getpixel:                       ; GetPixel
5350 serge 4286
        mov     ecx, [_display.width]
2288 clevermous 4287
        xor     edx, edx
4288
        mov     eax, ebx
4289
        div     ecx
4290
        mov     ebx, edx
4291
        xchg    eax, ebx
2430 mario79 4292
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
2288 clevermous 4293
        call    dword [GETPIXEL]; eax - x, ebx - y
9831 dunkaist 4294
        mov     [esp + SYSCALL_STACK.eax], ecx
2288 clevermous 4295
        ret
2509 mario79 4296
;-----------------------------------------------------------------------------
2288 clevermous 4297
align 4
4298
syscall_getarea:
4299
;eax = 36
4300
;ebx = pointer to bufer for img BBGGRRBBGGRR...
4301
;ecx = [size x]*65536 + [size y]
4302
;edx = [start x]*65536 + [start y]
4303
        pushad
4304
        mov     edi, ebx
4305
        mov     eax, edx
4306
        shr     eax, 16
4307
        mov     ebx, edx
4308
        and     ebx, 0xffff
4309
        dec     eax
4310
        dec     ebx
4311
     ; eax - x, ebx - y
4312
        mov     edx, ecx
4313
 
4314
        shr     ecx, 16
4315
        and     edx, 0xffff
4316
        mov     esi, ecx
4317
     ; ecx - size x, edx - size y
4318
 
4319
        mov     ebp, edx
8598 rgimad 4320
        lea     ebp, [ebp*3]
4321
        imul    ebp, esi
4322
        stdcall is_region_userspace, edi, ebp
9045 dunkaist 4323
        jnz     .exit
8598 rgimad 4324
 
4325
        mov     ebp, edx
2288 clevermous 4326
        dec     ebp
4327
        lea     ebp, [ebp*3]
4328
 
4329
        imul    ebp, esi
4330
 
4331
        mov     esi, ecx
4332
        dec     esi
4333
        lea     esi, [esi*3]
4334
 
4335
        add     ebp, esi
4336
        add     ebp, edi
4337
 
4338
        add     ebx, edx
2509 mario79 4339
;--------------------------------------
4340
align 4
2288 clevermous 4341
.start_y:
4342
        push    ecx edx
2509 mario79 4343
;--------------------------------------
4344
align 4
2288 clevermous 4345
.start_x:
4346
        push    eax ebx ecx
4347
        add     eax, ecx
4348
 
2430 mario79 4349
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
2288 clevermous 4350
        call    dword [GETPIXEL]; eax - x, ebx - y
4351
 
4352
        mov     [ebp], cx
4353
        shr     ecx, 16
4354
        mov     [ebp+2], cl
4355
 
4356
        pop     ecx ebx eax
4357
        sub     ebp, 3
4358
        dec     ecx
4359
        jnz     .start_x
4360
        pop     edx ecx
4361
        dec     ebx
4362
        dec     edx
4363
        jnz     .start_y
8598 rgimad 4364
 
4365
.exit:
2288 clevermous 4366
        popad
4367
        ret
2509 mario79 4368
;-----------------------------------------------------------------------------
8675 rgimad 4369
 
2288 clevermous 4370
align 4
4371
syscall_threads:                        ; CreateThreads
4372
;
4105 Serge 4373
;   ecx=thread entry point
4374
;   edx=thread stack pointer
2288 clevermous 4375
;
4376
; on return : eax = pid
4105 Serge 4377
        xor     ebx, ebx
2288 clevermous 4378
        call    new_sys_threads
4379
 
9831 dunkaist 4380
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4381
        ret
4382
 
2438 mario79 4383
;------------------------------------------------------------------------------
2288 clevermous 4384
align 4
2438 mario79 4385
calculate_fast_getting_offset_for_WinMapAddress:
4386
; calculate data area for fast getting offset to _WinMapAddress
2446 mario79 4387
        xor     eax, eax
2438 mario79 4388
        mov     ecx, [_display.height]
4389
        mov     edi, d_width_calc_area
4390
        cld
4391
@@:
4392
        stosd
4393
        add     eax, [_display.width]
4394
        dec     ecx
4395
        jnz     @r
4396
        ret
4397
;------------------------------------------------------------------------------
4398
align 4
2480 mario79 4399
calculate_fast_getting_offset_for_LFB:
4400
; calculate data area for fast getting offset to LFB
4401
        xor     eax, eax
4402
        mov     ecx, [_display.height]
4403
        mov     edi, BPSLine_calc_area
4404
        cld
4405
@@:
4406
        stosd
5351 serge 4407
        add     eax, [_display.lfb_pitch]
2480 mario79 4408
        dec     ecx
4409
        jnz     @r
4410
        ret
4411
;------------------------------------------------------------------------------
4412
align 4
2288 clevermous 4413
set_screen:
2654 mario79 4414
; in:
4415
; eax - new Screen_Max_X
4416
; ecx - new BytesPerScanLine
4417
; edx - new Screen_Max_Y
2288 clevermous 4418
 
4419
        pushfd
4420
        cli
4421
 
5351 serge 4422
        mov     [_display.lfb_pitch], ecx
2288 clevermous 4423
 
4424
        mov     [screen_workarea.right], eax
4425
        mov     [screen_workarea.bottom], edx
4426
 
4427
        push    ebx
4428
        push    esi
4429
        push    edi
4430
 
4431
        pushad
4432
 
2654 mario79 4433
        cmp     [do_not_touch_winmap], 1
4434
        je      @f
4435
 
5351 serge 4436
        stdcall kernel_free, [_display.win_map]
2288 clevermous 4437
 
4438
        mov     eax, [_display.width]
4439
        mul     [_display.height]
5351 serge 4440
        mov     [_display.win_map_size], eax
2288 clevermous 4441
 
4442
        stdcall kernel_alloc, eax
5351 serge 4443
        mov     [_display.win_map], eax
2288 clevermous 4444
        test    eax, eax
4445
        jz      .epic_fail
2654 mario79 4446
; store for f.18.24
4447
        mov     eax, [_display.width]
4448
        mov     [display_width_standard], eax
2288 clevermous 4449
 
2654 mario79 4450
        mov     eax, [_display.height]
4451
        mov     [display_height_standard], eax
4452
@@:
2438 mario79 4453
        call    calculate_fast_getting_offset_for_WinMapAddress
2545 mario79 4454
; for Qemu or non standart video cards
2991 Serge 4455
; Unfortunately [BytesPerScanLine] does not always
2545 mario79 4456
;                             equal to [_display.width] * [ScreenBPP] / 8
4457
        call    calculate_fast_getting_offset_for_LFB
2288 clevermous 4458
        popad
4459
 
4460
        call    repos_windows
4461
        xor     eax, eax
4462
        xor     ebx, ebx
5350 serge 4463
        mov     ecx, [_display.width]
4464
        mov     edx, [_display.height]
4465
        dec     ecx
4466
        dec     edx
2288 clevermous 4467
        call    calculatescreen
4468
        pop     edi
4469
        pop     esi
4470
        pop     ebx
4471
 
4472
        popfd
4473
        ret
4474
 
4475
.epic_fail:
4476
        hlt                     ; Houston, we've had a problem
4477
 
4478
; --------------- APM ---------------------
4479
uglobal
4480
apm_entry       dp      0
4481
apm_vf          dd      0
4482
endg
4483
 
4484
align 4
4485
sys_apm:
4486
        xor     eax, eax
4487
        cmp     word [apm_vf], ax       ; Check APM BIOS enable
4488
        jne     @f
4489
        inc     eax
4490
        or      dword [esp + 44], eax   ; error
4491
        add     eax, 7
9911 Doczom 4492
        mov     dword [esp + SYSCALL_STACK.eax], eax   ; 32-bit protected-mode interface not supported
2288 clevermous 4493
        ret
4494
 
4495
@@:
4496
;       xchg    eax, ecx
4497
;       xchg    ebx, ecx
4498
 
4499
        cmp     dx, 3
4500
        ja      @f
4501
        and     [esp + 44], byte 0xfe    ; emulate func 0..3 as func 0
4502
        mov     eax, [apm_vf]
9911 Doczom 4503
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4504
        shr     eax, 16
9911 Doczom 4505
        mov     [esp + SYSCALL_STACK.ecx], eax
2288 clevermous 4506
        ret
4507
 
4508
@@:
4509
 
4510
        mov     esi, [master_tab+(OS_BASE shr 20)]
4511
        xchg    [master_tab], esi
4512
        push    esi
4513
        mov     edi, cr3
4514
        mov     cr3, edi                ;flush TLB
4515
 
4516
        call    pword [apm_entry]       ;call APM BIOS
4517
 
4518
        xchg    eax, [esp]
4519
        mov     [master_tab], eax
4520
        mov     eax, cr3
4521
        mov     cr3, eax
4522
        pop     eax
4523
 
9911 Doczom 4524
        mov     [esp + SYSCALL_STACK.edi], edi
4525
        mov     [esp + SYSCALL_STACK.esi], esi
4526
        mov     [esp + SYSCALL_STACK.ebx], ebx
4527
        mov     [esp + SYSCALL_STACK.edx], edx
4528
        mov     [esp + SYSCALL_STACK.ecx], ecx
4529
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4530
        setc    al
4531
        and     [esp + 44], byte 0xfe
4532
        or      [esp + 44], al
4533
        ret
4534
; -----------------------------------------
4535
 
4536
align 4
4537
undefined_syscall:                      ; Undefined system call
9831 dunkaist 4538
        mov     [esp + SYSCALL_STACK.eax], dword -1
2288 clevermous 4539
        ret
4540
 
8160 rgimad 4541
align 4
8962 Boppan 4542
; @brief Check if given memory region lays in lower 2gb (userspace memory) or not
4543
; @param base Base address of region
4544
; @param len Lenght of region
4545
; @return ZF = 1 if region in userspace memory,
4546
;         ZF = 0 otherwise
8329 rgimad 4547
proc is_region_userspace stdcall, base:dword, len:dword
9045 dunkaist 4548
        push    eax
8329 rgimad 4549
        mov     eax, [base]
8216 rgimad 4550
 
9045 dunkaist 4551
        cmp     eax, OS_BASE-1
4552
        ja      @f              ; zf
8216 rgimad 4553
 
8329 rgimad 4554
        add     eax, [len]
9045 dunkaist 4555
        jc      @f              ; zf
8160 rgimad 4556
        cmp     eax, OS_BASE
9045 dunkaist 4557
        ja      @f              ; zf
2288 clevermous 4558
 
9045 dunkaist 4559
        cmp     eax, eax        ; ZF
8160 rgimad 4560
@@:
9045 dunkaist 4561
        pop     eax
8160 rgimad 4562
        ret
8329 rgimad 4563
endp
8160 rgimad 4564
 
9823 dunkaist 4565
align 4
4566
; @brief Check whether given string lays in userspace memory, i.e. below OS_BASE
4567
; @param base Base address of string
4568
; @return ZF = 1 if string in userspace memory,
4569
;         zf = 0 otherwise
4570
proc is_string_userspace stdcall, base:dword
4571
        push    eax ecx edi
4572
        xor     eax, eax
4573
        mov     edi, [base]
4574
 
4575
        mov     ecx, OS_BASE-1
4576
        sub     ecx, edi
4577
        jb      .done           ; zf
4578
        inc     ecx
4579
        cmp     ecx, 0x10000    ; don't allow strings larger than 64k?
4580
        jbe     @f
4581
        mov     ecx, 0x10000
4582
@@:
4583
        repnz scasb
4584
.done:
4585
        pop     edi ecx eax
4586
        ret
4587
endp
4588
 
3627 Serge 4589
if ~ lang eq sp
4590
diff16 "end of .text segment",0,$
4591
end if
4592
 
2288 clevermous 4593
include "data32.inc"
4594
 
4595
__REV__ = __REV
4596
 
3341 yogev_ezra 4597
if ~ lang eq sp
2288 clevermous 4598
diff16 "end of kernel code",0,$
3287 esevece 4599
end if