Subversion Repositories Kolibri OS

Rev

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