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