Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
709 diamond 3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;                                                              ;;
7
;;  MenuetOS process management, protected ring3                ;;
8
;;                                                              ;;
9
;;  Distributed under GPL. See file COPYING for details.        ;;
10
;;  Copyright 2003 Ville Turjanmaa                              ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 13
 
593 mikedld 14
$Revision: 788 $
15
 
16
 
389 serge 17
align 4
1 ha 18
idtreg:
19
     dw   8*0x41-1
20
     dd   idts+8
21
 
22
build_interrupt_table:
23
 
759 Rus 24
	mov    edi, idts+8
25
	mov    esi, sys_int
26
	mov    ecx, 0x40
6 poddubny 27
     @@:
759 Rus 28
	lodsd
29
	mov    [edi],	ax	     ; lower part of offset
30
	mov    [edi+2], word os_code ; segment selector
31
	mov	ax, word 10001110b shl 8	; type: interrupt gate
32
	mov	[edi+4], eax
33
	add    edi, 8
34
	loop	@b
164 serge 35
 
759 Rus 36
	;mov    edi,8*0x40+idts+8
37
	mov	dword [edi], (i40 and 0xFFFF) or (os_code shl 16)
38
	mov	dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000)
39
						; type: trap gate
40
	ret
1 ha 41
 
42
iglobal
656 mikedld 43
 
759 Rus 44
  msg_sel_ker	db "kernel", 0
45
  msg_sel_app	db "application", 0
656 mikedld 46
 
1 ha 47
  sys_int:
164 serge 48
    dd e0,debug_exc,e2,e3
49
    dd e4,e5,e6,e7
50
    dd e8,e9,e10,e11
51
    dd e12,e13,page_fault_handler,e15
52
 
168 serge 53
    dd except_16, e17,e18, except_19
54
    times 12 dd unknown_interrupt
1 ha 55
 
788 diamond 56
    dd	 irq0, irq_serv.irq_1, irq_serv.irq_2
566 serge 57
if USE_COM_IRQ
759 Rus 58
    dd	 irq_serv.irq_3, irq_serv.irq_4
566 serge 59
else
759 Rus 60
    dd	 p_irq3, p_irq4
566 serge 61
end if
759 Rus 62
    dd	 irq_serv.irq_5,  p_irq6,	  irq_serv.irq_7
63
    dd	 irq_serv.irq_8,  irq_serv.irq_9, irq_serv.irq_10
64
    dd	 irq_serv.irq_11, irq_serv.irq_12,irqD ,p_irq14,p_irq15
1 ha 65
 
66
    times 16 dd unknown_interrupt
67
 
759 Rus 68
    dd	 i40
1 ha 69
endg
70
 
40 halyavin 71
macro save_ring3_context
72
{
58 mario79 73
    pushad
40 halyavin 74
}
75
macro restore_ring3_context
76
{
58 mario79 77
    popad
40 halyavin 78
}
79
 
8 poddubny 80
; simply return control to interrupted process
81
unknown_interrupt:
82
     iret
1 ha 83
 
22 poddubny 84
macro exc_wo_code [num]
8 poddubny 85
{
86
  forward
87
  e#num :
40 halyavin 88
      save_ring3_context
20 mario79 89
      mov bl, num
90
      jmp exc_c
8 poddubny 91
}
1 ha 92
 
22 poddubny 93
macro exc_w_code [num]
94
{
95
  forward
96
  e#num :
97
      add esp, 4
40 halyavin 98
      save_ring3_context
22 poddubny 99
      mov bl, num
100
      jmp exc_c
101
}
102
 
709 diamond 103
exc_wo_code 0, 2, 3, 4, 5, 6, 9, 15, 18
22 poddubny 104
exc_w_code 8, 10, 11, 12, 13, 14, 17
105
 
8 poddubny 106
exc_c:
759 Rus 107
	mov   ax, app_data  ;исключение
108
	mov   ds, ax	    ;загрузим правильные значени
109
	mov   es, ax	    ;в регистры
1 ha 110
 
709 diamond 111
; redirect to V86 manager? (EFLAGS & 0x20000) != 0?
759 Rus 112
	test	byte [esp+20h+8+2], 2
113
	jnz	v86_exc_c
709 diamond 114
 
40 halyavin 115
; test if debugging
759 Rus 116
	cli
117
	mov   eax, [current_slot]
118
	mov   eax, [eax+APPDATA.debugger_slot]
119
	test  eax, eax
120
	jnz   .debug
121
	sti
40 halyavin 122
; not debuggee => say error and terminate
759 Rus 123
	movzx eax, bl
124
	mov   [error_interrupt], eax
125
	call  show_error_parameters
658 Ghost 126
	add   esp, 0x20
759 Rus 127
	mov   edx, [TASK_BASE]
128
	mov   [edx + TASKDATA.state], byte 4
164 serge 129
 
759 Rus 130
	jmp   change_task
1 ha 131
 
40 halyavin 132
.debug:
133
; we are debugged process, notify debugger and suspend ourself
134
; eax=debugger PID
759 Rus 135
	cld
136
	movzx ecx, bl
137
	push  ecx
138
	mov   ecx, [TASK_BASE]
139
	push  dword [ecx+TASKDATA.pid]	  ; PID of current process
140
	push  12
141
	pop   ecx
142
	push  1        ; 1=exception
143
	call  debugger_notify
144
	pop   ecx
145
	pop   ecx
146
	pop   ecx
147
	mov   edx, [TASK_BASE]
148
	mov   byte [edx+TASKDATA.state], 1	  ; suspended
149
	call  change_task
150
	restore_ring3_context
151
	iretd
1 ha 152
 
153
iglobal
658 Ghost 154
	hexletters	db '0123456789ABCDEF'
759 Rus 155
	error_interrupt dd  -1
1 ha 156
endg
157
 
658 Ghost 158
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1 ha 159
show_error_parameters:
656 mikedld 160
    mov eax,[CURRENT_TASK]
161
    shl eax, 5
162
    DEBUGF  1, "K : Process - forced terminate PID: %x\n", [CURRENT_TASK + TASKDATA.pid + eax]
163
    DEBUGF  1, "K : Exception : %x Error : xxxxxxxx\n", [error_interrupt]
164
    DEBUGF  1, "K : EAX : %x EBX : %x ECX : %x\n", [esp + 0x20], [esp - 12 + 0x20], [esp - 4 + 0x20]
165
    DEBUGF  1, "K : EDX : %x ESI : %x EDI : %x\n", [esp - 8 + 0x20], [esp - 24 + 0x20], [esp - 28 + 0x20]
166
    DEBUGF  1, "K : EBP : %x EIP : %x ", [esp - 20 + 0x20], [esp + 4 + 0x20]
164 serge 167
 
656 mikedld 168
    mov eax, [esp + 8 + 0x20]
169
    mov edi, msg_sel_app
170
    mov ebx, [esp + 16 + 0x20]
171
    cmp eax, app_code
759 Rus 172
    je	@f
656 mikedld 173
    mov edi, msg_sel_ker
174
    mov ebx, [esp - 16 + 0x20]
175
@@:
658 Ghost 176
    DEBUGF  1, "ESP : %x\nK : Flags : %x CS : %x (%s)\n", ebx, [esp + 12 + 0x20], eax, edi
177
    ret
178
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
164 serge 179
 
16 poddubny 180
 
6 poddubny 181
; irq1  ->  hid/keyboard.inc
10 poddubny 182
macro irqh [num]
8 poddubny 183
{
184
  forward
185
  p_irq#num :
186
     mov   edi, num
788 diamond 187
     jmp   irqhandler
8 poddubny 188
}
1 ha 189
 
769 Rus 190
irqh 2,3,4,5,7,8,9,10,11
1 ha 191
 
11 poddubny 192
 
193
p_irq6:
40 halyavin 194
     save_ring3_context
465 serge 195
     mov   ax, app_data  ;os_data
11 poddubny 196
     mov   ds, ax
197
     mov   es, ax
198
     call  fdc_irq
33 mario79 199
     call  ready_for_next_irq
40 halyavin 200
     restore_ring3_context
33 mario79 201
     iret
15 poddubny 202
 
203
 
160 diamond 204
p_irq14:
759 Rus 205
	save_ring3_context
206
	mov	ax, app_data  ;os_data
207
	mov	ds, ax
208
	mov	es, ax
209
	mov	byte [BOOT_VAR + 0x48E], 0xFF
210
	call	[irq14_func]
211
	call	ready_for_next_irq_1
212
	restore_ring3_context
213
	iret
160 diamond 214
p_irq15:
759 Rus 215
	save_ring3_context
216
	mov	ax, app_data  ;os_data
217
	mov	ds, ax
218
	mov	es, ax
219
	mov	byte [BOOT_VAR + 0x48E], 0xFF
220
	call	[irq15_func]
221
	call	ready_for_next_irq_1
222
	restore_ring3_context
223
	iret
160 diamond 224
 
33 mario79 225
ready_for_next_irq:
226
     mov    [check_idle_semaphore],5
227
     mov   al, 0x20
228
     out   0x20, al
229
     ret
230
 
231
ready_for_next_irq_1:
232
     mov    [check_idle_semaphore],5
233
     mov   al, 0x20
234
     out    0xa0,al
235
     out   0x20, al
236
     ret
237
 
6 poddubny 238
irqD:
40 halyavin 239
     save_ring3_context
465 serge 240
     mov   ax, app_data  ;os_data
8 poddubny 241
     mov   ds, ax
242
     mov   es, ax
164 serge 243
 
6 poddubny 244
     mov   dx,0xf0
245
     mov   al,0
246
     out   dx,al
1 ha 247
 
6 poddubny 248
     mov   dx,0xa0
249
     mov   al,0x20
250
     out   dx,al
251
     mov   dx,0x20
40 halyavin 252
     out   dx,al
253
 
254
     restore_ring3_context
164 serge 255
 
8 poddubny 256
     iret
1 ha 257
 
258
 
259
irqhandler:
260
 
759 Rus 261
     mov    esi,edi	     ; 1
262
     shl    esi,6	     ; 1
1 ha 263
     add    esi,irq00read    ; 1
759 Rus 264
     shl    edi,12	     ; 1
381 serge 265
     add    edi,IRQ_SAVE
75 diamond 266
     mov    ecx,16
1 ha 267
 
268
   irqnewread:
75 diamond 269
     dec    ecx
270
     js     irqover
1 ha 271
 
759 Rus 272
     movzx  edx, word [esi]	   ; 2+
1 ha 273
 
759 Rus 274
     test   edx, edx		   ; 1
1 ha 275
     jz     irqover
276
 
277
 
759 Rus 278
     mov    ebx, [edi]		   ; address of begin of buffer in edi      ; + 0x0 dword - data size
279
     mov    eax, 4000							    ; + 0x4 dword - data begin offset
280
     cmp    ebx, eax
1 ha 281
     je     irqfull
759 Rus 282
     add    ebx, [edi + 0x4]	   ; add data size to data begin offset
283
     cmp    ebx, eax		   ; if end of buffer, begin cycle again
284
     jb     @f
1 ha 285
 
759 Rus 286
     xor    ebx, ebx
1 ha 287
 
759 Rus 288
  @@:
289
     add    ebx, edi
290
     movzx  eax, byte[esi + 3]	   ; get type of data being received 1 - byte, 2 - word
291
     dec    eax
292
     jz     irqbyte
293
     dec    eax
294
     jnz    noirqword
1 ha 295
 
759 Rus 296
     in     ax,dx
297
     cmp    ebx, 3999		   ; check for address odd in the end of buffer
298
     jne    .odd
299
     mov    [ebx + 0x10], ax
300
     jmp    .add_size
301
  .odd:
302
     mov    [ebx + 0x10], al	   ; I could make mistake here :)
303
     mov    [edi + 0x10], ah
304
  .add_size:
305
     add    dword [edi], 2
306
     jmp    nextport
1 ha 307
 
308
 
759 Rus 309
  irqbyte:
310
     in     al,dx
311
     mov    [ebx + 0x10],al
312
     inc    dword [edi]
313
  nextport:
1 ha 314
     add    esi,4
315
     jmp    irqnewread
316
 
759 Rus 317
 
1 ha 318
   noirqword:
319
   irqfull:
320
   irqover:
321
 
322
     ret
323
 
324
 
325
 
326
set_application_table_status:
759 Rus 327
	push eax
1 ha 328
 
759 Rus 329
	mov  eax,[CURRENT_TASK]
330
	shl  eax, 5
331
	add  eax,CURRENT_TASK+TASKDATA.pid
332
	mov  eax,[eax]
1 ha 333
 
759 Rus 334
	mov  [application_table_status],eax
1 ha 335
 
759 Rus 336
	pop  eax
1 ha 337
 
759 Rus 338
	ret
1 ha 339
 
340
 
341
clear_application_table_status:
759 Rus 342
	push eax
1 ha 343
 
759 Rus 344
	mov  eax,[CURRENT_TASK]
345
	shl  eax, 5
346
	add  eax,CURRENT_TASK+TASKDATA.pid
347
	mov  eax,[eax]
1 ha 348
 
759 Rus 349
	cmp  eax,[application_table_status]
350
	jne  apptsl1
351
	mov  [application_table_status],0
1 ha 352
      apptsl1:
353
 
759 Rus 354
	pop  eax
1 ha 355
 
759 Rus 356
	ret
1 ha 357
 
358
sys_resize_app_memory:
759 Rus 359
	; eax = 1 - resize
360
	;     ebx = new amount of memory
1 ha 361
 
759 Rus 362
	cmp    eax,1
363
	jne    .no_application_mem_resize
1 ha 364
 
759 Rus 365
	stdcall new_mem_resize, ebx
366
	mov [esp+36], eax
367
	ret
1 ha 368
 
164 serge 369
.no_application_mem_resize:
759 Rus 370
	ret
1 ha 371
 
372
sys_threads:
373
 
374
; eax=1 create thread
375
;
376
;   ebx=thread start
377
;   ecx=thread stack value
378
;
379
; on return : eax = pid
380
jmp new_sys_threads
381
 
382
iglobal
759 Rus 383
  process_terminating	db 'K : Process - terminating',13,10,0
384
  process_terminated	db 'K : Process - done',13,10,0
385
  msg_obj_destroy	db 'K : destroy app object',13,10,0
1 ha 386
endg
387
 
329 serge 388
; param
389
;  esi= slot
1 ha 390
 
391
terminate: ; terminate application
392
 
759 Rus 393
	   .slot equ esp   ;locals
329 serge 394
 
759 Rus 395
	   push   esi	   ;save .slot
334 serge 396
 
759 Rus 397
	   shl esi, 8
398
	   cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
399
	   jne @F
400
	   pop	  esi
401
	   shl	  esi, 5
402
	   mov	  [CURRENT_TASK+esi+TASKDATA.state], 9
403
	   ret
334 serge 404
@@:
759 Rus 405
	   ;mov    esi,process_terminating
406
	   ;call   sys_msg_board_str
407
	   DEBUGF 1,"%s",process_terminating
40 halyavin 408
@@:
759 Rus 409
	   cli
410
	   cmp	 [application_table_status],0
411
	   je	 term9
412
	   sti
413
	   call  change_task
414
	   jmp	 @b
329 serge 415
term9:
759 Rus 416
	   call  set_application_table_status
1 ha 417
 
709 diamond 418
; if the process is in V86 mode...
759 Rus 419
	mov	eax, [.slot]
420
	shl	eax, 8
421
	mov	esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
422
	add	esi, RING0_STACK_SIZE
423
	cmp	[eax+SLOT_BASE+APPDATA.saved_esp0], esi
424
	jz	.nov86
709 diamond 425
; ...it has page directory for V86 mode
759 Rus 426
	mov	esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
427
	mov	ecx, [esi+4]
428
	mov	[eax+SLOT_BASE+APPDATA.dir_table], ecx
709 diamond 429
; ...and I/O permission map for V86 mode
759 Rus 430
	mov	ecx, [esi+12]
431
	mov	[eax+SLOT_BASE+APPDATA.io_map], ecx
432
	mov	ecx, [esi+8]
433
	mov	[eax+SLOT_BASE+APPDATA.io_map+4], ecx
709 diamond 434
.nov86:
435
 
759 Rus 436
	   mov esi, [.slot]
437
	   shl esi,8
438
	   add esi, SLOT_BASE+APP_OBJ_OFFSET
329 serge 439
@@:
759 Rus 440
	   mov eax, [esi+APPOBJ.fd]
441
	   test eax, eax
442
	   jz @F
334 serge 443
 
759 Rus 444
	   cmp eax, esi
445
	   je @F
164 serge 446
 
759 Rus 447
	   push esi
448
	   call [eax+APPOBJ.destroy]
449
	   DEBUGF 1,"%s",msg_obj_destroy
450
	   pop esi
451
	   jmp @B
329 serge 452
@@:
759 Rus 453
	   mov eax, [.slot]
454
	   shl eax, 8
455
	   mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
456
	   stdcall destroy_app_space, eax
1 ha 457
 
759 Rus 458
	   mov esi, [.slot]
459
	   cmp [fpu_owner],esi	 ; if user fpu last -> fpu user = 1
460
	   jne @F
164 serge 461
 
759 Rus 462
	   mov [fpu_owner],1
463
	   mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
464
	   clts
465
	   bt [cpu_caps], CAPS_SSE
466
	   jnc .no_SSE
467
	   fxrstor [eax]
468
	   jmp @F
203 serge 469
.no_SSE:
759 Rus 470
	   fnclex
471
	   frstor [eax]
357 serge 472
@@:
203 serge 473
 
759 Rus 474
    mov   [KEY_COUNT],byte 0	       ; empty keyboard buffer
475
    mov   [BTN_COUNT],byte 0	       ; empty button buffer
1 ha 476
 
477
 
92 diamond 478
; remove defined hotkeys
759 Rus 479
	mov	eax, hotkey_list
92 diamond 480
.loop:
759 Rus 481
	cmp	[eax+8], esi
482
	jnz	.cont
483
	mov	ecx, [eax]
484
	jecxz	@f
485
	push	dword [eax+12]
486
	pop	dword [ecx+12]
92 diamond 487
@@:
759 Rus 488
	mov	ecx, [eax+12]
489
	push	dword [eax]
490
	pop	dword [ecx]
491
	xor	ecx, ecx
492
	mov	[eax], ecx
493
	mov	[eax+4], ecx
494
	mov	[eax+8], ecx
495
	mov	[eax+12], ecx
92 diamond 496
.cont:
759 Rus 497
	add	eax, 16
498
	cmp	eax, hotkey_list+256*16
499
	jb	.loop
92 diamond 500
; remove hotkeys in buffer
759 Rus 501
	mov	eax, hotkey_buffer
92 diamond 502
.loop2:
759 Rus 503
	cmp	[eax], esi
504
	jnz	.cont2
505
	and	dword [eax+4], 0
506
	and	dword [eax], 0
92 diamond 507
.cont2:
759 Rus 508
	add	eax, 8
509
	cmp	eax, hotkey_buffer+120*8
510
	jb	.loop2
92 diamond 511
 
759 Rus 512
    mov   ecx,esi		  ; remove buttons
1 ha 513
  bnewba2:
381 serge 514
    mov   edi,[BTN_ADDR]
1 ha 515
    mov   eax,edi
516
    cld
517
    movzx ebx,word [edi]
518
    inc   bx
519
  bnewba:
520
    dec   bx
759 Rus 521
    jz	  bnmba
1 ha 522
    add   eax,0x10
523
    cmp   cx,[eax]
524
    jnz   bnewba
525
    pusha
526
    mov   ecx,ebx
527
    inc   ecx
528
    shl   ecx,4
529
    mov   ebx,eax
530
    add   eax,0x10
531
    call  memmove
532
    dec   dword [edi]
533
    popa
534
    jmp   bnewba2
535
  bnmba:
536
 
537
    pusha     ; save window coordinates for window restoring
538
    cld
539
    shl   esi,5
540
    add   esi,window_data
114 mikedld 541
    mov   eax,[esi+WDATA.box.left]
102 poddubny 542
    mov   [dlx],eax
114 mikedld 543
    add   eax,[esi+WDATA.box.width]
102 poddubny 544
    mov   [dlxe],eax
114 mikedld 545
    mov   eax,[esi+WDATA.box.top]
102 poddubny 546
    mov   [dly],eax
114 mikedld 547
    add   eax,[esi+WDATA.box.height]
102 poddubny 548
    mov   [dlye],eax
1 ha 549
 
142 diamond 550
    xor   eax, eax
551
    mov   [esi+WDATA.box.left],eax
552
    mov   [esi+WDATA.box.width],eax
114 mikedld 553
    mov   [esi+WDATA.box.top],eax
142 diamond 554
    mov   [esi+WDATA.box.height],eax
115 poddubny 555
    mov   [esi+WDATA.cl_workarea],eax
556
    mov   [esi+WDATA.cl_titlebar],eax
557
    mov   [esi+WDATA.cl_frames],eax
558
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
102 poddubny 559
    lea   edi, [esi-window_data+draw_data]
1 ha 560
    mov   ecx,32/4
561
    rep   stosd
562
    popa
563
 
40 halyavin 564
; debuggee test
565
    pushad
566
    mov  edi, esi
567
    shl  edi, 5
380 serge 568
    mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
40 halyavin 569
    test eax, eax
759 Rus 570
    jz	 .nodebug
40 halyavin 571
    push 8
572
    pop  ecx
759 Rus 573
    push dword [CURRENT_TASK+edi+TASKDATA.pid]	 ; PID
40 halyavin 574
    push 2
575
    call debugger_notify
576
    pop  ecx
577
    pop  ecx
578
.nodebug:
579
    popad
580
 
759 Rus 581
	   mov ebx, [.slot]
582
	   shl ebx, 8
583
	   push ebx
584
	   mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
1 ha 585
 
759 Rus 586
	   stdcall kernel_free, ebx
1 ha 587
 
759 Rus 588
	   pop ebx
589
	   mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
590
	   stdcall kernel_free, ebx
521 diamond 591
 
759 Rus 592
	   mov edi, [.slot]
593
	   shl edi,8
594
	   add edi,SLOT_BASE
465 serge 595
 
759 Rus 596
	   mov eax, [edi+APPDATA.io_map]
597
	   cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
598
	   je @F
599
	   call free_page
465 serge 600
@@:
759 Rus 601
	   mov eax, [edi+APPDATA.io_map+4]
602
	   cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
603
	   je @F
604
	   call free_page
465 serge 605
@@:
759 Rus 606
	   mov eax, 0x20202020
607
	   stosd
608
	   stosd
609
	   stosd
610
	   mov ecx,244/4
611
	   xor eax, eax
612
	   rep stosd
1 ha 613
 
102 poddubny 614
  ; activate window
759 Rus 615
	movzx  eax, word [WIN_STACK + esi*2]
616
	cmp    eax, [TASK_COUNT]
617
	jne    .dont_activate
618
	pushad
102 poddubny 619
 .check_next_window:
759 Rus 620
	dec    eax
621
	cmp    eax, 1
622
	jbe    .nothing_to_activate
623
	lea    esi, [WIN_POS+eax*2]
624
	movzx  edi, word [esi]		     ; edi = process
625
	shl    edi, 5
626
	cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
627
	je     .check_next_window
628
	add    edi, window_data
154 diamond 629
; \begin{diamond}[19.09.2006]
630
; skip minimized windows
759 Rus 631
	test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
632
	jnz    .check_next_window
154 diamond 633
; \end{diamond}
759 Rus 634
	call   waredraw
102 poddubny 635
 .nothing_to_activate:
759 Rus 636
	popad
102 poddubny 637
 .dont_activate:
638
 
759 Rus 639
	push	esi	; remove hd1 & cd & flp reservation
640
	shl	esi, 5
641
	mov	esi, [esi+CURRENT_TASK+TASKDATA.pid]
642
	cmp	[hd1_status], esi
643
	jnz	@f
644
	call	free_hd_channel
645
	mov	[hd1_status], 0
92 diamond 646
@@:
759 Rus 647
	cmp	[cd_status], esi
648
	jnz	@f
649
	call	free_cd_channel
650
	mov	[cd_status], 0
92 diamond 651
@@:
759 Rus 652
	cmp	[flp_status], esi
653
	jnz	@f
654
	mov	[flp_status], 0
92 diamond 655
@@:
759 Rus 656
	pop	esi
657
	cmp	[bgrlockpid], esi
658
	jnz	@f
659
	and	[bgrlockpid], 0
660
	mov	[bgrlock], 0
546 diamond 661
@@:
1 ha 662
 
663
    pusha ; remove all irq reservations
92 diamond 664
    mov   eax,esi
115 poddubny 665
    shl   eax, 5
379 serge 666
    mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
1 ha 667
    mov   edi,irq_owner
774 Rus 668
    xor   ebx, ebx
669
    xor   edx, edx
1 ha 670
  newirqfree:
774 Rus 671
    cmp   [edi + 4 * ebx], eax
1 ha 672
    jne   nofreeirq
774 Rus 673
    mov   [edi + 4 * ebx], edx				; remove irq reservation
674
    mov   [irq_tab + 4 * ebx], edx			; remove irq handler
675
    mov   [irq_rights + 4 * ebx], edx			; set access rights to full access
1 ha 676
  nofreeirq:
774 Rus 677
    inc   ebx
678
    cmp   ebx, 16
679
    jb	  newirqfree
1 ha 680
    popa
681
 
759 Rus 682
    pusha		      ; remove all port reservations
1 ha 683
    mov   edx,esi
115 poddubny 684
    shl   edx, 5
379 serge 685
    add   edx,CURRENT_TASK
115 poddubny 686
    mov   edx,[edx+TASKDATA.pid]
1 ha 687
 
688
  rmpr0:
689
 
381 serge 690
    mov   esi,[RESERVED_PORTS]
1 ha 691
 
692
    cmp   esi,0
759 Rus 693
    je	  rmpr9
1 ha 694
 
695
  rmpr3:
696
 
697
    mov   edi,esi
698
    shl   edi,4
381 serge 699
    add   edi,RESERVED_PORTS
1 ha 700
 
701
    cmp   edx,[edi]
759 Rus 702
    je	  rmpr4
1 ha 703
 
704
    dec   esi
705
    jnz   rmpr3
706
 
707
    jmp   rmpr9
708
 
709
  rmpr4:
710
 
711
    mov   ecx,256
712
    sub   ecx,esi
713
    shl   ecx,4
714
 
715
    mov   esi,edi
716
    add   esi,16
717
    cld
718
    rep   movsb
719
 
381 serge 720
    dec   dword [RESERVED_PORTS]
1 ha 721
 
722
    jmp   rmpr0
723
 
724
  rmpr9:
725
 
726
    popa
759 Rus 727
    mov  edi,esi	 ; do not run this process slot
6 poddubny 728
    shl  edi, 5
379 serge 729
    mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
40 halyavin 730
; debugger test - terminate all debuggees
731
    mov  eax, 2
380 serge 732
    mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
40 halyavin 733
.xd0:
379 serge 734
    cmp  eax, [TASK_COUNT]
759 Rus 735
    ja	 .xd1
40 halyavin 736
    cmp  dword [ecx], esi
737
    jnz  @f
738
    and  dword [ecx], 0
739
    pushad
684 diamond 740
    xchg eax, ecx
741
    mov  ebx, 2
40 halyavin 742
    call sys_system
743
    popad
744
@@:
745
    inc  eax
746
    add  ecx, 0x100
747
    jmp  .xd0
748
.xd1:
1 ha 749
;    call  systest
750
    sti  ; .. and life goes on
751
 
112 poddubny 752
    mov   eax, [dlx]
753
    mov   ebx, [dly]
754
    mov   ecx, [dlxe]
755
    mov   edx, [dlye]
1 ha 756
    call  calculatescreen
757
    xor   eax, eax
758
    xor   esi, esi
759
    call  redrawscreen
760
 
381 serge 761
    mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
762
    mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
1 ha 763
 
764
    mov   [application_table_status],0
506 mikedld 765
    ;mov   esi,process_terminated
766
    ;call  sys_msg_board_str
767
    DEBUGF 1,"%s",process_terminated
357 serge 768
    add esp, 4
1 ha 769
    ret
345 serge 770
restore .slot
1 ha 771
 
772
iglobal
759 Rus 773
  boot_sched_1	  db   'Building gdt tss pointer',0
774
  boot_sched_2	  db   'Building IDT table',0
1 ha 775
endg
776
 
777
 
778
build_scheduler:
779
 
759 Rus 780
	mov    esi,boot_sched_1
781
	call   boot_log
465 serge 782
  ;      call   build_process_gdt_tss_pointer
1 ha 783
 
465 serge 784
  ;      mov    esi,boot_sched_2
785
  ;      call   boot_log
1 ha 786
 
759 Rus 787
	ret