Subversion Repositories Kolibri OS

Rev

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