Subversion Repositories Kolibri OS

Rev

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