Subversion Repositories Kolibri OS

Rev

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