Subversion Repositories Kolibri OS

Rev

Rev 9932 | Rev 9947 | 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: 9941 $
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
; restore default cursor before killing
1905
        pusha
1906
        mov     ecx, [current_slot]
9930 Doczom 1907
        mov     ecx, [ecx + APPDATA.window]
2435 mario79 1908
        call    restore_default_cursor_before_killing
2430 mario79 1909
        popa
1910
;--------------------------------------
3545 hidnplayr 1911
; kill all sockets this process owns
1912
        pusha
9612 Doczom 1913
        mov     edx, [current_slot]
9715 Doczom 1914
        mov     edx, [edx + APPDATA.tid]
6011 hidnplayr 1915
        call    socket_process_end
3545 hidnplayr 1916
        popa
1917
;--------------------------------------
2288 clevermous 1918
        mov     ecx, [current_slot]
9715 Doczom 1919
        mov     eax, [ecx + APPDATA.tls_base]
2288 clevermous 1920
        test    eax, eax
1921
        jz      @F
1922
 
1923
        stdcall user_free, eax
1924
@@:
1925
 
9612 Doczom 1926
        mov     eax, [current_slot]
9715 Doczom 1927
        mov     [eax + APPDATA.state], TSTATE_ZOMBIE
3534 clevermous 1928
        call    wakeup_osloop
2288 clevermous 1929
 
3597 Serge 1930
.waitterm:            ; wait here for termination
1931
        call    change_task
1932
        jmp     .waitterm
2435 mario79 1933
;------------------------------------------------------------------------------
2452 mario79 1934
align 4
9930 Doczom 1935
; ecx - ptr WDATA
2435 mario79 1936
restore_default_cursor_before_killing:
2468 mario79 1937
        pushfd
1938
        cli
2435 mario79 1939
        mov     eax, [def_cursor]
9930 Doczom 1940
        mov     [ecx + WDATA.cursor], eax
2288 clevermous 1941
 
2435 mario79 1942
        movzx   eax, word [MOUSE_Y]
1943
        movzx   ebx, word [MOUSE_X]
2446 mario79 1944
        mov     eax, [d_width_calc_area + eax*4]
1945
 
5351 serge 1946
        add     eax, [_display.win_map]
9715 Doczom 1947
        movzx   edx, byte [ebx + eax]
9930 Doczom 1948
        shl     edx, BSF sizeof.WDATA
1949
        mov     esi, [window_data + edx + WDATA.cursor]
2452 mario79 1950
 
1951
        cmp     esi, [current_cursor]
1952
        je      @f
1953
 
9941 Doczom 1954
        cmp     [_display.select_cursor], 0
1955
        jz      @f
1956
 
1957
        stdcall [_display.select_cursor], esi
2435 mario79 1958
        mov     [current_cursor], esi
2452 mario79 1959
@@:
2450 mario79 1960
        mov     [redrawmouse_unconditional], 1
3534 clevermous 1961
        call    wakeup_osloop
2468 mario79 1962
        popfd
2435 mario79 1963
        ret
1964
;------------------------------------------------------------------------------
2288 clevermous 1965
iglobal
1966
align 4
1967
sys_system_table:
1968
        dd      sysfn_deactivate        ; 1 = deactivate window
1969
        dd      sysfn_terminate         ; 2 = terminate thread
1970
        dd      sysfn_activate          ; 3 = activate window
1971
        dd      sysfn_getidletime       ; 4 = get idle time
1972
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
1973
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
1974
        dd      sysfn_getactive         ; 7 = get active window
1975
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
1976
        dd      sysfn_shutdown          ; 9 = shutdown with parameter
1977
        dd      sysfn_minimize          ; 10 = minimize window
1978
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
9268 Doczom 1979
        dd      undefined_syscall       ; 12 = get last pressed key. function removed. sysfn_lastkey
2288 clevermous 1980
        dd      sysfn_getversion        ; 13 = get kernel version
1981
        dd      sysfn_waitretrace       ; 14 = wait retrace
1982
        dd      sysfn_centermouse       ; 15 = center mouse cursor
1983
        dd      sysfn_getfreemem        ; 16 = get free memory size
1984
        dd      sysfn_getallmem         ; 17 = get total memory size
1985
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
1986
                                        ;                 instead of slot
1987
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1988
        dd      sysfn_meminfo           ; 20 = get extended memory info
1989
        dd      sysfn_pid_to_slot       ; 21 = get slot number for pid
1990
        dd      sysfn_min_rest_window   ; 22 = minimize and restore any window
2648 mario79 1991
        dd      sysfn_min_windows       ; 23 = minimize all windows
2654 mario79 1992
        dd      sysfn_set_screen_sizes  ; 24 = set screen sizes for Vesa
5836 GerdtR 1993
 
1994
        dd      sysfn_zmodif            ; 25 = get/set window z modifier  ;Fantomer
2288 clevermous 1995
sysfn_num = ($ - sys_system_table)/4
1996
endg
1997
;------------------------------------------------------------------------------
1998
sys_system:
1999
        dec     ebx
2000
        cmp     ebx, sysfn_num
2001
        jae     @f
2002
        jmp     dword [sys_system_table + ebx*4]
2003
@@:
2004
        ret
2005
;------------------------------------------------------------------------------
2006
sysfn_shutdown:          ; 18.9 = system shutdown
7122 dunkaist 2007
        cmp     ecx, SYSTEM_SHUTDOWN
9930 Doczom 2008
        jl      .exit_for_anyone
7122 dunkaist 2009
        cmp     ecx, SYSTEM_RESTART
9930 Doczom 2010
        jg      .exit_for_anyone
7132 dunkaist 2011
        mov     [BOOT.shutdown_type], cl
2288 clevermous 2012
 
8866 rgimad 2013
        mov     eax, [thread_count]
2288 clevermous 2014
        mov     [SYS_SHUTDOWN], al
2015
        mov     [shutdown_processes], eax
3534 clevermous 2016
        call    wakeup_osloop
9831 dunkaist 2017
        and     dword [esp + SYSCALL_STACK.eax], 0
9930 Doczom 2018
.exit_for_anyone:
2288 clevermous 2019
        ret
2020
  uglobal
2021
   shutdown_processes:
2022
                       dd 0x0
2023
  endg
2024
;------------------------------------------------------------------------------
8270 dunkaist 2025
; in: eax -- APPDATA ptr
2026
; out: Z/z -- is/not kernel thread
2027
is_kernel_thread:
9715 Doczom 2028
        mov     eax, [eax + APPDATA.process]
2029
        cmp     eax, [SLOT_BASE + 2*sizeof.APPDATA + APPDATA.process]       ; OS
8270 dunkaist 2030
        ret
2031
;------------------------------------------------------------------------------
2288 clevermous 2032
sysfn_terminate:        ; 18.2 = TERMINATE
2472 mario79 2033
        push    ecx
2288 clevermous 2034
        cmp     ecx, 2
9910 Doczom 2035
        jb      .noprocessterminate
8866 rgimad 2036
        mov     edx, [thread_count]
2288 clevermous 2037
        cmp     ecx, edx
9910 Doczom 2038
        ja      .noprocessterminate
8866 rgimad 2039
        mov     eax, [thread_count]
9709 Doczom 2040
        shl     ecx, BSF sizeof.APPDATA
2041
        add     ecx, SLOT_BASE
9911 Doczom 2042
 
9709 Doczom 2043
        mov     edx, [ecx + APPDATA.tid]
2044
        cmp     byte [ecx + APPDATA.state], TSTATE_FREE
9910 Doczom 2045
        jz      .noprocessterminate
8270 dunkaist 2046
        push    eax
9709 Doczom 2047
        mov     eax, ecx
8270 dunkaist 2048
        call    is_kernel_thread
2049
        pop     eax
9910 Doczom 2050
        jz      .noprocessterminate
3296 clevermous 2051
        push    ecx edx
9709 Doczom 2052
        mov     edx, ecx
3296 clevermous 2053
        call    request_terminate
2054
        pop     edx ecx
2055
        test    eax, eax
9910 Doczom 2056
        jz      .noprocessterminate
2430 mario79 2057
;--------------------------------------
3545 hidnplayr 2058
; terminate all network sockets it used
2059
        pusha
9709 Doczom 2060
        mov     eax, edx     ;TODO: check function
6011 hidnplayr 2061
        call    socket_process_end
3545 hidnplayr 2062
        popa
2063
;--------------------------------------
2430 mario79 2064
; restore default cursor before killing
2065
        pusha
2066
        mov     ecx, [esp+32]
9930 Doczom 2067
        shl     ecx, BSF sizeof.WDATA
2068
        add     ecx, window_data
2452 mario79 2069
        mov     eax, [def_cursor]
9930 Doczom 2070
        cmp     [ecx + WDATA.cursor], eax
2452 mario79 2071
        je      @f
2435 mario79 2072
        call    restore_default_cursor_before_killing
2452 mario79 2073
@@:
2430 mario79 2074
        popa
2075
;--------------------------------------
2288 clevermous 2076
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
9709 Doczom 2077
        mov     [ecx + APPDATA.state], TSTATE_ZOMBIE; clear possible i40's
3534 clevermous 2078
        call    wakeup_osloop
2288 clevermous 2079
     ;call MEM_Heap_UnLock
2080
 
3534 clevermous 2081
        cmp     edx, [application_table_owner]; clear app table stat
9910 Doczom 2082
        jne     .noatsc
3534 clevermous 2083
        call    unlock_application_table
9910 Doczom 2084
.noatsc:
2085
.noprocessterminate:
2472 mario79 2086
        add     esp, 4
2288 clevermous 2087
        ret
2088
;------------------------------------------------------------------------------
2089
sysfn_terminate2:
3534 clevermous 2090
        call    lock_application_table
2288 clevermous 2091
        mov     eax, ecx
2092
        call    pid_to_slot
2093
        test    eax, eax
2094
        jz      .not_found
2095
        mov     ecx, eax
2096
        cli
2097
        call    sysfn_terminate
3534 clevermous 2098
        call    unlock_application_table
2288 clevermous 2099
        sti
9831 dunkaist 2100
        and     dword [esp + SYSCALL_STACK.eax], 0
2288 clevermous 2101
        ret
2102
.not_found:
3534 clevermous 2103
        call    unlock_application_table
9831 dunkaist 2104
        or      dword [esp + SYSCALL_STACK.eax], -1
2288 clevermous 2105
        ret
2106
;------------------------------------------------------------------------------
2107
sysfn_deactivate:         ; 18.1 = DEACTIVATE WINDOW
2108
        cmp     ecx, 2
2109
        jb      .nowindowdeactivate
8866 rgimad 2110
        cmp     ecx, [thread_count]
2288 clevermous 2111
        ja      .nowindowdeactivate
2408 Serge 2112
 
2288 clevermous 2113
        movzx   esi, word [WIN_STACK + ecx*2]
2114
        cmp     esi, 1
2115
        je      .nowindowdeactivate ; already deactive
2116
 
2117
        mov     edi, ecx
9926 Doczom 2118
        shl     edi, BSF sizeof.WDATA
2288 clevermous 2119
        add     edi, window_data
2120
        movzx   esi, word [WIN_STACK + ecx * 2]
2121
        lea     esi, [WIN_POS + esi * 2]
2122
        call    window._.window_deactivate
6800 pathoswith 2123
        call    syscall_display_settings.calculateScreen
2124
        call    syscall_display_settings.redrawScreen
2288 clevermous 2125
.nowindowdeactivate:
2126
        ret
3455 mario79 2127
;------------------------------------------------------------------------------
2288 clevermous 2128
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
5675 leency 2129
        cmp     ecx, 2
2130
        jb      .nowindowactivate
8866 rgimad 2131
        cmp     ecx, [thread_count]
2288 clevermous 2132
        ja      .nowindowactivate
3455 mario79 2133
;-------------------------------------
2134
@@:
2135
; If the window is captured and moved by the user,
2136
; then you can't change the position in window stack!!!
2137
        mov     al, [mouse.active_sys_window.action]
2138
        and     al, WINDOW_MOVE_AND_RESIZE_FLAGS
2139
        test    al, al
2140
        jz      @f
2141
        call    change_task
2142
        jmp     @b
2143
@@:
2144
;-------------------------------------
2288 clevermous 2145
        mov     [window_minimize], 2; restore window if minimized
3534 clevermous 2146
        call    wakeup_osloop
2288 clevermous 2147
 
2148
        movzx   esi, word [WIN_STACK + ecx*2]
8866 rgimad 2149
        cmp     esi, [thread_count]
2288 clevermous 2150
        je      .nowindowactivate; already active
2151
 
2152
        mov     edi, ecx
9715 Doczom 2153
        shl     edi, BSF sizeof.WDATA
2288 clevermous 2154
        add     edi, window_data
2155
        movzx   esi, word [WIN_STACK + ecx * 2]
2156
        lea     esi, [WIN_POS + esi * 2]
2157
        call    waredraw
2158
.nowindowactivate:
2159
        ret
2160
;------------------------------------------------------------------------------
5865 GerdtR 2161
align 4
5836 GerdtR 2162
sysfn_zmodif:
2163
;18,25,1 - get z_modif
2164
;18,25,2 - set z_modif
2165
;edx = -1(for current task) or TID
2166
;esi(for 2) = new value z_modif
2167
;return:
2168
;1:   eax = z_modif
2169
;2: eax=0(fail),1(success) for set z_modif
2170
 
2171
        cmp     edx, -1
2172
        jne     @f
8869 rgimad 2173
        mov     edx, [current_slot_idx]
5836 GerdtR 2174
     @@:
8866 rgimad 2175
        cmp     edx, [thread_count]
5865 GerdtR 2176
        ja      .fail
5836 GerdtR 2177
        cmp     edx, 1
5865 GerdtR 2178
        je      .fail
5836 GerdtR 2179
 
5865 GerdtR 2180
        mov     eax, edx
9715 Doczom 2181
        shl     edx, BSF sizeof.WDATA
5836 GerdtR 2182
 
9930 Doczom 2183
        test    [window_data + edx + WDATA.fl_wstate], WSTATE_USED
2184
        jz      .fail
5836 GerdtR 2185
 
2186
        cmp     ecx, 1
2187
        jnz     .set_zmod
2188
 
9715 Doczom 2189
        mov     al, [window_data + edx + WDATA.z_modif]
5865 GerdtR 2190
        jmp     .exit
5836 GerdtR 2191
 
2192
.set_zmod:
2193
        cmp     ecx, 2
5865 GerdtR 2194
        jnz     .fail
5836 GerdtR 2195
 
5865 GerdtR 2196
        mov     ebx, esi
2197
        mov     esi, eax
5836 GerdtR 2198
 
5865 GerdtR 2199
        cmp     bl, ZPOS_ALWAYS_TOP
2200
        jg      .fail
5836 GerdtR 2201
 
9715 Doczom 2202
        mov     [window_data + edx + WDATA.z_modif], bl
5836 GerdtR 2203
 
9715 Doczom 2204
        mov     eax, [window_data + edx + WDATA.box.left]
2205
        mov     ebx, [window_data + edx + WDATA.box.top]
2206
        mov     ecx, [window_data + edx + WDATA.box.width]
2207
        mov     edx, [window_data + edx + WDATA.box.height]
5836 GerdtR 2208
        add     ecx, eax
2209
        add     edx, ebx
5865 GerdtR 2210
        call    window._.set_screen
5836 GerdtR 2211
        call    window._.set_top_wnd
5865 GerdtR 2212
        call    window._.redraw_top_wnd
5836 GerdtR 2213
 
9715 Doczom 2214
        shl     esi, BSF sizeof.WDATA
9930 Doczom 2215
        mov     [esi + window_data + WDATA.fl_redraw], WSTATE_REDRAW
5865 GerdtR 2216
 
2217
 
5836 GerdtR 2218
        mov     eax, 1
5865 GerdtR 2219
        jmp     .exit
2220
.fail:
2221
        xor     eax, eax
5836 GerdtR 2222
.exit:
9831 dunkaist 2223
        mov     [esp + SYSCALL_STACK.eax], eax
5836 GerdtR 2224
        ret
2225
 
2226
;------------------------------------------------------------------------------
2288 clevermous 2227
sysfn_getidletime:              ; 18.4 = GET IDLETIME
9932 Doczom 2228
        mov     eax, [SLOT_BASE + sizeof.APPDATA + APPDATA.cpu_usage]
9831 dunkaist 2229
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2230
        ret
2231
;------------------------------------------------------------------------------
2232
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
3481 Serge 2233
        mov     eax, dword [cpu_freq]
9831 dunkaist 2234
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2235
        ret
2236
;------------------------------------------------------------------------------
3481 Serge 2237
get_cpu_freq:
2238
        mov     eax, dword [cpu_freq]
2239
        mov     edx, dword [cpu_freq+4]
2240
        ret
9268 Doczom 2241
;  SAVE ramdisk to /hd/1/kolibri.img
2288 clevermous 2242
;!!!!!!!!!!!!!!!!!!!!!!!!
2243
   include 'blkdev/rdsave.inc'
2244
;!!!!!!!!!!!!!!!!!!!!!!!!
2245
;------------------------------------------------------------------------------
2246
align 4
2247
sysfn_getactive:        ; 18.7 = get active window
8866 rgimad 2248
        mov     eax, [thread_count]
2288 clevermous 2249
        movzx   eax, word [WIN_POS + eax*2]
9831 dunkaist 2250
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2251
        ret
2252
;------------------------------------------------------------------------------
2253
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2254
;     cmp  ecx,1
2255
        dec     ecx
9911 Doczom 2256
        jnz     .set_flag
2288 clevermous 2257
        movzx   eax, byte [sound_flag]; get sound_flag
9831 dunkaist 2258
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2259
        ret
9911 Doczom 2260
.set_flag:
2288 clevermous 2261
;     cmp  ecx,2
2262
        dec     ecx
9911 Doczom 2263
        jnz     .err
2288 clevermous 2264
        xor     byte [sound_flag], 1
9911 Doczom 2265
.err:
2288 clevermous 2266
        ret
2267
;------------------------------------------------------------------------------
2268
sysfn_minimize:         ; 18.10 = minimize window
2269
        mov     [window_minimize], 1
3534 clevermous 2270
        call    wakeup_osloop
2288 clevermous 2271
        ret
2272
;------------------------------------------------------------------------------
2273
align 4
2274
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2275
        dec     ecx
4641 mario79 2276
        jnz     .exit
2277
.small_table:
8598 rgimad 2278
        stdcall is_region_userspace, edx, DRIVE_DATA_SIZE
9045 dunkaist 2279
        jnz     .exit
2288 clevermous 2280
        mov     edi, edx
2281
        mov     esi, DRIVE_DATA
4641 mario79 2282
        mov     ecx, DRIVE_DATA_SIZE ;10
2288 clevermous 2283
        cld
4641 mario79 2284
        rep movsb
2285
.exit:
2288 clevermous 2286
        ret
2287
;------------------------------------------------------------------------------
2288
sysfn_getversion:       ; 18.13 = get kernel ID and version
8247 rgimad 2289
        ; if given memory address belongs to kernel then error
9917 Doczom 2290
        stdcall is_region_userspace, ecx, version_inf.size
9045 dunkaist 2291
        jnz     .addr_error
8247 rgimad 2292
 
2288 clevermous 2293
        mov     edi, ecx
2294
        mov     esi, version_inf
9917 Doczom 2295
        mov     ecx, version_inf.size
2288 clevermous 2296
        rep movsb
2297
        ret
8247 rgimad 2298
.addr_error:    ; if given memory address is illegal
9831 dunkaist 2299
        mov     dword [esp + SYSCALL_STACK.eax], -1
8247 rgimad 2300
        ret
2288 clevermous 2301
;------------------------------------------------------------------------------
2302
sysfn_waitretrace:     ; 18.14 = sys wait retrace
9911 Doczom 2303
        ;wait retrace functions
2288 clevermous 2304
        mov     edx, 0x3da
9911 Doczom 2305
.loop:
2288 clevermous 2306
        in      al, dx
2307
        test    al, 1000b
9911 Doczom 2308
        jz      .loop
9831 dunkaist 2309
        and     [esp + SYSCALL_STACK.eax], dword 0
2288 clevermous 2310
        ret
2311
;------------------------------------------------------------------------------
2312
align 4
2313
sysfn_centermouse:      ; 18.15 = mouse centered
5350 serge 2314
        mov     eax, [_display.width]
2288 clevermous 2315
        shr     eax, 1
2316
        mov     [MOUSE_X], ax
5350 serge 2317
        mov     eax, [_display.height]
2288 clevermous 2318
        shr     eax, 1
2319
        mov     [MOUSE_Y], ax
3534 clevermous 2320
        call    wakeup_osloop
2288 clevermous 2321
        xor     eax, eax
9831 dunkaist 2322
        and     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2323
        ret
2324
;------------------------------------------------------------------------------
5851 pathoswith 2325
sysfn_mouse_acceleration:       ; 18.19 = set/get mouse features
2326
        cmp     ecx, 8
2327
        jnc     @f
9715 Doczom 2328
        jmp     dword [.table + ecx*4]
5851 pathoswith 2329
.get_mouse_acceleration:
2288 clevermous 2330
        xor     eax, eax
2331
        mov     ax, [mouse_speed_factor]
9831 dunkaist 2332
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2333
        ret
5851 pathoswith 2334
.set_mouse_acceleration:
2288 clevermous 2335
        mov     [mouse_speed_factor], dx
2336
        ret
5851 pathoswith 2337
.get_mouse_delay:
5853 pathoswith 2338
        xor     eax, eax
2339
        mov     al, [mouse_delay]
9831 dunkaist 2340
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2341
        ret
5851 pathoswith 2342
.set_mouse_delay:
5853 pathoswith 2343
        mov     [mouse_delay], dl
5851 pathoswith 2344
@@:
2288 clevermous 2345
        ret
5851 pathoswith 2346
.set_pointer_position:
5350 serge 2347
        cmp     dx, word[_display.height]
5851 pathoswith 2348
        jae     @b
2288 clevermous 2349
        rol     edx, 16
5350 serge 2350
        cmp     dx, word[_display.width]
5851 pathoswith 2351
        jae     @b
2288 clevermous 2352
        mov     [MOUSE_X], edx
4381 hidnplayr 2353
        mov     [mouse_active], 1
5851 pathoswith 2354
        jmp     wakeup_osloop
2355
.set_mouse_button:
2356
        mov     [BTN_DOWN], edx
2288 clevermous 2357
        mov     [mouse_active], 1
5851 pathoswith 2358
        jmp     wakeup_osloop
2359
.get_doubleclick_delay:
2360
        xor     eax, eax
2361
        mov     al, [mouse_doubleclick_delay]
9831 dunkaist 2362
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2363
        ret
5851 pathoswith 2364
.set_doubleclick_delay:
2365
        mov     [mouse_doubleclick_delay], dl
2366
        ret
2367
align 4
2368
.table:
2369
dd      .get_mouse_acceleration
2370
dd      .set_mouse_acceleration
2371
dd      .get_mouse_delay
2372
dd      .set_mouse_delay
2373
dd      .set_pointer_position
2374
dd      .set_mouse_button
2375
dd      .get_doubleclick_delay
2376
dd      .set_doubleclick_delay
2288 clevermous 2377
;------------------------------------------------------------------------------
2378
sysfn_getfreemem:
2379
        mov     eax, [pg_data.pages_free]
2380
        shl     eax, 2
9831 dunkaist 2381
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2382
        ret
2648 mario79 2383
;------------------------------------------------------------------------------
2288 clevermous 2384
sysfn_getallmem:
2385
        mov     eax, [MEM_AMOUNT]
2386
        shr     eax, 10
9831 dunkaist 2387
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2388
        ret
2648 mario79 2389
;------------------------------------------------------------------------------
2288 clevermous 2390
sysfn_pid_to_slot:
2391
        mov     eax, ecx
2392
        call    pid_to_slot
9831 dunkaist 2393
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2394
        ret
2648 mario79 2395
;------------------------------------------------------------------------------
2288 clevermous 2396
sysfn_min_rest_window:
2397
        pushad
2398
        mov     eax, edx ; ebx - operating
2399
        shr     ecx, 1
2400
        jnc     @f
2401
        call    pid_to_slot
2402
@@:
2403
        or      eax, eax ; eax - number of slot
2404
        jz      .error
9828 Doczom 2405
        cmp     eax, max_processes    ; varify maximal slot number
2288 clevermous 2406
        ja      .error
2407
        movzx   eax, word [WIN_STACK + eax*2]
2408
        shr     ecx, 1
2409
        jc      .restore
2410
 ; .minimize:
2411
        call    minimize_window
2412
        jmp     .exit
2413
.restore:
2414
        call    restore_minimized_window
2415
.exit:
2416
        popad
2417
        xor     eax, eax
9831 dunkaist 2418
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2419
        ret
2420
.error:
2421
        popad
2422
        xor     eax, eax
2423
        dec     eax
9831 dunkaist 2424
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2425
        ret
2648 mario79 2426
;------------------------------------------------------------------------------
2427
sysfn_min_windows:
2428
        call    minimize_all_window
9831 dunkaist 2429
        mov     [esp + SYSCALL_STACK.eax], eax
2648 mario79 2430
        call    change_task
2431
        ret
2432
;------------------------------------------------------------------------------
2654 mario79 2433
sysfn_set_screen_sizes:
2434
        cmp     [SCR_MODE], word 0x13
2435
        jbe     .exit
2436
 
2437
        cmp     [_display.select_cursor], select_cursor
2438
        jne     .exit
2439
 
2440
        cmp     ecx, [display_width_standard]
2441
        ja      .exit
2442
 
2443
        cmp     edx, [display_height_standard]
2444
        ja      .exit
2445
 
2446
        pushfd
2447
        cli
2448
        mov     eax, ecx
5351 serge 2449
        mov     ecx, [_display.lfb_pitch]
2654 mario79 2450
        mov     [_display.width], eax
2451
        dec     eax
2452
        mov     [_display.height], edx
2453
        dec     edx
2454
; eax - new Screen_Max_X
2455
; edx - new Screen_Max_Y
2456
        mov     [do_not_touch_winmap], 1
2457
        call    set_screen
2458
        mov     [do_not_touch_winmap], 0
2459
        popfd
2460
        call    change_task
2461
.exit:
2462
        ret
2463
;------------------------------------------------------------------------------
2288 clevermous 2464
uglobal
2465
screen_workarea RECT
2654 mario79 2466
display_width_standard dd 0
2467
display_height_standard dd 0
2468
do_not_touch_winmap db 0
2288 clevermous 2469
window_minimize db 0
2470
sound_flag      db 0
2654 mario79 2471
 
2288 clevermous 2472
endg
2473
 
2474
iglobal
2475
version_inf:
3454 mario79 2476
        db 0,7,7,0  ; version 0.7.7.0
2477
        db 0
2478
.rev    dd __REV__
9917 Doczom 2479
.size = $ - version_inf
2288 clevermous 2480
endg
2515 mario79 2481
;------------------------------------------------------------------------------
2482
align 4
2288 clevermous 2483
sys_cachetodiskette:
2484
        cmp     ebx, 1
4273 clevermous 2485
        jb      .no_floppy_save
2288 clevermous 2486
        cmp     ebx, 2
4273 clevermous 2487
        ja      .no_floppy_save
2288 clevermous 2488
        call    save_image
9831 dunkaist 2489
        mov     [esp + SYSCALL_STACK.eax], eax
4273 clevermous 2490
        ret
2491
.no_floppy_save:
9831 dunkaist 2492
        mov     [esp + SYSCALL_STACK.eax], dword 1
2288 clevermous 2493
        ret
2515 mario79 2494
;------------------------------------------------------------------------------
2495
align 4
2288 clevermous 2496
sys_cpuusage:
2497
 
2498
;  RETURN:
2499
;
2500
;  +00 dword     process cpu usage
2501
;  +04  word     position in windowing stack
2502
;  +06  word     windowing stack value at current position (cpu nro)
2503
;  +10 12 bytes  name
2504
;  +22 dword     start in mem
2505
;  +26 dword     used mem
2506
;  +30 dword     PID , process idenfification number
2507
;
8246 rgimad 2508
        ; if given memory address belongs to kernel then error
8329 rgimad 2509
        stdcall is_region_userspace, ebx, 0x4C
9045 dunkaist 2510
        jnz     .addr_error
2288 clevermous 2511
 
2512
        cmp     ecx, -1 ; who am I ?
2513
        jne     .no_who_am_i
8869 rgimad 2514
        mov     ecx, [current_slot_idx]
2288 clevermous 2515
  .no_who_am_i:
2516
        cmp     ecx, max_processes
2517
        ja      .nofillbuf
2518
 
2519
; +4: word: position of the window of thread in the window stack
2520
        mov     ax, [WIN_STACK + ecx * 2]
2521
        mov     [ebx+4], ax
2522
; +6: word: number of the thread slot, which window has in the window stack
2523
;           position ecx (has no relation to the specific thread)
2524
        mov     ax, [WIN_POS + ecx * 2]
2525
        mov     [ebx+6], ax
2526
 
9715 Doczom 2527
        shl     ecx, BSF sizeof.APPDATA
2288 clevermous 2528
 
2529
; +0: dword: memory usage
9932 Doczom 2530
        mov     eax, [SLOT_BASE + ecx + APPDATA.cpu_usage]
2288 clevermous 2531
        mov     [ebx], eax
2532
; +10: 11 bytes: name of the process
2533
        push    ecx
9715 Doczom 2534
        lea     eax, [SLOT_BASE + ecx + APPDATA.app_name]
2288 clevermous 2535
        add     ebx, 10
2536
        mov     ecx, 11
2537
        call    memmove
2538
        pop     ecx
2539
 
2540
; +22: address of the process in memory
2541
; +26: size of used memory - 1
2542
        push    edi
2543
        lea     edi, [ebx+12]
2544
        xor     eax, eax
2545
        mov     edx, 0x100000*16
9932 Doczom 2546
        cmp     ecx, 1 shl BSF sizeof.APPDATA
2288 clevermous 2547
        je      .os_mem
9932 Doczom 2548
        mov     edx, [SLOT_BASE + ecx + APPDATA.process]
9715 Doczom 2549
        mov     edx, [edx + PROC.mem_used]
2288 clevermous 2550
        mov     eax, std_application_base_address
2551
.os_mem:
2552
        stosd
2553
        lea     eax, [edx-1]
2554
        stosd
2555
 
9941 Doczom 2556
        mov     edx, [SLOT_BASE + ecx + APPDATA.window]
9932 Doczom 2557
 
2288 clevermous 2558
; +30: PID/TID
9932 Doczom 2559
        mov     eax, [SLOT_BASE + ecx + APPDATA.tid]
2288 clevermous 2560
        stosd
2561
 
2562
    ; window position and size
2563
        push    esi
9941 Doczom 2564
        lea     esi, [edx + WDATA.box]
2288 clevermous 2565
        movsd
2566
        movsd
2567
        movsd
2568
        movsd
2569
 
2570
    ; Process state (+50)
9932 Doczom 2571
        movzx   eax, byte [SLOT_BASE + ecx + APPDATA.state]
2288 clevermous 2572
        stosd
2573
 
2574
    ; Window client area box
9941 Doczom 2575
        lea     esi, [edx + WDATA.clientbox]
2288 clevermous 2576
        movsd
2577
        movsd
2578
        movsd
2579
        movsd
2580
 
2581
    ; Window state
9941 Doczom 2582
        mov     al, [edx + WDATA.fl_wstate]
2288 clevermous 2583
        stosb
2584
 
2585
    ; Event mask (+71)
9932 Doczom 2586
        mov     eax, dword [SLOT_BASE + ecx + APPDATA.event_mask]
2288 clevermous 2587
        stosd
4286 Serge 2588
 
4262 0CodErr 2589
    ; Keyboard mode (+75)
9932 Doczom 2590
        mov     al, byte [SLOT_BASE + ecx + APPDATA.keyboard_mode]
4286 Serge 2591
        stosb
2288 clevermous 2592
 
2593
        pop     esi
2594
        pop     edi
2595
 
2596
.nofillbuf:
2597
    ; return number of processes
2598
 
8866 rgimad 2599
        mov     eax, [thread_count]
9831 dunkaist 2600
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2601
        ret
2602
 
8246 rgimad 2603
.addr_error:    ; if given memory address is illegal
9831 dunkaist 2604
        mov     dword [esp + SYSCALL_STACK.eax], -1
8246 rgimad 2605
        ret
2606
 
2288 clevermous 2607
 
9612 Doczom 2608
; redraw status
2288 clevermous 2609
align 4
2610
sys_redrawstat:
2611
        cmp     ebx, 1
9910 Doczom 2612
        jne     .no_widgets_away
2288 clevermous 2613
        ; buttons away
8869 rgimad 2614
        mov     ecx, [current_slot_idx]
9910 Doczom 2615
.sys_newba2:
2288 clevermous 2616
        mov     edi, [BTN_ADDR]
2617
        cmp     [edi], dword 0  ; empty button list ?
9910 Doczom 2618
        je      .end_of_buttons_away
2288 clevermous 2619
        movzx   ebx, word [edi]
2620
        inc     ebx
2621
        mov     eax, edi
9910 Doczom 2622
.sys_newba:
2288 clevermous 2623
        dec     ebx
9910 Doczom 2624
        jz      .end_of_buttons_away
2288 clevermous 2625
 
2626
        add     eax, 0x10
2627
        cmp     cx, [eax]
9910 Doczom 2628
        jnz     .sys_newba
2288 clevermous 2629
 
2630
        push    eax ebx ecx
2631
        mov     ecx, ebx
2632
        inc     ecx
2633
        shl     ecx, 4
2634
        mov     ebx, eax
2635
        add     eax, 0x10
2636
        call    memmove
2637
        dec     dword [edi]
2638
        pop     ecx ebx eax
2639
 
9910 Doczom 2640
        jmp     .sys_newba2
2288 clevermous 2641
 
9910 Doczom 2642
.end_of_buttons_away:
2288 clevermous 2643
        ret
2644
 
9910 Doczom 2645
.no_widgets_away:
2288 clevermous 2646
 
2647
        cmp     ebx, 2
9910 Doczom 2648
        jnz     .srl1
2288 clevermous 2649
 
9930 Doczom 2650
        mov     edx, [current_slot]      ; return whole screen draw area for this app
2651
        mov     edx, [edx + APPDATA.window]
2652
        mov     [edx + WDATA.draw_data.left], 0
2653
        mov     [edx + WDATA.draw_data.top], 0
5350 serge 2654
        mov     eax, [_display.width]
2655
        dec     eax
9930 Doczom 2656
        mov     [edx + WDATA.draw_data.right], eax
5350 serge 2657
        mov     eax, [_display.height]
2658
        dec     eax
9930 Doczom 2659
        mov     [edx + WDATA.draw_data.bottom], eax
2288 clevermous 2660
 
9910 Doczom 2661
.srl1:
2288 clevermous 2662
        ret
2663
 
2664
;ok - 100% work
2665
;nt - not tested
2666
;---------------------------------------------------------------------------------------------
2667
;eax
2668
;0 - task switch counter. Ret switch counter in eax. Block. ok.
2669
;1 - change task. Ret nothing. Block. ok.
2670
;2 - performance control
2671
; ebx
2672
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
2673
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
2674
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
2675
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
2676
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
2677
;eax
2678
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2679
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2680
;---------------------------------------------------------------------------------------------
2681
iglobal
2682
align 4
2683
sheduler:
2684
        dd      sys_sheduler.00
2685
        dd      change_task
2686
        dd      sys_sheduler.02
2687
        dd      sys_sheduler.03
2688
        dd      sys_sheduler.04
2689
endg
2690
sys_sheduler:
2691
;rewritten by   29.12.2009
9715 Doczom 2692
        jmp     dword [sheduler + ebx*4]
2288 clevermous 2693
;.shed_counter:
2694
.00:
2695
        mov     eax, [context_counter]
9831 dunkaist 2696
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2697
        ret
2698
 
2699
.02:
2700
;.perf_control:
2701
        inc     ebx                     ;before ebx=2, ebx=3
2702
        cmp     ebx, ecx                ;if ecx=3, ebx=3
2703
        jz      cache_disable
2704
 
2705
        dec     ebx                     ;ebx=2
2706
        cmp     ebx, ecx                ;
2707
        jz      cache_enable            ;if ecx=2 and ebx=2
2708
 
2709
        dec     ebx                     ;ebx=1
2710
        cmp     ebx, ecx
2711
        jz      is_cache_enabled        ;if ecx=1 and ebx=1
2712
 
2713
        dec     ebx
2714
        test    ebx, ecx                ;ebx=0 and ecx=0
2715
        jz      modify_pce              ;if ecx=0
2716
 
2717
        ret
2718
 
2719
.03:
2720
;.rdmsr_instr:
2721
;now counter in ecx
2722
;(edx:eax) esi:edi => edx:esi
2723
        mov     eax, esi
2724
        mov     ecx, edx
2725
        rdmsr
9831 dunkaist 2726
        mov     [esp + SYSCALL_STACK.eax], eax
2727
        mov     [esp + SYSCALL_STACK.ebx], edx           ;ret in ebx?
2288 clevermous 2728
        ret
2729
 
2730
.04:
2731
;.wrmsr_instr:
2732
;now counter in ecx
2733
;(edx:eax) esi:edi => edx:esi
2734
        ; Fast Call MSR can't be destroy
3539 clevermous 2735
        ; Но MSR_AMD_EFER можно изменять, т.к. в этом регистре лиш
2736
        ; включаются/выключаются расширенные возможности
2288 clevermous 2737
        cmp     edx, MSR_SYSENTER_CS
2738
        je      @f
2739
        cmp     edx, MSR_SYSENTER_ESP
2740
        je      @f
2741
        cmp     edx, MSR_SYSENTER_EIP
2742
        je      @f
2743
        cmp     edx, MSR_AMD_STAR
2744
        je      @f
2745
 
2746
        mov     eax, esi
2747
        mov     ecx, edx
2748
        wrmsr
2749
        ; mov   [esp + 32], eax
2750
        ; mov   [esp + 20], edx ;ret in ebx?
2751
@@:
2752
        ret
2753
 
2754
cache_disable:
2755
        mov     eax, cr0
9831 dunkaist 2756
        or      eax, 01100000_00000000_00000000_00000000b
2288 clevermous 2757
        mov     cr0, eax
2758
        wbinvd  ;set MESI
2759
        ret
2760
 
2761
cache_enable:
2762
        mov     eax, cr0
9831 dunkaist 2763
        and     eax, 10011111_11111111_11111111_11111111b
2288 clevermous 2764
        mov     cr0, eax
2765
        ret
2766
 
2767
is_cache_enabled:
2768
        mov     eax, cr0
9831 dunkaist 2769
        and     eax, 01100000_00000000_00000000_00000000b
9941 Doczom 2770
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2771
        ret
2772
 
2773
modify_pce:
2774
        mov     eax, cr4
2775
;       mov ebx,0
2776
;       or  bx,100000000b ;pce
2777
;       xor eax,ebx ;invert pce
2778
        bts     eax, 8;pce=cr4[8]
2779
        mov     cr4, eax
9831 dunkaist 2780
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 2781
        ret
2782
;---------------------------------------------------------------------------------------------
2783
 
2784
 
2785
iglobal
2786
  cpustring db 'CPU',0
2787
endg
2788
 
2789
uglobal
2790
background_defined    db    0    ; diamond, 11.04.2006
2791
endg
2513 mario79 2792
;-----------------------------------------------------------------------------
2288 clevermous 2793
align 4
2794
checkmisc:
2795
        cmp     [ctrl_alt_del], 1
9910 Doczom 2796
        jne     .nocpustart
2288 clevermous 2797
 
2798
        mov     ebp, cpustring
2799
        call    fs_execute_from_sysdir
2800
 
2801
        mov     [ctrl_alt_del], 0
2513 mario79 2802
;--------------------------------------
2803
align 4
9910 Doczom 2804
.nocpustart:
2288 clevermous 2805
        cmp     [mouse_active], 1
9910 Doczom 2806
        jne     .mouse_not_active
2288 clevermous 2807
        mov     [mouse_active], 0
2411 Serge 2808
 
2288 clevermous 2809
        xor     edi, edi
9709 Doczom 2810
        mov     ebx, window_data
2411 Serge 2811
 
8866 rgimad 2812
        mov     ecx, [thread_count]
2408 Serge 2813
        movzx   eax, word [WIN_POS + ecx*2]     ; active window
9925 Doczom 2814
        shl     eax, BSF sizeof.APPDATA
2414 Serge 2815
        push    eax
2408 Serge 2816
 
2414 Serge 2817
        movzx   eax, word [MOUSE_X]
2818
        movzx   edx, word [MOUSE_Y]
2513 mario79 2819
;--------------------------------------
2408 Serge 2820
align 4
2821
.set_mouse_event:
8093 dunkaist 2822
        add     edi, sizeof.APPDATA
9709 Doczom 2823
        add     ebx, sizeof.WDATA
9917 Doczom 2824
        test    [SLOT_BASE + edi + APPDATA.event_mask], EVM_MOUSE_FILTER
2414 Serge 2825
        jz      .pos_filter
2826
 
2827
        cmp     edi, [esp]                      ; skip if filtration active
2828
        jne     .skip
2513 mario79 2829
;--------------------------------------
2830
align 4
2414 Serge 2831
.pos_filter:
9917 Doczom 2832
        test    [SLOT_BASE + edi + APPDATA.event_mask], EVM_CURSOR_FILTER
2411 Serge 2833
        jz      .set
2288 clevermous 2834
 
9709 Doczom 2835
        mov     esi, [ebx + WDATA.box.left]
2414 Serge 2836
        cmp     eax, esi
2837
        jb      .skip
9709 Doczom 2838
        add     esi, [ebx + WDATA.box.width]
2414 Serge 2839
        cmp     eax, esi
2840
        ja      .skip
2841
 
9709 Doczom 2842
        mov     esi, [ebx + WDATA.box.top]
2414 Serge 2843
        cmp     edx, esi
2844
        jb      .skip
9709 Doczom 2845
        add     esi, [ebx + WDATA.box.height]
2414 Serge 2846
        cmp     edx, esi
2847
        ja      .skip
2513 mario79 2848
;--------------------------------------
2849
align 4
2411 Serge 2850
.set:
9715 Doczom 2851
        or      [SLOT_BASE + edi + APPDATA.occurred_events], EVENT_MOUSE
2513 mario79 2852
;--------------------------------------
2853
align 4
2411 Serge 2854
.skip:
2408 Serge 2855
        loop    .set_mouse_event
2856
 
2414 Serge 2857
        pop     eax
2513 mario79 2858
;--------------------------------------
2859
align 4
9910 Doczom 2860
.mouse_not_active:
6585 pathoswith 2861
        cmp     [REDRAW_BACKGROUND], 0  ; background update ?
2288 clevermous 2862
        jz      nobackgr
2524 mario79 2863
 
2288 clevermous 2864
        cmp     [background_defined], 0
2865
        jz      nobackgr
2513 mario79 2866
;--------------------------------------
2867
align 4
3536 clevermous 2868
backgr:
9930 Doczom 2869
        mov     eax, [background_window + WDATA.draw_data.left]
2537 mario79 2870
        shl     eax, 16
9930 Doczom 2871
        add     eax, [background_window + WDATA.draw_data.right]
2537 mario79 2872
        mov     [BG_Rect_X_left_right], eax ; [left]*65536 + [right]
2873
 
9930 Doczom 2874
        mov     eax, [background_window + WDATA.draw_data.top]
2537 mario79 2875
        shl     eax, 16
9930 Doczom 2876
        add     eax, [background_window + WDATA.draw_data.bottom]
2537 mario79 2877
        mov     [BG_Rect_Y_top_bottom], eax ; [top]*65536 + [bottom]
2878
 
2288 clevermous 2879
        call    drawbackground
2580 mario79 2880
;        DEBUGF  1, "K : drawbackground\n"
2620 mario79 2881
;        DEBUGF  1, "K : backg x %x\n",[BG_Rect_X_left_right]
2882
;        DEBUGF  1, "K : backg y %x\n",[BG_Rect_Y_top_bottom]
2513 mario79 2883
;--------- set event 5 start ----------
2884
        push    ecx edi
9941 Doczom 2885
        mov     edi, window_data
8866 rgimad 2886
        mov     ecx, [thread_count]
2513 mario79 2887
;--------------------------------------
2888
align 4
2889
set_bgr_event:
9930 Doczom 2890
        add     edi, sizeof.WDATA
3536 clevermous 2891
        mov     eax, [BG_Rect_X_left_right]
2892
        mov     edx, [BG_Rect_Y_top_bottom]
9941 Doczom 2893
        cmp     [edi + WDATA.draw_bgr_x], 0
3536 clevermous 2894
        jz      .set
2895
.join:
9941 Doczom 2896
        cmp     word [edi + WDATA.draw_bgr_x], ax
3611 clevermous 2897
        jae     @f
9941 Doczom 2898
        mov     word [edi + WDATA.draw_bgr_x], ax
3611 clevermous 2899
@@:
2900
        shr     eax, 16
9941 Doczom 2901
        cmp     word [edi + WDATA.draw_bgr_x + 2], ax
3536 clevermous 2902
        jbe     @f
9941 Doczom 2903
        mov     word [edi + WDATA.draw_bgr_x + 2], ax
3536 clevermous 2904
@@:
9941 Doczom 2905
        cmp     word [edi + WDATA.draw_bgr_y], dx
3536 clevermous 2906
        jae     @f
9941 Doczom 2907
        mov     word [edi + WDATA.draw_bgr_y], dx
3536 clevermous 2908
@@:
3611 clevermous 2909
        shr     edx, 16
9941 Doczom 2910
        cmp     word [edi + WDATA.draw_bgr_y+2], dx
3536 clevermous 2911
        jbe     @f
9941 Doczom 2912
        mov     word [edi + WDATA.draw_bgr_y+2], dx
3536 clevermous 2913
@@:
2914
        jmp     .common
2915
.set:
9941 Doczom 2916
        mov     [edi + WDATA.draw_bgr_x], eax
2917
        mov     [edi + WDATA.draw_bgr_y], edx
3536 clevermous 2918
.common:
9941 Doczom 2919
        mov     eax, [edi + WDATA.thread]
9930 Doczom 2920
        test    eax, eax
2921
        jz      @f
2922
        or      [eax + APPDATA.occurred_events], EVENT_BACKGROUND
2923
@@:
9941 Doczom 2924
        loop    set_bgr_event
2513 mario79 2925
        pop     edi ecx
2926
;--------- set event 5 stop -----------
6585 pathoswith 2927
        dec     [REDRAW_BACKGROUND]     ; got new update request?
3536 clevermous 2928
        jnz     backgr
2513 mario79 2929
 
3536 clevermous 2930
        xor     eax, eax
9930 Doczom 2931
        mov     [background_window + WDATA.draw_data.left], eax
2932
        mov     [background_window + WDATA.draw_data.top], eax
2933
        mov     [background_window + WDATA.draw_data.right], eax
2934
        mov     [background_window + WDATA.draw_data.bottom], eax
2513 mario79 2935
;--------------------------------------
2936
align 4
2288 clevermous 2937
nobackgr:
2513 mario79 2938
; system shutdown request
2288 clevermous 2939
        cmp     [SYS_SHUTDOWN], byte 0
2940
        je      noshutdown
2941
 
2942
        mov     edx, [shutdown_processes]
2943
 
2944
        cmp     [SYS_SHUTDOWN], dl
3325 clevermous 2945
        jne     noshutdown
2288 clevermous 2946
 
2947
        lea     ecx, [edx-1]
9941 Doczom 2948
        mov     edx, SLOT_BASE + sizeof.APPDATA*2 ;OS_BASE+0x3040
3325 clevermous 2949
        jecxz   no_mark_system_shutdown
2513 mario79 2950
;--------------------------------------
2951
align 4
2288 clevermous 2952
markz:
3296 clevermous 2953
        push    ecx edx
9709 Doczom 2954
        cmp     [edx + APPDATA.state], TSTATE_FREE
3325 clevermous 2955
        jz      .nokill
9715 Doczom 2956
        cmp     [edx + APPDATA.process], sys_proc
3325 clevermous 2957
        jz      .nokill
3296 clevermous 2958
        call    request_terminate
3325 clevermous 2959
        jmp     .common
2960
.nokill:
2961
        dec     byte [SYS_SHUTDOWN]
2962
        xor     eax, eax
2963
.common:
3296 clevermous 2964
        pop     edx ecx
2965
        test    eax, eax
2966
        jz      @f
9709 Doczom 2967
        mov     [edx + APPDATA.state], TSTATE_ZOMBIE
3296 clevermous 2968
@@:
9709 Doczom 2969
        add     edx, sizeof.APPDATA
2288 clevermous 2970
        loop    markz
3534 clevermous 2971
        call    wakeup_osloop
2513 mario79 2972
;--------------------------------------
2973
align 4
2288 clevermous 2974
@@:
2513 mario79 2975
no_mark_system_shutdown:
2288 clevermous 2976
        dec     byte [SYS_SHUTDOWN]
2977
        je      system_shutdown
2513 mario79 2978
;--------------------------------------
2979
align 4
2288 clevermous 2980
noshutdown:
8866 rgimad 2981
        mov     eax, [thread_count]           ; termination
9709 Doczom 2982
        mov     ebx, SLOT_BASE + sizeof.APPDATA + APPDATA.state
2288 clevermous 2983
        mov     esi, 1
2513 mario79 2984
;--------------------------------------
2985
align 4
2288 clevermous 2986
newct:
2987
        mov     cl, [ebx]
9715 Doczom 2988
        cmp     cl, TSTATE_ZOMBIE
3325 clevermous 2989
        jz      .terminate
2513 mario79 2990
 
9715 Doczom 2991
        cmp     cl, TSTATE_TERMINATING
3325 clevermous 2992
        jnz     .noterminate
2993
.terminate:
2994
        pushad
9941 Doczom 2995
        push    esi
2996
        mov     ecx, dword[ebx - APPDATA.state + APPDATA.window]
3493 mario79 2997
        call    restore_default_cursor_before_killing
2998
 
9941 Doczom 2999
        pop     esi
3325 clevermous 3000
        call    terminate
3001
        popad
3002
        cmp     byte [SYS_SHUTDOWN], 0
3003
        jz      .noterminate
3004
        dec     byte [SYS_SHUTDOWN]
3005
        je      system_shutdown
2288 clevermous 3006
 
3325 clevermous 3007
.noterminate:
9709 Doczom 3008
        add     ebx, sizeof.APPDATA
2288 clevermous 3009
        inc     esi
3010
        dec     eax
3011
        jnz     newct
3012
        ret
2513 mario79 3013
;-----------------------------------------------------------------------------
3014
align 4
9941 Doczom 3015
; eax - ptr to WDATA
2288 clevermous 3016
redrawscreen:
3017
; eax , if process window_data base is eax, do not set flag/limits
3018
 
3019
        pushad
3020
        push    eax
3021
 
3022
;;;         mov   ebx,2
3023
;;;         call  delay_hs
3024
 
3025
         ;mov   ecx,0               ; redraw flags for apps
3026
        xor     ecx, ecx
2513 mario79 3027
;--------------------------------------
3028
align 4
3029
newdw2:
2288 clevermous 3030
        inc     ecx
3031
        push    ecx
3032
 
3033
        mov     eax, ecx
9715 Doczom 3034
        shl     eax, BSF sizeof.WDATA
2288 clevermous 3035
        add     eax, window_data
3036
 
3037
        cmp     eax, [esp+4]
3038
        je      not_this_task
3039
                                   ; check if window in redraw area
3040
        mov     edi, eax
3041
 
3042
        cmp     ecx, 1             ; limit for background
3043
        jz      bgli
3044
 
5870 GerdtR 3045
        mov     eax, [esp+4]        ;if upper in z-position - no redraw
3046
        test    eax, eax
3047
        jz      @f
3048
        mov     al, [eax + WDATA.z_modif]
3049
        cmp     [edi + WDATA.z_modif], al
3050
        jg      ricino
3051
      @@:
3052
 
2288 clevermous 3053
        mov     eax, [edi + WDATA.box.left]
3054
        mov     ebx, [edi + WDATA.box.top]
3055
 
9941 Doczom 3056
        cmp     ebx, [draw_limits.bottom] ; ecx = area y end     ebx = window y start
3057
        jae     ricino
2288 clevermous 3058
 
9941 Doczom 3059
        cmp     eax, [draw_limits.right] ; ecx = area x end     eax = window x start
3060
        jae     ricino
2288 clevermous 3061
 
3062
        mov     eax, [edi + WDATA.box.left]
3063
        mov     ebx, [edi + WDATA.box.top]
3064
        mov     ecx, [edi + WDATA.box.width]
3065
        mov     edx, [edi + WDATA.box.height]
3066
        add     ecx, eax
3067
        add     edx, ebx
3068
 
3069
        mov     eax, [draw_limits.top]  ; eax = area y start     edx = window y end
3070
        cmp     edx, eax
3071
        jb      ricino
3072
 
3073
        mov     eax, [draw_limits.left]  ; eax = area x start     ecx = window x end
3074
        cmp     ecx, eax
3075
        jb      ricino
2513 mario79 3076
;--------------------------------------
3077
align 4
3078
bgli:
9941 Doczom 3079
        cmp     dword[esp], 1  ; check index in window_data array, 1 - idle
2288 clevermous 3080
        jnz     .az
2513 mario79 3081
 
6585 pathoswith 3082
        cmp     [REDRAW_BACKGROUND], 0
2288 clevermous 3083
        jz      .az
2513 mario79 3084
 
2288 clevermous 3085
        mov     dl, 0
3086
        mov     ebx, [draw_limits.left]
9930 Doczom 3087
        cmp     ebx, [edi + WDATA.draw_data.left]
2288 clevermous 3088
        jae     @f
2513 mario79 3089
 
9930 Doczom 3090
        mov     [edi + WDATA.draw_data.left], ebx
2288 clevermous 3091
        mov     dl, 1
2513 mario79 3092
;--------------------------------------
3093
align 4
3094
@@:
2288 clevermous 3095
        mov     ebx, [draw_limits.top]
9930 Doczom 3096
        cmp     ebx, [edi + WDATA.draw_data.top]
2288 clevermous 3097
        jae     @f
2513 mario79 3098
 
9930 Doczom 3099
        mov     [edi + WDATA.draw_data.top], ebx
2288 clevermous 3100
        mov     dl, 1
2513 mario79 3101
;--------------------------------------
3102
align 4
3103
@@:
2288 clevermous 3104
        mov     ebx, [draw_limits.right]
9930 Doczom 3105
        cmp     ebx, [edi + WDATA.draw_data.right]
2288 clevermous 3106
        jbe     @f
2513 mario79 3107
 
9930 Doczom 3108
        mov     [edi + WDATA.draw_data.right], ebx
2288 clevermous 3109
        mov     dl, 1
2513 mario79 3110
;--------------------------------------
3111
align 4
3112
@@:
2288 clevermous 3113
        mov     ebx, [draw_limits.bottom]
9930 Doczom 3114
        cmp     ebx, [edi + WDATA.draw_data.bottom]
2288 clevermous 3115
        jbe     @f
2513 mario79 3116
 
9930 Doczom 3117
        mov     [edi + WDATA.draw_data.bottom], ebx
2288 clevermous 3118
        mov     dl, 1
2513 mario79 3119
;--------------------------------------
3120
align 4
3121
@@:
6585 pathoswith 3122
        add     [REDRAW_BACKGROUND], dl
3534 clevermous 3123
        call    wakeup_osloop
2288 clevermous 3124
        jmp     newdw8
2513 mario79 3125
;--------------------------------------
3126
align 4
3127
.az:
2288 clevermous 3128
        mov     ebx, [draw_limits.left]        ; set limits
9941 Doczom 3129
        mov     [edi + WDATA.draw_data.left], ebx
2288 clevermous 3130
        mov     ebx, [draw_limits.top]
9941 Doczom 3131
        mov     [edi + WDATA.draw_data.top], ebx
2288 clevermous 3132
        mov     ebx, [draw_limits.right]
9941 Doczom 3133
        mov     [edi + WDATA.draw_data.right], ebx
2288 clevermous 3134
        mov     ebx, [draw_limits.bottom]
9941 Doczom 3135
        mov     [edi + WDATA.draw_data.bottom], ebx
2288 clevermous 3136
 
9941 Doczom 3137
        cmp     dword [esp], 1  ; check idle thread
2288 clevermous 3138
        jne     nobgrd
6585 pathoswith 3139
        inc     [REDRAW_BACKGROUND]
3534 clevermous 3140
        call    wakeup_osloop
2513 mario79 3141
;--------------------------------------
3142
align 4
3143
newdw8:
3144
nobgrd:
3936 mario79 3145
;--------------------------------------
9941 Doczom 3146
        push    edi ebp
3147
        mov     edi, [esp+8]
3936 mario79 3148
        cmp     edi, 1
3149
        je      .found
2288 clevermous 3150
 
3936 mario79 3151
        mov     eax, [draw_limits.left]
3152
        mov     ebx, [draw_limits.top]
3153
        mov     ecx, [draw_limits.right]
3154
        sub     ecx, eax
3155
        test    ecx, ecx
3156
        jz      .not_found
3157
 
3158
        mov     edx, [draw_limits.bottom]
3159
        sub     edx, ebx
3160
        test    edx, edx
3161
        jz      .not_found
3162
 
3163
; eax - x, ebx - y
3164
; ecx - size x, edx - size y
3165
        add     ebx, edx
3166
;--------------------------------------
3167
align 4
3168
.start_y:
3169
        push    ecx
3170
;--------------------------------------
3171
align 4
3172
.start_x:
3173
        add     eax, ecx
3174
        mov     ebp, [d_width_calc_area + ebx*4]
5351 serge 3175
        add     ebp, [_display.win_map]
3936 mario79 3176
        movzx   ebp, byte[eax+ebp] ; get value for current point
3177
        cmp     ebp, edi
3178
        jne     @f
3179
 
3180
        pop     ecx
3181
        jmp     .found
3182
;--------------------------------------
3183
align 4
3184
@@:
3185
        sub     eax, ecx
3186
 
3187
        dec     ecx
9221 dunkaist 3188
        jns     .start_x
3936 mario79 3189
 
3190
        pop     ecx
3191
        dec     ebx
3192
        dec     edx
9221 dunkaist 3193
        jns     .start_y
3936 mario79 3194
;--------------------------------------
3195
align 4
3196
.not_found:
9941 Doczom 3197
        pop     ebp edi
3936 mario79 3198
        jmp     ricino
3199
;--------------------------------------
3200
align 4
3201
.found:
9941 Doczom 3202
        pop     ebp edi
3936 mario79 3203
 
9941 Doczom 3204
        mov     [edi + WDATA.fl_redraw], WSTATE_REDRAW  ; mark as redraw
2513 mario79 3205
;--------------------------------------
3206
align 4
3207
ricino:
3208
not_this_task:
2288 clevermous 3209
        pop     ecx
3210
 
8866 rgimad 3211
        cmp     ecx, [thread_count]
2288 clevermous 3212
        jle     newdw2
3213
 
3214
        pop     eax
3215
        popad
3216
        ret
2513 mario79 3217
;-----------------------------------------------------------------------------
3218
align 4
2288 clevermous 3219
calculatebackground:   ; background
5351 serge 3220
        mov     edi, [_display.win_map]              ; set os to use all pixels
2288 clevermous 3221
        mov     eax, 0x01010101
5351 serge 3222
        mov     ecx, [_display.win_map_size]
2288 clevermous 3223
        shr     ecx, 2
3224
        rep stosd
9930 Doczom 3225
        mov     byte[background_window + WDATA.z_modif], ZPOS_DESKTOP
6585 pathoswith 3226
        mov     [REDRAW_BACKGROUND], 0
2288 clevermous 3227
        ret
2513 mario79 3228
;-----------------------------------------------------------------------------
2288 clevermous 3229
uglobal
3230
  imax    dd 0x0
3231
endg
2513 mario79 3232
;-----------------------------------------------------------------------------
3233
align 4
2288 clevermous 3234
delay_ms:     ; delay in 1/1000 sec
8139 dunkaist 3235
        pushad
3236
 
3237
        cmp     [hpet_base], 0
3238
        jz      .no_hpet
3239
        mov     eax, esi
8176 dunkaist 3240
        mov     edx, 1_000_000 ; ms to ns
8139 dunkaist 3241
        mul     edx
3242
        mov     ebx, edx
3243
        mov     ecx, eax
3244
 
2288 clevermous 3245
        push    ecx
8139 dunkaist 3246
        call    get_clock_ns
3247
        pop     ecx
3248
        mov     edi, edx
3249
        mov     esi, eax
3250
.wait:
3251
        push    ecx
3252
        call    get_clock_ns
3253
        pop     ecx
3254
        sub     eax, esi
3255
        sbb     edx, edi
3256
        sub     eax, ecx
3257
        sbb     edx, ebx
3258
        jc      .wait
3259
        jmp     .done
2288 clevermous 3260
 
8139 dunkaist 3261
.no_hpet:
2288 clevermous 3262
        mov     ecx, esi
3263
        ; 
3264
        imul    ecx, 33941
3265
        shr     ecx, 9
3266
        ; 
3267
 
3268
        in      al, 0x61
3269
        and     al, 0x10
3270
        mov     ah, al
3271
        cld
8139 dunkaist 3272
 
3273
.cnt1:
2288 clevermous 3274
        in      al, 0x61
3275
        and     al, 0x10
3276
        cmp     al, ah
8139 dunkaist 3277
        jz      .cnt1
2288 clevermous 3278
 
3279
        mov     ah, al
8139 dunkaist 3280
        loop    .cnt1
2288 clevermous 3281
 
8139 dunkaist 3282
.done:
3283
        popad
2288 clevermous 3284
        ret
2513 mario79 3285
;-----------------------------------------------------------------------------
2411 Serge 3286
align 4
2288 clevermous 3287
set_app_param:
9612 Doczom 3288
        mov     edi, [current_slot]
9614 Doczom 3289
        xchg    ebx, [edi + APPDATA.event_mask] ; set new event mask
9897 dunkaist 3290
        mov     [esp + SYSCALL_STACK.eax], ebx  ; return old mask value
2288 clevermous 3291
        ret
2513 mario79 3292
;-----------------------------------------------------------------------------
3303 clevermous 3293
 
3294
; this is for syscall
3295
proc delay_hs_unprotected
3296
        call    unprotect_from_terminate
3297
        call    delay_hs
3298
        call    protect_from_terminate
3299
        ret
3300
endp
3301
 
3597 Serge 3302
if 1
2513 mario79 3303
align 4
2288 clevermous 3304
delay_hs:     ; delay in 1/100 secs
3305
; ebx = delay time
3595 Serge 3306
        pushad
3307
        push    ebx
3308
        xor     esi, esi
3309
        mov     ecx, MANUAL_DESTROY
3310
        call    create_event
3311
        test    eax, eax
3312
        jz      .done
2288 clevermous 3313
 
3595 Serge 3314
        mov     ebx, edx
3315
        mov     ecx, [esp]
3597 Serge 3316
        push    edx
3595 Serge 3317
        push    eax
3318
        call    wait_event_timeout
3319
        pop     eax
3597 Serge 3320
        pop     ebx
3595 Serge 3321
        call    destroy_event
3322
.done:
3323
        add     esp, 4
3324
        popad
2288 clevermous 3325
        ret
3596 Serge 3326
 
3327
else
3328
 
3329
align 4
3330
delay_hs:     ; delay in 1/100 secs
3331
; ebx = delay time
3332
        push    ecx
3333
        push    edx
3334
 
3335
        mov     edx, [timer_ticks]
3336
;--------------------------------------
3337
align 4
9910 Doczom 3338
.newtic:
3596 Serge 3339
        mov     ecx, [timer_ticks]
3340
        sub     ecx, edx
3341
        cmp     ecx, ebx
9910 Doczom 3342
        jae     .zerodelay
3596 Serge 3343
 
3344
        call    change_task
3345
 
9910 Doczom 3346
        jmp     .newtic
3596 Serge 3347
;--------------------------------------
3348
align 4
9910 Doczom 3349
.zerodelay:
3596 Serge 3350
        pop     edx
3351
        pop     ecx
3352
        ret
3353
end if
3354
 
2513 mario79 3355
;-----------------------------------------------------------------------------
2288 clevermous 3356
align 16        ;very often call this subrutine
3357
memmove:       ; memory move in bytes
3358
; eax = from
3359
; ebx = to
3360
; ecx = no of bytes
3361
        test    ecx, ecx
3362
        jle     .ret
3363
 
3364
        push    esi edi ecx
3365
 
3366
        mov     edi, ebx
3367
        mov     esi, eax
3368
 
3369
        test    ecx, not 11b
3370
        jz      @f
3371
 
3372
        push    ecx
3373
        shr     ecx, 2
3374
        rep movsd
3375
        pop     ecx
3376
        and     ecx, 11b
3377
        jz      .finish
2513 mario79 3378
;--------------------------------------
3379
align 4
3380
@@:
2288 clevermous 3381
        rep movsb
2513 mario79 3382
;--------------------------------------
3383
align 4
3384
.finish:
2288 clevermous 3385
        pop     ecx edi esi
2513 mario79 3386
;--------------------------------------
3387
align 4
3388
.ret:
2288 clevermous 3389
        ret
2513 mario79 3390
;-----------------------------------------------------------------------------
2288 clevermous 3391
 
9742 Doczom 3392
; in: eax = port
3393
;     ebp = subfunction
3394
;          0 - set access
3395
;          1 - clear access
3396
; out: not return value
2288 clevermous 3397
align 4
3398
set_io_access_rights:
3399
        push    edi eax
3400
        mov     edi, tss._io_map_0
9743 Doczom 3401
 
9742 Doczom 3402
        test    ebp, ebp         ; enable access - ebp = 0
2288 clevermous 3403
        jnz     .siar1
9743 Doczom 3404
 
2288 clevermous 3405
        btr     [edi], eax
3406
        pop     eax edi
3407
        ret
3408
.siar1:
9742 Doczom 3409
        bts     [edi], eax      ; disable access - ebp = 1
2288 clevermous 3410
        pop     eax edi
3411
        ret
9279 Doczom 3412
 
3413
align 4
9743 Doczom 3414
; @brief ReservePortArea and FreePortArea
3415
; @param edx number end arrea of ports (include last number of port)
3416
; @param ecx number start arrea of ports
3417
; @param ebx sub function 0 - reserve, 1 - free
3418
; @param eax 46 - number function
3419
; @returns  eax = 0 - succesful eax = 1 - error
3420
syscall_reserveportarea:        ; ReservePortArea and FreePortArea
9279 Doczom 3421
 
3422
        call    r_f_port_area
9831 dunkaist 3423
        mov     [esp + SYSCALL_STACK.eax], eax
9279 Doczom 3424
        ret
3425
 
2288 clevermous 3426
;reserve/free group of ports
3427
;  * eax = 46 - number function
3428
;  * ebx = 0 - reserve, 1 - free
3429
;  * ecx = number start arrea of ports
3430
;  * edx = number end arrea of ports (include last number of port)
3431
;Return value:
3432
;  * eax = 0 - succesful
3433
;  * eax = 1 - error
3434
;  * The system has reserve this ports:
3435
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
3436
;destroys eax,ebx, ebp
3437
r_f_port_area:
3438
 
3439
        test    ebx, ebx
9910 Doczom 3440
        jnz     .free_port_area
2288 clevermous 3441
 
3442
        cmp     ecx, edx      ; beginning > end ?
9917 Doczom 3443
        ja      .err
9743 Doczom 3444
        cmp     edx, 65536    ;test ebx, not 0xffff
9917 Doczom 3445
        jae     .err
2288 clevermous 3446
        mov     eax, [RESERVED_PORTS]
3447
        test    eax, eax      ; no reserved areas ?
9910 Doczom 3448
        je      .rpal2
2288 clevermous 3449
        cmp     eax, 255      ; max reserved
9917 Doczom 3450
        jae     .err
9910 Doczom 3451
 .rpal3:
2288 clevermous 3452
        mov     ebx, eax
9743 Doczom 3453
        shl     ebx, 4   ;16 byte is sizeof item in RESERVED_PORTS table
2288 clevermous 3454
        add     ebx, RESERVED_PORTS
3455
        cmp     ecx, [ebx+8]
9910 Doczom 3456
        ja      .rpal4
2288 clevermous 3457
        cmp     edx, [ebx+4]
9917 Doczom 3458
        jae     .err
9910 Doczom 3459
 .rpal4:
2288 clevermous 3460
        dec     eax
9910 Doczom 3461
        jnz     .rpal3
3462
        jmp     .rpal2
9917 Doczom 3463
.err:
2288 clevermous 3464
        xor     eax, eax
3465
        inc     eax
3466
        ret
9917 Doczom 3467
 
9910 Doczom 3468
   .rpal2:
2288 clevermous 3469
     ; enable port access at port IO map
3470
        pushad                        ; start enable io map
3471
        mov     eax, ecx
3472
        xor     ebp, ebp               ; enable - eax = port
9742 Doczom 3473
        cli
9910 Doczom 3474
.new_port_access:
2288 clevermous 3475
        call    set_io_access_rights
9742 Doczom 3476
 
2288 clevermous 3477
        inc     eax
3478
        cmp     eax, edx
9910 Doczom 3479
        jbe     .new_port_access
9917 Doczom 3480
 
9742 Doczom 3481
        sti
2288 clevermous 3482
        popad                         ; end enable io map
3483
 
3484
        mov     eax, [RESERVED_PORTS]
9742 Doczom 3485
        inc     eax
2288 clevermous 3486
        mov     [RESERVED_PORTS], eax
3487
        shl     eax, 4
3488
        add     eax, RESERVED_PORTS
9692 Doczom 3489
        mov     ebx, [current_slot]
9715 Doczom 3490
        mov     ebx, [ebx + APPDATA.tid]
9743 Doczom 3491
        mov     [eax], ebx   ; tid
3492
        mov     [eax+4], ecx ;start port
3493
        mov     [eax+8], edx ;finish port
2288 clevermous 3494
 
3495
        xor     eax, eax
3496
        ret
3497
 
9910 Doczom 3498
.free_port_area:
2288 clevermous 3499
 
3500
        mov     eax, [RESERVED_PORTS]; no reserved areas ?
3501
        test    eax, eax
9910 Doczom 3502
        jz      .frpal2
9692 Doczom 3503
        mov     ebx, [current_slot]
9715 Doczom 3504
        mov     ebx, [ebx + APPDATA.tid]
9910 Doczom 3505
   .frpal3:
2288 clevermous 3506
        mov     edi, eax
3507
        shl     edi, 4
3508
        add     edi, RESERVED_PORTS
3509
        cmp     ebx, [edi]
9910 Doczom 3510
        jne     .frpal4
2288 clevermous 3511
        cmp     ecx, [edi+4]
9910 Doczom 3512
        jne     .frpal4
2288 clevermous 3513
        cmp     edx, [edi+8]
9910 Doczom 3514
        jne     .frpal4
3515
        jmp     .frpal1
3516
   .frpal4:
2288 clevermous 3517
        dec     eax
9910 Doczom 3518
        jnz     .frpal3
3519
   .frpal2:
2288 clevermous 3520
        inc     eax
3521
        ret
9910 Doczom 3522
   .frpal1:
2288 clevermous 3523
        push    ecx
3524
        mov     ecx, 256
3525
        sub     ecx, eax
3526
        shl     ecx, 4
3527
        mov     esi, edi
3528
        add     esi, 16
3529
        cld
3530
        rep movsb
3531
 
3532
        dec     dword [RESERVED_PORTS]
3533
;disable port access at port IO map
9742 Doczom 3534
                        ; start disable io map
2288 clevermous 3535
        pop     eax     ;start port
9742 Doczom 3536
        ;cmp     edx, 65536
3537
        ;jge     no_mask_io
2288 clevermous 3538
 
3539
        xor     ebp, ebp
3540
        inc     ebp
9910 Doczom 3541
.new_port_access_disable:           ; disable - eax = port
2288 clevermous 3542
        call    set_io_access_rights
9742 Doczom 3543
 
2288 clevermous 3544
        inc     eax
3545
        cmp     eax, edx
9910 Doczom 3546
        jbe     .new_port_access_disable
9917 Doczom 3547
                                    ; end disable io map
2288 clevermous 3548
        xor     eax, eax
3549
        ret
2430 mario79 3550
;-----------------------------------------------------------------------------
2288 clevermous 3551
align 4
3552
drawbackground:
3553
        cmp     [BgrDrawMode], dword 1
9910 Doczom 3554
        jne     .bgrstr
2288 clevermous 3555
        call    vesa20_drawbackground_tiled
2453 mario79 3556
;        call    [draw_pointer]
3557
        call    __sys_draw_pointer
2288 clevermous 3558
        ret
2430 mario79 3559
;--------------------------------------
3560
align 4
9910 Doczom 3561
.bgrstr:
2288 clevermous 3562
        call    vesa20_drawbackground_stretch
2453 mario79 3563
;        call    [draw_pointer]
3564
        call    __sys_draw_pointer
2288 clevermous 3565
        ret
2430 mario79 3566
;-----------------------------------------------------------------------------
2288 clevermous 3567
align 4
3568
syscall_putimage:                       ; PutImage
8714 Doczom 3569
; add check pointer
3570
        push    ecx
3571
        mov     ax, cx
3572
        shr     ecx, 16
3573
        imul    eax, ecx
3574
        lea     eax, [eax*3]
3575
        stdcall is_region_userspace, ebx, eax
3576
        pop     ecx
9045 dunkaist 3577
        jnz     sys_putimage.exit
8714 Doczom 3578
 
2288 clevermous 3579
sys_putimage:
3580
        test    ecx, 0x80008000
3581
        jnz     .exit
3582
        test    ecx, 0x0000FFFF
3583
        jz      .exit
3584
        test    ecx, 0xFFFF0000
3585
        jnz     @f
2430 mario79 3586
;--------------------------------------
3587
align 4
3588
.exit:
2288 clevermous 3589
        ret
2430 mario79 3590
;--------------------------------------
3591
align 4
3592
@@:
9926 Doczom 3593
        mov     edi, [current_slot_idx]
3594
        shl     edi, BSF sizeof.WDATA
3595
        add     dx, word[window_data + edi + WDATA.clientbox.top]
2288 clevermous 3596
        rol     edx, 16
9926 Doczom 3597
        add     dx, word[window_data + edi + WDATA.clientbox.left]
2288 clevermous 3598
        rol     edx, 16
2430 mario79 3599
;--------------------------------------
3600
align 4
3601
.forced:
2288 clevermous 3602
        push    ebp esi 0
3603
        mov     ebp, putimage_get24bpp
3604
        mov     esi, putimage_init24bpp
2430 mario79 3605
;--------------------------------------
3606
align 4
2288 clevermous 3607
sys_putimage_bpp:
2430 mario79 3608
        call    vesa20_putimage
2288 clevermous 3609
        pop     ebp esi ebp
2430 mario79 3610
        ret
3611
;        jmp     [draw_pointer]
3612
;-----------------------------------------------------------------------------
2288 clevermous 3613
align 4
3614
sys_putimage_palette:
3615
; ebx = pointer to image
3616
; ecx = [xsize]*65536 + [ysize]
3617
; edx = [xstart]*65536 + [ystart]
3618
; esi = number of bits per pixel, must be 8, 24 or 32
3619
; edi = pointer to palette
3620
; ebp = row delta
8715 Doczom 3621
; check pointer
9910 Doczom 3622
        push    ecx esi
8715 Doczom 3623
        mov     ax, cx
3624
        shr     ecx, 16
3625
        imul    eax, ecx
9910 Doczom 3626
;        imul    eax, esi ; eax*count bit in 1 pixel
3627
;        shr     eax, 3
8715 Doczom 3628
        stdcall is_region_userspace, ebx, eax
9910 Doczom 3629
        pop     esi ecx
9045 dunkaist 3630
        jnz     sys_putimage.exit
8715 Doczom 3631
 
9926 Doczom 3632
        mov     eax, [current_slot_idx]
3633
        shl     eax, BSF sizeof.WDATA
3634
        add     dx, word [window_data + eax + WDATA.clientbox.top]
2288 clevermous 3635
        rol     edx, 16
9926 Doczom 3636
        add     dx, word [window_data + eax + WDATA.clientbox.left]
2288 clevermous 3637
        rol     edx, 16
2430 mario79 3638
;--------------------------------------
3639
align 4
2288 clevermous 3640
.forced:
3641
        cmp     esi, 1
3642
        jnz     @f
3643
        push    edi
3644
        mov     eax, [edi+4]
3645
        sub     eax, [edi]
3646
        push    eax
3647
        push    dword [edi]
3648
        push    0ffffff80h
3649
        mov     edi, esp
3650
        call    put_mono_image
3651
        add     esp, 12
3652
        pop     edi
3653
        ret
2430 mario79 3654
;--------------------------------------
3655
align 4
2288 clevermous 3656
@@:
3657
        cmp     esi, 2
3658
        jnz     @f
3659
        push    edi
3660
        push    0ffffff80h
3661
        mov     edi, esp
3662
        call    put_2bit_image
3663
        pop     eax
3664
        pop     edi
3665
        ret
2430 mario79 3666
;--------------------------------------
3667
align 4
2288 clevermous 3668
@@:
3669
        cmp     esi, 4
3670
        jnz     @f
3671
        push    edi
3672
        push    0ffffff80h
3673
        mov     edi, esp
3674
        call    put_4bit_image
3675
        pop     eax
3676
        pop     edi
3677
        ret
2430 mario79 3678
;--------------------------------------
3679
align 4
2288 clevermous 3680
@@:
3681
        push    ebp esi ebp
3682
        cmp     esi, 8
3683
        jnz     @f
3684
        mov     ebp, putimage_get8bpp
3685
        mov     esi, putimage_init8bpp
3686
        jmp     sys_putimage_bpp
2430 mario79 3687
;--------------------------------------
3688
align 4
2288 clevermous 3689
@@:
2727 dunkaist 3690
        cmp     esi, 9
3691
        jnz     @f
3692
        mov     ebp, putimage_get9bpp
3693
        mov     esi, putimage_init9bpp
3694
        jmp     sys_putimage_bpp
3695
;--------------------------------------
3696
align 4
3697
@@:
2288 clevermous 3698
        cmp     esi, 15
3699
        jnz     @f
3700
        mov     ebp, putimage_get15bpp
3701
        mov     esi, putimage_init15bpp
3702
        jmp     sys_putimage_bpp
2430 mario79 3703
;--------------------------------------
3704
align 4
2288 clevermous 3705
@@:
3706
        cmp     esi, 16
3707
        jnz     @f
3708
        mov     ebp, putimage_get16bpp
3709
        mov     esi, putimage_init16bpp
3710
        jmp     sys_putimage_bpp
2430 mario79 3711
;--------------------------------------
3712
align 4
2288 clevermous 3713
@@:
3714
        cmp     esi, 24
3715
        jnz     @f
3716
        mov     ebp, putimage_get24bpp
3717
        mov     esi, putimage_init24bpp
3718
        jmp     sys_putimage_bpp
2430 mario79 3719
;--------------------------------------
3720
align 4
2288 clevermous 3721
@@:
3722
        cmp     esi, 32
3723
        jnz     @f
3724
        mov     ebp, putimage_get32bpp
3725
        mov     esi, putimage_init32bpp
3726
        jmp     sys_putimage_bpp
2430 mario79 3727
;--------------------------------------
3728
align 4
2288 clevermous 3729
@@:
3730
        pop     ebp esi ebp
3731
        ret
2430 mario79 3732
;-----------------------------------------------------------------------------
3733
align 4
2288 clevermous 3734
put_mono_image:
3735
        push    ebp esi ebp
3736
        mov     ebp, putimage_get1bpp
3737
        mov     esi, putimage_init1bpp
3738
        jmp     sys_putimage_bpp
2430 mario79 3739
;-----------------------------------------------------------------------------
3740
align 4
2288 clevermous 3741
put_2bit_image:
3742
        push    ebp esi ebp
3743
        mov     ebp, putimage_get2bpp
3744
        mov     esi, putimage_init2bpp
3745
        jmp     sys_putimage_bpp
2430 mario79 3746
;-----------------------------------------------------------------------------
3747
align 4
2288 clevermous 3748
put_4bit_image:
3749
        push    ebp esi ebp
3750
        mov     ebp, putimage_get4bpp
3751
        mov     esi, putimage_init4bpp
3752
        jmp     sys_putimage_bpp
2430 mario79 3753
;-----------------------------------------------------------------------------
3754
align 4
2288 clevermous 3755
putimage_init24bpp:
3756
        lea     eax, [eax*3]
3757
putimage_init8bpp:
2727 dunkaist 3758
putimage_init9bpp:
2288 clevermous 3759
        ret
2430 mario79 3760
;-----------------------------------------------------------------------------
2288 clevermous 3761
align 16
3762
putimage_get24bpp:
3763
        movzx   eax, byte [esi+2]
3764
        shl     eax, 16
3765
        mov     ax, [esi]
3766
        add     esi, 3
3767
        ret     4
2430 mario79 3768
;-----------------------------------------------------------------------------
2288 clevermous 3769
align 16
3770
putimage_get8bpp:
3771
        movzx   eax, byte [esi]
3772
        push    edx
3773
        mov     edx, [esp+8]
9715 Doczom 3774
        mov     eax, [edx + eax*4]
2288 clevermous 3775
        pop     edx
3776
        inc     esi
3777
        ret     4
2430 mario79 3778
;-----------------------------------------------------------------------------
2727 dunkaist 3779
align 16
3780
putimage_get9bpp:
3781
        lodsb
3782
        mov     ah, al
3783
        shl     eax, 8
3784
        mov     al, ah
3785
        ret     4
3786
;-----------------------------------------------------------------------------
2430 mario79 3787
align 4
2288 clevermous 3788
putimage_init1bpp:
3789
        add     eax, ecx
3790
        push    ecx
3791
        add     eax, 7
3792
        add     ecx, 7
3793
        shr     eax, 3
3794
        shr     ecx, 3
3795
        sub     eax, ecx
3796
        pop     ecx
3797
        ret
2430 mario79 3798
;-----------------------------------------------------------------------------
2288 clevermous 3799
align 16
3800
putimage_get1bpp:
3801
        push    edx
3802
        mov     edx, [esp+8]
3803
        mov     al, [edx]
3804
        add     al, al
3805
        jnz     @f
3806
        lodsb
3807
        adc     al, al
3808
@@:
3809
        mov     [edx], al
3810
        sbb     eax, eax
3811
        and     eax, [edx+8]
3812
        add     eax, [edx+4]
3813
        pop     edx
3814
        ret     4
2430 mario79 3815
;-----------------------------------------------------------------------------
3816
align 4
2288 clevermous 3817
putimage_init2bpp:
3818
        add     eax, ecx
3819
        push    ecx
3820
        add     ecx, 3
3821
        add     eax, 3
3822
        shr     ecx, 2
3823
        shr     eax, 2
3824
        sub     eax, ecx
3825
        pop     ecx
3826
        ret
2430 mario79 3827
;-----------------------------------------------------------------------------
2288 clevermous 3828
align 16
3829
putimage_get2bpp:
3830
        push    edx
3831
        mov     edx, [esp+8]
3832
        mov     al, [edx]
3833
        mov     ah, al
3834
        shr     al, 6
3835
        shl     ah, 2
3836
        jnz     .nonewbyte
3837
        lodsb
3838
        mov     ah, al
3839
        shr     al, 6
3840
        shl     ah, 2
3841
        add     ah, 1
3842
.nonewbyte:
3843
        mov     [edx], ah
3844
        mov     edx, [edx+4]
3845
        movzx   eax, al
9715 Doczom 3846
        mov     eax, [edx + eax*4]
2288 clevermous 3847
        pop     edx
3848
        ret     4
2430 mario79 3849
;-----------------------------------------------------------------------------
3850
align 4
2288 clevermous 3851
putimage_init4bpp:
3852
        add     eax, ecx
3853
        push    ecx
3854
        add     ecx, 1
9268 Doczom 3855
        inc     eax      ;add   eax, 1
2288 clevermous 3856
        shr     ecx, 1
3857
        shr     eax, 1
3858
        sub     eax, ecx
3859
        pop     ecx
3860
        ret
2430 mario79 3861
;-----------------------------------------------------------------------------
2288 clevermous 3862
align 16
3863
putimage_get4bpp:
3864
        push    edx
3865
        mov     edx, [esp+8]
3866
        add     byte [edx], 80h
3867
        jc      @f
3868
        movzx   eax, byte [edx+1]
3869
        mov     edx, [edx+4]
3870
        and     eax, 0x0F
9715 Doczom 3871
        mov     eax, [edx + eax*4]
2288 clevermous 3872
        pop     edx
3873
        ret     4
3874
@@:
3875
        movzx   eax, byte [esi]
3876
        add     esi, 1
3877
        mov     [edx+1], al
3878
        shr     eax, 4
3879
        mov     edx, [edx+4]
9715 Doczom 3880
        mov     eax, [edx + eax*4]
2288 clevermous 3881
        pop     edx
3882
        ret     4
2430 mario79 3883
;-----------------------------------------------------------------------------
3884
align 4
2288 clevermous 3885
putimage_init32bpp:
3886
        shl     eax, 2
3887
        ret
2430 mario79 3888
;-----------------------------------------------------------------------------
2288 clevermous 3889
align 16
3890
putimage_get32bpp:
3891
        lodsd
3892
        ret     4
2430 mario79 3893
;-----------------------------------------------------------------------------
3894
align 4
2288 clevermous 3895
putimage_init15bpp:
3896
putimage_init16bpp:
3897
        add     eax, eax
3898
        ret
2430 mario79 3899
;-----------------------------------------------------------------------------
2288 clevermous 3900
align 16
3901
putimage_get15bpp:
3902
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
3903
        push    ecx edx
3904
        movzx   eax, word [esi]
3905
        add     esi, 2
3906
        mov     ecx, eax
3907
        mov     edx, eax
3908
        and     eax, 0x1F
3909
        and     ecx, 0x1F shl 5
3910
        and     edx, 0x1F shl 10
3911
        shl     eax, 3
3912
        shl     ecx, 6
3913
        shl     edx, 9
3914
        or      eax, ecx
3915
        or      eax, edx
3916
        pop     edx ecx
3917
        ret     4
2430 mario79 3918
;-----------------------------------------------------------------------------
2288 clevermous 3919
align 16
3920
putimage_get16bpp:
3921
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
3922
        push    ecx edx
3923
        movzx   eax, word [esi]
3924
        add     esi, 2
3925
        mov     ecx, eax
3926
        mov     edx, eax
3927
        and     eax, 0x1F
3928
        and     ecx, 0x3F shl 5
3929
        and     edx, 0x1F shl 11
3930
        shl     eax, 3
3931
        shl     ecx, 5
3932
        shl     edx, 8
3933
        or      eax, ecx
3934
        or      eax, edx
3935
        pop     edx ecx
3936
        ret     4
2430 mario79 3937
;-----------------------------------------------------------------------------
3938
;align 4
2288 clevermous 3939
; eax x beginning
3940
; ebx y beginning
3941
; ecx x end
3942
        ; edx y end
3943
; edi color
2430 mario79 3944
;__sys_drawbar:
9926 Doczom 3945
;        mov     esi, [current_slot_idx]
3946
;        shl     esi, BSF sizeof.WDATA
3947
;        add     eax, [window_data+esi+WDATA.clientbox.left]
3948
;        add     ecx, [window_data+esi+WDATA.clientbox.left]
3949
;        add     ebx, [window_data+esi+WDATA.clientbox.top]
3950
;        add     edx, [window_data+esi+WDATA.clientbox.top]
2430 mario79 3951
;--------------------------------------
3952
;align 4
3953
;.forced:
3954
;        call    vesa20_drawbar
2407 mario79 3955
;        call    [draw_pointer]
3956
;        ret
2430 mario79 3957
;-----------------------------------------------------------------------------
2288 clevermous 3958
if used _rdtsc
3959
_rdtsc:
3960
        bt      [cpu_caps], CAPS_TSC
9910 Doczom 3961
        jnc     .ret_rdtsc
2288 clevermous 3962
        rdtsc
3963
        ret
9910 Doczom 3964
   .ret_rdtsc:
2288 clevermous 3965
        mov     edx, 0xffffffff
3966
        mov     eax, 0xffffffff
3967
        ret
3968
end if
3969
 
3970
sys_msg_board_str:
3971
 
3972
        pushad
3973
   @@:
3974
        cmp     [esi], byte 0
3975
        je      @f
3614 shikhin 3976
        mov     ebx, 1
3977
        movzx   ecx, byte [esi]
2288 clevermous 3978
        call    sys_msg_board
3979
        inc     esi
3980
        jmp     @b
3981
   @@:
3982
        popad
3983
        ret
3984
 
3985
sys_msg_board_byte:
3986
; in: al = byte to display
3987
; out: nothing
3988
; destroys: nothing
3989
        pushad
3990
        mov     ecx, 2
3991
        shl     eax, 24
3992
        jmp     @f
3993
 
3994
sys_msg_board_word:
3995
; in: ax = word to display
3996
; out: nothing
3997
; destroys: nothing
3998
        pushad
3999
        mov     ecx, 4
4000
        shl     eax, 16
4001
        jmp     @f
4002
 
4003
sys_msg_board_dword:
4004
; in: eax = dword to display
4005
; out: nothing
4006
; destroys: nothing
4007
        pushad
4008
        mov     ecx, 8
4009
@@:
4010
        push    ecx
4011
        rol     eax, 4
4012
        push    eax
4013
        and     al, 0xF
4014
        cmp     al, 10
4015
        sbb     al, 69h
4016
        das
3614 shikhin 4017
        mov     cl, al
4018
        xor     ebx, ebx
4019
        inc     ebx
2288 clevermous 4020
        call    sys_msg_board
4021
        pop     eax
4022
        pop     ecx
4023
        loop    @b
4024
        popad
4025
        ret
4026
 
3392 clevermous 4027
msg_board_data_size = 65536 ; Must be power of two
4028
 
2288 clevermous 4029
uglobal
6501 pathoswith 4030
msg_board_data  rb  msg_board_data_size
4031
msg_board_count dd  ?
2288 clevermous 4032
endg
4033
 
6501 pathoswith 4034
iglobal
4035
msg_board_pos   dd  42*6*65536+10 ; for printing debug output on the screen
4036
endg
4037
 
2288 clevermous 4038
sys_msg_board:
6501 pathoswith 4039
; ebx=1 -> write, cl = byte to write
4040
; ebx=2 -> read, ecx=0 -> no data, ecx=1 -> data in al
4041
        push    eax ebx
3614 shikhin 4042
        mov     eax, ebx
4043
        mov     ebx, ecx
2288 clevermous 4044
        mov     ecx, [msg_board_count]
4045
        cmp     eax, 1
6501 pathoswith 4046
        jne     .read
2288 clevermous 4047
 
4048
if defined debug_com_base
4049
        push    dx ax
6501 pathoswith 4050
@@: ; wait for empty transmit register
2288 clevermous 4051
        mov     dx, debug_com_base+5
4052
        in      al, dx
4053
        test    al, 1 shl 5
4054
        jz      @r
4055
        mov     dx, debug_com_base      ; Output the byte
4056
        mov     al, bl
4057
        out     dx, al
4058
        pop     ax dx
4059
end if
4060
 
4061
        mov     [msg_board_data+ecx], bl
3777 yogev_ezra 4062
        cmp     byte [debug_direct_print], 1
6501 pathoswith 4063
        jnz     .end
3507 clevermous 4064
        pusha
4065
        lea     edx, [msg_board_data+ecx]
4066
        mov     ecx, 0x40FFFFFF
4067
        mov     ebx, [msg_board_pos]
4068
        mov     edi, 1
9268 Doczom 4069
        mov     esi, edi ;1
3507 clevermous 4070
        call    dtext
4071
        popa
4072
        add     word [msg_board_pos+2], 6
6501 pathoswith 4073
        cmp     word [msg_board_pos+2], 105*6
4074
        jnc     @f
3507 clevermous 4075
        cmp     bl, 10
6501 pathoswith 4076
        jnz     .end
4077
@@:
4078
        mov     word [msg_board_pos+2], 42*6
3507 clevermous 4079
        add     word [msg_board_pos], 10
6501 pathoswith 4080
        mov     eax, [_display.height]
4081
        sub     eax, 10
4082
        cmp     ax, word [msg_board_pos]
4083
        jnc     @f
3507 clevermous 4084
        mov     word [msg_board_pos], 10
4085
@@:
3534 clevermous 4086
        pusha
6501 pathoswith 4087
        mov     eax, [msg_board_pos]
4088
        movzx   ebx, ax
4089
        shr     eax, 16
4090
        mov     edx, 105*6
4091
        xor     ecx, ecx
4092
        mov     edi, 1
4093
        mov     esi, 9
4094
@@:
4095
        call    hline
4096
        inc     ebx
4097
        dec     esi
4098
        jnz     @b
3534 clevermous 4099
        popa
6501 pathoswith 4100
.end:
2288 clevermous 4101
        inc     ecx
3392 clevermous 4102
        and     ecx, msg_board_data_size - 1
2288 clevermous 4103
        mov     [msg_board_count], ecx
6501 pathoswith 4104
.ret:
3614 shikhin 4105
        pop     ebx eax
2288 clevermous 4106
        ret
6501 pathoswith 4107
 
4108
.read:
2288 clevermous 4109
        cmp     eax, 2
6501 pathoswith 4110
        jne     .ret
9897 dunkaist 4111
        add     esp, 8  ; returning data in ebx and eax, so no need to restore them
2288 clevermous 4112
        test    ecx, ecx
9897 dunkaist 4113
        jnz     @f
4114
        mov     [esp + SYSCALL_STACK.eax], ecx
4115
        mov     [esp + SYSCALL_STACK.ebx], ecx
4116
        ret
4117
@@:
2288 clevermous 4118
        mov     eax, msg_board_data+1
4119
        mov     ebx, msg_board_data
4120
        movzx   edx, byte [ebx]
4121
        call    memmove
4122
        dec     [msg_board_count]
9897 dunkaist 4123
        mov     [esp + SYSCALL_STACK.eax], edx
4124
        mov     [esp + SYSCALL_STACK.ebx], 1
2288 clevermous 4125
        ret
4126
 
4127
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4128
;; 61 sys function.                                                ;;
4129
;; in eax=61,ebx in [1..3]                                         ;;
4130
;; out eax                                                         ;;
4131
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4132
iglobal
4133
align 4
4134
f61call:
4135
           dd sys_gs.1   ; resolution
4136
           dd sys_gs.2   ; bits per pixel
4137
           dd sys_gs.3   ; bytes per scanline
4138
endg
4139
 
4140
 
4141
align 4
4142
 
4143
sys_gs:                         ; direct screen access
4144
        dec     ebx
4145
        cmp     ebx, 2
4146
        ja      .not_support
9715 Doczom 4147
        jmp     dword [f61call + ebx*4]
2288 clevermous 4148
.not_support:
9831 dunkaist 4149
        or      [esp + SYSCALL_STACK.eax], dword -1
2288 clevermous 4150
        ret
4151
 
4152
 
4153
.1:                             ; resolution
5350 serge 4154
        mov     eax, [_display.width]
2288 clevermous 4155
        shl     eax, 16
5350 serge 4156
        mov     ax, word [_display.height]
9831 dunkaist 4157
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4158
        ret
4159
.2:                             ; bits per pixel
5154 hidnplayr 4160
        mov     eax, [_display.bits_per_pixel]
9831 dunkaist 4161
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4162
        ret
4163
.3:                             ; bytes per scanline
5351 serge 4164
        mov     eax, [_display.lfb_pitch]
9831 dunkaist 4165
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4166
        ret
4167
 
4168
align 4
4169
syscall_getscreensize:                  ; GetScreenSize
5350 serge 4170
        mov     ax, word [_display.width]
4171
        dec     ax
2288 clevermous 4172
        shl     eax, 16
5350 serge 4173
        mov     ax, word [_display.height]
4174
        dec     ax
9831 dunkaist 4175
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4176
        ret
4700 mario79 4177
;-----------------------------------------------------------------------------
2288 clevermous 4178
align 4
4713 mario79 4179
syscall_cdaudio:
4711 mario79 4180
; ECX - position of CD/DVD-drive
4181
; from 0=Primary Master to 3=Secondary Slave for first IDE contr.
4182
; from 4=Primary Master to 7=Secondary Slave for second IDE contr.
4183
; from 8=Primary Master to 11=Secondary Slave for third IDE contr.
4184
        cmp     ecx, 11
4185
        ja      .exit
4186
 
4187
        mov     eax, ecx
4188
        shr     eax, 2
4189
        lea     eax, [eax*5]
9715 Doczom 4190
        mov     al, [eax + DRIVE_DATA + 1]
4711 mario79 4191
 
4192
        push    ecx ebx
4193
        mov     ebx, ecx
4194
        and     ebx, 11b
4195
        shl     ebx, 1
4196
        mov     cl, 6
4197
        sub     cl, bl
4198
        shr     al, cl
4199
        test    al, 2 ; it's not an ATAPI device
4200
        pop     ebx ecx
4201
 
4202
        jz      .exit
4203
 
4700 mario79 4204
        cmp     ebx, 4
4205
        je      .eject
2288 clevermous 4206
 
4207
        cmp     ebx, 5
4700 mario79 4208
        je      .load
4711 mario79 4209
;--------------------------------------
4210
.exit:
4700 mario79 4211
        ret
4212
;--------------------------------------
2288 clevermous 4213
.load:
4214
        call    .reserve
4215
        call    LoadMedium
4216
        jmp     .free
4700 mario79 4217
;--------------------------------------
2288 clevermous 4218
.eject:
4219
        call    .reserve
4220
        call    clear_CD_cache
4221
        call    allow_medium_removal
4222
        call    EjectMedium
4223
        jmp     .free
4700 mario79 4224
;--------------------------------------
2288 clevermous 4225
.reserve:
4226
        call    reserve_cd
4700 mario79 4227
 
4228
        mov     ebx, ecx
4229
        inc     ebx
4230
        mov     [cdpos], ebx
4231
 
2288 clevermous 4232
        mov     eax, ecx
4233
        shr     eax, 1
4234
        and     eax, 1
4235
        inc     eax
6464 pathoswith 4236
        mov     [ChannelNumber], al
2288 clevermous 4237
        mov     eax, ecx
4238
        and     eax, 1
4239
        mov     [DiskNumber], al
4240
        call    reserve_cd_channel
4241
        ret
4700 mario79 4242
;--------------------------------------
2288 clevermous 4243
.free:
4244
        call    free_cd_channel
4245
        and     [cd_status], 0
4246
        ret
2511 mario79 4247
;-----------------------------------------------------------------------------
2288 clevermous 4248
align 4
2511 mario79 4249
syscall_getpixel_WinMap:                       ; GetPixel WinMap
5350 serge 4250
        cmp     ebx, [_display.width]
4251
        jb      @f
4252
        cmp     ecx, [_display.height]
4253
        jb      @f
2511 mario79 4254
        xor     eax, eax
4255
        jmp     .store
4256
;--------------------------------------
4257
align 4
4258
@@:
4259
        mov     eax, [d_width_calc_area + ecx*4]
5351 serge 4260
        add     eax, [_display.win_map]
2511 mario79 4261
        movzx   eax, byte[eax+ebx]        ; get value for current point
4262
;--------------------------------------
4263
align 4
4264
.store:
9831 dunkaist 4265
        mov     [esp + SYSCALL_STACK.eax], eax
2511 mario79 4266
        ret
4267
;-----------------------------------------------------------------------------
4268
align 4
2288 clevermous 4269
syscall_getpixel:                       ; GetPixel
5350 serge 4270
        mov     ecx, [_display.width]
2288 clevermous 4271
        xor     edx, edx
4272
        mov     eax, ebx
4273
        div     ecx
4274
        mov     ebx, edx
4275
        xchg    eax, ebx
2430 mario79 4276
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
2288 clevermous 4277
        call    dword [GETPIXEL]; eax - x, ebx - y
9831 dunkaist 4278
        mov     [esp + SYSCALL_STACK.eax], ecx
2288 clevermous 4279
        ret
2509 mario79 4280
;-----------------------------------------------------------------------------
2288 clevermous 4281
align 4
4282
syscall_getarea:
4283
;eax = 36
4284
;ebx = pointer to bufer for img BBGGRRBBGGRR...
4285
;ecx = [size x]*65536 + [size y]
4286
;edx = [start x]*65536 + [start y]
4287
        pushad
4288
        mov     edi, ebx
4289
        mov     eax, edx
4290
        shr     eax, 16
4291
        mov     ebx, edx
4292
        and     ebx, 0xffff
4293
        dec     eax
4294
        dec     ebx
4295
     ; eax - x, ebx - y
4296
        mov     edx, ecx
4297
 
4298
        shr     ecx, 16
4299
        and     edx, 0xffff
4300
        mov     esi, ecx
4301
     ; ecx - size x, edx - size y
4302
 
4303
        mov     ebp, edx
8598 rgimad 4304
        lea     ebp, [ebp*3]
4305
        imul    ebp, esi
4306
        stdcall is_region_userspace, edi, ebp
9045 dunkaist 4307
        jnz     .exit
8598 rgimad 4308
 
4309
        mov     ebp, edx
2288 clevermous 4310
        dec     ebp
4311
        lea     ebp, [ebp*3]
4312
 
4313
        imul    ebp, esi
4314
 
4315
        mov     esi, ecx
4316
        dec     esi
4317
        lea     esi, [esi*3]
4318
 
4319
        add     ebp, esi
4320
        add     ebp, edi
4321
 
4322
        add     ebx, edx
2509 mario79 4323
;--------------------------------------
4324
align 4
2288 clevermous 4325
.start_y:
4326
        push    ecx edx
2509 mario79 4327
;--------------------------------------
4328
align 4
2288 clevermous 4329
.start_x:
4330
        push    eax ebx ecx
4331
        add     eax, ecx
4332
 
2430 mario79 4333
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
2288 clevermous 4334
        call    dword [GETPIXEL]; eax - x, ebx - y
4335
 
4336
        mov     [ebp], cx
4337
        shr     ecx, 16
4338
        mov     [ebp+2], cl
4339
 
4340
        pop     ecx ebx eax
4341
        sub     ebp, 3
4342
        dec     ecx
4343
        jnz     .start_x
4344
        pop     edx ecx
4345
        dec     ebx
4346
        dec     edx
4347
        jnz     .start_y
8598 rgimad 4348
 
4349
.exit:
2288 clevermous 4350
        popad
4351
        ret
2509 mario79 4352
;-----------------------------------------------------------------------------
8675 rgimad 4353
 
2288 clevermous 4354
align 4
4355
syscall_threads:                        ; CreateThreads
4356
;
4105 Serge 4357
;   ecx=thread entry point
4358
;   edx=thread stack pointer
2288 clevermous 4359
;
4360
; on return : eax = pid
4105 Serge 4361
        xor     ebx, ebx
2288 clevermous 4362
        call    new_sys_threads
4363
 
9831 dunkaist 4364
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4365
        ret
4366
 
2438 mario79 4367
;------------------------------------------------------------------------------
2288 clevermous 4368
align 4
2438 mario79 4369
calculate_fast_getting_offset_for_WinMapAddress:
4370
; calculate data area for fast getting offset to _WinMapAddress
2446 mario79 4371
        xor     eax, eax
2438 mario79 4372
        mov     ecx, [_display.height]
4373
        mov     edi, d_width_calc_area
4374
        cld
4375
@@:
4376
        stosd
4377
        add     eax, [_display.width]
4378
        dec     ecx
4379
        jnz     @r
4380
        ret
4381
;------------------------------------------------------------------------------
4382
align 4
2480 mario79 4383
calculate_fast_getting_offset_for_LFB:
4384
; calculate data area for fast getting offset to LFB
4385
        xor     eax, eax
4386
        mov     ecx, [_display.height]
4387
        mov     edi, BPSLine_calc_area
4388
        cld
4389
@@:
4390
        stosd
5351 serge 4391
        add     eax, [_display.lfb_pitch]
2480 mario79 4392
        dec     ecx
4393
        jnz     @r
4394
        ret
4395
;------------------------------------------------------------------------------
4396
align 4
2288 clevermous 4397
set_screen:
2654 mario79 4398
; in:
4399
; eax - new Screen_Max_X
4400
; ecx - new BytesPerScanLine
4401
; edx - new Screen_Max_Y
2288 clevermous 4402
 
4403
        pushfd
4404
        cli
4405
 
5351 serge 4406
        mov     [_display.lfb_pitch], ecx
2288 clevermous 4407
 
4408
        mov     [screen_workarea.right], eax
4409
        mov     [screen_workarea.bottom], edx
4410
 
4411
        push    ebx
4412
        push    esi
4413
        push    edi
4414
 
4415
        pushad
4416
 
2654 mario79 4417
        cmp     [do_not_touch_winmap], 1
4418
        je      @f
4419
 
5351 serge 4420
        stdcall kernel_free, [_display.win_map]
2288 clevermous 4421
 
4422
        mov     eax, [_display.width]
4423
        mul     [_display.height]
5351 serge 4424
        mov     [_display.win_map_size], eax
2288 clevermous 4425
 
4426
        stdcall kernel_alloc, eax
5351 serge 4427
        mov     [_display.win_map], eax
2288 clevermous 4428
        test    eax, eax
4429
        jz      .epic_fail
2654 mario79 4430
; store for f.18.24
4431
        mov     eax, [_display.width]
4432
        mov     [display_width_standard], eax
2288 clevermous 4433
 
2654 mario79 4434
        mov     eax, [_display.height]
4435
        mov     [display_height_standard], eax
4436
@@:
2438 mario79 4437
        call    calculate_fast_getting_offset_for_WinMapAddress
2545 mario79 4438
; for Qemu or non standart video cards
2991 Serge 4439
; Unfortunately [BytesPerScanLine] does not always
2545 mario79 4440
;                             equal to [_display.width] * [ScreenBPP] / 8
4441
        call    calculate_fast_getting_offset_for_LFB
2288 clevermous 4442
        popad
4443
 
4444
        call    repos_windows
4445
        xor     eax, eax
4446
        xor     ebx, ebx
5350 serge 4447
        mov     ecx, [_display.width]
4448
        mov     edx, [_display.height]
4449
        dec     ecx
4450
        dec     edx
2288 clevermous 4451
        call    calculatescreen
4452
        pop     edi
4453
        pop     esi
4454
        pop     ebx
4455
 
4456
        popfd
4457
        ret
4458
 
4459
.epic_fail:
4460
        hlt                     ; Houston, we've had a problem
4461
 
4462
; --------------- APM ---------------------
4463
uglobal
4464
apm_entry       dp      0
4465
apm_vf          dd      0
4466
endg
4467
 
4468
align 4
4469
sys_apm:
4470
        xor     eax, eax
4471
        cmp     word [apm_vf], ax       ; Check APM BIOS enable
4472
        jne     @f
4473
        inc     eax
4474
        or      dword [esp + 44], eax   ; error
4475
        add     eax, 7
9911 Doczom 4476
        mov     dword [esp + SYSCALL_STACK.eax], eax   ; 32-bit protected-mode interface not supported
2288 clevermous 4477
        ret
4478
 
4479
@@:
4480
;       xchg    eax, ecx
4481
;       xchg    ebx, ecx
4482
 
4483
        cmp     dx, 3
4484
        ja      @f
4485
        and     [esp + 44], byte 0xfe    ; emulate func 0..3 as func 0
4486
        mov     eax, [apm_vf]
9911 Doczom 4487
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4488
        shr     eax, 16
9911 Doczom 4489
        mov     [esp + SYSCALL_STACK.ecx], eax
2288 clevermous 4490
        ret
4491
 
4492
@@:
4493
 
4494
        mov     esi, [master_tab+(OS_BASE shr 20)]
4495
        xchg    [master_tab], esi
4496
        push    esi
4497
        mov     edi, cr3
4498
        mov     cr3, edi                ;flush TLB
4499
 
4500
        call    pword [apm_entry]       ;call APM BIOS
4501
 
4502
        xchg    eax, [esp]
4503
        mov     [master_tab], eax
4504
        mov     eax, cr3
4505
        mov     cr3, eax
4506
        pop     eax
4507
 
9911 Doczom 4508
        mov     [esp + SYSCALL_STACK.edi], edi
4509
        mov     [esp + SYSCALL_STACK.esi], esi
4510
        mov     [esp + SYSCALL_STACK.ebx], ebx
4511
        mov     [esp + SYSCALL_STACK.edx], edx
4512
        mov     [esp + SYSCALL_STACK.ecx], ecx
4513
        mov     [esp + SYSCALL_STACK.eax], eax
2288 clevermous 4514
        setc    al
4515
        and     [esp + 44], byte 0xfe
4516
        or      [esp + 44], al
4517
        ret
4518
; -----------------------------------------
4519
 
4520
align 4
4521
undefined_syscall:                      ; Undefined system call
9831 dunkaist 4522
        mov     [esp + SYSCALL_STACK.eax], dword -1
2288 clevermous 4523
        ret
4524
 
8160 rgimad 4525
align 4
8962 Boppan 4526
; @brief Check if given memory region lays in lower 2gb (userspace memory) or not
4527
; @param base Base address of region
4528
; @param len Lenght of region
4529
; @return ZF = 1 if region in userspace memory,
4530
;         ZF = 0 otherwise
8329 rgimad 4531
proc is_region_userspace stdcall, base:dword, len:dword
9045 dunkaist 4532
        push    eax
8329 rgimad 4533
        mov     eax, [base]
8216 rgimad 4534
 
9045 dunkaist 4535
        cmp     eax, OS_BASE-1
4536
        ja      @f              ; zf
8216 rgimad 4537
 
8329 rgimad 4538
        add     eax, [len]
9045 dunkaist 4539
        jc      @f              ; zf
8160 rgimad 4540
        cmp     eax, OS_BASE
9045 dunkaist 4541
        ja      @f              ; zf
2288 clevermous 4542
 
9045 dunkaist 4543
        cmp     eax, eax        ; ZF
8160 rgimad 4544
@@:
9045 dunkaist 4545
        pop     eax
8160 rgimad 4546
        ret
8329 rgimad 4547
endp
8160 rgimad 4548
 
9823 dunkaist 4549
align 4
4550
; @brief Check whether given string lays in userspace memory, i.e. below OS_BASE
4551
; @param base Base address of string
4552
; @return ZF = 1 if string in userspace memory,
4553
;         zf = 0 otherwise
4554
proc is_string_userspace stdcall, base:dword
4555
        push    eax ecx edi
4556
        xor     eax, eax
4557
        mov     edi, [base]
4558
 
4559
        mov     ecx, OS_BASE-1
4560
        sub     ecx, edi
4561
        jb      .done           ; zf
4562
        inc     ecx
4563
        cmp     ecx, 0x10000    ; don't allow strings larger than 64k?
4564
        jbe     @f
4565
        mov     ecx, 0x10000
4566
@@:
4567
        repnz scasb
4568
.done:
4569
        pop     edi ecx eax
4570
        ret
4571
endp
4572
 
3627 Serge 4573
if ~ lang eq sp
4574
diff16 "end of .text segment",0,$
4575
end if
4576
 
2288 clevermous 4577
include "data32.inc"
4578
 
4579
__REV__ = __REV
4580
 
3341 yogev_ezra 4581
if ~ lang eq sp
2288 clevermous 4582
diff16 "end of kernel code",0,$
3287 esevece 4583
end if