Subversion Repositories Kolibri OS

Rev

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