Subversion Repositories Kolibri OS

Rev

Rev 684 | Rev 740 | 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: 709 $
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
 
6 poddubny 24
        mov    edi, idts+8
25
        mov    esi, sys_int
8 poddubny 26
        mov    ecx, 0x40
6 poddubny 27
     @@:
434 diamond 28
        lodsd
465 serge 29
        mov    [edi],   ax           ; lower part of offset
30
        mov    [edi+2], word os_code ; segment selector
434 diamond 31
        mov     ax, word 10001110b shl 8        ; type: interrupt gate
32
        mov     [edi+4], eax
465 serge 33
        add    edi, 8
434 diamond 34
        loop    @b
164 serge 35
 
8 poddubny 36
        ;mov    edi,8*0x40+idts+8
434 diamond 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
1 ha 40
        ret
41
 
42
iglobal
656 mikedld 43
 
44
  msg_sel_ker   db "kernel", 0
45
  msg_sel_app   db "application", 0
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
 
566 serge 56
    dd   irq0, irq_serv.irq_1, p_irq2
57
if USE_COM_IRQ
58
    dd   irq_serv.irq_3, irq_serv.irq_4
59
else
60
    dd   p_irq3, p_irq4
61
end if
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
 
68
    dd   i40
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:
465 serge 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?
112
        test    byte [esp+20h+8+2], 2
113
        jnz     v86_exc_c
114
 
40 halyavin 115
; test if debugging
116
        cli
465 serge 117
        mov   eax, [current_slot]
118
        mov   eax, [eax+APPDATA.debugger_slot]
40 halyavin 119
        test  eax, eax
120
        jnz   .debug
121
        sti
122
; not debuggee => say error and terminate
164 serge 123
        movzx eax, bl
8 poddubny 124
        mov   [error_interrupt], eax
1 ha 125
        call  show_error_parameters
658 Ghost 126
	add   esp, 0x20
379 serge 127
        mov   edx, [TASK_BASE]
115 poddubny 128
        mov   [edx + TASKDATA.state], byte 4
164 serge 129
 
1 ha 130
        jmp   change_task
131
 
40 halyavin 132
.debug:
133
; we are debugged process, notify debugger and suspend ourself
134
; eax=debugger PID
113 diamond 135
        cld
40 halyavin 136
        movzx ecx, bl
137
        push  ecx
379 serge 138
        mov   ecx, [TASK_BASE]
115 poddubny 139
        push  dword [ecx+TASKDATA.pid]    ; PID of current process
40 halyavin 140
        push  12
141
        pop   ecx
58 mario79 142
        push  1        ; 1=exception
40 halyavin 143
        call  debugger_notify
144
        pop   ecx
145
        pop   ecx
146
        pop   ecx
379 serge 147
        mov   edx, [TASK_BASE]
115 poddubny 148
        mov   byte [edx+TASKDATA.state], 1        ; suspended
40 halyavin 149
        call  change_task
150
        restore_ring3_context
151
        iretd
1 ha 152
 
153
iglobal
658 Ghost 154
	hexletters	db '0123456789ABCDEF'
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
172
    je  @f
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
219
     mov   dx, 2F8h     ;[COMPortBaseAddr]
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
237
     mov   dx, 3F8h     ;[COMPortBaseAddr]
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:
248
        save_ring3_context
465 serge 249
        mov     ax, app_data  ;os_data
160 diamond 250
        mov     ds, ax
251
        mov     es, ax
709 diamond 252
        mov     byte [BOOT_VAR + 0x48E], 0xFF
160 diamond 253
        call    [irq14_func]
254
        call    ready_for_next_irq_1
255
        restore_ring3_context
256
        iret
257
p_irq15:
258
        save_ring3_context
465 serge 259
        mov     ax, app_data  ;os_data
160 diamond 260
        mov     ds, ax
261
        mov     es, ax
709 diamond 262
        mov     byte [BOOT_VAR + 0x48E], 0xFF
160 diamond 263
        call    [irq15_func]
264
        call    ready_for_next_irq_1
265
        restore_ring3_context
266
        iret
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:
709 diamond 303
        cmp     [v86_irqhooks+edi*8], 0
304
        jnz     v86_irq2
1 ha 305
 
306
     push   edi
307
 
308
     mov    esi,edi          ; 1
309
     shl    esi,6            ; 1
310
     add    esi,irq00read    ; 1
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
 
321
     mov    dx,[esi]         ; 2+
322
 
323
     cmp    dx,0             ; 1
324
     jz     irqover
325
     cmp    [esi+3],byte 1   ; 2     ; byte read
326
     jne    noirqbyte        ; 4-11
327
 
328
     in     al,dx
329
 
330
     mov    edx,[edi]
331
     cmp    edx,4000
332
     je     irqfull
333
     mov    ebx,edi
334
     add    ebx,0x10
335
     add    ebx,edx
336
     mov    [ebx],al
337
     inc    edx
338
     mov    [edi],edx
339
 
340
     add    esi,4
341
     jmp    irqnewread
342
 
343
   noirqbyte:
344
 
345
 
346
     cmp    [esi+3],byte 2     ; word read
347
     jne    noirqword
348
 
349
     in     ax,dx
350
 
351
     mov    edx,[edi]
352
     cmp    edx,4000
353
     je     irqfull
354
     mov    ebx,edi
355
     add    ebx,0x10
356
     add    ebx,edx
357
     mov    [ebx],ax
358
     add    edx,2
359
     mov    [edi],edx
360
     add    esi,4
361
     jmp    irqnewread
362
 
363
   noirqword:
364
   irqfull:
365
   irqover:
366
 
367
     mov    al,0x20            ; ready for next irq
368
     out    0x20,al
369
 
370
     pop    ebx
371
     cmp    ebx,7
372
     jbe    noa0
373
     out    0xa0,al
374
   noa0:
375
 
376
     ret
377
 
378
 
379
 
380
set_application_table_status:
381
        push eax
382
 
379 serge 383
        mov  eax,[CURRENT_TASK]
1 ha 384
        shl  eax, 5
379 serge 385
        add  eax,CURRENT_TASK+TASKDATA.pid
1 ha 386
        mov  eax,[eax]
387
 
388
        mov  [application_table_status],eax
389
 
390
        pop  eax
391
 
392
        ret
393
 
394
 
395
clear_application_table_status:
396
        push eax
397
 
379 serge 398
        mov  eax,[CURRENT_TASK]
1 ha 399
        shl  eax, 5
379 serge 400
        add  eax,CURRENT_TASK+TASKDATA.pid
1 ha 401
        mov  eax,[eax]
402
 
403
        cmp  eax,[application_table_status]
404
        jne  apptsl1
405
        mov  [application_table_status],0
406
      apptsl1:
407
 
408
        pop  eax
409
 
410
        ret
411
 
412
sys_resize_app_memory:
413
        ; eax = 1 - resize
414
        ;     ebx = new amount of memory
415
 
416
        cmp    eax,1
4 poddubny 417
        jne    .no_application_mem_resize
1 ha 418
 
164 serge 419
        stdcall new_mem_resize, ebx
420
        mov [esp+36], eax
421
        ret
1 ha 422
 
164 serge 423
.no_application_mem_resize:
1 ha 424
        ret
425
 
426
sys_threads:
427
 
428
; eax=1 create thread
429
;
430
;   ebx=thread start
431
;   ecx=thread stack value
432
;
433
; on return : eax = pid
434
jmp new_sys_threads
435
 
436
iglobal
437
  process_terminating   db 'K : Process - terminating',13,10,0
438
  process_terminated    db 'K : Process - done',13,10,0
329 serge 439
  msg_obj_destroy       db 'K : destroy app object',13,10,0
1 ha 440
endg
441
 
329 serge 442
; param
443
;  esi= slot
1 ha 444
 
445
terminate: ; terminate application
446
 
329 serge 447
           .slot equ esp   ;locals
448
 
449
           push   esi      ;save .slot
334 serge 450
 
451
           shl esi, 8
380 serge 452
           cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
334 serge 453
           jne @F
709 diamond 454
           pop    esi
455
           shl    esi, 5
456
           mov    [CURRENT_TASK+esi+TASKDATA.state], 9
334 serge 457
           ret
458
@@:
506 mikedld 459
           ;mov    esi,process_terminating
460
           ;call   sys_msg_board_str
461
           DEBUGF 1,"%s",process_terminating
40 halyavin 462
@@:
329 serge 463
           cli
464
           cmp   [application_table_status],0
465
           je    term9
466
           sti
467
           call  change_task
468
           jmp   @b
469
term9:
470
           call  set_application_table_status
1 ha 471
 
709 diamond 472
; if the process is in V86 mode...
473
        mov     eax, [.slot]
474
        shl     eax, 8
475
        mov     esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
476
        add     esi, RING0_STACK_SIZE
477
        cmp     [eax+SLOT_BASE+APPDATA.saved_esp0], esi
478
        jz      .nov86
479
; ...it has page directory for V86 mode
480
        mov     esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
481
        mov     ecx, [esi+4]
482
        mov     [eax+SLOT_BASE+APPDATA.dir_table], ecx
483
; ...and I/O permission map for V86 mode
484
        mov     ecx, [esi+12]
485
        mov     [eax+SLOT_BASE+APPDATA.io_map], ecx
486
        mov     ecx, [esi+8]
487
        mov     [eax+SLOT_BASE+APPDATA.io_map+4], ecx
488
.nov86:
489
 
329 serge 490
           mov esi, [.slot]
491
           shl esi,8
380 serge 492
           add esi, SLOT_BASE+APP_OBJ_OFFSET
329 serge 493
@@:
494
           mov eax, [esi+APPOBJ.fd]
334 serge 495
           test eax, eax
496
           jz @F
497
 
329 serge 498
           cmp eax, esi
499
           je @F
164 serge 500
 
329 serge 501
           push esi
502
           call [eax+APPOBJ.destroy]
506 mikedld 503
           ;mov  esi, msg_obj_destroy
504
           ;call sys_msg_board_str
505
           DEBUGF 1,"%s",msg_obj_destroy
329 serge 506
           pop esi
507
           jmp @B
508
@@:
509
           mov eax, [.slot]
510
           shl eax, 8
380 serge 511
           mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
329 serge 512
           stdcall destroy_app_space, eax
1 ha 513
 
357 serge 514
           mov esi, [.slot]
329 serge 515
           cmp [fpu_owner],esi   ; if user fpu last -> fpu user = 1
357 serge 516
           jne @F
164 serge 517
 
329 serge 518
           mov [fpu_owner],1
380 serge 519
           mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
379 serge 520
           clts
329 serge 521
           bt [cpu_caps], CAPS_SSE
522
           jnc .no_SSE
523
           fxrstor [eax]
357 serge 524
           jmp @F
203 serge 525
.no_SSE:
329 serge 526
           fnclex
527
           frstor [eax]
357 serge 528
@@:
203 serge 529
 
381 serge 530
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
531
    mov   [BTN_COUNT],byte 0           ; empty button buffer
1 ha 532
 
533
 
92 diamond 534
; remove defined hotkeys
535
        mov     eax, hotkey_list
536
.loop:
537
        cmp     [eax+8], esi
538
        jnz     .cont
539
        mov     ecx, [eax]
540
        jecxz   @f
541
        push    dword [eax+12]
542
        pop     dword [ecx+12]
543
@@:
544
        mov     ecx, [eax+12]
545
        push    dword [eax]
546
        pop     dword [ecx]
547
        xor     ecx, ecx
548
        mov     [eax], ecx
549
        mov     [eax+4], ecx
550
        mov     [eax+8], ecx
551
        mov     [eax+12], ecx
552
.cont:
553
        add     eax, 16
554
        cmp     eax, hotkey_list+256*16
555
        jb      .loop
556
; remove hotkeys in buffer
557
        mov     eax, hotkey_buffer
558
.loop2:
559
        cmp     [eax], esi
560
        jnz     .cont2
561
        and     dword [eax+4], 0
562
        and     dword [eax], 0
563
.cont2:
564
        add     eax, 8
565
        cmp     eax, hotkey_buffer+120*8
566
        jb      .loop2
567
 
1 ha 568
    mov   ecx,esi                 ; remove buttons
569
  bnewba2:
381 serge 570
    mov   edi,[BTN_ADDR]
1 ha 571
    mov   eax,edi
572
    cld
573
    movzx ebx,word [edi]
574
    inc   bx
575
  bnewba:
576
    dec   bx
577
    jz    bnmba
578
    add   eax,0x10
579
    cmp   cx,[eax]
580
    jnz   bnewba
581
    pusha
582
    mov   ecx,ebx
583
    inc   ecx
584
    shl   ecx,4
585
    mov   ebx,eax
586
    add   eax,0x10
587
    call  memmove
588
    dec   dword [edi]
589
    popa
590
    jmp   bnewba2
591
  bnmba:
592
 
593
    pusha     ; save window coordinates for window restoring
594
    cld
595
    shl   esi,5
596
    add   esi,window_data
114 mikedld 597
    mov   eax,[esi+WDATA.box.left]
102 poddubny 598
    mov   [dlx],eax
114 mikedld 599
    add   eax,[esi+WDATA.box.width]
102 poddubny 600
    mov   [dlxe],eax
114 mikedld 601
    mov   eax,[esi+WDATA.box.top]
102 poddubny 602
    mov   [dly],eax
114 mikedld 603
    add   eax,[esi+WDATA.box.height]
102 poddubny 604
    mov   [dlye],eax
1 ha 605
 
142 diamond 606
    xor   eax, eax
607
    mov   [esi+WDATA.box.left],eax
608
    mov   [esi+WDATA.box.width],eax
114 mikedld 609
    mov   [esi+WDATA.box.top],eax
142 diamond 610
    mov   [esi+WDATA.box.height],eax
115 poddubny 611
    mov   [esi+WDATA.cl_workarea],eax
612
    mov   [esi+WDATA.cl_titlebar],eax
613
    mov   [esi+WDATA.cl_frames],eax
614
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
102 poddubny 615
    lea   edi, [esi-window_data+draw_data]
1 ha 616
    mov   ecx,32/4
617
    rep   stosd
618
    popa
619
 
40 halyavin 620
; debuggee test
621
    pushad
622
    mov  edi, esi
623
    shl  edi, 5
380 serge 624
    mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
40 halyavin 625
    test eax, eax
626
    jz   .nodebug
627
    push 8
628
    pop  ecx
379 serge 629
    push dword [CURRENT_TASK+edi+TASKDATA.pid]   ; PID
40 halyavin 630
    push 2
631
    call debugger_notify
632
    pop  ecx
633
    pop  ecx
634
.nodebug:
635
    popad
636
 
357 serge 637
           mov ebx, [.slot]
638
           shl ebx, 8
521 diamond 639
           push ebx
380 serge 640
           mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
1 ha 641
 
357 serge 642
           stdcall kernel_free, ebx
1 ha 643
 
521 diamond 644
           pop ebx
645
           mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
646
           stdcall kernel_free, ebx
647
 
357 serge 648
           mov edi, [.slot]
649
           shl edi,8
380 serge 650
           add edi,SLOT_BASE
465 serge 651
 
652
           mov eax, [edi+APPDATA.io_map]
653
           cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
654
           je @F
655
           call free_page
656
@@:
657
           mov eax, [edi+APPDATA.io_map+4]
658
           cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
659
           je @F
660
           call free_page
661
@@:
357 serge 662
           mov eax, 0x20202020
663
           stosd
664
           stosd
665
           stosd
666
           mov ecx,244/4
667
           xor eax, eax
668
           rep stosd
1 ha 669
 
102 poddubny 670
  ; activate window
380 serge 671
        movzx  eax, word [WIN_STACK + esi*2]
379 serge 672
        cmp    eax, [TASK_COUNT]
102 poddubny 673
        jne    .dont_activate
674
        pushad
675
 .check_next_window:
676
        dec    eax
677
        cmp    eax, 1
678
        jbe    .nothing_to_activate
380 serge 679
        lea    esi, [WIN_POS+eax*2]
102 poddubny 680
        movzx  edi, word [esi]               ; edi = process
681
        shl    edi, 5
379 serge 682
        cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
102 poddubny 683
        je     .check_next_window
684
        add    edi, window_data
154 diamond 685
; \begin{diamond}[19.09.2006]
686
; skip minimized windows
164 serge 687
        test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
688
        jnz    .check_next_window
154 diamond 689
; \end{diamond}
102 poddubny 690
        call   waredraw
691
 .nothing_to_activate:
692
        popad
693
 .dont_activate:
694
 
92 diamond 695
        push    esi     ; remove hd1 & cd & flp reservation
696
        shl     esi, 5
379 serge 697
        mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
92 diamond 698
        cmp     [hd1_status], esi
699
        jnz     @f
321 diamond 700
        call    free_hd_channel
92 diamond 701
        mov     [hd1_status], 0
702
@@:
703
        cmp     [cd_status], esi
704
        jnz     @f
321 diamond 705
        call    free_cd_channel
92 diamond 706
        mov     [cd_status], 0
707
@@:
708
        cmp     [flp_status], esi
709
        jnz     @f
710
        mov     [flp_status], 0
711
@@:
712
        pop     esi
546 diamond 713
        cmp     [bgrlockpid], esi
714
        jnz     @f
715
        and     [bgrlockpid], 0
716
        mov     [bgrlock], 0
717
@@:
1 ha 718
 
719
    pusha ; remove all irq reservations
92 diamond 720
    mov   eax,esi
115 poddubny 721
    shl   eax, 5
379 serge 722
    mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
1 ha 723
    mov   edi,irq_owner
724
    mov   ecx,16
725
  newirqfree:
92 diamond 726
    scasd
1 ha 727
    jne   nofreeirq
92 diamond 728
    mov   [edi-4],dword 0
1 ha 729
  nofreeirq:
730
    loop   newirqfree
731
    popa
732
 
733
    pusha                     ; remove all port reservations
734
    mov   edx,esi
115 poddubny 735
    shl   edx, 5
379 serge 736
    add   edx,CURRENT_TASK
115 poddubny 737
    mov   edx,[edx+TASKDATA.pid]
1 ha 738
 
739
  rmpr0:
740
 
381 serge 741
    mov   esi,[RESERVED_PORTS]
1 ha 742
 
743
    cmp   esi,0
744
    je    rmpr9
745
 
746
  rmpr3:
747
 
748
    mov   edi,esi
749
    shl   edi,4
381 serge 750
    add   edi,RESERVED_PORTS
1 ha 751
 
752
    cmp   edx,[edi]
753
    je    rmpr4
754
 
755
    dec   esi
756
    jnz   rmpr3
757
 
758
    jmp   rmpr9
759
 
760
  rmpr4:
761
 
762
    mov   ecx,256
763
    sub   ecx,esi
764
    shl   ecx,4
765
 
766
    mov   esi,edi
767
    add   esi,16
768
    cld
769
    rep   movsb
770
 
381 serge 771
    dec   dword [RESERVED_PORTS]
1 ha 772
 
773
    jmp   rmpr0
774
 
775
  rmpr9:
776
 
777
    popa
778
    mov  edi,esi         ; do not run this process slot
6 poddubny 779
    shl  edi, 5
379 serge 780
    mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
40 halyavin 781
; debugger test - terminate all debuggees
782
    mov  eax, 2
380 serge 783
    mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
40 halyavin 784
.xd0:
379 serge 785
    cmp  eax, [TASK_COUNT]
40 halyavin 786
    ja   .xd1
787
    cmp  dword [ecx], esi
788
    jnz  @f
789
    and  dword [ecx], 0
790
    pushad
684 diamond 791
    xchg eax, ecx
792
    mov  ebx, 2
40 halyavin 793
    call sys_system
794
    popad
795
@@:
796
    inc  eax
797
    add  ecx, 0x100
798
    jmp  .xd0
799
.xd1:
1 ha 800
;    call  systest
801
    sti  ; .. and life goes on
802
 
112 poddubny 803
    mov   eax, [dlx]
804
    mov   ebx, [dly]
805
    mov   ecx, [dlxe]
806
    mov   edx, [dlye]
1 ha 807
    call  calculatescreen
808
    xor   eax, eax
809
    xor   esi, esi
810
    call  redrawscreen
811
 
381 serge 812
    mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
813
    mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
1 ha 814
 
815
    mov   [application_table_status],0
506 mikedld 816
    ;mov   esi,process_terminated
817
    ;call  sys_msg_board_str
818
    DEBUGF 1,"%s",process_terminated
357 serge 819
    add esp, 4
1 ha 820
    ret
345 serge 821
restore .slot
1 ha 822
 
823
iglobal
824
  boot_sched_1    db   'Building gdt tss pointer',0
8 poddubny 825
  boot_sched_2    db   'Building IDT table',0
1 ha 826
endg
827
 
828
 
829
build_scheduler:
830
 
465 serge 831
        mov    esi,boot_sched_1
832
        call   boot_log
833
  ;      call   build_process_gdt_tss_pointer
1 ha 834
 
465 serge 835
  ;      mov    esi,boot_sched_2
836
  ;      call   boot_log
1 ha 837
 
838
        ret