Subversion Repositories Kolibri OS

Rev

Rev 774 | Rev 788 | 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: 787 $
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
 
759 Rus 56
    dd	 irq0, irq_serv.irq_1, p_irq2
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 :
787 diamond 186
     save_ring3_context
8 poddubny 187
     mov   edi, num
787 diamond 188
     jmp   irq_c
8 poddubny 189
}
1 ha 190
 
769 Rus 191
irqh 2,3,4,5,7,8,9,10,11
1 ha 192
 
787 diamond 193
irq_c:
194
        mov     ax, app_data
195
        mov     ds, ax
196
        mov     es, ax
197
        call    irqhandler
198
        restore_ring3_context
199
        iret
11 poddubny 200
 
201
p_irq6:
40 halyavin 202
     save_ring3_context
465 serge 203
     mov   ax, app_data  ;os_data
11 poddubny 204
     mov   ds, ax
205
     mov   es, ax
206
     call  fdc_irq
33 mario79 207
     call  ready_for_next_irq
40 halyavin 208
     restore_ring3_context
33 mario79 209
     iret
15 poddubny 210
 
211
 
160 diamond 212
p_irq14:
759 Rus 213
	save_ring3_context
214
	mov	ax, app_data  ;os_data
215
	mov	ds, ax
216
	mov	es, ax
217
	mov	byte [BOOT_VAR + 0x48E], 0xFF
218
	call	[irq14_func]
219
	call	ready_for_next_irq_1
220
	restore_ring3_context
221
	iret
160 diamond 222
p_irq15:
759 Rus 223
	save_ring3_context
224
	mov	ax, app_data  ;os_data
225
	mov	ds, ax
226
	mov	es, ax
227
	mov	byte [BOOT_VAR + 0x48E], 0xFF
228
	call	[irq15_func]
229
	call	ready_for_next_irq_1
230
	restore_ring3_context
231
	iret
160 diamond 232
 
33 mario79 233
ready_for_next_irq:
234
     mov    [check_idle_semaphore],5
235
     mov   al, 0x20
236
     out   0x20, al
237
     ret
238
 
239
ready_for_next_irq_1:
240
     mov    [check_idle_semaphore],5
241
     mov   al, 0x20
242
     out    0xa0,al
243
     out   0x20, al
244
     ret
245
 
6 poddubny 246
irqD:
40 halyavin 247
     save_ring3_context
465 serge 248
     mov   ax, app_data  ;os_data
8 poddubny 249
     mov   ds, ax
250
     mov   es, ax
164 serge 251
 
6 poddubny 252
     mov   dx,0xf0
253
     mov   al,0
254
     out   dx,al
1 ha 255
 
6 poddubny 256
     mov   dx,0xa0
257
     mov   al,0x20
258
     out   dx,al
259
     mov   dx,0x20
40 halyavin 260
     out   dx,al
261
 
262
     restore_ring3_context
164 serge 263
 
8 poddubny 264
     iret
1 ha 265
 
266
 
267
irqhandler:
759 Rus 268
	cmp	[v86_irqhooks+edi*8], 0
269
	jnz	v86_irq2
1 ha 270
 
271
 
759 Rus 272
     mov    esi,edi	     ; 1
273
     shl    esi,6	     ; 1
1 ha 274
     add    esi,irq00read    ; 1
759 Rus 275
     shl    edi,12	     ; 1
381 serge 276
     add    edi,IRQ_SAVE
75 diamond 277
     mov    ecx,16
1 ha 278
 
279
   irqnewread:
75 diamond 280
     dec    ecx
281
     js     irqover
1 ha 282
 
759 Rus 283
     movzx  edx, word [esi]	   ; 2+
1 ha 284
 
759 Rus 285
     test   edx, edx		   ; 1
1 ha 286
     jz     irqover
287
 
288
 
759 Rus 289
     mov    ebx, [edi]		   ; address of begin of buffer in edi      ; + 0x0 dword - data size
290
     mov    eax, 4000							    ; + 0x4 dword - data begin offset
291
     cmp    ebx, eax
1 ha 292
     je     irqfull
759 Rus 293
     add    ebx, [edi + 0x4]	   ; add data size to data begin offset
294
     cmp    ebx, eax		   ; if end of buffer, begin cycle again
295
     jb     @f
1 ha 296
 
759 Rus 297
     xor    ebx, ebx
1 ha 298
 
759 Rus 299
  @@:
300
     add    ebx, edi
301
     movzx  eax, byte[esi + 3]	   ; get type of data being received 1 - byte, 2 - word
302
     dec    eax
303
     jz     irqbyte
304
     dec    eax
305
     jnz    noirqword
1 ha 306
 
759 Rus 307
     in     ax,dx
308
     cmp    ebx, 3999		   ; check for address odd in the end of buffer
309
     jne    .odd
310
     mov    [ebx + 0x10], ax
311
     jmp    .add_size
312
  .odd:
313
     mov    [ebx + 0x10], al	   ; I could make mistake here :)
314
     mov    [edi + 0x10], ah
315
  .add_size:
316
     add    dword [edi], 2
317
     jmp    nextport
1 ha 318
 
319
 
759 Rus 320
  irqbyte:
321
     in     al,dx
322
     mov    [ebx + 0x10],al
323
     inc    dword [edi]
324
  nextport:
1 ha 325
     add    esi,4
326
     jmp    irqnewread
327
 
759 Rus 328
 
1 ha 329
   noirqword:
330
   irqfull:
331
   irqover:
332
 
333
     ret
334
 
335
 
336
 
337
set_application_table_status:
759 Rus 338
	push eax
1 ha 339
 
759 Rus 340
	mov  eax,[CURRENT_TASK]
341
	shl  eax, 5
342
	add  eax,CURRENT_TASK+TASKDATA.pid
343
	mov  eax,[eax]
1 ha 344
 
759 Rus 345
	mov  [application_table_status],eax
1 ha 346
 
759 Rus 347
	pop  eax
1 ha 348
 
759 Rus 349
	ret
1 ha 350
 
351
 
352
clear_application_table_status:
759 Rus 353
	push eax
1 ha 354
 
759 Rus 355
	mov  eax,[CURRENT_TASK]
356
	shl  eax, 5
357
	add  eax,CURRENT_TASK+TASKDATA.pid
358
	mov  eax,[eax]
1 ha 359
 
759 Rus 360
	cmp  eax,[application_table_status]
361
	jne  apptsl1
362
	mov  [application_table_status],0
1 ha 363
      apptsl1:
364
 
759 Rus 365
	pop  eax
1 ha 366
 
759 Rus 367
	ret
1 ha 368
 
369
sys_resize_app_memory:
759 Rus 370
	; eax = 1 - resize
371
	;     ebx = new amount of memory
1 ha 372
 
759 Rus 373
	cmp    eax,1
374
	jne    .no_application_mem_resize
1 ha 375
 
759 Rus 376
	stdcall new_mem_resize, ebx
377
	mov [esp+36], eax
378
	ret
1 ha 379
 
164 serge 380
.no_application_mem_resize:
759 Rus 381
	ret
1 ha 382
 
383
sys_threads:
384
 
385
; eax=1 create thread
386
;
387
;   ebx=thread start
388
;   ecx=thread stack value
389
;
390
; on return : eax = pid
391
jmp new_sys_threads
392
 
393
iglobal
759 Rus 394
  process_terminating	db 'K : Process - terminating',13,10,0
395
  process_terminated	db 'K : Process - done',13,10,0
396
  msg_obj_destroy	db 'K : destroy app object',13,10,0
1 ha 397
endg
398
 
329 serge 399
; param
400
;  esi= slot
1 ha 401
 
402
terminate: ; terminate application
403
 
759 Rus 404
	   .slot equ esp   ;locals
329 serge 405
 
759 Rus 406
	   push   esi	   ;save .slot
334 serge 407
 
759 Rus 408
	   shl esi, 8
409
	   cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
410
	   jne @F
411
	   pop	  esi
412
	   shl	  esi, 5
413
	   mov	  [CURRENT_TASK+esi+TASKDATA.state], 9
414
	   ret
334 serge 415
@@:
759 Rus 416
	   ;mov    esi,process_terminating
417
	   ;call   sys_msg_board_str
418
	   DEBUGF 1,"%s",process_terminating
40 halyavin 419
@@:
759 Rus 420
	   cli
421
	   cmp	 [application_table_status],0
422
	   je	 term9
423
	   sti
424
	   call  change_task
425
	   jmp	 @b
329 serge 426
term9:
759 Rus 427
	   call  set_application_table_status
1 ha 428
 
709 diamond 429
; if the process is in V86 mode...
759 Rus 430
	mov	eax, [.slot]
431
	shl	eax, 8
432
	mov	esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
433
	add	esi, RING0_STACK_SIZE
434
	cmp	[eax+SLOT_BASE+APPDATA.saved_esp0], esi
435
	jz	.nov86
709 diamond 436
; ...it has page directory for V86 mode
759 Rus 437
	mov	esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
438
	mov	ecx, [esi+4]
439
	mov	[eax+SLOT_BASE+APPDATA.dir_table], ecx
709 diamond 440
; ...and I/O permission map for V86 mode
759 Rus 441
	mov	ecx, [esi+12]
442
	mov	[eax+SLOT_BASE+APPDATA.io_map], ecx
443
	mov	ecx, [esi+8]
444
	mov	[eax+SLOT_BASE+APPDATA.io_map+4], ecx
709 diamond 445
.nov86:
446
 
759 Rus 447
	   mov esi, [.slot]
448
	   shl esi,8
449
	   add esi, SLOT_BASE+APP_OBJ_OFFSET
329 serge 450
@@:
759 Rus 451
	   mov eax, [esi+APPOBJ.fd]
452
	   test eax, eax
453
	   jz @F
334 serge 454
 
759 Rus 455
	   cmp eax, esi
456
	   je @F
164 serge 457
 
759 Rus 458
	   push esi
459
	   call [eax+APPOBJ.destroy]
460
	   DEBUGF 1,"%s",msg_obj_destroy
461
	   pop esi
462
	   jmp @B
329 serge 463
@@:
759 Rus 464
	   mov eax, [.slot]
465
	   shl eax, 8
466
	   mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
467
	   stdcall destroy_app_space, eax
1 ha 468
 
759 Rus 469
	   mov esi, [.slot]
470
	   cmp [fpu_owner],esi	 ; if user fpu last -> fpu user = 1
471
	   jne @F
164 serge 472
 
759 Rus 473
	   mov [fpu_owner],1
474
	   mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
475
	   clts
476
	   bt [cpu_caps], CAPS_SSE
477
	   jnc .no_SSE
478
	   fxrstor [eax]
479
	   jmp @F
203 serge 480
.no_SSE:
759 Rus 481
	   fnclex
482
	   frstor [eax]
357 serge 483
@@:
203 serge 484
 
759 Rus 485
    mov   [KEY_COUNT],byte 0	       ; empty keyboard buffer
486
    mov   [BTN_COUNT],byte 0	       ; empty button buffer
1 ha 487
 
488
 
92 diamond 489
; remove defined hotkeys
759 Rus 490
	mov	eax, hotkey_list
92 diamond 491
.loop:
759 Rus 492
	cmp	[eax+8], esi
493
	jnz	.cont
494
	mov	ecx, [eax]
495
	jecxz	@f
496
	push	dword [eax+12]
497
	pop	dword [ecx+12]
92 diamond 498
@@:
759 Rus 499
	mov	ecx, [eax+12]
500
	push	dword [eax]
501
	pop	dword [ecx]
502
	xor	ecx, ecx
503
	mov	[eax], ecx
504
	mov	[eax+4], ecx
505
	mov	[eax+8], ecx
506
	mov	[eax+12], ecx
92 diamond 507
.cont:
759 Rus 508
	add	eax, 16
509
	cmp	eax, hotkey_list+256*16
510
	jb	.loop
92 diamond 511
; remove hotkeys in buffer
759 Rus 512
	mov	eax, hotkey_buffer
92 diamond 513
.loop2:
759 Rus 514
	cmp	[eax], esi
515
	jnz	.cont2
516
	and	dword [eax+4], 0
517
	and	dword [eax], 0
92 diamond 518
.cont2:
759 Rus 519
	add	eax, 8
520
	cmp	eax, hotkey_buffer+120*8
521
	jb	.loop2
92 diamond 522
 
759 Rus 523
    mov   ecx,esi		  ; remove buttons
1 ha 524
  bnewba2:
381 serge 525
    mov   edi,[BTN_ADDR]
1 ha 526
    mov   eax,edi
527
    cld
528
    movzx ebx,word [edi]
529
    inc   bx
530
  bnewba:
531
    dec   bx
759 Rus 532
    jz	  bnmba
1 ha 533
    add   eax,0x10
534
    cmp   cx,[eax]
535
    jnz   bnewba
536
    pusha
537
    mov   ecx,ebx
538
    inc   ecx
539
    shl   ecx,4
540
    mov   ebx,eax
541
    add   eax,0x10
542
    call  memmove
543
    dec   dword [edi]
544
    popa
545
    jmp   bnewba2
546
  bnmba:
547
 
548
    pusha     ; save window coordinates for window restoring
549
    cld
550
    shl   esi,5
551
    add   esi,window_data
114 mikedld 552
    mov   eax,[esi+WDATA.box.left]
102 poddubny 553
    mov   [dlx],eax
114 mikedld 554
    add   eax,[esi+WDATA.box.width]
102 poddubny 555
    mov   [dlxe],eax
114 mikedld 556
    mov   eax,[esi+WDATA.box.top]
102 poddubny 557
    mov   [dly],eax
114 mikedld 558
    add   eax,[esi+WDATA.box.height]
102 poddubny 559
    mov   [dlye],eax
1 ha 560
 
142 diamond 561
    xor   eax, eax
562
    mov   [esi+WDATA.box.left],eax
563
    mov   [esi+WDATA.box.width],eax
114 mikedld 564
    mov   [esi+WDATA.box.top],eax
142 diamond 565
    mov   [esi+WDATA.box.height],eax
115 poddubny 566
    mov   [esi+WDATA.cl_workarea],eax
567
    mov   [esi+WDATA.cl_titlebar],eax
568
    mov   [esi+WDATA.cl_frames],eax
569
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
102 poddubny 570
    lea   edi, [esi-window_data+draw_data]
1 ha 571
    mov   ecx,32/4
572
    rep   stosd
573
    popa
574
 
40 halyavin 575
; debuggee test
576
    pushad
577
    mov  edi, esi
578
    shl  edi, 5
380 serge 579
    mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
40 halyavin 580
    test eax, eax
759 Rus 581
    jz	 .nodebug
40 halyavin 582
    push 8
583
    pop  ecx
759 Rus 584
    push dword [CURRENT_TASK+edi+TASKDATA.pid]	 ; PID
40 halyavin 585
    push 2
586
    call debugger_notify
587
    pop  ecx
588
    pop  ecx
589
.nodebug:
590
    popad
591
 
759 Rus 592
	   mov ebx, [.slot]
593
	   shl ebx, 8
594
	   push ebx
595
	   mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
1 ha 596
 
759 Rus 597
	   stdcall kernel_free, ebx
1 ha 598
 
759 Rus 599
	   pop ebx
600
	   mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
601
	   stdcall kernel_free, ebx
521 diamond 602
 
759 Rus 603
	   mov edi, [.slot]
604
	   shl edi,8
605
	   add edi,SLOT_BASE
465 serge 606
 
759 Rus 607
	   mov eax, [edi+APPDATA.io_map]
608
	   cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
609
	   je @F
610
	   call free_page
465 serge 611
@@:
759 Rus 612
	   mov eax, [edi+APPDATA.io_map+4]
613
	   cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
614
	   je @F
615
	   call free_page
465 serge 616
@@:
759 Rus 617
	   mov eax, 0x20202020
618
	   stosd
619
	   stosd
620
	   stosd
621
	   mov ecx,244/4
622
	   xor eax, eax
623
	   rep stosd
1 ha 624
 
102 poddubny 625
  ; activate window
759 Rus 626
	movzx  eax, word [WIN_STACK + esi*2]
627
	cmp    eax, [TASK_COUNT]
628
	jne    .dont_activate
629
	pushad
102 poddubny 630
 .check_next_window:
759 Rus 631
	dec    eax
632
	cmp    eax, 1
633
	jbe    .nothing_to_activate
634
	lea    esi, [WIN_POS+eax*2]
635
	movzx  edi, word [esi]		     ; edi = process
636
	shl    edi, 5
637
	cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
638
	je     .check_next_window
639
	add    edi, window_data
154 diamond 640
; \begin{diamond}[19.09.2006]
641
; skip minimized windows
759 Rus 642
	test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
643
	jnz    .check_next_window
154 diamond 644
; \end{diamond}
759 Rus 645
	call   waredraw
102 poddubny 646
 .nothing_to_activate:
759 Rus 647
	popad
102 poddubny 648
 .dont_activate:
649
 
759 Rus 650
	push	esi	; remove hd1 & cd & flp reservation
651
	shl	esi, 5
652
	mov	esi, [esi+CURRENT_TASK+TASKDATA.pid]
653
	cmp	[hd1_status], esi
654
	jnz	@f
655
	call	free_hd_channel
656
	mov	[hd1_status], 0
92 diamond 657
@@:
759 Rus 658
	cmp	[cd_status], esi
659
	jnz	@f
660
	call	free_cd_channel
661
	mov	[cd_status], 0
92 diamond 662
@@:
759 Rus 663
	cmp	[flp_status], esi
664
	jnz	@f
665
	mov	[flp_status], 0
92 diamond 666
@@:
759 Rus 667
	pop	esi
668
	cmp	[bgrlockpid], esi
669
	jnz	@f
670
	and	[bgrlockpid], 0
671
	mov	[bgrlock], 0
546 diamond 672
@@:
1 ha 673
 
674
    pusha ; remove all irq reservations
92 diamond 675
    mov   eax,esi
115 poddubny 676
    shl   eax, 5
379 serge 677
    mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
1 ha 678
    mov   edi,irq_owner
774 Rus 679
    xor   ebx, ebx
680
    xor   edx, edx
1 ha 681
  newirqfree:
774 Rus 682
    cmp   [edi + 4 * ebx], eax
1 ha 683
    jne   nofreeirq
774 Rus 684
    mov   [edi + 4 * ebx], edx				; remove irq reservation
685
    mov   [irq_tab + 4 * ebx], edx			; remove irq handler
686
    mov   [irq_rights + 4 * ebx], edx			; set access rights to full access
1 ha 687
  nofreeirq:
774 Rus 688
    inc   ebx
689
    cmp   ebx, 16
690
    jb	  newirqfree
1 ha 691
    popa
692
 
759 Rus 693
    pusha		      ; remove all port reservations
1 ha 694
    mov   edx,esi
115 poddubny 695
    shl   edx, 5
379 serge 696
    add   edx,CURRENT_TASK
115 poddubny 697
    mov   edx,[edx+TASKDATA.pid]
1 ha 698
 
699
  rmpr0:
700
 
381 serge 701
    mov   esi,[RESERVED_PORTS]
1 ha 702
 
703
    cmp   esi,0
759 Rus 704
    je	  rmpr9
1 ha 705
 
706
  rmpr3:
707
 
708
    mov   edi,esi
709
    shl   edi,4
381 serge 710
    add   edi,RESERVED_PORTS
1 ha 711
 
712
    cmp   edx,[edi]
759 Rus 713
    je	  rmpr4
1 ha 714
 
715
    dec   esi
716
    jnz   rmpr3
717
 
718
    jmp   rmpr9
719
 
720
  rmpr4:
721
 
722
    mov   ecx,256
723
    sub   ecx,esi
724
    shl   ecx,4
725
 
726
    mov   esi,edi
727
    add   esi,16
728
    cld
729
    rep   movsb
730
 
381 serge 731
    dec   dword [RESERVED_PORTS]
1 ha 732
 
733
    jmp   rmpr0
734
 
735
  rmpr9:
736
 
737
    popa
759 Rus 738
    mov  edi,esi	 ; do not run this process slot
6 poddubny 739
    shl  edi, 5
379 serge 740
    mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
40 halyavin 741
; debugger test - terminate all debuggees
742
    mov  eax, 2
380 serge 743
    mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
40 halyavin 744
.xd0:
379 serge 745
    cmp  eax, [TASK_COUNT]
759 Rus 746
    ja	 .xd1
40 halyavin 747
    cmp  dword [ecx], esi
748
    jnz  @f
749
    and  dword [ecx], 0
750
    pushad
684 diamond 751
    xchg eax, ecx
752
    mov  ebx, 2
40 halyavin 753
    call sys_system
754
    popad
755
@@:
756
    inc  eax
757
    add  ecx, 0x100
758
    jmp  .xd0
759
.xd1:
1 ha 760
;    call  systest
761
    sti  ; .. and life goes on
762
 
112 poddubny 763
    mov   eax, [dlx]
764
    mov   ebx, [dly]
765
    mov   ecx, [dlxe]
766
    mov   edx, [dlye]
1 ha 767
    call  calculatescreen
768
    xor   eax, eax
769
    xor   esi, esi
770
    call  redrawscreen
771
 
381 serge 772
    mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
773
    mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
1 ha 774
 
775
    mov   [application_table_status],0
506 mikedld 776
    ;mov   esi,process_terminated
777
    ;call  sys_msg_board_str
778
    DEBUGF 1,"%s",process_terminated
357 serge 779
    add esp, 4
1 ha 780
    ret
345 serge 781
restore .slot
1 ha 782
 
783
iglobal
759 Rus 784
  boot_sched_1	  db   'Building gdt tss pointer',0
785
  boot_sched_2	  db   'Building IDT table',0
1 ha 786
endg
787
 
788
 
789
build_scheduler:
790
 
759 Rus 791
	mov    esi,boot_sched_1
792
	call   boot_log
465 serge 793
  ;      call   build_process_gdt_tss_pointer
1 ha 794
 
465 serge 795
  ;      mov    esi,boot_sched_2
796
  ;      call   boot_log
1 ha 797
 
759 Rus 798
	ret