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